Search in sources :

Example 1 with SlackWebhook

use of edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook 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 2 with SlackWebhook

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

Example 3 with SlackWebhook

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

the class SlackWebhookRepository_IT method setUp.

@Before
public void setUp() {
    mongoClient = MongoTestUtils.createMongoClient();
    Morphia morphia = MongoTestUtils.createMorphia();
    datastore = morphia.createDatastore(mongoClient, MongoTestUtils.getTestDbName());
    repository = new SlackWebhookRepositoryImpl(datastore);
    repository.ensureIndexes();
    slackWebhookA = new SlackWebhook(projectId, PAYLOAD_URL_A);
    slackWebhookB = new SlackWebhook(projectId, PAYLOAD_URL_B);
}
Also used : Morphia(org.mongodb.morphia.Morphia) SlackWebhook(edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook) Before(org.junit.Before)

Aggregations

SlackWebhook (edu.stanford.bmir.protege.web.shared.webhook.SlackWebhook)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 ProjectDetails (edu.stanford.bmir.protege.web.shared.project.ProjectDetails)2 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)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 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)2 ProjectWebhook (edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhook)2 ProjectWebhookEventType (edu.stanford.bmir.protege.web.shared.webhook.ProjectWebhookEventType)2 java.util (java.util)2 Collectors.toList (java.util.stream.Collectors.toList)2 Inject (javax.inject.Inject)2 Before (org.junit.Before)1 Morphia (org.mongodb.morphia.Morphia)1