use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class HardDeleteHandlerV1Test method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.
@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(String structContainerGuid) throws Exception {
// Verify that the unidirectional references from the struct and trait instances
// to the deleted entities were disconnected.
ITypedReferenceableInstance structContainerConvertedEntity = metadataService.getEntityDefinition(structContainerGuid);
ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
assertNull(struct.get("target"));
IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
assertNotNull(trait);
assertNull(trait.get("target"));
}
use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class SoftDeleteHandlerV1Test method assertMaxForTestDisconnectBidirectionalReferences.
@Override
protected void assertMaxForTestDisconnectBidirectionalReferences(final Map<String, String> nameGuidMap) throws Exception {
// Verify that the Department.employees reference to the deleted employee
// was disconnected.
ITypedReferenceableInstance hrDept = metadataService.getEntityDefinition(nameGuidMap.get("hr"));
List<ITypedReferenceableInstance> employees = (List<ITypedReferenceableInstance>) hrDept.get("employees");
Assert.assertEquals(employees.size(), 4);
String maxGuid = nameGuidMap.get("Max");
for (ITypedReferenceableInstance employee : employees) {
if (employee.getId()._getId().equals(maxGuid)) {
assertEquals(employee.getId().getState(), Id.EntityState.DELETED);
}
}
// Verify that the Manager.subordinates still references deleted employee
ITypedReferenceableInstance jane = metadataService.getEntityDefinition(nameGuidMap.get("Jane"));
List<ITypedReferenceableInstance> subordinates = (List<ITypedReferenceableInstance>) jane.get("subordinates");
assertEquals(subordinates.size(), 2);
for (ITypedReferenceableInstance subordinate : subordinates) {
if (subordinate.getId()._getId().equals(maxGuid)) {
assertEquals(subordinate.getId().getState(), Id.EntityState.DELETED);
}
}
// Verify that max's Person.mentor unidirectional reference to john was disconnected.
ITypedReferenceableInstance john = metadataService.getEntityDefinition(nameGuidMap.get("John"));
Id mentor = (Id) john.get("mentor");
assertEquals(mentor._getId(), maxGuid);
assertEquals(mentor.getState(), Id.EntityState.DELETED);
}
use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class SoftDeleteHandlerV1Test method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.
@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(final String structContainerGuid) throws Exception {
// Verify that the unidirectional references from the struct and trait instances
// to the deleted entities were not disconnected.
ITypedReferenceableInstance structContainerConvertedEntity = metadataService.getEntityDefinition(structContainerGuid);
ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
assertNotNull(struct.get("target"));
IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
assertNotNull(trait);
assertNotNull(trait.get("target"));
}
use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class ClassType method createInstanceWithTraits.
public ITypedReferenceableInstance createInstanceWithTraits(Id id, AtlasSystemAttributes systemAttributes, Referenceable r, String... traitNames) throws AtlasException {
ImmutableMap.Builder<String, ITypedStruct> b = new ImmutableBiMap.Builder<>();
if (traitNames != null) {
for (String t : traitNames) {
TraitType tType = typeSystem.getDataType(TraitType.class, t);
IStruct iTraitObject = r == null ? null : r.getTrait(t);
ITypedStruct trait = iTraitObject == null ? tType.createInstance() : tType.convert(iTraitObject, Multiplicity.REQUIRED);
b.put(t, trait);
}
}
return new ReferenceableInstance(id == null ? new Id(getName()) : id, getName(), systemAttributes, fieldMapping, new boolean[fieldMapping.fields.size()], new boolean[fieldMapping.fields.size()], fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools], fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes], fieldMapping.numShorts == 0 ? null : new short[fieldMapping.numShorts], fieldMapping.numInts == 0 ? null : new int[fieldMapping.numInts], fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs], fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats], fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles], fieldMapping.numBigDecimals == 0 ? null : new BigDecimal[fieldMapping.numBigDecimals], fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts], fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates], fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings], fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays], fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps], fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs], fieldMapping.numReferenceables == 0 ? null : new ReferenceableInstance[fieldMapping.numReferenceables], fieldMapping.numReferenceables == 0 ? null : new Id[fieldMapping.numReferenceables], b.build());
}
use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class RequestContext method recordEntityDelete.
public void recordEntityDelete(String entityId, String typeName) throws AtlasException {
ClassType type = typeSystem.getDataType(ClassType.class, typeName);
ITypedReferenceableInstance entity = type.createInstance(new Id(entityId, 0, typeName));
if (deletedEntityIds.add(entityId)) {
deletedEntities.add(entity);
}
}
Aggregations