Search in sources :

Example 36 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class TestMappingDynamicSysVar method testScriptSystemVariablesConditionAddObjectFalse.

public void testScriptSystemVariablesConditionAddObjectFalse(String filename) throws Exception {
    // GIVEN
    final String TEST_NAME = "testScriptSystemVariablesConditionAddObjectFalse";
    System.out.println("===[ " + TEST_NAME + "]===");
    PrismObject<UserType> user = evaluator.getUserOld();
    user.asObjectable().getEmployeeType().clear();
    user.asObjectable().getEmployeeType().add("SAILOR");
    ObjectDelta<UserType> delta = ObjectDelta.createAddDelta(user);
    Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping(filename, TEST_NAME, "title", delta);
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    assertNull("Unexpected output triple: " + outputTriple, outputTriple);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 37 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class ModelDiagController method assertMultivaluePolyString.

private void assertMultivaluePolyString(String message, String[] expectedOrigs, Collection<PolyString> actualPolyStrings, OperationResult result) {
    if (expectedOrigs.length != actualPolyStrings.size()) {
        fail(message + ": expected " + expectedOrigs.length + " values but has " + actualPolyStrings.size() + " values: " + actualPolyStrings, result);
        return;
    }
    for (String expectedOrig : expectedOrigs) {
        boolean found = false;
        for (PolyString actualPolyString : actualPolyStrings) {
            if (expectedOrig.equals(actualPolyString.getOrig())) {
                found = true;
                assertEquals(message + ", norm", polyStringNorm(expectedOrig), actualPolyString.getNorm(), result);
                break;
            }
        }
        if (!found) {
            fail(message + ": expected value '" + expectedOrig + "' not found in actual values " + actualPolyStrings, result);
            return;
        }
    }
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RandomString(com.evolveum.midpoint.util.RandomString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 38 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class TestMappingDynamicSysVar method testNpeFalseToTrue.

@Test
public void testNpeFalseToTrue() throws Exception {
    final String TEST_NAME = "testNpeFalseToTrue";
    System.out.println("===[ " + TEST_NAME + "]===");
    // GIVEN
    ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, UserType.F_ADDITIONAL_NAME, evaluator.getPrismContext(), "Captain Sparrow");
    Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping("mapping-npe.xml", TEST_NAME, "title", delta);
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, PrismTestUtil.createPolyString("15"));
    PrismAsserts.assertTripleNoMinus(outputTriple);
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 39 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class PageTaskController method getDeltasToExecute.

private List<ItemDelta<?, ?>> getDeltasToExecute(TaskDto dto) throws SchemaException {
    List<ItemDelta<?, ?>> rv = new ArrayList<>();
    TaskEditableState orig = dto.getOriginalEditableState();
    TaskEditableState curr = dto.getCurrentEditableState();
    if (!StringUtils.equals(orig.getName(), curr.getName())) {
        String name = curr.getName() != null ? curr.getName() : "";
        addDelta(rv, TaskType.F_NAME, new PolyString(name));
    }
    if (!StringUtils.equals(orig.getDescription(), curr.getDescription())) {
        addDelta(rv, TaskType.F_DESCRIPTION, curr.getDescription());
    }
    ScheduleType origSchedule = orig.getScheduleType();
    ScheduleType currSchedule = curr.getScheduleType();
    if (!origSchedule.equals(currSchedule)) {
        if (dto.getTaskType().getSchedule() != null) {
            currSchedule.setLatestFinishTime(dto.getTaskType().getSchedule().getLatestFinishTime());
        }
        addDelta(rv, TaskType.F_SCHEDULE, currSchedule);
    }
    if (orig.isRecurring() != curr.isRecurring()) {
        addDelta(rv, TaskType.F_RECURRENCE, curr.isRecurring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
    }
    if (orig.isBound() != curr.isBound()) {
        addDelta(rv, TaskType.F_BINDING, curr.isBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);
    }
    if (orig.getThreadStopActionType() != curr.getThreadStopActionType()) {
        addDelta(rv, TaskType.F_THREAD_STOP_ACTION, curr.getThreadStopActionType());
    }
    if (!ObjectUtils.equals(orig.getWorkerThreads(), curr.getWorkerThreads())) {
        SchemaRegistry registry = parentPage.getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry.findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORKER_THREADS);
        rv.add(DeltaBuilder.deltaFor(TaskType.class, parentPage.getPrismContext()).item(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_WORKER_THREADS), def).replace(curr.getWorkerThreads()).asItemDelta());
    }
    rv.addAll(dto.getHandlerDto().getDeltasToExecute(orig.getHandlerSpecificState(), curr.getHandlerSpecificState(), parentPage.getPrismContext()));
    return rv;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) TaskEditableState(com.evolveum.midpoint.web.page.admin.server.dto.TaskEditableState) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 40 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class InitialDataImport method init.

public void init() throws SchemaException {
    LOGGER.info("Starting initial object import (if necessary).");
    OperationResult mainResult = new OperationResult(OPERATION_INITIAL_OBJECTS_IMPORT);
    Task task = taskManager.createTaskInstance(OPERATION_INITIAL_OBJECTS_IMPORT);
    task.setChannel(SchemaConstants.CHANNEL_GUI_INIT_URI);
    int count = 0;
    int errors = 0;
    File[] files = getInitialImportObjects();
    LOGGER.debug("Files to be imported: {}.", Arrays.toString(files));
    // We need to provide a fake Spring security context here.
    // We have to fake it because we do not have anything in the repository yet. And to get
    // something to the repository we need a context. Chicken and egg. So we fake the egg.
    SecurityContext securityContext = SecurityContextHolder.getContext();
    UserType userAdministrator = new UserType();
    prismContext.adopt(userAdministrator);
    userAdministrator.setName(new PolyStringType(new PolyString("initAdmin", "initAdmin")));
    MidPointPrincipal principal = new MidPointPrincipal(userAdministrator);
    AuthorizationType superAutzType = new AuthorizationType();
    prismContext.adopt(superAutzType, RoleType.class, new ItemPath(RoleType.F_AUTHORIZATION));
    superAutzType.getAction().add(AuthorizationConstants.AUTZ_ALL_URL);
    Authorization superAutz = new Authorization(superAutzType);
    Collection<Authorization> authorities = principal.getAuthorities();
    authorities.add(superAutz);
    Authentication authentication = new PreAuthenticatedAuthenticationToken(principal, null);
    securityContext.setAuthentication(authentication);
    for (File file : files) {
        try {
            LOGGER.debug("Considering initial import of file {}.", file.getName());
            PrismObject object = prismContext.parseObject(file);
            if (ReportType.class.equals(object.getCompileTimeClass())) {
                ReportTypeUtil.applyDefinition(object, prismContext);
            }
            Boolean importObject = importObject(object, file, task, mainResult);
            if (importObject == null) {
                continue;
            }
            if (importObject) {
                count++;
            } else {
                errors++;
            }
        } catch (Exception ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file {}", ex, file.getName());
            mainResult.recordFatalError("Couldn't import file '" + file.getName() + "'", ex);
        }
    }
    securityContext.setAuthentication(null);
    mainResult.recomputeStatus("Couldn't import objects.");
    LOGGER.info("Initial object import finished ({} objects imported, {} errors)", count, errors);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Initialization status:\n" + mainResult.debugDump());
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) URISyntaxException(java.net.URISyntaxException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) IOException(java.io.IOException) Authorization(com.evolveum.midpoint.security.api.Authorization) PrismObject(com.evolveum.midpoint.prism.PrismObject) Authentication(org.springframework.security.core.Authentication) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SecurityContext(org.springframework.security.core.context.SecurityContext) AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PolyString (com.evolveum.midpoint.prism.polystring.PolyString)168 Test (org.testng.annotations.Test)103 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)90 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)67 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)53 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)44 Task (com.evolveum.midpoint.task.api.Task)41 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)27 PrismObject (com.evolveum.midpoint.prism.PrismObject)21 QName (javax.xml.namespace.QName)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)16 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)15 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)12 ArrayList (java.util.ArrayList)12 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 File (java.io.File)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)8 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)8