@Test public void checkCreateEntityWithComplexCollcetionInitialyNull() throws ODataJPAProcessException, ODataJPAModelException { assertNull(new Collection().getNested()); doReturn(helper.getJPAEntityType("Collections")).when(requestEntity).getEntityType(); final Map<String, Object> complex = new HashMap<>(); final List<Map<String, Object>> nested = new ArrayList<>(); final Map<String, Object> nestedItem = new HashMap<>(); final Map<String, Object> inner = new HashMap<>(); final List<String> comment = new ArrayList<>(); inner.put("figure1", 100L); nestedItem.put("inner", inner); nestedItem.put("number", 50L); nested.add(nestedItem); comment.add("How about this"); complex.put("number", 25L); complex.put("comment", comment); data.put("iD", "707"); data.put("complex", complex); data.put("nested", nested); final Collection act = (Collection) cut.createEntity(requestEntity, em); assertNotNull(act); assertEquals("707", act.getID()); assertNotNull(act.getNested()); assertEquals(1, act.getNested().size()); assertEquals(50L, act.getNested().get(0).getNumber()); assertEquals(100L, act.getNested().get(0).getInner().getFigure1()); assertNotNull(act.getComplex()); assertNotNull(act.getComplex().getComment()); assertEquals(1, act.getComplex().getComment().size()); }
@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);  }