Search in sources :

Example 1 with JsonAttribute

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

the class ImportFacade method addCollectionMetadata.

private void addCollectionMetadata(Collection collection, String[] headers, int[] counts, int documentsCount) {
    Set<Attribute> attributes = new HashSet<>();
    for (int i = 0; i < headers.length; i++) {
        attributes.add(new JsonAttribute(headers[i], headers[i], Collections.emptySet(), counts[i]));
    }
    collection.setAttributes(attributes);
    collection.setDocumentsCount(documentsCount);
    collection.setLastTimeUsed(LocalDateTime.now());
    collectionDao.updateCollection(collection.getId(), collection);
}
Also used : JsonAttribute(io.lumeer.api.dto.JsonAttribute) Attribute(io.lumeer.api.model.Attribute) JsonAttribute(io.lumeer.api.dto.JsonAttribute) HashSet(java.util.HashSet)

Example 2 with JsonAttribute

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

the class CollectionFacadeIT method testDeleteCollectionAttribute.

@Test
public void testDeleteCollectionAttribute() {
    JsonAttribute attribute = new JsonAttribute(ATTRIBUTE_NAME, ATTRIBUTE_FULLNAME, ATTRIBUTE_CONSTRAINTS, ATTRIBUTE_COUNT);
    Collection collection = createCollection(CODE, attribute);
    assertThat(collection.getAttributes()).isNotEmpty();
    collectionFacade.deleteCollectionAttribute(collection.getId(), ATTRIBUTE_FULLNAME);
    collection = collectionDao.getCollectionByCode(CODE);
    assertThat(collection).isNotNull();
    assertThat(collection.getAttributes()).isEmpty();
}
Also used : JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Test(org.junit.Test)

Example 3 with JsonAttribute

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

the class CollectionFacadeIT method testUpdateCollectionAttributeUpdate.

@Test
public void testUpdateCollectionAttributeUpdate() {
    JsonAttribute attribute = new JsonAttribute(ATTRIBUTE_NAME, ATTRIBUTE_FULLNAME, ATTRIBUTE_CONSTRAINTS, ATTRIBUTE_COUNT);
    Collection collection = createCollection(CODE, attribute);
    assertThat(collection.getAttributes()).isNotEmpty();
    JsonAttribute updatedAttribute = new JsonAttribute(ATTRIBUTE_NAME, ATTRIBUTE_FULLNAME2, ATTRIBUTE_CONSTRAINTS, ATTRIBUTE_COUNT);
    collectionFacade.updateCollectionAttribute(collection.getId(), ATTRIBUTE_FULLNAME, updatedAttribute);
    collection = collectionDao.getCollectionByCode(CODE);
    assertThat(collection).isNotNull();
    assertThat(collection.getAttributes()).hasSize(1);
    Attribute storedAttribute = collection.getAttributes().iterator().next();
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(storedAttribute.getName()).isEqualTo(ATTRIBUTE_NAME);
    assertions.assertThat(storedAttribute.getFullName()).isEqualTo(ATTRIBUTE_FULLNAME2);
    assertions.assertThat(storedAttribute.getConstraints()).isEqualTo(ATTRIBUTE_CONSTRAINTS);
    assertions.assertThat(storedAttribute.getUsageCount()).isEqualTo(ATTRIBUTE_COUNT);
    assertions.assertAll();
}
Also used : JsonAttribute(io.lumeer.api.dto.JsonAttribute) Attribute(io.lumeer.api.model.Attribute) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Test(org.junit.Test)

Example 4 with JsonAttribute

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

the class CollectionServiceIT method testGetCollectionAttributes.

