From: Jani Simomaa Date: Thu, 26 Jul 2018 09:30:57 +0000 (+0300) Subject: Prevent paste to resources that are `L0.Entity_published` X-Git-Tag: v1.43.0~136^2~435 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F53%2F1953%2F3;p=simantics%2Fplatform.git Prevent paste to resources that are `L0.Entity_published` gitlab #57 Change-Id: Ie4728421bca56ba0c10ae03d08f99123faffa1f1 --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultPasteHandler.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultPasteHandler.java index ccef12ebf..067ed9207 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultPasteHandler.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultPasteHandler.java @@ -21,6 +21,7 @@ import java.util.Set; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.PasteHandlerAdapter; import org.simantics.db.layer0.internal.SimanticsInternal; @@ -146,6 +147,10 @@ public class DefaultPasteHandler extends PasteHandlerAdapter { Collection result = new ArrayList<>(); + + // Check if root resource is allowed for pasting + checkIfRootAllowsPaste(graph); + Map hints = Collections.singletonMap(ClipboardUtils.HINT_TARGET_RESOURCE, resource); onPasteBegin(graph); @@ -179,6 +184,15 @@ public class DefaultPasteHandler extends PasteHandlerAdapter { } + protected void checkIfRootAllowsPaste(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + // check if root is published + Boolean published = graph.getPossibleRelatedValue(resource, L0.Entity_published); + if (published != null && published) { + throw new DatabaseException("Target resource " + NameUtils.getSafeName(graph, resource) + " is published and does not allow paste."); + } + } + @SuppressWarnings("rawtypes") @Override public Object getAdapter(Class adapter) {