From 49c4e5d261115415eb45022e22935f470bfb9356 Mon Sep 17 00:00:00 2001 From: soimugeo Date: Tue, 5 Nov 2024 15:29:37 +0200 Subject: [PATCH] changed call for the logical definitions superclass ancestors to GetClassAncestorsWithLinearizationAction. --- .../LogicalDefinitionPortletViewImpl.java | 113 +++++++++--------- .../protege/web/shared/dispatch/Action.java | 5 +- .../protege/web/shared/dispatch/Result.java | 3 +- .../web/shared/dispatch/RpcWhiteList.java | 2 + ...ClassAncestorsWithLinearizationAction.java | 27 +++++ ...ClassAncestorsWithLinearizationResult.java | 26 ++++ 6 files changed, 114 insertions(+), 62 deletions(-) create mode 100644 webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsWithLinearizationAction.java create mode 100644 webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsWithLinearizationResult.java diff --git a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/logicaldefinition/LogicalDefinitionPortletViewImpl.java b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/logicaldefinition/LogicalDefinitionPortletViewImpl.java index c72a50845..253b25576 100644 --- a/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/logicaldefinition/LogicalDefinitionPortletViewImpl.java +++ b/webprotege-gwt-ui-client/src/main/java/edu/stanford/bmir/protege/web/client/logicaldefinition/LogicalDefinitionPortletViewImpl.java @@ -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; @@ -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; @@ -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); @@ -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, @@ -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."); @@ -162,6 +159,7 @@ public LogicalDefinitionPortletViewImpl(@Nonnull DispatchServiceManager dispatch public void setWidget(IsWidget w) { } + @Override public void dispose() { @@ -183,10 +181,8 @@ public void setEntity(OWLEntity owlEntity, ProjectId projectId) { this.necessaryConditionsTable.setSuperclassScalesValue(superclassScalesValue); }); - dispatchServiceManager.execute(GetClassAncestorsAction.create(owlEntity.getIRI(), projectId), getHierarchyParentsResult -> { - Set 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(); @@ -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 superClassTableRows = logicalDefinition.getAxis2filler().stream() .map(LogicalDefinitionTableRow::new) .collect(Collectors.toList()); @@ -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 necessaryConditionsTableRows = getEntityLogicalDefinitionResult.getNecessaryConditions().stream() .map(LogicalDefinitionTableRow::new) @@ -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 equivalentRoots = axisToGenericScales.stream() .filter(axis -> axis.getPostcoordinationAxis().equalsIgnoreCase(postCoordinationAxis)) .map(PostcoordinationAxisToGenericScale::getGenericPostcoordinationScaleTopClass) @@ -267,9 +263,7 @@ private void handleAxisValueChanged(String postCoordinationAxis, LogicalDefiniti Set 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) { @@ -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 equivalentRoots = axisToGenericScales.stream() .filter(axis -> axis.getPostcoordinationAxis().equalsIgnoreCase(postCoordinationAxis)) .map(PostcoordinationAxisToGenericScale::getGenericPostcoordinationScaleTopClass) @@ -287,7 +281,7 @@ private void initializeTable(String postCoordinationAxis, LogicalDefinitionTable } Map map = new HashMap<>(); - for(String availableAxis : selectedScales) { + for (String availableAxis : selectedScales) { map.put(availableAxis, availableAxis); } @@ -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 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)); } @@ -309,25 +303,25 @@ private void populateAvailableAxisValues(OWLEntity owlEntity) { } private void saveValues() { - List 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 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.", + ""); + } } @@ -347,36 +341,37 @@ private boolean verifyForDuplicates(List 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 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(); } } diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Action.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Action.java index a5261b61f..8ede443ef 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Action.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Action.java @@ -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.*; @@ -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 extends IsSerializable { diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Result.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Result.java index bcb71ff37..ca6feeee3 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Result.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/Result.java @@ -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.*; @@ -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 { diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/RpcWhiteList.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/RpcWhiteList.java index 5dd2e39e6..01bcb6dee 100644 --- a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/RpcWhiteList.java +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/dispatch/RpcWhiteList.java @@ -623,6 +623,8 @@ public class RpcWhiteList implements IsSerializable, Action, Result { GetEntityLogicalDefinitionResult _GetEntityLogicalDefinitionResult; SetNamedHierarchiesAction _SetNamedHierarchiesAction; SetNamedHierarchiesResult _SetNamedHierarchiesResult; + GetClassAncestorsWithLinearizationAction _GetClassAncestorsWithLinearizationAction; + GetClassAncestorsWithLinearizationResult _GetClassAncestorsWithLinearizationResult; public RpcWhiteList() { } diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsWithLinearizationAction.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsWithLinearizationAction.java new file mode 100644 index 000000000..830a43279 --- /dev/null +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsWithLinearizationAction.java @@ -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 { + + 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(); +} diff --git a/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsWithLinearizationResult.java b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsWithLinearizationResult.java new file mode 100644 index 000000000..18211a5d8 --- /dev/null +++ b/webprotege-gwt-ui-shared/src/main/java/edu/stanford/bmir/protege/web/shared/icd/GetClassAncestorsWithLinearizationResult.java @@ -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 getAncestorsWithLinearization(); + + @JsonCreator + public static GetClassAncestorsWithLinearizationResult create(@JsonProperty("ancestorsWithLinearization") List ancestorsWithLinearization ) { + return new AutoValue_GetClassAncestorsWithLinearizationResult(ancestorsWithLinearization); + } +}