Search in sources :

Example 1 with Attribute

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

the class SuggestionFacade method keepOnlyMatchingAttributes.

private static List<Collection> keepOnlyMatchingAttributes(List<Collection> collections, String text) {
    for (Collection collection : collections) {
        Set<Attribute> attributes = collection.getAttributes().stream().filter(a -> a.getName().toLowerCase().contains(text)).collect(Collectors.toSet());
        collection.setAttributes(attributes);
    }
    return collections;
}
Also used : View(io.lumeer.api.model.View) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) Set(java.util.Set) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Collectors(java.util.stream.Collectors) LinkType(io.lumeer.api.model.LinkType) SuggestionType(io.lumeer.api.model.SuggestionType) Inject(javax.inject.Inject) List(java.util.List) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) ViewDao(io.lumeer.storage.api.dao.ViewDao) RequestScoped(javax.enterprise.context.RequestScoped) SuggestionQuery(io.lumeer.storage.api.query.SuggestionQuery) Attribute(io.lumeer.api.model.Attribute) JsonSuggestions(io.lumeer.api.dto.JsonSuggestions) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Attribute(io.lumeer.api.model.Attribute) Collection(io.lumeer.api.model.Collection)

Example 2 with Attribute

use of io.lumeer.api.model.Attribute 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 3 with Attribute

use of io.lumeer.api.model.Attribute 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 Attribute

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

the class CollectionServiceIT method testDeleteCollectionAttribute.

@Test
public void testDeleteCollectionAttribute() {
    Collection collection = createCollection(CODE);
    assertThat(collection.getAttributes()).hasSize(1);
    Response response = client.target(COLLECTIONS_URL).path(collection.getId()).path("attributes").path(ATTRIBUTE_FULLNAME).request(MediaType.APPLICATION_JSON).buildDelete().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Collection storedCollection = collectionDao.getCollectionByCode(CODE);
    Set<Attribute> storedAttributes = storedCollection.getAttributes();
    assertThat(storedAttributes).isEmpty();
}
Also used : Response(javax.ws.rs.core.Response) JsonAttribute(io.lumeer.api.dto.JsonAttribute) Attribute(io.lumeer.api.model.Attribute) JsonCollection(io.lumeer.api.dto.JsonCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 5 with Attribute

use of io.lumeer.api.model.Attribute 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

Attribute (io.lumeer.api.model.Attribute)7 JsonAttribute (io.lumeer.api.dto.JsonAttribute)6 Collection (io.lumeer.api.model.Collection)6 JsonCollection (io.lumeer.api.dto.JsonCollection)4 Test (org.junit.Test)4 SoftAssertions (org.assertj.core.api.SoftAssertions)3 CollectionDao (io.lumeer.storage.api.dao.CollectionDao)2 SearchQuery (io.lumeer.storage.api.query.SearchQuery)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 RequestScoped (javax.enterprise.context.RequestScoped)2 Inject (javax.inject.Inject)2 Response (javax.ws.rs.core.Response)2 JsonSuggestions (io.lumeer.api.dto.JsonSuggestions)1 Document (io.lumeer.api.model.Document)1 LinkType (io.lumeer.api.model.LinkType)1 Pagination (io.lumeer.api.model.Pagination)1