@Test public void checkPatchOnePrimitiveCollectionValue() throws ODataJPAModelException, ODataJPAProcessException { final String id = "1"; final Organization beforImage = new Organization(id); final List<String> newComments = Arrays.asList("This is a test", "YAT"); beforImage.getComment().add("YAC"); doReturn(helper.getJPAEntityType("Organizations")).when(requestEntity).getEntityType(); doReturn(beforImage).when(em).find(Organization.class, id); data.put("comment", newComments); keys.put("iD", id); final JPAUpdateResult act = cut.updateEntity(requestEntity, em, HttpMethod.DELETE); assertFalse(act.wasCreate()); assertNotNull(((Organization) act.getModifyedEntity()).getComment()); final List<String> actComments = ((Organization) act.getModifyedEntity()).getComment(); assertEquals(2, actComments.size()); assertTrue(actComments.contains("YAT")); assertTrue(actComments.contains("This is a test")); }
@Override public JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em, final HttpMethod method) throws ODataJPAProcessException { if (method == HttpMethod.PATCH || method == HttpMethod.DELETE) { final Object instance = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil() .createPrimaryKey(requestEntity.getEntityType(), requestEntity.getKeys(), requestEntity.getEntityType())); if (instance == null) { throw new JPAExampleModifyException(ENTITY_NOT_FOUND, HttpStatusCode.NOT_FOUND); } requestEntity.getModifyUtil().setAttributesDeep(requestEntity.getData(), instance, requestEntity.getEntityType()); updateLinks(requestEntity, em, instance); return new JPAUpdateResult(false, instance); } return super.updateEntity(requestEntity, em, method); }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em, final HttpMethod method) throws ODataJPAProcessException { if (method == HttpMethod.PATCH || method == HttpMethod.DELETE) { final Object instance = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil() .createPrimaryKey(requestEntity.getEntityType(), requestEntity.getKeys(), requestEntity.getEntityType())); if (instance == null) { throw new JPAExampleModifyException(ENTITY_NOT_FOUND, HttpStatusCode.NOT_FOUND); } requestEntity.getModifyUtil().setAttributesDeep(requestEntity.getData(), instance, requestEntity.getEntityType()); updateLinks(requestEntity, em, instance); return new JPAUpdateResult(false, instance); } return super.updateEntity(requestEntity, em, method); } }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em, final HttpMethod method) throws ODataJPAProcessException { if (method == HttpMethod.PATCH || method == HttpMethod.DELETE) { final Object instance = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil() .createPrimaryKey(requestEntity.getEntityType(), requestEntity.getKeys(), requestEntity.getEntityType())); if (instance == null) { throw new JPAExampleModifyException(ENTITY_NOT_FOUND, HttpStatusCode.NOT_FOUND); } requestEntity.getModifyUtil().setAttributesDeep(requestEntity.getData(), instance, requestEntity.getEntityType()); updateLinks(requestEntity, em, instance); return new JPAUpdateResult(false, instance); } return super.updateEntity(requestEntity, em, method); } JPAExampleCUDRequestHandler(); }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em, final HttpMethod method) throws ODataJPAProcessException { if (method == HttpMethod.PATCH || method == HttpMethod.DELETE) { final Object instance = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil() .createPrimaryKey(requestEntity.getEntityType(), requestEntity.getKeys(), requestEntity.getEntityType())); if (instance == null) { throw new JPAExampleModifyException(ENTITY_NOT_FOUND, HttpStatusCode.NOT_FOUND); } requestEntity.getModifyUtil().setAttributesDeep(requestEntity.getData(), instance, requestEntity.getEntityType()); updateLinks(requestEntity, em, instance); return new JPAUpdateResult(false, instance); } return super.updateEntity(requestEntity, em, method); } JPAExampleCUDRequestHandler(); @Override Object createEntity(final JPARequestEntity requestEntity, final EntityManager em); @Override void deleteEntity(JPARequestEntity requestEntity, EntityManager em); @Override JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em,
      final HttpMethod method); @Override void validateChanges(EntityManager em); }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em, final HttpMethod method) throws ODataJPAProcessException { if (method == HttpMethod.PATCH || method == HttpMethod.DELETE) { final Object instance = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil() .createPrimaryKey(requestEntity.getEntityType(), requestEntity.getKeys(), requestEntity.getEntityType())); if (instance == null) { throw new JPAExampleModifyException(ENTITY_NOT_FOUND, HttpStatusCode.NOT_FOUND); } requestEntity.getModifyUtil().setAttributesDeep(requestEntity.getData(), instance, requestEntity.getEntityType()); updateLinks(requestEntity, em, instance); return new JPAUpdateResult(false, instance); } return super.updateEntity(requestEntity, em, method); } JPAExampleCUDRequestHandler(); @Override Object createEntity(final JPARequestEntity requestEntity, final EntityManager em); @Override void deleteEntity(JPARequestEntity requestEntity, EntityManager em); @Override JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em,
      final HttpMethod method); @Override void validateChanges(EntityManager em);  }