use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class TestRoleEntitlement method test121ModifyRoleLinkEntitlement.
@Test
public void test121ModifyRoleLinkEntitlement() throws Exception {
final String TEST_NAME = "test121ModifyRoleLinkEntitlement";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestRoleEntitlement.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.POSITIVE);
dummyAuditService.clear();
prepareNotifications();
ObjectDelta<RoleType> roleDelta = ObjectDelta.createEmptyModifyDelta(RoleType.class, ROLE_PIRATE_OID, prismContext);
ReferenceDelta linkDelta = ReferenceDelta.createModificationAdd(RoleType.F_LINK_REF, getUserDefinition(), groupOid);
roleDelta.addModification(linkDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(roleDelta);
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
PrismObject<RoleType> role = getRole(ROLE_PIRATE_OID);
assertLinks(role, 1);
groupOid = getSingleLinkOid(role);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, groupOid, null, result);
assertDummyGroupShadowRepo(accountShadow, groupOid, GROUP_PIRATE_DUMMY_NAME);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, groupOid, null, task, result);
assertDummyGroupShadowModel(accountModel, groupOid, GROUP_PIRATE_DUMMY_NAME);
// Check group in dummy resource
assertDummyGroup(GROUP_PIRATE_DUMMY_NAME, "Scurvy pirates");
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(2);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, RoleType.class);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertTarget(ROLE_PIRATE_OID);
dummyAuditService.assertExecutionSuccess();
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class ObjectUpdater method createAddParentRefDelta.
private <T extends ObjectType> List<ReferenceDelta> createAddParentRefDelta(PrismObject<T> object) {
PrismReference parentOrgRef = object.findReference(ObjectType.F_PARENT_ORG_REF);
if (parentOrgRef == null || parentOrgRef.isEmpty()) {
return new ArrayList<>();
}
PrismObjectDefinition def = object.getDefinition();
ReferenceDelta delta = ReferenceDelta.createModificationAdd(new ItemPath(ObjectType.F_PARENT_ORG_REF), def, parentOrgRef.getClonedValues());
return Arrays.asList(delta);
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class ObjectUpdater method nonOverwriteAddObjectAttempt.
private <T extends ObjectType> String nonOverwriteAddObjectAttempt(PrismObject<T> object, RObject rObject, String originalOid, Session session, OrgClosureManager.Context closureContext) throws ObjectAlreadyExistsException, SchemaException, DtoTranslationException {
// check name uniqueness (by type)
if (StringUtils.isNotEmpty(originalOid)) {
LOGGER.trace("Checking oid uniqueness.");
//todo improve this table name bullshit
Class hqlType = ClassMapper.getHQLTypeClass(object.getCompileTimeClass());
SQLQuery query = session.createSQLQuery("select count(*) from " + RUtil.getTableName(hqlType) + " where oid=:oid");
query.setString("oid", object.getOid());
Number count = (Number) query.uniqueResult();
if (count != null && count.longValue() > 0) {
throw new ObjectAlreadyExistsException("Object '" + object.getCompileTimeClass().getSimpleName() + "' with oid '" + object.getOid() + "' already exists.");
}
}
updateFullObject(rObject, object);
LOGGER.trace("Saving object (non overwrite).");
String oid = (String) session.save(rObject);
lookupTableHelper.addLookupTableRows(session, rObject, false);
caseHelper.addCertificationCampaignCases(session, rObject, false);
if (closureManager.isEnabled()) {
Collection<ReferenceDelta> modifications = createAddParentRefDelta(object);
closureManager.updateOrgClosure(null, modifications, session, oid, object.getCompileTimeClass(), OrgClosureManager.Operation.ADD, closureContext);
}
return oid;
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class AddGetObjectTest method addGetSystemConfigFile.
@Test
public void addGetSystemConfigFile() throws Exception {
LOGGER.info("===[ addGetPasswordPolicy ]===");
File file = new File(FOLDER_BASIC, "password-policy.xml");
PrismObject<ValuePolicyType> filePasswordPolicy = prismContext.parseObject(new File(FOLDER_BASIC, "password-policy.xml"));
OperationResult result = new OperationResult("ADD");
String pwdPolicyOid = "00000000-0000-0000-0000-000000000003";
String oid = repositoryService.addObject(filePasswordPolicy, null, result);
AssertJUnit.assertNotNull(oid);
AssertJUnit.assertEquals(pwdPolicyOid, oid);
PrismObject<ValuePolicyType> repoPasswordPolicy = repositoryService.getObject(ValuePolicyType.class, oid, null, result);
AssertJUnit.assertNotNull(repoPasswordPolicy);
String systemCongigOid = "00000000-0000-0000-0000-000000000001";
PrismObject<SystemConfigurationType> fileSystemConfig = prismContext.parseObject(new File(FOLDER_BASIC, "systemConfiguration.xml"));
LOGGER.info("System config from file: {}", fileSystemConfig.debugDump());
oid = repositoryService.addObject(fileSystemConfig, null, result);
AssertJUnit.assertNotNull(oid);
AssertJUnit.assertEquals(systemCongigOid, oid);
PrismObject<SystemConfigurationType> repoSystemConfig = repositoryService.getObject(SystemConfigurationType.class, systemCongigOid, null, result);
// AssertJUnit.assertNotNull("global password policy null", repoSystemConfig.asObjectable().getGlobalPasswordPolicy());
LOGGER.info("System config from repo: {}", repoSystemConfig.debugDump());
AssertJUnit.assertNull("global password policy not null", repoSystemConfig.asObjectable().getGlobalPasswordPolicyRef());
ReferenceDelta refDelta = ReferenceDelta.createModificationAdd(SystemConfigurationType.F_GLOBAL_PASSWORD_POLICY_REF, repoSystemConfig.getDefinition(), PrismReferenceValue.createFromTarget(repoPasswordPolicy));
List<ReferenceDelta> refDeltas = new ArrayList<ReferenceDelta>();
refDeltas.add(refDelta);
repositoryService.modifyObject(SystemConfigurationType.class, systemCongigOid, refDeltas, result);
repoSystemConfig = repositoryService.getObject(SystemConfigurationType.class, systemCongigOid, null, result);
LOGGER.info("system config after modify: {}", repoSystemConfig.debugDump());
AssertJUnit.assertNotNull("global password policy null", repoSystemConfig.asObjectable().getGlobalPasswordPolicyRef());
AssertJUnit.assertNull("default user template not null", repoSystemConfig.asObjectable().getDefaultUserTemplateRef());
}
use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.
the class AbstractConfiguredModelIntegrationTest method clearUserOrgAndRoleRefs.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void clearUserOrgAndRoleRefs(String userOid) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
OperationResult result = new OperationResult("clearUserOrgAndRoleRefs");
Collection modifications = new ArrayList<>();
ReferenceDelta parentOrgRefDelta = ReferenceDelta.createModificationReplace(UserType.F_PARENT_ORG_REF, getUserDefinition(), (PrismReferenceValue) null);
modifications.add(parentOrgRefDelta);
ReferenceDelta roleMembershipRefDelta = ReferenceDelta.createModificationReplace(UserType.F_ROLE_MEMBERSHIP_REF, getUserDefinition(), (PrismReferenceValue) null);
modifications.add(roleMembershipRefDelta);
repositoryService.modifyObject(UserType.class, userOid, modifications, result);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userBefore = getUser(userOid);
display("User before", userBefore);
}
Aggregations