Search in sources :

Example 36 with ProjectId

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

the class MoveProjectsToTrashActionHandler method execute.

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

Example 37 with ProjectId

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

the class GetProjectEventsActionHandler method execute.

@Nonnull
@Override
public GetProjectEventsResult execute(@Nonnull GetProjectEventsAction action, @Nonnull ExecutionContext executionContext) {
    EventTag sinceTag = action.getSinceTag();
    ProjectId projectId = action.getProjectId();
    UserId userId = executionContext.getUserId();
    if (!accessManager.hasPermission(forUser(userId), forProject(action.getProjectId()), VIEW_PROJECT)) {
        return getEmptyResult(projectId, sinceTag);
    }
    if (!projectManager.isActive(projectId)) {
        return getEmptyResult(projectId, sinceTag);
    }
    Optional<Project> project = projectManager.getProjectIfActive(projectId);
    if (!project.isPresent()) {
        return getEmptyResult(projectId, sinceTag);
    }
    EventManager<ProjectEvent<?>> eventManager = project.get().getEventManager();
    EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(sinceTag);
    ProjectEventList projectEventList = ProjectEventList.builder(eventList.getStartTag(), projectId, eventList.getEndTag()).addEvents(eventList.getEvents()).build();
    return new GetProjectEventsResult(projectEventList);
}
Also used : Project(edu.stanford.bmir.protege.web.server.project.Project) ProjectResource.forProject(edu.stanford.bmir.protege.web.server.access.ProjectResource.forProject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull)

Example 38 with ProjectId

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

the class ProjectEntityCrudKitSettingsTestCase method equalsShouldReturnTrueForEqualProjectIdAndEqualSettings.

@Test
public void equalsShouldReturnTrueForEqualProjectIdAndEqualSettings() {
    ProjectId projectId = mock(ProjectId.class);
    EntityCrudKitSettings<?> settings = mock(EntityCrudKitSettings.class);
    ProjectEntityCrudKitSettings settingsA = new ProjectEntityCrudKitSettings(projectId, settings);
    ProjectEntityCrudKitSettings settingsB = new ProjectEntityCrudKitSettings(projectId, settings);
    assertEquals(settingsA, settingsB);
}
Also used : ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Test(org.junit.Test)

Example 39 with ProjectId

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

the class ProjectIdReadConverterTestCase method convertShouldReturnProjectIdWithSuppliedId.

@Test
public void convertShouldReturnProjectIdWithSuppliedId() {
    ProjectIdReadConverter converter = new ProjectIdReadConverter();
    String suppliedId = UUID.randomUUID().toString();
    ProjectId projectId = converter.convert(suppliedId);
    assertEquals(suppliedId, projectId.getId());
}
Also used : ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Test(org.junit.Test)

Example 40 with ProjectId

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

the class ProjectSharingSettingsManagerImpl method setProjectSharingSettings.

@Override
public void setProjectSharingSettings(ProjectSharingSettings settings) {
    ProjectId projectId = settings.getProjectId();
    ProjectResource projectResource = new ProjectResource(projectId);
    // Remove existing assignments
    accessManager.getSubjectsWithAccessToResource(projectResource).forEach(subject -> accessManager.setAssignedRoles(subject, projectResource, Collections.emptySet()));
    Map<PersonId, SharingSetting> map = settings.getSharingSettings().stream().collect(toMap(SharingSetting::getPersonId, s -> s, (s1, s2) -> s1));
    Optional<SharingPermission> linkSharingPermission = settings.getLinkSharingPermission();
    linkSharingPermission.ifPresent(permission -> {
        Collection<RoleId> roleId = Roles.fromSharingPermission(permission);
        accessManager.setAssignedRoles(forAnySignedInUser(), projectResource, roleId);
    });
    if (!linkSharingPermission.isPresent()) {
        accessManager.setAssignedRoles(forAnySignedInUser(), projectResource, emptySet());
    }
    for (SharingSetting setting : map.values()) {
        PersonId personId = setting.getPersonId();
        Optional<UserId> userId = userLookup.getUserByUserIdOrEmail(personId.getId());
        if (userId.isPresent()) {
            ImmutableSet<RoleId> roles = Roles.fromSharingPermission(setting.getSharingPermission());
            accessManager.setAssignedRoles(forUser(userId.get()), projectResource, roles);
        } else {
            logger.info("User in sharing setting not found.  An email invitation needs to be sent");
        // TODO
        // We need to send the user an email invitation
        }
    }
}
Also used : Subject(edu.stanford.bmir.protege.web.server.access.Subject) java.util(java.util) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) RoleId(edu.stanford.bmir.protege.web.shared.access.RoleId) Collections.emptySet(java.util.Collections.emptySet) Subject.forUser(edu.stanford.bmir.protege.web.server.access.Subject.forUser) LoggerFactory(org.slf4j.LoggerFactory) PersonId(edu.stanford.bmir.protege.web.shared.sharing.PersonId) SharingSetting(edu.stanford.bmir.protege.web.shared.sharing.SharingSetting) Inject(javax.inject.Inject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Collectors.toMap(java.util.stream.Collectors.toMap) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) Subject.forAnySignedInUser(edu.stanford.bmir.protege.web.server.access.Subject.forAnySignedInUser) SharingPermission(edu.stanford.bmir.protege.web.shared.sharing.SharingPermission) HasGetUserIdByUserIdOrEmail(edu.stanford.bmir.protege.web.server.user.HasGetUserIdByUserIdOrEmail) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectResource(edu.stanford.bmir.protege.web.server.access.ProjectResource) ProjectSharingSettings(edu.stanford.bmir.protege.web.shared.sharing.ProjectSharingSettings) SharingPermission(edu.stanford.bmir.protege.web.shared.sharing.SharingPermission) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) RoleId(edu.stanford.bmir.protege.web.shared.access.RoleId) PersonId(edu.stanford.bmir.protege.web.shared.sharing.PersonId) SharingSetting(edu.stanford.bmir.protege.web.shared.sharing.SharingSetting) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ProjectResource(edu.stanford.bmir.protege.web.server.access.ProjectResource)

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