Skip to content

Commit

Permalink
interim fix for who-icatx/icatx-project#111 refactored ChangeEntityPa…
Browse files Browse the repository at this point in the history
…rentsResult to include the linearizationPathParent check
  • Loading branch information
soimugeoWB committed Jan 15, 2025
1 parent 7298fdb commit 983c5e9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,12 @@ public interface Messages extends com.google.gwt.i18n.client.Messages {
"Please correct this in order to save changes")
SafeHtml classHierarchy_parentsHaveRetiredAncestors(String classesWithRetiredParents);

@DefaultMessage("<em>A Linearization Path Parent cannot be removed <br>" +
"Following parent is a linearization path parent: <strong>{0}</strong></em><br>" +
"<br>" +
"Please change the linearization path parent before removing the parent")
SafeHtml classHierarchy_removeParentThatIsLinearizationPathParent(String linearizationPathParent);

@DefaultMessage("<em>A released class cannot be moved to a retired parent!")
String classHierarchy_cannotMoveReleasedClassToRetiredParent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import edu.stanford.bmir.protege.web.client.library.modal.ModalPresenter;
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;
import edu.stanford.bmir.protege.web.shared.hierarchy.ChangeEntityParentsAction;
import edu.stanford.bmir.protege.web.shared.hierarchy.ChangeEntityParentsResult;
import edu.stanford.bmir.protege.web.shared.hierarchy.GetHierarchyParentsAction;
import edu.stanford.bmir.protege.web.shared.issues.CreateEntityDiscussionThreadAction;
import edu.stanford.bmir.protege.web.shared.project.ProjectId;
Expand Down Expand Up @@ -99,39 +98,33 @@ private void handleHierarchyChange(ModalCloser closer) {
.collect(toImmutableSet());
dispatch.execute(ChangeEntityParentsAction.create(projectId, parentsSet, entity.asOWLClass(), view.getReasonForChange()),
changeEntityParentsResult -> {
if (isResultValid(changeEntityParentsResult)) {
view.clearClassesWithCycle();
view.clearClassesWithRetiredParents();
if (changeEntityParentsResult.isSuccess()) {
view.clearClassesWithCycleErrors();
view.clearClassesWithRetiredParentsErrors();
dispatch.execute(
CreateEntityDiscussionThreadAction.create(projectId, entity, view.getReasonForChange()),
threadActionResult -> closer.closeModal());
return;
}

if(hasClassesWithRetiredParents(changeEntityParentsResult)){
view.clearClassesWithRetiredParents();
if(changeEntityParentsResult.hasClassesWithRetiredParents()){
view.clearClassesWithRetiredParentsErrors();
Set<OWLEntityData> classesWithRetiredParents = changeEntityParentsResult.getClassesWithRetiredParents();
view.markClassesWithRetiredParents(classesWithRetiredParents);
}

if(hasClassesWithCycles(changeEntityParentsResult)){
view.clearClassesWithCycle();
if(changeEntityParentsResult.hasClassesWithCycle()){
view.clearClassesWithCycleErrors();
Set<OWLEntityData> classesWithCycles = changeEntityParentsResult.getClassesWithCycle();
view.markClassesWithCycles(classesWithCycles);
}

if(changeEntityParentsResult.hasLinearizationPathParent()){
view.clearLinearizationPathParentErrors();
OWLEntityData linearizationPathParent = changeEntityParentsResult.getLinearizationPathParent().get();
view.markLinearizationPathParent(linearizationPathParent);
}
});
}
}

private boolean isResultValid(ChangeEntityParentsResult changeEntityParentsResult) {
return !hasClassesWithCycles(changeEntityParentsResult) && !hasClassesWithRetiredParents(changeEntityParentsResult);
}

private boolean hasClassesWithCycles(ChangeEntityParentsResult changeEntityParentsResult) {
return !changeEntityParentsResult.getClassesWithCycle().isEmpty();
}

private boolean hasClassesWithRetiredParents(ChangeEntityParentsResult changeEntityParentsResult) {
return !changeEntityParentsResult.getClassesWithRetiredParents().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public interface EditParentsView extends IsWidget, HasBusy {

List<OWLPrimitiveData> getNewParentList();

void clearClassesWithCycle();
void clearClassesWithCycleErrors();

void markClassesWithCycles(Set<OWLEntityData> classesWithCycles);

void clearClassesWithRetiredParents();
void clearClassesWithRetiredParentsErrors();

void markClassesWithRetiredParents(Set<OWLEntityData> classesWithRetiredParents);

void clearLinearizationPathParentErrors();

void markLinearizationPathParent(OWLEntityData classesWithRetiredParents);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class EditParentsViewImpl extends Composite implements EditParentsView {
@UiField
HTML classesWithRetiredParentsField;

@UiField
HTML linearizationPathParentField;

private static final Logger logger = Logger.getLogger(EditParentsViewImpl.class.getName());

interface EditParentsViewImplUiBinder extends UiBinder<HTMLPanel, EditParentsViewImpl> {
Expand Down Expand Up @@ -100,11 +103,11 @@ public boolean isReasonForChangeSet() {
reasonForChangeErrorLabel.addStyleName(WebProtegeClientBundle.BUNDLE.style().errorLabel());
return false;
}
clearErrors();
clearReasonForChangeErrors();
return true;
}

public void clearErrors() {
public void clearReasonForChangeErrors() {
reasonForChangeErrorLabel.setText("");
reasonForChangeErrorLabel.removeStyleName(WebProtegeClientBundle.BUNDLE.style().errorLabel());
}
Expand All @@ -114,8 +117,9 @@ public void clearErrors() {
public void clear() {
textBox.setText("");
reasonForChangeTextBox.setText("");
clearErrors();
clearClassesWithCycle();
clearReasonForChangeErrors();
clearClassesWithCycleErrors();
clearLinearizationPathParentErrors();
}

@Nonnull
Expand All @@ -130,7 +134,7 @@ public List<OWLPrimitiveData> getNewParentList() {
}

@Override
public void clearClassesWithCycle() {
public void clearClassesWithCycleErrors() {
classesWithCyclesWarningField.setVisible(false);
classesWithCyclesWarningField.setHTML("");
}
Expand All @@ -143,7 +147,7 @@ public void markClassesWithCycles(Set<OWLEntityData> classesWithCycles) {
}

@Override
public void clearClassesWithRetiredParents() {
public void clearClassesWithRetiredParentsErrors() {
classesWithRetiredParentsField.setVisible(false);
classesWithRetiredParentsField.setHTML("");
}
Expand All @@ -154,4 +158,16 @@ public void markClassesWithRetiredParents(Set<OWLEntityData> classesWithRetiredP
classesWithCyclesWarningField.setHTML(messages.classHierarchy_parentsHaveRetiredAncestors(classes));
classesWithCyclesWarningField.setVisible(true);
}

@Override
public void clearLinearizationPathParentErrors() {
linearizationPathParentField.setVisible(false);
linearizationPathParentField.setHTML("");
}

@Override
public void markLinearizationPathParent(OWLEntityData linearizationPathParent) {
linearizationPathParentField.setHTML(messages.classHierarchy_removeParentThatIsLinearizationPathParent(linearizationPathParent.getBrowserText()));
linearizationPathParentField.setVisible(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<g:HTML ui:field="classesWithRetiredParentsField"
visible="false"
addStyleNames="{wp.style.warningLabel} {style.warningField}"/>
<g:HTML ui:field="linearizationPathParentField"
visible="false"
addStyleNames="{wp.style.warningLabel} {style.warningField}"/>
</div>
</g:HTMLPanel>
</ui:UiBinder>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.stanford.bmir.protege.web.shared.entity.OWLEntityData;

import javax.annotation.Nonnull;
import java.util.Optional;
import java.util.Set;


Expand All @@ -20,8 +21,9 @@ public abstract class ChangeEntityParentsResult implements Result {

@JsonCreator
public static ChangeEntityParentsResult create(@JsonProperty("classesWithCycle") @Nonnull Set<OWLEntityData> classesWithCycle,
@JsonProperty("classesWithRetiredParents") @Nonnull Set<OWLEntityData> classesWithRetiredParents) {
return new AutoValue_ChangeEntityParentsResult(classesWithCycle, classesWithRetiredParents);
@JsonProperty("classesWithRetiredParents") @Nonnull Set<OWLEntityData> classesWithRetiredParents,
@JsonProperty("linearizationPathParent") Optional<OWLEntityData> linearizationPathParent ) {
return new AutoValue_ChangeEntityParentsResult(classesWithCycle, classesWithRetiredParents, linearizationPathParent);
}

@JsonProperty("classesWithCycle")
Expand All @@ -32,4 +34,27 @@ public static ChangeEntityParentsResult create(@JsonProperty("classesWithCycle")
@Nonnull
public abstract Set<OWLEntityData> getClassesWithRetiredParents();

@JsonProperty("linearizationPathParent")
@Nonnull
public abstract Optional<OWLEntityData> getLinearizationPathParent();

public boolean hasClassesWithCycle(){
return !getClassesWithCycle().isEmpty();
}

public boolean hasClassesWithRetiredParents(){
return !getClassesWithRetiredParents().isEmpty();
}

public boolean hasLinearizationPathParent(){
return getLinearizationPathParent().isPresent();
}

public boolean isFailure(){
return hasClassesWithRetiredParents()||hasClassesWithCycle()||hasLinearizationPathParent();
}

public boolean isSuccess(){
return !isFailure();
}
}

0 comments on commit 983c5e9

Please sign in to comment.