Search in sources :

Example 11 with PolyStringTranslationType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType in project midpoint by Evolveum.

the class ValuePolicyProcessor method testInvalidCharacters.

private StringLimitationResult testInvalidCharacters(List<String> valueCharacters, HashSet<String> validChars, OperationResult result, List<LocalizableMessage> message) {
    StringBuilder invalidCharacters = new StringBuilder();
    for (String character : valueCharacters) {
        if (!validChars.contains(character)) {
            invalidCharacters.append(character);
        }
    }
    StringLimitationResult limitation = new StringLimitationResult();
    PolyStringType name = new PolyStringType("invalid characters");
    PolyStringTranslationType translation = new PolyStringTranslationType();
    translation.setKey("ValuePolicy.invalidCharacters");
    name.setTranslation(translation);
    limitation.setName(name);
    PolyStringType help = new PolyStringType(getCharsetAsString(validChars));
    limitation.setHelp(help);
    limitation.setSuccess(true);
    if (invalidCharacters.length() > 0) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.charactersNotAllowed").arg(invalidCharacters).build();
        result.addSubresult(new OperationResult("Check if value does not contain invalid characters", OperationResultStatus.FATAL_ERROR, msg));
        message.add(msg);
        limitation.setSuccess(false);
    }
    return limitation;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Example 12 with PolyStringTranslationType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType in project midpoint by Evolveum.

the class ValuePolicyProcessor method validateValue.

