@Override
  @GraphTransaction
  public AtlasClient.EntityResult deleteEntities(List<String> guids) throws RepositoryException {

    if (guids == null || guids.size() == 0) {
      throw new IllegalArgumentException("guids must be non-null and non-empty");
    }

    for (String guid : guids) {
      if (guid == null) {
        LOG.warn("deleteEntities: Ignoring null guid");
        continue;
      }
      try {
        Vertex instanceVertex = graphHelper.getVertexForGUID(guid);
        deleteHandler.deleteEntity(instanceVertex);
      } catch (EntityNotFoundException e) {
        // Entity does not exist - treat as non-error, since the caller
        // wanted to delete the entity and it's already gone.
        LOG.info("Deletion request ignored for non-existent entity with guid " + guid);
        continue;
      } catch (AtlasException e) {
        throw new RepositoryException(e);
      }
    }
    RequestContext requestContext = RequestContext.get();
    return new AtlasClient.EntityResult(
        requestContext.getCreatedEntityIds(),
        requestContext.getUpdatedEntityIds(),
        requestContext.getDeletedEntityIds());
  }
  /**
   * 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);
 }
  /**
   * Adds a new trait to an existing entity represented by a guid.
   *
   * @param guid globally unique identifier for the entity
   * @param traitInstance trait instance that needs to be added to entity
   * @throws RepositoryException
   */
  @Override
  @GraphTransaction
  public void addTrait(String guid, ITypedStruct traitInstance) throws RepositoryException {
    Preconditions.checkNotNull(traitInstance, "Trait instance cannot be null");
    final String traitName = traitInstance.getTypeName();
    LOG.debug("Adding a new trait={} for entity={}", traitName, guid);

    try {
      Vertex instanceVertex = graphHelper.getVertexForGUID(guid);

      // add the trait instance as a new vertex
      final String typeName = GraphHelper.getTypeName(instanceVertex);

      TypedInstanceToGraphMapper instanceToGraphMapper =
          new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
      instanceToGraphMapper.mapTraitInstanceToVertex(
          traitInstance, typeSystem.getDataType(ClassType.class, typeName), instanceVertex);

      // update the traits in entity once adding trait instance is successful
      GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName);
      GraphHelper.setProperty(
          instanceVertex,
          Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY,
          RequestContext.get().getRequestTime());

    } catch (RepositoryException e) {
      throw e;
    } catch (Exception e) {
      throw new RepositoryException(e);
    }
  }
  @Override
  @GraphTransaction
  public ITypedReferenceableInstance getEntityDefinition(String guid)
      throws RepositoryException, EntityNotFoundException {
    LOG.debug("Retrieving entity with guid={}", guid);

    Vertex instanceVertex = graphHelper.getVertexForGUID(guid);

    try {
      return graphToInstanceMapper.mapGraphToTypedInstance(guid, instanceVertex);
    } catch (AtlasException e) {
      throw new RepositoryException(e);
    }
  }