Search in sources :

Example 41 with ProjectId

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

the class TagsManager method setProjectTags.

/**
 * Sets the tags for the project that this manager is associated with.
 */
public void setProjectTags(@Nonnull Collection<TagData> newProjectTags) {
    checkNotNull(newProjectTags);
    Collection<Tag> currentProjectTags = getProjectTags();
    Set<OWLEntity> modifiedEntityTags = new HashSet<>();
    try {
        writeLock.lock();
        projectTags = null;
        Set<TagId> tagIds = newProjectTags.stream().map(TagData::getTagId).filter(Optional::isPresent).map(Optional::get).collect(toSet());
        // Remove current tags
        currentProjectTags.stream().map(Tag::getTagId).peek(tagId -> {
            if (!tagIds.contains(tagId)) {
                // Record modified entity tags
                entityTagsRepository.findByTagId(tagId).stream().map(EntityTags::getEntity).forEach(modifiedEntityTags::add);
                // Remove tag from entity
                entityTagsRepository.removeTag(projectId, tagId);
            }
        }).forEach(tagRepository::deleteTag);
        // Set fresh tags
        List<Tag> tags = newProjectTags.stream().map(tagData -> new Tag(tagData.getTagId().orElse(createTagId()), projectId, tagData.getLabel(), tagData.getDescription(), tagData.getColor(), tagData.getBackgroundColor())).peek(tag -> {
            // Find the modified entities for this tag
            entityTagsRepository.findByTagId(tag.getTagId()).stream().map(EntityTags::getEntity).forEach(modifiedEntityTags::add);
        }).collect(toList());
        tagRepository.saveTags(tags);
    } finally {
        writeLock.unlock();
    }
    Set<Tag> oldProjectTags = new HashSet<>(currentProjectTags);
    Set<Tag> projectTags = new HashSet<>(getProjectTags());
    if (!oldProjectTags.equals(projectTags)) {
        List<ProjectEvent<?>> events = new ArrayList<>();
        for (OWLEntity entity : modifiedEntityTags) {
            EntityTagsChangedEvent event = new EntityTagsChangedEvent(projectId, entity, getTags(entity));
            events.add(event);
        }
        events.add(new ProjectTagsChangedEvent(projectId, projectTags));
        eventBus.postEvents(events);
    }
}
Also used : java.util(java.util) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TagId.createTagId(edu.stanford.bmir.protege.web.shared.tag.TagId.createTagId) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) HasPostEvents(edu.stanford.bmir.protege.web.server.events.HasPostEvents) edu.stanford.bmir.protege.web.shared.tag(edu.stanford.bmir.protege.web.shared.tag) Lock(java.util.concurrent.locks.Lock) HashMultimap(com.google.common.collect.HashMultimap) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ProjectSingleton(edu.stanford.bmir.protege.web.shared.inject.ProjectSingleton) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) TagId.createTagId(edu.stanford.bmir.protege.web.shared.tag.TagId.createTagId) ProjectEvent(edu.stanford.bmir.protege.web.shared.event.ProjectEvent)

Example 42 with ProjectId

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

the class GetEntityTagsActionHandler method execute.

@Nonnull
@Override
public GetEntityTagsResult execute(@Nonnull GetEntityTagsAction action, @Nonnull ExecutionContext executionContext) {
    ProjectId projectId = action.getProjectId();
    OWLEntity entity = action.getEntity();
    return new GetEntityTagsResult(tagsManager.getTags(entity), tagsManager.getProjectTags());
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) GetEntityTagsResult(edu.stanford.bmir.protege.web.shared.tag.GetEntityTagsResult) Nonnull(javax.annotation.Nonnull)

Example 43 with ProjectId

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

the class ProjectTagsPlaceTokenizer method getPlace.

@Override
public ProjectTagsPlace getPlace(String token) {
    MatchResult matchResult = regExp.exec(token);
    if (matchResult == null) {
        return null;
    }
    String projectIdString = matchResult.getGroup(1);
    if (ProjectId.isWelFormedProjectId(projectIdString)) {
        ProjectId projectId = ProjectId.get(projectIdString);
        return new ProjectTagsPlace(projectId, Optional.empty());
    } else {
        return null;
    }
}
Also used : ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 44 with ProjectId

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

the class ProjectSettingsPlaceTokenizer method getPlace.

@Override
public ProjectSettingsPlace getPlace(String token) {
    MatchResult matchResult = regExp.exec(token);
    if (matchResult == null) {
        return null;
    }
    String projectIdString = matchResult.getGroup(1);
    if (ProjectId.isWelFormedProjectId(projectIdString)) {
        ProjectId projectId = ProjectId.get(projectIdString);
        return new ProjectSettingsPlace(projectId, empty());
    } else {
        return null;
    }
}
Also used : ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) MatchResult(com.google.gwt.regexp.shared.MatchResult) ProjectSettingsPlace(edu.stanford.bmir.protege.web.shared.place.ProjectSettingsPlace)

Example 45 with ProjectId

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

the class ProjectDownloadServlet method startProjectDownload.

private void startProjectDownload(HttpServletResponse resp, UserId userId, FileDownloadParameters downloadParameters) throws IOException {
    ProjectId projectId = downloadParameters.getProjectId();
    RevisionNumber revisionNumber = downloadParameters.getRequestedRevision();
    DownloadFormat format = downloadParameters.getFormat();
    projectDownloadService.downloadProject(userId, projectId, revisionNumber, format, resp);
}
Also used : ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) RevisionNumber(edu.stanford.bmir.protege.web.shared.revision.RevisionNumber)

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