use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class CollectionFacadeIT method testDurationAttributeConversion.
@Test
public void testDurationAttributeConversion() {
Collection collection = collectionFacade.createCollection(prepareCollection(CODE3));
collectionFacade.createCollectionAttributes(collection.getId(), Arrays.asList(new Attribute("a1", "Task", null, null, null, null, 0, null), new Attribute("a2", ATTRIBUTE_STATE, null, null, null, null, 0, null)));
// 100800000, 77700000, 86466000, 1345, 1434534000, 10806000, 14580000
// 3d4h, 2d5h35m, 3d1m6s, 1s, 9w4d6h28m54s, 3h6s, 4h3m
var values = Arrays.asList("3d4h", "14h455m", "3d66s", "1345", "1434534s", "3h6s", "0d3m4h0s");
var rnd = new Random();
var i = new AtomicInteger(1);
values.forEach(value -> {
documentFacade.createDocument(collection.getId(), new Document(new DataDocument("a1", "Task-" + i.getAndIncrement()).append("a2", value)));
});
var attributes = collectionFacade.getCollection(collection.getId()).getAttributes();
var attr = attributes.stream().filter(attribute -> attribute.getName().equals(ATTRIBUTE_STATE)).findFirst().get();
attr.setConstraint(new Constraint(ConstraintType.Duration, new org.bson.Document("type", "Work").append("conversions", new org.bson.Document("w", 5).append("d", 8).append("h", 60).append("m", 60).append("s", 1000))));
collectionFacade.updateCollectionAttribute(collection.getId(), attr.getId(), attr);
var documents = documentDao.getDocumentsByCollection(collection.getId());
Map<String, Long> res = new HashMap<>();
documents.forEach(document -> {
var doc = documentFacade.getDocument(collection.getId(), document.getId());
res.put(doc.getData().getString("a1"), doc.getData().getLong("a2"));
});
assertThat(res).contains(Map.entry("Task-1", 100800000L), Map.entry("Task-2", 77700000L), Map.entry("Task-3", 86466000L), Map.entry("Task-4", 1345L), Map.entry("Task-5", 1434534000L), Map.entry("Task-6", 10806000L), Map.entry("Task-7", 14580000L));
// now back to no constraint
var attr2 = attributes.stream().filter(attribute -> attribute.getName().equals(ATTRIBUTE_STATE)).findFirst().get();
attr2.setConstraint(new Constraint(ConstraintType.None, null));
collectionFacade.updateCollectionAttribute(collection.getId(), attr2.getId(), attr2);
documents = documentDao.getDocumentsByCollection(collection.getId());
Map<String, String> res2 = new HashMap<>();
documents.forEach(document -> {
var doc = documentFacade.getDocument(collection.getId(), document.getId());
res2.put(doc.getData().getString("a1"), doc.getData().getString("a2"));
});
assertThat(res2).contains(Map.entry("Task-1", "3d4h"), Map.entry("Task-2", "2d5h35m"), Map.entry("Task-3", "3d1m6s"), Map.entry("Task-4", "1s"), Map.entry("Task-5", "9w4d6h28m54s"), Map.entry("Task-6", "3h6s"), Map.entry("Task-7", "4h3m"));
// custom unit lengths
var attr3 = attributes.stream().filter(attribute -> attribute.getName().equals(ATTRIBUTE_STATE)).findFirst().get();
attr3.setConstraint(new Constraint(ConstraintType.Duration, new org.bson.Document("type", "Custom").append("conversions", new org.bson.Document("w", 5).append("d", 5).append("h", 30).append("m", 60).append("s", 1000))));
collectionFacade.updateCollectionAttribute(collection.getId(), attr3.getId(), attr3);
documents = documentDao.getDocumentsByCollection(collection.getId());
Map<String, Long> res3 = new HashMap<>();
documents.forEach(document -> {
var doc = documentFacade.getDocument(collection.getId(), document.getId());
res3.put(doc.getData().getString("a1"), doc.getData().getLong("a2"));
});
assertThat(res3).contains(Map.entry("Task-1", 34200000L), Map.entry("Task-2", 29100000L), Map.entry("Task-3", 27066000L), Map.entry("Task-4", 1000L), Map.entry("Task-5", 453534000L), Map.entry("Task-6", 5406000L), Map.entry("Task-7", 7380000L));
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class SearchFacadeIT method testSearchDocumentsCoordinatesConstraint.
@Test
public void testSearchDocumentsCoordinatesConstraint() {
Constraint constraint = new Constraint(ConstraintType.Coordinates, new DataDocument());
Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
String collectionId = createCollection("coordinatesCollection", attribute).getId();
String id1 = createDocument(collectionId, "40.123°N 74.123°W").getId();
String id2 = createDocument(collectionId, "45.123°N 74.123°W").getId();
String id3 = createDocument(collectionId, "60.123°N 74.123°W").getId();
Query query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.EQUALS, "40.123, -74.123"));
List<Document> documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1);
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class SearchFacadeIT method testSearchContributors.
@Test
public void testSearchContributors() {
Constraint constraint = new Constraint(ConstraintType.Number, new DataDocument());
Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
Collection collection = createCollection("numberCollection", attribute);
setCollectionUserRoles(collection, Set.of(new Role(RoleType.Read)));
String id1 = createDocument(collection.getId(), "10").getId();
String id2 = createDocumentWithOtherUser(collection.getId(), "20").getId();
String id3 = createDocument(collection.getId(), "30").getId();
String id4 = createDocumentWithOtherUser(collection.getId(), 40).getId();
String id5 = createDocument(collection.getId(), "50").getId();
String id6 = createDocumentWithOtherUser(collection.getId(), "60").getId();
String id7 = createDocumentWithOtherUser(collection.getId(), 70).getId();
String id8 = createDocument(collection.getId(), 80).getId();
Query query = new Query();
List<Document> documents = searchFacade.searchDocumentsAndLinks(query, true).getFirst();
assertThat(documents).extracting(Document::getId).isEmpty();
// contributor
setCollectionUserRoles(collection, Set.of(new Role(RoleType.Read), new Role(RoleType.DataContribute)));
documents = searchFacade.searchDocumentsAndLinks(query, true).getFirst();
assertThat(documents).extracting(Document::getId).containsOnly(id1, id3, id5, id8);
// read all data
setCollectionUserRoles(collection, Set.of(new Role(RoleType.Read), new Role(RoleType.DataRead)));
documents = searchFacade.searchDocumentsAndLinks(query, true).getFirst();
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3, id4, id5, id6, id7, id8);
// contributor with filters
setCollectionUserRoles(collection, Set.of(new Role(RoleType.Read), new Role(RoleType.DataContribute)));
query = createSimpleQueryWithAttributeFilter(collection.getId(), CollectionAttributeFilter.createFromValues(collection.getId(), DOCUMENT_KEY, ConditionType.LOWER_THAN, "40"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id3);
query = createSimpleQueryWithAttributeFilter(collection.getId(), CollectionAttributeFilter.createFromValues(collection.getId(), DOCUMENT_KEY, ConditionType.GREATER_THAN, "40"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id5, id8);
// reader with filters
setCollectionUserRoles(collection, Set.of(new Role(RoleType.Read), new Role(RoleType.DataRead)));
query = createSimpleQueryWithAttributeFilter(collection.getId(), CollectionAttributeFilter.createFromValues(collection.getId(), DOCUMENT_KEY, ConditionType.LOWER_THAN, "40"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3);
query = createSimpleQueryWithAttributeFilter(collection.getId(), CollectionAttributeFilter.createFromValues(collection.getId(), DOCUMENT_KEY, ConditionType.GREATER_THAN, "40"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id5, id6, id7, id8);
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class SearchFacadeIT method testSearchDocumentsByNumberConstraint.
@Test
public void testSearchDocumentsByNumberConstraint() {
Constraint constraint = new Constraint(ConstraintType.Number, new DataDocument());
Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
String collectionId = createCollection("numberCollection", attribute).getId();
String id1 = createDocument(collectionId, "20.3").getId();
String id2 = createDocument(collectionId, "40.1").getId();
String id3 = createDocument(collectionId, "60").getId();
String id4 = createDocument(collectionId, 80).getId();
String id5 = createDocument(collectionId, "100.2").getId();
String id6 = createDocument(collectionId, "-30.123").getId();
Query query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.EQUALS, 40.1));
List<Document> documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id2);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.NOT_EQUALS, "60"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id4, id5, id6);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.LOWER_THAN, "40.1"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id6);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.LOWER_THAN_EQUALS, "40.1"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id6);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.BETWEEN, "20", 41));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.NOT_BETWEEN, "20", 41));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id3, id4, id5, id6);
}
use of io.lumeer.api.model.Constraint in project engine by Lumeer.
the class SearchFacadeIT method testSearchDocumentsDateConstraint.
@Test
public void testSearchDocumentsDateConstraint() {
Constraint constraint = new Constraint(ConstraintType.DateTime, new DataDocument());
Attribute attribute = new Attribute(DOCUMENT_KEY, DOCUMENT_KEY, null, constraint, null, null, 3, null);
String collectionId = createCollection("dateCollection", attribute).getId();
String id1 = createDocument(collectionId, "2019-04-01T00:00:00.000Z").getId();
String id2 = createDocument(collectionId, "2019-04-02T00:00:00.000Z").getId();
String id3 = createDocument(collectionId, "2019-04-03T00:00:00.000Z").getId();
String id4 = createDocument(collectionId, "2019-04-04T00:00:00.000Z").getId();
String id5 = createDocument(collectionId, "2019-04-04T00:00:00.000Z").getId();
String id6 = createDocument(collectionId, "2019-04-05T00:00:00.000Z").getId();
Query query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.EQUALS, "2019-04-04T00:00:00.000Z"));
List<Document> documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id4, id5);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.NOT_EQUALS, "2019-04-04T00:00:00.000Z"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3, id6);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.GREATER_THAN, "2019-04-04T00:00:00.000Z"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id6);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.LOWER_THAN, "2019-04-04T00:00:00.000Z"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.LOWER_THAN_EQUALS, "2019-04-04T00:00:00.000Z"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3, id4, id5);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.LOWER_THAN_EQUALS, "2019-04-04T00:00:00.000Z"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1, id2, id3, id4, id5);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.BETWEEN, "2019-04-02T00:00:00.000Z", "2019-04-08T00:00:00.000Z"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id2, id3, id4, id5, id6);
query = createSimpleQueryWithAttributeFilter(collectionId, CollectionAttributeFilter.createFromValues(collectionId, DOCUMENT_KEY, ConditionType.NOT_BETWEEN, "2019-04-02T00:00:00.000Z", "2019-04-08T00:00:00.000Z"));
documents = searchFacade.searchDocuments(query, true);
assertThat(documents).extracting(Document::getId).containsOnly(id1);
}
Aggregations