Search in sources :

Example 6 with Resource

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

the class UserNotificationFacade method createResourceSharedNotifications.

private List<UserNotification> createResourceSharedNotifications(final Resource resource, final java.util.Collection<String> newUsers) {
    if (workspaceKeeper.getOrganization().isEmpty() && resource.getType() != ResourceType.ORGANIZATION) {
        return Collections.emptyList();
    }
    final DataDocument data = getResourceDescription(resource);
    final List<UserNotification> notifications = newUsers.stream().map(userId -> createNotification(userId, getNotificationTypeByResource(resource), data)).collect(Collectors.toList());
    return dao.createNotificationsBatch(notifications);
}
Also used : UserDao(io.lumeer.storage.api.dao.UserDao) NotificationType(io.lumeer.api.model.NotificationType) NotificationChannel(io.lumeer.api.model.NotificationChannel) UserNotification(io.lumeer.api.model.UserNotification) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) RemoveResource(io.lumeer.engine.api.event.RemoveResource) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) CreateResource(io.lumeer.engine.api.event.CreateResource) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) WorkspaceKeeper(io.lumeer.core.WorkspaceKeeper) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(io.lumeer.api.model.Language) RolesDifference(io.lumeer.api.model.RolesDifference) ResourceType(io.lumeer.api.model.ResourceType) QueryStem(io.lumeer.api.model.QueryStem) Resource(io.lumeer.api.model.common.Resource) Map(java.util.Map) Observes(javax.enterprise.event.Observes) Query(io.lumeer.api.model.Query) Organization(io.lumeer.api.model.Organization) View(io.lumeer.api.model.View) DataDocument(io.lumeer.engine.api.data.DataDocument) Permissions(io.lumeer.api.model.Permissions) Collection(java.util.Collection) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Project(io.lumeer.api.model.Project) List(java.util.List) AccessForbiddenException(io.lumeer.core.exception.AccessForbiddenException) UserNotificationDao(io.lumeer.storage.api.dao.UserNotificationDao) RequestScoped(javax.enterprise.context.RequestScoped) UpdateResource(io.lumeer.engine.api.event.UpdateResource) Utils(io.lumeer.core.util.Utils) Collections(java.util.Collections) DataDocument(io.lumeer.engine.api.data.DataDocument) UserNotification(io.lumeer.api.model.UserNotification)

Example 7 with Resource

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

the class FunctionFacade method convertQueueToTask.

