Search in sources :

Example 1 with ExecutionContext

use of edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext 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 2 with ExecutionContext

use of edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext in project webprotege by protegeproject.

the class GetProjectPrefixDeclarationsActionHandler method execute.

@Nonnull
@Override
public GetProjectPrefixDeclarationsResult execute(@Nonnull GetProjectPrefixDeclarationsAction action, @Nonnull ExecutionContext executionContext) {
    ProjectId projectId = action.getProjectId();
    List<PrefixDeclaration> decls = store.find(projectId).getPrefixes().entrySet().stream().map(entry -> PrefixDeclaration.get(entry.getKey(), entry.getValue())).collect(toList());
    return new GetProjectPrefixDeclarationsResult(projectId, decls);
}
Also used : GetProjectPrefixDeclarationsAction(edu.stanford.bmir.protege.web.shared.project.GetProjectPrefixDeclarationsAction) PrefixDeclaration(edu.stanford.bmir.protege.web.shared.project.PrefixDeclaration) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) GetProjectPrefixDeclarationsResult(edu.stanford.bmir.protege.web.shared.project.GetProjectPrefixDeclarationsResult) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) GetProjectPrefixDeclarationsResult(edu.stanford.bmir.protege.web.shared.project.GetProjectPrefixDeclarationsResult) PrefixDeclaration(edu.stanford.bmir.protege.web.shared.project.PrefixDeclaration) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull)

Example 3 with ExecutionContext

use of edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext in project webprotege by protegeproject.

the class GetCommentedEntitiesActionHandler method execute.

@Nonnull
@Override
public GetCommentedEntitiesResult execute(@Nonnull GetCommentedEntitiesAction action, @Nonnull ExecutionContext executionContext) {
    PageRequest request = action.getPageRequest();
    List<EntityDiscussionThread> allThreads = repository.getThreadsInProject(action.getProjectId());
    Map<OWLEntity, List<EntityDiscussionThread>> commentsByEntity = allThreads.stream().collect(groupingBy(EntityDiscussionThread::getEntity));
    List<CommentedEntityData> result = new ArrayList<>();
    commentsByEntity.forEach((entity, threads) -> {
        if (rootOntology.containsEntityInSignature(entity)) {
            int totalThreadCount = threads.size();
            int openThreadCount = (int) threads.stream().filter(thread -> thread.getStatus().isOpen()).count();
            List<Comment> entityComments = threads.stream().flatMap(thread -> thread.getComments().stream()).collect(toList());
            Comment lastComment = entityComments.stream().max(comparing(c -> c.getUpdatedAt().orElse(c.getCreatedAt()))).get();
            List<UserId> participants = entityComments.stream().map(Comment::getCreatedBy).collect(toList());
            result.add(new CommentedEntityData(renderer.getRendering(entity), totalThreadCount, openThreadCount, entityComments.size(), lastComment.getUpdatedAt().orElse(lastComment.getCreatedAt()), lastComment.getCreatedBy(), participants));
        }
    });
    if (action.getSortingKey() == SortingKey.SORT_BY_ENTITY) {
        result.sort(byEntity);
    } else {
        result.sort(byLastModified);
    }
    Pager<CommentedEntityData> pager = Pager.getPagerForPageSize(result, request.getPageSize());
    return new GetCommentedEntitiesResult(action.getProjectId(), pager.getPage(request.getPageNumber()));
}
Also used : HasGetRendering(edu.stanford.bmir.protege.web.server.mansyntax.render.HasGetRendering) CommentedEntityData.byLastModified(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData.byLastModified) edu.stanford.bmir.protege.web.shared.issues(edu.stanford.bmir.protege.web.shared.issues) RootOntology(edu.stanford.bmir.protege.web.server.inject.project.RootOntology) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Pager(edu.stanford.bmir.protege.web.server.pagination.Pager) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CommentedEntityData.byEntity(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData.byEntity) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) Map(java.util.Map) CommentedEntityData(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Comparator.comparing(java.util.Comparator.comparing) Nonnull(javax.annotation.Nonnull) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ArrayList(java.util.ArrayList) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) CommentedEntityData(edu.stanford.bmir.protege.web.shared.entity.CommentedEntityData) Nonnull(javax.annotation.Nonnull)

Example 4 with ExecutionContext

use of edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext in project webprotege by protegeproject.

the class SetDiscussionThreadStatusHandler method execute.