@Test
public void testGetCollectionAttributes() {
    Collection collection = createCollection(CODE);
    assertThat(collection.getAttributes()).hasSize(1);
    Response response = client.target(COLLECTIONS_URL).path(collection.getId()).path("attributes").request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonAttribute> attributes = response.readEntity(new GenericType<List<JsonAttribute>>() {
    });
    assertThat(attributes).hasSize(1);
    JsonAttribute attribute = attributes.get(0);
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(attribute.getName()).isEqualTo(ATTRIBUTE_NAME);
    assertions.assertThat(attribute.getFullName()).isEqualTo(ATTRIBUTE_FULLNAME);
    assertions.assertThat(attribute.getConstraints()).isEqualTo(ATTRIBUTE_CONSTRAINTS);
    assertions.assertThat(attribute.getUsageCount()).isEqualTo(ATTRIBUTE_COUNT);
    assertions.assertAll();
}
Also used : Response(javax.ws.rs.core.Response) SoftAssertions(org.assertj.core.api.SoftAssertions) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) List(java.util.List) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Test(org.junit.Test)

Example 5 with JsonAttribute

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

the class DocumentFacade method updateCollectionMetadata.

private void updateCollectionMetadata(Collection collection, Set<String> attributesToInc, Set<String> attributesToDec, int documentCountDiff) {
    Map<String, Attribute> oldAttributes = collection.getAttributes().stream().collect(Collectors.toMap(Attribute::getFullName, Function.identity()));
    oldAttributes.keySet().forEach(attributeName -> {
        if (attributesToInc.contains(attributeName)) {
            Attribute attribute = oldAttributes.get(attributeName);
            attribute.setUsageCount(attribute.getUsageCount() + 1);
            attributesToInc.remove(attributeName);
        } else if (attributesToDec.contains(attributeName)) {
            Attribute attribute = oldAttributes.get(attributeName);
            attribute.setUsageCount(Math.max(attribute.getUsageCount() - 1, 0));
        }
    });
    Set<Attribute> newAttributes = attributesToInc.stream().map(attributeName -> new JsonAttribute(extractAttributeName(attributeName), attributeName, Collections.emptySet(), 1)).collect(Collectors.toSet());
    newAttributes.addAll(oldAttributes.values());
    collection.setAttributes(newAttributes);
    collection.setLastTimeUsed(LocalDateTime.now());
    collection.setDocumentsCount(collection.getDocumentsCount() + documentCountDiff);
    collectionDao.updateCollection(collection.getId(), collection);
}
Also used : DocumentDao(io.lumeer.storage.api.dao.DocumentDao) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) LocalDateTime(java.time.LocalDateTime) Set(java.util.Set) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) DocumentUtils(io.lumeer.core.util.DocumentUtils) HashSet(java.util.HashSet) Inject(javax.inject.Inject) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) List(java.util.List) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Role(io.lumeer.api.model.Role) DataDao(io.lumeer.storage.api.dao.DataDao) JsonAttribute(io.lumeer.api.dto.JsonAttribute) RequestScoped(javax.enterprise.context.RequestScoped) Map(java.util.Map) Attribute(io.lumeer.api.model.Attribute) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Pagination(io.lumeer.api.model.Pagination) LinkedHashSet(java.util.LinkedHashSet) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Attribute(io.lumeer.api.model.Attribute) JsonAttribute(io.lumeer.api.dto.JsonAttribute)

Aggregations

JsonAttribute (io.lumeer.api.dto.JsonAttribute)8 Collection (io.lumeer.api.model.Collection)6 JsonCollection (io.lumeer.api.dto.JsonCollection)5 Attribute (io.lumeer.api.model.Attribute)5 Test (org.junit.Test)5 SoftAssertions (org.assertj.core.api.SoftAssertions)4 HashSet (java.util.HashSet)2 List (java.util.List)2 Response (javax.ws.rs.core.Response)2 Document (io.lumeer.api.model.Document)1 LinkType (io.lumeer.api.model.LinkType)1 Pagination (io.lumeer.api.model.Pagination)1 Role (io.lumeer.api.model.Role)1 DocumentUtils (io.lumeer.core.util.DocumentUtils)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 CollectionDao (io.lumeer.storage.api.dao.CollectionDao)1 DataDao (io.lumeer.storage.api.dao.DataDao)1 DocumentDao (io.lumeer.storage.api.dao.DocumentDao)1 LinkInstanceDao (io.lumeer.storage.api.dao.LinkInstanceDao)1 SearchQuery (io.lumeer.storage.api.query.SearchQuery)1