Search in sources :

Example 1 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class DocumentFacade method getDocument.

public Document getDocument(String collectionId, String documentId) {
    Collection collection = collectionDao.getCollectionById(collectionId);
    permissionsChecker.checkRole(collection, Role.READ);
    Document document = documentDao.getDocumentById(documentId);
    DataDocument data = dataDao.getData(collection.getId(), documentId);
    document.setData(data);
    return document;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document)

Example 2 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class DocumentFacade method createDocument.

public Document createDocument(String collectionId, Document document) {
    Collection collection = collectionDao.getCollectionById(collectionId);
    permissionsChecker.checkRole(collection, Role.WRITE);
    DataDocument data = DocumentUtils.checkDocumentKeysValidity(document.getData());
    Document storedDocument = createDocument(collection, document);
    DataDocument storedData = dataDao.createData(collection.getId(), storedDocument.getId(), data);
    storedDocument.setData(storedData);
    updateCollectionMetadata(collection, data.keySet(), Collections.emptySet(), 1);
    return storedDocument;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document)

Example 3 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class DocumentFacade method patchDocumentData.

public Document patchDocumentData(String collectionId, String documentId, DataDocument data) {
    Collection collection = collectionDao.getCollectionById(collectionId);
    permissionsChecker.checkRole(collection, Role.WRITE);
    DataDocument oldData = dataDao.getData(collectionId, documentId);
    Set<String> attributesToAdd = new HashSet<>(data.keySet());
    attributesToAdd.removeAll(oldData.keySet());
    updateCollectionMetadata(collection, attributesToAdd, Collections.emptySet(), 0);
    // TODO archive the old document
    DataDocument patchedData = dataDao.patchData(collection.getId(), documentId, data);
    Document updatedDocument = updateDocument(collection, documentId);
    updatedDocument.setData(patchedData);
    return updatedDocument;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class ImportFacade method addDocumentsToDb.

private void addDocumentsToDb(String collectionId, List<Document> documents) {
    List<Document> storedDocuments = documentDao.createDocuments(documents);
    List<DataDocument> dataDocuments = new LinkedList<>();
    for (int i = 0; i < documents.size(); i++) {
        DataDocument dataDocument = documents.get(i).getData();
        dataDocument.setId(storedDocuments.get(i).getId());
        dataDocuments.add(dataDocument);
    }
    dataDao.createData(collectionId, dataDocuments);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) LinkedList(java.util.LinkedList)

Example 5 with DataDocument

use of io.lumeer.engine.api.data.DataDocument in project engine by Lumeer.

the class DocumentUtils method checkDocumentKeysValidity.

public static DataDocument checkDocumentKeysValidity(DataDocument dataDocument) throws InvalidDocumentKeyException {
    DataDocument ndd = new DataDocument();
    for (Map.Entry<String, Object> entry : dataDocument.entrySet()) {
        String attributeName = entry.getKey().trim();
        if (!isAttributeNameValid(attributeName)) {
            throw new InvalidDocumentKeyException(attributeName);
        }
        Object value = entry.getValue();
        if (isDataDocument(value)) {
            ndd.put(attributeName, checkDocumentKeysValidity((DataDocument) value));
        } else if (isList(value)) {
            List l = (List) entry.getValue();
            if (!l.isEmpty() && isDataDocument(l.get(0))) {
                ArrayList<DataDocument> docs = new ArrayList<>();
                ndd.put(attributeName, docs);
                for (Object o : l) {
                    docs.add(checkDocumentKeysValidity((DataDocument) o));
                }
            } else {
                ndd.put(attributeName, l);
            }
        } else {
            ndd.put(attributeName, value);
        }
    }
    return ndd;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) InvalidDocumentKeyException(io.lumeer.engine.api.exception.InvalidDocumentKeyException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

DataDocument (io.lumeer.engine.api.data.DataDocument)75 Test (org.junit.Test)42 Collection (io.lumeer.api.model.Collection)16 Document (io.lumeer.api.model.Document)16 JsonDocument (io.lumeer.api.dto.JsonDocument)14 Document (org.bson.Document)13 SoftAssertions (org.assertj.core.api.SoftAssertions)10 ReturnDocument (com.mongodb.client.model.ReturnDocument)9 JsonCollection (io.lumeer.api.dto.JsonCollection)9 DataFilter (io.lumeer.engine.api.data.DataFilter)9 ImportedCollection (io.lumeer.api.model.ImportedCollection)6 SearchQuery (io.lumeer.storage.api.query.SearchQuery)6 LocalDateTime (java.time.LocalDateTime)6 BsonDocument (org.bson.BsonDocument)6 LinkedList (java.util.LinkedList)5 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Response (javax.ws.rs.core.Response)4 DataStorageStats (io.lumeer.engine.api.data.DataStorageStats)3