Skip to content

Commit

Permalink
Polishing default messages for constraints violations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 26, 2017
1 parent d3b0587 commit 1416feb
Show file tree
Hide file tree
Showing 23 changed files with 191 additions and 159 deletions.
Expand Up @@ -364,7 +364,9 @@ public static String resolveLocalizableMessage(LocalizableMessage localizableMes
.setModel(new Model<String>())
.setDefaultValue(localizableMessage.getFallbackMessage())
.setParameters(resolveArguments(localizableMessage.getArgs(), component));
return stringResourceModel.getString();
String rv = stringResourceModel.getString();
//System.out.println("GUI: Resolving [" + key + "]: to [" + rv + "]");
return rv;
}

private static Object[] resolveArguments(Object[] args, Component component) {
Expand Down
Expand Up @@ -188,7 +188,7 @@ private void initLayout() {
mainForm.add(policyViolationsContainer);

WebMarkupContainer approvalsContainer = new WebMarkupContainer(ID_APPROVALS_CONTAINER);
approvalsContainer.add(new VisibleBehaviour(() -> !approvalsModel.getObject().isEmpty()));
approvalsContainer.add(new VisibleBehaviour(() -> policyViolationsModel.getObject().isEmpty() && !approvalsModel.getObject().isEmpty()));
approvalsContainer.add(new ApprovalProcessesPreviewPanel(ID_APPROVALS, approvalsModel));
mainForm.add(approvalsContainer);

Expand Down
Expand Up @@ -63,6 +63,7 @@ public String translate(String key, Object[] params, Locale locale, String defau
try {
String value = source.getMessage(key, translated, locale);
if (StringUtils.isNotEmpty(value)) {
//System.out.println("LSI: resolved [" + key + "] into [" + value + "]");
return value;
}
} catch (NoSuchMessageException ex) {
Expand Down
Expand Up @@ -363,24 +363,24 @@ public void initialize() throws SAXException, IOException, SchemaException {
throw new IllegalStateException("Namespace prefix mapper not set");
}
try {
LOGGER.info("initialize() starting");
LOGGER.trace("initialize() starting");
long start = System.currentTimeMillis();

initResolver();
long resolverDone = System.currentTimeMillis();
LOGGER.info("initResolver() done in {} ms", resolverDone - start);
LOGGER.trace("initResolver() done in {} ms", resolverDone - start);

parsePrismSchemas();
long prismSchemasDone = System.currentTimeMillis();
LOGGER.info("parsePrismSchemas() done in {} ms", prismSchemasDone - resolverDone);
LOGGER.trace("parsePrismSchemas() done in {} ms", prismSchemasDone - resolverDone);

parseJavaxSchema();
long javaxSchemasDone = System.currentTimeMillis();
LOGGER.info("parseJavaxSchema() done in {} ms", javaxSchemasDone - prismSchemasDone);
LOGGER.trace("parseJavaxSchema() done in {} ms", javaxSchemasDone - prismSchemasDone);

compileCompileTimeClassList();
long classesDone = System.currentTimeMillis();
LOGGER.info("compileCompileTimeClassList() done in {} ms", classesDone - javaxSchemasDone);
LOGGER.trace("compileCompileTimeClassList() done in {} ms", classesDone - javaxSchemasDone);

initialized = true;
} catch (SAXException ex) {
Expand Down
Expand Up @@ -541,6 +541,7 @@ public abstract class SchemaConstants {
public static final String POLICY_CONSTRAINTS_AFTER_KEY = "PolicyConstraints.after";
public static final String TECHNICAL_OBJECT_SPECIFICATION_KEY = "TechnicalObjectSpecification";
public static final String OBJECT_SPECIFICATION_KEY = "ObjectSpecification";
public static final String OBJECT_SPECIFICATION_WITH_PATH_KEY = "ObjectSpecificationWithPath";
public static final String POLICY_VIOLATION_EXCEPTION_AGGREGATE_KEY = "PolicyViolationException.message.aggregate";

// // resetPassword
Expand Down
Expand Up @@ -36,6 +36,7 @@ public class LocalizationUtil {
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(
SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH);

// consider using LocalizationService instead
public static String resolve(String key) {
if (key != null && RESOURCE_BUNDLE.containsKey(key)) {
return RESOURCE_BUNDLE.getString(key);
Expand All @@ -44,6 +45,7 @@ public static String resolve(String key) {
}
}

// consider using LocalizationService instead
public static String resolve(String key, Object... params ) {
if (key != null && RESOURCE_BUNDLE.containsKey(key)) {
return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params);
Expand Down
Expand Up @@ -748,11 +748,11 @@ public static void mergeExtension(PrismContainerValue<?> dstExtensionContainerVa
}
}

public static LocalizableMessage createTechnicalObjectSpecification(PrismObject<?> object) {
public static LocalizableMessage createTechnicalObjectSpecification(PrismObject<?> object, boolean startsWithUppercase) {
if (object != null) {
return new LocalizableMessageBuilder()
.key(SchemaConstants.TECHNICAL_OBJECT_SPECIFICATION_KEY)
.arg(createObjectTypeSpecification(object.asObjectable().getClass().getSimpleName()))
.arg(createObjectTypeSpecification(object.asObjectable().getClass().getSimpleName(), startsWithUppercase))
.arg(object.asObjectable().getName())
.arg(object.getOid())
.build();
Expand All @@ -761,25 +761,39 @@ public static LocalizableMessage createTechnicalObjectSpecification(PrismObject<
}
}

public static LocalizableMessage createObjectSpecification(PrismObject<?> object) {
public static LocalizableMessage createObjectSpecification(PrismObject<?> object, boolean startsWithUppercase) {
if (object != null) {
return new LocalizableMessageBuilder()
.key(SchemaConstants.OBJECT_SPECIFICATION_KEY)
.arg(createObjectTypeSpecification(object.asObjectable().getClass().getSimpleName()))
.arg(createObjectTypeSpecification(object.asObjectable().getClass().getSimpleName(), startsWithUppercase))
.arg(object.asObjectable().getName())
.build();
} else {
return LocalizableMessageBuilder.buildFallbackMessage("?"); // should not really occur!
}
}

public static LocalizableMessage createObjectTypeSpecification(QName type) {
return createObjectTypeSpecification(type != null ? type.getLocalPart() : null);
public static LocalizableMessage createObjectSpecificationWithPath(PrismObject<?> object, boolean startsWithUppercase, String path) {
if (object != null) {
return new LocalizableMessageBuilder()
.key(SchemaConstants.OBJECT_SPECIFICATION_WITH_PATH_KEY)
.arg(createObjectTypeSpecification(object.asObjectable().getClass().getSimpleName(), startsWithUppercase))
.arg(object.asObjectable().getName())
.arg(path)
.build();
} else {
return LocalizableMessageBuilder.buildFallbackMessage("?"); // should not really occur!
}
}

public static LocalizableMessage createObjectTypeSpecification(QName type, boolean startsWithUppercase) {
return createObjectTypeSpecification(type != null ? type.getLocalPart() : null, startsWithUppercase);
}

public static LocalizableMessage createObjectTypeSpecification(String objectClassName) {
public static LocalizableMessage createObjectTypeSpecification(String objectClassName, boolean startsWithUppercase) {
String prefix = startsWithUppercase ? SchemaConstants.OBJECT_TYPE_KEY_PREFIX : SchemaConstants.OBJECT_TYPE_LOWERCASE_KEY_PREFIX;
return new LocalizableMessageBuilder()
.key(SchemaConstants.OBJECT_TYPE_LOWERCASE_KEY_PREFIX + objectClassName)
.key(prefix + objectClassName)
.fallbackMessage(objectClassName)
.build();
}
Expand Down

0 comments on commit 1416feb

Please sign in to comment.