Search in sources :

Example 1 with TraitNotFoundException

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

the class GraphBackedMetadataRepository method deleteTrait.

/**
     * Deletes a given trait from an existing entity represented by a guid.
     *
     * @param guid      globally unique identifier for the entity
     * @param traitNameToBeDeleted name of the trait
     * @throws RepositoryException
     */
@Override
@GraphTransaction
public void deleteTrait(String guid, String traitNameToBeDeleted) throws TraitNotFoundException, EntityNotFoundException, RepositoryException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting trait={} from entity={}", traitNameToBeDeleted, guid);
    }
    AtlasVertex instanceVertex = graphHelper.getVertexForGUID(guid);
    List<String> traitNames = GraphHelper.getTraitNames(instanceVertex);
    if (!traitNames.contains(traitNameToBeDeleted)) {
        throw new TraitNotFoundException("Could not find trait=" + traitNameToBeDeleted + " in the repository for entity: " + guid);
    }
    try {
        final String entityTypeName = GraphHelper.getTypeName(instanceVertex);
        String relationshipLabel = GraphHelper.getTraitLabel(entityTypeName, traitNameToBeDeleted);
        AtlasEdge edge = graphHelper.getEdgeForLabel(instanceVertex, relationshipLabel);
        if (edge != null) {
            deleteHandler.deleteEdgeReference(edge, DataTypes.TypeCategory.TRAIT, false, true);
            // update the traits in entity once trait removal is successful
            traitNames.remove(traitNameToBeDeleted);
            updateTraits(instanceVertex, traitNames);
        }
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) TraitNotFoundException(org.apache.atlas.typesystem.exception.TraitNotFoundException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) RepositoryException(org.apache.atlas.repository.RepositoryException) TraitNotFoundException(org.apache.atlas.typesystem.exception.TraitNotFoundException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasException(org.apache.atlas.AtlasException) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Aggregations

AtlasException (org.apache.atlas.AtlasException)1 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)1 RepositoryException (org.apache.atlas.repository.RepositoryException)1 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)1 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)1 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)1 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)1 TraitNotFoundException (org.apache.atlas.typesystem.exception.TraitNotFoundException)1