Search in sources :

Example 16 with COMPLETE

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.

the class ResourceProtectedEditor method initLayout.

protected void initLayout(final PageResourceWizard parentPage) {
    WebMarkupContainer container = new WebMarkupContainer(ID_CONTAINER);
    container.setOutputMarkupId(true);
    add(container);
    ListView repeater = new ListView<ResourceObjectPatternType>(ID_REPEATER, getModel()) {

        @Override
        protected void populateItem(final ListItem<ResourceObjectPatternType> item) {
            WebMarkupContainer linkCont = new WebMarkupContainer(ID_ACCOUNT_LINK);
            linkCont.setOutputMarkupId(true);
            linkCont.add(new AttributeModifier("href", createCollapseItemId(item, true)));
            item.add(linkCont);
            Label accountLabel = new Label(ID_ACCOUNT_NAME, new IModel<String>() {

                @Override
                public String getObject() {
                    StringBuilder sb = new StringBuilder();
                    ResourceObjectPatternType account = item.getModelObject();
                    sb.append("#").append(item.getIndex() + 1).append(" - ");
                    return sb.toString();
                }
            });
            linkCont.add(accountLabel);
            AjaxLink<Void> delete = new AjaxLink<Void>(ID_BUTTON_DELETE) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    deleteProtectedAccountPerformed(target, item);
                }
            };
            parentPage.addEditingVisibleBehavior(delete);
            linkCont.add(delete);
            WebMarkupContainer accountBody = new WebMarkupContainer(ID_ACCOUNT_BODY);
            accountBody.setOutputMarkupId(true);
            accountBody.setMarkupId(createCollapseItemId(item, false).getObject());
            if (changeState != ChangeState.SKIP) {
                accountBody.add(new AttributeModifier("class", new IModel<String>() {

                    @Override
                    public String getObject() {
                        if (changeState == ChangeState.FIRST && item.getIndex() == 0) {
                            return "panel-collapse collapse in";
                        } else if (changeState == ChangeState.LAST && item.getIndex() == (getModelObject().size() - 1)) {
                            return "panel-collapse collapse in";
                        } else {
                            return "panel-collapse collapse";
                        }
                    }
                }));
            }
            item.add(accountBody);
            // TODO - maybe add some validator and auto-complete functionality?
            TextField name = new TextField<>(ID_NAME, new PropertyModel<String>(item.getModel(), "name"));
            name.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            parentPage.addEditingEnabledBehavior(name);
            accountBody.add(name);
            // TODO - maybe add some validator and auto-complete functionality?
            TextField uid = new TextField<>(ID_UID, new PropertyModel<String>(item.getModel(), "uid"));
            uid.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            parentPage.addEditingEnabledBehavior(uid);
            accountBody.add(uid);
            SearchFilterPanel searchFilterPanel = new SearchFilterPanel<>(ID_FILTER_EDITOR, new NonEmptyPropertyModel<>(item.getModel(), "filter"), parentPage.getReadOnlyModel());
            accountBody.add(searchFilterPanel);
            Label nameTooltip = new Label(ID_T_NAME);
            nameTooltip.add(new InfoTooltipBehavior());
            accountBody.add(nameTooltip);
            Label uidTooltip = new Label(ID_T_UID);
            uidTooltip.add(new InfoTooltipBehavior());
            accountBody.add(uidTooltip);
            Label filterTooltip = new Label(ID_T_FILTER);
            filterTooltip.add(new InfoTooltipBehavior());
            accountBody.add(filterTooltip);
        }
    };
    repeater.setOutputMarkupId(true);
    container.add(repeater);
    AjaxLink<Void> add = new AjaxLink<Void>(ID_BUTTON_ADD) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            addProtectedAccountPerformed(target);
        }
    };
    parentPage.addEditingVisibleBehavior(add);
    add(add);
}
Also used : IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) ResourceObjectPatternType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectPatternType) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) ListView(org.apache.wicket.markup.html.list.ListView) TextField(org.apache.wicket.markup.html.form.TextField) ListItem(org.apache.wicket.markup.html.list.ListItem) SearchFilterPanel(com.evolveum.midpoint.web.component.input.SearchFilterPanel) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 17 with COMPLETE

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.

