Skip to content

Commit

Permalink
currentStageOutcome: enum -> URI
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Apr 7, 2017
1 parent b0c3ce5 commit 7359f13
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 96 deletions.
Expand Up @@ -321,6 +321,8 @@ public abstract class SchemaConstants {
QNameUtil.qNameToUri(new QName(NS_MODEL_CERTIFICATION_OUTCOME, "reduce"));
public static final String MODEL_CERTIFICATION_OUTCOME_NOT_DECIDED =
QNameUtil.qNameToUri(new QName(NS_MODEL_CERTIFICATION_OUTCOME, "notDecided"));
public static final String MODEL_CERTIFICATION_OUTCOME_NO_RESPONSE =
QNameUtil.qNameToUri(new QName(NS_MODEL_CERTIFICATION_OUTCOME, "noResponse")); // only for aggregated decisions

public static final QName MODEL_EXTENSION_OBJECT_TYPE = new QName(NS_MODEL_EXTENSION, "objectType");
public static final QName MODEL_EXTENSION_OBJECT_QUERY = new QName(NS_MODEL_EXTENSION, "objectQuery");
Expand Down
Expand Up @@ -825,7 +825,7 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="currentStageOutcome" type="tns:AccessCertificationResponseType" minOccurs="0" maxOccurs="1">
<xsd:element name="currentStageOutcome" type="xsd:anyURI" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Currently valid outcome, relevant to the current stage. It is recomputed on each reviewer's
Expand Down
Expand Up @@ -18,9 +18,6 @@

import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemOutcomeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemResultType;
import org.apache.commons.lang.BooleanUtils;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -42,6 +39,7 @@ public static String toUri(AccessCertificationResponseType response) {
case REVOKE: return SchemaConstants.MODEL_CERTIFICATION_OUTCOME_REVOKE;
case REDUCE: return SchemaConstants.MODEL_CERTIFICATION_OUTCOME_REDUCE;
case NOT_DECIDED: return SchemaConstants.MODEL_CERTIFICATION_OUTCOME_NOT_DECIDED;
case NO_RESPONSE: return SchemaConstants.MODEL_CERTIFICATION_OUTCOME_NO_RESPONSE;
default: throw new AssertionError("Unexpected response: " + response);
}
}
Expand All @@ -57,6 +55,8 @@ public static AccessCertificationResponseType fromUri(String uri) {
return AccessCertificationResponseType.REDUCE;
} else if (SchemaConstants.MODEL_CERTIFICATION_OUTCOME_NOT_DECIDED.equals(uri)) {
return AccessCertificationResponseType.NOT_DECIDED;
} else if (SchemaConstants.MODEL_CERTIFICATION_OUTCOME_NO_RESPONSE.equals(uri)) {
return AccessCertificationResponseType.NO_RESPONSE;
} else {
throw new IllegalArgumentException("Unrecognized URI: " + uri);
}
Expand Down
Expand Up @@ -54,6 +54,7 @@
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import java.util.*;
import java.util.Objects;

import static com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType.F_CASE;
Expand Down Expand Up @@ -106,17 +107,17 @@ void recordDecision(String campaignOid, long caseId, long workItemId,

ItemDelta.applyTo(deltaList, campaign.asPrismContainerValue());

AccessCertificationResponseType newCurrentOutcome = computationHelper.computeOutcomeForStage(_case, campaign, campaign.getStageNumber());
String newCurrentOutcome = OutcomeUtils.toUri(computationHelper.computeOutcomeForStage(_case, campaign, campaign.getStageNumber()));
if (!ObjectUtils.equals(newCurrentOutcome, _case.getCurrentStageOutcome())) {
deltaList.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext)
.item(F_CASE, _case.asPrismContainerValue().getId(), F_CURRENT_STAGE_OUTCOME).replace(newCurrentOutcome)
.asItemDelta());
}

AccessCertificationResponseType newOverallOutcome = computationHelper.computeOverallOutcome(_case, campaign, newCurrentOutcome);
String newOverallOutcome = OutcomeUtils.toUri(computationHelper.computeOverallOutcome(_case, campaign, newCurrentOutcome));
if (!ObjectUtils.equals(newOverallOutcome, _case.getOutcome())) {
deltaList.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext)
.item(F_CASE, _case.asPrismContainerValue().getId(), F_OUTCOME).replace(OutcomeUtils.toUri(newOverallOutcome))
.item(F_CASE, _case.asPrismContainerValue().getId(), F_OUTCOME).replace(newOverallOutcome)
.asItemDelta());
}

