Skip to content

Commit

Permalink
changed call for the logical definitions superclass ancestors to GetC…
Browse files Browse the repository at this point in the history
…lassAncestorsWithLinearizationAction.
  • Loading branch information
soimugeo committed Nov 5, 2024
1 parent 3f52b61 commit 49c4e5d
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package edu.stanford.bmir.protege.web.client.logicaldefinition;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.*;
import com.google.gwt.user.client.ui.*;
import edu.stanford.bmir.protege.web.client.dispatch.DispatchServiceManager;
import edu.stanford.bmir.protege.web.client.hierarchy.HierarchyPopupPresenterFactory;
Expand All @@ -11,16 +10,12 @@
import edu.stanford.bmir.protege.web.client.uuid.UuidV4Provider;
import edu.stanford.bmir.protege.web.resources.WebProtegeClientBundle;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.event.WebProtegeEventBus;
import edu.stanford.bmir.protege.web.shared.icd.AncestorClassHierarchy;
import edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsAction;
import edu.stanford.bmir.protege.web.shared.icd.*;
import edu.stanford.bmir.protege.web.shared.logicaldefinition.*;
import edu.stanford.bmir.protege.web.shared.perspective.ChangeRequestId;
import edu.stanford.bmir.protege.web.shared.postcoordination.*;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.*;
import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -51,10 +46,13 @@ public class LogicalDefinitionPortletViewImpl extends Composite implements Logic
@UiField
HTMLPanel necessaryConditionsTooltip;

@UiField Button editValuesButton;
@UiField Button cancelButton;
@UiField
Button editValuesButton;
@UiField
Button cancelButton;

@UiField Button saveValuesButton;
@UiField
Button saveValuesButton;

private static final LogicalDefinitionPortletViewImpl.LogicalDefinitionPortletViewImplUiBinder ourUiBinder = GWT.create(LogicalDefinitionPortletViewImpl.LogicalDefinitionPortletViewImplUiBinder.class);

