Search in sources :

Example 1 with GetAvailableProjectsResult

use of edu.stanford.bmir.protege.web.shared.project.GetAvailableProjectsResult 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)

Aggregations

AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)1 ProjectResource (edu.stanford.bmir.protege.web.server.access.ProjectResource)1 Subject (edu.stanford.bmir.protege.web.server.access.Subject)1 Subject.forUser (edu.stanford.bmir.protege.web.server.access.Subject.forUser)1 ApplicationActionHandler (edu.stanford.bmir.protege.web.server.dispatch.ApplicationActionHandler)1 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)1 RequestContext (edu.stanford.bmir.protege.web.server.dispatch.RequestContext)1 RequestValidator (edu.stanford.bmir.protege.web.server.dispatch.RequestValidator)1 NullValidator (edu.stanford.bmir.protege.web.server.dispatch.validators.NullValidator)1 ProjectPermissionsManager (edu.stanford.bmir.protege.web.server.permissions.ProjectPermissionsManager)1 UserActivityManager (edu.stanford.bmir.protege.web.server.user.UserActivityManager)1 UserActivityRecord (edu.stanford.bmir.protege.web.server.user.UserActivityRecord)1 DOWNLOAD_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.DOWNLOAD_PROJECT)1 MOVE_ANY_PROJECT_TO_TRASH (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.MOVE_ANY_PROJECT_TO_TRASH)1 AvailableProject (edu.stanford.bmir.protege.web.shared.project.AvailableProject)1 GetAvailableProjectsAction (edu.stanford.bmir.protege.web.shared.project.GetAvailableProjectsAction)1 GetAvailableProjectsResult (edu.stanford.bmir.protege.web.shared.project.GetAvailableProjectsResult)1 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 HashMap (java.util.HashMap)1