/** * 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 { LOG.debug("Deleting trait={} from entity={}", traitNameToBeDeleted, guid); Vertex 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); Edge edge = GraphHelper.getEdgeForLabel(instanceVertex, relationshipLabel); 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); } }
/** * Gets the list of trait names for a given entity represented by a guid. * * @param guid globally unique identifier for the entity * @return a list of trait names for the given entity guid * @throws RepositoryException */ @Override @GraphTransaction public List<String> getTraitNames(String guid) throws AtlasException { LOG.debug("Retrieving trait names for entity={}", guid); Vertex instanceVertex = graphHelper.getVertexForGUID(guid); return GraphHelper.getTraitNames(instanceVertex); }
/** * Delete all traits from the specified vertex. * * @param instanceVertex * @throws AtlasException */ private void deleteAllTraits(Vertex instanceVertex) throws AtlasException { List<String> traitNames = GraphHelper.getTraitNames(instanceVertex); LOG.debug("Deleting traits {} for {}", traitNames, string(instanceVertex)); String typeName = GraphHelper.getTypeName(instanceVertex); for (String traitNameToBeDeleted : traitNames) { String relationshipLabel = GraphHelper.getTraitLabel(typeName, traitNameToBeDeleted); deleteEdgeReference(instanceVertex, relationshipLabel, DataTypes.TypeCategory.TRAIT, false); } }