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;
}
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;
}
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();
}
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;
}
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);
}
}
Aggregations