public FunctionTask convertQueueToTask(final Deque<FunctionParameterDocuments> queue) {
    Set<String> collectionIds = queue.stream().filter(q -> q.getType() == FunctionResourceType.COLLECTION && q.getCollection() == null).map(FunctionParameter::getResourceId).collect(Collectors.toSet());
    Set<String> linkTypeIds = queue.stream().filter(q -> q.getType() == FunctionResourceType.LINK && q.getLinkType() == null).map(FunctionParameter::getResourceId).collect(Collectors.toSet());
    Map<String, Collection> collectionMap = collectionIds.size() > 0 ? collectionDao.getCollectionsByIds(collectionIds).stream().collect(Collectors.toMap(Resource::getId, c -> c)) : new HashMap<>();
    List<LinkType> linkTypes = linkTypeIds.size() > 0 ? linkTypeAdapter.mapLinkTypesComputedProperties(linkTypeDao.getLinkTypesByIds(linkTypeIds)) : new ArrayList<>();
    Map<String, LinkType> linkTypeMap = linkTypes.stream().collect(Collectors.toMap(LinkType::getId, c -> c));
    FunctionTask task = null;
    final Iterator<FunctionParameterDocuments> iterator = queue.descendingIterator();
    while (iterator.hasNext()) {
        final FunctionParameterDocuments parameter = iterator.next();
        if (parameter.getType() == FunctionResourceType.COLLECTION) {
            Collection collection = parameter.getCollection() != null ? parameter.getCollection() : collectionMap.get(parameter.getResourceId());
            Attribute attribute = parameter.getAttribute() != null ? parameter.getAttribute() : findAttributeInCollection(collection, parameter.getAttributeId());
            if (collection != null && attribute != null) {
                FunctionTask functionTask = contextualTaskFactory.getInstance(FunctionTask.class);
                functionTask.setFunctionTask(attribute, collection, parameter.getDocuments(), task);
                task = functionTask;
            }
        } else if (parameter.getType() == FunctionResourceType.LINK) {
            LinkType linkType = parameter.getLinkType() != null ? parameter.getLinkType() : linkTypeMap.get(parameter.getResourceId());
            Attribute attribute = parameter.getAttribute() != null ? parameter.getAttribute() : findAttributeInLinkType(linkType, parameter.getAttributeId());
            if (linkType != null && attribute != null) {
                FunctionTask functionTask = contextualTaskFactory.getInstance(FunctionTask.class);
                functionTask.setFunctionTask(attribute, linkType, parameter.getLinkInstances(), task);
                task = functionTask;
            }
        }
    }
    return task;
}
Also used : ContextualTaskFactory(io.lumeer.core.task.ContextualTaskFactory) FunctionOrder(io.lumeer.core.util.FunctionOrder) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) HashMap(java.util.HashMap) Deque(java.util.Deque) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Resource(io.lumeer.api.model.common.Resource) Map(java.util.Map) FunctionResourceType(io.lumeer.api.model.function.FunctionResourceType) FunctionTask(io.lumeer.core.task.FunctionTask) LinkedList(java.util.LinkedList) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) DataDocument(io.lumeer.engine.api.data.DataDocument) Iterator(java.util.Iterator) FunctionXmlParser(io.lumeer.core.util.FunctionXmlParser) Document(io.lumeer.api.model.Document) Set(java.util.Set) FunctionRow(io.lumeer.api.model.function.FunctionRow) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) LinkTypeAdapter(io.lumeer.core.adapter.LinkTypeAdapter) LinkType(io.lumeer.api.model.LinkType) Objects(java.util.Objects) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) List(java.util.List) ResourceUtils(io.lumeer.api.util.ResourceUtils) RequestScoped(javax.enterprise.context.RequestScoped) PostConstruct(javax.annotation.PostConstruct) FunctionDao(io.lumeer.storage.api.dao.FunctionDao) Optional(java.util.Optional) Attribute(io.lumeer.api.model.Attribute) FunctionParameter(io.lumeer.api.model.function.FunctionParameter) Utils(io.lumeer.core.util.Utils) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Attribute(io.lumeer.api.model.Attribute) Resource(io.lumeer.api.model.common.Resource) FunctionTask(io.lumeer.core.task.FunctionTask) Collection(io.lumeer.api.model.Collection) LinkType(io.lumeer.api.model.LinkType)

Example 8 with Resource

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

the class ViewCodec method generateIdIfAbsentFromDocument.

@Override
public View generateIdIfAbsentFromDocument(final View jsonView) {
    Resource resource = generateIdIfAbsentFromDocument((Resource) jsonView);
    jsonView.setId(resource.getId());
    return jsonView;
}
Also used : SimpleResource(io.lumeer.api.model.common.SimpleResource) Resource(io.lumeer.api.model.common.Resource)

Example 9 with Resource

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

the class CollectionCodec method generateIdIfAbsentFromDocument.

@Override
public Collection generateIdIfAbsentFromDocument(final Collection jsonCollection) {
    Resource resource = generateIdIfAbsentFromDocument((Resource) jsonCollection);
    jsonCollection.setId(resource.getId());
    return jsonCollection;
}
Also used : SimpleResource(io.lumeer.api.model.common.SimpleResource) Resource(io.lumeer.api.model.common.Resource)

Example 10 with Resource

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

the class PermissionsCheckerTest method testGetActualRolesEmpty.

@Test
public void testGetActualRolesEmpty() {
    Resource resource = prepareResource(Collections.emptySet(), Collections.emptySet());
    Set<RoleType> roles = permissionsChecker.getActualRoles(resource);
    assertThat(roles).isEmpty();
}
Also used : RoleType(io.lumeer.api.model.RoleType) Resource(io.lumeer.api.model.common.Resource) Test(org.junit.Test)

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