use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ValuePolicyProcessor method testMustBeFirst.
private StringLimitationResult testMustBeFirst(StringLimitType stringLimitation, OperationResult result, List<LocalizableMessage> messages, String value, Set<String> validFirstChars, StringLimitationResult limitation) {
if (stringLimitation.isMustBeFirst() == null) {
return limitation;
}
if (limitation == null) {
limitation = new StringLimitationResult();
limitation.setMustBeFirst(stringLimitation.isMustBeFirst());
limitation.setSuccess(StringUtils.isNotEmpty(value));
} else {
limitation.setMustBeFirst(stringLimitation.isMustBeFirst());
}
if (StringUtils.isNotEmpty(value) && isTrue(stringLimitation.isMustBeFirst()) && !validFirstChars.contains(value.substring(0, 1))) {
LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.firstCharacterNotAllowed").arg(validFirstChars.toString()).build();
result.addSubresult(new OperationResult("Check valid first char", OperationResultStatus.FATAL_ERROR, msg));
messages.add(msg);
limitation.setSuccess(false);
}
return limitation;
}
use of com.evolveum.midpoint.util.LocalizableMessage 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.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class OpResult method getOpResult.
public static OpResult getOpResult(PageBase page, OperationResult result) {
OpResult opResult = new OpResult();
Validate.notNull(result, "Operation result must not be null.");
Validate.notNull(result.getStatus(), "Operation result status must not be null.");
if (result.getCause() != null && result.getCause() instanceof CommonException) {
LocalizableMessage localizableMessage = ((CommonException) result.getCause()).getUserFriendlyMessage();
if (localizableMessage != null) {
opResult.message = WebComponentUtil.resolveLocalizableMessage(localizableMessage, page);
// Exclamation code:
// String key = localizableMessage.getKey() != null ? localizableMessage.getKey() : localizableMessage.getFallbackMessage();
// StringResourceModel stringResourceModel = new StringResourceModel(key, page).setModel(new Model<String>()).setDefaultValue(localizableMessage.getFallbackMessage())
// .setParameters(localizableMessage.getArgs());
// opResult.message = stringResourceModel.getString();
}
}
if (opResult.message == null) {
opResult.message = result.getMessage();
}
opResult.operation = result.getOperation();
opResult.status = result.getStatus();
opResult.count = result.getCount();
opResult.userFriendlyMessage = result.getUserFriendlyMessage();
if (result.getCause() != null) {
Throwable cause = result.getCause();
opResult.exceptionMessage = cause.getMessage();
Writer writer = new StringWriter();
cause.printStackTrace(new PrintWriter(writer));
opResult.exceptionsStackTrace = writer.toString();
}
for (Map.Entry<String, Collection<String>> entry : result.getParams().entrySet()) {
String paramValue = null;
Collection<String> values = entry.getValue();
if (values != null) {
paramValue = values.toString();
}
opResult.getParams().add(new Param(entry.getKey(), paramValue));
}
for (Map.Entry<String, Collection<String>> entry : result.getContext().entrySet()) {
String contextValue = null;
Collection<String> values = entry.getValue();
if (values != null) {
contextValue = values.toString();
}
opResult.getContexts().add(new Context(entry.getKey(), contextValue));
}
for (OperationResult subresult : result.getSubresults()) {
OpResult subOpResult = OpResult.getOpResult(page, subresult);
opResult.getSubresults().add(subOpResult);
subOpResult.parent = opResult;
}
String asynchronousOperationReference = result.findAsynchronousOperationReference();
opResult.backgroundTaskOid = OperationResult.referenceToTaskOid(asynchronousOperationReference);
opResult.caseOid = OperationResult.referenceToCaseOid(asynchronousOperationReference);
if (opResult.parent == null) {
opResult.xml = createXmlModel(result, page);
}
return opResult;
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ValuePolicyProcessor method testLength.
private StringLimitationResult testLength(String value, LimitationsType limitations, OperationResult result, List<LocalizableMessage> messages) {
if (limitations.getMinLength() == null && limitations.getMaxLength() == null) {
return null;
}
StringLimitationResult limitation = new StringLimitationResult();
limitation.setMinOccurs(limitations.getMinLength());
limitation.setMaxOccurs(limitations.getMaxLength());
PolyStringType name = new PolyStringType("characters");
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setKey("ValuePolicy.characters");
name.setTranslation(translation);
limitation.setName(name);
limitation.setSuccess(true);
if (limitations.getMinLength() != null && value.length() < limitations.getMinLength()) {
LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.minimalSizeNotMet").arg(limitations.getMinLength()).arg(value.length()).build();
result.addSubresult(new OperationResult("Check global minimal length", OperationResultStatus.FATAL_ERROR, msg));
messages.add(msg);
limitation.setSuccess(false);
}
if (limitations.getMaxLength() != null && value.length() > limitations.getMaxLength()) {
LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.maximalSizeExceeded").arg(limitations.getMaxLength()).arg(value.length()).build();
result.addSubresult(new OperationResult("Check global maximal length", OperationResultStatus.FATAL_ERROR, msg));
messages.add(msg);
limitation.setSuccess(false);
}
return limitation;
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ValuePolicyProcessor method testMaximalOccurrence.
private StringLimitationResult testMaximalOccurrence(StringLimitType stringLimitation, int count, OperationResult result, List<LocalizableMessage> messages, StringLimitationResult limitation) {
if (stringLimitation.getMaxOccurs() == null) {
return limitation;
}
if (limitation == null) {
limitation = new StringLimitationResult();
limitation.setMaxOccurs(stringLimitation.getMaxOccurs());
limitation.setSuccess(true);
} else {
limitation.setMaxOccurs(stringLimitation.getMaxOccurs());
}
if (count > stringLimitation.getMaxOccurs()) {
LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.maximalOccurrenceExceeded").arg(stringLimitation.getMaxOccurs()).arg(stringLimitation.getDescription()).arg(count).build();
result.addSubresult(new OperationResult("Check maximal occurrence of characters", OperationResultStatus.FATAL_ERROR, msg));
messages.add(msg);
limitation.setSuccess(false);
}
return limitation;
}
Aggregations