Search in sources :

Example 16 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class SearchFacadeIT method testSearchDocumentsByCombination.

@Test
public void testSearchDocumentsByCombination() {
    createDocument(collectionIds.get(0), "word");
    createDocument(collectionIds.get(0), "fulltext");
    createDocument(collectionIds.get(1), "something fulltext");
    createDocument(collectionIds.get(1), "some other word anything");
    createDocument(collectionIds.get(2), "full word");
    createDocument(collectionIds.get(2), "anything");
    List<Document> documents = searchFacade.searchDocuments(new JsonQuery(null, Collections.singleton(collectionIds.get(0)), null, null, "anything", null, null));
    assertThat(documents).extracting(Document::getId).isEmpty();
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) Test(org.junit.Test)

Example 17 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class DocumentServiceIT method createDocument.

private Document createDocument() {
    Document document = prepareDocument();
    document.setCollectionId(collection.getId());
    document.setCreatedBy(USER);
    document.setCreationDate(LocalDateTime.now());
    document.setDataVersion(DocumentFacade.INITIAL_VERSION);
    Document storedDocument = documentDao.createDocument(document);
    DataDocument storedData = dataDao.createData(collection.getId(), storedDocument.getId(), document.getData());
    storedDocument.setData(storedData);
    return storedDocument;
}
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)

Example 18 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class DocumentFacade method updateDocumentData.

public Document updateDocumentData(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());
    Set<String> attributesToDec = new HashSet<>(oldData.keySet());
    attributesToDec.removeAll(data.keySet());
    updateCollectionMetadata(collection, attributesToAdd, attributesToDec, 0);
    // TODO archive the old document
    DataDocument updatedData = dataDao.updateData(collection.getId(), documentId, data);
    Document updatedDocument = updateDocument(collection, documentId);
    updatedDocument.setData(updatedData);
    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 19 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class DocumentService method createDocument.

@POST
public Response createDocument(JsonDocument document) {
    Document storedDocument = documentFacade.createDocument(collectionId, document);
    URI resourceUri = getResourceUri(storedDocument.getId());
    return Response.created(resourceUri).build();
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) URI(java.net.URI) POST(javax.ws.rs.POST)

Example 20 with Document

use of io.lumeer.api.model.Document in project engine by Lumeer.

the class DocumentService method getDocuments.

@GET
public List<JsonDocument> getDocuments(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize) {
    Pagination pagination = new Pagination(page, pageSize);
    List<Document> documents = documentFacade.getDocuments(collectionId, pagination);
    return JsonDocument.convert(documents);
}
Also used : Pagination(io.lumeer.api.model.Pagination) DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument) Document(io.lumeer.api.model.Document) GET(javax.ws.rs.GET)

Aggregations

Document (io.lumeer.api.model.Document)32 DataDocument (io.lumeer.engine.api.data.DataDocument)31 JsonDocument (io.lumeer.api.dto.JsonDocument)21 Test (org.junit.Test)18 SoftAssertions (org.assertj.core.api.SoftAssertions)10 Collection (io.lumeer.api.model.Collection)7 LocalDateTime (java.time.LocalDateTime)7 MorphiaDocument (io.lumeer.storage.mongodb.model.MorphiaDocument)6 JsonQuery (io.lumeer.api.dto.JsonQuery)5 HashSet (java.util.HashSet)4 ObjectId (org.bson.types.ObjectId)4 JsonCollection (io.lumeer.api.dto.JsonCollection)3 Entity (javax.ws.rs.client.Entity)3 Response (javax.ws.rs.core.Response)3 Pagination (io.lumeer.api.model.Pagination)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 WriteResult (com.mongodb.WriteResult)1 CsvParser (com.univocity.parsers.csv.CsvParser)1 CsvParserSettings (com.univocity.parsers.csv.CsvParserSettings)1