Search in sources :

Example 81 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class ReverseReferenceUpdateSoftDeleteTest method assertTestOneToManyReference.

@Override
void assertTestOneToManyReference(Object object, ITypedReferenceableInstance referencingInstance) throws Exception {
    // Verify reference was not disconnected if soft deletes are enabled.
    Assert.assertTrue(object instanceof List);
    List<ITypedReferenceableInstance> refValues = (List<ITypedReferenceableInstance>) object;
    Assert.assertEquals(refValues.size(), 2);
    // Verify that one of the reference edges is marked DELETED.
    AtlasVertex vertexForGUID = GraphHelper.getInstance().getVertexForGUID(referencingInstance.getId()._getId());
    String edgeLabel = GraphHelper.getEdgeLabel(typeB, typeB.fieldMapping.fields.get("manyA"));
    Iterator<AtlasEdge> outGoingEdgesByLabel = GraphHelper.getInstance().getOutGoingEdgesByLabel(vertexForGUID, edgeLabel);
    boolean found = false;
    while (outGoingEdgesByLabel.hasNext()) {
        AtlasEdge edge = outGoingEdgesByLabel.next();
        String edgeState = edge.getProperty(Constants.STATE_PROPERTY_KEY, String.class);
        if (edgeState.equals(Id.EntityState.DELETED.name())) {
            found = true;
            break;
        }
    }
    Assert.assertTrue(found, "One edge for label " + edgeLabel + " should be marked " + Id.EntityState.DELETED.name());
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) List(java.util.List) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 82 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class ReverseReferenceUpdateSoftDeleteTest method assertTestOneToOneReference.

@Override
void assertTestOneToOneReference(Object actual, ITypedReferenceableInstance expectedValue, ITypedReferenceableInstance referencingInstance) throws Exception {
    // Verify reference was not disconnected if soft deletes are enabled.
    Assert.assertNotNull(actual);
    Assert.assertTrue(actual instanceof ITypedReferenceableInstance);
    ITypedReferenceableInstance referenceValue = (ITypedReferenceableInstance) actual;
    Assert.assertEquals(referenceValue.getId()._getId(), expectedValue.getId()._getId());
    //Verify reference edge was marked as DELETED.
    AtlasVertex vertexForGUID = GraphHelper.getInstance().getVertexForGUID(referencingInstance.getId()._getId());
    String edgeLabel = GraphHelper.getEdgeLabel(typeB, typeB.fieldMapping.fields.get("a"));
    AtlasEdge edgeForLabel = GraphHelper.getInstance().getEdgeForLabel(vertexForGUID, edgeLabel);
    String edgeState = edgeForLabel.getProperty(Constants.STATE_PROPERTY_KEY, String.class);
    Assert.assertEquals(edgeState, Id.EntityState.DELETED.name());
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 83 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class VertexLookupContext method addInstance.

/**
     * Adds an instance to be loaded.
     *
     */
public void addInstance(IReferenceableInstance instance) throws AtlasException {
    ClassType classType = typeSystem.getDataType(ClassType.class, instance.getTypeName());
    ITypedReferenceableInstance newInstance = classType.convert(instance, Multiplicity.REQUIRED);
    findReferencedInstancesToPreLoad(newInstance);
    Id id = instance.getId();
    if (mapper.lookupVertex(id) == null) {
        if (id.isAssigned()) {
            guidsToLookup.add(id);
        } else {
            addToClassMap(classType, instance);
        }
    }
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 84 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class ReplaceIdWithInstance method processNode.

@Override
public void processNode(ObjectGraphWalker.Node nd) throws AtlasException {
    if (nd.attributeName != null) {
        if (nd.aInfo.isComposite && nd.value != null) {
            if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
                if (nd.value instanceof Id) {
                    Id id = (Id) nd.value;
                    ITypedReferenceableInstance r = getInstance(id);
                    nd.instance.set(nd.attributeName, r);
                }
            } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
                DataTypes.ArrayType aT = (DataTypes.ArrayType) nd.aInfo.dataType();
                nd.instance.set(nd.attributeName, convertToInstances((ImmutableCollection) nd.value, nd.aInfo.multiplicity, aT));
            } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
                DataTypes.MapType mT = (DataTypes.MapType) nd.aInfo.dataType();
                nd.instance.set(nd.attributeName, convertToInstances((ImmutableMap) nd.value, nd.aInfo.multiplicity, mT));
            }
        }
    }
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ImmutableMap(com.google.common.collect.ImmutableMap) DataTypes(org.apache.atlas.typesystem.types.DataTypes)

Example 85 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class TypedInstanceToGraphMapper method addFullTextProperty.

private void addFullTextProperty(List<ITypedReferenceableInstance> instances, FullTextMapper fulltextMapper) throws AtlasException {
    if (!AtlasRepositoryConfiguration.isFullTextSearchEnabled()) {
        return;
    }
    for (ITypedReferenceableInstance typedInstance : instances) {
        // Traverse
        AtlasVertex instanceVertex = getClassVertex(typedInstance);
        String fullText = fulltextMapper.mapRecursive(instanceVertex, true);
        GraphHelper.setProperty(instanceVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Aggregations

ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)142 Test (org.testng.annotations.Test)54 List (java.util.List)34 ArrayList (java.util.ArrayList)29 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 AtlasException (org.apache.atlas.AtlasException)16 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)16 HashMap (java.util.HashMap)15 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