Class LocalisedCheckReport
- java.lang.Object
-
- de.aristaflow.adept2.util.CheckReport
-
- de.aristaflow.adept2.model.common.LocalisedCheckReport
-
- All Implemented Interfaces:
Serializable
public class LocalisedCheckReport extends CheckReport
A check report extension providing localised messages. The check report itself has a set of preferred locales which should be considered when adding a report entry.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LocalisedCheckReport.LocalisedReportEntry
A report entry extension providing localised messages.-
Nested classes/interfaces inherited from class de.aristaflow.adept2.util.CheckReport
CheckReport.ReportEntry, CheckReport.ResultType
-
-
Field Summary
Fields Modifier and Type Field Description protected List<Locale>
locales
The locales this check report should provide.protected LocalisationFactory
locFac
The localisation factory which to use for localising attributes from model elements.-
Fields inherited from class de.aristaflow.adept2.util.CheckReport
locale, nextEntryNumber, reportEntries
-
-
Constructor Summary
Constructors Constructor Description LocalisedCheckReport(URI base, LocalisationFactory locFac, Locale... locales)
Creates a localised check report for the designated base URI providing the designated locales (and their fallbacks) using the designated localisation factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addLocalisedReportEntry(CheckReport report, String checkId, CheckReport.ResultType reportEntryType, URI[] affectedElements, String msgKey, Function<Locale,Messages> provider, LocalisedString... args)
Adds a report entry with a localised message/with localised messages to the designated check report.void
addReportEntry(String checkID, CheckReport.ResultType reportEntryType, String defaultMessage, URI... affElems)
Adds a new entry to the report.void
addReportEntry(String checkID, CheckReport.ResultType reportEntryType, String defaultMessage, Map<Locale,String> localisedMessage, URI... affElems)
Adds a new localisable entry to the report.static CheckReport
createLocalisedCheckReport(URI base, LocalisationFactory locFac, Locale... locales)
Convenience method for creating a check report respecting localisation.List<? extends LocalisedCheckReport.LocalisedReportEntry>
getEntriesForCheckID(String checkID)
Returns all check report entries which do have the given checkIDLocalisedCheckReport.LocalisedReportEntry
getLastAddedReportEntry()
Returns the last added report entryLocalisationFactory
getLocalisationFactory()
Gets the localisation factory which to use for localising attributes from model elements ornull
if model elements should not be localised.static String
getLocalisedMessage(String msgKey, Locale locale, Function<Locale,Messages> provider, CheckReport report, LocalisedString... args)
Gets the localised message for the designated message key from the designated messages.List<Locale>
getPreferredLocales()
Gets the locales this check report should provide (or at least a fallback for each of the locales).List<? extends LocalisedCheckReport.LocalisedReportEntry>
getReportEntries()
Returns all report entries that keep the output of the different checks and are assigned to the check report.String
getReportSummary(Locale loc)
Gets a report summary of all check report entries using the designated locale for all messages.String
getSimpleReportSummary(Locale loc)
Gets a report summary of all warning and failure check report entries using the designated locale for all messages.void
printReportSummary(Locale loc)
Prints the report summary to STDOUT using the designated locale.void
setLocalisationFactory(LocalisationFactory locFac)
Sets the localisation factory if it is not set yet.-
Methods inherited from class de.aristaflow.adept2.util.CheckReport
addReportEntry, getBase, getCheckResult, getPreferredLocale, getReportSummary, getSimpleReportSummary, isFailure, printReportSummary
-
-
-
-
Field Detail
-
locFac
protected transient LocalisationFactory locFac
The localisation factory which to use for localising attributes from model elements. If this isnull
, model elements will not be localised.
-
-
Constructor Detail
-
LocalisedCheckReport
public LocalisedCheckReport(URI base, LocalisationFactory locFac, Locale... locales)
Creates a localised check report for the designated base URI providing the designated locales (and their fallbacks) using the designated localisation factory. If either the localisation factory or the locales arenull
, use aCheckReport
instead. This also applies when using onlyLocale.ROOT
.- Parameters:
base
- The process element identifier URI of the template or instance this check report is assigned to.locFac
- The localisation factory which to use for localising attributes from model elements. If this isnull
, model elements will not be localised.locales
- The locales this check report should provide. This must not be empty; if you do not need locales, use aCheckReport
instead.
-
-
Method Detail
-
getPreferredLocales
public List<Locale> getPreferredLocales()
Gets the locales this check report should provide (or at least a fallback for each of the locales).- Returns:
- The locales this check report should provide (or at least a fallback for each of the locales).
-
getLocalisationFactory
public LocalisationFactory getLocalisationFactory()
Gets the localisation factory which to use for localising attributes from model elements ornull
if model elements should not be localised.- Returns:
- The localisation factory which to use for localising attributes from model elements or
null
if model elements should not be localised.
-
addReportEntry
public void addReportEntry(String checkID, CheckReport.ResultType reportEntryType, String defaultMessage, URI... affElems)
Description copied from class:CheckReport
Adds a new entry to the report. Besides, the overall result of the report is adjusted accordingly to the givenreportEntryType
.- Overrides:
addReportEntry
in classCheckReport
- Parameters:
checkID
- The identifier of the check that generates this report entry.reportEntryType
- The severity of this report item.defaultMessage
- The message to report.affElems
- The process element identifier URIs of the process elements affected by this report entry.
-
addReportEntry
public void addReportEntry(String checkID, CheckReport.ResultType reportEntryType, String defaultMessage, Map<Locale,String> localisedMessage, URI... affElems)
Adds a new localisable entry to the report. Besides, the overall result of the report is adjusted accordingly to the designatedreportEntryType
.- Parameters:
checkID
- The identifier of the check that generates this report entry.reportEntryType
- The severity of this report item.defaultMessage
- The default message used if no corresponding localisation is found.localisedMessage
- The localised message for the corresponding locale. This should contain all preferred locales (or at least the corresponding fallbacks) of the check report.affElems
- The process element identifier URIs of the process elements affected by this report entry.
-
getReportEntries
public List<? extends LocalisedCheckReport.LocalisedReportEntry> getReportEntries()
Description copied from class:CheckReport
Returns all report entries that keep the output of the different checks and are assigned to the check report.- Overrides:
getReportEntries
in classCheckReport
- Returns:
- list of all report entries
-
getReportSummary
public String getReportSummary(Locale loc)
Gets a report summary of all check report entries using the designated locale for all messages.- Parameters:
loc
- The locale which to use for the messages in the report summary.- Returns:
- A textual summary of all entries.
- See Also:
CheckReport.getReportSummary()
-
getSimpleReportSummary
public String getSimpleReportSummary(Locale loc)
Gets a report summary of all warning and failure check report entries using the designated locale for all messages.- Parameters:
loc
- The locale which to use for the messages in the simple report summary.- Returns:
- A textual summary of all warning and failure entries.
- See Also:
CheckReport.getSimpleReportSummary()
-
printReportSummary
public void printReportSummary(Locale loc)
Prints the report summary to STDOUT using the designated locale.- Parameters:
loc
- The locale which to use for the printed messages.
-
getEntriesForCheckID
public List<? extends LocalisedCheckReport.LocalisedReportEntry> getEntriesForCheckID(String checkID)
Description copied from class:CheckReport
Returns all check report entries which do have the given checkID- Overrides:
getEntriesForCheckID
in classCheckReport
- Returns:
- check report entries or null if the check report does not contain any entries for the given id
-
getLastAddedReportEntry
public LocalisedCheckReport.LocalisedReportEntry getLastAddedReportEntry()
Description copied from class:CheckReport
Returns the last added report entry- Overrides:
getLastAddedReportEntry
in classCheckReport
- Returns:
- last added reportEntry or null if no entry exists till now.
-
setLocalisationFactory
public void setLocalisationFactory(LocalisationFactory locFac)
Sets the localisation factory if it is not set yet.
The localisation factory is set in the constructor but it is not serialised. Therefore when adding new report entries requiring localisation after deserialising the check report make sure you have set the localisation factory (again).- Parameters:
locFac
- The localisation factory to be set for this check report.
-
createLocalisedCheckReport
public static CheckReport createLocalisedCheckReport(URI base, LocalisationFactory locFac, Locale... locales)
Convenience method for creating a check report respecting localisation. This will usually be aLocalisedCheckReport
unless for one locale without an localisation factory or for the root locale only. In this case it will be a simpleCheckReport
.- Parameters:
base
- The process element identifier URI of the template or instance this check report is assigned to.locFac
- The localisation factory which to use for localising attributes from model elements. If this isnull
, model elements will not be localised.locales
- The locale(s) the created check report should provide. This may benull
.- Returns:
- A
LocalisedCheckReport
for several locales, a simpleCheckReport
for one or no specific locale.
-
addLocalisedReportEntry
public static void addLocalisedReportEntry(CheckReport report, String checkId, CheckReport.ResultType reportEntryType, URI[] affectedElements, String msgKey, Function<Locale,Messages> provider, LocalisedString... args)
Adds a report entry with a localised message/with localised messages to the designated check report. This distinguishes between aCheckReport
having only one preferred localisation and aLocalisedCheckReport
having several preferred localisations.- Parameters:
report
- The check report to which to add a localised report entry.checkId
- The ID of the check that generates this report entry.reportEntryType
- The severity of this report item.affectedElements
- The (URIs of the) affected elements that caused the report entry.msgKey
- The message key with which to retrieve the localisation from the messages.provider
- The provider for the localised messages.args
- Optional arguments passed to the corresponding localised message usingString.format(Locale, String, Object...)
. Make sure that only model elements or variables from the calling context need late localisation. Do not try to localise simple strings that belong to the message body. For instance, "input parameter" or "output parameter" need to be localised in the messages not by the means ofLocalisedString
. Use differentmsgKey
s for such cases.
-
getLocalisedMessage
public static String getLocalisedMessage(String msgKey, Locale locale, Function<Locale,Messages> provider, CheckReport report, LocalisedString... args)
Gets the localised message for the designated message key from the designated messages. The designated localised strings will be resolved and merged with the message for the designated message key from the messages. The resulting localised message is then returned. This may be a fallback locale for the requested locale.- Parameters:
msgKey
- The message key with which to retrieve the localisation from the messages.provider
- The provider for the localised messages.locale
- The locale for which to retrieve the localisation for the designated message key.report
- The check report providing the localisation factory. If the check report isnull
or does not provide one, no special localisation will be applied to the strings.args
- Optional arguments localised and afterwards passed to the corresponding localised message usingString.format(Locale, String, Object...)
.- Returns:
- The requested localised message.
- See Also:
LocalisationTools.getLocalisedMessage(String, Locale, Function, LocalisationFactory, LocalisedString...)
-
-