Search in sources :

Example 1 with CollectionPurpose

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

the class DelayedActionIT method configureCollection.

@Before
public void configureCollection() {
    User user = new User(USER);
    setUserNotifications(user);
    this.user = userDao.createUser(user);
    User user2 = new User(USER2);
    setUserNotifications(user2);
    this.user2 = userDao.createUser(user2);
    Organization organization = new Organization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new Permissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    organizationId = storedOrganization.getId();
    projectDao.setOrganization(storedOrganization);
    Permissions organizationPermissions = new Permissions();
    Permission userPermission = Permission.buildWithRoles(this.user.getId(), Organization.ROLES);
    Permission user2Permission = Permission.buildWithRoles(this.user2.getId(), Organization.ROLES);
    organizationPermissions.addUserPermissions(Set.of(userPermission, user2Permission));
    storedOrganization.setPermissions(organizationPermissions);
    organizationDao.updateOrganization(storedOrganization.getId(), storedOrganization);
    Project project = new Project();
    project.setCode(PROJECT_CODE);
    Permissions projectPermissions = new Permissions();
    projectPermissions.addUserPermissions(Set.of(new Permission(this.user.getId(), Project.ROLES), new Permission(this.user2.getId(), Project.ROLES)));
    project.setPermissions(projectPermissions);
    Project storedProject = projectDao.createProject(project);
    workspaceKeeper.setWorkspaceIds(storedOrganization.getId(), storedProject.getId());
    collectionDao.setProject(storedProject);
    collectionDao.createRepository(storedProject);
    Permissions collectionPermissions = new Permissions();
    collectionPermissions.addUserPermissions(Set.of(new Permission(this.user.getId(), Project.ROLES), new Permission(this.user2.getId(), Project.ROLES)));
    Collection jsonCollection = new Collection(null, COLLECTION_NAME, COLLECTION_ICON, COLLECTION_COLOR, collectionPermissions);
    jsonCollection.setLastAttributeNum(0);
    jsonCollection.setAttributes(List.of(new Attribute("a0", "Summary", null, new Constraint(ConstraintType.Text, null), null, null, 0, null), new Attribute("a1", "Assignee", null, new Constraint(ConstraintType.User, new org.bson.Document("multi", true).append("externalUsers", true)), null, null, 0, null), new Attribute("a2", "Due date", null, new Constraint(ConstraintType.DateTime, new org.bson.Document("format", "DD/MM/YYYY H:mm:ss")), null, null, 0, null), new Attribute("a3", "State", null, new Constraint(ConstraintType.Select, new org.bson.Document("options", List.of(new org.bson.Document("value", "New").append("displayValue", ""), new org.bson.Document("value", "In Progress").append("displayValue", ""), new org.bson.Document("value", "To Do").append("displayValue", ""), new org.bson.Document("value", "Done").append("displayValue", ""), new org.bson.Document("value", "Won't fix").append("displayValue", "")))), null, null, 0, null), new Attribute("a4", "Observers", null, new Constraint(ConstraintType.User, new org.bson.Document("multi", true).append("externalUsers", true)), null, null, 0, null), new Attribute("a5", "Something", null, null, null, null, 0, null)));
    jsonCollection.setDefaultAttributeId("a0");
    jsonCollection.setPurpose(new CollectionPurpose(CollectionPurposeType.Tasks, new DataDocument(CollectionPurpose.META_ASSIGNEE_ATTRIBUTE_ID, "a1").append(CollectionPurpose.META_DUE_DATE_ATTRIBUTE_ID, "a2").append(CollectionPurpose.META_STATE_ATTRIBUTE_ID, "a3").append(CollectionPurpose.META_FINAL_STATES_LIST, List.of("Done", "Won't fix")).append(CollectionPurpose.META_OBSERVERS_ATTRIBUTE_ID, "a4")));
    collection = collectionDao.createCollection(jsonCollection);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) Organization(io.lumeer.api.model.Organization) Attribute(io.lumeer.api.model.Attribute) Constraint(io.lumeer.api.model.Constraint) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) Project(io.lumeer.api.model.Project) Permissions(io.lumeer.api.model.Permissions) Permission(io.lumeer.api.model.Permission) Collection(io.lumeer.api.model.Collection) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) Before(org.junit.Before)

Example 2 with CollectionPurpose

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

the class SearchFacadeIT method createTaskCollectionWithAttributes.

private Collection createTaskCollectionWithAttributes(String name) {
    var options = Arrays.asList(new DataDocument("option", "a"), new DataDocument("option", "b"), new DataDocument("option", "c"), new DataDocument("option", "d"));
    Constraint stateConstraint = new Constraint(ConstraintType.Select, new DataDocument("multi", true).append("options", options));
    Attribute stateAttribute = new Attribute("a1", "a1", null, stateConstraint, null, null, 1, null);
    var stateAttributeId = stateAttribute.getId();
    Constraint assigneeConstraint = new Constraint(ConstraintType.User, new DataDocument());
    Attribute assigneeAttribute = new Attribute("a2", "a2", null, assigneeConstraint, null, null, 1, null);
    var assigneeAttributeId = assigneeAttribute.getId();
    var purposeMetadata = new DataDocument(CollectionPurpose.META_STATE_ATTRIBUTE_ID, stateAttributeId).append(CollectionPurpose.META_ASSIGNEE_ATTRIBUTE_ID, assigneeAttributeId).append(CollectionPurpose.META_FINAL_STATES_LIST, Arrays.asList("c", "d"));
    CollectionPurpose purpose = new CollectionPurpose(CollectionPurposeType.Tasks, purposeMetadata);
    Constraint numberConstraint = new Constraint(ConstraintType.Number, new DataDocument());
    Attribute otherAttribute = new Attribute("a3", "a3", null, numberConstraint, null, null, 3, null);
    return createTaskCollection(name, purpose, stateAttribute, assigneeAttribute, otherAttribute);
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) Constraint(io.lumeer.api.model.Constraint) Attribute(io.lumeer.api.model.Attribute) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Example 3 with CollectionPurpose

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