Expand Down Expand Up @@ -117,14 +115,15 @@ public LogicalDefinitionPortletViewImpl(@Nonnull DispatchServiceManager dispatch

initWidget(ourUiBinder.createAndBindUi(this));

dispatchServiceManager.execute(GetPostcoordinationAxisToGenericScaleAction.create(), result -> {
this.axisToGenericScales = result.getPostcoordinationAxisToGenericScales();
});
dispatchServiceManager.execute(
GetPostcoordinationAxisToGenericScaleAction.create(),
result -> this.axisToGenericScales = result.getPostcoordinationAxisToGenericScales()
);

this.addDefinitionButton.setStyleName(buttonCss.addButton());

this.addDefinitionButton.addClickHandler((event -> {
if(tableWrappers.isEmpty()) {
if (tableWrappers.isEmpty()) {
definitions.clear();
}
LogicalDefinitionTableWrapper newTable = new LogicalDefinitionTableBuilder(dispatchServiceManager,
Expand All @@ -146,9 +145,7 @@ public LogicalDefinitionPortletViewImpl(@Nonnull DispatchServiceManager dispatch
this.saveValuesButton.addClickHandler(event -> saveValues());
displayPlaceholder();

cancelButton.addClickHandler((event) -> {
this.setEntity(this.currentEntity, this.projectId);
});
cancelButton.addClickHandler((event) -> this.setEntity(this.currentEntity, this.projectId));

this.setHelpText(this.logicalDefinitionsTooltip, "A Logical Definition provides a way to formally define the meaning of a precoordinated entity by " +
"specifying a parent entity with combinations of postcoordination axes with their corresponding values.");
Expand All @@ -162,6 +159,7 @@ public LogicalDefinitionPortletViewImpl(@Nonnull DispatchServiceManager dispatch
public void setWidget(IsWidget w) {

}

@Override
public void dispose() {

Expand All @@ -183,10 +181,8 @@ public void setEntity(OWLEntity owlEntity, ProjectId projectId) {
this.necessaryConditionsTable.setSuperclassScalesValue(superclassScalesValue);
});

dispatchServiceManager.execute(GetClassAncestorsAction.create(owlEntity.getIRI(), projectId), getHierarchyParentsResult -> {
Set<OWLEntityData> result = new HashSet<>();
populateAncestorsFromTree(getHierarchyParentsResult.getAncestorsTree(), result);
ancestorsList = new ArrayList<>(result);
dispatchServiceManager.execute(GetClassAncestorsWithLinearizationAction.create(owlEntity.getIRI(), projectId), result -> {
ancestorsList = new ArrayList<>(result.getAncestorsWithLinearization());

dispatchServiceManager.execute(GetPostCoordinationTableConfigurationAction.create("ICD"), config -> {
this.labels = config.getLabels();
Expand All @@ -202,16 +198,16 @@ public void setEntity(OWLEntity owlEntity, ProjectId projectId) {

@Override
public void setEntityData(OWLEntityData entityData) {
this.entityData =entityData;
this.entityData = entityData;
}

private void populateWithExistingDefinition(OWLEntity owlEntity, ProjectId projectId) {
dispatchServiceManager.execute(GetEntityLogicalDefinitionAction.create(projectId, owlEntity.asOWLClass()), (GetEntityLogicalDefinitionResult getEntityLogicalDefinitionResult) -> {
this.pristineData = LogicalConditions.create(getEntityLogicalDefinitionResult.getLogicalDefinitions(), getEntityLogicalDefinitionResult.getNecessaryConditions());
if(getEntityLogicalDefinitionResult.getLogicalDefinitions() != null && !getEntityLogicalDefinitionResult.getLogicalDefinitions().isEmpty()) {
if (getEntityLogicalDefinitionResult.getLogicalDefinitions() != null && !getEntityLogicalDefinitionResult.getLogicalDefinitions().isEmpty()) {
definitions.getElement().getStyle().setBackgroundImage(null);

for(LogicalDefinition logicalDefinition : getEntityLogicalDefinitionResult.getLogicalDefinitions()) {
for (LogicalDefinition logicalDefinition : getEntityLogicalDefinitionResult.getLogicalDefinitions()) {
List<LogicalDefinitionTableRow> superClassTableRows = logicalDefinition.getAxis2filler().stream()
.map(LogicalDefinitionTableRow::new)
.collect(Collectors.toList());
Expand All @@ -235,7 +231,7 @@ private void populateWithExistingDefinition(OWLEntity owlEntity, ProjectId proje
} else {
displayPlaceholder();
}
if(getEntityLogicalDefinitionResult.getNecessaryConditions() != null && !getEntityLogicalDefinitionResult.getNecessaryConditions().isEmpty()) {
if (getEntityLogicalDefinitionResult.getNecessaryConditions() != null && !getEntityLogicalDefinitionResult.getNecessaryConditions().isEmpty()) {

List<LogicalDefinitionTableRow> necessaryConditionsTableRows = getEntityLogicalDefinitionResult.getNecessaryConditions().stream()
.map(LogicalDefinitionTableRow::new)
Expand All @@ -256,7 +252,7 @@ private void handleAxisValueChanged(String postCoordinationAxis, LogicalDefiniti
.flatMap(s -> s.getPostcoordinationScaleValues().stream())
.collect(Collectors.toList());

if(selectedScales.isEmpty()) {
if (selectedScales.isEmpty()) {
List<String> equivalentRoots = axisToGenericScales.stream()
.filter(axis -> axis.getPostcoordinationAxis().equalsIgnoreCase(postCoordinationAxis))
.map(PostcoordinationAxisToGenericScale::getGenericPostcoordinationScaleTopClass)
Expand All @@ -267,9 +263,7 @@ private void handleAxisValueChanged(String postCoordinationAxis, LogicalDefiniti
Set<OWLClass> roots = selectedScales.stream().map(scale -> new OWLClassImpl(IRI.create(scale)))
.collect(Collectors.toSet());

logicalDefinitionModal.showModal(roots, (entityNode) -> {
table.addNewRow(entityNode);
});
logicalDefinitionModal.showModal(roots, table::addNewRow);
}

private void initializeTable(String postCoordinationAxis, LogicalDefinitionTable table) {
Expand All @@ -278,7 +272,7 @@ private void initializeTable(String postCoordinationAxis, LogicalDefinitionTable
.flatMap(s -> s.getPostcoordinationScaleValues().stream())
.collect(Collectors.toList());

if(selectedScales.isEmpty()) {
if (selectedScales.isEmpty()) {
List<String> equivalentRoots = axisToGenericScales.stream()
.filter(axis -> axis.getPostcoordinationAxis().equalsIgnoreCase(postCoordinationAxis))
.map(PostcoordinationAxisToGenericScale::getGenericPostcoordinationScaleTopClass)
Expand All @@ -287,7 +281,7 @@ private void initializeTable(String postCoordinationAxis, LogicalDefinitionTable
}

Map<String, String> map = new HashMap<>();
for(String availableAxis : selectedScales) {
for (String availableAxis : selectedScales) {
map.put(availableAxis, availableAxis);
}

Expand All @@ -298,9 +292,9 @@ private void populateAvailableAxisValues(OWLEntity owlEntity) {
dispatchServiceManager.execute(GetEntityPostCoordinationAction.create(owlEntity.getIRI().toString(), projectId), postcoordination -> {

this.superclassSpecification = postcoordination.getPostCoordinationSpecification();
if(this.superclassSpecification.getPostCoordinationSpecifications() != null) {
if (this.superclassSpecification.getPostCoordinationSpecifications() != null) {
Optional<PostCoordinationSpecification> mmsSpec = this.superclassSpecification.getPostCoordinationSpecifications()
.stream().filter( spec -> spec.getLinearizationView().equalsIgnoreCase("http://id.who.int/icd/release/11/mms"))
.stream().filter(spec -> spec.getLinearizationView().equalsIgnoreCase("http://id.who.int/icd/release/11/mms"))
.findFirst();
mmsSpec.ifPresent(postCoordinationSpecification -> necessaryConditionsTable.setAvailableAxisFromSpec(postCoordinationSpecification, this.labels));
}
Expand All @@ -309,25 +303,25 @@ private void populateAvailableAxisValues(OWLEntity owlEntity) {
}

private void saveValues() {
List<LogicalDefinition> definitions = this.tableWrappers.stream().map(LogicalDefinitionTableWrapper::getLogicalDefinition).collect(Collectors.toList());

boolean hasDuplicates = verifyForDuplicates(definitions);

if(!hasDuplicates) {
this.dispatchServiceManager.execute(UpdateLogicalDefinitionAction.create(ChangeRequestId.get(uuidV4Provider.get()),
projectId,
this.currentEntity.asOWLClass(),
this.pristineData,
LogicalConditions.create(definitions, necessaryConditionsTable.getValues()),
"Edited the Logical Definitons and/or Necessary Conditions for " + this.entityData.getBrowserText()
), response ->{
switchToReadOnly();
});
} else {
messageBox.showAlert(
"There are several logical definitions with the same superclass, only one is allowed. Please remove the logical definitions that you do not want to keep.",
"");
}
List<LogicalDefinition> definitions = this.tableWrappers.stream().map(LogicalDefinitionTableWrapper::getLogicalDefinition).collect(Collectors.toList());

boolean hasDuplicates = verifyForDuplicates(definitions);

if (!hasDuplicates) {
this.dispatchServiceManager.execute(
UpdateLogicalDefinitionAction.create(ChangeRequestId.get(uuidV4Provider.get()),
projectId,
this.currentEntity.asOWLClass(),
this.pristineData,
LogicalConditions.create(definitions, necessaryConditionsTable.getValues()),
"Edited the Logical Definitons and/or Necessary Conditions for " + this.entityData.getBrowserText()
), response -> switchToReadOnly()
);
} else {
messageBox.showAlert(
"There are several logical definitions with the same superclass, only one is allowed. Please remove the logical definitions that you do not want to keep.",
"");
}

}

Expand All @@ -347,36 +341,37 @@ private boolean verifyForDuplicates(List<LogicalDefinition> definitions) {
private void removeWrapper(LogicalDefinitionTableWrapper wrapper) {
this.tableWrappers.remove(wrapper);
this.definitions.remove(wrapper.asWidget());
if(tableWrappers.isEmpty()){
if (tableWrappers.isEmpty()) {
displayPlaceholder();
}
}

private void populateAncestorsFromTree(AncestorClassHierarchy node, Set<OWLEntityData> accumulator) {
accumulator.add(node.getCurrentNode());
for(AncestorClassHierarchy child: node.getChildren()) {
for (AncestorClassHierarchy child : node.getChildren()) {
populateAncestorsFromTree(child, accumulator);
}
}

private void switchToReadOnly() {
toggleButtons(true);
this.necessaryConditionsTable.setReadOnly();
for(LogicalDefinitionTableWrapper wrapper : this.tableWrappers) {
for (LogicalDefinitionTableWrapper wrapper : this.tableWrappers) {
wrapper.enableReadOnly();
}
}

private void toggleButtons(boolean readOnly){
private void toggleButtons(boolean readOnly) {
this.saveValuesButton.setVisible(!readOnly);
this.cancelButton.setVisible(!readOnly);
this.editValuesButton.setVisible(readOnly);
this.addDefinitionButton.setEnabled(!readOnly);
}

private void switchToEditable(){
private void switchToEditable() {
this.toggleButtons(false);
this.necessaryConditionsTable.setEditable();
for(LogicalDefinitionTableWrapper wrapper : this.tableWrappers) {
for (LogicalDefinitionTableWrapper wrapper : this.tableWrappers) {
wrapper.enableEditable();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import edu.stanford.bmir.protege.web.shared.form.*;
import edu.stanford.bmir.protege.web.shared.frame.*;
import edu.stanford.bmir.protege.web.shared.hierarchy.*;
import edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsAction;
import edu.stanford.bmir.protege.web.shared.icd.*;
import edu.stanford.bmir.protege.web.shared.individuals.GetIndividualsAction;
import edu.stanford.bmir.protege.web.shared.individuals.GetIndividualsPageContainingIndividualAction;
import edu.stanford.bmir.protege.web.shared.issues.*;
Expand Down Expand Up @@ -241,7 +241,8 @@
@Type(value = UpdateLogicalDefinitionAction.class),
@Type(value = GetEntityLogicalDefinitionAction.class),
@Type(value = TranslateEventListAction.class),
@Type(value = SetNamedHierarchiesAction.class)
@Type(value = SetNamedHierarchiesAction.class),
@Type(value = GetClassAncestorsWithLinearizationAction.class)
})
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
public interface Action<R extends Result> extends IsSerializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import edu.stanford.bmir.protege.web.shared.form.*;
import edu.stanford.bmir.protege.web.shared.frame.*;
import edu.stanford.bmir.protege.web.shared.hierarchy.*;
import edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsResult;
import edu.stanford.bmir.protege.web.shared.icd.*;
import edu.stanford.bmir.protege.web.shared.individuals.*;
import edu.stanford.bmir.protege.web.shared.issues.*;
import edu.stanford.bmir.protege.web.shared.itemlist.*;
Expand Down Expand Up @@ -221,6 +221,7 @@
@JsonSubTypes.Type(UpdateLogicalDefinitionResult.class),
@JsonSubTypes.Type(GetUserInfoResult.class),
@JsonSubTypes.Type(SetNamedHierarchiesResult.class),
@JsonSubTypes.Type(GetClassAncestorsWithLinearizationResult.class)
})
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
public interface Result extends IsSerializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ public class RpcWhiteList implements IsSerializable, Action, Result {
GetEntityLogicalDefinitionResult _GetEntityLogicalDefinitionResult;
SetNamedHierarchiesAction _SetNamedHierarchiesAction;
SetNamedHierarchiesResult _SetNamedHierarchiesResult;
GetClassAncestorsWithLinearizationAction _GetClassAncestorsWithLinearizationAction;
GetClassAncestorsWithLinearizationResult _GetClassAncestorsWithLinearizationResult;

public RpcWhiteList() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package edu.stanford.bmir.protege.web.shared.icd;

import com.fasterxml.jackson.annotation.*;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.GwtCompatible;
import edu.stanford.bmir.protege.web.shared.dispatch.Action;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
import org.semanticweb.owlapi.model.IRI;

import static edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsWithLinearizationAction.CHANNEL;

@AutoValue
@GwtCompatible(serializable = true)
@JsonTypeName(CHANNEL)
public abstract class GetClassAncestorsWithLinearizationAction implements Action<GetClassAncestorsWithLinearizationResult> {

public final static String CHANNEL = "webprotege.entities.GetClassAncestorsWithLinearization";

@JsonCreator
public static GetClassAncestorsWithLinearizationAction create(@JsonProperty("classIri") IRI classIri,
@JsonProperty("projectId") ProjectId projectId) {
return new AutoValue_GetClassAncestorsWithLinearizationAction(classIri, projectId);
}

public abstract IRI getClassIri();
public abstract ProjectId getProjectId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.stanford.bmir.protege.web.shared.icd;

import com.fasterxml.jackson.annotation.*;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.GwtCompatible;
import edu.stanford.bmir.protege.web.shared.dispatch.Result;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;

import java.util.List;

import static edu.stanford.bmir.protege.web.shared.icd.GetClassAncestorsWithLinearizationAction.CHANNEL;


@AutoValue
@GwtCompatible(serializable = true)
@JsonTypeName(CHANNEL)
public abstract class GetClassAncestorsWithLinearizationResult implements Result {

@JsonProperty("ancestorsWithLinearization")
public abstract List<OWLEntityData> getAncestorsWithLinearization();

@JsonCreator
public static GetClassAncestorsWithLinearizationResult create(@JsonProperty("ancestorsWithLinearization") List<OWLEntityData> ancestorsWithLinearization ) {
return new AutoValue_GetClassAncestorsWithLinearizationResult(ancestorsWithLinearization);
}
}

0 comments on commit 49c4e5d

Please sign in to comment.