Search in sources :

Example 46 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class AccCertUpdateHelper method addObjectPreAuthorized.

// endregion
// region ================================ Model and repository operations ================================
void addObjectPreAuthorized(ObjectType objectType, Task task, OperationResult result) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
    ObjectDelta<? extends ObjectType> objectDelta = DeltaFactory.Object.createAddDelta(objectType.asPrismObject());
    Collection<ObjectDeltaOperation<? extends ObjectType>> ops;
    try {
        ops = modelService.executeChanges(singleton(objectDelta), ModelExecuteOptions.create(prismContext).raw().preAuthorized(), task, result);
    } catch (ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
        throw new SystemException("Unexpected exception when adding object: " + e.getMessage(), e);
    }
    ObjectDeltaOperation odo = ops.iterator().next();
    objectType.setOid(odo.getObjectDelta().getOid());
/* ALTERNATIVELY, we can go directly into the repository. (No audit there.)
        String oid = repositoryService.addObject(objectType.asPrismObject(), null, result);
        objectType.setOid(oid);
         */
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation)

Example 47 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class TestAssignmentErrors method test101AddUserCharlesAssignBlankAccount.

/**
 * The "while" resource has no outbound mapping and there is also no mapping in the assignment. Therefore
 * this results in account without any attributes. It should fail.
 */
@Test
public void test101AddUserCharlesAssignBlankAccount() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    dummyAuditService.clear();
    PrismObject<UserType> userCharles = createUser("charles", "Charles L. Charles");
    fillinUserAssignmentAccountConstruction(userCharles, RESOURCE_DUMMY_WHITE_OID);
    ObjectDelta<UserType> userDelta = DeltaFactory.Object.createAddDelta(userCharles);
    // WHEN
    when();
    // we do not expect this to throw an exception. instead the fatal error in the result is excpected
    Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = executeChanges(userDelta, null, task, result);
    // THEN
    then();
    assertFailure(result);
    // Even though the operation failed the addition of a user should be successful. Let's check if user was really added.
    String userOid = ObjectDeltaOperation.findFocusDeltaOidInCollection(executedChanges);
    assertNotNull("No user OID in delta after operation", userOid);
    PrismObject<UserType> userAfter = getUser(userOid);
    assertUser(userAfter, userOid, "charles", "Charles L. Charles", null, null, null);
    // Check audit
    displayDumpable("Audit", dummyAuditService);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionOutcome(OperationResultStatus.PARTIAL_ERROR);
    dummyAuditService.assertExecutionMessage();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 48 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class LensObjectDeltaOperation method fromLensObjectDeltaOperationType.

static LensObjectDeltaOperation fromLensObjectDeltaOperationType(LensObjectDeltaOperationType jaxb) throws SchemaException {
    ObjectDeltaOperation odo = DeltaConvertor.createObjectDeltaOperation(jaxb.getObjectDeltaOperation(), PrismContext.get());
    LensObjectDeltaOperation retval = new LensObjectDeltaOperation();
    retval.setObjectDelta(odo.getObjectDelta());
    retval.setExecutionResult(odo.getExecutionResult());
    retval.setAudited(jaxb.isAudited());
    return retval;
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation)

Example 49 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class TestModelServiceContract method test191ModifyUserJackModifyAssignment.

