Skip to content
Snippets Groups Projects
Commit ae9467ec authored by Mike Hodge's avatar Mike Hodge
Browse files

XNAT-4507, XNAT-4508: Fix missing variables in automation and wrong div...

XNAT-4507, XNAT-4508:  Fix missing variables in automation and wrong div showing when no event handlers
parent 8b4d7c3c
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
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.
......
......@@ -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());
......
......@@ -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();
......
......@@ -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%;">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment