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

[11238] ITask#getResultEntryTyped and ITask#isSucceeded

parent 1b0a5826
Pipeline #12179 passed with stages
in 4 minutes and 50 seconds
......@@ -90,6 +90,21 @@
</eGenericType>
</eParameters>
</eOperations>
<eOperations name="getResultEntryTyped">
<eGenericType eTypeParameter="#//ITask/getResultEntryTyped/T"/>
<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/getResultEntryTyped/T"/>
</eGenericType>
</eParameters>
</eOperations>
<eOperations name="isSucceeded" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="The task isFinished and finished with either TaskState.COMPLETED or TaskState.COMPLETED_WARN"/>
</eAnnotations>
</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"
......
......@@ -74,6 +74,12 @@
<genParameters ecoreParameter="model.ecore#//ITask/getResultEntryAsTypedList/clazz"/>
<genTypeParameters ecoreTypeParameter="model.ecore#//ITask/getResultEntryAsTypedList/T"/>
</genOperations>
<genOperations ecoreOperation="model.ecore#//ITask/getResultEntryTyped">
<genParameters ecoreParameter="model.ecore#//ITask/getResultEntryTyped/key"/>
<genParameters ecoreParameter="model.ecore#//ITask/getResultEntryTyped/clazz"/>
<genTypeParameters ecoreTypeParameter="model.ecore#//ITask/getResultEntryTyped/T"/>
</genOperations>
<genOperations ecoreOperation="model.ecore#//ITask/isSucceeded"/>
</genClasses>
<genClasses image="false" ecoreClass="model.ecore#//ITaskService">
<genOperations ecoreOperation="model.ecore#//ITaskService/createTaskDescriptor">
......
......@@ -203,5 +203,24 @@ public interface ITask extends Identifiable, Deleteable {
*/
<T> List<T> getResultEntryAsTypedList(String key, Class<T> clazz);
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @model
* @generated
*/
<T> T getResultEntryTyped(String key, Class<T> clazz);
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* <!-- begin-model-doc -->
* The task isFinished and finished with either TaskState.COMPLETED or TaskState.COMPLETED_WARN
* <!-- end-model-doc -->
* @model kind="operation"
* @generated
*/
boolean isSucceeded();
} // ITask
......@@ -704,6 +704,18 @@ public class ModelPackageImpl extends EPackageImpl implements ModelPackage {
g1.getETypeArguments().add(g2);
initEOperation(op, g1);
op = addEOperation(iTaskEClass, null, "getResultEntryTyped", 0, 1, IS_UNIQUE, IS_ORDERED);
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(t1);
initEOperation(op, g1);
addEOperation(iTaskEClass, ecorePackage.getEBoolean(), "isSucceeded", 0, 1, IS_UNIQUE, IS_ORDERED);
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);
......
......@@ -12,6 +12,7 @@ import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -165,6 +166,22 @@ public class Task extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.entiti
return Collections.emptyList();
}
@Override
public <T> T getResultEntryTyped(String key, Class<T> clazz){
String json = getEntity().getResult();
if (json != null) {
JSONObject map = new JSONObject(json);
String valueToString = JSONObject.valueToString(map.get(key));
return gson.fromJson(valueToString, clazz);
}
return null;
}
@Override
public boolean isSucceeded(){
return (TaskState.COMPLETED == getState() || TaskState.COMPLETED_WARN == getState());
}
@Override
public boolean isFinished(){
return (TaskState.COMPLETED == getState() || TaskState.COMPLETED_WARN == getState()
......@@ -186,7 +203,7 @@ public class Task extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.entiti
ITaskDescriptor originTaskDescriptor = getTaskDescriptor();
String runnableWithContextId = originTaskDescriptor.getIdentifiedRunnableId();
try {
IIdentifiedRunnable runnableWithContext =
TaskServiceHolder.get().instantiateRunnableById(runnableWithContextId);
......@@ -233,7 +250,7 @@ public class Task extends AbstractIdDeleteModelAdapter<ch.elexis.core.jpa.entiti
if (progressMonitor != null) {
progressMonitor.done();
}
}
@Override
......
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