Search in sources :

Example 1 with JsonDocument

use of io.lumeer.api.dto.JsonDocument in project engine by Lumeer.

the class SearchFacadeIT method createDocument.

private Document createDocument(String collectionId, Object value) {
    Document document = new JsonDocument(new DataDocument(DOCUMENT_KEY, value));
    document.setCollectionId(collectionId);
    document.setCreatedBy(USER);
    document.setCreationDate(LocalDateTime.now());
    document.setDataVersion(DocumentFacade.INITIAL_VERSION);
    Document storedDocument = documentDao.createDocument(document);
    DataDocument storedData = dataDao.createData(collectionId, 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) JsonDocument(io.lumeer.api.dto.JsonDocument)

Example 2 with JsonDocument

use of io.lumeer.api.dto.JsonDocument in project engine by Lumeer.

the class DocumentServiceIT method testGetDocument.

@Test
@Ignore("Works manually but there is unexpected exception in tests")
public void testGetDocument() {
    String id = createDocument().getId();
    Response response = client.target(DOCUMENTS_URL_PREFIX).path(collection.getId()).path("documents").path(id).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    JsonDocument document = response.readEntity(JsonDocument.class);
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(document.getId()).isEqualTo(id);
    assertions.assertThat(document.getCollectionId()).isNull();
    assertions.assertThat(document.getCreatedBy()).isEqualTo(USER);
    assertions.assertThat(document.getCreationDate()).isBeforeOrEqualTo(LocalDateTime.now());
    assertions.assertThat(document.getUpdatedBy()).isNull();
    assertions.assertThat(document.getUpdateDate()).isNull();
    assertions.assertThat(document.getDataVersion()).isEqualTo(1);
    assertions.assertAll();
    DataDocument data = document.getData();
    assertThat(data).isNotNull();
    assertThat(data).containsEntry(KEY1, VALUE1);
    assertThat(data).containsEntry(KEY2, VALUE2);
}
Also used : Response(javax.ws.rs.core.Response) DataDocument(io.lumeer.engine.api.data.DataDocument) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonDocument(io.lumeer.api.dto.JsonDocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with JsonDocument

use of io.lumeer.api.dto.JsonDocument in project engine by Lumeer.

the class ImportFacade method createDocumentFromRow.

private Document createDocumentFromRow(String[] headers, String[] row, int[] counts) {
    final DataDocument d = new DataDocument();
    for (int i = 0; i < Math.min(headers.length, row.length); i++) {
        if (row[i] != null) {
            d.append(headers[i], row[i]);
            counts[i]++;
        }
    }
    return new JsonDocument(d);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) JsonDocument(io.lumeer.api.dto.JsonDocument)

Example 4 with JsonDocument

use of io.lumeer.api.dto.JsonDocument 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 5 with JsonDocument

use of io.lumeer.api.dto.JsonDocument 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

JsonDocument (io.lumeer.api.dto.JsonDocument)6 DataDocument (io.lumeer.engine.api.data.DataDocument)5 Document (io.lumeer.api.model.Document)3 Response (javax.ws.rs.core.Response)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 Pagination (io.lumeer.api.model.Pagination)1 URI (java.net.URI)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 SoftAssertions (org.assertj.core.api.SoftAssertions)1