Search in sources :

Example 11 with CreateUpdateEntitiesResult

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;
}
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 12 with CreateUpdateEntitiesResult

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);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 13 with CreateUpdateEntitiesResult

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);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 14 with CreateUpdateEntitiesResult

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;
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult)

Example 15 with CreateUpdateEntitiesResult

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;
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult)

Aggregations

CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)22 AtlasException (org.apache.atlas.AtlasException)9 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)9 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)5 Referenceable (org.apache.atlas.typesystem.Referenceable)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)4 GuidMapping (org.apache.atlas.model.instance.GuidMapping)4 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)4 Id (org.apache.atlas.typesystem.persistence.Id)4 Test (org.testng.annotations.Test)4 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)3 RepositoryException (org.apache.atlas.repository.RepositoryException)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)3 ReferenceableInstance (org.apache.atlas.typesystem.persistence.ReferenceableInstance)3 ClassType (org.apache.atlas.typesystem.types.ClassType)3