the class ManualResourceTest method test110CloseCaseAndRecomputeWill.

/**
 * Case is closed. The operation is complete.
 */
@Test
public void test110CloseCaseAndRecomputeWill() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    dummyAuditService.clear();
    dummyTransport.clearMessages();
    // WHEN
    when();
    CaseType caseBefore = getCase(willLastCaseOid);
    display("Case before work item completion", caseBefore);
    List<CaseWorkItemType> workItems = caseBefore.getWorkItem();
    assertEquals("Wrong # of work items", 2, workItems.size());
    assertEquals("Wrong assignees", new HashSet<>(Arrays.asList(USER_ADMINISTRATOR_OID, userJackOid)), workItems.stream().map(wi -> wi.getOriginalAssigneeRef().getOid()).collect(Collectors.toSet()));
    Optional<CaseWorkItemType> adminWorkItem = workItems.stream().filter(wi -> USER_ADMINISTRATOR_OID.equals(wi.getOriginalAssigneeRef().getOid())).findAny();
    assertTrue("no admin work item", adminWorkItem.isPresent());
    caseManager.completeWorkItem(WorkItemId.of(adminWorkItem.get()), new AbstractWorkItemOutputType(prismContext).outcome(OperationResultStatusType.SUCCESS.value()), null, task, result);
    accountWillCompletionTimestampStart = clock.currentTimeXMLGregorianCalendar();
    // We need reconcile and not recompute here. We need to fetch the updated case status.
    reconcileUser(userWillOid, task, result);
    // THEN
    then();
    assertSuccess(result);
    CaseType caseAfter = getCase(willLastCaseOid);
    display("Case after work item completion", caseAfter);
    accountWillCompletionTimestampEnd = clock.currentTimeXMLGregorianCalendar();
    assertWillAfterCreateCaseClosed();
    displayDumpable("dummy audit", dummyAuditService);
    displayDumpable("dummy transport", dummyTransport);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) AssertJUnit(org.testng.AssertJUnit) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) ShadowAsserter(com.evolveum.midpoint.test.asserter.ShadowAsserter) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) AbstractWfTest(com.evolveum.midpoint.wf.impl.AbstractWfTest) HashSet(java.util.HashSet) IntegrationTestTools(com.evolveum.midpoint.test.IntegrationTestTools) TestUtil(com.evolveum.midpoint.test.util.TestUtil) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) File(java.io.File) WorkItemId(com.evolveum.midpoint.schema.util.WorkItemId) List(java.util.List) MidPointConstants(com.evolveum.midpoint.schema.constants.MidPointConstants) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) QName(javax.xml.namespace.QName) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractWfTest(com.evolveum.midpoint.wf.impl.AbstractWfTest)

Example 18 with COMPLETE

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.

the class TestBucketingStatic method test210GetReleaseCompleteSequenceForWorkers.

/**
 * Check a sequence of get / release / complete operations on coordinator + 5 worker tasks.
 */
