Search in sources :

Example 26 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class SearchShadowOwnerTest method searchShadowOwner.

@Test
public void searchShadowOwner() throws Exception {
    OperationResult result = new OperationResult("List owner");
    //look for account owner
    PrismObject<UserType> user = repositoryService.searchShadowOwner("11223344", null, result);
    assertNotNull("No owner for account", user);
    PrismProperty name = user.findProperty(ObjectType.F_NAME);
    AssertJUnit.assertNotNull(name);
    AssertJUnit.assertEquals("atestuserX00003", ((PolyString) name.getRealValue()).getOrig());
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 27 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class AbstractOrgClosureTest method addExtensionProperty.

protected void addExtensionProperty(PrismObject object, String name, Object value) throws SchemaException {
    String NS = "http://example.com/p";
    PrismProperty p = object.findOrCreateProperty(new ItemPath(UserType.F_EXTENSION, new QName(NS, name)));
    p.setRealValue(value);
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) QName(javax.xml.namespace.QName) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 28 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class MockSingleTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    LOGGER.info("MockSingle.run starting (id = " + id + ")");
    long progress = task.getProgress();
    OperationResult opResult = new OperationResult(MockSingleTaskHandler.class.getName() + ".run");
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    // TODO
    progress++;
    opResult.recordSuccess();
    // This "run" is finished. But the task goes on ...
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    runResult.setProgress(progress);
    hasRun = true;
    if ("L1".equals(id)) {
        PrismProperty<Boolean> l1flag = task.getExtensionProperty(L1_FLAG_QNAME);
        if (l1flag == null || l1flag.getRealValue() == false) {
            LOGGER.info("L1 handler, first run - scheduling L2 handler");
            ScheduleType l2Schedule = new ScheduleType();
            l2Schedule.setInterval(2);
            task.pushHandlerUri(TestQuartzTaskManagerContract.L2_TASK_HANDLER_URI, l2Schedule, TaskBinding.TIGHT, ((TaskQuartzImpl) task).createExtensionDelta(l1FlagDefinition, true));
            try {
                task.savePendingModifications(opResult);
            } catch (Exception e) {
                throw new SystemException("Cannot schedule L2 handler", e);
            }
            runResult.setRunResultStatus(TaskRunResultStatus.RESTART_REQUESTED);
        } else {
            LOGGER.info("L1 handler, not the first run (progress = " + progress + ", l1Flag = " + l1flag.getRealValue() + "), exiting.");
        }
    } else if ("L2".equals(id)) {
        if (progress == 5) {
            LOGGER.info("L2 handler, fourth run - scheduling L3 handler");
            task.pushHandlerUri(TestQuartzTaskManagerContract.L3_TASK_HANDLER_URI, new ScheduleType(), null);
            try {
                task.savePendingModifications(opResult);
            } catch (Exception e) {
                throw new SystemException("Cannot schedule L3 handler", e);
            }
            runResult.setRunResultStatus(TaskRunResultStatus.RESTART_REQUESTED);
        } else if (progress < 5) {
            LOGGER.info("L2 handler, progress = " + progress + ", continuing.");
        } else if (progress > 5) {
            LOGGER.info("L2 handler, progress too big, i.e. " + progress + ", exiting.");
            try {
                ((TaskQuartzImpl) task).finishHandler(opResult);
            } catch (Exception e) {
                throw new SystemException("Cannot finish L2 handler", e);
            }
        }
    } else if ("L3".equals(id)) {
        LOGGER.info("L3 handler, simply exiting. Progress = " + progress);
    } else if ("WFS".equals(id)) {
        PrismProperty<Boolean> wfsFlag = task.getExtensionProperty(WFS_FLAG_QNAME);
        if (wfsFlag == null || wfsFlag.getRealValue() == false) {
            LOGGER.info("Wait-for-subtasks creating subtasks...");
            Task t1 = task.createSubtask();
            t1.setHandlerUri(TestQuartzTaskManagerContract.L3_TASK_HANDLER_URI);
            taskManager.switchToBackground(t1, opResult);
            Task t2 = task.createSubtask();
            t2.setHandlerUri(TestQuartzTaskManagerContract.SINGLE_TASK_HANDLER_URI);
            taskManager.switchToBackground(t2, opResult);
            try {
                ArrayList<ItemDelta<?, ?>> deltas = new ArrayList<>();
                deltas.add(((TaskQuartzImpl) task).createExtensionDelta(wfsFlagDefinition, true));
                runResult = ((TaskQuartzImpl) task).waitForSubtasks(2, deltas, opResult);
                runResult.setProgress(1);
            } catch (Exception e) {
                throw new SystemException("WaitForSubtasks failed.", e);
            }
        } else {
            LOGGER.info("Wait-for-subtasks seems to finish successfully; progress = " + progress + ", wfsFlag = " + wfsFlag.getRealValue());
        }
    }
    LOGGER.info("MockSingle.run stopping");
    return runResult;
}
Also used : ScheduleType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScheduleType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 29 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class TestScience method test100JackAssignRoleStatistics.

