Search in sources :

Example 1 with UserDetailsManager

use of edu.stanford.bmir.protege.web.server.user.UserDetailsManager in project webprotege by protegeproject.

the class WatchTriggeredHandlerImpl method handleWatchTriggered.

@Override
public void handleWatchTriggered(@Nonnull Set<UserId> usersToNotify, @Nonnull OWLEntity modifiedEntity, @Nonnull UserId byUser) {
    List<String> emailAddresses = usersToNotify.stream().filter(u -> accessManager.hasPermission(forUser(u), forProject(projectId), VIEW_PROJECT)).map(userDetailsManager::getEmail).filter(Optional::isPresent).map(Optional::get).distinct().collect(toList());
    OWLEntityData modifiedEntityData = renderingManager.getRendering(modifiedEntity);
    Map<String, Object> templateObjects = TemplateObjectsBuilder.builder().withUserId(byUser).withEntity(modifiedEntityData).withProjectDetails(projectDetailsManager.getProjectDetails(projectId)).withApplicationName(applicationNameSupplier.get()).withProjectUrl(placeUrl.getProjectUrl(projectId)).build();
    String displayName = projectDetailsManager.getProjectDetails(projectId).getDisplayName();
    String emailSubject = String.format("[%s] Changes made to %s in %s by %s", displayName, modifiedEntityData.getBrowserText(), displayName, userDetailsManager.getUserDetails(byUser).map(d -> "by " + d.getDisplayName()).orElse(""));
    String emailBody = templateEngine.populateTemplate(watchTemplate.getContents(), templateObjects);
    logger.info("{} Watch triggered by {} on {}.  Notifying {}", projectId, byUser, modifiedEntity, usersToNotify);
    sendMail.sendMail(emailAddresses, emailSubject, emailBody, MessageHeader.inReplyTo(projectId.getId()), MessageHeader.references(projectId.getId()));
}
Also used : SendMail(edu.stanford.bmir.protege.web.server.mail.SendMail) LoggerFactory(org.slf4j.LoggerFactory) Inject(javax.inject.Inject) RenderingManager(edu.stanford.bmir.protege.web.server.renderer.RenderingManager) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) AccessManager(edu.stanford.bmir.protege.web.server.access.AccessManager) ProjectDetailsManager(edu.stanford.bmir.protege.web.server.project.ProjectDetailsManager) TemplateObjectsBuilder(edu.stanford.bmir.protege.web.server.templates.TemplateObjectsBuilder) Map(java.util.Map) Nonnull(javax.annotation.Nonnull) FileContents(edu.stanford.bmir.protege.web.server.filemanager.FileContents) UserDetailsManager(edu.stanford.bmir.protege.web.server.user.UserDetailsManager) Logger(org.slf4j.Logger) MessageHeader(edu.stanford.bmir.protege.web.server.mail.MessageHeader) PlaceUrl(edu.stanford.bmir.protege.web.server.app.PlaceUrl) Subject.forUser(edu.stanford.bmir.protege.web.server.access.Subject.forUser) VIEW_PROJECT(edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT) Set(java.util.Set) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) ApplicationNameSupplier(edu.stanford.bmir.protege.web.server.app.ApplicationNameSupplier) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Optional(java.util.Optional) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) ProjectResource.forProject(edu.stanford.bmir.protege.web.server.access.ProjectResource.forProject) TemplateEngine(edu.stanford.bmir.protege.web.server.templates.TemplateEngine) Optional(java.util.Optional) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)

Aggregations

AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)1 ProjectResource.forProject (edu.stanford.bmir.protege.web.server.access.ProjectResource.forProject)1 Subject.forUser (edu.stanford.bmir.protege.web.server.access.Subject.forUser)1 ApplicationNameSupplier (edu.stanford.bmir.protege.web.server.app.ApplicationNameSupplier)1 PlaceUrl (edu.stanford.bmir.protege.web.server.app.PlaceUrl)1 FileContents (edu.stanford.bmir.protege.web.server.filemanager.FileContents)1 MessageHeader (edu.stanford.bmir.protege.web.server.mail.MessageHeader)1 SendMail (edu.stanford.bmir.protege.web.server.mail.SendMail)1 ProjectDetailsManager (edu.stanford.bmir.protege.web.server.project.ProjectDetailsManager)1 RenderingManager (edu.stanford.bmir.protege.web.server.renderer.RenderingManager)1 TemplateEngine (edu.stanford.bmir.protege.web.server.templates.TemplateEngine)1 TemplateObjectsBuilder (edu.stanford.bmir.protege.web.server.templates.TemplateObjectsBuilder)1 UserDetailsManager (edu.stanford.bmir.protege.web.server.user.UserDetailsManager)1 VIEW_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT)1 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)1 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1