diff --git a/src/main/java/org/nrg/xnat/event/listeners/AutomationEventScriptHandler.java b/src/main/java/org/nrg/xnat/event/listeners/AutomationEventScriptHandler.java index 113c83e078dcc34c23d7705d7284f637465a71a8..4062b61cc8dd980f00b764c39a8649055fea6e75 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/AutomationEventScriptHandler.java +++ b/src/main/java/org/nrg/xnat/event/listeners/AutomationEventScriptHandler.java @@ -301,7 +301,6 @@ public class AutomationEventScriptHandler implements Consumer<Event<AutomationEv } final String eventName = eventID.replaceAll("\\*OPEN\\*", "(").replaceAll("\\*CLOSE\\*", ")"); //check to see if this has been handled before - final AutomationCompletionEventI automationCompletionEvent = automationEvent.getAutomationCompletionEvent(); for (final Script script : getScripts(automationEvent.getExternalId(), eventClass, eventID, filterMap)) { try { final String action = "Executed script " + script.getScriptId(); @@ -321,10 +320,7 @@ public class AutomationEventScriptHandler implements Consumer<Event<AutomationEv scriptWrk.setStatus(PersistentWorkflowUtils.QUEUED); WorkflowUtils.save(scriptWrk, scriptWrk.buildEvent()); - final AutomatedScriptRequest request = new AutomatedScriptRequest(automationEvent.getSrcStringifiedId(), automationEvent.getSrcEventClass(), user, script.getScriptId(), eventName, - scriptWrk.getWorkflowId().toString(), automationEvent.getEntityType(), automationEvent.getSrcStringifiedId(), automationEvent.getExternalId(), - automationEvent.getParameterMap(), automationCompletionEvent); - + final AutomatedScriptRequest request = new AutomatedScriptRequest(automationEvent, eventName, user, script, scriptWrk); XDAT.sendJmsRequest(request); } catch (Exception e1) { logger.error("Script launch exception", e1); diff --git a/src/main/java/org/nrg/xnat/services/messaging/automation/AutomatedScriptRequest.java b/src/main/java/org/nrg/xnat/services/messaging/automation/AutomatedScriptRequest.java index a0c0e286a7f4549d896b840ce2ec8df64f69d3b1..e7e2e281fb102d4a433aabbbb249f166cb8394a4 100644 --- a/src/main/java/org/nrg/xnat/services/messaging/automation/AutomatedScriptRequest.java +++ b/src/main/java/org/nrg/xnat/services/messaging/automation/AutomatedScriptRequest.java @@ -1,7 +1,10 @@ package org.nrg.xnat.services.messaging.automation; import org.json.JSONObject; +import org.nrg.automation.entities.Script; import org.nrg.automation.event.AutomationCompletionEventI; +import org.nrg.automation.event.AutomationEventImplementerI; +import org.nrg.xft.event.persist.PersistentWorkflowI; import org.nrg.xft.security.UserI; import com.google.common.collect.Maps; @@ -47,7 +50,11 @@ public class AutomatedScriptRequest implements Serializable { /** The _argument map. */ private final Map<String,Object> _argumentMap = Maps.newHashMap(); + /** The _automation completion event. */ private final AutomationCompletionEventI _automationCompletionEvent; + + /** The _automation event. */ + private final AutomationEventImplementerI _automationEvent; /** * Instantiates a new automated script request. @@ -77,6 +84,7 @@ public class AutomatedScriptRequest implements Serializable { _dataId = dataId; _externalId = externalId; _automationCompletionEvent = automationCompletionEvent; + _automationEvent = null; if (argumentMap != null) { _argumentMap.putAll(argumentMap); } @@ -117,6 +125,32 @@ public class AutomatedScriptRequest implements Serializable { this(srcEventId, srcEventClass, user, scriptId, event, scriptWorkflow, dataType, dataId, externalId, argumentMap, null); } + /** + * Instantiates a new automated script request. + * + * @param automationEvent the automation event + * @param eventName the event name + * @param user the user + * @param script the script + * @param scriptWrk the script wrk + */ + public AutomatedScriptRequest(AutomationEventImplementerI automationEvent, String eventName, UserI user, Script script, PersistentWorkflowI scriptWrk) { + this._automationEvent = automationEvent; + this._srcEventId = automationEvent.getSrcStringifiedId(); + this._srcEventClass = automationEvent.getSrcEventClass(); + this._user = user; + this._scriptId = script.getScriptId(); + this._event = eventName; + this._scriptWorkflowId = scriptWrk.getWorkflowId().toString(); + this._dataType = automationEvent.getEntityType(); + this._dataId = automationEvent.getEntityId(); + this._externalId = automationEvent.getExternalId(); + this._automationCompletionEvent = automationEvent.getAutomationCompletionEvent(); + if (automationEvent.getParameterMap()!=null) { + this._argumentMap.putAll(automationEvent.getParameterMap()); + } + } + /** * Gets the src event id. * @@ -216,6 +250,16 @@ public class AutomatedScriptRequest implements Serializable { public AutomationCompletionEventI getAutomationCompletionEvent() { return _automationCompletionEvent; } + + + /** + * Gets the automation event. + * + * @return the automation event + */ + public AutomationEventImplementerI getAutomationEvent() { + return _automationEvent; + } /** * Gets the argument json. diff --git a/src/main/java/org/nrg/xnat/services/messaging/automation/AutomatedScriptRequestListener.java b/src/main/java/org/nrg/xnat/services/messaging/automation/AutomatedScriptRequestListener.java index a3a3efbbb86149296ef8db19666e3259810ad0d8..24b95097808dd3863f53b573b7265f0742e751cf 100644 --- a/src/main/java/org/nrg/xnat/services/messaging/automation/AutomatedScriptRequestListener.java +++ b/src/main/java/org/nrg/xnat/services/messaging/automation/AutomatedScriptRequestListener.java @@ -3,10 +3,12 @@ package org.nrg.xnat.services.messaging.automation; import org.nrg.automation.entities.ScriptOutput; import org.nrg.automation.entities.ScriptOutput.Status; import org.nrg.automation.event.AutomationCompletionEventI; +import org.nrg.automation.event.AutomationEventImplementerI; import org.nrg.automation.services.ScriptRunnerService; import org.nrg.framework.exceptions.NrgServiceException; import org.nrg.framework.services.NrgEventService; import org.nrg.xdat.turbine.utils.AdminUtils; +import org.nrg.xft.event.entities.WorkflowStatusEvent; import org.nrg.xft.event.persist.PersistentWorkflowI; import org.nrg.xft.event.persist.PersistentWorkflowUtils; import org.nrg.xnat.utils.WorkflowUtils; @@ -42,6 +44,7 @@ public class AutomatedScriptRequestListener { workflow.setStatus(PersistentWorkflowUtils.IN_PROGRESS); WorkflowUtils.save(workflow, workflow.buildEvent()); final AutomationCompletionEventI automationCompletionEvent = request.getAutomationCompletionEvent(); + final AutomationEventImplementerI automationEvent = request.getAutomationEvent(); final Map<String, Object> parameters = new HashMap<>(); parameters.put("user", request.getUser()); @@ -51,9 +54,17 @@ public class AutomatedScriptRequestListener { final String srcEventClass = request.getSrcEventClass(); parameters.put("srcEventClass", srcEventClass); // For backwards compatibility - if (srcEventClass.contains("WorkflowStatusEvent") || srcEventClass.contains("WrkWorkflowdata")) { + if (srcEventClass.contains("WorkflowStatusEvent") && automationEvent instanceof WorkflowStatusEvent) { + final WorkflowStatusEvent wfse = (WorkflowStatusEvent) automationEvent; + if (wfse!=null && wfse.getWorkflow()!=null) { + parameters.put("srcWorkflowId", wfse.getWorkflow().getWorkflowId()); + } + } else if (srcEventClass.contains("WrkWorkflowdata")) { parameters.put("srcWorkflowId", request.getArgumentMap().get("wrkWorkflowId")); } + if (parameters.get("srcWorkflowId")==null) { + parameters.put("srcWorkflowId", null); + } parameters.put("scriptWorkflowId", request.getScriptWorkflowId()); parameters.put("dataType", request.getDataType()); parameters.put("dataId", request.getDataId()); diff --git a/src/main/webapp/scripts/xnat/app/eventsManager.js b/src/main/webapp/scripts/xnat/app/eventsManager.js index 8cc0599dd798270221ec81aec7554af229f4ff2d..73b5177165661b18426baf1d9be82c9cdcfce639 100644 --- a/src/main/webapp/scripts/xnat/app/eventsManager.js +++ b/src/main/webapp/scripts/xnat/app/eventsManager.js @@ -108,7 +108,7 @@ $(function(){ else { if (!hasEvents) { $add_event_handler.prop('disabled',true); - $no_events_defined.show(); + $no_event_handlers.show(); } else { $no_event_handlers.show(); diff --git a/src/main/webapp/xnat-templates/screens/xnat_projectData/xnat_projectData_summary_manage.vm b/src/main/webapp/xnat-templates/screens/xnat_projectData/xnat_projectData_summary_manage.vm index 024af73d65d004b61a76325a90d691b8ba9392a2..d84106629a122b139e513f1aacb605125d5a63fe 100644 --- a/src/main/webapp/xnat-templates/screens/xnat_projectData/xnat_projectData_summary_manage.vm +++ b/src/main/webapp/xnat-templates/screens/xnat_projectData/xnat_projectData_summary_manage.vm @@ -474,7 +474,7 @@ <h3>Event Handlers</h3> <div id="events_list" style="min-height:120px;"> - <p id="no_events_defined" style="display:none;padding:20px;">There are no events currently defined for this site.</p> + ##<p id="no_events_defined" style="display:none;padding:20px;">There are no events currently defined for this site.</p> <p id="no_event_handlers" style="display:none;padding:20px;">There are no event handlers currently configured for this project.</p> <!-- <table id="events_table" class="xnat-table" style="display:none;width:100%;">