Search in sources :

Example 66 with PrismPropertyValue

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

the class TestMappingDynamicSysVar method testPasswordString.

@Test
public void testPasswordString() throws Exception {
    // WHEN
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = evaluator.evaluateMappingDynamicReplace("mapping-script-system-variables-password.xml", "testPasswordString", // target
    "employeeType", // changed property
    new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE), // changed values
    evaluator.createProtectedString("weighAnch0r"));
    // THEN
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, "weighAnch0r");
    PrismAsserts.assertTripleMinus(outputTriple, "d3adM3nT3llN0Tal3s");
}
Also used : ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Test(org.testng.annotations.Test)

Example 67 with PrismPropertyValue

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

the class TestMappingDynamicSysVar method testScriptSystemVariablesConditionTrueToFalse.

public void testScriptSystemVariablesConditionTrueToFalse(String filename) throws Exception {
    // GIVEN
    final String TEST_NAME = "testScriptSystemVariablesConditionTrueToFalse";
    System.out.println("===[ " + TEST_NAME + "]===");
    ObjectDelta<UserType> delta = ObjectDelta.createModificationReplaceProperty(UserType.class, evaluator.USER_OLD_OID, evaluator.toPath("name"), evaluator.getPrismContext(), "Jack");
    delta.addModificationDeleteProperty(evaluator.toPath("employeeType"), "CAPTAIN");
    Mapping<PrismPropertyValue<PolyString>, PrismPropertyDefinition<PolyString>> mapping = evaluator.createMapping(filename, TEST_NAME, "title", delta);
    PrismObject<UserType> user = (PrismObject<UserType>) mapping.getSourceContext().getOldObject();
    user.asObjectable().getEmployeeType().add("CAPTAIN");
    mapping.getSourceContext().recompute();
    OperationResult opResult = new OperationResult(TEST_NAME);
    // WHEN
    mapping.evaluate(null, opResult);
    // THEN
    PrismValueDeltaSetTriple<PrismPropertyValue<PolyString>> outputTriple = mapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTripleNoPlus(outputTriple);
    PrismAsserts.assertTripleMinus(outputTriple, PrismTestUtil.createPolyString("Captain jack"));
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) 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 68 with PrismPropertyValue

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

the class FocusProjectionsTabPanel method updateShadowActivation.

private void updateShadowActivation(AjaxRequestTarget target, List<FocusSubwrapperDto<ShadowType>> accounts, boolean enabled) {
    if (!isAnyProjectionSelected(target, projectionModel)) {
        return;
    }
    for (FocusSubwrapperDto<ShadowType> account : accounts) {
        if (!account.isLoadedOK()) {
            continue;
        }
        ObjectWrapper<ShadowType> wrapper = account.getObject();
        ContainerWrapper<ActivationType> activation = wrapper.findContainerWrapper(new ItemPath(ShadowType.F_ACTIVATION));
        if (activation == null) {
            warn(getString("pageAdminFocus.message.noActivationFound", wrapper.getDisplayName()));
            continue;
        }
        PropertyWrapper enabledProperty = (PropertyWrapper) activation.findPropertyWrapper(ActivationType.F_ADMINISTRATIVE_STATUS);
        if (enabledProperty == null || enabledProperty.getValues().size() != 1) {
            warn(getString("pageAdminFocus.message.noEnabledPropertyFound", wrapper.getDisplayName()));
            continue;
        }
        ValueWrapper value = (ValueWrapper) enabledProperty.getValues().get(0);
        ActivationStatusType status = enabled ? ActivationStatusType.ENABLED : ActivationStatusType.DISABLED;
        ((PrismPropertyValue) value.getValue()).setValue(status);
        wrapper.setSelected(false);
    }
    target.add(getFeedbackPanel(), get(createComponentPath(ID_SHADOWS)));
}
Also used : ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 69 with PrismPropertyValue

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

the class PersonaProcessor method processPersonaChangesFocus.