Expand Down Expand Up @@ -200,7 +201,7 @@ <F extends FocusType> List<ItemDelta<?,?>> getDeltasToCreateCases(
List<ObjectReferenceType> reviewers = reviewersHelper.getReviewersForCase(_case, campaign, reviewerSpec, task, result);
_case.getWorkItem().addAll(createWorkItems(reviewers, 1));

AccessCertificationResponseType currentStageOutcome = computationHelper.computeOutcomeForStage(_case, campaign, 1);
String currentStageOutcome = OutcomeUtils.toUri(computationHelper.computeOutcomeForStage(_case, campaign, 1));
_case.setCurrentStageOutcome(currentStageOutcome);
_case.setOutcome(OutcomeUtils.toUri(computationHelper.computeOverallOutcome(_case, campaign, currentStageOutcome)));

Expand Down Expand Up @@ -256,7 +257,7 @@ List<ItemDelta<?,?>> getDeltasToAdvanceCases(AccessCertificationCampaignType cam
.item(F_CASE, caseId, F_WORK_ITEM).add(PrismContainerValue.toPcvList(workItems))
.item(F_CASE, caseId, F_CURRENT_STAGE_CREATE_TIMESTAMP).replace(stage.getStart())
.item(F_CASE, caseId, F_CURRENT_STAGE_DEADLINE).replace(stage.getDeadline())
.item(F_CASE, caseId, F_CURRENT_STAGE_OUTCOME).replace(currentOutcome)
.item(F_CASE, caseId, F_CURRENT_STAGE_OUTCOME).replace(OutcomeUtils.toUri(currentOutcome))
.item(F_CASE, caseId, F_OUTCOME).replace(OutcomeUtils.toUri(overallOutcome))
.item(F_CASE, caseId, F_STAGE_NUMBER).replace(stageToBe)
.asItemDeltas());
Expand All @@ -279,35 +280,23 @@ List<ItemDelta<?,?>> createOutcomeDeltas(AccessCertificationCampaignType campaig
if (_case.getStageNumber() != campaign.getStageNumber()) {
continue;
}
AccessCertificationResponseType newStageOutcome = computationHelper.computeOutcomeForStage(_case, campaign, campaign.getStageNumber());
if (newStageOutcome != _case.getCurrentStageOutcome()) {
if (newStageOutcome == null) {
throw new IllegalStateException(
"Computed currentStateOutcome is null for case id " + _case.asPrismContainerValue().getId());
}
ItemDelta currentStageOutcomeDelta = DeltaBuilder
.deltaFor(AccessCertificationCampaignType.class, prismContext)
String newStageOutcome = OutcomeUtils.toUri(computationHelper.computeOutcomeForStage(_case, campaign, campaign.getStageNumber()));
if (!Objects.equals(newStageOutcome, _case.getCurrentStageOutcome())) {
rv.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext)
.item(F_CASE, _case.asPrismContainerValue().getId(), F_CURRENT_STAGE_OUTCOME).replace(newStageOutcome)
.asItemDelta();
rv.add(currentStageOutcomeDelta);
.asItemDelta());
}

rv.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext)
.item(F_CASE, _case.asPrismContainerValue().getId(), F_EVENT).add(new StageCompletionEventType()
.timestamp(clock.currentTimeXMLGregorianCalendar())
.stageNumber(campaign.getStageNumber())
.outcome(OutcomeUtils.toUri(newStageOutcome)))
.outcome(newStageOutcome))
.asItemDelta());