@Test
public void test210GetReleaseCompleteSequenceForWorkers() throws Exception {
    OperationResult result = createOperationResult();
    // suspended
    taskAdd(TASK_210_COORDINATOR, result);
    // suspended
    taskAdd(TASK_210_WORKER_1, result);
    // suspended
    taskAdd(TASK_210_WORKER_2, result);
    // suspended
    taskAdd(TASK_210_WORKER_3, result);
    // suspended
    taskAdd(TASK_210_WORKER_4, result);
    // suspended
    taskAdd(TASK_210_WORKER_5, result);
    Task coordinator = taskManager.getTaskPlain(TASK_210_COORDINATOR.oid, result);
    String oidC = TASK_210_COORDINATOR.oid;
    String oidW1 = TASK_210_WORKER_1.oid;
    String oidW2 = TASK_210_WORKER_2.oid;
    String oidW3 = TASK_210_WORKER_3.oid;
    String oidW4 = TASK_210_WORKER_4.oid;
    String oidW5 = TASK_210_WORKER_5.oid;
    when();
    WorkBucketType bucket1 = getWorkBucket(coordinator, oidW1, result);
    WorkBucketType bucket2 = getWorkBucket(coordinator, oidW2, result);
    WorkBucketType bucket3 = getWorkBucket(coordinator, oidW3, result);
    WorkBucketType bucket4 = getWorkBucket(coordinator, oidW4, result);
    // should be the same as bucket4 (the same worker)
    WorkBucketType bucket4a = getWorkBucket(coordinator, oidW4, result);
    then();
    displayValue("1st allocated bucket", bucket1);
    displayValue("2nd allocated bucket", bucket2);
    displayValue("3rd allocated bucket", bucket3);
    displayValue("4th allocated bucket", bucket4);
    displayValue("4+th allocated bucket", bucket4a);
    coordinator.refresh(result);
    displayDumpable("coordinator task after 4+1x allocation", coordinator);
    assertNumericBucket(bucket1, null, 1, 0, 1);
    assertNumericBucket(bucket2, null, 2, 1, 2);
    assertNumericBucket(bucket3, null, 3, 2, 3);
    assertNumericBucket(bucket4, null, 4, 3, 4);
    assertNumericBucket(bucket4a, null, 4, 3, 4);
    List<WorkBucketType> buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(4, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 1, 0, 1);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 2, 1, 2);
    assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 3, 2, 3);
    assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 4, 3, 4);
    when("complete bucket #2");
    bucketingManager.completeWorkBucket(oidC, oidW2, ActivityPath.empty(), 2, null, null, result);
    then("complete bucket #2");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 2nd bucket", coordinator);
    buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(4, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 1, 0, 1);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 2, 1, 2);
    assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 3, 2, 3);
    assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 4, 3, 4);
    when("complete bucket #1");
    bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 1, null, null, result);
    WorkBucketType bucket = getWorkBucket(coordinator, oidW1, result);
    then("complete bucket #1");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 1st bucket and fetching next one", coordinator);
    assertNumericBucket(bucket, null, 5, 4, 5);
    buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(4, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 2, 1, 2);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 3, 2, 3);
    assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 4, 3, 4);
    assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 5, 4, 5);
    when("no more buckets");
    WorkBucketType nothing = getWorkBucket(coordinator, oidW5, result);
    then("no more buckets");
    assertNull("Found bucket even if none should be found", nothing);
    when("release bucket #4");
    bucketingManager.releaseWorkBucket(oidC, oidW4, ActivityPath.empty(), 4, null, result);
    then("release bucket #4");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after releasing of 4th bucket", coordinator);
    buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(4, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 2, 1, 2);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 3, 2, 3);
    assertNumericBucket(buckets.get(2), READY, 4, 3, 4);
    assertNumericBucket(buckets.get(3), WorkBucketStateType.DELEGATED, 5, 4, 5);
    when("complete bucket #3");
    bucketingManager.completeWorkBucket(oidC, oidW3, ActivityPath.empty(), 3, null, null, result);
    bucket = getWorkBucket(coordinator, oidW5, result);
    then("complete bucket #3");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 3rd bucket and getting next one", coordinator);
    assertNumericBucket(bucket, null, 4, 3, 4);
    buckets = new ArrayList<>(getBuckets(coordinator));
    sortBucketsBySequentialNumber(buckets);
    assertEquals(3, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 3, 2, 3);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.DELEGATED, 4, 3, 4);
    assertNumericBucket(buckets.get(2), WorkBucketStateType.DELEGATED, 5, 4, 5);
    when("complete bucket #5");
    bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 5, null, null, result);
    taskManager.closeTask(oidW5, result);
    then("complete bucket #5");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 5th bucket and closing worker5", coordinator);
    buckets = new ArrayList<>(getOrCreateBuckets(coordinator.getWorkState().getActivity()));
    assertEquals(2, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 4, 3, 4);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 5, 4, 5);
    when("reclaiming mis-allocated bucket");
    bucket = getWorkBucket(coordinator, oidW1, b -> b.withFreeBucketWaitTime(-1).withIsScavenger(true), result);
    assertThat(bucket).isNotNull();
    then("reclaiming mis-allocated bucket");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after reclaiming mis-allocated bucket", coordinator);
    assertNumericBucket(bucket, null, 4, 3, 4);
    buckets = new ArrayList<>(getBuckets(coordinator));
    assertEquals(2, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.DELEGATED, 4, 3, 4);
    assertNumericBucket(buckets.get(1), WorkBucketStateType.COMPLETE, 5, 4, 5);
    when("complete bucket #4");
    bucketingManager.completeWorkBucket(oidC, oidW1, ActivityPath.empty(), 4, null, null, result);
    then("complete bucket #4");
    coordinator = taskManager.getTaskPlain(coordinator.getOid(), result);
    displayDumpable("coordinator after completion of 4th bucket", coordinator);
    buckets = new ArrayList<>(getBuckets(coordinator));
    assertEquals(1, buckets.size());
    assertNumericBucket(buckets.get(0), WorkBucketStateType.COMPLETE, 5, 4, 5);
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) AssertJUnit(org.testng.AssertJUnit) Arrays(java.util.Arrays) CommonTaskBeans(com.evolveum.midpoint.repo.common.activity.run.CommonTaskBeans) ActivityPath(com.evolveum.midpoint.schema.util.task.ActivityPath) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) GetBucketOperationOptionsBuilder(com.evolveum.midpoint.repo.common.activity.run.buckets.GetBucketOperationOptions.GetBucketOperationOptionsBuilder) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) BucketingUtil(com.evolveum.midpoint.schema.util.task.BucketingUtil) DebugUtil(com.evolveum.midpoint.util.DebugUtil) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) BucketFactory(com.evolveum.midpoint.repo.common.activity.run.buckets.segmentation.BucketFactory) COMPLETE(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE) BucketingConfigurationOverrides(com.evolveum.midpoint.repo.common.activity.run.buckets.BucketingConfigurationOverrides) AbstractRepoCommonTest(com.evolveum.midpoint.repo.common.AbstractRepoCommonTest) PrismContext(com.evolveum.midpoint.prism.PrismContext) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ActivityDistributionDefinition(com.evolveum.midpoint.repo.common.activity.definition.ActivityDistributionDefinition) BucketingManager(com.evolveum.midpoint.repo.common.activity.run.buckets.BucketingManager) BucketContentFactory(com.evolveum.midpoint.repo.common.activity.run.buckets.segmentation.BucketContentFactory) PrismAsserts(com.evolveum.midpoint.prism.util.PrismAsserts) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) Task(com.evolveum.midpoint.task.api.Task) StringBucketContentFactory(com.evolveum.midpoint.repo.common.activity.run.buckets.segmentation.StringBucketContentFactory) File(java.io.File) Consumer(java.util.function.Consumer) List(java.util.List) TestResource(com.evolveum.midpoint.test.TestResource) READY(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.READY) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PostConstruct(javax.annotation.PostConstruct) BucketingUtil.sortBucketsBySequentialNumber(com.evolveum.midpoint.schema.util.task.BucketingUtil.sortBucketsBySequentialNumber) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) BucketContentFactoryGenerator(com.evolveum.midpoint.repo.common.activity.run.buckets.segmentation.BucketContentFactoryGenerator) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test) AbstractRepoCommonTest(com.evolveum.midpoint.repo.common.AbstractRepoCommonTest)