public <F extends FocusType> HookOperationMode processPersonaChangesFocus(LensContext<F> context, Task task, OperationResult result) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, PolicyViolationException {
    DeltaSetTriple<EvaluatedAssignmentImpl<F>> evaluatedAssignmentTriple = (DeltaSetTriple) context.getEvaluatedAssignmentTriple();
    if (evaluatedAssignmentTriple == null || evaluatedAssignmentTriple.isEmpty()) {
        return HookOperationMode.FOREGROUND;
    }
    DeltaSetTriple<PersonaKey> activePersonaKeyTriple = new DeltaSetTriple<>();
    ComplexConstructionConsumer<PersonaKey, PersonaConstruction<F>> consumer = new ComplexConstructionConsumer<PersonaKey, PersonaConstruction<F>>() {

        @Override
        public boolean before(PersonaKey key) {
            return true;
        }

        @Override
        public void onAssigned(PersonaKey key, String desc) {
            activePersonaKeyTriple.addToPlusSet(key);
        }

        @Override
        public void onUnchangedValid(PersonaKey key, String desc) {
            activePersonaKeyTriple.addToZeroSet(key);
        }

        @Override
        public void onUnchangedInvalid(PersonaKey key, String desc) {
        }

        @Override
        public void onUnassigned(PersonaKey key, String desc) {
            activePersonaKeyTriple.addToMinusSet(key);
        }

        @Override
        public void after(PersonaKey key, String desc, DeltaMapTriple<PersonaKey, ConstructionPack<PersonaConstruction<F>>> constructionMapTriple) {
        }
    };
    DeltaMapTriple<PersonaKey, ConstructionPack<PersonaConstruction<F>>> constructionMapTriple = constructionProcessor.processConstructions(context, evaluatedAssignmentTriple, evaluatedAssignment -> evaluatedAssignment.getPersonaConstructionTriple(), construction -> new PersonaKey(construction.getConstructionType()), consumer, task, result);
    LOGGER.trace("activePersonaKeyTriple:\n{}", activePersonaKeyTriple.debugDumpLazily());
    List<FocusType> existingPersonas = readExistingPersonas(context, task, result);
    LOGGER.trace("existingPersonas:\n{}", existingPersonas);
    for (PersonaKey key : activePersonaKeyTriple.getNonNegativeValues()) {
        FocusType existingPersona = findPersona(existingPersonas, key);
        LOGGER.trace("existingPersona: {}", existingPersona);
        // TODO: add ability to merge several constructions
        ConstructionPack<PersonaConstruction<F>> pack = constructionMapTriple.getPlusMap().get(key);
        if (pack == null) {
            pack = constructionMapTriple.getZeroMap().get(key);
        }
        Collection<PrismPropertyValue<PersonaConstruction<F>>> constructions = pack.getConstructions();
        if (constructions.isEmpty()) {
            continue;
        }
        if (constructions.size() > 1) {
            throw new UnsupportedOperationException("Merging of multiple persona constructions is not supported yet");
        }
        PersonaConstruction<F> construction = constructions.iterator().next().getValue();
        LOGGER.trace("construction:\n{}", construction.debugDumpLazily());
        if (existingPersona == null) {
            personaAdd(context, key, construction, task, result);
        } else {
            personaModify(context, key, construction, existingPersona.asPrismObject(), task, result);
        }
    }
    for (PersonaKey key : activePersonaKeyTriple.getMinusSet()) {
        FocusType existingPersona = findPersona(existingPersonas, key);
        if (existingPersona != null) {
            personaDelete(context, key, existingPersona, task, result);
        }
    }
    return HookOperationMode.FOREGROUND;
}
Also used : DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) ComplexConstructionConsumer(com.evolveum.midpoint.model.impl.lens.projector.ComplexConstructionConsumer) DeltaMapTriple(com.evolveum.midpoint.prism.delta.DeltaMapTriple) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 70 with PrismPropertyValue

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

the class LockoutStatusPanel method initLayout.

private void initLayout(final IModel<LockoutStatusType> model) {
    WebMarkupContainer container = new WebMarkupContainer(ID_CONTAINER);
    add(container);
    Label label = new Label(ID_LABEL, new IModel<String>() {

        @Override
        public String getObject() {
            LockoutStatusType object = model != null ? model.getObject() : null;
            String labelValue = object == null ? ((PageBase) getPage()).createStringResource("LockoutStatusType.UNDEFINED").getString() : WebComponentUtil.createLocalizedModelForEnum(object, getLabel()).getObject();
            if (!isInitialState) {
                labelValue += " " + ((PageBase) getPage()).createStringResource("LockoutStatusPanel.changesSaving").getString();
            }
            return labelValue;
        }

        @Override
        public void setObject(String s) {
        }

        @Override
        public void detach() {
        }
    });
    label.setOutputMarkupId(true);
    container.add(label);
    AjaxButton button = new AjaxButton(ID_BUTTON, getButtonModel()) {

        @Override
        public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            PrismPropertyValue oldValue = (PrismPropertyValue) valueWrapper.getOldValue();
            if (!isInitialState) {
                model.setObject(initialValue);
                oldValue.setValue(initialValue);
                valueWrapper.setStatus(ValueStatus.NOT_CHANGED);
            } else {
                model.setObject(LockoutStatusType.NORMAL);
                if (oldValue.getValue() != null) {
                    oldValue.setValue(null);
                }
            }
            isInitialState = !isInitialState;
            ajaxRequestTarget.add(getButton());
            ajaxRequestTarget.add(getLabel());
        }
    };
    button.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return true;
        }
    });
    button.setOutputMarkupId(true);
    container.add(button);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Label(org.apache.wicket.markup.html.basic.Label) LockoutStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)176 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)93 Test (org.testng.annotations.Test)83 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)81 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)81 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)60 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)43 QName (javax.xml.namespace.QName)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ArrayList (java.util.ArrayList)16 Task (com.evolveum.midpoint.task.api.Task)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)8 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 File (java.io.File)8