Search in sources :

Example 11 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class HierarchyChangeComputer method prepareForOntologyChanges.

@SuppressWarnings("unchecked")
@Override
public void prepareForOntologyChanges(List<OWLOntologyChange> submittedChanges) {
    for (OWLOntologyChange change : submittedChanges) {
        for (OWLEntity entity : change.getSignature()) {
            if (entity.isType(entityType)) {
                final T t = (T) entity;
                final Set<T> parentsBefore = hierarchyProvider.getParents(t);
                child2ParentMap.putAll(t, parentsBefore);
            }
        }
    }
    roots.addAll(hierarchyProvider.getRoots());
}
Also used : OWLOntologyChange(org.semanticweb.owlapi.model.OWLOntologyChange) OWLEntity(org.semanticweb.owlapi.model.OWLEntity)

Example 12 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class HierarchyChangeComputer method translateOntologyChanges.

@SuppressWarnings("unchecked")
@Override
public void translateOntologyChanges(Revision revision, ChangeApplicationResult<?> result, List<ProjectEvent<?>> projectEventList) {
    Set<T> changeSignature = new HashSet<>();
    for (OWLOntologyChange change : result.getChangeList()) {
        for (OWLEntity child : change.getSignature()) {
            if (child.isType(entityType)) {
                final T t = (T) child;
                if (!changeSignature.contains(t)) {
                    changeSignature.add(t);
                    Set<T> parentsBefore = child2ParentMap.get(t);
                    Set<T> parentsAfter = hierarchyProvider.getParents(t);
                    for (T parentBefore : parentsBefore) {
                        if (!parentsAfter.contains(parentBefore)) {
                            // Removed
                            projectEventList.addAll(createRemovedEvents(t, parentBefore));
                        }
                    }
                    for (T parentAfter : parentsAfter) {
                        if (!parentsBefore.contains(parentAfter)) {
                            // Added
                            projectEventList.addAll(createAddedEvents(t, parentAfter));
                        }
                    }
                }
            }
        }
    }
    Set<T> rootsAfter = new HashSet<>(hierarchyProvider.getRoots());
    for (T rootAfter : rootsAfter) {
        if (!roots.contains(rootAfter)) {
            List<GraphModelChange<EntityHierarchyNode>> changes = Collections.singletonList(new AddRootNode<>(new GraphNode<>(renderer.render(rootAfter), hierarchyProvider.getChildren(rootAfter).isEmpty())));
            EntityHierarchyChangedEvent event = new EntityHierarchyChangedEvent(projectId, hierarchyId, new GraphModelChangedEvent<>(changes));
            projectEventList.add(event);
            projectEventList.add(new HierarchyRootAddedEvent<>(projectId, hierarchyId, rootAfter));
        }
    }
    for (T rootBefore : roots) {
        if (!rootsAfter.contains(rootBefore)) {
            List<GraphModelChange<EntityHierarchyNode>> changes = Collections.singletonList(new RemoveRootNode<>(new GraphNode<>(renderer.render(rootBefore))));
            EntityHierarchyChangedEvent event = new EntityHierarchyChangedEvent(projectId, hierarchyId, new GraphModelChangedEvent<>(changes));
            projectEventList.add(event);
            projectEventList.add(new HierarchyRootRemovedEvent<>(projectId, hierarchyId, rootBefore));
        }
    }
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) OWLOntologyChange(org.semanticweb.owlapi.model.OWLOntologyChange)

Example 13 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity 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)

Example 14 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class OWLEntityReadConverter_TestCase method shouldReadOWLObjectProperty.

@Test
public void shouldReadOWLObjectProperty() {
    when(dbObject.get("type")).thenReturn(EntityType.OBJECT_PROPERTY.getName());
    OWLEntity entity = converter.convert(dbObject);
    assertThat(entity.isOWLObjectProperty(), is(true));
    assertThat(entity.getIRI(), is(iri));
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Test(org.junit.Test)

Example 15 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class OWLEntityReadConverter_TestCase method shouldReadOWLDatatype.

@Test
public void shouldReadOWLDatatype() {
    when(dbObject.get("type")).thenReturn(EntityType.DATATYPE.getName());
    OWLEntity entity = converter.convert(dbObject);
    assertThat(entity.isOWLDatatype(), is(true));
    assertThat(entity.getIRI(), is(iri));
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) Test(org.junit.Test)

Aggregations

OWLEntity (org.semanticweb.owlapi.model.OWLEntity)45 Test (org.junit.Test)13 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)7 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 Inject (javax.inject.Inject)6 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)5 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)4 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)3 IRI (org.semanticweb.owlapi.model.IRI)3 DBObject (com.mongodb.DBObject)2 EntitySuggestion (edu.stanford.bmir.protege.web.client.library.suggest.EntitySuggestion)2 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)2 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)2 VIEW_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT)2 ColumnType (edu.stanford.bmir.protege.web.shared.csv.ColumnType)2 OWLPrimitiveData (edu.stanford.bmir.protege.web.shared.entity.OWLPrimitiveData)2 ProjectEvent (edu.stanford.bmir.protege.web.shared.event.ProjectEvent)2 Comparator.comparing (java.util.Comparator.comparing)2