Search in sources :

Example 11 with Resource

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

the class PermissionsCheckerTest method prepareResource.

private Resource prepareResource(Set<Role> userRoles, Set<Role> groupRoles) {
    Resource resource = Mockito.mock(Resource.class);
    preparePermissions(resource, userRoles, groupRoles);
    Mockito.when(resource.getType()).thenReturn(ResourceType.PROJECT);
    return resource;
}
Also used : Resource(io.lumeer.api.model.common.Resource)

Example 12 with Resource

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

the class PermissionsCheckerTest method testCheckDifferentRole.

@Test
public void testCheckDifferentRole() {
    Resource resource = prepareResource(Collections.singleton(new Role(RoleType.DataWrite)), Collections.singleton(new Role(RoleType.Read)));
    assertThatThrownBy(() -> permissionsChecker.checkRole(resource, RoleType.Manage)).isInstanceOf(NoResourcePermissionException.class).hasFieldOrPropertyWithValue("resource", resource);
}
Also used : Role(io.lumeer.api.model.Role) NoResourcePermissionException(io.lumeer.core.exception.NoResourcePermissionException) Resource(io.lumeer.api.model.common.Resource) Test(org.junit.Test)

Example 13 with Resource

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

the class PermissionsCheckerTest method testGetActualRolesIntersection.

@Test
public void testGetActualRolesIntersection() {
    Resource resource = prepareResource(Sets.newLinkedHashSet(new Role(RoleType.Read), new Role(RoleType.DataWrite)), Sets.newLinkedHashSet(new Role(RoleType.UserConfig), new Role(RoleType.PerspectiveConfig)));
    Set<RoleType> roles = permissionsChecker.getActualRoles(resource);
    assertThat(roles).containsOnly(RoleType.Read, RoleType.DataWrite, RoleType.UserConfig, RoleType.PerspectiveConfig);
}
Also used : Role(io.lumeer.api.model.Role) RoleType(io.lumeer.api.model.RoleType) Resource(io.lumeer.api.model.common.Resource) Test(org.junit.Test)

Example 14 with Resource

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

the class PermissionsCheckerTest method testGetActualRolesGroupOnly.

@Test
public void testGetActualRolesGroupOnly() {
    Resource resource = prepareResource(Collections.emptySet(), Sets.newLinkedHashSet(new Role(RoleType.Read), new Role(RoleType.UserConfig)));
    Set<RoleType> roles = permissionsChecker.getActualRoles(resource);
    assertThat(roles).containsOnly(RoleType.Read, RoleType.UserConfig);
}
Also used : Role(io.lumeer.api.model.Role) RoleType(io.lumeer.api.model.RoleType) Resource(io.lumeer.api.model.common.Resource) Test(org.junit.Test)

Example 15 with Resource

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

the class DocumentFacade method createDocumentsChain.

