@Override @GraphTransaction public AtlasEntitiesWithExtInfo getByIds(List<String> guids, boolean isMinExtInfo) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> getByIds({}, {})", guids, isMinExtInfo); } EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry); AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids, isMinExtInfo); if(ret != null){ for(String guid : guids){ AtlasEntity entity = ret.getEntity(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(entity)), "read entity: guid=", guid); } } if (LOG.isDebugEnabled()) { LOG.debug("<== getByIds({}, {}): {}", guids, isMinExtInfo, ret); } return ret; }
@Override @GraphTransaction public AtlasEntitiesWithExtInfo getByIds(List<String> guids, boolean isMinExtInfo) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> getByIds({}, {})", guids, isMinExtInfo); } EntityGraphRetriever entityRetriever = new EntityGraphRetriever(typeRegistry); AtlasEntitiesWithExtInfo ret = entityRetriever.toAtlasEntitiesWithExtInfo(guids, isMinExtInfo); if(ret != null){ for(String guid : guids){ AtlasEntity entity = ret.getEntity(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(entity)), "read entity: guid=", guid); } } if (LOG.isDebugEnabled()) { LOG.debug("<== getByIds({}, {}): {}", guids, isMinExtInfo, ret); } return ret; }
@Test public void testInverseReferenceAutoUpdate_NonComposite_OneToMany() throws Exception { AtlasObjectId juliusId = nameIdMap.get("Julius"); // Change Max's Employee.manager reference to Julius and apply the change as a partial update. // This should also update Julius to add Max to the inverse Manager.subordinates reference. AtlasEntity maxEntityForUpdate = new AtlasEntity(TestUtilsV2.EMPLOYEE_TYPE); maxEntityForUpdate.setAttribute("manager", juliusId); AtlasEntityType employeeType = typeRegistry.getEntityTypeByName(TestUtilsV2.EMPLOYEE_TYPE); Map<String, Object> uniqAttributes = Collections.<String, Object>singletonMap("name", "Max"); EntityMutationResponse updateResponse = entityStore.updateByUniqueAttributes(employeeType, uniqAttributes , new AtlasEntityWithExtInfo(maxEntityForUpdate)); List<AtlasEntityHeader> partialUpdatedEntities = updateResponse.getPartialUpdatedEntities(); // 3 entities should have been updated: // * Max to change the Employee.manager reference // * Julius to add Max to Manager.subordinates // * Jane to remove Max from Manager.subordinates assertEquals(partialUpdatedEntities.size(), 3); AtlasObjectId maxId = nameIdMap.get("Max"); String janeGuid = nameIdMap.get("Jane").getGuid(); AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(maxId.getGuid(), juliusId.getGuid(), janeGuid)); AtlasEntity storedEntity = storedEntities.getEntity(maxId.getGuid()); verifyReferenceValue(storedEntity, "manager", juliusId.getGuid()); storedEntity = storedEntities.getEntity(juliusId.getGuid()); verifyReferenceList(storedEntity, "subordinates", ImmutableList.of(maxId)); storedEntity = storedEntities.getEntity(janeGuid); verify_testInverseReferenceAutoUpdate_NonComposite_OneToMany(storedEntity); }
AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid()); Object value = storedEntity.getAttribute("mapToB"); assertTrue(value instanceof Map); referencedEntityId = refMap.get("b2"); assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b2)); storedEntity = storedEntities.getEntity(b1.getGuid()); verifyReferenceValue(storedEntity, "mappedFromA", a1.getGuid()); storedEntity = storedEntities.getEntity(b2.getGuid()); verifyReferenceValue(storedEntity, "mappedFromA", a1.getGuid()); AtlasEntity storedB3 = storedEntities.getEntity(b3.getGuid()); verifyReferenceValue(storedB3, "mappedFromA", a1.getGuid()); verify_testInverseReferenceAutoUpdate_Map(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(b1.getGuid()), storedEntities.getEntity(b2.getGuid()), storedB3);
AtlasEntity maxEntity = updatedEntities.getEntity(maxId.getGuid()); verifyRelationshipAttributeValue(maxEntity, "manager", juliusId.getGuid()); AtlasEntity juliusEntity = updatedEntities.getEntity(juliusId.getGuid()); verifyRelationshipAttributeList(juliusEntity, "subordinates", ImmutableList.of(maxId, mikeId)); AtlasEntity janeEntity = updatedEntities.getEntity(janeId.getGuid()); maxEntity = updatedEntities.getEntity(maxId.getGuid()); juliusEntity = updatedEntities.getEntity(juliusId.getGuid()); AtlasEntity mikeEntity = updatedEntities.getEntity(mikeId.getGuid()); AtlasEntity johnEntity = updatedEntities.getEntity(johnId.getGuid()); juliusEntity = updatedEntities.getEntity(juliusId.getGuid()); janeEntity = updatedEntities.getEntity(janeId.getGuid()); mikeEntity = updatedEntities.getEntity(mikeId.getGuid());
AtlasEntitiesWithExtInfo updatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid())); AtlasEntity a1Entity = updatedEntities.getEntity(a1.getGuid()); verifyRelationshipAttributeValue(a1Entity, "oneB", b.getGuid()); AtlasEntity a2Entity = updatedEntities.getEntity(a2.getGuid()); verifyRelationshipAttributeValue(a2Entity, "oneB", b.getGuid()); AtlasEntity bEntity = updatedEntities.getEntity(b.getGuid()); verifyRelationshipAttributeList(bEntity, "manyA", ImmutableList.of(getAtlasObjectId(a1), getAtlasObjectId(a2))); a1Entity = updatedEntities.getEntity(a1.getGuid()); a2Entity = updatedEntities.getEntity(a2.getGuid()); bEntity = updatedEntities.getEntity(b.getGuid()); AtlasEntity a3Entity = updatedEntities.getEntity(a3.getGuid()); verifyRelationshipAttributeValue(a3Entity, "oneB", b.getGuid());
AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid()); verifyReferenceValue(storedEntity, "oneB", b.getGuid()); storedEntity = storedEntities.getEntity(a2.getGuid()); verifyReferenceValue(storedEntity, "oneB", b.getGuid()); storedEntity = storedEntities.getEntity(b.getGuid()); verifyReferenceList(storedEntity, "manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2))); verifyReferenceValue(storedEntities.getEntity(a3.getGuid()), "oneB", b.getGuid()); verify_testInverseReferenceAutoUpdate_NonCompositeManyToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(a2.getGuid()), storedEntities.getEntity(a3.getGuid()), storedEntities.getEntity(b.getGuid()));
AtlasEntitiesWithExtInfo partialUpdatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b.getGuid())); AtlasEntity a1Entity = partialUpdatedEntities.getEntity(a1.getGuid()); verifyRelationshipAttributeValue(a1Entity, "b", b.getGuid()); AtlasEntity bEntity = partialUpdatedEntities.getEntity(b.getGuid()); verifyRelationshipAttributeValue(bEntity, "a", a1.getGuid()); partialUpdatedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid())); bEntity = partialUpdatedEntities.getEntity(b.getGuid()); verifyRelationshipAttributeValue(bEntity, "a", a2.getGuid()); AtlasEntity a2Entity = partialUpdatedEntities.getEntity(a2.getGuid()); verifyRelationshipAttributeValue(a2Entity, "b", b.getGuid()); a1Entity = partialUpdatedEntities.getEntity(a1.getGuid()); verifyRelationshipAttributeUpdate_NonComposite_OneToOne(a1Entity, bEntity);
AtlasEntity b1Entity = updatedEntities.getEntity(b1.getGuid()); verifyRelationshipAttributeList(b1Entity, "manyToManyA", ImmutableList.of(getAtlasObjectId(a1), getAtlasObjectId(a2))); AtlasEntity a1Entity = updatedEntities.getEntity(a1.getGuid()); verifyRelationshipAttributeList(a1Entity, "manyB", ImmutableList.of(getAtlasObjectId(b1))); AtlasEntity a2Entity = updatedEntities.getEntity(a2.getGuid()); verifyRelationshipAttributeList(a2Entity, "manyB", ImmutableList.of(getAtlasObjectId(b1)));
assertEquals(partialUpdatedEntities.size(), 3); AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b1.getGuid())); AtlasEntity storedEntity = storedEntities.getEntity(b1.getGuid()); verifyReferenceList(storedEntity, "manyToManyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2))); storedEntity = storedEntities.getEntity(a1.getGuid()); verifyReferenceList(storedEntity, "manyB", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(b1))); storedEntity = storedEntities.getEntity(a2.getGuid()); verifyReferenceList(storedEntity, "manyB", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(b1)));
assertEquals(partialUpdatedEntities.size(), 3); AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b1.getGuid())); AtlasEntity storedEntity = storedEntities.getEntity(b1.getGuid()); verifyReferenceList(storedEntity, "manyToManyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2))); storedEntity = storedEntities.getEntity(a1.getGuid()); verifyReferenceList(storedEntity, "manyB", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(b1))); storedEntity = storedEntities.getEntity(a2.getGuid()); verifyReferenceList(storedEntity, "manyB", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(b1)));
AtlasEntity b1Entity = updatedEntities.getEntity(b1.getGuid()); verifyRelationshipAttributeList(b1Entity, "manyToManyA", ImmutableList.of(getAtlasObjectId(a1), getAtlasObjectId(a2))); AtlasEntity a1Entity = updatedEntities.getEntity(a1.getGuid()); verifyRelationshipAttributeList(a1Entity, "manyB", ImmutableList.of(getAtlasObjectId(b1))); AtlasEntity a2Entity = updatedEntities.getEntity(a2.getGuid()); verifyRelationshipAttributeList(a2Entity, "manyB", ImmutableList.of(getAtlasObjectId(b1)));
@Test public void testInverseReferenceAutoUpdate_NonComposite_OneToMany() throws Exception { AtlasObjectId juliusId = nameIdMap.get("Julius"); // Change Max's Employee.manager reference to Julius and apply the change as a partial update. // This should also update Julius to add Max to the inverse Manager.subordinates reference. AtlasEntity maxEntityForUpdate = new AtlasEntity(TestUtilsV2.EMPLOYEE_TYPE); maxEntityForUpdate.setAttribute("manager", juliusId); AtlasEntityType employeeType = typeRegistry.getEntityTypeByName(TestUtilsV2.EMPLOYEE_TYPE); Map<String, Object> uniqAttributes = Collections.<String, Object>singletonMap("name", "Max"); EntityMutationResponse updateResponse = entityStore.updateByUniqueAttributes(employeeType, uniqAttributes , new AtlasEntityWithExtInfo(maxEntityForUpdate)); List<AtlasEntityHeader> partialUpdatedEntities = updateResponse.getPartialUpdatedEntities(); // 3 entities should have been updated: // * Max to change the Employee.manager reference // * Julius to add Max to Manager.subordinates // * Jane to remove Max from Manager.subordinates assertEquals(partialUpdatedEntities.size(), 3); AtlasObjectId maxId = nameIdMap.get("Max"); String janeGuid = nameIdMap.get("Jane").getGuid(); AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(maxId.getGuid(), juliusId.getGuid(), janeGuid)); AtlasEntity storedEntity = storedEntities.getEntity(maxId.getGuid()); verifyReferenceValue(storedEntity, "manager", juliusId.getGuid()); storedEntity = storedEntities.getEntity(juliusId.getGuid()); verifyReferenceList(storedEntity, "subordinates", ImmutableList.of(maxId)); storedEntity = storedEntities.getEntity(janeGuid); verify_testInverseReferenceAutoUpdate_NonComposite_OneToMany(storedEntity); }
public AtlasEntity getEntity(String guid) { return entitiesWithExtInfo != null && guid != null ? entitiesWithExtInfo.getEntity(guid) : null; }
public AtlasEntity getById(String guid) { if( entities != null) { return entities.getEntity(guid); } return null; }
@Override public AtlasEntity getByGuid(String guid) { AtlasEntity ent = super.entitiesWithExtInfo.getEntity(guid); if(ent == null && entityStream != null) { return entityStream.getByGuid(guid); } return ent; }
@Override public AtlasEntity getByGuid(String guid) { return entityStream != null ? entityStream.getByGuid(guid) : entitiesWithExtInfo.getEntity(guid); }
@Override public AtlasEntity getByGuid(String guid) { return entityStream != null ? entityStream.getByGuid(guid) : entitiesWithExtInfo.getEntity(guid); }
@Override public AtlasEntity getByGuid(String guid) { AtlasEntity ent = super.entitiesWithExtInfo.getEntity(guid); if(ent == null && entityStream != null) { return entityStream.getByGuid(guid); } return ent; }
public AtlasEntity getById(String guid) { if( entities != null) { return entities.getEntity(guid); } return null; }