AccessCertificationResponseType newOverallOutcome = computationHelper.computeOverallOutcome(_case, campaign, newStageOutcome);
if (newOverallOutcome != OutcomeUtils.fromUri(_case.getOutcome())) {
// TODO what about NO_RESPONSE here?
if (newOverallOutcome == null) {
throw new IllegalStateException(
"Computed overallOutcome is null for case id " + _case.asPrismContainerValue().getId());
}
String newOverallOutcome = OutcomeUtils.toUri(computationHelper.computeOverallOutcome(_case, campaign, newStageOutcome));
if (!Objects.equals(newOverallOutcome, _case.getOutcome())) {
rv.add(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext)
.item(F_CASE, _case.asPrismContainerValue().getId(), F_OUTCOME).replace(OutcomeUtils.toUri(newOverallOutcome))
.item(F_CASE, _case.asPrismContainerValue().getId(), F_OUTCOME).replace(newOverallOutcome)
.asItemDelta());
}
}
Expand Down
Expand Up @@ -66,10 +66,8 @@ public boolean computeEnabled(AccessCertificationCampaignType campaign, AccessCe
if (_case.getStageNumber() != campaign.getStageNumber()) {
return false; // it is not enabled in the current stage at all
}
final AccessCertificationResponseType currentOutcome;
if (_case.getCurrentStageOutcome() != null) {
currentOutcome =_case.getCurrentStageOutcome();
} else {
AccessCertificationResponseType currentOutcome = OutcomeUtils.fromUri(_case.getCurrentStageOutcome());
if (currentOutcome == null) {
currentOutcome = NO_RESPONSE;
}
return !outcomesToStopOn.contains(currentOutcome);
Expand Down Expand Up @@ -153,6 +151,11 @@ public AccessCertificationResponseType computeOverallOutcome(AccessCertification
}

// aCase contains outcomes from stages 1..N-1. Outcome from stage N is in currentStageOutcome
AccessCertificationResponseType computeOverallOutcome(AccessCertificationCaseType aCase, AccessCertificationCampaignType campaign,
String currentStageOutcome) {
return computeOverallOutcome(aCase, campaign, OutcomeUtils.fromUri(currentStageOutcome));
}

AccessCertificationResponseType computeOverallOutcome(AccessCertificationCaseType aCase, AccessCertificationCampaignType campaign,
AccessCertificationResponseType currentStageOutcome) {
final OutcomeStrategy strategy = getOverallOutcomeStrategy(campaign);
Expand Down
Expand Up @@ -410,7 +410,7 @@ public AccessCertificationCasesStatisticsType getCampaignStatistics(String campa
AccessCertificationResponseType outcome;
if (currentStageOnly) {
if (_case.getStageNumber() == campaign.getStageNumber()) {
outcome = _case.getCurrentStageOutcome();
outcome = OutcomeUtils.fromUri(_case.getCurrentStageOutcome());
} else {
continue;
}
Expand Down
Expand Up @@ -404,7 +404,7 @@ protected void assertDefinitionAndOwner(AccessCertificationCampaignType campaign

protected void assertCaseReviewers(AccessCertificationCaseType _case, AccessCertificationResponseType currentStageOutcome,
int currentStage, List<String> reviewerOidList) {
assertEquals("wrong current stage outcome for "+_case, currentStageOutcome, _case.getCurrentStageOutcome());
assertEquals("wrong current stage outcome for "+_case, OutcomeUtils.toUri(currentStageOutcome), _case.getCurrentStageOutcome());
assertEquals("wrong current stage number for "+_case, currentStage, _case.getStageNumber());
Set<String> realReviewerOids = CertCampaignTypeUtil.getCurrentReviewers(_case).stream().map(ref -> ref.getOid()).collect(Collectors.toSet());
assertEquals("wrong reviewer oids for "+_case, new HashSet<>(reviewerOidList), realReviewerOids);
Expand Down Expand Up @@ -448,7 +448,7 @@ protected void assertSingleDecision(AccessCertificationCaseType _case, AccessCer
if (response != null) {
assertApproximateTime("timestamp", new Date(), workItem.getOutputChangeTimestamp());
}
assertEquals("wrong current stage outcome", currentStageOutcome, _case.getCurrentStageOutcome());
assertEquals("wrong current stage outcome", OutcomeUtils.toUri(currentStageOutcome), _case.getCurrentStageOutcome());
if (checkHistory) {
assertHistoricOutcome(_case, stageNumber, currentStageOutcome);
}
Expand All @@ -463,7 +463,7 @@ protected void assertReviewerDecision(AccessCertificationCaseType _case, AccessC
if (response != null) {
assertApproximateTime("timestamp", new Date(), workItem.getOutputChangeTimestamp());
}
assertEquals("wrong current stage outcome", currentStageOutcome, _case.getCurrentStageOutcome());
assertEquals("wrong current stage outcome", OutcomeUtils.toUri(currentStageOutcome), _case.getCurrentStageOutcome());
if (checkHistory) {
assertHistoricOutcome(_case, stageNumber, currentStageOutcome);
}
Expand Down Expand Up @@ -520,14 +520,14 @@ public AccessCertificationWorkItemType getWorkItemsForReviewer(AccessCertificati
protected void assertNoDecision(AccessCertificationCaseType _case, int stage, AccessCertificationResponseType aggregatedResponse, boolean checkHistory) {
List<AccessCertificationWorkItemType> currentWorkItems = getCurrentWorkItems(_case, stage, true);
assertEquals("wrong # of decisions", 0, currentWorkItems.size());
assertEquals("wrong current response", aggregatedResponse, _case.getCurrentStageOutcome());
assertEquals("wrong current response", OutcomeUtils.toUri(aggregatedResponse), _case.getCurrentStageOutcome());
if (checkHistory) {
assertHistoricOutcome(_case, stage, aggregatedResponse);
}
}

protected void assertCurrentState(AccessCertificationCaseType _case, AccessCertificationResponseType aggregatedResponse, int currentResponseStage) {
assertEquals("wrong current response", aggregatedResponse, _case.getCurrentStageOutcome());
assertEquals("wrong current response", OutcomeUtils.toUri(aggregatedResponse), _case.getCurrentStageOutcome());
assertEquals("wrong current response stage number", currentResponseStage, _case.getStageNumber());
}

Expand All @@ -544,7 +544,7 @@ protected void assertDecision2(AccessCertificationCaseType _case, AccessCertific
if (response != null) {
assertApproximateTime("timestamp", new Date(), workItem.getOutputChangeTimestamp());
}
assertEquals("wrong current response", aggregatedResponse, _case.getCurrentStageOutcome());
assertEquals("wrong current response", OutcomeUtils.toUri(aggregatedResponse), _case.getCurrentStageOutcome());
}

protected AccessCertificationCampaignType getCampaignWithCases(String campaignOid) throws ConfigurationException, ObjectNotFoundException, SchemaException, CommunicationException, SecurityViolationException {
Expand Down Expand Up @@ -595,7 +595,7 @@ private AccessCertificationResponseType checkCaseStageOutcome(AccessCertificatio
protected void assertCaseOutcome(List<AccessCertificationCaseType> caseList, String subjectOid, String targetOid,
AccessCertificationResponseType stageOutcome, AccessCertificationResponseType overallOutcome, Integer completedStage) {
AccessCertificationCaseType ccase = findCase(caseList, subjectOid, targetOid);
assertEquals("Wrong stage outcome in " + ccase, stageOutcome, ccase.getCurrentStageOutcome());
assertEquals("Wrong stage outcome in " + ccase, OutcomeUtils.toUri(stageOutcome), ccase.getCurrentStageOutcome());
assertEquals("Wrong overall outcome in " + ccase, OutcomeUtils.toUri(overallOutcome), ccase.getOutcome());

if (completedStage != null) {
Expand Down
Expand Up @@ -22,7 +22,6 @@
import com.evolveum.midpoint.repo.sql.data.common.RAccessCertificationCampaign;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation;
import com.evolveum.midpoint.repo.sql.data.common.embedded.REmbeddedReference;
import com.evolveum.midpoint.repo.sql.data.common.enums.RAccessCertificationResponse;
import com.evolveum.midpoint.repo.sql.data.common.id.RContainerId;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbName;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbType;
Expand Down Expand Up @@ -89,7 +88,7 @@ public class RAccessCertificationCase implements Container<RAccessCertificationC
private XMLGregorianCalendar reviewRequestedTimestamp;
private XMLGregorianCalendar reviewDeadline;
private XMLGregorianCalendar remediedTimestamp;
private RAccessCertificationResponse currentStageOutcome;
private String currentStageOutcome;
private Integer currentStageNumber;
private String outcome;

Expand Down Expand Up @@ -171,7 +170,7 @@ public XMLGregorianCalendar getRemediedTimestamp() {
return remediedTimestamp;
}

public RAccessCertificationResponse getCurrentStageOutcome() {
public String getCurrentStageOutcome() {
return currentStageOutcome;
}

Expand Down Expand Up @@ -230,7 +229,7 @@ public void setRemediedTimestamp(XMLGregorianCalendar remediedTimestamp) {
this.remediedTimestamp = remediedTimestamp;
}

public void setCurrentStageOutcome(RAccessCertificationResponse currentStageOutcome) {
public void setCurrentStageOutcome(String currentStageOutcome) {
this.currentStageOutcome = currentStageOutcome;
}

Expand Down Expand Up @@ -338,7 +337,7 @@ private static RAccessCertificationCase toRepo(RAccessCertificationCase rCase, A
rCase.setReviewRequestedTimestamp(case1.getCurrentStageCreateTimestamp());
rCase.setReviewDeadline(case1.getCurrentStageDeadline());
rCase.setRemediedTimestamp(case1.getRemediedTimestamp());
rCase.setCurrentStageOutcome(RUtil.getRepoEnumValue(case1.getCurrentStageOutcome(), RAccessCertificationResponse.class));
rCase.setCurrentStageOutcome(case1.getCurrentStageOutcome());
rCase.setCurrentStageNumber(case1.getStageNumber());
rCase.setOutcome(case1.getOutcome());
PrismContainerValue<AccessCertificationCaseType> cvalue = case1.asPrismContainerValue();
Expand Down

This file was deleted.

0 comments on commit 7359f13

Please sign in to comment.