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