Search in sources :

Example 56 with Id

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

the class AtlasObjectIdConverter method fromV1ToV2.

@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, AtlasFormatConverter.ConverterContext converterContext) throws AtlasBaseException {
    Object ret = null;
    if (v1Obj != null) {
        if (v1Obj instanceof Id) {
            Id id = (Id) v1Obj;
            ret = new AtlasObjectId(id._getId(), id.getTypeName());
        } else if (v1Obj instanceof IReferenceableInstance) {
            IReferenceableInstance refInst = (IReferenceableInstance) v1Obj;
            String guid = refInst.getId()._getId();
            ret = new AtlasObjectId(guid, refInst.getTypeName());
            if (!converterContext.entityExists(guid) && hasAnyAssignedAttribute(refInst)) {
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(refInst.getTypeName());
                AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
                AtlasEntity entity = converter.fromV1ToV2(v1Obj, entityType, converterContext);
                converterContext.addReferredEntity(entity);
            }
        }
    }
    return ret;
}
Also used : IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.typesystem.persistence.Id) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 57 with Id

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

the class ObjectGraphTraversal method processReferenceableInstance.

void processReferenceableInstance(Object val) throws AtlasException {
    if (val == null || !(val instanceof IReferenceableInstance || val instanceof Id)) {
        return;
    }
    if (val instanceof Id) {
        Id id = (Id) val;
        if (id.isUnassigned()) {
            add(id, null);
        }
        return;
    }
    IReferenceableInstance ref = (IReferenceableInstance) val;
    Id id = ref.getId();
    if (id.isUnassigned()) {
        add(id, ref);
        if (!processedIds.contains(id)) {
            processedIds.add(id);
            processStruct(val);
            ImmutableList<String> traits = ref.getTraits();
            for (String trait : traits) {
                processStruct(ref.getTrait(trait));
            }
        }
    }
}
Also used : IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id)

Example 58 with Id

use of org.apache.atlas.typesystem.persistence.Id 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 59 with Id

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

the class EntityJerseyResourceIT method testAddReferenceProperty.

@Test
public void testAddReferenceProperty() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    //Create new db instance
    dbName = "db" + randomString();
    Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
    databaseInstance.set(NAME, dbName);
    databaseInstance.set(QUALIFIED_NAME, dbName);
    databaseInstance.set(CLUSTER_NAME, randomString());
    databaseInstance.set("description", "new database");
    databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    databaseInstance.set("owner", "user1");
    databaseInstance.set(CLUSTER_NAME, "cl1");
    databaseInstance.set("parameters", Collections.EMPTY_MAP);
    databaseInstance.set("location", "/tmp");
    Id dbInstance = createInstance(databaseInstance);
    String newDBId = dbInstance._getId();
    //Add reference property
    addProperty(guid, "db", newDBId);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 60 with Id

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

the class EntityJerseyResourceIT method testGetEntityDefinition.

@Test
public void testGetEntityDefinition() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    Referenceable entity = atlasClientV1.getEntity(guid);
    Assert.assertNotNull(entity);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Aggregations

Id (org.apache.atlas.typesystem.persistence.Id)94 Referenceable (org.apache.atlas.typesystem.Referenceable)50 Test (org.testng.annotations.Test)37 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)28 List (java.util.List)17 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)12 ImmutableList (com.google.common.collect.ImmutableList)10 TraitType (org.apache.atlas.typesystem.types.TraitType)10 JSONObject (org.codehaus.jettison.json.JSONObject)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 Struct (org.apache.atlas.typesystem.Struct)7 ClassType (org.apache.atlas.typesystem.types.ClassType)7 AtlasException (org.apache.atlas.AtlasException)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5