@Test
public void test100JackAssignRoleStatistics() throws Exception {
    final String TEST_NAME = "test100JackAssignRoleStatistics";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestScience.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assignRole(USER_JACK_OID, ROLE_STATISTICS_OID);
    PrismObject<UserType> userJack = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
    AssertJUnit.assertNotNull("User jack not found", userJack);
    UserType jackType = userJack.asObjectable();
    IntegrationTestTools.display("User Jack", jackType);
    AssertJUnit.assertEquals("Wrong number of link refs", 3, jackType.getLinkRef().size());
    assertUserJack(userJack);
    assertLinks(userJack, 3);
    String accountStatsOid = getLinkRefOid(userJack, RESOURCE_DUMMY_STATS_OID);
    String accountUnixOid = getLinkRefOid(userJack, RESOURCE_DUMMY_UNIX_OID);
    String accountOpenDjOid = getLinkRefOid(userJack, RESOURCE_OPENDJ_AD_SIMULATION_OID);
    PrismObject<ShadowType> shadowStats = provisioningService.getObject(ShadowType.class, accountStatsOid, null, task, result);
    IntegrationTestTools.display("Stats account: ", shadowStats);
    PrismObject<ShadowType> shadowUnix = provisioningService.getObject(ShadowType.class, accountUnixOid, null, task, result);
    IntegrationTestTools.display("Unix account: ", shadowUnix);
    PrismObject<ShadowType> shadowOpenDj = provisioningService.getObject(ShadowType.class, accountOpenDjOid, null, task, result);
    IntegrationTestTools.display("AD account: ", shadowOpenDj);
    //internalId on unix dummy resource and title on openDJ simulation must be the same
    PrismProperty unixId = shadowUnix.findProperty(new ItemPath(ShadowType.F_ATTRIBUTES, UNIX_INTERNAL_ID));
    assertNotNull("No " + UNIX_INTERNAL_ID + " in " + shadowUnix, unixId);
    PrismProperty openDjSyncedId = shadowOpenDj.findProperty(new ItemPath(ShadowType.F_ATTRIBUTES, new QName(NS_RESOURCE_INSTANCE, "title")));
    assertNotNull("No 'title' in " + shadowOpenDj, openDjSyncedId);
    PrismAsserts.assertEquals("Unix id was not synced to the opendj properly.", String.valueOf(unixId.getAnyRealValue()), openDjSyncedId.getAnyRealValue());
    PrismProperty<Integer> generatedValue = userJack.findExtensionItem(SCIENCE_EXTENSION_UID_QNAME);
    assertNotNull("Generated id value must not be null", generatedValue);
    assertFalse("Generated value must not be empty", generatedValue.isEmpty());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 30 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class PageTaskController method deleteSyncTokenPerformed.

public void deleteSyncTokenPerformed(AjaxRequestTarget target) {
    LOGGER.debug("Deleting sync token.");
    OperationResult result = new OperationResult(PageTaskEdit.OPERATION_DELETE_SYNC_TOKEN);
    Task operationTask = parentPage.createSimpleTask(PageTaskEdit.OPERATION_DELETE_SYNC_TOKEN);
    try {
        final TaskDto taskDto = parentPage.getTaskDto();
        final PrismProperty property = taskDto.getExtensionProperty(SchemaConstants.SYNC_TOKEN);
        if (property == null) {
            // should be treated by isVisible
            result.recordWarning("Token is not present in this task.");
        } else {
            final ObjectDelta<? extends ObjectType> delta = (ObjectDelta<? extends ObjectType>) DeltaBuilder.deltaFor(TaskType.class, parentPage.getPrismContext()).item(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.SYNC_TOKEN), property.getDefinition()).replace().asObjectDelta(parentPage.getTaskDto().getOid());
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Deleting sync token:\n{}", delta.debugDump());
            }
            parentPage.getModelService().executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singleton(delta), null, operationTask, result);
            result.recomputeStatus();
        }
    } catch (Exception ex) {
        result.recomputeStatus();
        result.recordFatalError("Couldn't delete sync token from the task.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete sync token from the task.", ex);
    }
    afterStateChangingOperation(target, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) TaskDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskDto) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PrismProperty (com.evolveum.midpoint.prism.PrismProperty)41 PrismObject (com.evolveum.midpoint.prism.PrismObject)14 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 QName (javax.xml.namespace.QName)13 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 ArrayList (java.util.ArrayList)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)7 SystemException (com.evolveum.midpoint.util.exception.SystemException)7 Containerable (com.evolveum.midpoint.prism.Containerable)6 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)6 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 Test (org.testng.annotations.Test)6 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)5 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)5 Item (com.evolveum.midpoint.prism.Item)4 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)4 Task (com.evolveum.midpoint.task.api.Task)4