Class OlapQueryIdPatch

java.lang.Object
org.alfresco.repo.admin.patch.AbstractPatch
fr.becpg.repo.admin.patch.AbstractBeCPGPatch
fr.becpg.repo.admin.patch.OlapQueryIdPatch
All Implemented Interfaces:
org.alfresco.repo.admin.patch.Patch, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationEventPublisherAware

public class OlapQueryIdPatch extends AbstractBeCPGPatch
Gives the OLAP queries, dashboards and applications already installed the technical id they now carry, so that nothing keeps identifying them by a translated label.

#24931: before this patch a resource was identified by its file name, which beCPG shipped translated. Renaming the files therefore had to come with a migration, or every reference would break at once and without a trace: a dashboard would point at a query that no longer exists, and the Share dashlet would find nothing behind the query id stored in each user's preferences.

The three are migrated together and in that order, since the mapping from the old identity to the new one is built while walking the folder:

  1. every installed resource receives bcpg:olapQueryId and a cm:title in every language shipped, its name being left untouched;
  2. the dashboards and applications have their query references rewritten to those ids;
  3. the OLAP dashlet preference of every user is rewritten to the same ids.

A query a user saved from Saiku carries no id: it is left exactly as it is, its name remaining its identity.

Author:
matthieu
  • Field Details

    • logger

      private static final org.apache.commons.logging.Log logger
    • MSG_SUCCESS

      private static final String MSG_SUCCESS
      See Also:
    • LABEL_BUNDLE

      private static final String LABEL_BUNDLE
      Bundle holding the shipped labels, keyed by technical id.
      See Also:
    • LABEL_KEY_PREFIX

      private static final String LABEL_KEY_PREFIX
      See Also:
    • PREFERENCE_ROOT

      private static final String PREFERENCE_ROOT
      Preference holding the query selected in an OLAP dashlet, one per dashlet region.
      See Also:
    • PREFERENCE_QUERY_SUFFIX

      private static final String PREFERENCE_QUERY_SUFFIX
      See Also:
    • REFERENCE_PREFIX

      private static final String REFERENCE_PREFIX
      See Also:
    • contentService

      private org.alfresco.service.cmr.repository.ContentService contentService
    • preferenceService

      private org.alfresco.service.cmr.preference.PreferenceService preferenceService
    • personService

      private org.alfresco.service.cmr.security.PersonService personService
  • Constructor Details

    • OlapQueryIdPatch

      public OlapQueryIdPatch()
  • Method Details

    • setContentService

      public void setContentService(org.alfresco.service.cmr.repository.ContentService contentService)

      Setter for the field contentService.

      Parameters:
      contentService - a ContentService object
    • setPreferenceService

      public void setPreferenceService(org.alfresco.service.cmr.preference.PreferenceService preferenceService)

      Setter for the field preferenceService.

      Parameters:
      preferenceService - a PreferenceService object
    • setPersonService

      public void setPersonService(org.alfresco.service.cmr.security.PersonService personService)

      Setter for the field personService.

      Parameters:
      personService - a PersonService object
    • applyInternal

      protected String applyInternal() throws Exception
      Specified by:
      applyInternal in class org.alfresco.repo.admin.patch.AbstractPatch
      Throws:
      Exception
    • stampTechnicalIds

      private int stampTechnicalIds(org.alfresco.service.cmr.repository.NodeRef folderNodeRef, Map<String,String> idByLabel, Map<String,String> idByOldIdentity)
      Stamps every installed resource that beCPG ships with its technical id and its translated title, and records what that resource used to be identified by.
      Parameters:
      folderNodeRef - the shared OLAP query folder
      idByLabel - the technical id of every shipped label, in every language shipped
      idByOldIdentity - filled with the old identities the resource answered to
      Returns:
      the number of resources stamped
    • recordOldIdentities

      private void recordOldIdentities(org.alfresco.service.cmr.repository.NodeRef nodeRef, String label, String olapQueryId, Map<String,String> idByOldIdentity)
      Records the identities a resource used to answer to: its translated name, and the query id its content declares, which the Share dashlet stored in the user preferences.
      Parameters:
      nodeRef - the resource being migrated
      label - its name, extension stripped
      olapQueryId - the technical id it now carries
      idByOldIdentity - the mapping to fill
    • rewriteReferences

      private int rewriteReferences(org.alfresco.service.cmr.repository.NodeRef folderNodeRef, Map<String,String> idByOldIdentity)
      Rewrites the query references a dashboard or an application holds, which used to be the translated file name of the query.
      Parameters:
      folderNodeRef - the shared OLAP query folder
      idByOldIdentity - the mapping from the old identity to the technical id
      Returns:
      the number of documents rewritten
    • rewriteDocumentReferences

      private boolean rewriteDocumentReferences(org.alfresco.service.cmr.repository.NodeRef nodeRef, Map<String,String> idByOldIdentity)
    • rewritePreferences

      private int rewritePreferences(Map<String,String> idByOldIdentity)
      Rewrites the OLAP dashlet preference of every user, which holds the query id it must select.

      A preference pointing at something no longer shipped is left untouched: the dashlet falls back to its first query, which is a better outcome than silently choosing another one. When nothing was migrated there is nothing to rewrite either, and the users are not walked at all.

      Parameters:
      idByOldIdentity - the mapping from the old identity to the technical id
      Returns:
      the number of preferences rewritten
    • rewritePreferences

      private int rewritePreferences(String userName, Map<String,String> idByOldIdentity)
    • indexIdByLabel

      private Map<String,String> indexIdByLabel()
      Indexes the technical id of every shipped resource by the label it carries, in every language shipped: an instance installed in French must be recognised from its French names.
      Returns:
      the technical id of every known label
    • setTitles

      private void setTitles(org.alfresco.service.cmr.repository.NodeRef nodeRef, String olapQueryId)
      Writes the multilingual title of a migrated resource.

      Without the ML-aware flag the interceptor keeps only the value of the current locale, and every other language is lost on the way in.

      Parameters:
      nodeRef - the resource being migrated
      olapQueryId - its technical id
    • bundleFor

      private static ResourceBundle bundleFor(Locale locale)
      Loads the label bundle of a locale, or null when no module on the classpath ships one, which is the case of a repository installed without the PLM module.
      Parameters:
      locale - the locale to load
      Returns:
      the bundle, or null
    • stripExtension

      private static String stripExtension(String name)