Search in sources :

Example 11 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class GetAvailableProjectsHandler method execute.

@Nonnull
@Override
public GetAvailableProjectsResult execute(@Nonnull GetAvailableProjectsAction action, @Nonnull ExecutionContext executionContext) {
    UserId userId = executionContext.getUserId();
    Optional<UserActivityRecord> userActivityRecord = userActivityManager.getUserActivityRecord(executionContext.getUserId());
    Map<ProjectId, Long> lastOpenedMap = new HashMap<>();
    userActivityRecord.ifPresent(record -> record.getRecentProjects().forEach(recent -> lastOpenedMap.put(recent.getProjectId(), recent.getTimestamp())));
    List<AvailableProject> availableProjects = projectPermissionsManager.getReadableProjects(userId).stream().map(details -> {
        Subject user = forUser(userId);
        ProjectResource projectResource = new ProjectResource(details.getProjectId());
        boolean downloadable = accessManager.hasPermission(user, projectResource, DOWNLOAD_PROJECT);
        boolean trashable = details.getOwner().equals(userId) || accessManager.hasPermission(user, projectResource, MOVE_ANY_PROJECT_TO_TRASH);
        long lastOpened = lastOpenedMap.getOrDefault(details.getProjectId(), 0L);
        return new AvailableProject(details, downloadable, trashable, lastOpened);
    }).collect(toList());
    return new GetAvailableProjectsResult(availableProjects);
}
Also used : AvailableProject(edu.stanford.bmir.protege.web.shared.project.AvailableProject) UserActivityManager(edu.stanford.bmir.protege.web.server.user.UserActivityManager) ApplicationActionHandler(edu.stanford.bmir.protege.web.server.dispatch.ApplicationActionHandler) UserActivityRecord(edu.stanford.bmir.protege.web.server.user.UserActivityRecord) HashMap(java.util.HashMap) Inject(javax.inject.Inject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) DOWNLOAD_PROJECT(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.DOWNLOAD_PROJECT) Map(java.util.Map) ProjectResource(edu.stanford.bmir.protege.web.server.access.ProjectResource) Nonnull(javax.annotation.Nonnull) Subject(edu.stanford.bmir.protege.web.server.access.Subject) NullValidator(edu.stanford.bmir.protege.web.server.dispatch.validators.NullValidator) Subject.forUser(edu.stanford.bmir.protege.web.server.access.Subject.forUser) RequestValidator(edu.stanford.bmir.protege.web.server.dispatch.RequestValidator) MOVE_ANY_PROJECT_TO_TRASH(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.MOVE_ANY_PROJECT_TO_TRASH) ProjectPermissionsManager(edu.stanford.bmir.protege.web.server.permissions.ProjectPermissionsManager) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) Optional(java.util.Optional) GetAvailableProjectsResult(edu.stanford.bmir.protege.web.shared.project.GetAvailableProjectsResult) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) RequestContext(edu.stanford.bmir.protege.web.server.dispatch.RequestContext) GetAvailableProjectsAction(edu.stanford.bmir.protege.web.shared.project.GetAvailableProjectsAction) HashMap(java.util.HashMap) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Subject(edu.stanford.bmir.protege.web.server.access.Subject) UserActivityRecord(edu.stanford.bmir.protege.web.server.user.UserActivityRecord) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) GetAvailableProjectsResult(edu.stanford.bmir.protege.web.shared.project.GetAvailableProjectsResult) AvailableProject(edu.stanford.bmir.protege.web.shared.project.AvailableProject) ProjectResource(edu.stanford.bmir.protege.web.server.access.ProjectResource) Nonnull(javax.annotation.Nonnull)

Example 12 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class RemoveProjectsFromTrashActionHandler method execute.

@Nonnull
@Override
public RemoveProjectsFromTrashResult execute(@Nonnull RemoveProjectFromTrashAction action, @Nonnull ExecutionContext executionContext) {
    List<ProjectMovedFromTrashEvent> events = new ArrayList<>();
    ProjectId projectId = action.getProjectId();
    projectDetailsManager.setInTrash(projectId, false);
    events.add(new ProjectMovedFromTrashEvent(projectId));
    return new RemoveProjectsFromTrashResult(new EventList<>(EventTag.getFirst(), events, EventTag.getFirst()));
}
Also used : RemoveProjectsFromTrashResult(edu.stanford.bmir.protege.web.shared.project.RemoveProjectsFromTrashResult) ProjectMovedFromTrashEvent(edu.stanford.bmir.protege.web.shared.event.ProjectMovedFromTrashEvent) ArrayList(java.util.ArrayList) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull)

Example 13 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class DispatchServiceExecutorImpl method setTemporaryThreadName.

/**
 * Sets the name of a thread so that it contains details of the action (and target project) being executed
 * @param thread The thread.
 * @param action The action.
 * @param projectId The optional project id.
 */
private static void setTemporaryThreadName(@Nonnull Thread thread, @Nonnull Action<?> action, @Nullable ProjectId projectId) {
    String tempThreadName;
    final ProjectId targetProjectId;
    if (projectId != null) {
        targetProjectId = projectId;
    } else if (action instanceof HasProjectId) {
        targetProjectId = ((HasProjectId) action).getProjectId();
    } else {
        targetProjectId = null;
    }
    if (targetProjectId == null) {
        tempThreadName = String.format("[DispatchService] %s", action.getClass().getSimpleName());
    } else {
        tempThreadName = String.format("[DispatchService] %s %s", action.getClass().getSimpleName(), targetProjectId);
    }
    thread.setName(tempThreadName);
}
Also used : HasProjectId(edu.stanford.bmir.protege.web.shared.project.HasProjectId) HasProjectId(edu.stanford.bmir.protege.web.shared.project.HasProjectId) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId)

