Skip to content

Commit

Permalink
Fixed workflow-impl tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 22, 2016
1 parent 83533be commit 01d0378
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 33 deletions.
Expand Up @@ -218,6 +218,7 @@ public S_ItemEntry replace(Collection<PrismValue> values) {

@Override
public S_ItemEntry replace(PrismValue... values) {
checkNullMisuse(values);
currentDelta.setValuesToReplace(values);
return this;
}
Expand Down
Expand Up @@ -126,7 +126,7 @@ public TaskRunResult run(Task task) {
}
clockwork.run(context, task, result);

task.setExtensionContainer(context.toPrismContainer());
task.setModelOperationContext(context.toLensContextType());
task.savePendingModifications(result);

if (result.isUnknown()) {
Expand Down
Expand Up @@ -637,7 +637,7 @@ public ModelContext unwrapModelContext(LensContextType lensContextType) throws S
}

public LensContextType wrapModelContext(LensContext<?> lensContext) throws SchemaException {
return lensContext.toPrismContainer().getValue().asContainerable();
return lensContext.toLensContextType();
}

// Convenience functions
Expand Down
Expand Up @@ -846,6 +846,11 @@ public String debugDump(int indent, boolean showTriples) {
return sb.toString();
}

public LensContextType toLensContextType() throws SchemaException {
PrismContainer<LensContextType> pc = toPrismContainer();
return pc.getValue().asContainerable();
}

public PrismContainer<LensContextType> toPrismContainer() throws SchemaException {

PrismContainer<LensContextType> lensContextTypeContainer = PrismContainer.newInstance(getPrismContext(), LensContextType.COMPLEX_TYPE);
Expand Down
@@ -1,8 +1,6 @@
package com.evolveum.midpoint.wf.impl.jobs;

import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskExecutionStatus;
Expand All @@ -13,6 +11,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.wf.impl.processors.ChangeProcessor;
import com.evolveum.midpoint.wf.impl.processors.primary.ObjectTreeDeltas;
import org.apache.commons.lang3.Validate;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -40,6 +39,8 @@ public class Job {
}

Job(JobController jobController, Task task, String activitiId, ChangeProcessor changeProcessor) {
Validate.notNull(task, "Task");
Validate.notNull(changeProcessor, "Change processor");
this.jobController = jobController;
this.task = task;
this.activitiId = activitiId;
Expand Down Expand Up @@ -147,8 +148,8 @@ public ObjectTreeDeltas retrieveResultingDeltas() throws SchemaException {
return getWfTaskUtil().retrieveResultingDeltas(task);
}

public void setSkipModelContextProcessingProperty(OperationResult result) throws SchemaException, ObjectNotFoundException {
getWfTaskUtil().setSkipModelContextProcessingProperty(task, result);
public void deleteModelOperationContext(OperationResult result) throws SchemaException, ObjectNotFoundException {
getWfTaskUtil().deleteModelOperationContext(task, result);
}

public void storeModelContext(ModelContext modelContext) throws SchemaException {
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.audit.api.AuditService;
import com.evolveum.midpoint.model.impl.controller.ModelOperationTaskHandler;
import com.evolveum.midpoint.model.impl.lens.LensContext;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.repo.api.RepositoryService;
Expand Down Expand Up @@ -225,7 +226,10 @@ private Task createTask(JobCreationInstruction instruction, Task parentTask, Ope
wfTaskUtil.pushProcessShadowHandler(instruction.isSimple(), task, TASK_START_DELAY, result);
}

// put task variables
// put model context + task variables
if (instruction.getTaskModelContext() != null) {
task.setModelOperationContext(((LensContext) instruction.getTaskModelContext()).toLensContextType());
}
for (Item item : instruction.getTaskVariables().values()) {
task.setExtensionItem(item);
}
Expand Down
Expand Up @@ -63,6 +63,7 @@ public class JobCreationInstruction implements DebugDumpable {

private Map<String,Serializable> processVariables = new HashMap<>(); // values of process variables
private Map<QName,Item> taskVariables = new HashMap<>(); // items to be put into task extension
private ModelContext taskModelContext; // model context to be put into the task
private PrismObject taskObject; // object to be attached to the task; this object must have its definition available
private PrismObject<UserType> taskOwner; // if null, owner from parent task will be taken (if there's no parent task, exception will be thrown)
private PolyStringType taskName; // name of task to be created/updated (applies only if the task has no name already) - e.g. "Approve adding role R to U"
Expand Down Expand Up @@ -256,6 +257,14 @@ public PrismObject<UserType> getTaskOwner() {
public void setTaskOwner(PrismObject<UserType> taskOwner) {
this.taskOwner = taskOwner;
}

public ModelContext getTaskModelContext() {
return taskModelContext;
}

public void setTaskModelContext(ModelContext taskModelContext) {
this.taskModelContext = taskModelContext;
}
//endregion

//region Setters for handlers
Expand Down Expand Up @@ -331,8 +340,7 @@ public <T> void addTaskVariableValues(PrismPropertyDefinition<T> definition, Col

public void addTaskModelContext(ModelContext modelContext) throws SchemaException {
Validate.notNull(modelContext, "model context cannot be null");
PrismContainer<LensContextType> modelContextPrism = ((LensContext) modelContext).toPrismContainer();
taskVariables.put(modelContextPrism.getElementName(), modelContextPrism);
setTaskModelContext(modelContext);
}
//endregion

Expand Down
Expand Up @@ -299,16 +299,12 @@ public ModelContext retrieveModelContext(Task task, OperationResult result) thro

public void storeModelContext(Task task, ModelContext context) throws SchemaException {
//Validate.notNull(context, "model context cannot be null");
PrismContainer<LensContextType> modelContext = context != null ? ((LensContext) context).toPrismContainer() : null;
LensContextType modelContext = context != null ? ((LensContext) context).toLensContextType() : null;
storeModelContext(task, modelContext);
}

public void storeModelContext(Task task, PrismContainer<LensContextType> context) throws SchemaException {
LensContextType lct = null;
if (context != null && !context.isEmpty()) {
lct = context.getValue().asContainerable();
}
task.setModelOperationContext(lct);
public void storeModelContext(Task task, LensContextType context) throws SchemaException {
task.setModelOperationContext(context);
}

public void storeResultingDeltas(ObjectTreeDeltas deltas, Task task) throws SchemaException {
Expand Down Expand Up @@ -386,7 +382,7 @@ public String getRootTaskOid(Task task) {
return getExtensionValue(String.class, task, WfTaskExtensionItemsNames.WFROOT_TASK_OID_PROPERTY_NAME);
}

public void setSkipModelContextProcessingProperty(Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
public void deleteModelOperationContext(Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
task.setModelOperationContext(null);
}

Expand Down
Expand Up @@ -201,7 +201,7 @@ public void onProcessEnd(ProcessEvent event, Job job, OperationResult result) th
wfTaskUtil.storeModelContext(rootTask, (ModelContext) null);
} else {
LOGGER.debug("Putting (changed or unchanged) value of {} into the task {}", GcpProcessVariableNames.VARIABLE_MODEL_CONTEXT, rootTask);
wfTaskUtil.storeModelContext(rootTask, lensContextType.asPrismContainerValue().getContainer());
wfTaskUtil.storeModelContext(rootTask, lensContextType);
}

rootTask.savePendingModifications(result);
Expand Down
Expand Up @@ -116,7 +116,7 @@ public JobCreationInstruction prepareJobCreationInstruction(GeneralChangeProcess
instruction.setRequesterOidInProcess(taskFromModel.getOwner());
instruction.setTaskName("Workflow-monitoring task");
instruction.setProcessInterfaceBean(defaultProcessMidPointInterface);
LensContextType lensContextType = context.toPrismContainer().getValue().asContainerable();
LensContextType lensContextType = context.toLensContextType();
instruction.addProcessVariable(GcpProcessVariableNames.VARIABLE_MODEL_CONTEXT, new JaxbValueContainer<>(lensContextType, prismContext));
return instruction;
}
Expand Down
Expand Up @@ -115,7 +115,7 @@ public TaskRunResult run(Task task) {
LOGGER.trace("We'll delete model operation context.");
}

job.setSkipModelContextProcessingProperty(result);
job.deleteModelOperationContext(result);

} else {

Expand Down
Expand Up @@ -19,7 +19,6 @@
import com.evolveum.midpoint.model.api.context.ModelProjectionContext;
import com.evolveum.midpoint.model.impl.lens.LensContext;
import com.evolveum.midpoint.model.impl.lens.LensFocusContext;
import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -29,10 +28,8 @@
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.wf.impl.WfConfiguration;
import com.evolveum.midpoint.wf.impl.jobs.Job;
import com.evolveum.midpoint.wf.impl.jobs.JobController;
import com.evolveum.midpoint.wf.impl.jobs.WfTaskUtil;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -140,7 +137,7 @@ public TaskRunResult run(Task task) {


if (!rootContext.hasAnyPrimaryChange()) {
rootJob.setSkipModelContextProcessingProperty(result);
rootContext = null; // deletes the model context
changed = true; // regardless of whether rootContext was changed or not
}

Expand Down
Expand Up @@ -107,7 +107,7 @@ public void test100SerializeContext() throws Exception {
LensFocusContext<UserType> focusContext = context.getOrCreateFocusContext();
focusContext.setPrimaryDelta(userDelta);

LensContextType contextType = context.toPrismContainer().getValue().asContainerable();
LensContextType contextType = context.toLensContextType();
JaxbValueContainer<LensContextType> container = new JaxbValueContainer<LensContextType>(contextType, prismContext);
container.clearActualValue();
System.out.println("XML value = " + container.getXmlValue());
Expand Down
6 changes: 2 additions & 4 deletions model/workflow-impl/testng-integration.xml
Expand Up @@ -18,12 +18,10 @@
<suite name="unit" parallel="false">
<test name="Default" preserve-order="true" parallel="false" verbose="10" enabled="true">
<classes>
<!-- temporarily disabled -->
<!--<class name="com.evolveum.midpoint.wf.impl.TestUserChangeApproval"/>
<class name="com.evolveum.midpoint.wf.impl.TestUserChangeApproval"/>
<class name="com.evolveum.midpoint.wf.impl.TestCreateModifyUser"/>
<class name="com.evolveum.midpoint.wf.impl.TestCreateOrg"/>
<class name="com.evolveum.midpoint.wf.impl.TestAddAssociation"/>-->

<class name="com.evolveum.midpoint.wf.impl.TestAddAssociation"/>

<!--<class name="com.evolveum.midpoint.wf.impl.general.TestGeneralChangeProcessor"/>-->
</classes>
Expand Down
Expand Up @@ -35,6 +35,7 @@
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.EqualFilter;
Expand Down Expand Up @@ -87,6 +88,8 @@
import java.util.Set;
import java.util.concurrent.Future;

import static com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_MODEL_OPERATION_CONTEXT;

/**
* Implementation of a Task.
*
Expand Down Expand Up @@ -1960,14 +1963,23 @@ public void setModelOperationContextTransient(LensContextType value) {
taskPrism.asObjectable().setModelOperationContext(value);
}

private ContainerDelta<?> setModelOperationContextAndPrepareDelta(LensContextType value)
private ItemDelta<?, ?> setModelOperationContextAndPrepareDelta(LensContextType value)
throws SchemaException {
setModelOperationContextTransient(value);
return isPersistent() ? ContainerDelta.createModificationReplace(TaskType.F_MODEL_OPERATION_CONTEXT,
taskManager.getTaskObjectDefinition(), value.asPrismContainerValue()) : null;
if (!isPersistent()) {
return null;
}
if (value != null) {
return DeltaBuilder.deltaFor(TaskType.class, getPrismContext())
.item(F_MODEL_OPERATION_CONTEXT).replace(value.asPrismContainerValue().clone())
.asItemDelta();
} else {
return DeltaBuilder.deltaFor(TaskType.class, getPrismContext())
.item(F_MODEL_OPERATION_CONTEXT).replace()
.asItemDelta();
}
}


// @Override
// public PrismReference getRequesteeRef() {
// return (PrismReference) getExtensionItem(SchemaConstants.C_TASK_REQUESTEE_REF);
Expand Down

0 comments on commit 01d0378

Please sign in to comment.