@JsonSerialize(include = Inclusion.NON_NULL) public List<UUID> getIds() { if (ids != null) { return ids; } /* * if (connectionTypeAndEntityTypeToEntityIdMap != null) { ids = new * ArrayList<UUID>(); Set<UUID> entitySet = new LinkedHashSet<UUID>(); * for (String ctype : connectionTypeAndEntityTypeToEntityIdMap * .keySet()) { Map<String, List<UUID>> m = * connectionTypeAndEntityTypeToEntityIdMap .get(ctype); for (String * etype : m.keySet()) { List<UUID> l = m.get(etype); for (UUID id : l) * { if (!entitySet.contains(id)) { ids.add(id); } } } } return ids; } */ if (connections != null) { ids = new ArrayList<UUID>(); for (ConnectionRef connection : connections) { if (forwardConnections) { ConnectedEntityRef c = connection.getConnectedEntity(); if (c != null) { ids.add(c.getUuid()); } } else { EntityRef c = connection.getConnectingEntity(); if (c != null) { ids.add(c.getUuid()); } } } return ids; } if ((entities != null) /* || (connectionTypeAndEntityTypeToEntityMap != null) */ ) { // getEntities(); ids = new ArrayList<UUID>(); for (Entity entity : entities) { ids.add(entity.getUuid()); } return ids; } if (refs != null) { ids = new ArrayList<UUID>(); for (EntityRef ref : refs) { ids.add(ref.getUuid()); } return ids; } if (id != null) { ids = new ArrayList<UUID>(); ids.add(id); return ids; } if (entity != null) { ids = new ArrayList<UUID>(); ids.add(entity.getUuid()); return ids; } return new ArrayList<UUID>(); }
@Test public void testEntityManager() throws Exception { LOG.info("EntityManagerIT.testEntityManagerTest"); UUID applicationId = setup.createApplication("testOrganization", "testEntityManagerTest"); assertNotNull(applicationId); EntityManager em = setup.getEmf().getEntityManager(applicationId); assertNotNull(em); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put("username", "edanuff"); properties.put("email", "*****@*****.**"); Entity user = em.create("user", properties); assertNotNull(user); user = em.get(user); assertNotNull(user); assertEquals("user.username not expected value", "edanuff", user.getProperty("username")); assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email")); EntityRef userRef = em.getAlias(applicationId, "user", "edanuff"); assertNotNull(userRef); assertEquals("userRef.id not expected value", user.getUuid(), userRef.getUuid()); assertEquals("userRef.type not expected value", "user", userRef.getType()); LOG.info("user.username: "******"username")); LOG.info("user.email: " + user.getProperty("email")); Results results = em.searchCollection( em.getApplicationRef(), "users", new Query().addEqualityFilter("username", "edanuff")); assertNotNull(results); assertEquals(1, results.size()); user = results.getEntity(); assertNotNull(user); assertEquals("user.username not expected value", "edanuff", user.getProperty("username")); assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email")); LOG.info("user.username: "******"username")); LOG.info("user.email: " + user.getProperty("email")); results = em.searchCollection( em.getApplicationRef(), "users", new Query().addEqualityFilter("email", "*****@*****.**")); assertNotNull(results); assertEquals(1, results.size()); user = results.getEntity(); assertNotNull(user); assertEquals("user.username not expected value", "edanuff", user.getProperty("username")); assertEquals("user.email not expected value", "*****@*****.**", user.getProperty("email")); LOG.info("user.username: "******"username")); LOG.info("user.email: " + user.getProperty("email")); }
@JsonSerialize(include = Inclusion.NON_NULL) public Map<UUID, EntityRef> getRefsMap() { if (refsMap != null) { return refsMap; } getEntitiesMap(); if (entitiesMap != null) { refsMap = cast(entitiesMap); return refsMap; } getRefs(); if (refs != null) { refsMap = new LinkedHashMap<UUID, EntityRef>(); for (EntityRef ref : refs) { refsMap.put(ref.getUuid(), ref); } } return refsMap; }
public Results startingFrom(UUID entityId) { if (entities != null) { for (int i = 0; i < entities.size(); i++) { Entity entity = entities.get(i); if (entityId.equals(entity.getUuid())) { if (i == 0) { return this; } return Results.fromEntities(entities.subList(i, entities.size())); } } } if (refs != null) { for (int i = 0; i < refs.size(); i++) { EntityRef entityRef = refs.get(i); if (entityId.equals(entityRef.getUuid())) { if (i == 0) { return this; } return Results.fromRefList(refs.subList(i, refs.size())); } } } if (ids != null) { for (int i = 0; i < ids.size(); i++) { UUID uuid = ids.get(i); if (entityId.equals(uuid)) { if (i == 0) { return this; } return Results.fromIdList(ids.subList(i, ids.size())); } } } return this; }
@JsonSerialize(include = Inclusion.NON_NULL) public UUID getId() { if (id != null) { return id; } if (entity != null) { id = entity.getUuid(); return id; } if ((ids != null) && (ids.size() > 0)) { id = ids.get(0); return id; } if ((entities != null) && (entities.size() > 0)) { entity = entities.get(0); id = entity.getUuid(); return id; } if ((refs != null) && (refs.size() > 0)) { EntityRef ref = refs.get(0); id = ref.getUuid(); } return id; }