diff --git a/inception/inception-constraints/src/main/java/de/tudarmstadt/ukp/clarin/webanno/constraints/evaluator/ConstraintsEvaluator.java b/inception/inception-constraints/src/main/java/de/tudarmstadt/ukp/clarin/webanno/constraints/evaluator/ConstraintsEvaluator.java index 2b9eeff26c5..51c415b765a 100644 --- a/inception/inception-constraints/src/main/java/de/tudarmstadt/ukp/clarin/webanno/constraints/evaluator/ConstraintsEvaluator.java +++ b/inception/inception-constraints/src/main/java/de/tudarmstadt/ukp/clarin/webanno/constraints/evaluator/ConstraintsEvaluator.java @@ -100,7 +100,9 @@ public boolean anyRuleAffectingFeatureMatchesAllConditions(ParsedConstraints aCo for (var rule : scope.getRules()) { if (allRuleConditionsMatch(aConstraints, rule, aContext)) { - return anyRestrictionAffectsFeature(aConstraints, rule, aFeature); + if (anyRestrictionAffectsFeature(aConstraints, rule, aFeature)) { + return true; + } } } diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/KnowledgeBasePanel.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/KnowledgeBasePanel.java index 6f5f56f392e..01cb0d7463f 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/KnowledgeBasePanel.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/KnowledgeBasePanel.java @@ -21,8 +21,8 @@ import static de.tudarmstadt.ukp.inception.ui.kb.KnowledgeBasePage.PAGE_PARAM_KB_NAME; import static org.apache.wicket.RuntimeConfigurationType.DEVELOPMENT; -import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.Optional; import org.apache.wicket.AttributeModifier; @@ -261,30 +261,39 @@ else if (aKbObject instanceof KBProperty) { public void actionStatementChanged(AjaxStatementChangedEvent event) { // if this event is not about renaming (changing the RDFS label) of a KBObject, return - KBStatement statement = event.getStatement(); + var statement = event.getStatement(); if (isLabelStatement(statement)) { // determine whether the concept name or property name was changed (or neither), then // update the name in the respective KBHandle - - List> models = Arrays.asList(selectedConceptHandle, - selectedPropertyHandle); - models.stream().filter(model -> model.getObject() != null && model.getObject() - .getIdentifier().equals(statement.getInstance().getIdentifier())) - .forEach(model -> { - Optional kbObject = kbService.readHandle(kbModel.getObject(), - model.getObject().getIdentifier()); - if (kbObject.isPresent()) { - model.getObject().setName(kbObject.get().getName()); - } - event.getTarget().add(this); - }); + if (updateStatmentModel(event, statement, selectedConceptHandle)) { + event.getTarget().add(this); + } + if (updateStatmentModel(event, statement, selectedPropertyHandle)) { + event.getTarget().add(this); + } } else { event.getTarget().add(getPage()); } } + private boolean updateStatmentModel(AjaxStatementChangedEvent event, KBStatement statement, + Model mod) + { + if (mod.getObject() != null && mod.getObject().getIdentifier() + .equals(statement.getInstance().getIdentifier())) { + var kbObject = kbService.readHandle(kbModel.getObject(), + mod.getObject().getIdentifier()); + if (kbObject.isPresent() + && !Objects.equals(kbObject.get().getName(), mod.getObject().getName())) { + mod.getObject().setName(kbObject.get().getName()); + return true; + } + } + return false; + } + /** * Checks if the given statement is (potentially) assigning the label to the item in subject * position. This is the case if the property is a label property. Since we do at this point not @@ -298,22 +307,6 @@ private boolean isLabelStatement(KBStatement aStatement) } return labelProperties.contains(aStatement.getProperty().getIdentifier()); - - // SimpleValueFactory vf = SimpleValueFactory.getInstance(); - // - // String propertyIri = aStatement.getProperty().getIdentifier(); - // IRI subjectIri = vf.createIRI(aStatement.getInstance().getIdentifier()); - // IRI labelIri = kbModel.getObject().getLabelIri(); - // - // try (RepositoryConnection conn = kbService.getConnection(kbModel.getObject())) { - // - // boolean hasMainLabel = RdfUtils - // .readFirst(conn, subjectIri, labelIri, null, kbModel.getObject()).isPresent(); - // - // return propertyIri.equals(labelIri.stringValue()) - // || (kbService.isLabelProperty(kbModel.getObject(), propertyIri) - // && !hasMainLabel); - // } } @OnEvent diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/event/AjaxStatementChangedEvent.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/event/AjaxStatementChangedEvent.java index ff8d6d78a3f..46aab664399 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/event/AjaxStatementChangedEvent.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/event/AjaxStatementChangedEvent.java @@ -30,7 +30,6 @@ public class AjaxStatementChangedEvent extends AbstractAjaxAwareEvent { - /** * Statement editor component of the changed statement. */ diff --git a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/stmt/editor/StatementEditor.java b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/stmt/editor/StatementEditor.java index 168d827f9d3..bb87dc18016 100644 --- a/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/stmt/editor/StatementEditor.java +++ b/inception/inception-ui-kb/src/main/java/de/tudarmstadt/ukp/inception/ui/kb/stmt/editor/StatementEditor.java @@ -17,13 +17,14 @@ */ package de.tudarmstadt.ukp.inception.ui.kb.stmt.editor; +import static org.apache.wicket.event.Broadcast.BREADTH; + import java.util.Iterator; import java.util.List; import java.util.Optional; import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.event.Broadcast; import org.apache.wicket.feedback.IFeedback; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; @@ -145,9 +146,8 @@ private void actionCancelExistingStatement(AjaxRequestTarget aTarget) private void actionCancelNewStatement(AjaxRequestTarget aTarget) { // send a delete event to trigger the deletion in the UI - AjaxStatementChangedEvent deleteEvent = new AjaxStatementChangedEvent(aTarget, - statement.getObject(), this, true); - send(getPage(), Broadcast.BREADTH, deleteEvent); + var deleteEvent = new AjaxStatementChangedEvent(aTarget, statement.getObject(), this, true); + send(getPage(), BREADTH, deleteEvent); } private void actionSave(AjaxRequestTarget aTarget, Form aForm) @@ -167,7 +167,7 @@ private void actionSave(AjaxRequestTarget aTarget, Form aForm) statement.setObject(modifiedStatement); // switch back to ViewMode and send notification to listeners actionCancelExistingStatement(aTarget); - send(getPage(), Broadcast.BREADTH, + send(getPage(), BREADTH, new AjaxStatementChangedEvent(aTarget, statement.getObject(), oldStatement)); } catch (RepositoryException e) { @@ -184,7 +184,7 @@ private void actionDelete(AjaxRequestTarget aTarget) AjaxStatementChangedEvent deleteEvent = new AjaxStatementChangedEvent(aTarget, statement.getObject(), this, true); - send(getPage(), Broadcast.BREADTH, deleteEvent); + send(getPage(), BREADTH, deleteEvent); } catch (RepositoryException e) { error("Unable to delete statement: " + e.getLocalizedMessage()); @@ -203,8 +203,7 @@ private void actionMakeExplicit(AjaxRequestTarget aTarget) // KBStatement to false, so that's what's done here statement.getObject().setInferred(false); aTarget.add(this); - send(getPage(), Broadcast.BREADTH, - new AjaxStatementChangedEvent(aTarget, statement.getObject())); + send(getPage(), BREADTH, new AjaxStatementChangedEvent(aTarget, statement.getObject())); } catch (RepositoryException e) { error("Unable to make statement explicit " + e.getLocalizedMessage());