Search in sources :

Example 1 with ProjectDetails

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

the class LoadProjectActionHandler method execute.

@Nonnull
@Override
public LoadProjectResult execute(@Nonnull final LoadProjectAction action, @Nonnull ExecutionContext executionContext) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    logger.info("{} is being loaded due to request by {}", action.getProjectId(), executionContext.getUserId());
    projectManager.getProject(action.getProjectId(), executionContext.getUserId());
    stopwatch.stop();
    logger.info("{} was loaded in {} ms due to request by {}", action.getProjectId(), stopwatch.elapsed(TimeUnit.MILLISECONDS), executionContext.getUserId());
    MemoryMonitor memoryMonitor = new MemoryMonitor(logger);
    memoryMonitor.monitorMemoryUsage();
    memoryMonitor.logMemoryUsage();
    final ProjectId projectId = action.getProjectId();
    ProjectDetails projectDetails = projectDetailsManager.getProjectDetails(projectId);
    if (!executionContext.getUserId().isGuest()) {
        userActivityManager.addRecentProject(executionContext.getUserId(), action.getProjectId(), System.currentTimeMillis());
    }
    return new LoadProjectResult(action.getProjectId(), executionContext.getUserId(), projectDetails);
}
Also used : MemoryMonitor(edu.stanford.bmir.protege.web.server.util.MemoryMonitor) ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails) Stopwatch(com.google.common.base.Stopwatch) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) LoadProjectResult(edu.stanford.bmir.protege.web.shared.project.LoadProjectResult) Nonnull(javax.annotation.Nonnull)

Example 2 with ProjectDetails

use of edu.stanford.bmir.protege.web.shared.project.ProjectDetails 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);
}
Also used : UnknownProjectException(edu.stanford.bmir.protege.web.shared.project.UnknownProjectException) WebhookRepository(edu.stanford.bmir.protege.web.server.webhook.WebhookRepository) java.util(java.util) ProjectWebhook(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhook) SlackIntegrationSettings(edu.stanford.bmir.protege.web.shared.projectsettings.SlackIntegrationSettings) ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails) WebhookSettings(edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSettings) ProjectWebhookEventType(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhookEventType) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SlackWebhookRepository(edu.stanford.bmir.protege.web.server.webhook.SlackWebhookRepository) Inject(javax.inject.Inject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Collectors.toList(java.util.stream.Collectors.toList) NewProjectSettings(edu.stanford.bmir.protege.web.shared.project.NewProjectSettings) SlackWebhook(edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook) WebhookSetting(edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSetting) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectSettings(edu.stanford.bmir.protege.web.shared.projectsettings.ProjectSettings) ProjectWebhookEventType(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhookEventType) ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectWebhook(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhook) SlackWebhook(edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook)

Example 3 with ProjectDetails

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

the class ProjectDetailsManagerImpl method registerProject.

@Override
public void registerProject(ProjectId projectId, NewProjectSettings settings) {
    long now = System.currentTimeMillis();
    ProjectDetails record = new ProjectDetails(projectId, settings.getDisplayName(), settings.getProjectDescription(), settings.getProjectOwner(), false, now, settings.getProjectOwner(), now, settings.getProjectOwner());
    repository.save(record);
}
Also used : ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails)

Example 4 with ProjectDetails

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

the class ProjectDetailsConverter method fromDocument.

@Override
public ProjectDetails fromDocument(@Nonnull Document document) {
    ProjectId projectId = ProjectId.get(document.getString(PROJECT_ID));
    String displayName = document.getString(DISPLAY_NAME);
    String description = Optional.ofNullable(document.getString(DESCRIPTION)).orElse("");
    UserId owner = UserId.getUserId(document.getString(OWNER));
    boolean inTrash = document.getBoolean(IN_TRASH, false);
    long createdAt = Optional.ofNullable(document.getDate(CREATED_AT)).map(Date::getTime).orElse(0L);
    UserId createdBy = UserId.getUserId(Optional.ofNullable(document.getString(CREATED_BY)).orElse(owner.getUserName()));
    long lastModifiedAt = Optional.ofNullable(document.getDate(MODIFIED_AT)).map(Date::getTime).orElse(0L);
    UserId lastModifiedBy = UserId.getUserId(Optional.ofNullable(document.getString(MODIFIED_BY)).orElse(owner.getUserName()));
    return new ProjectDetails(projectId, displayName, description, owner, inTrash, createdAt, createdBy, lastModifiedAt, lastModifiedBy);
}
Also used : ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId)

