• Exécutez le script suivant pour migrer le service Carte. Réconstruisez le workspace Live ensuite.

      function __convertStringPropertyToLong(node, propertyName) 
      { 
        var hasChanged = false; 
        if (node.hasProperty(propertyName)) 
        { 
          var property = node.getProperty(propertyName); 
          if (property.getType() == 1) // 1 is for string 
          { 
            var valueAsString = property.getString(); 
            property.remove(); 
       
            if (valueAsString) 
            { 
              node['setProperty(java.lang.String, long)'](propertyName, Number(valueAsString)); 
              hasChanged = true; 
            } 
          } 
        } 
        return hasChanged; 
      }
      
      function __convertGeocodeProperties(node, latitudePropertyName, longitudePropertyName, newNodeName)
      {
        var hasChanged = false;
       
        if (node.hasProperty(latitudePropertyName) && node.hasProperty(longitudePropertyName))
        {
          var latitudeProperty = node.getProperty(latitudePropertyName);
          var longitudeProperty = node.getProperty(longitudePropertyName);
          if (latitudeProperty.getType() == 4 && longitudeProperty.getType() == 4) // 4 is for double
          {
            var latitude = latitudeProperty.getDouble();
            var longitude = longitudeProperty.getDouble();
      
            latitudeProperty.remove();
            longitudeProperty.remove();
      
            var nodeWithNewProperties = node;
            if (newNodeName)
            {
              nodeWithNewProperties = node.addNode('ametys:' + newNodeName, 'ametys:compositeMetadata');
            }
            nodeWithNewProperties['setProperty(java.lang.String, double)']('ametys:latitude', latitude);
            nodeWithNewProperties['setProperty(java.lang.String, double)']('ametys:longitude', longitude);
      
            hasChanged = true;
          }
        }
        return hasChanged;
      }
      
      function __renameVertexNode(node)
      {
        // Get the actual number of the vertex node (examples: 0001, 0025, 1258)
        var vertexActualNumber = node.getName().substring('ametys:point-'.length);
       
        // Get the new number of the vertex node (examples: 1, 25, 1258)
        var vertexNewNumber = vertexActualNumber.substring(vertexActualNumber.lastIndexOf('0') + 1);
       
        // Rename the node from ametys:point-000x to ametys:x
        return __renameNode(node, vertexNewNumber);
      }
      
      function __renameNode(node, newName)
      {
        var hasChanged = false;
        if (newName != node.getName())
        {
          session.move(node.getPath(), node.getParent().getPath() + '/ametys:' + newName);
          hasChanged = true;
        }
        return hasChanged;
      }
       
      function migrateMapsService() 
      {
        var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = 'org.ametys.plugins.maps.services.Maps']", javax.jcr.query.Query.XPATH);
        var nodes = query.execute().getNodes();
        var count = 0;
       
        var hasChanges = false;
        while (nodes.hasNext()) 
        {
          var paramsNode = nodes.nextNode().getNode("ametys:service_parameters");
       
          // Converts the height parameters from String to Long
          hasChanges = __convertStringPropertyToLong(paramsNode, "ametys:height") || hasChanges;
       
          // Converts the centerLat and centerLng properties to create a geocode node named center
          hasChanges = __convertGeocodeProperties(paramsNode, 'ametys:centerLat', 'ametys:centerLng', 'center') || hasChanges;
       
          if (paramsNode.hasNode('ametys:pois'))
          {
            var poisNode = paramsNode.getNode('ametys:pois');
       
            // Iterate on points of interest
            var poisNodes = poisNode.getNodes('ametys:poi-*');
            while (poisNodes.hasNext())
            {
              var poiNode = poisNodes.nextNode();
       
              var poiType = poiNode.getProperty('ametys:type').getString();
              if ('marker' == poiType)
              {
                // For markers, just convert the lat and lng properties to create a geocode node named point
                hasChanges = __convertGeocodeProperties(poiNode, 'ametys:lat', 'ametys:lng', 'point') || hasCHanges;
              }
              else if ('polygon' == poiType)
              {
                var pointsNode = poiNode.getNode('ametys:points');
       
                // Change the type of the points node
                pointsNode.setPrimaryType('ametys:multipleItem');
                pointsNode.setProperty('ametys-internal:typeId', 'geocode');
       
                // Iterate on polygon's vertex nodes
                var vertexesNodes = pointsNode.getNodes();
                while (vertexesNodes.hasNext())
                {
                  var vertexNode = vertexesNodes.nextNode();
      
                  // Converts the lat and lng properties to rename them and fit to a geocode node
                  hasChanges = __convertGeocodeProperties(vertexNode, 'ametys:lat', 'ametys:lng') || hasChanges;
       
                  // Rename the vertex node from ametys:point-000x to ametys:x
                  hasChanges = __renameVertexNode(vertexNode) || hasChanges;
                }
              }
              else
              {
                // Should not happen, do nothing
              }
       
              // Rename the point of interest node from ametys:poi-x to ametys:x
              hasChanges = __renameNode(poiNode, poiNode.getName().substring('ametys:poi-'.length)) || hasChanges;
            }
       
            // Rename the points of interest node from ametys:pois to ametys:pointsOfInterest
            hasChanges = __renameNode(poisNode, 'pointsOfInterest') || hasChanges;
          }
       
          if (hasChanges) 
          { 
            count++; 
          } 
        } 
       
        if (count > 0) 
        { 
          session.save(); 
          print(count + " maps services have been migrated."); 
        } 
      }
       
      var qm = session.getWorkspace().getQueryManager();
      migrateMapsService();
       
      print("End of migration, you can rebuild the Live workspace");
Retour en haut