Skip to content

Commit

Permalink
Merge pull request #383 from edmcouncil/Incomplete-update-of-onto-viewer
Browse files Browse the repository at this point in the history
fix problem in MetadataHandler at Incomplete-update-of-onto-viewer
  • Loading branch information
mereolog authored Feb 15, 2024
2 parents edc0b19 + 611e4db commit d7c9367
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.edmcouncil.spec.ontoviewer.core.ontology.data.handler.module.ModuleHandler;
import org.edmcouncil.spec.ontoviewer.core.ontology.data.handler.data.AnnotationsDataHandler;
import org.edmcouncil.spec.ontoviewer.core.ontology.data.label.LabelProvider;
import org.edmcouncil.spec.ontoviewer.core.ontology.updater.model.UpdateJobStatus;
import org.edmcouncil.spec.ontoviewer.core.ontology.updater.util.UpdateJobIdGenerator;
import org.edmcouncil.spec.ontoviewer.core.ontology.updater.util.UpdaterOperation;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
Expand Down Expand Up @@ -44,6 +47,8 @@ public MetadataHandler(LabelProvider labelProvider, ModuleHelper moduleHelper,

private final Map<IRI, OntologyResources> resources = new HashMap<>();

private long numberOfResourcesUpdates = 0;

public OwlListDetails handle(IRI iri) {

OwlListDetails ontologyDetails = new OwlListDetails();
Expand Down Expand Up @@ -94,6 +99,9 @@ public OwlDetailsProperties<PropertyValue> handle(IRI iri, OwlListDetails detail
}

private OntologyResources getOntologyResources(IRI ontologyIri) {

clearResourcesAfterUpdate();

if (!resources.containsKey(ontologyIri)) {
var owlOntologyOptional = ontologyManager.getOntologyWithImports()
.filter(owlOntology -> {
Expand All @@ -111,4 +119,13 @@ private OntologyResources getOntologyResources(IRI ontologyIri) {
}
return resources.get(ontologyIri);
}
}

private void clearResourcesAfterUpdate() {
final long numberOfOntologyUpdates = UpdateJobIdGenerator.getCurrentID();
final UpdateJobStatus statusOfLastUpdate = UpdaterOperation.getLastStatusFromLastJob();
if (numberOfOntologyUpdates > numberOfResourcesUpdates && UpdateJobStatus.DONE.equals(statusOfLastUpdate)) {
resources.clear();
numberOfResourcesUpdates = numberOfOntologyUpdates;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ public static long nextId() {
return id++;
}

public static long getCurrentID(){
return id;
}

public static String nextStringId() {
long tmp = id++;
return String.valueOf(tmp);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,49 @@
public class UpdaterOperation {

private static Logger LOG = LoggerFactory.getLogger(UpdaterOperation.class);
public static UpdateJobStatus lastStatusFromLastJob;

public static UpdateJob setJobStatusToInProgress(UpdateJob job) {
public static UpdateJob setJobStatusToInProgress(UpdateJob job) {
job.setStatus(UpdateJobStatus.IN_PROGRESS);
lastStatusFromLastJob = UpdateJobStatus.IN_PROGRESS;
job.setMsg("");
LOG.debug(job.toString());
return job;
}

public static UpdateJob setJobStatusToError(UpdateJob job, String msgError) {
job.setStatus(UpdateJobStatus.ERROR);
lastStatusFromLastJob = UpdateJobStatus.ERROR;
job.setMsg(msgError);
LOG.debug(job.toString());
return job;
}

public static UpdateJob setJobStatusToDone(UpdateJob job) {
job.setStatus(UpdateJobStatus.DONE);
lastStatusFromLastJob = UpdateJobStatus.DONE;
job.setMsg("");
LOG.debug(job.toString());
return job;
}

public static UpdateJob setJobStatusToWaiting(UpdateJob job, String msg) {
job.setStatus(UpdateJobStatus.WAITING);
lastStatusFromLastJob = UpdateJobStatus.WAITING;
job.setMsg(msg);
LOG.debug(job.toString());
return job;
}

public static UpdateJob setJobStatusToInterrupt(UpdateJob job, String msg) {
job.setStatus(UpdateJobStatus.INTERRUPT_IN_PROGRESS);
lastStatusFromLastJob = UpdateJobStatus.INTERRUPT_IN_PROGRESS;
job.setMsg(msg);
LOG.debug(job.toString());
return job;
}

}
public static UpdateJobStatus getLastStatusFromLastJob() {
return lastStatusFromLastJob;
}
}

0 comments on commit d7c9367

Please sign in to comment.