1 Reply Latest reply on Aug 5, 2013 4:54 AM by Ivan Vasyliev

    Content mirroring into federation

    Ivan Vasyliev Newbie

      I have requirement to do some sort of mirroring: when content got to modeshape - copy or move it (depending on conditions) to federation:

      1. When user uploaded PDF, based on folder, send this document to FTP for printing (assuming another software listens on FTP

      2. For some sorts of PDF's (based on folder or node types) - move them completely into SAN/external CMIS repo for archival.

       

      I've tried to use sequencers, but it looks that sequencers are not suitable for this kind of use cases, so I'm thinking to use ObservationManager and I would love to configure mirroring (event listeners) via modeshape JSON (like configuration for sequencers), do you see any issues/possibilities if I'l try to plug event listeners somewhere to modeshape json? Can I have some place in json where I can plug my own config for "source path OR node type" + "copy/move listener" + "target path"?

       

      Another trouble I've got - when content "moved" into federation, ID is changed, so if client has an ID - it would be not valid anymore and assuming my node has mix:referenceable this is not according JCR spec...

      What I'm thinking - is to add artificial property into medadata like jcr:uuid and ignore real ID from underlying repo, then handle jcr:uuid via search instead of getting nodes by ID. Well, first try to get by ID and if not found - search and use uuid from metadata as an ID.

        • 1. Re: Content mirroring into federation
          Ivan Vasyliev Newbie

          Use of sequencers section to plug custom code (not listeners so far, but I assume with listeners there will be no issues):

           

          Example:

           

          {code:json}

          "sequencers" : {

          "extension1" :

          { "classname" : "", "extensionClass" : "com.acme.IdHandlerExtension", "isExtension" : "true", "targetType" : "", "targetProperty" : "" }

          ,

          "extension2" :

          { "classname" : "", "extensionClass" : "com.acme.IdHandlerExtension", "isExtension" : "true", "targetType" : "", "targetProperty" : "" }

          }

          {code}

           

          And java to extract config:

           

          {code:java}

              /** Extract all extension configurations

               *

               * @return boolean true if configuration was changed

               */

              private boolean getExtensionConfiguration(RepositoryConfiguration configuration) {

                  extensionConfigurationParams.clear();

                  RepositoryConfiguration.Sequencing sequencing = configuration.getSequencing();

                  if (sequencing == null) {

                      return false;

                  }

                  List<RepositoryConfiguration.Component> sequencersList =  sequencing.getSequencers();

                  if (sequencersList == null ) {

                      return false;

                  }

                  boolean result = false;

                  int listSize = sequencersList.size();

                  for (int i = 0; listSize > i; i++) {

                      RepositoryConfiguration.Component component = sequencersList.get(i);

                      if (component == null) {

                          continue;

                      }

                      Document document = component.getDocument();

                      if (document == null) {

                          continue;

                      }

                      //  if don't have extension flag => skip

                      if (! document.containsField(CONFIGURATION_EXTENSION_FLAG_NAME)) {

                          continue;

                      }

                      //  if extension flag is NOT TRUE (flag == false) => skip

                      if (!document.getString(CONFIGURATION_EXTENSION_FLAG_NAME).equalsIgnoreCase("true")) {

                          continue;

                      }

                      // if unknown extension (extension class name not defined) => skip

                      if (! document.containsField(CONFIGURATION_EXTENSION_CLASSNAME)) {

                          continue;

                      }

                      // if empty extension class name => skip

                      if (document.getString(CONFIGURATION_EXTENSION_CLASSNAME).trim().equals("")) {

                          continue;

                      }

                      String extensionName = component.getName();

                      // if empty extension name => skip

                      if (extensionName.trim().equals("")) {

                          continue;

                      }

                      // if this extension name already exists in configuration => skip

                      if (extensionConfigurationParams.containsKey(extensionName)) {

                          continue;

                      }

                      Map<String, String> extensionProperties = new HashMap<String, String>();

                      Iterator<Document.Field> fieldsIterator = document.fields().iterator();

                      while(fieldsIterator.hasNext()) {

                          Document.Field field = fieldsIterator.next();

                          String fieldName = field.getName();

                          if (extensionProperties.containsKey(fieldName)) {

                              LOG.warn("Duplicated configuration value in: ' " + extensionName + " value name: '" + fieldName +"'" );

                              continue;

                          }

                          try {

                              extensionProperties.put(fieldName, field.getValueAsString());

                          } catch (IllegalFormatConversionException e) {

                              LOG.debug("Conversion error during configuration reading: " + e.getMessage());

                          }

                      }

                      //  Save extension configuration

                      extensionConfigurationParams.put(extensionName, extensionProperties);

                      result = true;

                  }

                  return result;

              }

          {code}