@Test public void checkCreateEntityWithComplexCollcetion() throws ODataJPAProcessException, ODataJPAModelException { doReturn(helper.getJPAEntityType("Persons")).when(requestEntity).getEntityType(); final List<Map<String, Object>> inhouseAddrs = new ArrayList<>(2); final Map<String, Object> addr1 = new HashMap<>(4); addr1.put("roomNumber", 32); addr1.put("floor", 2); addr1.put("building", "7"); addr1.put("taskID", "MAIN"); inhouseAddrs.add(addr1); final Map<String, Object> addr2 = new HashMap<>(4); addr2.put("roomNumber", 245); addr2.put("floor", -3); addr2.put("building", "1"); addr2.put("taskID", "DEV"); inhouseAddrs.add(addr2); data.put("iD", "707"); data.put("inhouseAddress", inhouseAddrs); final Person act = (Person) cut.createEntity(requestEntity, em); assertNotNull(act); assertEquals("707", act.getID()); assertEquals(2, act.getInhouseAddress().size()); assertNotNull(act.getInhouseAddress().get(0).getTaskID()); verify(em).persist(act); }
@Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; } }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; } JPAExampleCUDRequestHandler(); }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; } 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 Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; } 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);  }