Example 5 with ProjectDetails

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

the class ProjectDetailsManagerImpl method getProjectSettings.

@Override
public ProjectSettings getProjectSettings(ProjectId projectId) throws UnknownProjectException {
    List<SlackWebhook> projectWebhooks = slackWebhookRepository.getWebhooks(projectId);
    String slackPayloadUrl = projectWebhooks.stream().findFirst().map(SlackWebhook::getPayloadUrl).orElse("");
    List<WebhookSetting> webhookSettings = webhookRepository.getProjectWebhooks(projectId).stream().map(wh -> new WebhookSetting(wh.getPayloadUrl(), new LinkedHashSet<ProjectWebhookEventType>(wh.getSubscribedToEvents()))).collect(toList());
    ProjectDetails projectDetails = getProjectDetails(projectId);
    return new ProjectSettings(projectId, projectDetails.getDisplayName(), projectDetails.getDescription(), new SlackIntegrationSettings(slackPayloadUrl), new WebhookSettings(webhookSettings));
}
Also used : UnknownProjectException(edu.stanford.bmir.protege.web.shared.project.UnknownProjectException) WebhookRepository(edu.stanford.bmir.protege.web.server.webhook.WebhookRepository) java.util(java.util) ProjectWebhook(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhook) SlackIntegrationSettings(edu.stanford.bmir.protege.web.shared.projectsettings.SlackIntegrationSettings) ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails) WebhookSettings(edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSettings) ProjectWebhookEventType(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhookEventType) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SlackWebhookRepository(edu.stanford.bmir.protege.web.server.webhook.SlackWebhookRepository) Inject(javax.inject.Inject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Collectors.toList(java.util.stream.Collectors.toList) NewProjectSettings(edu.stanford.bmir.protege.web.shared.project.NewProjectSettings) SlackWebhook(edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook) WebhookSetting(edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSetting) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectSettings(edu.stanford.bmir.protege.web.shared.projectsettings.ProjectSettings) ProjectWebhookEventType(edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhookEventType) ProjectDetails(edu.stanford.bmir.protege.web.shared.project.ProjectDetails) WebhookSettings(edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSettings) SlackWebhook(edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook) WebhookSetting(edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSetting) SlackIntegrationSettings(edu.stanford.bmir.protege.web.shared.projectsettings.SlackIntegrationSettings) NewProjectSettings(edu.stanford.bmir.protege.web.shared.project.NewProjectSettings) ProjectSettings(edu.stanford.bmir.protege.web.shared.projectsettings.ProjectSettings)

Aggregations

ProjectDetails (edu.stanford.bmir.protege.web.shared.project.ProjectDetails)7 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)4 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 SlackWebhookRepository (edu.stanford.bmir.protege.web.server.webhook.SlackWebhookRepository)2 WebhookRepository (edu.stanford.bmir.protege.web.server.webhook.WebhookRepository)2 NewProjectSettings (edu.stanford.bmir.protege.web.shared.project.NewProjectSettings)2 UnknownProjectException (edu.stanford.bmir.protege.web.shared.project.UnknownProjectException)2 ProjectSettings (edu.stanford.bmir.protege.web.shared.projectsettings.ProjectSettings)2 SlackIntegrationSettings (edu.stanford.bmir.protege.web.shared.projectsettings.SlackIntegrationSettings)2 WebhookSetting (edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSetting)2 WebhookSettings (edu.stanford.bmir.protege.web.shared.projectsettings.WebhookSettings)2 ProjectWebhook (edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhook)2 ProjectWebhookEventType (edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhookEventType)2 SlackWebhook (edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook)2 java.util (java.util)2 Collectors.toList (java.util.stream.Collectors.toList)2 Inject (javax.inject.Inject)2 Stopwatch (com.google.common.base.Stopwatch)1 MongoClient (com.mongodb.MongoClient)1