the class MongoCollectionDaoTest method prepareCollection.

private Collection prepareCollection(String code, String name) {
    Collection collection = new Collection(code, name, ICON, COLOR, "", null, new Permissions(PERMISSIONS), ATTRIBUTES, new HashMap<>(), "", new CollectionPurpose(CollectionPurposeType.None, null));
    collection.setLastTimeUsed(LAST_TIME_USED);
    return collection;
}
Also used : Permissions(io.lumeer.api.model.Permissions) Collection(io.lumeer.api.model.Collection) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Example 4 with CollectionPurpose

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

the class CollectionCreator method getCollection.

private Collection getCollection(final JSONObject o) {
    final Collection c = new Collection((String) o.get(Collection.CODE), (String) o.get(Collection.NAME), (String) o.get(Collection.ICON), (String) o.get(Collection.COLOR), null);
    c.setDataDescription((String) o.get(Collection.DATA_DESCRIPTION));
    final JSONObject purpose = (JSONObject) o.get(Collection.PURPOSE);
    if (purpose != null) {
        var purposeType = Utils.computeIfNotNull((String) purpose.get(CollectionPurpose.TYPE), CollectionPurposeType::valueOf);
        final JSONObject metaData = (JSONObject) purpose.get(CollectionPurpose.META_DATA);
        final DataDocument dataDocument = new DataDocument();
        if (metaData != null) {
            metaData.forEach((k, v) -> dataDocument.append(templateParser.translateConfig(k, constraintManager).toString(), templateParser.translateConfig(v, constraintManager)));
        }
        c.setPurpose(new CollectionPurpose(purposeType, dataDocument));
    }
    c.setPriority((Long) o.get(Collection.PRIORITY));
    return c;
}
Also used : DataDocument(io.lumeer.engine.api.data.DataDocument) JSONObject(org.json.simple.JSONObject) Collection(io.lumeer.api.model.Collection) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) CollectionPurposeType(io.lumeer.api.model.CollectionPurposeType)

Example 5 with CollectionPurpose

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

the class DueDateChangeDetector method detectChanges.

@Override
public void detectChanges(final DocumentEvent documentEvent, final Collection collection) {
    final CollectionPurpose purpose = collection.getPurpose();
    final String dueDateAttr = purpose.getDueDateAttributeId();
    if (StringUtils.isNotEmpty(dueDateAttr) && isAttributeChanged(documentEvent, dueDateAttr)) {
        if (!(documentEvent instanceof CreateDocument)) {
            // delete previous due date events on the document
            delayedActionDao.deleteScheduledActions(getResourcePath(documentEvent), Set.of(NotificationType.DUE_DATE_SOON, NotificationType.PAST_DUE_DATE, NotificationType.DUE_DATE_CHANGED));
        }
        if (!(documentEvent instanceof RemoveDocument) && !isDoneState(documentEvent, collection)) {
            // create new due date events on the document
            final ZonedDateTime dueDate = getDueDate(documentEvent, collection);
            final String assigneeAttr = purpose.getAssigneeAttributeId();
            // due date has changed - but it goes with the assignee change message, so send it only if the assignee did not change
            if (isAttributeChanged(documentEvent, dueDateAttr) && !isAttributeChanged(documentEvent, assigneeAttr)) {
                delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.DUE_DATE_CHANGED, nowPlus()));
            }
            // if it is not unset, then schedule past due and due date soon
            if (dueDate != null) {
                delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.PAST_DUE_DATE, dueDate));
                if (dueDate.minus(DUE_DATE_SOON_DAYS, ChronoUnit.DAYS).isAfter(ZonedDateTime.now())) {
                    delayedActionDao.scheduleActions(getDelayedActions(documentEvent, collection, NotificationType.DUE_DATE_SOON, dueDate.minus(DUE_DATE_SOON_DAYS, ChronoUnit.DAYS)));
                }
            }
        }
    }
}
Also used : RemoveDocument(io.lumeer.engine.api.event.RemoveDocument) ZonedDateTime(java.time.ZonedDateTime) CreateDocument(io.lumeer.engine.api.event.CreateDocument) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Aggregations

CollectionPurpose (io.lumeer.api.model.CollectionPurpose)12 Collection (io.lumeer.api.model.Collection)6 DataDocument (io.lumeer.engine.api.data.DataDocument)6 Attribute (io.lumeer.api.model.Attribute)4 CreateDocument (io.lumeer.engine.api.event.CreateDocument)4 RemoveDocument (io.lumeer.engine.api.event.RemoveDocument)4 Permissions (io.lumeer.api.model.Permissions)3 ZonedDateTime (java.time.ZonedDateTime)3 CollectionPurposeType (io.lumeer.api.model.CollectionPurposeType)2 Constraint (io.lumeer.api.model.Constraint)2 Organization (io.lumeer.api.model.Organization)2 Permission (io.lumeer.api.model.Permission)2 Project (io.lumeer.api.model.Project)2 User (io.lumeer.api.model.User)2 AuthenticatedUser (io.lumeer.core.auth.AuthenticatedUser)2 UpdateDocument (io.lumeer.engine.api.event.UpdateDocument)2 Document (org.bson.Document)2 Before (org.junit.Before)2 Document (io.lumeer.api.model.Document)1 Group (io.lumeer.api.model.Group)1