Search in sources :

Example 21 with ReferenceDelta

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 22 with ReferenceDelta

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);
}
Also used : PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) PrismReference(com.evolveum.midpoint.prism.PrismReference) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with ReferenceDelta

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;
}
Also used : ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) SQLQuery(org.hibernate.SQLQuery) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 24 with ReferenceDelta

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());
}
Also used : ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 25 with ReferenceDelta

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);
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)49 Task (com.evolveum.midpoint.task.api.Task)44 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)42 Test (org.testng.annotations.Test)41 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)33 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)29 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)29 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)27 Collection (java.util.Collection)21 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)12 ArrayList (java.util.ArrayList)12 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)11 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6