use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ValuePolicyProcessor method testMinimalUniqueCharacters.
private StringLimitationResult testMinimalUniqueCharacters(String password, LimitationsType limitations, OperationResult result, List<LocalizableMessage> message) {
if (limitations.getMinUniqueChars() == null) {
return null;
}
HashSet<String> distinctCharacters = new HashSet<>(StringPolicyUtils.stringTokenizer(password));
StringLimitationResult limitation = new StringLimitationResult();
limitation.setMinOccurs(limitations.getMinUniqueChars());
PolyStringType name = new PolyStringType("unique characters");
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setKey("ValuePolicy.uniqueCharacters");
name.setTranslation(translation);
limitation.setName(name);
limitation.setSuccess(true);
if (limitations.getMinUniqueChars() > distinctCharacters.size()) {
LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.minimalUniqueCharactersNotMet").arg(limitations.getMinUniqueChars()).arg(distinctCharacters.size()).build();
result.addSubresult(new OperationResult("Check minimal count of unique chars", 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 ValuePolicyProcessor method testMinimalOccurrence.
private StringLimitationResult testMinimalOccurrence(StringLimitType stringLimitation, int count, OperationResult result, List<LocalizableMessage> messages, StringLimitationResult limitation) {
if (stringLimitation.getMinOccurs() == null) {
return limitation;
}
if (limitation == null) {
limitation = new StringLimitationResult();
limitation.setMinOccurs(stringLimitation.getMinOccurs());
limitation.setSuccess(true);
} else {
limitation.setMinOccurs(stringLimitation.getMinOccurs());
}
if (count < stringLimitation.getMinOccurs()) {
LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.minimalOccurrenceNotMet").arg(stringLimitation.getMinOccurs()).arg(stringLimitation.getDescription()).arg(count).build();
result.addSubresult(new OperationResult("Check minimal occurrence of characters", 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 testCheckExpression.
private List<StringLimitationResult> testCheckExpression(String newPassword, LimitationsType lims, ExpressionProfile expressionProfile, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult result, List<LocalizableMessage> messages) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
List<StringLimitationResult> limitations = new ArrayList<>();
for (CheckExpressionType checkExpression : lims.getCheckExpression()) {
ExpressionType expressionType = checkExpression.getExpression();
if (expressionType == null) {
continue;
}
StringLimitationResult limitation = new StringLimitationResult();
PolyStringType name = null;
if (checkExpression.getDisplay() != null) {
name = checkExpression.getDisplay().getLabel();
limitation.setHelp(checkExpression.getDisplay().getHelp());
}
if (name == null) {
name = new PolyStringType("Check expression");
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setKey("ValuePolicy.checkExpression");
name.setTranslation(translation);
}
limitation.setName(name);
limitation.setSuccess(true);
if (!checkExpression(newPassword, expressionType, expressionProfile, originResolver, shortDesc, task, result)) {
LocalizableMessage msg;
if (checkExpression.getLocalizableFailureMessage() != null) {
msg = LocalizationUtil.toLocalizableMessage(checkExpression.getLocalizableFailureMessage());
} else if (checkExpression.getFailureMessage() != null) {
msg = LocalizableMessageBuilder.buildFallbackMessage(checkExpression.getFailureMessage());
} else {
msg = LocalizableMessageBuilder.buildKey("ValuePolicy.checkExpressionFailed");
}
result.addSubresult(new OperationResult("Check expression", OperationResultStatus.FATAL_ERROR, msg));
messages.add(msg);
limitation.setSuccess(false);
}
limitations.add(limitation);
}
return limitations;
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class Projector method computeResultStatus.
private void computeResultStatus(XMLGregorianCalendar projectorStartTimestampCal, OperationResult result) {
boolean hasProjectionError = false;
OperationResultStatus finalStatus = OperationResultStatus.SUCCESS;
String message = null;
LocalizableMessage userFriendlyMessage = null;
for (OperationResult subresult : result.getSubresults()) {
if (subresult.isNotApplicable() || subresult.isSuccess()) {
continue;
}
if (subresult.isHandledError()) {
if (finalStatus == OperationResultStatus.SUCCESS) {
finalStatus = OperationResultStatus.HANDLED_ERROR;
}
continue;
}
if (subresult.isError()) {
message = subresult.getMessage();
userFriendlyMessage = subresult.getUserFriendlyMessage();
if (OPERATION_PROJECT_PROJECTION.equals(subresult.getOperation())) {
hasProjectionError = true;
} else {
if (finalStatus != OperationResultStatus.FATAL_ERROR) {
finalStatus = subresult.getStatus();
}
}
}
}
if (finalStatus != OperationResultStatus.FATAL_ERROR && hasProjectionError) {
finalStatus = OperationResultStatus.PARTIAL_ERROR;
}
result.setStatus(finalStatus);
result.setMessage(message);
result.setUserFriendlyMessage(userFriendlyMessage);
result.cleanupResult();
if (LOGGER.isDebugEnabled()) {
long projectorStartTimestamp = XmlTypeConverter.toMillis(projectorStartTimestampCal);
long projectorEndTimestamp = clock.currentTimeMillis();
LOGGER.trace("Projector finished ({}). Etime: {} ms", result.getStatus(), (projectorEndTimestamp - projectorStartTimestamp));
}
}
use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.
the class ModelHelper method createInstructionForRoot.
/**
* Creates a root job creation instruction.
*
* @param changeProcessor reference to the change processor responsible for the whole operation
* @param contextForRootCase model context that should be put into the root task (might be different from the modelContext)
* @return the job creation instruction
*/
public StartInstruction createInstructionForRoot(ChangeProcessor changeProcessor, @NotNull ModelInvocationContext<?> ctx, ModelContext<?> contextForRootCase, OperationResult result) throws SchemaException {
StartInstruction instruction = StartInstruction.create(changeProcessor, SystemObjectsType.ARCHETYPE_OPERATION_REQUEST.value());
instruction.setModelContext(contextForRootCase);
LocalizableMessage rootCaseName = determineRootCaseName(ctx);
String rootCaseNameInDefaultLocale = localizationService.translate(rootCaseName, Locale.getDefault());
instruction.setName(rootCaseNameInDefaultLocale, rootCaseName);
instruction.setObjectRef(ctx);
instruction.setRequesterRef(ctx.getRequestor(result));
return instruction;
}
Aggregations