Skip to content

Commit

Permalink
Creating work items for new cases in manual resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 9, 2017
1 parent b0cffcc commit 1f6a690
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 47 deletions.
Expand Up @@ -4846,6 +4846,15 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="operatorRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Reference to users that should execute operations on manual resources.
It may point to user or organization. (Currently only users are supported.)
If more than one operator is specified they are considered equivalent.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long" use="optional"/>
</xsd:complexType>
Expand Down
Expand Up @@ -437,10 +437,10 @@ public void test100AddAccountWill() throws Exception {

assertNotNull("No async reference in result", willLastCaseOid);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}


protected abstract String[] getExpectedOperators();

@Test
public void test102GetAccountWillFuture() throws Exception {
Expand Down Expand Up @@ -525,7 +525,7 @@ public void test104RefreshAccountWill() throws Exception {

PendingOperationType pendingOperation = assertSinglePendingOperation(shadowProvisioning, accountWillReqestTimestampStart, accountWillReqestTimestampEnd);

assertCase(pendingOperation.getAsynchronousOperationReference(), SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(pendingOperation.getAsynchronousOperationReference(), SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}

protected void backingStoreAddWill() throws IOException {
Expand Down Expand Up @@ -715,7 +715,7 @@ public void test110CloseCaseAndRefreshAccountWill() throws Exception {
OperationResultStatusType.SUCCESS,
accountWillCompletionTimestampStart, accountWillCompletionTimestampEnd);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -759,7 +759,7 @@ public void test120RefreshAccountWillAfter5min() throws Exception {
OperationResultStatusType.SUCCESS,
accountWillCompletionTimestampStart, accountWillCompletionTimestampEnd);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());

syncServiceMock.assertNoNotifyChange();
syncServiceMock.assertNoNotifcations();
Expand Down Expand Up @@ -799,7 +799,7 @@ public void test130RefreshAccountWillAfter25min() throws Exception {
ACCOUNT_WILL_OID, null, task, result);
assertNoPendingOperation(shadowProvisioning);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());

syncServiceMock.assertNoNotifyChange();
syncServiceMock.assertNoNotifcations();
Expand Down Expand Up @@ -875,7 +875,7 @@ ACCOUNT_WILL_OID, new ItemPath(ShadowType.F_ATTRIBUTES, ATTR_FULLNAME_QNAME), pr

assertNotNull("No async reference in result", willLastCaseOid);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}

@Test
Expand Down Expand Up @@ -936,7 +936,7 @@ public void test202RefreshAccountWill() throws Exception {
assertAttribute(shadowProvisioningFuture, ATTR_FULLNAME_QNAME, ACCOUNT_WILL_FULLNAME_PIRATE);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());

}

Expand Down Expand Up @@ -1014,7 +1014,7 @@ public void test204CloseCaseAndRefreshAccountWill() throws Exception {
assertAttributeFromBackingStore(shadowProvisioningFuture, ATTR_DESCRIPTION_QNAME, ACCOUNT_WILL_DESCRIPTION_MANUAL);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());

