Search in sources :

Example 6 with ITypedReferenceableInstance

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"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct)

Example 7 with ITypedReferenceableInstance

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);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) List(java.util.List) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.typesystem.persistence.Id)

Example 8 with ITypedReferenceableInstance

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"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct)

Example 9 with ITypedReferenceableInstance

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());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) StructInstance(org.apache.atlas.typesystem.persistence.StructInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ImmutableMap(com.google.common.collect.ImmutableMap) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) IStruct(org.apache.atlas.typesystem.IStruct)

Example 10 with ITypedReferenceableInstance

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);
    }
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType)

Aggregations

ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)142 Test (org.testng.annotations.Test)54 List (java.util.List)34 ArrayList (java.util.ArrayList)30 Id (org.apache.atlas.typesystem.persistence.Id)28 Referenceable (org.apache.atlas.typesystem.Referenceable)22 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)21 ImmutableList (com.google.common.collect.ImmutableList)20 ClassType (org.apache.atlas.typesystem.types.ClassType)19 HashMap (java.util.HashMap)16 AtlasException (org.apache.atlas.AtlasException)16 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)16 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)14 EntityResult (org.apache.atlas.model.legacy.EntityResult)12 IStruct (org.apache.atlas.typesystem.IStruct)10 Map (java.util.Map)9 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 RepositoryException (org.apache.atlas.repository.RepositoryException)9 BeforeTest (org.testng.annotations.BeforeTest)9