@Nonnull
@Override
public SetDiscussionThreadStatusResult execute(@Nonnull SetDiscussionThreadStatusAction action, @Nonnull ExecutionContext executionContext) {
    EventTag fromTag = eventManager.getCurrentTag();
    ThreadId threadId = action.getThreadId();
    Status status = action.getStatus();
    Optional<EntityDiscussionThread> thread = repository.setThreadStatus(threadId, status);
    int openComments = thread.map(t -> repository.getOpenCommentsCount(projectId, t.getEntity())).orElse(-1);
    eventManager.postEvent(new DiscussionThreadStatusChangedEvent(projectId, threadId, thread.map(EntityDiscussionThread::getEntity), openComments, status));
    EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(fromTag);
    return new SetDiscussionThreadStatusResult(threadId, status, eventList);
}
Also used : edu.stanford.bmir.protege.web.shared.issues(edu.stanford.bmir.protege.web.shared.issues) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) EventList(edu.stanford.bmir.protege.web.shared.event.EventList) EventManager(edu.stanford.bmir.protege.web.server.events.EventManager) Inject(javax.inject.Inject) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) SET_OBJECT_COMMENT_STATUS(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.SET_OBJECT_COMMENT_STATUS) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) EventTag(edu.stanford.bmir.protege.web.shared.event.EventTag) Optional(java.util.Optional) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EventTag(edu.stanford.bmir.protege.web.shared.event.EventTag) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) Nonnull(javax.annotation.Nonnull)

Example 5 with ExecutionContext

use of edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext in project webprotege by protegeproject.

the class GetIndividualsActionHandler method execute.

@Nonnull
@Override
public GetIndividualsResult execute(@Nonnull GetIndividualsAction action, @Nonnull ExecutionContext executionContext) {
    Stream<OWLNamedIndividual> stream;
    if (action.getType().isOWLThing()) {
        stream = rootOntology.getIndividualsInSignature(Imports.INCLUDED).stream();
    } else {
        stream = rootOntology.getImportsClosure().stream().flatMap(o -> o.getClassAssertionAxioms(action.getType()).stream()).map(OWLClassAssertionAxiom::getIndividual).filter(OWLIndividual::isNamed).map(OWLIndividual::asOWLNamedIndividual);
    }
    Counter counter = new Counter();
    List<OWLNamedIndividualData> individualsData = stream.peek(i -> counter.increment()).map(renderingManager::getRendering).filter(i -> {
        String searchString = action.getFilterString();
        return searchString.isEmpty() || StringUtils.containsIgnoreCase(i.getBrowserText(), searchString);
    }).distinct().sorted().collect(toList());
    PageRequest pageRequest = action.getPageRequest();
    Pager<OWLNamedIndividualData> pager = Pager.getPagerForPageSize(individualsData, pageRequest.getPageSize());
    Page<OWLNamedIndividualData> page = pager.getPage(pageRequest.getPageNumber());
    OWLClassData type = renderingManager.getRendering(action.getType());
    logger.info(BROWSING, "{} {} retrieved instances of {} ({})", projectId, executionContext.getUserId(), action.getType(), renderingManager.getRendering(action.getType()).getBrowserText());
    return new GetIndividualsResult(type, page, counter.getCount(), individualsData.size());
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) RootOntology(edu.stanford.bmir.protege.web.server.inject.project.RootOntology) LoggerFactory(org.slf4j.LoggerFactory) OWLNamedIndividualData(edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData) Inject(javax.inject.Inject) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) RenderingManager(edu.stanford.bmir.protege.web.server.renderer.RenderingManager) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Page(edu.stanford.bmir.protege.web.shared.pagination.Page) Imports(org.semanticweb.owlapi.model.parameters.Imports) Logger(org.slf4j.Logger) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) VIEW_PROJECT(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT) BuiltInAction(edu.stanford.bmir.protege.web.shared.access.BuiltInAction) Pager(edu.stanford.bmir.protege.web.server.pagination.Pager) GetIndividualsResult(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsResult) AbstractProjectActionHandler(edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) ExecutionContext(edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) GetIndividualsAction(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsAction) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) BROWSING(edu.stanford.bmir.protege.web.server.logging.Markers.BROWSING) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) PageRequest(edu.stanford.bmir.protege.web.shared.pagination.PageRequest) GetIndividualsResult(edu.stanford.bmir.protege.web.shared.individualslist.GetIndividualsResult) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLNamedIndividualData(edu.stanford.bmir.protege.web.shared.entity.OWLNamedIndividualData) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) Nonnull(javax.annotation.Nonnull)

Aggregations

AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)7 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)7 Nonnull (javax.annotation.Nonnull)7 Inject (javax.inject.Inject)7 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)6 BuiltInAction (edu.stanford.bmir.protege.web.shared.access.BuiltInAction)5 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)5 Nullable (javax.annotation.Nullable)5 List (java.util.List)4 Optional (java.util.Optional)4 Collectors.toList (java.util.stream.Collectors.toList)4 edu.stanford.bmir.protege.web.shared.issues (edu.stanford.bmir.protege.web.shared.issues)3 EventManager (edu.stanford.bmir.protege.web.server.events.EventManager)2 RootOntology (edu.stanford.bmir.protege.web.server.inject.project.RootOntology)2 Pager (edu.stanford.bmir.protege.web.server.pagination.Pager)2 VIEW_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT)2 EventList (edu.stanford.bmir.protege.web.shared.event.EventList)2 EventTag (edu.stanford.bmir.protege.web.shared.event.EventTag)2 ProjectEvent (edu.stanford.bmir.protege.web.shared.event.ProjectEvent)2 PageRequest (edu.stanford.bmir.protege.web.shared.pagination.PageRequest)2