use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class AssignExecutor method parseParameters.
@Override
AssignParameters parseParameters(ActionExpressionType action, PipelineData input, ExecutionContext context, OperationResult result) throws SchemaException, ScriptExecutionException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
AssignParameters parameters = new AssignParameters();
// Dynamic parameters
Collection<ObjectReferenceType> dynamicRoleRefs = getRolesParameter(action, input, context, result);
Collection<ObjectReferenceType> dynamicResourceRefs = getResourcesParameter(action, input, context, result);
Collection<QName> relationSpecifications = getRelationsParameter(action, input, context, result);
QName relationSpecification = MiscUtil.extractSingleton(relationSpecifications, () -> new IllegalArgumentException("Using 'relation' as a multivalued parameter is not allowed"));
if (PrismConstants.Q_ANY.matches(relationSpecification)) {
throw new IllegalArgumentException("Using 'q:any' as relation specification is not allowed");
}
QName relationOverride;
if (relationSpecification != null) {
List<RelationDefinitionType> relationDefinitions = relationRegistry.getRelationDefinitions();
relationOverride = relationDefinitions.stream().filter(definition -> prismContext.relationMatches(relationSpecification, definition.getRef())).findFirst().orElseThrow(() -> new IllegalArgumentException("Relation matching '" + relationSpecification + "' not found")).getRef();
} else {
relationOverride = null;
}
// Static parameters
Collection<ObjectReferenceType> staticTargetRefs;
Collection<ObjectReferenceType> staticResourceRefs;
Collection<ConstructionType> staticConstructions;
if (action instanceof AssignActionExpressionType) {
staticTargetRefs = ((AssignActionExpressionType) action).getTargetRef();
staticResourceRefs = ((AssignActionExpressionType) action).getResourceRef();
staticConstructions = ((AssignActionExpressionType) action).getConstruction();
} else {
staticTargetRefs = emptyList();
staticResourceRefs = emptyList();
staticConstructions = emptyList();
}
// Consolidation
Task task = context.getTask();
parameters.targetRefs.addAll(resolve(staticTargetRefs, relationOverride, task, result));
parameters.targetRefs.addAll(resolve(dynamicRoleRefs, relationOverride, task, result));
QName defaultRelation = relationRegistry.getDefaultRelation();
parameters.constructions.addAll(staticConstructions);
parameters.constructions.addAll(resourceRefsToConstructions(resolve(staticResourceRefs, defaultRelation, task, result)));
parameters.constructions.addAll(resourceRefsToConstructions(resolve(dynamicResourceRefs, defaultRelation, task, result)));
return parameters;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method fillinUserAssignmentAccountConstruction.
protected void fillinUserAssignmentAccountConstruction(PrismObject<UserType> user, String resourceOid) {
AssignmentType assignmentType = new AssignmentType();
ConstructionType accountConstruntion = new ConstructionType();
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.setOid(resourceOid);
resourceRef.setType(ResourceType.COMPLEX_TYPE);
accountConstruntion.setResourceRef(resourceRef);
accountConstruntion.setKind(ShadowKindType.ACCOUNT);
assignmentType.setConstruction(accountConstruntion);
user.asObjectable().getAssignment().add(assignmentType);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class TestConsistencyMechanism method test511AssignAccountMorgan.
/**
* assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
* account should be linked to the user.
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
// GIVEN
openDJController.assumeRunning();
Task task = getTestTask();
OperationResult result = task.getResult();
dummyAuditService.clear();
// prepare new OU in opendj
openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILE);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(prismContext.xnodeFactory().primitive("uid=morgan,ou=users,dc=example,dc=com").frozen(), prismContext);
JAXBElement<?> val = of.createValue(raw);
expression.getExpressionEvaluator().add(val);
MappingType mapping = new MappingType();
mapping.setExpression(expression);
ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
attrDefType.setRef(new ItemPathType(ItemPath.create(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo, prismContext));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
// noinspection unchecked
ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object().createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
when();
modelService.executeChanges(deltas, null, task, result);
// THEN
then();
result.computeStatus();
// assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
provisioningService.applyDefinition(accountShadow, task, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertShadowModel(accountModel, accountOid, "uid=morgan,ou=users,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute<?> attributes = ShadowUtil.getAttribute(accountModel, new QName(MidPointConstants.NS_RI, "uid"));
assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class AssignmentAsserter method assertResource.
public AssignmentAsserter<R> assertResource(String expectedOid) {
ConstructionType construction = assignment.getConstruction();
assertThat(construction).as("construction in " + desc()).isNotNull();
assertThat(construction.getResourceRef()).as("resourceRef in construction in " + desc()).isNotNull();
assertThat(construction.getResourceRef().getOid()).as("resource OID in construction in " + desc()).isEqualTo(expectedOid);
return this;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType in project midpoint by Evolveum.
the class QAssignmentMapping method insert.
// about duplication see the comment in QObjectMapping.toRowObjectWithoutFullObject
@SuppressWarnings("DuplicatedCode")
@Override
public MAssignment insert(AssignmentType assignment, OR ownerRow, JdbcSession jdbcSession) {
MAssignment row = initRowObject(assignment, ownerRow);
row.lifecycleState = assignment.getLifecycleState();
row.orderValue = assignment.getOrder();
setReference(assignment.getOrgRef(), o -> row.orgRefTargetOid = o, t -> row.orgRefTargetType = t, r -> row.orgRefRelationId = r);
setReference(assignment.getTargetRef(), o -> row.targetRefTargetOid = o, t -> row.targetRefTargetType = t, r -> row.targetRefRelationId = r);
setReference(assignment.getTenantRef(), o -> row.tenantRefTargetOid = o, t -> row.tenantRefTargetType = t, r -> row.tenantRefRelationId = r);
row.policySituations = processCacheableUris(assignment.getPolicySituation());
row.subtypes = stringsToArray(assignment.getSubtype());
row.ext = processExtensions(assignment.getExtension(), MExtItemHolderType.EXTENSION);
ConstructionType construction = assignment.getConstruction();
if (construction != null) {
setReference(construction.getResourceRef(), o -> row.resourceRefTargetOid = o, t -> row.resourceRefTargetType = t, r -> row.resourceRefRelationId = r);
}
ActivationType activation = assignment.getActivation();
if (activation != null) {
row.administrativeStatus = activation.getAdministrativeStatus();
row.effectiveStatus = activation.getEffectiveStatus();
row.enableTimestamp = MiscUtil.asInstant(activation.getEnableTimestamp());
row.disableTimestamp = MiscUtil.asInstant(activation.getDisableTimestamp());
row.disableReason = activation.getDisableReason();
row.validityStatus = activation.getValidityStatus();
row.validFrom = MiscUtil.asInstant(activation.getValidFrom());
row.validTo = MiscUtil.asInstant(activation.getValidTo());
row.validityChangeTimestamp = MiscUtil.asInstant(activation.getValidityChangeTimestamp());
row.archiveTimestamp = MiscUtil.asInstant(activation.getArchiveTimestamp());
}
MetadataType metadata = assignment.getMetadata();
if (metadata != null) {
setReference(metadata.getCreatorRef(), o -> row.creatorRefTargetOid = o, t -> row.creatorRefTargetType = t, r -> row.creatorRefRelationId = r);
row.createChannelId = processCacheableUri(metadata.getCreateChannel());
row.createTimestamp = MiscUtil.asInstant(metadata.getCreateTimestamp());
setReference(metadata.getModifierRef(), o -> row.modifierRefTargetOid = o, t -> row.modifierRefTargetType = t, r -> row.modifierRefRelationId = r);
row.modifyChannelId = processCacheableUri(metadata.getModifyChannel());
row.modifyTimestamp = MiscUtil.asInstant(metadata.getModifyTimestamp());
}
// insert before treating sub-entities
insert(row, jdbcSession);
if (metadata != null) {
storeRefs(row, metadata.getCreateApproverRef(), QAssignmentReferenceMapping.getForAssignmentCreateApprover(), jdbcSession);
storeRefs(row, metadata.getModifyApproverRef(), QAssignmentReferenceMapping.getForAssignmentModifyApprover(), jdbcSession);
}
return row;
}
Aggregations