Class 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
    • Field Detail

      • locales

        protected final List<Locale> locales
        The locales this check report should provide.
      • locFac

        protected transient LocalisationFactory locFac
        The localisation factory which to use for localising attributes from model elements. If this is null, 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 are null, use a CheckReport instead. This also applies when using only Locale.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 is null, 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 a CheckReport 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 or null 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 given reportEntryType.
        Overrides:
        addReportEntry in class CheckReport
        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 designated reportEntryType.
        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.
      • 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.
      • 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 a LocalisedCheckReport unless for one locale without an localisation factory or for the root locale only. In this case it will be a simple CheckReport.
        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 is null, model elements will not be localised.
        locales - The locale(s) the created check report should provide. This may be null.
        Returns:
        A LocalisedCheckReport for several locales, a simple CheckReport 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 a CheckReport having only one preferred localisation and a LocalisedCheckReport 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 using String.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 of LocalisedString. Use different msgKeys 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 is null 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 using String.format(Locale, String, Object...).
        Returns:
        The requested localised message.
        See Also:
        LocalisationTools.getLocalisedMessage(String, Locale, Function, LocalisationFactory, LocalisedString...)