@Test public void checkPatchComplexCollctionProperty() throws ODataJPAProcessException, ODataJPAModelException { final String id = "2"; final Person beforImage = new Person(); final List<Map<String, Object>> newInhouseAddresses = new ArrayList<>(2); beforImage.setID(id); beforImage.getInhouseAddress().add(new InhouseAddress("DEV", "D-2")); doReturn(helper.getJPAEntityType("Persons")).when(requestEntity).getEntityType(); doReturn(beforImage).when(em).find(Person.class, id); final Map<String, Object> addr1 = new HashMap<>(); addr1.put("taskID", "MAIN"); addr1.put("floor", "U1"); newInhouseAddresses.add(addr1); final Map<String, Object> addr2 = new HashMap<>(); addr2.put("taskID", "EDU"); addr2.put("floor", "E"); newInhouseAddresses.add(addr2); data.put("inhouseAddress", newInhouseAddresses); keys.put("iD", id); final JPAUpdateResult act = cut.updateEntity(requestEntity, em, HttpMethod.PATCH); assertFalse(act.wasCreate()); assertNotNull(((Person) act.getModifyedEntity()).getInhouseAddress()); final List<InhouseAddress> actInhouseAddrs = ((Person) act.getModifyedEntity()).getInhouseAddress(); assertEquals(2, actInhouseAddrs.size()); assertTrue(actInhouseAddrs.get(0).getBuilding() == null || actInhouseAddrs.get(0).getBuilding().isEmpty()); assertTrue(actInhouseAddrs.get(1).getBuilding() == null || actInhouseAddrs.get(1).getBuilding().isEmpty()); }
@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);  }