/**
 * We try to modify an assignment of the account and see whether changes will be recorded in the account itself.
 *
 * We also check the metadata.channel migration for both the object and the assignment (MID-6547).
 */
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
    PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
    ResourceSchema refinedSchema = ResourceSchemaFactory.getCompleteSchema(dummyResource);
    // This explicitly parses the schema, therefore ...
    assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 1);
    ResourceObjectTypeDefinition accountDefinition = refinedSchema.findObjectTypeDefinitionRequired(ShadowKindType.ACCOUNT, null);
    PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new ItemName("http://midpoint.evolveum.com/xml/ns/public/resource/instance-3", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME));
    assertNotNull("gossip attribute definition not found", gossipDefinition);
    ConstructionType accountConstruction = createAccountConstruction(RESOURCE_DUMMY_OID, null);
    ResourceAttributeDefinitionType radt = new ResourceAttributeDefinitionType();
    radt.setRef(new ItemPathType(gossipDefinition.getItemName()));
    MappingType outbound = new MappingType();
    radt.setOutbound(outbound);
    ExpressionType expression = new ExpressionType();
    outbound.setExpression(expression);
    MappingType value = new MappingType();
    // noinspection unchecked
    PrismProperty<String> property = gossipDefinition.instantiate();
    property.addRealValue("q");
    List evaluators = expression.getExpressionEvaluator();
    Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property);
    ObjectFactory of = new ObjectFactory();
    for (JAXBElement<RawType> obj : collection) {
        // noinspection unchecked
        evaluators.add(of.createValue(obj.getValue()));
    }
    value.setExpression(expression);
    radt.setOutbound(value);
    accountConstruction.getAttribute().add(radt);
    PrismObject<UserType> jackBefore = getUserFromRepo(USER_JACK_OID);
    assertEquals("Wrong # of assignments", 1, jackBefore.asObjectable().getAssignment().size());
    Long assignmentId = jackBefore.asObjectable().getAssignment().get(0).getId();
    ObjectDelta<UserType> accountAssignmentUserDelta = createReplaceAccountConstructionUserDelta(USER_JACK_OID, assignmentId, accountConstruction);
    deltas.add(accountAssignmentUserDelta);
    // Set user and assignment create channel to legacy value.
    repositoryService.modifyObject(UserType.class, jackBefore.getOid(), deltaFor(UserType.class).item(UserType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace(Channel.USER.getLegacyUri()).item(UserType.F_ASSIGNMENT, assignmentId, AssignmentType.F_METADATA, MetadataType.F_CREATE_CHANNEL).replace(Channel.USER.getLegacyUri()).asItemDeltas(), result);
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
    display("User before change execution", userJackOld);
    display("Deltas to execute execution", deltas);
    when();
    modelService.executeChanges(deltas, null, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    // First fetch: initial account read
    // Second fetch: fetchback after modification to correctly process inbound
    assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 2);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after change execution", userJack);
    assertUserJack(userJack, "Jack Sparrow");
    accountJackOid = getSingleLinkOid(userJack);
    // MID-6547 (channel URI migration)
    assertThat(userJack.asObjectable().getMetadata().getCreateChannel()).isEqualTo(Channel.USER.getUri());
    assertThat(userJack.asObjectable().getAssignment().get(0).getMetadata().getCreateChannel()).isEqualTo(Channel.USER.getUri());
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, SelectorOptions.createCollection(GetOperationOptions.createRaw()), result);
    assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
    // Check account in dummy resource
    assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
    DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
    display(dummyAccount.debugDump());
    assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "q");
    assertDummyScriptsModify(userJack, true);
    // Check audit
    displayDumpable("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecutionDeltas = dummyAuditService.getExecutionDeltas();
    assertEquals("Wrong number of execution deltas", 2, auditExecutionDeltas.size());
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    assertCounterIncrement(InternalCounters.SCRIPT_COMPILE_COUNT, 0);
    assertSteadyResources();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) List(java.util.List) ArrayList(java.util.ArrayList) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) JAXBElement(javax.xml.bind.JAXBElement) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) Test(org.testng.annotations.Test)

Example 50 with ObjectDeltaOperation

use of com.evolveum.midpoint.schema.ObjectDeltaOperation in project midpoint by Evolveum.

the class AuditCleanupPerformanceTest method createObjectDeltaOperation.

private ObjectDeltaOperation<UserType> createObjectDeltaOperation(int i) throws Exception {
    ObjectDelta<UserType> delta = prismContext.deltaFor(UserType.class).item(UserType.F_DESCRIPTION).replace("d" + i).asObjectDeltaCast("oid-" + i);
    ObjectDeltaOperation<UserType> odo = new ObjectDeltaOperation<>();
    odo.setObjectDelta(delta);
    odo.setExecutionResult(new OperationResult("asdf"));
    return odo;
}
Also used : ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)51 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)24 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)15 Task (com.evolveum.midpoint.task.api.Task)12 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)11 Test (org.testng.annotations.Test)11 ArrayList (java.util.ArrayList)9 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 ModelService (com.evolveum.midpoint.model.api.ModelService)3 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 CommonException (com.evolveum.midpoint.util.exception.CommonException)3 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2