Search in sources :

Example 96 with ITypedReferenceableInstance

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

the class TestUtils method loadAndDoSimpleValidation.

/**
     * Loads the entity and does sanity testing of the GuidMapping that was
     * created during the operation.
     *
     */
public static ITypedReferenceableInstance loadAndDoSimpleValidation(String guid, Referenceable original, MetadataService repositoryService) throws AtlasException {
    ITypedReferenceableInstance loaded = repositoryService.getEntityDefinition(guid);
    doSimpleValidation(original, loaded);
    return loaded;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Example 97 with ITypedReferenceableInstance

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

the class TestUtils method createDeptEg1.

public static ITypedReferenceableInstance createDeptEg1(TypeSystem ts) throws AtlasException {
    Referenceable hrDept = new Referenceable(DEPARTMENT_TYPE);
    Referenceable john = new Referenceable(PERSON_TYPE);
    Referenceable jane = new Referenceable("Manager", "SecurityClearance");
    Referenceable johnAddr = new Referenceable("Address");
    Referenceable janeAddr = new Referenceable("Address");
    Referenceable julius = new Referenceable("Manager");
    Referenceable juliusAddr = new Referenceable("Address");
    Referenceable max = new Referenceable("Person");
    Referenceable maxAddr = new Referenceable("Address");
    hrDept.set(NAME, "hr");
    john.set(NAME, "John");
    john.set(DEPARTMENT_ATTR, hrDept);
    johnAddr.set("street", "Stewart Drive");
    johnAddr.set("city", "Sunnyvale");
    john.set("address", johnAddr);
    john.set("birthday", new Date(1950, 5, 15));
    john.set("isOrganDonor", true);
    john.set("hasPets", true);
    john.set("numberOfCars", 1);
    john.set("houseNumber", 153);
    john.set("carMileage", 13364);
    john.set("shares", 15000);
    john.set("salary", 123345.678);
    john.set("age", 50);
    john.set("numberOfStarsEstimate", new BigInteger("1000000000000000000000"));
    john.set("approximationOfPi", new BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286"));
    jane.set(NAME, "Jane");
    jane.set(DEPARTMENT_ATTR, hrDept);
    janeAddr.set("street", "Great America Parkway");
    janeAddr.set("city", "Santa Clara");
    jane.set("address", janeAddr);
    janeAddr.set("street", "Great America Parkway");
    julius.set(NAME, "Julius");
    julius.set(DEPARTMENT_ATTR, hrDept);
    juliusAddr.set("street", "Madison Ave");
    juliusAddr.set("city", "Newtonville");
    julius.set("address", juliusAddr);
    julius.set("subordinates", ImmutableList.<Referenceable>of());
    max.set(NAME, "Max");
    max.set(DEPARTMENT_ATTR, hrDept);
    maxAddr.set("street", "Ripley St");
    maxAddr.set("city", "Newton");
    max.set("address", maxAddr);
    max.set("manager", jane);
    max.set("mentor", julius);
    max.set("birthday", new Date(1979, 3, 15));
    max.set("isOrganDonor", true);
    max.set("hasPets", true);
    max.set("age", 36);
    max.set("numberOfCars", 2);
    max.set("houseNumber", 17);
    max.set("carMileage", 13);
    max.set("shares", Long.MAX_VALUE);
    max.set("salary", Double.MAX_VALUE);
    max.set("numberOfStarsEstimate", new BigInteger("1000000000000000000000000000000"));
    max.set("approximationOfPi", new BigDecimal("3.1415926535897932"));
    john.set("manager", jane);
    john.set("mentor", max);
    hrDept.set(EMPLOYEES_ATTR, ImmutableList.of(john, jane, julius, max));
    jane.set("subordinates", ImmutableList.of(john, max));
    jane.getTrait("SecurityClearance").set("level", 1);
    ClassType deptType = ts.getDataType(ClassType.class, "Department");
    ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED);
    Assert.assertNotNull(hrDept2);
    return hrDept2;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) BigInteger(java.math.BigInteger) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 98 with ITypedReferenceableInstance

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

the class TestUtils method loadAndDoSimpleValidation.

/**
     * Loads the entity and does sanity testing of the GuidMapping  that was
     * created during the operation.
     *
     */
public static ITypedReferenceableInstance loadAndDoSimpleValidation(String guid, Referenceable original, MetadataRepository repositoryService) throws AtlasException {
    ITypedReferenceableInstance loaded = repositoryService.getEntityDefinition(guid);
    doSimpleValidation(original, loaded);
    return loaded;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Example 99 with ITypedReferenceableInstance

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

the class DefaultMetadataService method updateEntityAttributeByGuid.

@Override
public CreateUpdateEntitiesResult updateEntityAttributeByGuid(String guid, String attributeName, String value) throws AtlasException {
    guid = ParamChecker.notEmpty(guid, "entity id");
    attributeName = ParamChecker.notEmpty(attributeName, "attribute name");
    value = ParamChecker.notEmpty(value, "attribute value");
    ITypedReferenceableInstance existInstance = validateEntityExists(guid);
    ClassType type = typeSystem.getDataType(ClassType.class, existInstance.getTypeName());
    ITypedReferenceableInstance newInstance = type.createInstance();
    AttributeInfo attributeInfo = type.fieldMapping.fields.get(attributeName);
    if (attributeInfo == null) {
        throw new AtlasException("Invalid property " + attributeName + " for entity " + existInstance.getTypeName());
    }
    DataTypes.TypeCategory attrTypeCategory = attributeInfo.dataType().getTypeCategory();
    switch(attrTypeCategory) {
        case PRIMITIVE:
            newInstance.set(attributeName, value);
            break;
        case CLASS:
            Id id = new Id(value, 0, attributeInfo.dataType().getName());
            newInstance.set(attributeName, id);
            break;
        default:
            throw new AtlasException("Update of " + attrTypeCategory + " is not supported");
    }
    ((ReferenceableInstance) newInstance).replaceWithNewId(new Id(guid, 0, newInstance.getTypeName()));
    CreateUpdateEntitiesResult result = repository.updatePartial(newInstance);
    onEntitiesAddedUpdated(result.getEntityResult());
    return result;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) 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) AtlasException(org.apache.atlas.AtlasException)

Example 100 with ITypedReferenceableInstance

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

the class DefaultMetadataService method updateEntityPartialByGuid.

@Override
public CreateUpdateEntitiesResult updateEntityPartialByGuid(String guid, Referenceable newEntity) throws AtlasException {
    guid = ParamChecker.notEmpty(guid, "guid cannot be null");
    newEntity = ParamChecker.notNull(newEntity, "updatedEntity cannot be null");
    ITypedReferenceableInstance existInstance = validateEntityExists(guid);
    ITypedReferenceableInstance newInstance = validateAndConvertToTypedInstance(newEntity, existInstance.getTypeName());
    ((ReferenceableInstance) newInstance).replaceWithNewId(new Id(guid, 0, newInstance.getTypeName()));
    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) Id(org.apache.atlas.typesystem.persistence.Id)

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