public List<StringLimitationResult> validateValue(String newValue, ValuePolicyType pp, ObjectBasedValuePolicyOriginResolver<?> originResolver, List<LocalizableMessage> messages, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    // TODO: do we want to throw exception when no value policy defined??
    Validate.notNull(pp, "Value policy must not be null.");
    OperationResult result = parentResult.createSubresult(OPERATION_STRING_POLICY_VALIDATION);
    result.addArbitraryObjectAsParam("policyName", pp.getName());
    List<StringLimitationResult> limitations = new ArrayList<>();
    try {
        normalize(pp);
        if (newValue == null) {
            newValue = "";
        }
        LimitationsType lims = pp.getStringPolicy().getLimitations();
        CollectionUtils.addIgnoreNull(limitations, testLength(newValue, lims, result, messages));
        CollectionUtils.addIgnoreNull(limitations, testMinimalUniqueCharacters(newValue, lims, result, messages));
        CollectionUtils.addIgnoreNull(limitations, testProhibitedValues(newValue, pp.getProhibitedValues(), originResolver, shortDesc, task, result, messages));
        // TODO: this needs to be determined from ValuePolicyType archetype
        ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
        limitations.addAll(testCheckExpression(newValue, lims, expressionProfile, originResolver, shortDesc, task, result, messages));
        if (!lims.getLimit().isEmpty()) {
            // check limitation
            HashSet<String> validChars;
            HashSet<String> allValidChars = new HashSet<>();
            List<String> characters = StringPolicyUtils.stringTokenizer(newValue);
            for (StringLimitType stringLimitationType : lims.getLimit()) {
                OperationResult limitResult = new OperationResult("Tested limitation: " + stringLimitationType.getDescription());
                validChars = getValidCharacters(stringLimitationType.getCharacterClass(), pp);
                int count = countValidCharacters(validChars, characters);
                allValidChars.addAll(validChars);
                StringLimitationResult limitation = null;
                limitation = testMinimalOccurrence(stringLimitationType, count, limitResult, messages, limitation);
                limitation = testMaximalOccurrence(stringLimitationType, count, limitResult, messages, limitation);
                limitation = testMustBeFirst(stringLimitationType, limitResult, messages, newValue, validChars, limitation);
                if (limitation != null) {
                    PolyStringType name = stringLimitationType.getName();
                    if (name == null) {
                        name = new PolyStringType(stringLimitationType.getDescription());
                        PolyStringTranslationType translation = new PolyStringTranslationType();
                        translation.setKey(stringLimitationType.getDescription());
                        name.setTranslation(translation);
                    }
                    PolyStringType help = new PolyStringType(getCharsetAsString(validChars));
                    limitation.setHelp(help);
                    limitation.setName(name);
                    limitations.add(limitation);
                }
                limitResult.computeStatus();
                result.addSubresult(limitResult);
            }
            CollectionUtils.addIgnoreNull(limitations, testInvalidCharacters(characters, allValidChars, result, messages));
        }
    } catch (Throwable t) {
        result.recordFatalError(t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
    if (!result.isSuccess() && !messages.isEmpty()) {
        result.setUserFriendlyMessage(new LocalizableMessageListBuilder().messages(messages).separator(LocalizableMessageList.SPACE).buildOptimized());
    }
    return limitations;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) LocalizableMessageListBuilder(com.evolveum.midpoint.util.LocalizableMessageListBuilder) StringLimitType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringLimitType) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Example 13 with PolyStringTranslationType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType in project midpoint by Evolveum.

the class WebComponentUtil method getRelationHeaderLabelKeyIfKnown.

@Nullable
public static String getRelationHeaderLabelKeyIfKnown(QName relation) {
    RelationDefinitionType definition = getRelationRegistry().getRelationDefinition(relation);
    PolyStringType label = getRelationLabel(definition);
    if (label == null) {
        return null;
    }
    PolyStringTranslationType translation = label.getTranslation();
    if (translation == null) {
        return label.getOrig();
    }
    return translation.getKey();
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with PolyStringTranslationType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType in project midpoint by Evolveum.

the class WebComponentUtil method setTranslateToPolystring.

private static PolyString setTranslateToPolystring(PolyString polystring) {
    if (org.apache.commons.lang3.StringUtils.isNotBlank(polystring.getOrig())) {
        if (polystring.getTranslation() == null) {
            PolyStringTranslationType translation = new PolyStringTranslationType();
            translation.setKey(polystring.getOrig());
            if (org.apache.commons.lang3.StringUtils.isBlank(translation.getFallback())) {
                translation.setFallback(polystring.getOrig());
            }
            polystring.setTranslation(translation);
        } else if (org.apache.commons.lang3.StringUtils.isNotBlank(polystring.getTranslation().getKey())) {
            polystring.getTranslation().setKey(polystring.getOrig());
            if (org.apache.commons.lang3.StringUtils.isBlank(polystring.getTranslation().getFallback())) {
                polystring.getTranslation().setFallback(polystring.getOrig());
            }
        }
    }
    return polystring;
}
Also used : PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Example 15 with PolyStringTranslationType

use of com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType in project midpoint by Evolveum.

the class LocalizationServiceImpl method translate.

private String translate(PolyStringTranslationType translation, Locale locale) {
    String key = translation.getKey();
    if (StringUtils.isEmpty(key)) {
        return translateFromFallback(translation, locale, key);
    }
    String result;
    List<PolyStringTranslationArgumentType> arguments = translation.getArgument();
    if (arguments == null) {
        result = translate(key, null, locale, key);
    } else {
        result = translate(key, arguments.toArray(), locale, key);
    }
    if (result != null) {
        return result;
    } else {
        return translateFromFallback(translation, locale, null);
    }
}
Also used : PolyStringTranslationArgumentType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationArgumentType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

PolyStringTranslationType (com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)19 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)16 StringLimitationResult (com.evolveum.midpoint.model.api.validator.StringLimitationResult)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 LocalizableMessageBuilder (com.evolveum.midpoint.util.LocalizableMessageBuilder)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ExpressionProfile (com.evolveum.midpoint.schema.expression.ExpressionProfile)2 LocalizableMessageListBuilder (com.evolveum.midpoint.util.LocalizableMessageListBuilder)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 LimitationsType (com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType)2 StringLimitType (com.evolveum.midpoint.xml.ns._public.common.common_3.StringLimitType)2 NotNull (org.jetbrains.annotations.NotNull)2 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)1 StandardLoggerType (com.evolveum.midpoint.gui.impl.page.admin.configuration.component.StandardLoggerType)1 MutablePrismPropertyDefinition (com.evolveum.midpoint.prism.MutablePrismPropertyDefinition)1 PrimitiveType (com.evolveum.midpoint.prism.PrimitiveType)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)1