// In this case check notifications at the end. There were some reads that
// internally triggered refresh. Maku sure no extra notifications were sent.
Expand Down Expand Up @@ -1087,7 +1087,7 @@ public void test210RefreshAccountWillAfter5min() throws Exception {
assertAttributeFromBackingStore(shadowProvisioningFuture, ATTR_DESCRIPTION_QNAME, ACCOUNT_WILL_DESCRIPTION_MANUAL);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

protected void backingStoreUpdateWill(String newFullName, ActivationStatusType newAdministrativeStatus, String password) throws IOException {
Expand Down Expand Up @@ -1152,7 +1152,7 @@ public void test212UpdateBackingStoreAndGetAccountWill() throws Exception {
assertAttributeFromBackingStore(shadowProvisioningFuture, ATTR_DESCRIPTION_QNAME, ACCOUNT_WILL_DESCRIPTION_MANUAL);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}


Expand Down Expand Up @@ -1236,7 +1236,7 @@ public void test220ModifyAccountWillDisable() throws Exception {

assertNotNull("No async reference in result", willLastCaseOid);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -1324,8 +1324,8 @@ public void test230ModifyAccountWillChangePasswordAndEnable() throws Exception {

assertNotNull("No async reference in result", willSecondLastCaseOid);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -1420,8 +1420,8 @@ public void test240CloseDisableCaseAndReadAccountWill() throws Exception {
// TODO
// assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -1511,8 +1511,8 @@ public void test250RefreshAccountWillAfter5min() throws Exception {
// TODO
// assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}

@Test
Expand Down Expand Up @@ -1573,8 +1573,8 @@ public void test252UpdateBackingStoreAndGetAccountWill() throws Exception {
// TODO
// assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -1673,8 +1673,8 @@ public void test260ClosePasswordChangeCaseAndRefreshAccountWill() throws Excepti
assertAttributeFromBackingStore(shadowProvisioningFuture, ATTR_DESCRIPTION_QNAME, ACCOUNT_WILL_DESCRIPTION_MANUAL);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -1766,8 +1766,8 @@ public void test270RefreshAccountWillAfter7min() throws Exception {
assertAttributeFromBackingStore(shadowProvisioningFuture, ATTR_DESCRIPTION_QNAME, ACCOUNT_WILL_DESCRIPTION_MANUAL);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

@Test
Expand Down Expand Up @@ -1828,8 +1828,8 @@ public void test272UpdateBackingStoreAndGetAccountWill() throws Exception {
// TODO
// assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -1917,8 +1917,8 @@ public void test280RefreshAccountWillAfter5min() throws Exception {
assertAttributeFromBackingStore(shadowProvisioningFuture, ATTR_DESCRIPTION_QNAME, ACCOUNT_WILL_DESCRIPTION_MANUAL);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -1986,8 +1986,8 @@ public void test290RefreshAccountWillAfter5min() throws Exception {
assertAttributeFromBackingStore(shadowProvisioningFuture, ATTR_DESCRIPTION_QNAME, ACCOUNT_WILL_DESCRIPTION_MANUAL);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
assertCase(willSecondLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

@Test
Expand Down Expand Up @@ -2057,7 +2057,7 @@ public void test300DeleteAccountWill() throws Exception {

assertNotNull("No async reference in result", willLastCaseOid);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_OPEN, getResourceOid(), getExpectedOperators());
}

@Test
Expand Down Expand Up @@ -2180,7 +2180,7 @@ public void test310CloseCaseAndRefreshAccountWill() throws Exception {
assertShadowDead(shadowProvisioningFuture);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

/**
Expand Down Expand Up @@ -2243,7 +2243,7 @@ public void test320RefreshAccountWillAfter5min() throws Exception {
assertShadowDead(shadowProvisioningFuture);
assertShadowPassword(shadowProvisioningFuture);

assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid());
assertCase(willLastCaseOid, SchemaConstants.CASE_STATE_CLOSED, getResourceOid(), getExpectedOperators());
}

// TODO: create, close case, then update backing store.
Expand Down
Expand Up @@ -126,4 +126,9 @@ protected File getResourceFile() {
protected void assertResourceSchemaBeforeTest(Element resourceXsdSchemaElementBefore) {
AssertJUnit.assertNotNull("No schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
}

@Override
protected String[] getExpectedOperators() {
return new String[] { "operator1-oid", "operator2-oid" };
}
}
Expand Up @@ -35,6 +35,7 @@
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemObjectsType;
import org.apache.commons.io.FileUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -158,4 +159,9 @@ protected void assertShadowPassword(PrismObject<ShadowType> shadow) {
PrismProperty<PolyStringType> passValProp = shadow.findProperty(SchemaConstants.PATH_PASSWORD_VALUE);
assertNotNull("No password value property in "+shadow+": "+passValProp, passValProp);
}

@Override
protected String[] getExpectedOperators() {
return new String[] { SystemObjectsType.USER_ADMINISTRATOR.value() };
}
}
Expand Up @@ -81,5 +81,10 @@
<consistency>
<pendingOperationGracePeriod>PT15M</pendingOperationGracePeriod>
</consistency>

<business>
<operatorRef oid="operator1-oid" type="UserType"/>
<operatorRef oid="operator2-oid" type="UserType"/>
</business>

</resource>
Expand Up @@ -15,7 +15,9 @@
*/
package com.evolveum.midpoint.provisioning.ucf.impl.builtin;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

import com.evolveum.midpoint.prism.PrismObject;
Expand Down Expand Up @@ -67,6 +69,8 @@ public class ManualConnectorInstance extends AbstractManualConnectorInstance imp
private boolean connected = false;

private static int randomDelayRange = 0;

private static final String DEFAULT_OPERATOR_OID = "00000000-0000-0000-0000-000000000002"; // administrator

protected static final Random RND = new Random();

Expand Down Expand Up @@ -151,7 +155,24 @@ private PrismObject<CaseType> addCase(String description, String resourceOid, Op
}
LOGGER.info("Manual connector wait is over");
}


PrismObject<ResourceType> resource;
try {
resource = repositoryService.getObject(ResourceType.class, resourceOid, null, result);
} catch (ObjectNotFoundException e) {
// We do not signal this as ObjectNotFoundException as it could be misinterpreted as "shadow
// object not found" with subsequent handling as such.
throw new SystemException("Resource " + resourceOid + " couldn't be found", e);
}
ResourceBusinessConfigurationType businessConfiguration = resource.asObjectable().getBusiness();
List<ObjectReferenceType> operators = new ArrayList<>();
if (businessConfiguration != null) {
operators.addAll(businessConfiguration.getOperatorRef());
}
if (operators.isEmpty()) {
operators.add(new ObjectReferenceType().oid(DEFAULT_OPERATOR_OID).type(UserType.COMPLEX_TYPE));
}

String caseOid = OidUtil.generateOid();

caseType.setOid(caseOid);
Expand All @@ -165,6 +186,15 @@ private PrismObject<CaseType> addCase(String description, String resourceOid, Op

caseType.setObjectRef(new ObjectReferenceType().oid(resourceOid).type(ResourceType.COMPLEX_TYPE));

for (ObjectReferenceType operator : operators) {
CaseWorkItemType workItem = new CaseWorkItemType(getPrismContext())
.originalAssigneeRef(operator.clone())
.assigneeRef(operator.clone())
.name(caseType.getName().getOrig());
caseType.getWorkItem().add(workItem);
// TODO deadline and maybe other fields
}

// TODO: case payload
// TODO: a lot of other things

Expand Down
Expand Up @@ -5,19 +5,7 @@
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.cxf.common.util.StringUtils;
Expand Down Expand Up @@ -129,6 +117,10 @@ private List<PrismContainer<?>> getContainersToGenerateIdsFor(PrismObject parent
CollectionUtils.addIgnoreNull(containers, parent.findContainer(ResourceType.F_ADDITIONAL_CONNECTOR));
}

if (CaseType.class.isAssignableFrom(parent.getCompileTimeClass())) {
CollectionUtils.addIgnoreNull(containers, parent.findContainer(CaseType.F_WORK_ITEM));
}

if (UserType.class.isAssignableFrom(parent.getCompileTimeClass())) {
CollectionUtils.addIgnoreNull(containers, parent.findContainer(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER)));
}
Expand Down

0 comments on commit 1f6a690

Please sign in to comment.