Search in sources :

Example 1 with ReferenceableInstance

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

the class GraphHelper method getTypedReferenceableInstance.

public static ITypedReferenceableInstance getTypedReferenceableInstance(TypeSystem typeSystem, Referenceable entityInstance) throws AtlasException {
    final String entityTypeName = ParamChecker.notEmpty(entityInstance.getTypeName(), "Entity type cannot be null");
    ClassType entityType = typeSystem.getDataType(ClassType.class, entityTypeName);
    //Both assigned id and values are required for full update
    //classtype.convert() will remove values if id is assigned. So, set temp id, convert and
    // then replace with original id
    Id origId = entityInstance.getId();
    entityInstance.replaceWithNewId(new Id(entityInstance.getTypeName()));
    ITypedReferenceableInstance typedInstrance = entityType.convert(entityInstance, Multiplicity.REQUIRED);
    ((ReferenceableInstance) typedInstrance).replaceWithNewId(origId);
    return typedInstrance;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 2 with ReferenceableInstance

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

the class DefaultMetadataService method updateEntityByUniqueAttribute.

@Override
public CreateUpdateEntitiesResult updateEntityByUniqueAttribute(String typeName, String uniqueAttributeName, String attrValue, Referenceable updatedEntity) throws AtlasException {
    typeName = ParamChecker.notEmpty(typeName, "typeName");
    uniqueAttributeName = ParamChecker.notEmpty(uniqueAttributeName, "uniqueAttributeName");
    attrValue = ParamChecker.notNull(attrValue, "unique attribute value");
    updatedEntity = ParamChecker.notNull(updatedEntity, "updatedEntity");
    ITypedReferenceableInstance oldInstance = getEntityDefinitionReference(typeName, uniqueAttributeName, attrValue);
    final ITypedReferenceableInstance newInstance = validateAndConvertToTypedInstance(updatedEntity, typeName);
    ((ReferenceableInstance) newInstance).replaceWithNewId(oldInstance.getId());
    CreateUpdateEntitiesResult result = repository.updatePartial(newInstance);
    onEntitiesAddedUpdated(result.getEntityResult());
    return result;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Example 3 with ReferenceableInstance

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

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

the class MemRepository method getDuringWalk.

/*
     * - Id must be valid; Class must be valid.
     * - Ask ClassStore to createInstance.
     * - Ask ClassStore to load instance.
     * - load instance traits
     * - add to GraphWalker
     */
ITypedReferenceableInstance getDuringWalk(Id id, ObjectGraphWalker walker) throws RepositoryException {
    ClassStore cS = getClassStore(id.getTypeName());
    if (cS == null) {
        throw new RepositoryException(String.format("Unknown Class %s", id.getTypeName()));
    }
    cS.validate(this, id);
    ReferenceableInstance r = cS.createInstance(this, id);
    cS.load(r);
    for (String traitName : r.getTraits()) {
        HierarchicalTypeStore tt = typeStores.get(traitName);
        tt.load(r);
    }
    walker.addRoot(r);
    return r;
}
Also used : RepositoryException(org.apache.atlas.repository.RepositoryException) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Example 5 with ReferenceableInstance

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

the class ClassStore method createInstance.

/*
     * - assumes id is already validated
     */
ReferenceableInstance createInstance(MemRepository repo, Id id) throws RepositoryException {
    Integer pos = idPosMap.get(id);
    String typeName = typeNameList.get(pos);
    if (!Objects.equals(typeName, hierarchicalType.getName())) {
        return repo.getClassStore(typeName).createInstance(repo, id);
    }
    ImmutableList<String> traitNames = traitNamesStore.get(pos);
    String[] tNs = traitNames.toArray(new String[] {});
    try {
        return (ReferenceableInstance) classType.createInstance(id, tNs);
    } catch (AtlasException me) {
        throw new RepositoryException(me);
    }
}
Also used : RepositoryException(org.apache.atlas.repository.RepositoryException) ReferenceableInstance(org.apache.atlas.typesystem.persistence.ReferenceableInstance) AtlasException(org.apache.atlas.AtlasException)

Aggregations

ReferenceableInstance (org.apache.atlas.typesystem.persistence.ReferenceableInstance)8 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)7 Id (org.apache.atlas.typesystem.persistence.Id)5 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 AtlasException (org.apache.atlas.AtlasException)2 RepositoryException (org.apache.atlas.repository.RepositoryException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 IStruct (org.apache.atlas.typesystem.IStruct)1 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)1 StructInstance (org.apache.atlas.typesystem.persistence.StructInstance)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1