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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations