|
|
|
|
@@ -0,0 +1,153 @@
|
|
|
|
|
package at.ucs.magnolia.util.bootstrap.simpleUpdate;
|
|
|
|
|
|
|
|
|
|
import at.ucs.magnolia.util.bootstrap.task.CreateNodeWithFixedUUIDTask;
|
|
|
|
|
import at.ucs.magnolia.util.core.Workspace;
|
|
|
|
|
import info.magnolia.jcr.util.NodeTypes;
|
|
|
|
|
import info.magnolia.module.delta.*;
|
|
|
|
|
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class UpdateHelper {
|
|
|
|
|
/**
|
|
|
|
|
* Create and add tasks,which are required, to add a new role to the system and 'publish' it immediately
|
|
|
|
|
*
|
|
|
|
|
* @param tasks the list of tasks to which the new tasks will be appended
|
|
|
|
|
* @param roleName the name of the newly created role
|
|
|
|
|
* @param aclDefinitions list of ACL definitions to add
|
|
|
|
|
* @param uuid uuid the new node should have
|
|
|
|
|
*/
|
|
|
|
|
public static void createAndPublishUserrole(List<Task> tasks, String roleName, Collection<SimpleACLDefinition> aclDefinitions, List<String> assignToGroups, String uuid) {
|
|
|
|
|
addCreateRoleTask(tasks, roleName, aclDefinitions, null, assignToGroups, uuid);
|
|
|
|
|
setActivationStatus(tasks, Workspace.USER_ROLES, "/" + roleName);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create and add tasks,which are required, to add a new role to the system and 'publish' it immediately
|
|
|
|
|
*
|
|
|
|
|
* @param tasks the list of tasks to which the new tasks will be appended
|
|
|
|
|
* @param roleName the name of the newly created role
|
|
|
|
|
* @param aclDefinitions list of ACL definitions to add
|
|
|
|
|
* @param uuid uuid the new node should have
|
|
|
|
|
*/
|
|
|
|
|
public static void createAndPublishUserrole(List<Task> tasks, String roleName, Collection<SimpleACLDefinition> aclDefinitions, Collection<SimpleWebACLDefinition> webACLDefinitions, List<String> assignToGroups, String uuid) {
|
|
|
|
|
addCreateRoleTask(tasks, roleName, aclDefinitions, webACLDefinitions, assignToGroups, uuid);
|
|
|
|
|
setActivationStatus(tasks, Workspace.USER_ROLES, "/" + roleName);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create and add tasks,which are required, to add a new role to the system
|
|
|
|
|
*
|
|
|
|
|
* @param tasks the list of tasks to which the new tasks will be appended
|
|
|
|
|
* @param roleName the name of the newly created role
|
|
|
|
|
* @param aclDefinitions list of ACL definitions to add
|
|
|
|
|
*/
|
|
|
|
|
public static void createUserrole(List<Task> tasks, String roleName, Collection<SimpleACLDefinition> aclDefinitions, List<String> assignToGroups) {
|
|
|
|
|
addCreateRoleTask(tasks, roleName, aclDefinitions, null, assignToGroups, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create and add tasks,which are required, to add a new role to the system
|
|
|
|
|
*
|
|
|
|
|
* @param tasks the list of tasks to which the new tasks will be appended
|
|
|
|
|
* @param roleName the name of the newly created role
|
|
|
|
|
* @param aclDefinitions list of ACL definitions to add
|
|
|
|
|
* @param webACLDefinitions list of web ACL definitions to add
|
|
|
|
|
* @param uuid uuid the new node should have, if null a uuid is automatically assigned.
|
|
|
|
|
*/
|
|
|
|
|
private static void addCreateRoleTask(List<Task> tasks, String roleName, Collection<SimpleACLDefinition> aclDefinitions, Collection<SimpleWebACLDefinition> webACLDefinitions, List<String> assignToGroups, String uuid) {
|
|
|
|
|
if (uuid != null) {
|
|
|
|
|
tasks.add(new CreateNodeWithFixedUUIDTask("Create default userrole " + roleName, "Creates default userroles", Workspace.USER_ROLES, "/", roleName, NodeTypes.Role.NAME, uuid));
|
|
|
|
|
} else {
|
|
|
|
|
tasks.add(new CreateNodeTask("Create default userrole " + roleName, "Creates default userroles", Workspace.USER_ROLES, "/", roleName, NodeTypes.Role.NAME));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aclDefinitions != null) {
|
|
|
|
|
for (SimpleACLDefinition definition : aclDefinitions) {
|
|
|
|
|
addJcrAcl(tasks, roleName, definition.getWorkspace(), definition.getPath(), definition.getPermission(), definition.isIncludeSubNodes());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (webACLDefinitions != null) {
|
|
|
|
|
for (SimpleWebACLDefinition definition : webACLDefinitions) {
|
|
|
|
|
addWebAcl(tasks, roleName, definition.getPath(), definition.getPermission());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (assignToGroups != null) {
|
|
|
|
|
for (String groupName : assignToGroups) {
|
|
|
|
|
addRoleToGroup(tasks, roleName, groupName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addJcrAcl(List<Task> tasks, String roleName, List<SimpleACLDefinition> jcrAcls) {
|
|
|
|
|
jcrAcls.forEach(
|
|
|
|
|
simpleACLDefinition ->
|
|
|
|
|
tasks.add(new AddPermissionTask("Add permission to default userrole " + roleName, roleName, simpleACLDefinition.getWorkspace(), simpleACLDefinition.getPath(), simpleACLDefinition.getPermission() , simpleACLDefinition.isIncludeSubNodes()))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addJcrAcl(List<Task> tasks, String roleName, String workspace, String path, long permission, boolean includingSubNodes) {
|
|
|
|
|
tasks.add(new AddPermissionTask("Add permission to default userrole " + roleName, roleName, workspace, path, permission, includingSubNodes));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addWebAcl(List<Task> tasks, String roleName, List<SimpleWebACLDefinition> webAcls) {
|
|
|
|
|
webAcls.forEach(
|
|
|
|
|
simpleWebACLDefinition ->
|
|
|
|
|
tasks.add(new AddURIPermissionTask("Add web permission to default userrole " + roleName, roleName, simpleWebACLDefinition.getPath(), simpleWebACLDefinition.getPermission()))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addWebAcl(List<Task> tasks, String roleName, String path, int permission) {
|
|
|
|
|
tasks.add(new AddURIPermissionTask("Add web permission to default userrole " + roleName, roleName, path, permission));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addRoleToGroup(List<Task> tasks, String roleName, String groupName) {
|
|
|
|
|
tasks.add(new AddRoleToGroupTask("Assign default role " + roleName + " to default group " + groupName, roleName, groupName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addEmptyFolder(List<Task> tasks, String workspace, String parentPath, String folderName) {
|
|
|
|
|
tasks.add(new CreateNodeTask("Create default folder " + folderName, "Creates default folder", workspace, parentPath, folderName, NodeTypes.Folder.NAME));
|
|
|
|
|
tasks.add(new SetPropertyTask(workspace, folderName, "name", folderName.replaceAll("-", " ")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addEmptyFolderAndPublish(List<Task> tasks, String workspace, String parentPath, String folderName, String uuid) {
|
|
|
|
|
tasks.add(new CreateNodeWithFixedUUIDTask("Create default folder " + folderName, "Creates default folder", workspace, parentPath, folderName, NodeTypes.Folder.NAME, uuid));
|
|
|
|
|
tasks.add(new SetPropertyTask(workspace, folderName, "name", folderName.replaceAll("-", " ")));
|
|
|
|
|
setActivationStatus(tasks, workspace, Paths.get(parentPath, folderName).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addGroup(List<Task> tasks, String groupName) {
|
|
|
|
|
tasks.add(new CreateNodeTask("Create default usergroup " + groupName, "Creates default usergroups", Workspace.USERGROUPS, Workspace.JCR_ROOT_PATH, groupName, NodeTypes.Group.NAME));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addGroupAndPublish(List<Task> tasks, String groupName, String uuid) {
|
|
|
|
|
tasks.add(new CreateNodeWithFixedUUIDTask("Create default usergroup " + groupName, "Creates default usergroups", Workspace.USERGROUPS, Workspace.JCR_ROOT_PATH, groupName, NodeTypes.Group.NAME, uuid));
|
|
|
|
|
setActivationStatus(tasks, Workspace.USERGROUPS, "/" + groupName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the activation status of a node to true.
|
|
|
|
|
* This does not actually publish the node!
|
|
|
|
|
* All this does is make the green light show up in admincentral.
|
|
|
|
|
*
|
|
|
|
|
* @param tasks tasks
|
|
|
|
|
* @param workspace workspace
|
|
|
|
|
* @param nodePath nodePath
|
|
|
|
|
*/
|
|
|
|
|
public static void setActivationStatus(List<Task> tasks, String workspace, String nodePath) {
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
tasks.add(new SetPropertyTask(workspace, nodePath, "mgnl:activationStatus", "true"));
|
|
|
|
|
tasks.add(new SetPropertyTask("Set " + nodePath + "/mgnl:lastModified", workspace, nodePath,
|
|
|
|
|
"mgnl:lastModified", calendar));
|
|
|
|
|
calendar.add(Calendar.MINUTE, 2);
|
|
|
|
|
tasks.add(new SetPropertyTask("Set " + nodePath + "/mgnl:lastActivated", workspace, nodePath,
|
|
|
|
|
"mgnl:lastActivated", calendar));
|
|
|
|
|
tasks.add(new SetPropertyTask(workspace, nodePath, "mgnl:lastActivatedBy", "autopublish"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|