Class MongoStorageServiceImpl
- java.lang.Object
-
- co.mastermindcms.modules.services.MongoStorageServiceImpl
-
- All Implemented Interfaces:
MongoStorageService
,java.io.Serializable
@Service public class MongoStorageServiceImpl extends java.lang.Object implements MongoStorageService
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private org.springframework.data.mongodb.gridfs.GridFsOperations
gridFsOperations
private org.springframework.data.mongodb.gridfs.GridFsTemplate
gridFsTemplate
private static org.slf4j.Logger
logger
private org.springframework.data.mongodb.core.MongoTemplate
mongoTemplate
-
Constructor Summary
Constructors Constructor Description MongoStorageServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
downloadBinary(java.lang.String id)
This method does download data in database.byte[]
downloadBinary(java.lang.String dbName, java.lang.String collectionName, java.lang.Object doc)
This method does download data in database.<T> org.springframework.data.domain.Page<T>
find(org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort)
This method does find requests and returns data as page.java.util.Map<java.lang.String,java.lang.Object>
findDocuments(java.lang.String dbName, java.lang.String collectionName, java.util.Map<java.lang.String,java.lang.Object> filter)
This method does find documents and returns data as map.<T> java.util.stream.Stream<T>
findToStream(org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort)
This method does find requests and returns data as stream.com.mongodb.client.gridfs.GridFSBucket
getBinaryStorage(java.lang.String dbName, java.lang.String binaryCollection)
This method does return database system.com.mongodb.client.MongoCollection<org.bson.Document>
getCollection(java.lang.String dbName, java.lang.String collectionName)
This method does return database collection.java.util.List<java.util.Map<java.lang.String,java.lang.String>>
getCollections(java.lang.String dbName)
This method retrieves a map, which can be processed in a database.com.mongodb.client.MongoDatabase
getDatabase(java.lang.String dbName)
This method does return database.org.bson.Document
getDocument(java.lang.String dbName, java.lang.String collectionName, java.lang.Object id)
This method does return database document.<T> T
insert(T item)
This method does insert database entity.java.lang.Object
insertDocument(java.lang.String dbName, java.lang.String collectionName, java.util.Map<java.lang.String,java.lang.Object> mapObject)
This method does insert database document.<T> void
remove(T item)
This method does remove database entity.void
removeBinary(java.lang.String id)
This method does remove database binary.void
removeBinary(java.lang.String dbName, java.lang.String binStorageName, java.lang.String json)
This method does remove database binary.void
removeDocument(java.lang.String dbName, java.lang.String collectionName, java.lang.String id)
This method does remove database document.<T> T
save(T item)
This method does save database entity.java.lang.Object
saveDocument(java.lang.String dbName, java.lang.String collectionName, java.lang.String id, java.util.Map<java.lang.String,java.lang.Object> mapObject)
This method does save database document.<T> org.springframework.data.domain.Page<T>
search(org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort, int skip, int limit)
This method does search requests and returns data as page.<T> org.springframework.data.domain.Page<T>
textSearch(java.lang.String[] searchTerms, org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort, int skip, int limit)
This method does search requests and returns data as page.<T> java.util.List<T>
textSearchAsList(java.lang.String[] searchTerms, org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort)
This method does search requests and returns data as list.<T> org.springframework.data.domain.Page<T>
textSearchUnpaged(java.lang.String[] searchTerms, org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort)
This method does search requests and returns data as page.java.lang.String
uploadBinary(java.util.Map<java.lang.String,java.lang.Object> metadata, org.springframework.web.multipart.MultipartFile file)
This method does upload database bean.
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
mongoTemplate
@Autowired private org.springframework.data.mongodb.core.MongoTemplate mongoTemplate
-
gridFsTemplate
@Autowired private org.springframework.data.mongodb.gridfs.GridFsTemplate gridFsTemplate
-
gridFsOperations
@Autowired private org.springframework.data.mongodb.gridfs.GridFsOperations gridFsOperations
-
-
Method Detail
-
getDocument
public org.bson.Document getDocument(java.lang.String dbName, java.lang.String collectionName, java.lang.Object id)
Description copied from interface:MongoStorageService
This method does return database document.- Specified by:
getDocument
in interfaceMongoStorageService
- Parameters:
dbName
- database, from which will be returnedcollectionName
- database collection, from which will be returnedid
- database document, which will be returned- Returns:
- database document
-
getCollection
public com.mongodb.client.MongoCollection<org.bson.Document> getCollection(java.lang.String dbName, java.lang.String collectionName)
Description copied from interface:MongoStorageService
This method does return database collection.- Specified by:
getCollection
in interfaceMongoStorageService
- Parameters:
dbName
- database, from which will be returnedcollectionName
- database collection, which will be returned- Returns:
- database collection
-
getCollections
public java.util.List<java.util.Map<java.lang.String,java.lang.String>> getCollections(java.lang.String dbName)
Description copied from interface:MongoStorageService
This method retrieves a map, which can be processed in a database.- Specified by:
getCollections
in interfaceMongoStorageService
- Parameters:
dbName
- identification for database collection which will be retrieved- Returns:
- map-representation of data
-
getDatabase
public com.mongodb.client.MongoDatabase getDatabase(java.lang.String dbName)
Description copied from interface:MongoStorageService
This method does return database.- Specified by:
getDatabase
in interfaceMongoStorageService
- Parameters:
dbName
- database, where will be returned- Returns:
- database
-
insertDocument
public java.lang.Object insertDocument(java.lang.String dbName, java.lang.String collectionName, java.util.Map<java.lang.String,java.lang.Object> mapObject)
Description copied from interface:MongoStorageService
This method does insert database document.- Specified by:
insertDocument
in interfaceMongoStorageService
- Parameters:
dbName
- database, where will be savedcollectionName
- collection, where will be savedmapObject
- map-representation which converted in json object and inserted in database- Returns:
- inserted database document
-
insert
public <T> T insert(T item)
Description copied from interface:MongoStorageService
This method does insert database entity.- Specified by:
insert
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
item
- database entity, which will be saved- Returns:
- inserted database entity
-
saveDocument
public java.lang.Object saveDocument(java.lang.String dbName, java.lang.String collectionName, java.lang.String id, java.util.Map<java.lang.String,java.lang.Object> mapObject)
Description copied from interface:MongoStorageService
This method does save database document.- Specified by:
saveDocument
in interfaceMongoStorageService
- Parameters:
dbName
- database, where will be savedcollectionName
- collection, where will be savedid
- database document, which will be savedmapObject
- map-representation which converted in json object and inserted in database- Returns:
- saved database document
-
save
public <T> T save(T item)
Description copied from interface:MongoStorageService
This method does save database entity.- Specified by:
save
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
item
- database entity, which will be saved- Returns:
- saved database entity
-
removeDocument
public void removeDocument(java.lang.String dbName, java.lang.String collectionName, java.lang.String id)
Description copied from interface:MongoStorageService
This method does remove database document.- Specified by:
removeDocument
in interfaceMongoStorageService
- Parameters:
dbName
- database, from which it will be removedcollectionName
- collection, from which it will be removedid
- database document, which will be removed
-
remove
public <T> void remove(T item)
Description copied from interface:MongoStorageService
This method does remove database entity.- Specified by:
remove
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
item
- database entity, which will be removed
-
findDocuments
public java.util.Map<java.lang.String,java.lang.Object> findDocuments(java.lang.String dbName, java.lang.String collectionName, java.util.Map<java.lang.String,java.lang.Object> filter)
Description copied from interface:MongoStorageService
This method does find documents and returns data as map.- Specified by:
findDocuments
in interfaceMongoStorageService
- Parameters:
dbName
- search querycollectionName
- field which sort and returned itemsfilter
- database entity class type which will be returned- Returns:
- database entities as map
-
findToStream
public <T> java.util.stream.Stream<T> findToStream(org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort)
Description copied from interface:MongoStorageService
This method does find requests and returns data as stream.- Specified by:
findToStream
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
query
- search queryclazz
- database entity class type which will be returnedsort
- field which sort and returned items- Returns:
- database entities as stream
-
find
public <T> org.springframework.data.domain.Page<T> find(org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort)
Description copied from interface:MongoStorageService
This method does find requests and returns data as page.- Specified by:
find
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
query
- search queryclazz
- database entity class type which will be returnedsort
- field which sort and returned items- Returns:
- database entities as page
-
search
public <T> org.springframework.data.domain.Page<T> search(org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort, int skip, int limit)
Description copied from interface:MongoStorageService
This method does search requests and returns data as page.- Specified by:
search
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
query
- search queryclazz
- database entity class type which will be returnedsort
- field which sort and returned itemsskip
- skip for returned itemslimit
- limit for returned items- Returns:
- database entities as page
-
textSearch
public <T> org.springframework.data.domain.Page<T> textSearch(java.lang.String[] searchTerms, org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort, int skip, int limit)
Description copied from interface:MongoStorageService
This method does search requests and returns data as page.- Specified by:
textSearch
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
searchTerms
- fields list which filter and returned itemsquery
- search queryclazz
- database entity class type which will be returnedsort
- field which sort and returned itemsskip
- skip for returned itemslimit
- limit for returned items- Returns:
- database entities as page
-
textSearchUnpaged
public <T> org.springframework.data.domain.Page<T> textSearchUnpaged(java.lang.String[] searchTerms, org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort)
Description copied from interface:MongoStorageService
This method does search requests and returns data as page.- Specified by:
textSearchUnpaged
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
searchTerms
- fields list which filter and returned itemsquery
- search queryclazz
- database entity class type which will be returnedsort
- field which sort and returned items- Returns:
- database entities as page
-
textSearchAsList
public <T> java.util.List<T> textSearchAsList(java.lang.String[] searchTerms, org.springframework.data.mongodb.core.query.Query query, java.lang.Class<T> clazz, java.lang.String sort)
Description copied from interface:MongoStorageService
This method does search requests and returns data as list.- Specified by:
textSearchAsList
in interfaceMongoStorageService
- Type Parameters:
T
- class type of entity- Parameters:
searchTerms
- fields list which filter and returned itemsquery
- search queryclazz
- database entity class type which will be returnedsort
- field which sort and returned items- Returns:
- database entities as list
-
downloadBinary
public byte[] downloadBinary(java.lang.String dbName, java.lang.String collectionName, java.lang.Object doc)
Description copied from interface:MongoStorageService
This method does download data in database.- Specified by:
downloadBinary
in interfaceMongoStorageService
- Parameters:
dbName
- database, from which it will be downloadedcollectionName
- collection, from which it will be downloadeddoc
- database document, which will be downloaded- Returns:
- data as byte list
-
downloadBinary
public byte[] downloadBinary(java.lang.String id)
Description copied from interface:MongoStorageService
This method does download data in database.- Specified by:
downloadBinary
in interfaceMongoStorageService
- Parameters:
id
- unique id from file in storage- Returns:
- data as byte list
-
getBinaryStorage
public com.mongodb.client.gridfs.GridFSBucket getBinaryStorage(java.lang.String dbName, java.lang.String binaryCollection)
Description copied from interface:MongoStorageService
This method does return database system.- Specified by:
getBinaryStorage
in interfaceMongoStorageService
- Parameters:
dbName
- database, from which it will be returnedbinaryCollection
- collection, from which it will be returned- Returns:
- database system
-
uploadBinary
public java.lang.String uploadBinary(java.util.Map<java.lang.String,java.lang.Object> metadata, org.springframework.web.multipart.MultipartFile file)
Description copied from interface:MongoStorageService
This method does upload database bean.- Specified by:
uploadBinary
in interfaceMongoStorageService
- Parameters:
metadata
- meta information for uploaded documentfile
- file data, which will be uploaded- Returns:
- unique id from uploaded file
-
removeBinary
public void removeBinary(java.lang.String dbName, java.lang.String binStorageName, java.lang.String json)
Description copied from interface:MongoStorageService
This method does remove database binary.- Specified by:
removeBinary
in interfaceMongoStorageService
- Parameters:
dbName
- database, from which it will be returnedbinStorageName
- database bean storage name, which it will be removedjson
- JSON-object of request contains an instructions for search binary
-
removeBinary
public void removeBinary(java.lang.String id)
Description copied from interface:MongoStorageService
This method does remove database binary.- Specified by:
removeBinary
in interfaceMongoStorageService
- Parameters:
id
- unique id, which it will be removed
-
-