public DocumentsChain createDocumentsChain(List<Document> documents, List<LinkInstance> linkInstances) {
    var collectionsMap = documents.stream().filter(document -> document.getId() == null).map(document -> checkCreateDocuments(document.getCollectionId())).collect(Collectors.toMap(Resource::getId, Function.identity()));
    var linkTypesMap = linkInstances.stream().filter(linkInstance -> linkInstance.getId() == null).map(linkInstanceId -> checkCreateLinks(linkInstanceId.getLinkTypeId())).collect(Collectors.toMap(LinkType::getId, Function.identity()));
    permissionsChecker.checkDocumentLimits(documents);
    if (documents.isEmpty()) {
        return new DocumentsChain(Collections.emptyList(), Collections.emptyList());
    }
    List<Document> createdDocuments = new ArrayList<>();
    List<LinkInstance> createdLinks = new ArrayList<>();
    String previousDocumentId = linkInstances.size() == documents.size() ? Utils.firstNotNullElement(linkInstances.get(0).getDocumentIds()) : null;
    var linkInstanceIndex = 0;
    for (Document document : documents) {
        String currentDocumentId;
        if (document.getId() != null) {
            currentDocumentId = document.getId();
        } else {
            var collection = collectionsMap.get(document.getCollectionId());
            var tuple = createDocument(collection, document);
            createdDocuments.add(tuple.getSecond());
            currentDocumentId = tuple.getFirst().getId();
            collectionAdapter.updateCollectionMetadata(collection, tuple.getSecond().getData().keySet(), Collections.emptySet());
        }
        var linkInstance = linkInstances.size() > linkInstanceIndex ? linkInstances.get(linkInstanceIndex) : null;
        if (previousDocumentId != null && linkInstance != null) {
            linkInstance.setDocumentIds(Arrays.asList(previousDocumentId, currentDocumentId));
            if (linkInstance.getId() != null) {
                var updatedLinkInstance = linkInstanceDao.updateLinkInstance(linkInstance.getId(), linkInstance);
                updatedLinkInstance.setData(linkInstance.getData());
                createdLinks.add(updatedLinkInstance);
            } else {
                var linkType = linkTypesMap.get(linkInstance.getLinkTypeId());
                var linkData = linkInstanceFacade.createLinkInstance(linkType, linkInstance);
                createdLinks.add(linkData.getSecond());
            }
            linkInstanceIndex++;
        }
        previousDocumentId = currentDocumentId;
    }
    if (this.createChainEvent != null) {
        this.createChainEvent.fire(new CreateDocumentsAndLinks(createdDocuments, createdLinks));
    }
    return new DocumentsChain(createdDocuments, createdLinks);
}
Also used : Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) DocumentsChain(io.lumeer.api.model.DocumentsChain) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) HashMap(java.util.HashMap) DocumentAdapter(io.lumeer.core.adapter.DocumentAdapter) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) DataDao(io.lumeer.storage.api.dao.DataDao) ResourceType(io.lumeer.api.model.ResourceType) Resource(io.lumeer.api.model.common.Resource) Map(java.util.Map) ResourceCommentDao(io.lumeer.storage.api.dao.ResourceCommentDao) CollectionAdapter(io.lumeer.core.adapter.CollectionAdapter) ImportCollectionContent(io.lumeer.engine.api.event.ImportCollectionContent) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) Tuple(io.lumeer.core.util.Tuple) Event(javax.enterprise.event.Event) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) DataDocument(io.lumeer.engine.api.data.DataDocument) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Document(io.lumeer.api.model.Document) CreateDocument(io.lumeer.engine.api.event.CreateDocument) Set(java.util.Set) UUID(java.util.UUID) Constraint(io.lumeer.api.model.Constraint) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) LinkType(io.lumeer.api.model.LinkType) DocumentUtils(io.lumeer.core.util.DocumentUtils) Objects(java.util.Objects) FileAttachment(io.lumeer.api.model.FileAttachment) Project(io.lumeer.api.model.Project) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) List(java.util.List) ResourceUtils(io.lumeer.api.util.ResourceUtils) RequestScoped(javax.enterprise.context.RequestScoped) PostConstruct(javax.annotation.PostConstruct) FavoriteItemDao(io.lumeer.storage.api.dao.FavoriteItemDao) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument) Utils(io.lumeer.core.util.Utils) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) CreateDocumentsAndLinks(io.lumeer.engine.api.event.CreateDocumentsAndLinks) DocumentsChain(io.lumeer.api.model.DocumentsChain) ArrayList(java.util.ArrayList) CreateDocumentsAndLinks(io.lumeer.engine.api.event.CreateDocumentsAndLinks) LinkInstance(io.lumeer.api.model.LinkInstance) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) CreateDocument(io.lumeer.engine.api.event.CreateDocument) UpdateDocument(io.lumeer.engine.api.event.UpdateDocument)

Aggregations

Resource (io.lumeer.api.model.common.Resource)16 Test (org.junit.Test)8 Role (io.lumeer.api.model.Role)6 RoleType (io.lumeer.api.model.RoleType)4 SimpleResource (io.lumeer.api.model.common.SimpleResource)4 Utils (io.lumeer.core.util.Utils)3 DataDocument (io.lumeer.engine.api.data.DataDocument)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Collection (io.lumeer.api.model.Collection)2 Document (io.lumeer.api.model.Document)2 LinkInstance (io.lumeer.api.model.LinkInstance)2 LinkType (io.lumeer.api.model.LinkType)2 Project (io.lumeer.api.model.Project)2 ResourceType (io.lumeer.api.model.ResourceType)2 ResourceUtils (io.lumeer.api.util.ResourceUtils)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2