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;
}
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);
}
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();
}
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();
}
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);
}
Aggregations