Commit b4b07429 authored by Marco Descher's avatar Marco Descher 🏔

[11238] ITask#getResultEntryAsTypedList and multiple other changes

parent 40d49fcc
Pipeline #12143 passed with stages
in 4 minutes and 43 seconds
......@@ -253,8 +253,8 @@ public class BillLabResultOnCreationIdentifiedRunnable implements IIdentifiedRun
}
@Override
public Map<String, String> getDefaultRunContext(){
Map<String, String> defaultRunContext = new HashMap<>();
public Map<String, Serializable> getDefaultRunContext(){
Map<String, Serializable> defaultRunContext = new HashMap<>();
defaultRunContext.put(RunContextParameter.IDENTIFIABLE_ID,
RunContextParameter.VALUE_MISSING_REQUIRED);
defaultRunContext.put(Parameters.ADDCONS_SAMEDAY, Boolean.TRUE.toString());
......
......@@ -75,12 +75,12 @@ public class HL7ImporterIIdentifiedRunnable implements IIdentifiedRunnable {
}
@Override
public Map<String, String> getDefaultRunContext() {
Map<String, String> defaultRunContext = new HashMap<>();
public Map<String, Serializable> getDefaultRunContext() {
Map<String, Serializable> defaultRunContext = new HashMap<>();
defaultRunContext.put(RunContextParameter.STRING_URL, RunContextParameter.VALUE_MISSING_REQUIRED);
defaultRunContext.put(RCP_BOOLEAN_CREATE_PATIENT_IF_NOT_EXISTS, Boolean.toString(false));
defaultRunContext.put(RCP_BOOLEAN_CREATE_LABORATORY_IF_NOT_EXISTS, Boolean.toString(true));
defaultRunContext.put(RCP_BOOLEAN_MOVE_FILE_AFTER_IMPORT, Boolean.toString(true));
defaultRunContext.put(RCP_BOOLEAN_CREATE_PATIENT_IF_NOT_EXISTS, Boolean.FALSE);
defaultRunContext.put(RCP_BOOLEAN_CREATE_LABORATORY_IF_NOT_EXISTS, Boolean.TRUE);
defaultRunContext.put(RCP_BOOLEAN_MOVE_FILE_AFTER_IMPORT, Boolean.TRUE);
defaultRunContext.put(RCP_STRING_IMPORTER_LABNAME, "myLab");
return defaultRunContext;
}
......@@ -89,8 +89,8 @@ public class HL7ImporterIIdentifiedRunnable implements IIdentifiedRunnable {
public Map<String, Serializable> run(Map<String, Serializable> context, IProgressMonitor progressMonitor,
Logger logger) throws TaskException {
boolean bCreateLaboratoryIfNotExists = Boolean.valueOf((String) context.get(RCP_BOOLEAN_CREATE_LABORATORY_IF_NOT_EXISTS));
boolean bMoveFile = Boolean.valueOf((String) context.get(RCP_BOOLEAN_MOVE_FILE_AFTER_IMPORT));
boolean bCreateLaboratoryIfNotExists = (boolean) context.get(RCP_BOOLEAN_CREATE_LABORATORY_IF_NOT_EXISTS);
boolean bMoveFile = (boolean) context.get(RCP_BOOLEAN_MOVE_FILE_AFTER_IMPORT);
String urlString = (String) context.get(RunContextParameter.STRING_URL);
String labName = (String) context.get(RCP_STRING_IMPORTER_LABNAME);
......
......@@ -46,7 +46,7 @@
</eAnnotations>
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EMap">
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eTypeArguments eClassifier="#//Serializable"/>
</eGenericType>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="triggerType" eType="#//TaskTriggerType"
......@@ -78,6 +78,18 @@
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="A running instance of an ITaskDescriptor."/>
</eAnnotations>
<eOperations name="getResultEntryAsTypedList">
<eGenericType eClassifier="ecore:EClass ../../ch.elexis.core/model/types.ecore#//List">
<eTypeArguments eTypeParameter="#//ITask/getResultEntryAsTypedList/T"/>
</eGenericType>
<eTypeParameters name="T"/>
<eParameters name="key" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eParameters name="clazz">
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EJavaClass">
<eTypeArguments eTypeParameter="#//ITask/getResultEntryAsTypedList/T"/>
</eGenericType>
</eParameters>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="id" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
changeable="false" iD="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="state" lowerBound="1" eType="#//TaskState"
......@@ -220,8 +232,13 @@
<eLiterals name="IN_PROGRESS" value="20"/>
<eLiterals name="CANCELLED" value="30"/>
<eLiterals name="ON_HOLD" value="40"/>
<eLiterals name="FAILED" value="90"/>
<eLiterals name="COMPLETED" value="50"/>
<eLiterals name="COMPLETED_WARN" value="55" literal="COMPLETED_WARN">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="The task completed successfully, but not flawless. I.e. there were warnings somebody should consider."/>
</eAnnotations>
</eLiterals>
<eLiterals name="FAILED" value="90"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="OwnerTaskNotification">
<eLiterals name="NEVER"/>
......
......@@ -21,8 +21,9 @@
<genEnumLiterals ecoreEnumLiteral="model.ecore#//TaskState/IN_PROGRESS"/>
<genEnumLiterals ecoreEnumLiteral="model.ecore#//TaskState/CANCELLED"/>
<genEnumLiterals ecoreEnumLiteral="model.ecore#//TaskState/ON_HOLD"/>
<genEnumLiterals ecoreEnumLiteral="model.ecore#//TaskState/FAILED"/>
<genEnumLiterals ecoreEnumLiteral="model.ecore#//TaskState/COMPLETED"/>
<genEnumLiterals ecoreEnumLiteral="model.ecore#//TaskState/COMPLETED_WARN"/>
<genEnumLiterals ecoreEnumLiteral="model.ecore#//TaskState/FAILED"/>
</genEnums>
<genEnums typeSafeEnumCompatible="false" ecoreEnum="model.ecore#//OwnerTaskNotification">
<genEnumLiterals ecoreEnumLiteral="model.ecore#//OwnerTaskNotification/NEVER"/>
......@@ -68,6 +69,11 @@
<genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//ITask/runContext"/>
<genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//ITask/finished"/>
<genFeatures property="Readonly" createChild="false" ecoreFeature="ecore:EAttribute model.ecore#//ITask/descriptorId"/>
<genOperations ecoreOperation="model.ecore#//ITask/getResultEntryAsTypedList">
<genParameters ecoreParameter="model.ecore#//ITask/getResultEntryAsTypedList/key"/>
<genParameters ecoreParameter="model.ecore#//ITask/getResultEntryAsTypedList/clazz"/>
<genTypeParameters ecoreTypeParameter="model.ecore#//ITask/getResultEntryAsTypedList/T"/>
</genOperations>
</genClasses>
<genClasses image="false" ecoreClass="model.ecore#//ITaskService">
<genOperations ecoreOperation="model.ecore#//ITaskService/createTaskDescriptor">
......
......@@ -15,6 +15,7 @@ import ch.elexis.core.model.Identifiable;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
......@@ -129,10 +130,7 @@ public interface ITask extends Identifiable, Deleteable {
/**
* Returns the value of the '<em><b>Result</b></em>' attribute.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Result</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* Result is de-serialized out of a json string. Numeric entries are always returned as doubles.
* <!-- end-user-doc -->
* @return the value of the '<em>Result</em>' attribute.
* @see ch.elexis.core.tasks.model.ModelPackage#getITask_Result()
......@@ -201,4 +199,13 @@ public interface ITask extends Identifiable, Deleteable {
*/
String getDescriptorId();
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @model type="ch.elexis.core.types.List&lt;T&gt;" many="false"
* @generated
*/
<T> List<T> getResultEntryAsTypedList(String key, Class<T> clazz);
} // ITask
......@@ -15,6 +15,7 @@ import ch.elexis.core.model.IUser;
import ch.elexis.core.model.Identifiable;
import com.cronutils.model.Cron;
import java.io.Serializable;
import java.util.Map;
/**
......@@ -209,7 +210,7 @@ public interface ITaskDescriptor extends Identifiable, Deleteable {
* @model transient="true"
* @generated
*/
Map<String, String> getRunContext();
Map<String, Serializable> getRunContext();
/**
* Sets the value of the '{@link ch.elexis.core.tasks.model.ITaskDescriptor#getRunContext <em>Run Context</em>}' attribute.
......@@ -219,7 +220,7 @@ public interface ITaskDescriptor extends Identifiable, Deleteable {
* @see #getRunContext()
* @generated
*/
void setRunContext(Map<String, String> value);
void setRunContext(Map<String, Serializable> value);
/**
* Returns the value of the '<em><b>Trigger Type</b></em>' attribute.
......
......@@ -77,24 +77,33 @@ public enum TaskState implements Enumerator {
ON_HOLD(40, "ON_HOLD", "ON_HOLD"),
/**
* The '<em><b>FAILED</b></em>' literal object.
* The '<em><b>COMPLETED</b></em>' literal object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #FAILED_VALUE
* @see #COMPLETED_VALUE
* @generated
* @ordered
*/
FAILED(90, "FAILED", "FAILED"),
/**
* The '<em><b>COMPLETED</b></em>' literal object.
COMPLETED(50, "COMPLETED", "COMPLETED"), /**
* The '<em><b>COMPLETED WARN</b></em>' literal object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #COMPLETED_VALUE
* <!-- begin-model-doc -->
* The task completed successfully, but not flawless. I.e. there were warnings somebody should consider.
* <!-- end-model-doc -->
* @see #COMPLETED_WARN_VALUE
* @generated
* @ordered
*/
COMPLETED_WARN(55, "COMPLETED_WARN", "COMPLETED_WARN"), /**
* The '<em><b>FAILED</b></em>' literal object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #FAILED_VALUE
* @generated
* @ordered
*/
COMPLETED(50, "COMPLETED", "COMPLETED");
FAILED(90, "FAILED", "FAILED");
/**
* The '<em><b>DRAFT</b></em>' literal value.
......@@ -172,34 +181,48 @@ public enum TaskState implements Enumerator {
public static final int ON_HOLD_VALUE = 40;
/**
* The '<em><b>FAILED</b></em>' literal value.
* The '<em><b>COMPLETED</b></em>' literal value.
* <!-- begin-user-doc -->
* <p>
* If the meaning of '<em><b>FAILED</b></em>' literal object isn't clear,
* If the meaning of '<em><b>COMPLETED</b></em>' literal object isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @see #FAILED
* @see #COMPLETED
* @model
* @generated
* @ordered
*/
public static final int FAILED_VALUE = 90;
public static final int COMPLETED_VALUE = 50;
/**
* The '<em><b>COMPLETED</b></em>' literal value.
* The '<em><b>COMPLETED WARN</b></em>' literal value.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* <!-- begin-model-doc -->
* The task completed successfully, but not flawless. I.e. there were warnings somebody should consider.
* <!-- end-model-doc -->
* @see #COMPLETED_WARN
* @model
* @generated
* @ordered
*/
public static final int COMPLETED_WARN_VALUE = 55;
/**
* The '<em><b>FAILED</b></em>' literal value.
* <!-- begin-user-doc -->
* <p>
* If the meaning of '<em><b>COMPLETED</b></em>' literal object isn't clear,
* If the meaning of '<em><b>FAILED</b></em>' literal object isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @see #COMPLETED
* @see #FAILED
* @model
* @generated
* @ordered
*/
public static final int COMPLETED_VALUE = 50;
public static final int FAILED_VALUE = 90;
/**
* An array of all the '<em><b>Task State</b></em>' enumerators.
......@@ -214,8 +237,9 @@ public enum TaskState implements Enumerator {
IN_PROGRESS,
CANCELLED,
ON_HOLD,
FAILED,
COMPLETED,
COMPLETED_WARN,
FAILED,
};
/**
......@@ -277,8 +301,9 @@ public enum TaskState implements Enumerator {
case IN_PROGRESS_VALUE: return IN_PROGRESS;
case CANCELLED_VALUE: return CANCELLED;
case ON_HOLD_VALUE: return ON_HOLD;
case FAILED_VALUE: return FAILED;
case COMPLETED_VALUE: return COMPLETED;
case COMPLETED_WARN_VALUE: return COMPLETED_WARN;
case FAILED_VALUE: return FAILED;
}
return null;
}
......
......@@ -38,6 +38,7 @@ import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.ETypeParameter;
import org.eclipse.emf.ecore.impl.EPackageImpl;
import org.slf4j.Logger;
......@@ -646,7 +647,7 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
EGenericType g1 = createEGenericType(ecorePackage.getEMap());
EGenericType g2 = createEGenericType(ecorePackage.getEString());
g1.getETypeArguments().add(g2);
g2 = createEGenericType(ecorePackage.getEString());
g2 = createEGenericType(this.getSerializable());
g1.getETypeArguments().add(g2);
initEAttribute(getITaskDescriptor_RunContext(), g1, "runContext", null, 0, 1, ITaskDescriptor.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getITaskDescriptor_TriggerType(), this.getTaskTriggerType(), "triggerType", "MANUAL", 0, 1, ITaskDescriptor.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
......@@ -691,6 +692,18 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
initEAttribute(getITask_Finished(), ecorePackage.getEBoolean(), "finished", "false", 1, 1, ITask.class, !IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getITask_DescriptorId(), ecorePackage.getEString(), "descriptorId", null, 1, 1, ITask.class, !IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
op = addEOperation(iTaskEClass, null, "getResultEntryAsTypedList", 0, 1, IS_UNIQUE, IS_ORDERED);
ETypeParameter t1 = addETypeParameter(op, "T");
addEParameter(op, ecorePackage.getEString(), "key", 0, 1, IS_UNIQUE, IS_ORDERED);
g1 = createEGenericType(ecorePackage.getEJavaClass());
g2 = createEGenericType(t1);
g1.getETypeArguments().add(g2);
addEParameter(op, g1, "clazz", 0, 1, IS_UNIQUE, IS_ORDERED);
g1 = createEGenericType(theTypesPackage.getList());
g2 = createEGenericType(t1);
g1.getETypeArguments().add(g2);
initEOperation(op, g1);
initEClass(iTaskServiceEClass, ITaskService.class, "ITaskService", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
op = addEOperation(iTaskServiceEClass, this.getITaskDescriptor(), "createTaskDescriptor", 0, 1, IS_UNIQUE, IS_ORDERED);
......@@ -772,8 +785,9 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
addEEnumLiteral(taskStateEEnum, TaskState.IN_PROGRESS);
addEEnumLiteral(taskStateEEnum, TaskState.CANCELLED);
addEEnumLiteral(taskStateEEnum, TaskState.ON_HOLD);
addEEnumLiteral(taskStateEEnum, TaskState.FAILED);
addEEnumLiteral(taskStateEEnum, TaskState.COMPLETED);
addEEnumLiteral(taskStateEEnum, TaskState.COMPLETED_WARN);
addEEnumLiteral(taskStateEEnum, TaskState.FAILED);
initEEnum(ownerTaskNotificationEEnum, OwnerTaskNotification.class, "OwnerTaskNotification");
addEEnumLiteral(ownerTaskNotificationEEnum, OwnerTaskNotification.NEVER);
......
......@@ -47,7 +47,7 @@ public class DeleteFileIdentifiedRunnable implements IIdentifiedRunnable {
}
@Override
public Map<String, String> getDefaultRunContext(){
public Map<String, Serializable> getDefaultRunContext(){
return Collections.singletonMap(RunContextParameter.STRING_URL,
RunContextParameter.VALUE_MISSING_REQUIRED);
}
......
......@@ -32,7 +32,7 @@ public class LogResultContextIdentifiedRunnable implements IIdentifiedRunnable {
}
@Override
public Map<String, String> getDefaultRunContext(){
public Map<String, Serializable> getDefaultRunContext(){
return Collections.emptyMap();
}
......
......@@ -53,8 +53,8 @@ public class TriggerTaskForEveryFileInDirectoryRunnable implements IIdentifiedRu
}
@Override
public Map<String, String> getDefaultRunContext(){
Map<String, String> runContext = new HashMap<>();
public Map<String, Serializable> getDefaultRunContext(){
Map<String, Serializable> runContext = new HashMap<>();
runContext.put(RunContextParameter.STRING_URL, RunContextParameter.VALUE_MISSING_REQUIRED);
runContext.put(RunContextParameter.TASK_DESCRIPTOR_REFID,
RunContextParameter.VALUE_MISSING_REQUIRED);
......
package ch.elexis.core.tasks.internal.service;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
......@@ -13,6 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import ch.elexis.core.jpa.model.adapter.AbstractIdDeleteModelAdapter;
import ch.elexis.core.model.IXid;
......@@ -143,9 +147,21 @@ public class Task extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.entiti
return new HashMap<>();
}
@Override
public <T> List<T> getResultEntryAsTypedList(String key, Class<T> clazz){
List<?> list = (List<?>) getResult().get(key);
if (list != null && !list.isEmpty()) {
String json = gson.toJson(list);
Type type = TypeToken.getParameterized(ArrayList.class, clazz).getType();
return gson.fromJson(json, type);
}
return Collections.emptyList();
}
@Override
public boolean isFinished(){
return (TaskState.COMPLETED == getState() || TaskState.FAILED == getState());
return (TaskState.COMPLETED == getState() || TaskState.COMPLETED_WARN == getState()
|| TaskState.FAILED == getState());
}
private void removeTaskRecord(){
......@@ -182,6 +198,7 @@ public class Task extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.entiti
setState(TaskState.IN_PROGRESS);
long beginTimeMillis = System.currentTimeMillis();
// TODO what if it runs forever?
Map<String, Serializable> result =
runnableWithContext.run(effectiveRunContext, progressMonitor, logger);
long endTimeMillis = System.currentTimeMillis();
......@@ -191,8 +208,12 @@ public class Task extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.entiti
result.put("runnableExecDuration",
Long.toString(endTimeMillis - beginTimeMillis));
}
setResult(result);
setState(TaskState.COMPLETED);
TaskState exitState =
(result.containsKey(ReturnParameter.MARKER_WARN)) ? TaskState.COMPLETED_WARN
: TaskState.COMPLETED;
setState(exitState);
if (effectiveRunContext.containsKey(ReturnParameter.MARKER_DO_NOT_PERSIST)
|| getResult().containsKey(ReturnParameter.MARKER_DO_NOT_PERSIST)) {
......
......@@ -87,7 +87,7 @@ public class TaskDescriptor
@SuppressWarnings("unchecked")
@Override
public Map<String, String> getRunContext(){
public Map<String, Serializable> getRunContext(){
String json = getEntity().getRunContext();
if (json != null) {
return gson.fromJson(json, Map.class);
......@@ -96,14 +96,14 @@ public class TaskDescriptor
}
@Override
public void setRunContext(Map<String, String> value){
public void setRunContext(Map<String, Serializable> value){
String json = gson.toJson(value);
getEntity().setRunContext(json);
}
@Override
public void setRunContextParameter(String key, String value){
Map<String, String> runContext = getRunContext();
Map<String, Serializable> runContext = getRunContext();
runContext.put(key, value);
setRunContext(runContext);
}
......
......@@ -299,6 +299,7 @@ public class TaskServiceImpl implements ITaskService {
(String) task.getResult().get(ReturnParameter.FAILED_TASK_EXCEPTION_MESSAGE);
message.addMessageCode(MessageCode.Key.Severity, MessageCode.Value.Severity_WARN);
} else {
// TODO handle result type
resultText = (String) task.getResult().get(ReturnParameter.RESULT_DATA);
message.addMessageCode(MessageCode.Key.Severity, MessageCode.Value.Severity_INFO);
}
......@@ -325,6 +326,8 @@ public class TaskServiceImpl implements ITaskService {
ITask task = new Task(taskDescriptor, triggerType, progressMonitor, runContext);
// TODO test if all runContext parameters are satisfied, else reject execution
try {
if (taskDescriptor.isSingleton()) {
// TODO per runnable singletonExecutorService
......@@ -431,8 +434,8 @@ public class TaskServiceImpl implements ITaskService {
return;
}
Set<Entry<String, String>> entrySet = runnable.getDefaultRunContext().entrySet();
for (Entry<String, String> entry : entrySet) {
Set<Entry<String, Serializable>> entrySet = runnable.getDefaultRunContext().entrySet();
for (Entry<String, Serializable> entry : entrySet) {
if (IIdentifiedRunnable.RunContextParameter.VALUE_MISSING_REQUIRED
.equals(entry.getValue())) {
Serializable value = taskDescriptor.getRunContext().get(entry.getKey());
......
......@@ -38,7 +38,8 @@ public interface IIdentifiedRunnable {
/**
* Run-Context parameter value: Denotes that a value for the given key is missing (no
* default applicable)and required for execution
* default applicable)and required for execution. If for any entry of the runContext this
* value is set, execution by the TaskService will be rejected.
*/
public static final String VALUE_MISSING_REQUIRED = "missingRequired";
}
......@@ -50,16 +51,24 @@ public interface IIdentifiedRunnable {
private ReturnParameter(){}
/**
* The class that is being delivered within {@link #RESULT_DATA}, if <code>null</code>
* assume {@link String}
* The full class name that is being delivered within {@link #RESULT_DATA} or
* {@link #RESULT_DATA_LIST}, if <code>null</code> assume {@link String}
*/
public static final String RESULT_CLASS = "resultClass";
/**
* The actual result data, can be casted to {@link #RESULT_CLASS}
* The actual result data for a single object. Object can be casted to
* {@link #RESULT_CLASS}. If multiple result objects are required, use
* {@link #RESULT_DATA_LIST}
*/
public static final String RESULT_DATA = "resultData";
/**
* The actual result data for multiple objects. Each object can be casted to
* {@link #RESULT_CLASS}. If a single result object is required use {@link #RESULT_DATA}
*/
public static final String RESULT_DATA_LIST = "resultDataList";
/**
* The existence of this key does advise the task system to not persist the tasks results.
* Use this e.g. to not "log" an empty run. (e.g. a directory watcher that found nothing).
......@@ -68,6 +77,13 @@ public interface IIdentifiedRunnable {
*/
public static final String MARKER_DO_NOT_PERSIST = "markerDoNotPersist";
/**
* The existence of this key does advise the task system that there was a warning during
* execution. That is, the task completed successfully, but not "flawlessly". The task
* object will be marked accordingly.
*/
public static final String MARKER_WARN = "markerWarn";
/**
* If the task throws an exception (task fails), the message of the exception is returned
* using this key.
......@@ -97,7 +113,7 @@ public interface IIdentifiedRunnable {
*
* @return
*/
Map<String, String> getDefaultRunContext();
Map<String, Serializable> getDefaultRunContext();
/**
* Execute the task. If no exception is thrown during execution, it is assumed that the task
......
package ch.elexis.core.model.tasks;
/**
* Carry the information of a result on a single identifiable with a running task.
*/
public class SingleIdentifiableTaskResult {
private final String code;
private final String storeToString;
private final String message;
private String data;
public SingleIdentifiableTaskResult(String identifiableStoreToString, String resultCode){
this(identifiableStoreToString, resultCode, null);
}
public SingleIdentifiableTaskResult(String identifiableStoreToString, String resultCode,
String message){
this.storeToString = identifiableStoreToString;
this.code = resultCode;
this.message = message;
}
public String getResultCode(){
return code;
}
public String getIdentifiableStoreToString(){
return storeToString;
}
public String getResultMessage(){
return message;
}
public String getData(){
return data;
}
public void setData(String data){
this.data = data;
}
}
......@@ -5,6 +5,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
......@@ -208,7 +209,7 @@ public class Hl7ImporterTaskIntegrationTest {
IIdentifiedRunnable watcherRunnable = TaskServiceHolder.get()
.instantiateRunnableById(IdentifiedRunnableIdConstants.TRIGGER_TASK_FOR_EVERY_FILE);
assertNotNull(watcherRunnable);
Map<String, String> watcherRunContext = watcherRunnable.getDefaultRunContext();
Map<String, Serializable> watcherRunContext = watcherRunnable.getDefaultRunContext();
watcherRunContext.put(RunContextParameter.STRING_URL, url);
watcherRunContext.put(RunContextParameter.TASK_DESCRIPTOR_REFID, "hl7Importer_a");
watcherRunContext.put("fileExtensionFilter", "hl7");
......
......@@ -47,7 +47,7 @@ public class TaskServiceTest {
IUser owner;
ITaskDescriptor taskDescriptor;
IProgressMonitor progressMonitor;
Map<String, String> runContext = new HashMap<>();
Map<String, Serializable> runContext = new HashMap<>();
static Path tempDirectory;
......@@ -111,7 +111,7 @@ public class TaskServiceTest {
taskDescriptor = taskService.createTaskDescriptor(rwcMisthios);
taskDescriptor.setOwner(owner);
taskDescriptor.setReferenceId("manual_helloWorld_misthios");
Map<String, String> context = new HashMap<>();
Map<String, Serializable> context = new HashMap<>();
context.put("bundle_url",
"https://gitlab.medelexis.ch/mdescher/elexis-misthios/raw/master/sample-misthios-bundle/");
taskDescriptor.setRunContext(context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment