Class VitamElasticsearchRepository

  • All Implemented Interfaces:
    VitamRepository

    public class VitamElasticsearchRepository
    extends java.lang.Object
    implements VitamRepository
    Implementation for Elasticsearch
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String IDENTIFIER
      Identifier
    • Constructor Summary

      Constructors 
      Constructor Description
      VitamElasticsearchRepository​(org.elasticsearch.client.RestHighLevelClient client, java.lang.String indexName, boolean indexByTenant)
      VitamElasticsearchRepository Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void delete​(java.util.List<java.lang.String> ids, int tenant)
      Deleted all documents by ids
      com.mongodb.client.FindIterable<org.bson.Document> findByFieldsDocuments​(java.util.Map<java.lang.String,​java.lang.String> fields, int mongoBatchSize, java.lang.Integer tenant)
      Return iterable over document for the given collection for a specific tenant and fields
      java.util.Optional<org.bson.Document> findByIdentifier​(java.lang.String identifier)
      Find by identifier for collections cross tenant
      java.util.Optional<org.bson.Document> findByIdentifierAndTenant​(java.lang.String identifier, java.lang.Integer tenant)
      find by identifier for all tenant
      com.mongodb.client.FindIterable<org.bson.Document> findDocuments​(int mongoBatchSize)
      Return iterable over document for the given collection
      com.mongodb.client.FindIterable<org.bson.Document> findDocuments​(int mongoBatchSize, java.lang.Integer tenant)
      Return iterable over document for the given collection for a specific tenant
      com.mongodb.client.FindIterable<org.bson.Document> findDocuments​(java.util.Collection<java.lang.String> ids, org.bson.conversions.Bson projection)
      Find collection of document by there id and return only projection fields
      com.mongodb.client.FindIterable<org.bson.Document> findDocuments​(org.bson.conversions.Bson query, int mongoBatchSize)
      Return iterable over document for the given collection
      java.util.Optional<org.bson.Document> getByID​(java.lang.String id, java.lang.Integer tenant)
      Get vitam document by id
      static long handlePurge​(org.elasticsearch.client.RestHighLevelClient client, java.lang.String index, org.elasticsearch.index.query.QueryBuilder qb)  
      long purge()
      Be careful when using this method Remove by tenant for collection cross-tenant
      long purge​(java.lang.Integer tenant)
      Be careful when using this method Remove by tenant for collection multi-tenant
      void remove​(java.lang.String id, java.lang.Integer tenant)
      Remove document by id
      long remove​(org.bson.conversions.Bson query)
      Be careful when using this method Remove by query
      void removeByNameAndTenant​(java.lang.String name, java.lang.Integer tenant)
      Be careful when using this method Remove collection by name and tenant
      void save​(ElasticsearchCollections elasticsearchCollections, java.util.List<org.bson.Document> documents)  
      void save​(java.util.List<org.bson.Document> documents)
      Save a list of vitam documents
      void save​(org.bson.Document document)
      Save vitam document
      void saveOrUpdate​(java.util.List<org.bson.Document> documents)
      Save or update a list of vitam documents
      VitamRepositoryStatus saveOrUpdate​(org.bson.Document document)
      Save or updatevitam document
      org.elasticsearch.action.search.SearchResponse search​(java.lang.String index, org.elasticsearch.index.query.QueryBuilder qb)  
      void update​(java.util.List<com.mongodb.client.model.WriteModel<org.bson.Document>> updates)
      Used to execute a bulk update If document exists then update If document do not exists then create document throw Duplicate key exception if document exists by _id but not exists by filter in the update one model
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

    • Constructor Detail

      • VitamElasticsearchRepository

        public VitamElasticsearchRepository​(org.elasticsearch.client.RestHighLevelClient client,
                                            java.lang.String indexName,
                                            boolean indexByTenant)
        VitamElasticsearchRepository Constructor
        Parameters:
        client - the es client
        indexName - the name of the index
        indexByTenant - specifies if the index is for a specific tenant or not
    • Method Detail

      • save

        public void save​(java.util.List<org.bson.Document> documents)
                  throws DatabaseException
        Description copied from interface: VitamRepository
        Save a list of vitam documents
        Specified by:
        save in interface VitamRepository
        Parameters:
        documents - the list of documents to be saved
        Throws:
        DatabaseException - in case error with database occurs
      • saveOrUpdate

        public void saveOrUpdate​(java.util.List<org.bson.Document> documents)
                          throws DatabaseException
        Description copied from interface: VitamRepository
        Save or update a list of vitam documents
        Specified by:
        saveOrUpdate in interface VitamRepository
        Parameters:
        documents - the list of document to be saved orupdated
        Throws:
        DatabaseException - in case error with database occurs
      • update

        public void update​(java.util.List<com.mongodb.client.model.WriteModel<org.bson.Document>> updates)
                    throws DatabaseException
        Description copied from interface: VitamRepository
        Used to execute a bulk update If document exists then update If document do not exists then create document throw Duplicate key exception if document exists by _id but not exists by filter in the update one model
        Specified by:
        update in interface VitamRepository
        Throws:
        DatabaseException
      • findDocuments

        public com.mongodb.client.FindIterable<org.bson.Document> findDocuments​(java.util.Collection<java.lang.String> ids,
                                                                                org.bson.conversions.Bson projection)
        Description copied from interface: VitamRepository
        Find collection of document by there id and return only projection fields
        Specified by:
        findDocuments in interface VitamRepository
        Parameters:
        ids - list of documents id
        projection - the fields wanted in the result
        Returns:
        An iterable of documents
      • remove

        public void remove​(java.lang.String id,
                           java.lang.Integer tenant)
                    throws DatabaseException
        Description copied from interface: VitamRepository
        Remove document by id
        Specified by:
        remove in interface VitamRepository
        Parameters:
        id - the id of the document to be removed
        tenant - the tenant of the document to be removed
        Throws:
        DatabaseException - in case error with database occurs
      • removeByNameAndTenant

        public void removeByNameAndTenant​(java.lang.String name,
                                          java.lang.Integer tenant)
                                   throws DatabaseException
        Description copied from interface: VitamRepository
        Be careful when using this method Remove collection by name and tenant
        Specified by:
        removeByNameAndTenant in interface VitamRepository
        Parameters:
        name - the name of the collection to be removed
        tenant - the tenant of the collection to be removed
        Throws:
        DatabaseException - in case error with database occurs
      • purge

        public long purge​(java.lang.Integer tenant)
                   throws DatabaseException
        Description copied from interface: VitamRepository
        Be careful when using this method Remove by tenant for collection multi-tenant
        Specified by:
        purge in interface VitamRepository
        Parameters:
        tenant - the tenant
        Returns:
        the number of deleted documents
        Throws:
        DatabaseException - in case error with database occurs
      • handlePurge

        public static long handlePurge​(org.elasticsearch.client.RestHighLevelClient client,
                                       java.lang.String index,
                                       org.elasticsearch.index.query.QueryBuilder qb)
                                throws DatabaseException
        Throws:
        DatabaseException
      • getByID

        public java.util.Optional<org.bson.Document> getByID​(java.lang.String id,
                                                             java.lang.Integer tenant)
                                                      throws DatabaseException
        Description copied from interface: VitamRepository
        Get vitam document by id
        Specified by:
        getByID in interface VitamRepository
        Parameters:
        id - the document id
        tenant - the tenant of the document
        Returns:
        the document if found
        Throws:
        DatabaseException - in case error with database occurs
      • findByIdentifierAndTenant

        public java.util.Optional<org.bson.Document> findByIdentifierAndTenant​(java.lang.String identifier,
                                                                               java.lang.Integer tenant)
                                                                        throws DatabaseException
        Description copied from interface: VitamRepository
        find by identifier for all tenant
        Specified by:
        findByIdentifierAndTenant in interface VitamRepository
        Parameters:
        identifier - the identifier of the document
        tenant - the tenant of the document
        Returns:
        the document if found
        Throws:
        DatabaseException - in case error with database occurs
      • search

        public org.elasticsearch.action.search.SearchResponse search​(java.lang.String index,
                                                                     org.elasticsearch.index.query.QueryBuilder qb)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • findByIdentifier

        public java.util.Optional<org.bson.Document> findByIdentifier​(java.lang.String identifier)
                                                               throws DatabaseException
        Description copied from interface: VitamRepository
        Find by identifier for collections cross tenant
        Specified by:
        findByIdentifier in interface VitamRepository
        Parameters:
        identifier - the identifier of the document
        Returns:
        the document if found
        Throws:
        DatabaseException - in case error with database occurs
      • findByFieldsDocuments

        public com.mongodb.client.FindIterable<org.bson.Document> findByFieldsDocuments​(java.util.Map<java.lang.String,​java.lang.String> fields,
                                                                                        int mongoBatchSize,
                                                                                        java.lang.Integer tenant)
        Description copied from interface: VitamRepository
        Return iterable over document for the given collection for a specific tenant and fields
        Specified by:
        findByFieldsDocuments in interface VitamRepository
        Parameters:
        fields - list of fields for filter
        mongoBatchSize - mongoBatchSize
        tenant - tenant id
        Returns:
        iterable over document for the given collection
      • findDocuments

        public com.mongodb.client.FindIterable<org.bson.Document> findDocuments​(int mongoBatchSize,
                                                                                java.lang.Integer tenant)
        Description copied from interface: VitamRepository
        Return iterable over document for the given collection for a specific tenant
        Specified by:
        findDocuments in interface VitamRepository
        Parameters:
        mongoBatchSize - mongoBatchSize
        tenant - tenant id
        Returns:
        iterable over document for the given collection
      • findDocuments

        public com.mongodb.client.FindIterable<org.bson.Document> findDocuments​(int mongoBatchSize)
        Description copied from interface: VitamRepository
        Return iterable over document for the given collection
        Specified by:
        findDocuments in interface VitamRepository
        Parameters:
        mongoBatchSize - mongoBatchSize
        Returns:
        iterable over document for the given collection
      • findDocuments

        public com.mongodb.client.FindIterable<org.bson.Document> findDocuments​(org.bson.conversions.Bson query,
                                                                                int mongoBatchSize)
        Description copied from interface: VitamRepository
        Return iterable over document for the given collection
        Specified by:
        findDocuments in interface VitamRepository
        Parameters:
        query - the mongo query to be executed
        mongoBatchSize - mongoBatchSize
        Returns:
        iterable over document for the given collection