diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java index e6a54343e..bb3340135 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/AbstractTransaction.java @@ -30,6 +30,7 @@ import li.strolch.handler.operationslog.LogMessage; import li.strolch.handler.operationslog.LogSeverity; import li.strolch.handler.operationslog.OperationsLog; import li.strolch.model.*; +import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.activity.IActivityElement; import li.strolch.model.audit.AccessType; @@ -631,6 +632,18 @@ public abstract class AbstractTransaction implements StrolchTransaction { return elements; } + @Override + public Resource getResourceFor(Action action) throws StrolchException { + return getResourceFor(action, false); + } + + @Override + public Resource getResourceFor(Action action, boolean assertExists) throws StrolchException { + DBC.PRE.assertNotEmpty("action.resourceType must be set", action.getResourceType()); + DBC.PRE.assertNotEmpty("action.resourceId must be set", action.getResourceId()); + return getResourceBy(action.getResourceType(), action.getResourceId(), assertExists); + } + @Override public Activity getActivityBy(String type, String id) { return getActivityBy(type, id, false); diff --git a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java index ed58352cf..d8e1c3068 100644 --- a/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java +++ b/li.strolch.agent/src/main/java/li/strolch/persistence/api/StrolchTransaction.java @@ -35,6 +35,7 @@ import li.strolch.model.Resource; import li.strolch.model.StrolchElement; import li.strolch.model.StrolchRootElement; import li.strolch.model.Tags; +import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.audit.AccessType; import li.strolch.model.audit.Audit; @@ -763,6 +764,36 @@ public interface StrolchTransaction extends AutoCloseable { */ public List getResourcesBy(StringListParameter refP, boolean assertExists) throws StrolchException; + /** + *

Returns the {@link Resource} for the given {@link Action}. This is done by getting the resource by {@link Action#getResourceType()} and {@link Action#getResourceId()}

+ * + *

Should the resource not exist, then null is returned

+ * + * @param action + * the action for which to return the resoruce + * + * @return the resource referenced by the action, or null if it does not exist + * + * @throws StrolchException + * if the action is null, or something else goes wrong + */ + public Resource getResourceFor(Action action) throws StrolchException; + + /** + *

Returns the {@link Resource} for the given {@link Action}. This is done by getting the resource by {@link Action#getResourceType()} and {@link Action#getResourceId()}

+ * + *

Should the resource not exist and assertExists is true, then an exception is thrown, otherwise null is returned

+ * + * @param action + * the action for which to return the resoruce + * + * @return the resource referenced by the action. If the resource does not exist and assertExists is true then an exception is thrown, otherwise null is returnee + * + * @throws StrolchException + * if the action is null and assertExists is true, or something else goes wrong + */ + public Resource getResourceFor(Action action, boolean assertExists) throws StrolchException; + /** * Returns the {@link Activity} with the given type and id, or null if it does not exist *