use of org.apache.atlas.CreateUpdateEntitiesResult 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;
}
use of org.apache.atlas.CreateUpdateEntitiesResult in project incubator-atlas by apache.
the class ReverseReferenceUpdateTestBase method testCallerHasSetBothEnds.
/**
* Verify that explicitly setting both ends of a reference
* does not cause duplicate entries due to auto-update of
* reverse reference.
*/
@Test
public void testCallerHasSetBothEnds() throws Exception {
ITypedReferenceableInstance a = typeA.createInstance();
a.setString("name", TestUtils.randomString());
ITypedReferenceableInstance b1 = typeB.createInstance();
b1.setString("name", TestUtils.randomString());
// Set both sides of the reference.
a.set("oneB", b1);
b1.set("manyA", Collections.singletonList(a));
CreateUpdateEntitiesResult result = repositoryService.createEntities(a);
Map<String, String> guidAssignments = result.getGuidMapping().getGuidAssignments();
String aGuid = a.getId()._getId();
String b1Guid = guidAssignments.get(b1.getId()._getId());
a = repositoryService.getEntityDefinition(aGuid);
Object object = a.get("oneB");
Assert.assertTrue(object instanceof ITypedReferenceableInstance);
Assert.assertEquals(((ITypedReferenceableInstance) object).getId()._getId(), b1Guid);
b1 = repositoryService.getEntityDefinition(b1Guid);
object = b1.get("manyA");
Assert.assertTrue(object instanceof List);
List<ITypedReferenceableInstance> refValues = (List<ITypedReferenceableInstance>) object;
Assert.assertEquals(refValues.size(), 1);
Assert.assertEquals(refValues.get(0).getId()._getId(), aGuid);
}
use of org.apache.atlas.CreateUpdateEntitiesResult in project incubator-atlas by apache.
the class GraphBackedMetadataRepository method createEntities.
@Override
@GraphTransaction
public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, EntityExistsException {
if (LOG.isDebugEnabled()) {
LOG.debug("adding entities={}", entities);
}
try {
TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.CREATE, entities);
List<String> createdGuids = RequestContext.get().getCreatedEntityIds();
CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
EntityResult entityResult = new EntityResult(createdGuids, null, null);
GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
result.setEntityResult(entityResult);
result.setGuidMapping(mapping);
return result;
} catch (EntityExistsException e) {
throw e;
} catch (AtlasException e) {
throw new RepositoryException(e);
}
}
use of org.apache.atlas.CreateUpdateEntitiesResult in project incubator-atlas by apache.
the class DefaultMetadataService method updateEntities.
/**
* Updates an entity, instance of the type based on the guid set.
*
* @param entityInstanceDefinitions
* @return guids - json array of guids
*/
@Override
public CreateUpdateEntitiesResult updateEntities(ITypedReferenceableInstance[] entityInstanceDefinitions) throws AtlasException {
CreateUpdateEntitiesResult result = repository.updateEntities(entityInstanceDefinitions);
onEntitiesAddedUpdated(result.getEntityResult());
return result;
}
use of org.apache.atlas.CreateUpdateEntitiesResult in project incubator-atlas by apache.
the class DefaultMetadataService method createEntities.
public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance[] typedInstances) throws AtlasException {
final CreateUpdateEntitiesResult result = repository.createEntities(typedInstances);
onEntitiesAdded(result.getCreatedEntities());
return result;
}
Aggregations