Skip to content

Commit

Permalink
added new goobiscript to set priority for one or all steps of processes
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenHankiewicz committed Jul 4, 2019
1 parent c171e3d commit a2f2754
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Goobi/src/de/sub/goobi/helper/GoobiScript.java
Expand Up @@ -35,6 +35,7 @@
import org.goobi.goobiScript.GoobiScriptPropertySet;
import org.goobi.goobiScript.GoobiScriptRunPlugin;
import org.goobi.goobiScript.GoobiScriptRunScript;
import org.goobi.goobiScript.GoobiScriptSetPriority;
import org.goobi.goobiScript.GoobiScriptSetProject;
import org.goobi.goobiScript.GoobiScriptSetRuleset;
import org.goobi.goobiScript.GoobiScriptSetStepNumber;
Expand Down Expand Up @@ -179,6 +180,8 @@ public String execute(List<Integer> inProzesse, String inScript) {
igs = new GoobiScriptMoveWorkflowForward();
} else if (myParameters.get("action").equalsIgnoreCase("moveWorkflowBackward")) {
igs = new GoobiScriptMoveWorkflowBackward();
} else if (myParameters.get("action").equalsIgnoreCase("setPriority")) {
igs = new GoobiScriptSetPriority();
} else if (this.myParameters.get("action").equals("executeStepAndUpdateStatus")) {
// can be used to execute a task. The script checks, if it is a script task, export task, plugin task or http task
// if the task was automatic and the execution successful, the task will be closed and the next one is opened,
Expand Down
121 changes: 121 additions & 0 deletions Goobi/src/org/goobi/goobiScript/GoobiScriptSetPriority.java
@@ -0,0 +1,121 @@
package org.goobi.goobiScript;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.goobi.beans.Process;
import org.goobi.beans.Step;
import org.goobi.production.enums.GoobiScriptResultType;
import org.goobi.production.enums.LogType;

import de.sub.goobi.helper.Helper;
import de.sub.goobi.helper.exceptions.DAOException;
import de.sub.goobi.persistence.managers.ProcessManager;
import de.sub.goobi.persistence.managers.StepManager;
import lombok.extern.log4j.Log4j;

@Log4j
public class GoobiScriptSetPriority extends AbstractIGoobiScript implements IGoobiScript {

@Override
public boolean prepare(List<Integer> processes, String command, HashMap<String, String> parameters) {
super.prepare(processes, command, parameters);

if (parameters.get("priority") == null || parameters.get("priority").equals("")) {
Helper.setFehlerMeldung("goobiScriptfield", "Missing parameter: ", "priority");
return false;
}

String prio = parameters.get("priority").toLowerCase();
if (!prio.equals("standard") && !prio.equals("high") && !prio.equals("higher") && !prio.equals("highest") && !prio.equals("correction")) {
Helper.setFehlerMeldung("goobiScriptfield", "Wrong priority parameter", "(only the following values are allowed: standard, high, higher, highest, correction)");
return false;
}

// add all valid commands to list
for (Integer i : processes) {
GoobiScriptResult gsr = new GoobiScriptResult(i, command, username, starttime);
resultList.add(gsr);
}

return true;
}

@Override
public void execute() {
SetPriorityThread et = new SetPriorityThread();
et.start();
}

class SetPriorityThread extends Thread {
@Override
public void run() {
// wait until there is no earlier script to be executed first
while (gsm.getAreEarlierScriptsWaiting(starttime)){
try {
sleep(1000);
} catch (InterruptedException e) {
log.error("Problem while waiting for running GoobiScripts", e);
}
}

String st = parameters.get("steptitle");
if (st==null) {
st = "";
}

int prio = 0;
switch (parameters.get("priority").toLowerCase()) {
case "high":
prio = 1;
break;
case "higher":
prio = 2;
break;
case "highest":
prio = 3;
break;
case "correction":
prio = 10;
break;
default:
prio = 0;
}

// execute all jobs that are still in waiting state
ArrayList<GoobiScriptResult> templist = new ArrayList<>(resultList);
for (GoobiScriptResult gsr : templist) {
if (gsm.getAreScriptsWaiting(command) && gsr.getResultType() == GoobiScriptResultType.WAITING && gsr.getCommand().equals(command)) {
Process p = ProcessManager.getProcessById(gsr.getProcessId());
gsr.setProcessTitle(p.getTitel());
gsr.setResultType(GoobiScriptResultType.RUNNING);
gsr.updateTimestamp();

for (Iterator<Step> iterator = p.getSchritteList().iterator(); iterator.hasNext();) {
Step s = iterator.next();
if (st.length() == 0 || s.getTitel().equals(st)) {
s.setPrioritaet(prio);
try {
StepManager.saveStep(s);
Helper.addMessageToProcessLog(p.getId(), LogType.DEBUG, "Changed priority of step '" + s.getTitel() + "' to '" + s.getPrioritaet() + "' using GoobiScript.", username);
log.info("Changed priority of step '" + s.getTitel() + "' to '" + s.getPrioritaet() + "' using GoobiScript for process with ID " + p.getId());
gsr.setResultMessage("Changed priority of step '" + s.getTitel() + "' to '" + s.getReihenfolge() + "' successfully.");
gsr.setResultType(GoobiScriptResultType.OK);
} catch (DAOException e) {
log.error("goobiScriptfield" + "Error while saving process: " + p.getTitel(), e);
gsr.setResultMessage("Error while changing the priority of step '" + s.getTitel() + "' to '" + s.getReihenfolge() + "'.");
gsr.setResultType(GoobiScriptResultType.ERROR);
gsr.setErrorText(e.getMessage());
}
}
}
gsr.updateTimestamp();
}
}
}
}

}
1 change: 1 addition & 0 deletions Goobi/webapp/uii/includes/process/list_action.xhtml
Expand Up @@ -129,6 +129,7 @@
<span class="badge badge-intranda-light pointer" onclick="document.getElementById('goobiScriptfield').value='action:importFromFileSystem sourcefolder:SOURCE_FOLDER'">importFromFileSystem</span>
<span class="badge badge-intranda-light pointer" onclick="document.getElementById('goobiScriptfield').value='action:setRuleset &quot;ruleset:TITLE_RULESET&quot;'">setRuleset</span>
<span class="badge badge-intranda-light pointer" onclick="document.getElementById('goobiScriptfield').value='action:setProject &quot;project:TITLE_PROJECT&quot;'">setProject</span>
<span class="badge badge-intranda-light pointer" onclick="document.getElementById('goobiScriptfield').value='action:setPriority &quot;priority:standard_high_higher_highest_correction&quot; &quot;steptitle:TITLE_STEP&quot;'">setPriority</span>
<span class="badge badge-intranda-light pointer" onclick="document.getElementById('goobiScriptfield').value='action:deleteStep &quot;steptitle:TITLE_STEP&quot;'">deleteStep</span>
<span class="badge badge-intranda-light pointer" onclick="document.getElementById('goobiScriptfield').value='action:addStep &quot;steptitle:TITLE_STEP&quot; number:NUMBER_1_TO_?'">addStep</span>
<span class="badge badge-intranda-light pointer" onclick="document.getElementById('goobiScriptfield').value='action:setStepStatus &quot;steptitle:TITLE_STEP&quot; status:NUMBER_0_TO_5'">setStepStatus</span>
Expand Down

0 comments on commit a2f2754

Please sign in to comment.