Search in sources :

Example 1 with ID

use of io.lumeer.storage.mongodb.model.common.MorphiaEntity.ID in project engine by Lumeer.

the class MorphiaDocumentDao method createDocuments.

@Override
public List<Document> createDocuments(final List<Document> documents) {
    List<org.bson.Document> bsonDocuments = documents.stream().map(doc -> new MorphiaDocument(doc).toBsonDocument()).collect(Collectors.toList());
    database.getCollection(databaseCollection()).insertMany(bsonDocuments);
    for (int i = 0; i < documents.size(); i++) {
        documents.get(i).setId(bsonDocuments.get(i).getObjectId(ID).toHexString());
    }
    return documents;
}
Also used : ID(io.lumeer.storage.mongodb.model.common.MorphiaEntity.ID) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) Arrays(java.util.Arrays) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Document(io.lumeer.api.model.Document) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Query(org.mongodb.morphia.query.Query) Project(io.lumeer.api.model.Project) WriteResult(com.mongodb.WriteResult) List(java.util.List) ResourceType(io.lumeer.api.model.ResourceType) RequestScoped(javax.enterprise.context.RequestScoped) WriteFailedException(io.lumeer.storage.mongodb.exception.WriteFailedException) ObjectId(org.bson.types.ObjectId) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) Document(io.lumeer.api.model.Document) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument) MorphiaDocument(io.lumeer.storage.mongodb.model.MorphiaDocument)

Aggregations

WriteResult (com.mongodb.WriteResult)1 Document (io.lumeer.api.model.Document)1 Project (io.lumeer.api.model.Project)1 ResourceType (io.lumeer.api.model.ResourceType)1 DocumentDao (io.lumeer.storage.api.dao.DocumentDao)1 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)1 WriteFailedException (io.lumeer.storage.mongodb.exception.WriteFailedException)1 MorphiaDocument (io.lumeer.storage.mongodb.model.MorphiaDocument)1 ID (io.lumeer.storage.mongodb.model.common.MorphiaEntity.ID)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RequestScoped (javax.enterprise.context.RequestScoped)1 ObjectId (org.bson.types.ObjectId)1 Query (org.mongodb.morphia.query.Query)1