Example 19 with COMPLETE

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.

the class AuditServiceProxy method completeRecord.

/**
 * Complete the record with data that can be computed or discovered from the
 * environment
 */
private void completeRecord(AuditEventRecord record, Task task, OperationResult result) {
    LightweightIdentifier id = null;
    if (record.getEventIdentifier() == null) {
        id = lightweightIdentifierGenerator.generate();
        record.setEventIdentifier(id.toString());
    }
    if (record.getTimestamp() == null) {
        if (id == null) {
            record.setTimestamp(System.currentTimeMillis());
        } else {
            // To be consistent with the ID
            record.setTimestamp(id.getTimestamp());
        }
    }
    if (record.getTaskIdentifier() == null && task != null) {
        record.setTaskIdentifier(task.getTaskIdentifier());
    }
    if (record.getTaskOid() == null && task != null) {
        if (task instanceof RunningTask) {
            record.setTaskOid(((RunningTask) task).getRootTaskOid());
        } else {
            record.setTaskOid(task.getOid());
        }
    }
    if (record.getChannel() == null && task != null) {
        record.setChannel(task.getChannel());
    }
    if (record.getInitiatorRef() == null && task != null) {
        PrismObject<? extends FocusType> taskOwner = task.getOwner(result);
        record.setInitiator(taskOwner);
    }
    if (record.getNodeIdentifier() == null && taskManager != null) {
        record.setNodeIdentifier(taskManager.getNodeId());
    }
    HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    if (connInfo == null && securityContextManager != null) {
        connInfo = securityContextManager.getStoredConnectionInformation();
    }
    if (connInfo != null) {
        if (record.getSessionIdentifier() == null) {
            record.setSessionIdentifier(connInfo.getSessionId());
        }
        if (record.getRemoteHostAddress() == null) {
            record.setRemoteHostAddress(connInfo.getRemoteHostAddress());
        }
        if (record.getHostIdentifier() == null) {
            record.setHostIdentifier(connInfo.getLocalHostName());
        }
    }
    if (record.getSessionIdentifier() == null && task != null) {
        record.setSessionIdentifier(task.getTaskIdentifier());
    }
    for (ObjectDeltaOperation<? extends ObjectType> objectDeltaOperation : record.getDeltas()) {
        ObjectDelta<? extends ObjectType> delta = objectDeltaOperation.getObjectDelta();
        // currently this does not work as expected (retrieves all default items)
        Collection<SelectorOptions<GetOperationOptions>> nameOnlyOptions = schemaService.getOperationOptionsBuilder().item(ObjectType.F_NAME).retrieve().build();
        ObjectDeltaSchemaLevelUtil.NameResolver nameResolver = (objectClass, oid) -> {
            if (record.getNonExistingReferencedObjects().contains(oid)) {
                // save a useless getObject call plus associated warning (MID-5378)
                return null;
            }
            if (repositoryService == null) {
                LOGGER.warn("No repository, no OID resolution (for {})", oid);
                return null;
            }
            LOGGER.warn("Unresolved object reference in delta being audited (for {}: {}) -- this might indicate " + "a performance problem, as these references are normally resolved using repository cache", objectClass.getSimpleName(), oid);
            PrismObject<? extends ObjectType> object = repositoryService.getObject(objectClass, oid, nameOnlyOptions, new OperationResult(AuditServiceProxy.class.getName() + ".completeRecord.resolveName"));
            return object.getName();
        };
        resolveNames(delta, nameResolver, prismContext);
    }
}
Also used : com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectDeltaSchemaLevelUtil.resolveNames(com.evolveum.midpoint.schema.util.ObjectDeltaSchemaLevelUtil.resolveNames) ArrayList(java.util.ArrayList) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) AuditServiceRegistry(com.evolveum.midpoint.audit.spi.AuditServiceRegistry) SystemConfigurationAuditType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationAuditType) PrismContext(com.evolveum.midpoint.prism.PrismContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) AuditService(com.evolveum.midpoint.audit.api.AuditService) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Collection(java.util.Collection) ObjectDeltaSchemaLevelUtil(com.evolveum.midpoint.schema.util.ObjectDeltaSchemaLevelUtil) PrismObject(com.evolveum.midpoint.prism.PrismObject) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) SecurityUtil(com.evolveum.midpoint.security.api.SecurityUtil) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) com.evolveum.midpoint.task.api(com.evolveum.midpoint.task.api) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) ObjectDeltaSchemaLevelUtil(com.evolveum.midpoint.schema.util.ObjectDeltaSchemaLevelUtil)

