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