Search in sources :

Example 11 with CollectionPurpose

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

the class CollectionFacade method deleteCollectionAttribute.

public void deleteCollectionAttribute(final String collectionId, final String attributeId) {
    final Collection collection = collectionDao.getCollectionById(collectionId);
    final Collection originalCollection = collection.copy();
    permissionsChecker.checkRole(collection, RoleType.AttributeEdit);
    dataDao.deleteAttribute(collectionId, attributeId);
    collection.deleteAttribute(attributeId);
    if (collection.getDefaultAttributeId() != null && collection.getDefaultAttributeId().equals(attributeId)) {
        collection.setDefaultAttributeId(null);
    }
    final CollectionPurpose purpose = collection.getPurpose();
    if (attributeId.equals(purpose.getStateAttributeId())) {
        purpose.clearStateAttributeId();
    }
    if (attributeId.equals(purpose.getDueDateAttributeId())) {
        purpose.clearDueDateAttributeId();
    }
    if (attributeId.equals(purpose.getAssigneeAttributeId())) {
        purpose.clearAssigneeAttributeId();
    }
    if (attributeId.equals(purpose.getObserverAttributeId())) {
        purpose.clearObserverAttributeId();
        purpose.clearFinalStatesList();
    }
    collection.setLastTimeUsed(ZonedDateTime.now());
    mapResourceUpdateValues(collection);
    filterAutoLinkRulesByAttribute(collection, collectionId, attributeId);
    collectionDao.updateCollection(collection.getId(), collection, originalCollection);
    deleteAutoLinkRulesByAttribute(collectionId, attributeId);
    fileAttachmentFacade.removeAllFileAttachments(collectionId, attributeId, FileAttachment.AttachmentType.DOCUMENT);
}
Also used : Collection(io.lumeer.api.model.Collection) CollectionPurpose(io.lumeer.api.model.CollectionPurpose)

Example 12 with CollectionPurpose

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

the class DocumentFacadeIT method configureCollection.

@Before
public void configureCollection() {
    User user = new User(USER);
    this.user = userDao.createUser(user);
    Organization organization = new Organization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new Permissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    groupDao.setOrganization(storedOrganization);
    group = groupDao.createGroup(new Group(GROUP, Collections.singletonList(user.getId())));
    user.setOrganizations(Collections.singleton(storedOrganization.getId()));
    this.user = userDao.updateUser(user.getId(), user);
    Permissions organizationPermissions = new Permissions();
    Permission userPermission = Permission.buildWithRoles(this.user.getId(), Collections.singleton(new Role(RoleType.Read)));
    organizationPermissions.updateUserPermissions(userPermission);
    storedOrganization.setPermissions(organizationPermissions);
    organizationDao.updateOrganization(storedOrganization.getId(), storedOrganization);
    Project project = new Project();
    project.setCode(PROJECT_CODE);
    Permissions projectPermissions = new Permissions();
    projectPermissions.updateUserPermissions(userPermission);
    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.updateUserPermissions(new Permission(this.user.getId(), Collections.singleton(new Role(RoleType.Read))));
    Collection collection = new Collection("123456789", COLLECTION_NAME, COLLECTION_ICON, COLLECTION_COLOR, collectionPermissions);
    collection.setLastAttributeNum(0);
    this.collection = collectionDao.createCollection(collection);
    Collection taskCollection = new Collection("abcdefghi", COLLECTION_NAME + "_task", COLLECTION_ICON, COLLECTION_COLOR, collectionPermissions);
    DataDocument purposeMetadata = new DataDocument(CollectionPurpose.META_ASSIGNEE_ATTRIBUTE_ID, KEY1);
    CollectionPurpose taskPurpose = new CollectionPurpose(CollectionPurposeType.Tasks, purposeMetadata);
    taskCollection.setPurpose(taskPurpose);
    taskCollection.setLastAttributeNum(0);
    taskCollection.setAttributes(Collections.singleton(new Attribute(KEY1)));
    this.taskCollection = collectionDao.createCollection(taskCollection);
    permissionsChecker.getPermissionAdapter().invalidateUserCache();
}
Also used : Role(io.lumeer.api.model.Role) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) 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) 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)

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