Example 20 with COMPLETE

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.

the class LiveSynchronizer method updateTokenValue.

private void updateTokenValue(LiveSyncCtx ctx, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, ConfigurationException, CommunicationException, ObjectAlreadyExistsException {
    LiveSyncCapabilityType capability = ctx.context.getEffectiveCapability(LiveSyncCapabilityType.class);
    boolean preciseTokenValue = capability != null && isTrue(capability.isPreciseTokenValue());
    boolean isDryRun = ctx.isDryRun();
    boolean updateTokenInDryRun = ctx.isUpdateLiveSyncTokenInDryRun();
    LiveSyncToken initialToken = ctx.getInitialToken();
    LiveSyncToken oldestTokenProcessed = ctx.oldestTokenWatcher.getOldestTokenProcessed();
    LOGGER.trace("oldestTokenProcessed = {}, synchronization result = {}", oldestTokenProcessed, ctx.syncResult);
    LiveSyncToken tokenToSet;
    if (ctx.isPreview()) {
        LOGGER.trace("Preview mode -> token will not be updated.");
        tokenToSet = null;
    } else if (isDryRun && !updateTokenInDryRun) {
        LOGGER.trace("Dry run mode with updateTokenInDryRun=false -> token will not be updated.");
        tokenToSet = null;
    } else if (ctx.canRun() && ctx.syncResult.isAllChangesFetched() && ctx.syncResult.isAllFetchedChangesProcessed()) {
        tokenToSet = ctx.finalToken != null ? ctx.finalToken : oldestTokenProcessed;
        LOGGER.trace("All changes fetched and processed (positively acknowledged). " + "Task is not suspended. Updating token to {}", tokenToSet);
    // Note that it is theoretically possible that tokenToSet is null here: it happens when no changes are fetched from
    // the resource and the connector returns null from .sync() method. But in this case nothing wrong happens: the
    // token in task will simply stay as it is. That's the correct behavior for such a case.
    } else if (preciseTokenValue) {
        LOGGER.trace("Processing is not complete but we can count on precise token values.");
        tokenToSet = oldestTokenProcessed;
        LOGGER.info("Capability of providing precise token values is present. Token in task is updated so the processing will " + "continue where it was stopped. New token value is '{}' (initial value was '{}')", SchemaDebugUtil.prettyPrint(tokenToSet), SchemaDebugUtil.prettyPrint(initialToken));
    } else {
        LOGGER.trace("Processing is not complete and we cannot count on precise token values. So we'll not update the token");
        tokenToSet = null;
        LOGGER.info("Capability of providing precise token values is NOT present. Token will not be updated so the " + "processing will restart from the beginning at next task run. So token value stays as it was: '{}'", SchemaDebugUtil.prettyPrint(initialToken));
    }
    if (tokenToSet != null) {
        LOGGER.trace("Setting token value of {}", SchemaDebugUtil.prettyPrintLazily(tokenToSet));
        ctx.tokenStorage.setToken(tokenToSet, result);
        ctx.syncResult.setTokenUpdatedTo(tokenToSet);
    }
}
Also used : LiveSyncToken(com.evolveum.midpoint.provisioning.api.LiveSyncToken) LiveSyncCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.LiveSyncCapabilityType)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)25 Test (org.testng.annotations.Test)21 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)14 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)13 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)12 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)11 Task (com.evolveum.midpoint.task.api.Task)11 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)9 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)9 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)9 Holder (javax.xml.ws.Holder)9 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)8 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)7 Element (org.w3c.dom.Element)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)5 List (java.util.List)5