Example 14 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class DispatchServiceExecutorImpl method execute.

@Override
public <A extends Action<R>, R extends Result> DispatchServiceResultContainer execute(A action, RequestContext requestContext, ExecutionContext executionContext) throws ActionExecutionException, PermissionDeniedException {
    ActionHandler<A, R> actionHandler = null;
    final Thread thread = Thread.currentThread();
    String threadName = thread.getName();
    if (action instanceof ProjectAction) {
        ProjectAction projectAction = (ProjectAction) action;
        ProjectId projectId = projectAction.getProjectId();
        setTemporaryThreadName(thread, action, projectId);
        ProjectActionHandlerRegistry actionHanderRegistry = projectManager.getActionHandlerRegistry(projectId);
        actionHandler = actionHanderRegistry.getActionHandler(action);
    } else {
        setTemporaryThreadName(thread, action, null);
        actionHandler = handlerRegistry.getActionHandler(action);
    }
    RequestValidator validator = actionHandler.getRequestValidator(action, requestContext);
    RequestValidationResult validationResult = validator.validateAction();
    if (!validationResult.isValid()) {
        throw getPermissionDeniedException(requestContext.getUserId(), validationResult);
    }
    try {
        R result = actionHandler.execute(action, executionContext);
        return new DispatchServiceResultContainer(result);
    } catch (PermissionDeniedException e) {
        throw e;
    } catch (Exception e) {
        logger.error("An error occurred whilst executing an action", e);
        throw new ActionExecutionException(e);
    } finally {
        thread.setName(threadName);
    }
}
Also used : HasProjectId(edu.stanford.bmir.protege.web.shared.project.HasProjectId) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) PermissionDeniedException(edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException) PermissionDeniedException(edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException)

Example 15 with ProjectId

use of edu.stanford.bmir.protege.web.shared.project.ProjectId in project webprotege by protegeproject.

the class ProjectDetailsManagerImpl method setProjectSettings.

@Override
public void setProjectSettings(ProjectSettings projectSettings) {
    ProjectId projectId = projectSettings.getProjectId();
    Optional<ProjectDetails> record = repository.findOne(projectId);
    if (!record.isPresent()) {
        return;
    }
    ProjectDetails updatedRecord = record.get().builder().setDisplayName(projectSettings.getProjectDisplayName()).setDescription(projectSettings.getProjectDescription()).build();
    repository.save(updatedRecord);
    slackWebhookRepository.clearWebhooks(projectId);
    String payloadUrl = projectSettings.getSlackIntegrationSettings().getPayloadUrl();
    if (!payloadUrl.isEmpty()) {
        slackWebhookRepository.addWebhooks(Collections.singletonList(new SlackWebhook(projectId, payloadUrl)));
    }
    webhookRepository.clearProjectWebhooks(projectId);
    List<ProjectWebhook> projectWebhooks = projectSettings.getWebhookSettings().getWebhookSettings().stream().map(s -> new ProjectWebhook(projectId, s.getPayloadUrl(), new ArrayList<ProjectWebhookEventType>(s.getEventTypes()))).collect(toList());
    webhookRepository.addProjectWebhooks(projectWebhooks);
}
Also used : UnknownProjectException(edu.stanford.bmir.protege.web.shared.project.UnknownProjectException) WebhookRepository(edu.stanford.bmir.protege.web.server.webhook.WebhookRepository) java.util(java.util) ProjectWebhook(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhook) SlackIntegrationSettings(edu.stanford.bmir.protege.web.shared.projectsettings.SlackIntegrationSettings) ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails) WebhookSettings(edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSettings) ProjectWebhookEventType(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhookEventType) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SlackWebhookRepository(edu.stanford.bmir.protege.web.server.webhook.SlackWebhookRepository) Inject(javax.inject.Inject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Collectors.toList(java.util.stream.Collectors.toList) NewProjectSettings(edu.stanford.bmir.protege.web.shared.project.NewProjectSettings) SlackWebhook(edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook) WebhookSetting(edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSetting) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectSettings(edu.stanford.bmir.protege.web.shared.projectsettings.ProjectSettings) ProjectWebhookEventType(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhookEventType) ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectWebhook(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhook) SlackWebhook(edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook)

Aggregations

ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)51 Nonnull (javax.annotation.Nonnull)19 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)16 Inject (javax.inject.Inject)14 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)8 java.util (java.util)7 HasProjectId (edu.stanford.bmir.protege.web.shared.project.HasProjectId)6 Collectors.toList (java.util.stream.Collectors.toList)6 Nullable (javax.annotation.Nullable)6 Test (org.junit.Test)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)5 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)5 Optional (java.util.Optional)5 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)5 Subject.forUser (edu.stanford.bmir.protege.web.server.access.Subject.forUser)4 ProjectDetails (edu.stanford.bmir.protege.web.shared.project.ProjectDetails)4 List (java.util.List)4 ImmutableSet (com.google.common.collect.ImmutableSet)3