Run the following script to migrate all your project space services.
Then rebuild the Live workspace.
function __getWorkspacesServicesNodes(serviceId)
{
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = 'org.ametys.plugins.workspaces." + serviceId + "']", javax.jcr.query.Query.XPATH);
return query.execute().getNodes();
}
function __migrateService(node, params)
{
var paramsNode = node.getNode("ametys:service_parameters");
var hasChanges = false;
for (var name in params)
{
var hasChanges = false;
var type = params[name];
if (type == 'long')
{
hasChanges = __convertStringPropertyToLong(paramsNode, "ametys:" + name) || hasChanges;
}
else if (type == 'boolean')
{
hasChanges = __convertStringPropertyToBoolean(paramsNode, "ametys:" + name) || hasChanges;
}
}
return hasChanges;
}
function __convertStringPropertyToBoolean(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 == "true")
{
node['setProperty(java.lang.String, boolean)'](propertyName, true);
hasChanged = true;
}
else if (valueAsString == "false")
{
node['setProperty(java.lang.String, boolean)'](propertyName, false);
hasChanged = true;
}
}
}
return hasChanged;
}
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 migrateTasksService()
{
var params = {'assigned-to-current-user': 'boolean', 'max-results': 'long', 'results-per-page': 'long', 'enable-add-task': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.Tasks');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " tasks services have been migrated.");
}
}
function migrateFilteredEventsService()
{
var params = {'max-results': 'long', 'results-per-page': 'long', 'search-period': 'long', 'enable-creation': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.FilteredEvents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " filtered events services have been migrated.");
}
}
function migrateProjectsCatalogueService()
{
var params = {'memberOnly': 'boolean', 'use_old_categories_system': 'boolean', 'display_restricted_pages': 'boolean', 'ping_activated': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.ProjectsCatalogue');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " projects catalogue services have been migrated.");
}
}
function migrateActivityStreamService()
{
var params = {'activities-per-page': 'long', 'max-activities': 'long', 'chronological-order': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.ActivityStream');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " activity stream services have been migrated.");
}
}
function migrateMembersService()
{
var params = {'nbMembers': 'long', 'expandGroup': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.Members');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " members services have been migrated.");
}
}
function migrateModuleMembersService()
{
var params = {'results-per-page': 'long'};
var nodes = __getWorkspacesServicesNodes('module.Members');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " module members services have been migrated.");
}
}
function migrateSimpleFilteredEventsService()
{
var params = {'max-results': 'long', 'search-period': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.FilteredEvents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple filtered events services have been migrated.");
}
}
function migrateSimpleTasksService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.Tasks');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple tasks services have been migrated.");
}
}
function migrateSimpleDocumentsService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.Documents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple documents services have been migrated.");
}
}
function migrateSimpleProjectsCatalogueService()
{
var params = {'max-results': 'long', 'memberOnly': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.simple.ProjectsCatalogue');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple projects catalogue services have been migrated.");
}
}
function migrateSimpleActivityStreamService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.ActivityStream');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple activity stream services have been migrated.");
}
}
function migrateProjectManagers()
{
var query = qm.createQuery("//element(*, ametys:project)", javax.jcr.query.Query.XPATH);
var projectNodes = query.execute().getNodes();
var count = 0;
while (projectNodes.hasNext())
{
var hasChanged = false;
var projectNode = projectNodes.nextNode();
var managersNodeName = 'ametys:managers';
if (!projectNode.hasNode(managersNodeName))
{
var managersNode = projectNode.addNode(managersNodeName, 'ametys:multipleItem');
managersNode.setProperty('ametys-internal:typeId', 'user');
hasChanged = true;
}
var managerNodeName = 'ametys:manager';
if (projectNode.hasNode(managerNodeName))
{
var managerNodes = projectNode.getNodes(managerNodeName);
var index = 1;
while (managerNodes.hasNext())
{
var managerNode = managerNodes.nextNode();
session.move(managerNode.getPath(), managerNode.getParent().getPath() + '/' + managersNodeName + '/ametys:' + index++);
}
hasChanged = true;
}
if (hasChanged)
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " workspace projects have been migrated.");
}
}
var qm = session.getWorkspace().getQueryManager();
migrateTasksService();
migrateFilteredEventsService();
migrateProjectsCatalogueService();
migrateActivityStreamService();
migrateMembersService();
migrateModuleMembersService();
migrateSimpleFilteredEventsService();
migrateSimpleTasksService();
migrateSimpleDocumentsService();
migrateSimpleProjectsCatalogueService();
migrateSimpleActivityStreamService();
migrateProjectManagers();
print("End of migration, you can rebuild the Live workspace");
function __getWorkspacesServicesNodes(serviceId)
{
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = 'org.ametys.plugins.workspaces." + serviceId + "']", javax.jcr.query.Query.XPATH);
return query.execute().getNodes();
}
function __migrateService(node, params)
{
var paramsNode = node.getNode("ametys:service_parameters");
var hasChanges = false;
for (var name in params)
{
var hasChanges = false;
var type = params[name];
if (type == 'long')
{
hasChanges = __convertStringPropertyToLong(paramsNode, "ametys:" + name) || hasChanges;
}
else if (type == 'boolean')
{
hasChanges = __convertStringPropertyToBoolean(paramsNode, "ametys:" + name) || hasChanges;
}
}
return hasChanges;
}
function __convertStringPropertyToBoolean(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 == "true")
{
node['setProperty(java.lang.String, boolean)'](propertyName, true);
hasChanged = true;
}
else if (valueAsString == "false")
{
node['setProperty(java.lang.String, boolean)'](propertyName, false);
hasChanged = true;
}
}
}
return hasChanged;
}
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 migrateTasksService()
{
var params = {'assigned-to-current-user': 'boolean', 'max-results': 'long', 'results-per-page': 'long', 'enable-add-task': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.Tasks');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " tasks services have been migrated.");
}
}
function migrateFilteredEventsService()
{
var params = {'max-results': 'long', 'results-per-page': 'long', 'search-period': 'long', 'enable-creation': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.FilteredEvents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " filtered events services have been migrated.");
}
}
function migrateProjectsCatalogueService()
{
var params = {'memberOnly': 'boolean', 'use_old_categories_system': 'boolean', 'display_restricted_pages': 'boolean', 'ping_activated': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.ProjectsCatalogue');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " projects catalogue services have been migrated.");
}
}
function migrateActivityStreamService()
{
var params = {'activities-per-page': 'long', 'max-activities': 'long', 'chronological-order': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.ActivityStream');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " activity stream services have been migrated.");
}
}
function migrateMembersService()
{
var params = {'nbMembers': 'long', 'expandGroup': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.Members');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " members services have been migrated.");
}
}
function migrateModuleMembersService()
{
var params = {'results-per-page': 'long'};
var nodes = __getWorkspacesServicesNodes('module.Members');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " module members services have been migrated.");
}
}
function migrateSimpleFilteredEventsService()
{
var params = {'max-results': 'long', 'search-period': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.FilteredEvents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple filtered events services have been migrated.");
}
}
function migrateSimpleTasksService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.Tasks');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple tasks services have been migrated.");
}
}
function migrateSimpleDocumentsService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.Documents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple documents services have been migrated.");
}
}
function migrateSimpleProjectsCatalogueService()
{
var params = {'max-results': 'long', 'memberOnly': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.simple.ProjectsCatalogue');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple projects catalogue services have been migrated.");
}
}
function migrateSimpleActivityStreamService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.ActivityStream');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple activity stream services have been migrated.");
}
}
function migrateProjectManagers()
{
var query = qm.createQuery("//element(*, ametys:project)", javax.jcr.query.Query.XPATH);
var projectNodes = query.execute().getNodes();
var count = 0;
while (projectNodes.hasNext())
{
var hasChanged = false;
var projectNode = projectNodes.nextNode();
var managersNodeName = 'ametys:managers';
if (!projectNode.hasNode(managersNodeName))
{
var managersNode = projectNode.addNode(managersNodeName, 'ametys:multipleItem');
managersNode.setProperty('ametys-internal:typeId', 'user');
hasChanged = true;
}
var managerNodeName = 'ametys:manager';
if (projectNode.hasNode(managerNodeName))
{
var managerNodes = projectNode.getNodes(managerNodeName);
var index = 1;
while (managerNodes.hasNext())
{
var managerNode = managerNodes.nextNode();
session.move(managerNode.getPath(), managerNode.getParent().getPath() + '/' + managersNodeName + '/ametys:' + index++);
}
hasChanged = true;
}
if (hasChanged)
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " workspace projects have been migrated.");
}
}
var qm = session.getWorkspace().getQueryManager();
migrateTasksService();
migrateFilteredEventsService();
migrateProjectsCatalogueService();
migrateActivityStreamService();
migrateMembersService();
migrateModuleMembersService();
migrateSimpleFilteredEventsService();
migrateSimpleTasksService();
migrateSimpleDocumentsService();
migrateSimpleProjectsCatalogueService();
migrateSimpleActivityStreamService();
migrateProjectManagers();
print("End of migration, you can rebuild the Live workspace");
function __getWorkspacesServicesNodes(serviceId)
{
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = 'org.ametys.plugins.workspaces." + serviceId + "']", javax.jcr.query.Query.XPATH);
return query.execute().getNodes();
}
function __migrateService(node, params)
{
var paramsNode = node.getNode("ametys:service_parameters");
var hasChanges = false;
for (var name in params)
{
var hasChanges = false;
var type = params[name];
if (type == 'long')
{
hasChanges = __convertStringPropertyToLong(paramsNode, "ametys:" + name) || hasChanges;
}
else if (type == 'boolean')
{
hasChanges = __convertStringPropertyToBoolean(paramsNode, "ametys:" + name) || hasChanges;
}
}
return hasChanges;
}
function __convertStringPropertyToBoolean(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 == "true")
{
node['setProperty(java.lang.String, boolean)'](propertyName, true);
hasChanged = true;
}
else if (valueAsString == "false")
{
node['setProperty(java.lang.String, boolean)'](propertyName, false);
hasChanged = true;
}
}
}
return hasChanged;
}
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 migrateTasksService()
{
var params = {'assigned-to-current-user': 'boolean', 'max-results': 'long', 'results-per-page': 'long', 'enable-add-task': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.Tasks');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " tasks services have been migrated.");
}
}
function migrateFilteredEventsService()
{
var params = {'max-results': 'long', 'results-per-page': 'long', 'search-period': 'long', 'enable-creation': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.FilteredEvents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " filtered events services have been migrated.");
}
}
function migrateProjectsCatalogueService()
{
var params = {'memberOnly': 'boolean', 'use_old_categories_system': 'boolean', 'display_restricted_pages': 'boolean', 'ping_activated': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.ProjectsCatalogue');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " projects catalogue services have been migrated.");
}
}
function migrateActivityStreamService()
{
var params = {'activities-per-page': 'long', 'max-activities': 'long', 'chronological-order': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.ActivityStream');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " activity stream services have been migrated.");
}
}
function migrateMembersService()
{
var params = {'nbMembers': 'long', 'expandGroup': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.Members');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " members services have been migrated.");
}
}
function migrateModuleMembersService()
{
var params = {'results-per-page': 'long'};
var nodes = __getWorkspacesServicesNodes('module.Members');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " module members services have been migrated.");
}
}
function migrateSimpleFilteredEventsService()
{
var params = {'max-results': 'long', 'search-period': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.FilteredEvents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple filtered events services have been migrated.");
}
}
function migrateSimpleTasksService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.Tasks');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple tasks services have been migrated.");
}
}
function migrateSimpleDocumentsService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.Documents');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple documents services have been migrated.");
}
}
function migrateSimpleProjectsCatalogueService()
{
var params = {'max-results': 'long', 'memberOnly': 'boolean'};
var nodes = __getWorkspacesServicesNodes('service.simple.ProjectsCatalogue');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple projects catalogue services have been migrated.");
}
}
function migrateSimpleActivityStreamService()
{
var params = {'max-results': 'long'};
var nodes = __getWorkspacesServicesNodes('service.simple.ActivityStream');
var count = 0;
while (nodes.hasNext())
{
if (__migrateService(nodes.nextNode(), params))
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " simple activity stream services have been migrated.");
}
}
function migrateProjectManagers()
{
var query = qm.createQuery("//element(*, ametys:project)", javax.jcr.query.Query.XPATH);
var projectNodes = query.execute().getNodes();
var count = 0;
while (projectNodes.hasNext())
{
var hasChanged = false;
var projectNode = projectNodes.nextNode();
var managersNodeName = 'ametys:managers';
if (!projectNode.hasNode(managersNodeName))
{
var managersNode = projectNode.addNode(managersNodeName, 'ametys:multipleItem');
managersNode.setProperty('ametys-internal:typeId', 'user');
hasChanged = true;
}
var managerNodeName = 'ametys:manager';
if (projectNode.hasNode(managerNodeName))
{
var managerNodes = projectNode.getNodes(managerNodeName);
var index = 1;
while (managerNodes.hasNext())
{
var managerNode = managerNodes.nextNode();
session.move(managerNode.getPath(), managerNode.getParent().getPath() + '/' + managersNodeName + '/ametys:' + index++);
}
hasChanged = true;
}
if (hasChanged)
{
count++;
}
}
if (count > 0)
{
session.save();
print(count + " workspace projects have been migrated.");
}
}
var qm = session.getWorkspace().getQueryManager();
migrateTasksService();
migrateFilteredEventsService();
migrateProjectsCatalogueService();
migrateActivityStreamService();
migrateMembersService();
migrateModuleMembersService();
migrateSimpleFilteredEventsService();
migrateSimpleTasksService();
migrateSimpleDocumentsService();
migrateSimpleProjectsCatalogueService();
migrateSimpleActivityStreamService();
migrateProjectManagers();
print("End of migration, you can rebuild the Live workspace");