From 3e89fd586724e4b2d86aec822bfc642c27c33cfd Mon Sep 17 00:00:00 2001 From: Zsolt Kovacs Date: Tue, 18 Dec 2018 21:21:36 +0100 Subject: [PATCH 1/8] Starting 3.6.0 snapshot --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ace8ff7..d52ea09 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ org.cristalise cristalise-kernel cristalise-kernel - 3.5.0-SNAPSHOT + 3.6.0-SNAPSHOT Cristal-ise is a description-driven software platform originally developed to track the construction of the CMS ECAL detector of the LHC at CERN. This is its core library, known as the kernel, which manages business objects called Items. Items are entirely configured from data, called descriptions, held in other Items. From 3468aa4794806f9a0a3fffd6d26b7dbbf909c924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Kov=C3=A1cs?= Date: Mon, 24 Dec 2018 12:05:10 +0100 Subject: [PATCH 2/8] #171: Throw IllegalArgumentException when Name contains Path delimiter --- src/main/java/org/cristalise/kernel/lookup/Path.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/cristalise/kernel/lookup/Path.java b/src/main/java/org/cristalise/kernel/lookup/Path.java index 86c6e83..c21a9e3 100644 --- a/src/main/java/org/cristalise/kernel/lookup/Path.java +++ b/src/main/java/org/cristalise/kernel/lookup/Path.java @@ -55,6 +55,8 @@ protected Path(String path) { * Create a path by appending a child string to an existing path */ protected Path(Path parent, String child) { + if (child.contains(delim)) throw new IllegalArgumentException("Child name '"+child+"' contains delimiter:"+delim); + mPath = Arrays.copyOf(parent.getPath(), parent.getPath().length + 1); mPath[mPath.length - 1] = child; } From 4f2f0c790f00550565dea9b0d99bb760c65c4877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Kov=C3=A1cs?= Date: Mon, 24 Dec 2018 14:20:40 +0100 Subject: [PATCH 3/8] #255: add new constructors to set cause --- .../kernel/scripting/ParameterException.java | 15 +++++++-- .../scripting/ScriptErrorException.java | 31 +++++++++++++------ .../scripting/ScriptLoadingException.java | 23 ++++++++------ .../scripting/ScriptParsingException.java | 15 ++++++++- .../scripting/ScriptingEngineException.java | 6 +++- 5 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/cristalise/kernel/scripting/ParameterException.java b/src/main/java/org/cristalise/kernel/scripting/ParameterException.java index 8d98200..17bfea2 100644 --- a/src/main/java/org/cristalise/kernel/scripting/ParameterException.java +++ b/src/main/java/org/cristalise/kernel/scripting/ParameterException.java @@ -22,7 +22,12 @@ public class ParameterException extends ScriptingEngineException { - /** + /** + * + */ + private static final long serialVersionUID = 7549607286659193866L; + + /** * Creates new ParameterException without detail message. */ public ParameterException() { @@ -35,6 +40,12 @@ public ParameterException() { public ParameterException(String msg) { super(msg); } -} + public ParameterException(Throwable throwable) { + super(throwable); + } + public ParameterException(String message, Throwable throwable) { + super(message, throwable); + } +} diff --git a/src/main/java/org/cristalise/kernel/scripting/ScriptErrorException.java b/src/main/java/org/cristalise/kernel/scripting/ScriptErrorException.java index 4d6fc05..c61025f 100644 --- a/src/main/java/org/cristalise/kernel/scripting/ScriptErrorException.java +++ b/src/main/java/org/cristalise/kernel/scripting/ScriptErrorException.java @@ -22,29 +22,42 @@ public class ScriptErrorException extends java.lang.Exception { - /** + /** + * + */ + private static final long serialVersionUID = -4298189043503060615L; + /** * Creates new sciptingEngineException without detail message. */ - ErrorInfo errors; + ErrorInfo errors; + public ScriptErrorException() { } /** * Constructs an sciptingEngineException with the specified detail message. - * @param msg the detail message. + * + * @param msg + * the detail message. */ public ScriptErrorException(String msg) { super(msg); } - + public ScriptErrorException(ErrorInfo errors) { - super(errors.toString()); + super(errors.toString()); this.errors = errors; } - public ErrorInfo getErrors() { - return errors; - } -} + public ErrorInfo getErrors() { + return errors; + } + public ScriptErrorException(Throwable throwable) { + super(throwable); + } + public ScriptErrorException(String message, Throwable throwable) { + super(message, throwable); + } +} diff --git a/src/main/java/org/cristalise/kernel/scripting/ScriptLoadingException.java b/src/main/java/org/cristalise/kernel/scripting/ScriptLoadingException.java index 72f0fdc..b902e44 100644 --- a/src/main/java/org/cristalise/kernel/scripting/ScriptLoadingException.java +++ b/src/main/java/org/cristalise/kernel/scripting/ScriptLoadingException.java @@ -20,16 +20,13 @@ */ package org.cristalise.kernel.scripting; -/************************************************************************** - * - * $Revision: 1.1 $ - * $Date: 2003/04/06 12:32:51 $ - * - * Copyright (C) 2003 CERN - European Organization for Nuclear Research - * All rights reserved. - **************************************************************************/ public class ScriptLoadingException extends ScriptingEngineException { - /** + /** + * + */ + private static final long serialVersionUID = 395106341865890224L; + + /** * */ public ScriptLoadingException() { @@ -41,4 +38,12 @@ public ScriptLoadingException() { public ScriptLoadingException(String msg) { super(msg); } + + public ScriptLoadingException(Throwable throwable) { + super(throwable); + } + + public ScriptLoadingException(String message, Throwable throwable) { + super(message, throwable); + } } diff --git a/src/main/java/org/cristalise/kernel/scripting/ScriptParsingException.java b/src/main/java/org/cristalise/kernel/scripting/ScriptParsingException.java index 3b6feb5..29b8c2e 100644 --- a/src/main/java/org/cristalise/kernel/scripting/ScriptParsingException.java +++ b/src/main/java/org/cristalise/kernel/scripting/ScriptParsingException.java @@ -22,7 +22,12 @@ public class ScriptParsingException extends ScriptingEngineException { - /** + /** + * + */ + private static final long serialVersionUID = 8076468979611699004L; + + /** * Creates new ScriptParsingException without detail message. */ public ScriptParsingException() { @@ -36,6 +41,14 @@ public ScriptParsingException() { public ScriptParsingException(String msg) { super(msg); } + + public ScriptParsingException(Throwable throwable) { + super(throwable); + } + + public ScriptParsingException(String message, Throwable throwable) { + super(message, throwable); + } } diff --git a/src/main/java/org/cristalise/kernel/scripting/ScriptingEngineException.java b/src/main/java/org/cristalise/kernel/scripting/ScriptingEngineException.java index 276f462..0690d2d 100644 --- a/src/main/java/org/cristalise/kernel/scripting/ScriptingEngineException.java +++ b/src/main/java/org/cristalise/kernel/scripting/ScriptingEngineException.java @@ -21,8 +21,12 @@ package org.cristalise.kernel.scripting; public class ScriptingEngineException extends java.lang.Exception { - /** + * + */ + private static final long serialVersionUID = 2902580887959991152L; + + /** * Creates new sciptingEngineException without detail message. */ public ScriptingEngineException() { From 2b0ae4e2c866b5167168f5d5e6ba89a4adc7fae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Kov=C3=A1cs?= Date: Mon, 24 Dec 2018 14:21:14 +0100 Subject: [PATCH 4/8] #255: set cause before throwing an exception --- .../cristalise/kernel/scripting/Script.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/cristalise/kernel/scripting/Script.java b/src/main/java/org/cristalise/kernel/scripting/Script.java index f518ec9..db5b768 100644 --- a/src/main/java/org/cristalise/kernel/scripting/Script.java +++ b/src/main/java/org/cristalise/kernel/scripting/Script.java @@ -301,7 +301,7 @@ private void parseScriptXML(String scriptXML) throws ScriptParsingException, Par scriptDoc = domBuilder.parse(new InputSource(new StringReader(scriptXML))); } catch (Exception ex) { - throw new ScriptParsingException("Error parsing Script XML : " + ex.toString()); + throw new ScriptParsingException("Error parsing Script XML", ex); } parseScriptTag (scriptDoc.getElementsByTagName("script")); @@ -353,20 +353,9 @@ private void parseIncludeTag(NodeList includeList) throws ScriptParsingException addIncludedInputParam(includeParam.getName(), includeParam.getType()); } } - catch (NumberFormatException e) { - throw new ScriptParsingException("Invalid version in imported script name:'"+includeName+"', version:'"+includeVersion+"'"); - } - catch (ScriptingEngineException e) { - Logger.error(e); - throw new ScriptParsingException("Error parsing imported script "+includeName+" v"+includeVersion+": "+e.getMessage()); - } - catch (ObjectNotFoundException e) { - Logger.error(e); - throw new ScriptParsingException("Error parsing imported script "+includeName+" v"+includeVersion+" not found."); - } - catch (InvalidDataException e) { + catch (NumberFormatException | ScriptingEngineException | ObjectNotFoundException | InvalidDataException e) { Logger.error(e); - throw new ScriptParsingException("Error parsing imported script "+includeName+" v"+includeVersion+" was invalid: "+e.getMessage()); + throw new ScriptParsingException("Included script '"+includeName+" v"+includeVersion+"' parse error", e); } } } @@ -382,7 +371,7 @@ private void parseScriptTag(NodeList scriptList) throws ScriptParsingException { setScriptEngine(scriptElem.getAttribute("language")); } catch (ScriptingEngineException ex) { - throw new ScriptParsingException(ex.getMessage()); + throw new ScriptParsingException(ex.getMessage(), ex); } // get script source from CDATA @@ -410,7 +399,7 @@ protected void addInputParam(String name, String type) throws ParameterException addInputParam(name, Gateway.getResource().getClassForName(type)); } catch (ClassNotFoundException ex) { - throw new ParameterException("Input parameter " + name + " specifies class " + type + " which was not found."); + throw new ParameterException("Input parameter " + name + " specifies class " + type + " which was not found.", ex); } } @@ -460,7 +449,7 @@ protected void addOutput(String name, String type) throws ParameterException { addOutput(name, Gateway.getResource().getClassForName(type)); } catch (ClassNotFoundException ex) { - throw new ParameterException("Output parameter " + name + " specifies class " + type + " which was not found."); + throw new ParameterException("Output parameter " + name + " specifies class " + type + " which was not found.", ex); } } @@ -543,7 +532,7 @@ public Object evaluate(ItemPath itemPath, CastorHashMap inputProps, String actCo catch (Exception e) { Logger.error("Script.evaluate() - Script:" + getName()); Logger.error(e); - throw new ScriptingEngineException(e.getMessage()); + throw new ScriptingEngineException(e); } } @@ -573,7 +562,7 @@ public Object execute() throws ScriptingEngineException { // croak if any missing if (missingParams.length() > 0) { - throw new ScriptingEngineException("Execution aborted, the following declared parameters were not set: \n" + missingParams.toString()); + throw new ScriptingEngineException("Parameters were not set: \n" + missingParams.toString()); } initOutputParams(); @@ -661,7 +650,10 @@ private void initOutputParams() { try { emptyObject = outputParam.getType().newInstance(); } - catch (Exception e) {} + catch (Exception e) { + //This case was originally not logged + Logger.warning("Script.initOutputParams() - Failed to init output:%s error:%s", outputParam.getName(), e.getMessage()); + } context.getBindings(ScriptContext.ENGINE_SCOPE).put(outputParam.getName(), emptyObject); } @@ -757,7 +749,7 @@ public void setScriptData(String script) throws ScriptParsingException { } catch (ScriptException e) { Logger.error(e); - throw new ScriptParsingException(e.getMessage()); + throw new ScriptParsingException(e); } } } @@ -842,9 +834,13 @@ public CollectionArrayList makeDescCollections() throws InvalidDataException, Ob for (Script script : mIncludes) { try { includeColl.addMember(script.getItemPath()); - } catch (InvalidCollectionModification e) { + } + catch (InvalidCollectionModification e) { + Logger.error(e); throw new InvalidDataException("Could not add "+script.getName()+" to description collection. "+e.getMessage()); - } catch (ObjectAlreadyExistsException e) { + } + catch (ObjectAlreadyExistsException e) { + Logger.error(e); throw new InvalidDataException("Script "+script.getName()+" included more than once."); } // } From 196706c46e7b76c1cb24d4f87b523760c071c042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Kov=C3=A1cs?= Date: Mon, 24 Dec 2018 14:21:44 +0100 Subject: [PATCH 5/8] #255: log exception regardless of loglevel --- .../org/cristalise/kernel/entity/ItemImplementation.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cristalise/kernel/entity/ItemImplementation.java b/src/main/java/org/cristalise/kernel/entity/ItemImplementation.java index ada80d2..e3b3337 100644 --- a/src/main/java/org/cristalise/kernel/entity/ItemImplementation.java +++ b/src/main/java/org/cristalise/kernel/entity/ItemImplementation.java @@ -256,7 +256,7 @@ public String delegatedAction(SystemKey agentId, SystemKey delegateId, String st catch (AccessRightsException | InvalidTransitionException | ObjectNotFoundException | PersistencyException | InvalidDataException | ObjectAlreadyExistsException | InvalidCollectionModification ex) { - if (Logger.doLog(8)) Logger.error(ex); + Logger.error(ex); String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex); @@ -270,7 +270,7 @@ public String delegatedAction(SystemKey agentId, SystemKey delegateId, String st } } catch (InvalidAgentPathException | ObjectCannotBeUpdated | CannotManageException ex) { - if (Logger.doLog(8)) Logger.error(ex); + Logger.error(ex); String errorOutcome = handleError(agentId, delegateId, stepPath, lifeCycle, ex); @@ -423,7 +423,7 @@ public String queryData(String path) throws AccessRightsException, ObjectNotFoun throw new PersistencyException("Server exception: " + ex.getClass().getName()); } - if (Logger.doLog(9)) Logger.msg(9, "ItemImplementation::queryData(" + mItemPath + ") - result:" + result); + if (Logger.doLog(8)) Logger.msg(9, "ItemImplementation::queryData(" + mItemPath + ") - result:" + result); return result; } From 8fd1370a38ca523f9d83018d5f0d83594c9fb9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Kov=C3=A1cs?= Date: Mon, 24 Dec 2018 14:45:29 +0100 Subject: [PATCH 6/8] #149: set locker if it was not set before; allow null value for inputs --- .../java/org/cristalise/kernel/scripting/Script.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cristalise/kernel/scripting/Script.java b/src/main/java/org/cristalise/kernel/scripting/Script.java index db5b768..453405f 100644 --- a/src/main/java/org/cristalise/kernel/scripting/Script.java +++ b/src/main/java/org/cristalise/kernel/scripting/Script.java @@ -482,7 +482,7 @@ public boolean setInputParamValue(String name, Object value) throws ParameterExc if (!mAllInputParams.containsKey(name)) return false; if (param != null) { // param is in this script - if (!param.getType().isInstance(value)) { + if (value != null && !param.getType().isInstance(value)) { throw new ParameterException( "Parameter "+name+" in script "+mName+" v"+mVersion+" is wrong type \n"+ "Required: "+param.getType().toString()+"\n"+"Supplied: "+value.getClass().toString()); } @@ -515,12 +515,15 @@ public Object evaluate(ItemPath itemPath, CastorHashMap inputProps, String actCo } } - if (getAllInputParams().containsKey("item")) + if (getAllInputParams().containsKey("item") && getAllInputParams().get("item") != null) setInputParamValue("item", Gateway.getProxyManager().getProxy(itemPath)); - if (getAllInputParams().containsKey("agent")) + if (getAllInputParams().containsKey("agent") && getAllInputParams().get("agent") != null) setInputParamValue("agent", Gateway.getProxyManager().getProxy(Gateway.getLookup().getAgentPath("system"))); + if (getAllInputParams().containsKey("locker") && getAllInputParams().get("locker") != null) + setInputParamValue("locker", locker); + Object retVal = execute(); if (retVal == null) retVal = ""; From 56e221a176dd9c9330bb286b41aba10494353662 Mon Sep 17 00:00:00 2001 From: Aldrin Cunanan Date: Sat, 29 Dec 2018 22:11:51 +0800 Subject: [PATCH 7/8] Issue149 add default locker to script (#257) * #217 - CA.search() work even it the CA does not have a parent workflow * Travis build status based on https://shields.io * Add default locker to Script * #149: remove new lines * #149: Add transactionKey to ItemPath and use it to retrieve data --- README.md | 2 +- .../kernel/entity/proxy/ItemProxy.java | 107 +++++++++++------- .../cristalise/kernel/scripting/Script.java | 15 ++- 3 files changed, 74 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 1357b5f..ba5bfed 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -CRISTAL-iSE kernel [![Build Status](https://travis-ci.org/cristal-ise/kernel.svg?branch=master)](https://travis-ci.org/cristal-ise/kernel)[![Javadocs](http://javadoc.io/badge/org.cristalise/cristalise-kernel.svg)](http://javadoc.io/doc/org.cristalise/cristalise-kernel) +CRISTAL-iSE kernel [![Build Status](https://img.shields.io/travis/cristal-ise/kernel/master.svg?label=master)](https://travis-ci.org/cristal-ise/kernel)[![Build Status](https://img.shields.io/travis/cristal-ise/kernel/develop.svg?label=develop)](https://travis-ci.org/cristal-ise/kernel)[![Javadocs](http://javadoc.io/badge/org.cristalise/cristalise-kernel.svg)](http://javadoc.io/doc/org.cristalise/cristalise-kernel) ================== [![Join the chat at https://gitter.im/cristal-ise/kernel](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cristal-ise/kernel?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) diff --git a/src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java b/src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java index 2c43084..8540537 100644 --- a/src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java +++ b/src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java @@ -67,6 +67,9 @@ import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.ValidationException; +import lombok.Getter; +import lombok.Setter; + /** * It is a wrapper for the connection and communication with Item. @@ -80,6 +83,12 @@ public class ItemProxy private final HashMap, ProxyObserver> mSubscriptions; + /** + * Set Transaction key (aka locker) when ItemProxy is used in server side scripting + */ + @Getter @Setter + private Object transactionKey = null; + /** * * @param ior @@ -374,7 +383,7 @@ private Job getJobByName(String actName, AgentPath agent) throws AccessRightsExc * @throws ObjectNotFoundException objects were not found */ public Collection getCollection(BuiltInCollections collection) throws ObjectNotFoundException { - return getCollection(collection, null); + return getCollection(collection, (Integer)null); } /** @@ -387,7 +396,7 @@ public Collection getCollection(BuiltInCollections collection) throws ObjectN * @throws ObjectNotFoundException objects were not found */ public Collection getCollection(BuiltInCollections collection, Object locker) throws ObjectNotFoundException { - return getCollection(collection, null, locker); + return getCollection(collection, (Integer)null, locker == null ? transactionKey : locker); } /** @@ -399,7 +408,7 @@ public Collection getCollection(BuiltInCollections collection, Object locker) * @throws ObjectNotFoundException objects were not found */ public Collection getCollection(BuiltInCollections collection, Integer version) throws ObjectNotFoundException { - return getCollection(collection, version, null); + return getCollection(collection, version, transactionKey); } /** @@ -407,12 +416,12 @@ public Collection getCollection(BuiltInCollections collection, Integer versio * * @param collection The built-in Collection * @param version The collection number. Use null to get the 'last' version. - * @param locker + * @param locker the transaction key * @return the Collection object * @throws ObjectNotFoundException objects were not found */ public Collection getCollection(BuiltInCollections collection, Integer version, Object locker) throws ObjectNotFoundException { - return getCollection(collection.getName(), version, locker); + return getCollection(collection.getName(), version, locker == null ? transactionKey : locker); } /** @@ -423,7 +432,7 @@ public Collection getCollection(BuiltInCollections collection, Integer versio * @throws ObjectNotFoundException objects were not found */ public Collection getCollection(String collName) throws ObjectNotFoundException { - return getCollection(collName, null, null); + return getCollection(collName, (Integer)null, transactionKey); } /** @@ -436,7 +445,7 @@ public Collection getCollection(String collName) throws ObjectNotFoundExcepti * @throws ObjectNotFoundException objects were not found */ public Collection getCollection(String collName, Object locker) throws ObjectNotFoundException { - return getCollection(collName, null, locker); + return getCollection(collName, (Integer)null, locker == null ? transactionKey : locker); } /** @@ -448,7 +457,7 @@ public Collection getCollection(String collName, Object locker) throws Object * @throws ObjectNotFoundException objects were not found */ public Collection getCollection(String collName, Integer version) throws ObjectNotFoundException { - return getCollection(collName, version, null); + return getCollection(collName, version, transactionKey); } /** @@ -463,7 +472,7 @@ public Collection getCollection(String collName, Integer version) throws Obje */ public Collection getCollection(String collName, Integer version, Object locker) throws ObjectNotFoundException { String verStr = version == null ? "last" : String.valueOf(version); - return (Collection) getObject(ClusterType.COLLECTION+"/"+collName+"/"+verStr, locker); + return (Collection) getObject(ClusterType.COLLECTION+"/"+collName+"/"+verStr, locker == null ? transactionKey : locker); } /** @@ -485,7 +494,7 @@ public Workflow getWorkflow() throws ObjectNotFoundException { * @throws ObjectNotFoundException objects were not found */ public Workflow getWorkflow(Object locker) throws ObjectNotFoundException { - return (Workflow)getObject(ClusterType.LIFECYCLE+"/workflow", locker); + return (Workflow)getObject(ClusterType.LIFECYCLE+"/workflow", locker == null ? transactionKey : locker); } /** @@ -511,7 +520,7 @@ public boolean checkViewpoint(String schemaName, String viewName) throws ObjectN * @throws ObjectNotFoundException Object not found */ public boolean checkViewpoint(String schemaName, String viewName, Object locker) throws ObjectNotFoundException { - return checkContent(ClusterType.VIEWPOINT+"/"+schemaName, viewName, locker); + return checkContent(ClusterType.VIEWPOINT+"/"+schemaName, viewName, locker == null ? transactionKey : locker); } /** @@ -535,7 +544,7 @@ public String[] getViewpoints(String schemaName) throws ObjectNotFoundException * @throws ObjectNotFoundException Object not found */ public String[] getViewpoints(String schemaName, Object locker) throws ObjectNotFoundException { - return getContents(ClusterType.VIEWPOINT+"/"+schemaName, locker); + return getContents(ClusterType.VIEWPOINT+"/"+schemaName, locker == null ? transactionKey : locker); } /** @@ -561,7 +570,7 @@ public Viewpoint getViewpoint(String schemaName, String viewName) throws ObjectN * @throws ObjectNotFoundException objects were not found */ public Viewpoint getViewpoint(String schemaName, String viewName, Object locker) throws ObjectNotFoundException { - return (Viewpoint)getObject(ClusterType.VIEWPOINT+"/"+schemaName+"/"+viewName, locker); + return (Viewpoint)getObject(ClusterType.VIEWPOINT+"/"+schemaName+"/"+viewName, locker == null ? transactionKey : locker); } /** @@ -574,7 +583,7 @@ public Viewpoint getViewpoint(String schemaName, String viewName, Object locker) * @throws ObjectNotFoundException Object not found */ public boolean checkOutcome(String schemaName, int schemaVersion, int eventId) throws ObjectNotFoundException { - return checkOutcome(schemaName, schemaVersion, eventId, null); + return checkOutcome(schemaName, schemaVersion, eventId, transactionKey); } /** @@ -590,7 +599,7 @@ public boolean checkOutcome(String schemaName, int schemaVersion, int eventId) t */ public boolean checkOutcome(String schemaName, int schemaVersion, int eventId, Object locker) throws ObjectNotFoundException { try { - return checkOutcome(LocalObjectLoader.getSchema(schemaName, schemaVersion), eventId, locker); + return checkOutcome(LocalObjectLoader.getSchema(schemaName, schemaVersion), eventId, locker == null ? transactionKey : locker); } catch (InvalidDataException e) { Logger.error(e); @@ -607,7 +616,7 @@ public boolean checkOutcome(String schemaName, int schemaVersion, int eventId, O * @throws ObjectNotFoundException Object not found */ public boolean checkOutcome(Schema schema, int eventId) throws ObjectNotFoundException { - return checkOutcome(schema, eventId, null); + return checkOutcome(schema, eventId, transactionKey); } /** @@ -621,7 +630,7 @@ public boolean checkOutcome(Schema schema, int eventId) throws ObjectNotFoundExc * @throws ObjectNotFoundException Object not found */ public boolean checkOutcome(Schema schema, int eventId, Object locker) throws ObjectNotFoundException { - return checkContent(ClusterType.OUTCOME+"/"+schema.getName()+"/"+schema.getVersion(), String.valueOf(eventId), locker); + return checkContent(ClusterType.OUTCOME+"/"+schema.getName()+"/"+schema.getVersion(), String.valueOf(eventId), locker == null ? transactionKey : locker); } /** @@ -635,7 +644,7 @@ public boolean checkOutcome(Schema schema, int eventId, Object locker) throws Ob * @throws ObjectNotFoundException object was not found */ public Outcome getOutcome(String schemaName, int schemaVersion, int eventId) throws ObjectNotFoundException { - return getOutcome(schemaName, schemaVersion, eventId, null); + return getOutcome(schemaName, schemaVersion, eventId, transactionKey); } /** @@ -651,7 +660,7 @@ public Outcome getOutcome(String schemaName, int schemaVersion, int eventId) thr */ public Outcome getOutcome(String schemaName, int schemaVersion, int eventId, Object locker) throws ObjectNotFoundException { try { - return getOutcome(LocalObjectLoader.getSchema(schemaName, schemaVersion), eventId, locker); + return getOutcome(LocalObjectLoader.getSchema(schemaName, schemaVersion), eventId, locker == null ? transactionKey : locker); } catch (InvalidDataException e) { Logger.error(e); @@ -668,7 +677,7 @@ public Outcome getOutcome(String schemaName, int schemaVersion, int eventId, Obj * @throws ObjectNotFoundException object was not found */ public Outcome getOutcome(Schema schema, int eventId) throws ObjectNotFoundException { - return getOutcome(schema, eventId, null); + return getOutcome(schema, eventId, transactionKey); } /** @@ -682,7 +691,7 @@ public Outcome getOutcome(Schema schema, int eventId) throws ObjectNotFoundExcep * @throws ObjectNotFoundException object was not found */ public Outcome getOutcome(Schema schema, int eventId, Object locker) throws ObjectNotFoundException { - return (Outcome)getObject(ClusterType.OUTCOME+"/"+schema.getName()+"/"+schema.getVersion()+"/"+eventId, locker); + return (Outcome)getObject(ClusterType.OUTCOME+"/"+schema.getName()+"/"+schema.getVersion()+"/"+eventId, locker == null ? transactionKey : locker); } /** @@ -694,7 +703,7 @@ public Outcome getOutcome(Schema schema, int eventId, Object locker) throws Obje * @throws ObjectNotFoundException Object not found */ public boolean checkOutcomeAttachment(Schema schema, int eventId) throws ObjectNotFoundException { - return checkOutcomeAttachment(schema, eventId, null); + return checkOutcomeAttachment(schema, eventId, transactionKey); } /** @@ -708,7 +717,7 @@ public boolean checkOutcomeAttachment(Schema schema, int eventId) throws ObjectN * @throws ObjectNotFoundException Object not found */ public boolean checkOutcomeAttachment(Schema schema, int eventId, Object locker) throws ObjectNotFoundException { - return checkContent(ClusterType.ATTACHMENT+"/"+schema.getName()+"/"+schema.getVersion(), String.valueOf(eventId), locker); + return checkContent(ClusterType.ATTACHMENT+"/"+schema.getName()+"/"+schema.getVersion(), String.valueOf(eventId), locker == null ? transactionKey : locker); } /** @@ -721,7 +730,7 @@ public boolean checkOutcomeAttachment(Schema schema, int eventId, Object locker) * @throws ObjectNotFoundException object was not found */ public OutcomeAttachment getOutcomeAttachment(String schemaName, int schemaVersion, int eventId) throws ObjectNotFoundException { - return getOutcomeAttachment(schemaName, schemaVersion, eventId, null); + return getOutcomeAttachment(schemaName, schemaVersion, eventId, transactionKey); } /** @@ -739,7 +748,7 @@ public OutcomeAttachment getOutcomeAttachment(String schemaName, int schemaVersi throws ObjectNotFoundException { try { - return getOutcomeAttachment(LocalObjectLoader.getSchema(schemaName, schemaVersion), eventId, locker); + return getOutcomeAttachment(LocalObjectLoader.getSchema(schemaName, schemaVersion), eventId, locker == null ? transactionKey : locker); } catch (InvalidDataException e) { Logger.error(e); @@ -756,7 +765,7 @@ public OutcomeAttachment getOutcomeAttachment(String schemaName, int schemaVersi * @throws ObjectNotFoundException object was not found */ public OutcomeAttachment getOutcomeAttachment(Schema schema, int eventId) throws ObjectNotFoundException { - return getOutcomeAttachment(schema, eventId, null); + return getOutcomeAttachment(schema, eventId, transactionKey); } /** @@ -770,7 +779,7 @@ public OutcomeAttachment getOutcomeAttachment(Schema schema, int eventId) throws * @throws ObjectNotFoundException object was not found */ public OutcomeAttachment getOutcomeAttachment(Schema schema, int eventId, Object locker) throws ObjectNotFoundException { - return (OutcomeAttachment)getObject(ClusterType.ATTACHMENT+"/"+schema.getName()+"/"+schema.getVersion()+"/"+eventId, locker); + return (OutcomeAttachment)getObject(ClusterType.ATTACHMENT+"/"+schema.getName()+"/"+schema.getVersion()+"/"+eventId, locker == null ? transactionKey : locker); } /** @@ -842,6 +851,18 @@ protected void finalize() throws Throwable { * @throws ObjectNotFoundException path was not correct */ public String queryData(String path) throws ObjectNotFoundException { + return queryData(path, transactionKey); + } + + /** + * Query data of the Item located by the ClusterStorage path + * + * @param path the ClusterStorage path + * @param locker the transaction key + * @return the data in XML form + * @throws ObjectNotFoundException path was not correct + */ + public String queryData(String path, Object locker) throws ObjectNotFoundException { try { Logger.msg(7, "ItemProxy.queryData() - "+mItemPath+"/"+path); @@ -860,7 +881,7 @@ public String queryData(String path) throws ObjectNotFoundException { return retString.toString(); } else { - C2KLocalObject target = Gateway.getStorage().get(mItemPath, path, null); + C2KLocalObject target = Gateway.getStorage().get(mItemPath, path, locker == null ? transactionKey : locker); return Gateway.getMarshaller().marshall(target); } } @@ -882,7 +903,7 @@ public String queryData(String path) throws ObjectNotFoundException { * @throws ObjectNotFoundException path was not correct */ public boolean checkContent(String path, String name) throws ObjectNotFoundException { - return checkContent(path, name, null); + return checkContent(path, name, transactionKey); } /** @@ -894,7 +915,7 @@ public boolean checkContent(String path, String name) throws ObjectNotFoundExcep * @throws ObjectNotFoundException path was not correct */ public boolean checkContent(ClusterType cluster, String name) throws ObjectNotFoundException { - return checkContent(cluster.getName(), name, null); + return checkContent(cluster.getName(), name, transactionKey); } /** @@ -908,7 +929,7 @@ public boolean checkContent(ClusterType cluster, String name) throws ObjectNotFo * @throws ObjectNotFoundException path was not correct */ public boolean checkContent(String path, String name, Object locker) throws ObjectNotFoundException { - for (String key : getContents(path, locker)) if (key.equals(name)) return true; + for (String key : getContents(path, locker == null ? transactionKey : locker)) if (key.equals(name)) return true; return false; } @@ -933,7 +954,7 @@ public String[] getContents(ClusterType type) throws ObjectNotFoundException { * @throws ObjectNotFoundException Object nt found */ public String[] getContents(ClusterType type, Object locker) throws ObjectNotFoundException { - return getContents(type.getName(), locker); + return getContents(type.getName(), locker == null ? transactionKey : locker); } /** @@ -944,7 +965,7 @@ public String[] getContents(ClusterType type, Object locker) throws ObjectNotFou * @throws ObjectNotFoundException Object not found */ public String[] getContents(String path) throws ObjectNotFoundException { - return getContents(path, null); + return getContents(path, transactionKey); } /** @@ -958,8 +979,8 @@ public String[] getContents(String path) throws ObjectNotFoundException { */ public String[] getContents(String path, Object locker) throws ObjectNotFoundException { try { - return Gateway.getStorage().getClusterContents(mItemPath, path); - //return Gateway.getStorage().getClusterContents(mItemPath, path, locker); + //return Gateway.getStorage().getClusterContents(mItemPath, path); + return Gateway.getStorage().getClusterContents(mItemPath, path, locker == null ? transactionKey : locker); } catch (PersistencyException e) { throw new ObjectNotFoundException(e.toString()); @@ -996,7 +1017,7 @@ public C2KLocalObject getObject(ClusterType type) throws ObjectNotFoundException * @throws ObjectNotFoundException the path did not result in a C2KLocalObject */ public C2KLocalObject getObject(String path) throws ObjectNotFoundException { - return getObject(path, null); + return getObject(path, transactionKey); } /** @@ -1010,7 +1031,7 @@ public C2KLocalObject getObject(String path) throws ObjectNotFoundException { */ public C2KLocalObject getObject(String path, Object locker) throws ObjectNotFoundException { try { - return Gateway.getStorage().get(mItemPath, path , locker); + return Gateway.getStorage().get(mItemPath, path , locker == null ? transactionKey : locker); } catch( PersistencyException ex ) { Logger.error("ItemProxy.getObject() - Exception loading object:"+mItemPath+"/"+path); @@ -1048,7 +1069,7 @@ public String getProperty(BuiltInItemProperties prop, String defaultValue) { * @return the value or the defaultValue */ public String getProperty(String name, String defaultValue) { - return getProperty(name, defaultValue, null); + return getProperty(name, defaultValue, transactionKey); } /** @@ -1062,8 +1083,8 @@ public String getProperty(String name, String defaultValue) { */ public String getProperty(String name, String defaultValue, Object locker) { try { - if (checkContent(ClusterType.PROPERTY.getName(), name, locker)) { - return getProperty(name, locker); + if (checkContent(ClusterType.PROPERTY.getName(), name, locker == null ? transactionKey : locker)) { + return getProperty(name, locker == null ? transactionKey : locker); } } catch(ObjectNotFoundException e) { @@ -1094,7 +1115,7 @@ public String getProperty( String name ) throws ObjectNotFoundException { public String getProperty(String name, Object locker) throws ObjectNotFoundException { Logger.msg(5, "ItemProxy.getProperty() - "+name+" from item "+mItemPath); - Property prop = (Property)getObject(ClusterType.PROPERTY+"/"+name, locker); + Property prop = (Property)getObject(ClusterType.PROPERTY+"/"+name, locker == null ? transactionKey : locker); if(prop != null) return prop.getValue(); else throw new ObjectNotFoundException("ItemProxy.getProperty() - COULD not find property "+name+" from item "+mItemPath); @@ -1126,7 +1147,7 @@ public String getType() { * @throws ObjectNotFoundException there is no event for the given id */ public Event getEvent(int eventId) throws ObjectNotFoundException { - return getEvent(eventId, null); + return getEvent(eventId, transactionKey); } /** @@ -1139,7 +1160,7 @@ public Event getEvent(int eventId) throws ObjectNotFoundException { * @throws ObjectNotFoundException there is no event for the given id */ public Event getEvent(int eventId, Object locker) throws ObjectNotFoundException { - return (Event) getObject(HISTORY + "/" + eventId, locker); + return (Event) getObject(HISTORY + "/" + eventId, locker == null ? transactionKey : locker); } diff --git a/src/main/java/org/cristalise/kernel/scripting/Script.java b/src/main/java/org/cristalise/kernel/scripting/Script.java index 453405f..cf64baf 100644 --- a/src/main/java/org/cristalise/kernel/scripting/Script.java +++ b/src/main/java/org/cristalise/kernel/scripting/Script.java @@ -515,21 +515,24 @@ public Object evaluate(ItemPath itemPath, CastorHashMap inputProps, String actCo } } - if (getAllInputParams().containsKey("item") && getAllInputParams().get("item") != null) - setInputParamValue("item", Gateway.getProxyManager().getProxy(itemPath)); + if (getAllInputParams().containsKey("item") && getAllInputParams().get("item") != null) { + ItemProxy item = Gateway.getProxyManager().getProxy(itemPath); + item.setTransactionKey(locker); + setInputParamValue("item", item); + } - if (getAllInputParams().containsKey("agent") && getAllInputParams().get("agent") != null) + if (getAllInputParams().containsKey("agent") && getAllInputParams().get("agent") != null) { setInputParamValue("agent", Gateway.getProxyManager().getProxy(Gateway.getLookup().getAgentPath("system"))); + } - if (getAllInputParams().containsKey("locker") && getAllInputParams().get("locker") != null) + if (getAllInputParams().containsKey("locker") && getAllInputParams().get("locker") != null) { setInputParamValue("locker", locker); + } Object retVal = execute(); if (retVal == null) retVal = ""; - //Logger.msg(2, "Script.evaluate("+getName()+") - Script returned:'"+retVal+"'"); - return retVal; } catch (Exception e) { From 7845981def21deef7a2a0a0180d13b7bbffb91fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zsolt=20Kov=C3=A1cs?= Date: Mon, 31 Dec 2018 10:22:02 +0100 Subject: [PATCH 8/8] #149: getOutcome(Viewpoint) methods to support ServerSide scripting --- .../kernel/entity/proxy/ItemProxy.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java b/src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java index 8540537..7f50787 100644 --- a/src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java +++ b/src/main/java/org/cristalise/kernel/entity/proxy/ItemProxy.java @@ -694,6 +694,36 @@ public Outcome getOutcome(Schema schema, int eventId, Object locker) throws Obje return (Outcome)getObject(ClusterType.OUTCOME+"/"+schema.getName()+"/"+schema.getVersion()+"/"+eventId, locker == null ? transactionKey : locker); } + /** + * Gets the Outcome selected by the Viewpoint + * + * @param view the Viewpoint to be used + * @return the Outcome object + * @throws ObjectNotFoundException object was not found + */ + public Outcome getOutcome(Viewpoint view) throws ObjectNotFoundException { + return getOutcome(view, transactionKey); + } + + /** + * Gets the Outcome selected by the Viewpoint. This method can be used in server side Script to find uncommitted changes + * during the active transaction. + * + * @param view the Viewpoint to be used + * @param locker the transaction key + * @return the Outcome object + * @throws ObjectNotFoundException object was not found + */ + public Outcome getOutcome(Viewpoint view, Object locker) throws ObjectNotFoundException { + try { + return view.getOutcome(locker == null ? transactionKey : locker); + } + catch (PersistencyException e) { + Logger.error(e); + throw new ObjectNotFoundException(e.getMessage()); + } + } + /** * Check if the given OutcomeAttachment exists *