Skip to content

Commit

Permalink
Submitting approval with comment now works.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 7, 2016
1 parent 5cefe3b commit ea650fc
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 131 deletions.
Expand Up @@ -305,8 +305,8 @@ private void savePerformed(AjaxRequestTarget target, boolean decision) {
OperationResult result = new OperationResult(OPERATION_SAVE_WORK_ITEM);

try {
// reviveModels();
// getWorkflowService().approveOrRejectWorkItemWithDetails(workItemDtoModel.getObject().getWorkItem().getWorkItemId(), object, decision, result);
WorkItemNewDto dto = workItemDtoModel.getObject();
getWorkflowService().approveOrRejectWorkItem(dto.getWorkItemId(), decision, dto.getApproverComment(), result);
setReinitializePreviousPages(true);
} catch (Exception ex) {
result.recordFatalError("Couldn't save work item.", ex);
Expand Down
Expand Up @@ -159,7 +159,7 @@ private void approveOrRejectWorkItemsPerformed(AjaxRequestTarget target, boolean
for (WorkItemNewDto workItemNewDto : WorkItemNewDtoList) {
OperationResult result = mainResult.createSubresult(OPERATION_APPROVE_OR_REJECT_ITEM);
try {
workflowService.approveOrRejectWorkItem(workItemNewDto.getWorkItemId(), approve, result);
workflowService.approveOrRejectWorkItem(workItemNewDto.getWorkItemId(), approve, null, result);
result.computeStatus();
} catch (Exception e) {
result.recordPartialError("Couldn't approve/reject work item due to an unexpected exception.", e);
Expand Down
Expand Up @@ -20,16 +20,11 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.mutable.MutableBoolean;

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.match.PolyStringNormMatchingRule;
import com.evolveum.midpoint.prism.match.PolyStringOrigMatchingRule;
import com.evolveum.midpoint.prism.path.ItemPath;
Expand Down Expand Up @@ -391,60 +386,49 @@ public static ObjectFilter simplify(ObjectFilter filter) {
}
}

public static <T> T getValueFromQuery(ObjectQuery query, QName propertyName) throws SchemaException {
public static PrismValue getValueFromQuery(ObjectQuery query, QName itemName) throws SchemaException {
if (query != null) {
return getValueFromFilter(query.getFilter(), propertyName);
return getValueFromFilter(query.getFilter(), itemName);
} else {
return null;
}
}

public static <T> Collection<T> getValuesFromQuery(ObjectQuery query, QName propertyName) throws SchemaException {
public static <T extends PrismValue> Collection<T> getValuesFromQuery(ObjectQuery query, QName itemName) throws SchemaException {
if (query != null) {
return getValuesFromFilter(query.getFilter(), propertyName);
return getValuesFromFilter(query.getFilter(), itemName);
} else {
return null;
}
}

public static <T> T getValueFromFilter(ObjectFilter filter, QName propertyName) throws SchemaException {
Collection<PrismPropertyValue<T>> values = getValuesFromFilter(filter, propertyName);
if (values == null) {
private static PrismValue getValueFromFilter(ObjectFilter filter, QName itemName) throws SchemaException {
Collection<PrismValue> values = getValuesFromFilter(filter, itemName);
if (values == null || values.size() == 0) {
return null;
} else if (values.size() > 1) {
throw new SchemaException("More than one " + propertyName + " defined in the search query.");
} else if (values.size() < 1) {
throw new SchemaException("Search query does not have specified " + propertyName + ".");
throw new SchemaException("More than one " + itemName + " defined in the search query.");
} else {
return values.iterator().next().getValue();
return values.iterator().next();
}
}

public static <T> Collection<T> getValuesFromFilter(ObjectFilter filter, QName propertyName) throws SchemaException {
ItemPath propertyPath = new ItemPath(propertyName);
private static <T extends PrismValue> Collection<T> getValuesFromFilter(ObjectFilter filter, QName itemName) throws SchemaException {
ItemPath propertyPath = new ItemPath(itemName);
if (filter instanceof EqualFilter && propertyPath.equivalent(((EqualFilter) filter).getFullPath())) {
return ((EqualFilter) filter).getValues();
} else if (filter instanceof RefFilter && propertyPath.equivalent(((RefFilter) filter).getFullPath())) {
return (Collection<T>) ((RefFilter) filter).getValues();
} else if (filter instanceof AndFilter) {
return getValuesFromFilter(((NaryLogicalFilter) filter).getConditions(), propertyName);
return getValuesFromFilter(((NaryLogicalFilter) filter).getConditions(), itemName);
} else if (filter instanceof TypeFilter) {
return getValuesFromFilter(((TypeFilter) filter).getFilter(), propertyName);
return getValuesFromFilter(((TypeFilter) filter).getFilter(), itemName);
} else {
return null;
}
}

public static <T> T getValueFromFilter(List<? extends ObjectFilter> conditions, QName propertyName)
throws SchemaException {
for (ObjectFilter f : conditions) {
T value = getValueFromFilter(f, propertyName);
if (value != null) {
return value;
}
}
return null;
}

public static <T> Collection<T> getValuesFromFilter(List<? extends ObjectFilter> conditions, QName propertyName)
private static <T extends PrismValue> Collection<T> getValuesFromFilter(List<? extends ObjectFilter> conditions, QName propertyName)
throws SchemaException {
for (ObjectFilter f : conditions) {
Collection<T> values = getValuesFromFilter(f, propertyName);
Expand All @@ -455,24 +439,21 @@ public static <T> Collection<T> getValuesFromFilter(List<? extends ObjectFilter>
return null;
}

public static String getResourceOidFromFilter(List<? extends ObjectFilter> conditions) throws SchemaException {
PrismReferenceValue referenceValue = getValueFromFilter(conditions, ShadowType.F_RESOURCE_REF);
private static String getResourceOidFromFilter(ObjectFilter filter) throws SchemaException {
PrismReferenceValue referenceValue = (PrismReferenceValue) getValueFromFilter(filter, ShadowType.F_RESOURCE_REF);
return referenceValue != null ? referenceValue.getOid() : null;
}

private static <T> T getPropertyRealValueFromFilter(ObjectFilter filter, QName propertyName) throws SchemaException {
PrismPropertyValue<T> propertyValue = (PrismPropertyValue<T>) getValueFromFilter(filter, propertyName);
return propertyValue != null ? propertyValue.getValue() : null;
}

public static ResourceShadowDiscriminator getCoordinates(ObjectFilter filter) throws SchemaException {
String resourceOid = null;
QName objectClass = null;
ShadowKindType kind = null;
String intent = null;

if (filter instanceof AndFilter) {
List<? extends ObjectFilter> conditions = ((AndFilter) filter).getConditions();
resourceOid = getResourceOidFromFilter(conditions);
objectClass = getValueFromFilter(conditions, ShadowType.F_OBJECT_CLASS);
kind = getValueFromFilter(conditions, ShadowType.F_KIND);
intent = getValueFromFilter(conditions, ShadowType.F_INTENT);
}
String resourceOid = getResourceOidFromFilter(filter);
QName objectClass = getPropertyRealValueFromFilter(filter, ShadowType.F_OBJECT_CLASS);
ShadowKindType kind = getPropertyRealValueFromFilter(filter, ShadowType.F_KIND);
String intent = getPropertyRealValueFromFilter(filter, ShadowType.F_INTENT);

if (resourceOid == null) {
throw new SchemaException("Resource not defined in a search query");
Expand Down
@@ -1,12 +1,9 @@
package com.evolveum.midpoint.model.api;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WfProcessInstanceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemNewType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType;
Expand Down Expand Up @@ -88,16 +85,12 @@ public interface WorkflowService {

/**
* Approves or rejects a work item (without supplying any further information).
*
* @param taskId identifier of activiti task backing the work item
* @param taskId identifier of activiti task backing the work item
* @param decision true = approve, false = reject
* @param parentResult
* @param comment
*/
void approveOrRejectWorkItem(String workItemId, boolean decision, OperationResult parentResult);

void approveOrRejectWorkItemWithDetails(String workItemId, PrismObject specific, boolean decision, OperationResult result);

void completeWorkItemWithDetails(String workItemId, PrismObject specific, String decision, OperationResult parentResult);
void approveOrRejectWorkItem(String workItemId, boolean decision, String comment, OperationResult parentResult);

void stopProcessInstance(String instanceId, String username, OperationResult parentResult);

Expand Down
Expand Up @@ -1850,18 +1850,8 @@ public WfProcessInstanceType getProcessInstanceById(String instanceId, boolean h
}

@Override
public void approveOrRejectWorkItem(String workItemId, boolean decision, OperationResult parentResult) {
getWorkflowManagerChecked().approveOrRejectWorkItem(workItemId, decision, parentResult);
}

@Override
public void approveOrRejectWorkItemWithDetails(String workItemId, PrismObject specific, boolean decision, OperationResult result) {
getWorkflowManagerChecked().approveOrRejectWorkItemWithDetails(workItemId, specific, decision, result);
}

@Override
public void completeWorkItemWithDetails(String workItemId, PrismObject specific, String decision, OperationResult parentResult) {
getWorkflowManagerChecked().completeWorkItemWithDetails(workItemId, specific, decision, parentResult);
public void approveOrRejectWorkItem(String workItemId, boolean decision, String comment, OperationResult parentResult) {
getWorkflowManagerChecked().approveOrRejectWorkItem(workItemId, decision, comment, parentResult);
}

@Override
Expand Down
Expand Up @@ -121,16 +121,12 @@ <T extends Containerable> SearchResultList<T> searchContainers(Class<T> type, Ob

/**
* Approves or rejects a work item (without supplying any further information).
*
* @param taskId identifier of activiti task backing the work item
* @param taskId identifier of activiti task backing the work item
* @param decision true = approve, false = reject
* @param comment
* @param parentResult
*/
void approveOrRejectWorkItem(String taskId, boolean decision, OperationResult parentResult);

void approveOrRejectWorkItemWithDetails(String taskId, PrismObject specific, boolean decision, OperationResult result);

void completeWorkItemWithDetails(String taskId, PrismObject specific, String decision, OperationResult parentResult);
void approveOrRejectWorkItem(String taskId, boolean decision, String comment, OperationResult parentResult);

void claimWorkItem(String workItemId, OperationResult result);

Expand Down
Expand Up @@ -135,18 +135,8 @@ public <T extends Containerable> SearchResultList<T> searchContainers(Class<T> t
}

@Override
public void approveOrRejectWorkItem(String taskId, boolean decision, OperationResult parentResult) {
workItemManager.completeWorkItemWithDetails(taskId, null, ApprovalUtils.approvalStringValue(decision), parentResult);
}

@Override
public void approveOrRejectWorkItemWithDetails(String taskId, PrismObject specific, boolean decision, OperationResult parentResult) {
workItemManager.completeWorkItemWithDetails(taskId, specific, ApprovalUtils.approvalStringValue(decision), parentResult);
}

@Override
public void completeWorkItemWithDetails(String taskId, PrismObject specific, String decision, OperationResult parentResult) {
workItemManager.completeWorkItemWithDetails(taskId, specific, decision, parentResult);
public void approveOrRejectWorkItem(String taskId, boolean decision, String comment, OperationResult parentResult) {
workItemManager.completeWorkItemWithDetails(taskId, comment, ApprovalUtils.approvalStringValue(decision), parentResult);
}

@Override
Expand Down
Expand Up @@ -79,7 +79,7 @@ public class WorkItemManager {
// exactly one of choiceDecision and approvalDecision must be set
//
// todo error reporting
public void completeWorkItemWithDetails(String taskId, PrismObject specific, String decision, OperationResult parentResult) {
public void completeWorkItemWithDetails(String taskId, String comment, String decision, OperationResult parentResult) {

MidPointPrincipal principal;
try {
Expand All @@ -91,14 +91,14 @@ public void completeWorkItemWithDetails(String taskId, PrismObject specific, Str

OperationResult result = parentResult.createSubresult(OPERATION_COMPLETE_WORK_ITEM);
result.addParam("taskId", taskId);
result.addParam("comment", comment);
result.addParam("decision", decision);
result.addParam("task-specific data", specific);
result.addContext("user", principal.getUser());

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Completing work item " + taskId);
LOGGER.trace("Decision: " + decision);
LOGGER.trace("WorkItem form object (task-specific) = " + (specific != null ? specific.debugDump() : "(none)"));
LOGGER.trace("Comment: " + comment);
LOGGER.trace("User: " + principal.getUser());
}

Expand All @@ -115,6 +115,9 @@ public void completeWorkItemWithDetails(String taskId, PrismObject specific, Str
Map<String,String> propertiesToSubmit = new HashMap<String,String>();

propertiesToSubmit.put(CommonProcessVariableNames.FORM_FIELD_DECISION, decision);
if (comment != null) {
propertiesToSubmit.put(CommonProcessVariableNames.FORM_FIELD_COMMENT, comment);
}

// we also fill-in the corresponding 'button' property (if there's one that corresponds to the decision)
for (FormProperty formProperty : data.getFormProperties()) {
Expand All @@ -125,38 +128,38 @@ public void completeWorkItemWithDetails(String taskId, PrismObject specific, Str
}
}

if (specific != null) {

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("# of form properties: " + data.getFormProperties().size());
}

for (FormProperty formProperty : data.getFormProperties()) {

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing property " + formProperty.getId() + ":" + formProperty.getName());
}

if (formProperty.isWritable()) {

Object value;

if (!CommonProcessVariableNames.FORM_FIELD_DECISION.equals(formProperty.getId()) &&
!formProperty.getId().startsWith(CommonProcessVariableNames.FORM_BUTTON_PREFIX)) {

// todo strip [flags] section
QName propertyName = new QName(SchemaConstants.NS_WFCF, formProperty.getId());
value = specific.getPropertyRealValue(propertyName, Object.class);

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Writable property " + formProperty.getId() + " has a value of " + value);
}

propertiesToSubmit.put(formProperty.getId(), value == null ? "" : value.toString());
}
}
}
}
// if (specific != null) {
//
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("# of form properties: " + data.getFormProperties().size());
// }
//
// for (FormProperty formProperty : data.getFormProperties()) {
//
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("Processing property " + formProperty.getId() + ":" + formProperty.getName());
// }
//
// if (formProperty.isWritable()) {
//
// Object value;
//
// if (!CommonProcessVariableNames.FORM_FIELD_DECISION.equals(formProperty.getId()) &&
// !formProperty.getId().startsWith(CommonProcessVariableNames.FORM_BUTTON_PREFIX)) {
//
// // todo strip [flags] section
// QName propertyName = new QName(SchemaConstants.NS_WFCF, formProperty.getId());
// value = specific.getPropertyRealValue(propertyName, Object.class);
//
// if (LOGGER.isTraceEnabled()) {
// LOGGER.trace("Writable property " + formProperty.getId() + " has a value of " + value);
// }
//
// propertiesToSubmit.put(formProperty.getId(), value == null ? "" : value.toString());
// }
// }
// }
// }

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Submitting " + propertiesToSubmit.size() + " properties");
Expand Down
Expand Up @@ -56,7 +56,6 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.wf.impl.activiti.ActivitiEngine;
import com.evolveum.midpoint.wf.impl.jobs.WfProcessInstanceShadowTaskHandler;
import com.evolveum.midpoint.wf.impl.jobs.WfTaskUtil;
import com.evolveum.midpoint.wf.impl.processes.common.WorkflowResult;
import com.evolveum.midpoint.wf.impl.processes.itemApproval.ApprovalRequestImpl;
Expand Down Expand Up @@ -443,7 +442,7 @@ protected void executeTest(String testName, String oid, TestDetails testDetails)

boolean approve = testDetails.decideOnApproval(executionId);

workflowServiceImpl.approveOrRejectWorkItem(taskId, approve, result);
workflowServiceImpl.approveOrRejectWorkItem(taskId, approve, null, result);
login(userAdministrator);
}
}
Expand Down
Expand Up @@ -190,7 +190,7 @@ void completeWorkItem(WorkItemType workItem, String taskId, OperationResult resu
}

login(getUser(USER_ADMINISTRATOR_OID));
workflowServiceImpl.completeWorkItemWithDetails(taskId, qFormObject, "approve", result);
// workflowServiceImpl.completeWorkItemWithDetails(taskId, qFormObject, "approve", result);
}

@Override
Expand Down Expand Up @@ -243,7 +243,7 @@ void completeWorkItem(WorkItemType workItem, String taskId, OperationResult resu
questionFormPrism.addReplaceExisting(rejectAll);

login(getUser(USER_ADMINISTRATOR_OID));
workflowServiceImpl.completeWorkItemWithDetails(taskId, questionFormPrism, "rejectAll", result);
// workflowServiceImpl.completeWorkItemWithDetails(taskId, questionFormPrism, "rejectAll", result);
}

@Override
Expand Down Expand Up @@ -343,7 +343,7 @@ void completeWorkItem(WorkItemType workItem, String taskId, OperationResult resu
questionFormPrism.addReplaceExisting(approve);

login(getUser(USER_ADMINISTRATOR_OID));
workflowServiceImpl.completeWorkItemWithDetails(taskId, questionFormPrism, "approve", result);
// workflowServiceImpl.completeWorkItemWithDetails(taskId, questionFormPrism, "approve", result);
}

@Override
Expand Down

0 comments on commit ea650fc

Please sign in to comment.