use of edu.stanford.bmir.protege.web.server.change.ChangeApplicationResult in project webprotege by protegeproject.
the class HighLevelEventGenerator method translateOntologyChanges.
@Override
public void translateOntologyChanges(Revision revision, ChangeApplicationResult<?> changes, final List<ProjectEvent<?>> projectEventList) {
// TODO: NEED TIDYING AND SPLITTING UP
final Set<OWLEntity> changedEntities = new HashSet<>();
for (OWLOntologyChange change : changes.getChangeList()) {
change.accept(new OWLOntologyChangeVisitor() {
@Override
public void visit(@Nonnull AddAxiom change) {
final OWLAxiom axiom = change.getAxiom();
handleAxiomChange(axiom);
}
@Override
public void visit(@Nonnull RemoveAxiom change) {
handleAxiomChange(change.getAxiom());
}
@Override
public void visit(@Nonnull SetOntologyID change) {
projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
}
@Override
public void visit(@Nonnull AddImport change) {
projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
}
@Override
public void visit(@Nonnull RemoveImport change) {
projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
}
@Override
public void visit(@Nonnull AddOntologyAnnotation change) {
projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
}
@Override
public void visit(@Nonnull RemoveOntologyAnnotation change) {
projectEventList.add(new OntologyFrameChangedEvent(change.getOntology().getOntologyID(), projectId));
}
private void handleAxiomChange(OWLAxiom axiom) {
AxiomSubjectProvider p = new AxiomSubjectProvider();
OWLObject subject = p.getSubject(axiom);
Set<OWLEntity> entities;
if (subject instanceof IRI) {
entities = hasGetEntitiesWithIRI.getEntitiesWithIRI((IRI) subject);
} else if (subject instanceof OWLEntity) {
entities = Collections.singleton((OWLEntity) subject);
} else {
entities = Collections.emptySet();
}
for (OWLEntity e : entities) {
if (!changedEntities.contains(e)) {
changedEntities.add(e);
ProjectEvent<?> event = e.accept(new OWLEntityVisitorEx<ProjectEvent<?>>() {
@Nonnull
@Override
public ProjectEvent<?> visit(@Nonnull OWLClass cls) {
return new ClassFrameChangedEvent(cls, projectId, revision.getUserId());
}
@Nonnull
@Override
public ProjectEvent<?> visit(@Nonnull OWLObjectProperty property) {
return new ObjectPropertyFrameChangedEvent(property, projectId, revision.getUserId());
}
@Nonnull
@Override
public ProjectEvent<?> visit(@Nonnull OWLDataProperty property) {
return new DataPropertyFrameChangedEvent(property, projectId, revision.getUserId());
}
@Nonnull
@Override
public ProjectEvent<?> visit(@Nonnull OWLNamedIndividual individual) {
return new NamedIndividualFrameChangedEvent(individual, projectId, revision.getUserId());
}
@Nonnull
@Override
public ProjectEvent<?> visit(@Nonnull OWLDatatype datatype) {
return new DatatypeFrameChangedEvent(datatype, projectId, revision.getUserId());
}
@Nonnull
@Override
public ProjectEvent<?> visit(@Nonnull OWLAnnotationProperty property) {
return new AnnotationPropertyFrameChangedEvent(property, projectId, revision.getUserId());
}
});
projectEventList.add(event);
}
}
}
});
}
Set<OWLEntityData> changedEntitiesData = new HashSet<>();
Object subject = changes.getSubject();
if (subject instanceof OWLEntity) {
OWLEntity entity = (OWLEntity) subject;
if (rootOntology.containsEntityInSignature(entity)) {
String browserText = browserTextProvider.getOWLEntityBrowserText(entity).orElse("");
changedEntitiesData.add(DataFactory.getOWLEntityData(entity, browserText));
}
} else if (subject instanceof OWLEntityData) {
OWLEntityData entityData = (OWLEntityData) subject;
if (rootOntology.containsEntityInSignature(entityData.getEntity())) {
changedEntitiesData.add(entityData);
}
} else if (subject instanceof Collection) {
Collection<?> collection = (Collection<?>) subject;
collection.stream().filter(element -> element instanceof OWLEntity).map(element -> (OWLEntity) element).filter(rootOntology::containsEntityInSignature).forEach(entity -> {
String browserText = browserTextProvider.getOWLEntityBrowserText(entity).orElse("");
changedEntitiesData.add(DataFactory.getOWLEntityData(entity, browserText));
});
}
Optional<RevisionSummary> revisionSummary = hasGetRevisionSummary.getRevisionSummary(revision.getRevisionNumber());
if (revisionSummary.isPresent()) {
ProjectEvent<?> event = new ProjectChangedEvent(projectId, revisionSummary.get(), changedEntitiesData);
projectEventList.add(event);
}
}
Aggregations