- java doc for conversion classes in portation
[FEATURE]
- export functionality for all important core classes is finished, yet untested

git-svn-id: https://svn.libreccm.org/ccm/trunk@4208 8810af33-2d31-482b-a856-94f89814c4df
master
tosmers 2016-07-25 16:48:24 +00:00
parent 7b03e13e6a
commit d87c8fcc4c
15 changed files with 582 additions and 123 deletions

View File

@ -19,19 +19,20 @@
package com.arsdigita.kernel; package com.arsdigita.kernel;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.persistence.OID; import com.arsdigita.domain.DomainCollection;
import com.arsdigita.persistence.metadata.ObjectType;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataAssociation; import com.arsdigita.persistence.DataAssociation;
import com.arsdigita.persistence.DataAssociationCursor; import com.arsdigita.persistence.DataAssociationCursor;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.metadata.ObjectType;
import org.apache.log4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
/** /**
* Represents a party, which can either be a group or a * Represents a party, which can either be a group or a
@ -320,4 +321,29 @@ public abstract class Party extends ACSObject {
public void setURI(String uri) { public void setURI(String uri) {
set("uri", uri); set("uri", uri);
} }
/**
* Retrieves all objects of this type stored in the database. Very
* necessary for exporting all entities of the current work environment.
*
* @return List of all groups
*/
public static List<Party> getAllObjectParties() {
List<Party> partyList = new ArrayList<>();
final Session session = SessionManager.getSession();
DomainCollection collection = new DomainCollection(session.retrieve(
Party.BASE_DATA_OBJECT_TYPE));
while (collection.next()) {
Party party = (Party) collection.getDomainObject();
if (party != null) {
partyList.add(party);
}
}
collection.close();
return partyList;
}
} }

View File

@ -18,12 +18,14 @@
*/ */
package com.arsdigita.portation.cmd; package com.arsdigita.portation.cmd;
import com.arsdigita.portation.conversion.MainConverter;
import com.arsdigita.util.cmd.Program; import com.arsdigita.util.cmd.Program;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* Commandline tool to exportUsers all the objects of a specified class to a xml-file. * A Commandline tool for exporting all the objects of specified classes to
* one or many specified file types.
* *
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 25.05.16 * @version created the 25.05.16
@ -32,16 +34,38 @@ public class ExportCliTool extends Program {
private final static Logger logger = Logger.getLogger(ExportCliTool.class); private final static Logger logger = Logger.getLogger(ExportCliTool.class);
/**
* Constructor for the command line tool.
*/
private ExportCliTool() { private ExportCliTool() {
super("Export Commandline Tool", super("Export Commandline Tool",
"1.0.0", "1.0.0",
"Exportation of POJOs..."); "Exportation of POJOs...");
} }
/**
* Main method, which calls the {@code doRun}-method and hands the given
* arguments over to that method.
*
* @param args The command line arguments
*/
public static void main(String[] args) { public static void main(String[] args) {
new ExportCliTool().run(args); new ExportCliTool().run(args);
} }
/**
* This method differentiates between multiple commands. Through the
* parameter the command line arguments will be matched to predefined
* commands which will then depending on the case define what will be
* called or executed.
*
* The commands are:
* {@code help} which prints just the usage of this tool
* {@code export} which executes the process of exporting whatever
* is required to be exported
*
* @param cmdLine The parsed command line arguments
*/
@Override @Override
protected void doRun(CommandLine cmdLine) { protected void doRun(CommandLine cmdLine) {
final String[] args = cmdLine.getArgs(); final String[] args = cmdLine.getArgs();
@ -60,6 +84,12 @@ public class ExportCliTool extends Program {
break; break;
case "export": case "export":
try {
MainConverter.startConversionToNg();
} catch (Exception e) {
logger.error("ERROR while converting trunk-objects to " +
"ng-objects", e);
}
export(args); export(args);
break; break;
@ -69,40 +99,121 @@ public class ExportCliTool extends Program {
} }
} }
/**
* Method defining the process of exporting after its command has been
* triggered.
*
* @param args The secondary command line arguments
*/
private void export(String[] args) { private void export(String[] args) {
if (args.length < 2) { if (args.length < 2) {
printUsage(); printUsage();
System.exit(-1); System.exit(-1);
} }
final String category = args[1]; final String moduleClass = args[1];
System.out.printf("\nCategory is %s\n", category); System.out.printf("\nModule class is %s\n", moduleClass);
try { try {
switch (category) { switch (moduleClass) {
case "categories":
ExportHelper.exportCategories();
break;
case "categorizations":
ExportHelper.exportCategorizations();
break;
case "users":
ExportHelper.exportUsers();
break;
case "groups":
ExportHelper.exportGroups();
break;
case "groupMemberships":
ExportHelper.exportGroupMemberships();
break;
case "roles":
ExportHelper.exportRoles();
break;
case "roleMemberships":
ExportHelper.exportRoleMemberships();
break;
case "workflows":
ExportHelper.exportWorkflows();
break;
case "userTasks":
ExportHelper.exportUserTasks();
break;
case "taskAssignments":
ExportHelper.exportTaskAssignments();
break;
case "permissions":
ExportHelper.exportPermissions();
break;
case "all_core":
ExportHelper.exportCategories();
ExportHelper.exportCategorizations();
ExportHelper.exportUsers();
ExportHelper.exportGroups();
ExportHelper.exportGroupMemberships();
ExportHelper.exportRoles();
ExportHelper.exportRoleMemberships();
ExportHelper.exportWorkflows();
ExportHelper.exportUserTasks();
ExportHelper.exportTaskAssignments();
ExportHelper.exportPermissions();
break;
default: default:
printUsage(); printUsage();
break; break;
} }
} catch (Exception ex) { } catch (Exception ex) {
logger.error("ERROR", ex); logger.error("ERROR while exporting", ex);
} }
} }
/**
* Prints the usage of this command line tool.
*/
private void printUsage() { private void printUsage() {
System.err.printf( System.err.printf(
"\n" +
"\t\t\t --- ExportCliTool ---\n" + "\t\t\t --- ExportCliTool ---\n" +
"usage:\t<command> [<category>]\n" + "\n" +
"usage:\t<command> [<module-class>] \t (module class optional)\n" +
"\n" + "\n" +
"Available commands:\n" + "Available commands:\n" +
"\tlist \t\t Shows information on how to use this tool.\n" + "\thelp" +
"\texportUsers <category> \t\t Exports the chosen category to xml file.\n" + "\t\t\t\t Shows information on how to use this tool.\n" +
"\texport <module-class> " +
"\t\t Exports the chosen module class to a file.\n" +
"\n" + "\n" +
"Available categories for exportUsers:\n" + "Available module-classes for export:\n" +
" \t\t users \t all users of the system\n" + " \t\t categories \t\t all categories of the system\n" +
" \t\t groups \t all groups of the system\n" + " \t\t categorizations \t\t all categorizations of the system\n" +
"Use for exporting java objects of a specified class to a xml-file.\n" " \t\t users \t\t all users of the system\n" +
" \t\t groups \t\t all groups of the system\n" +
" \t\t groupMemberships\t\t all groupsMemberships of the system\n" +
" \t\t roles \t\t all roles of the system\n" +
" \t\t roleMemberships \t\t all roleMemberships of the system\n" +
" \t\t workflows \t\t all workflows of the system\n" +
" \t\t userTasks \t\t all userTasks of the system\n" +
" \t\t taskAssignments \t\t all taskAssignments of the system\n" +
" \t\t permissions \t\t all permissions of the system\n" +
"\n" +
"Do use for exporting java objects of a specified class.\n" +
"\n"
); );
} }
} }

View File

@ -1,27 +0,0 @@
/*
* Copyright (C) 2015 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.portation.conversion;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 6/27/16
*/
public class MainConversion {
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2015 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.portation.conversion;
import com.arsdigita.portation.conversion.core.categorization.CategoryConversion;
import com.arsdigita.portation.conversion.core.security.GroupConversion;
import com.arsdigita.portation.conversion.core.security.PermissionConversion;
import com.arsdigita.portation.conversion.core.security.RoleConversion;
import com.arsdigita.portation.conversion.core.security.UserConversion;
import com.arsdigita.portation.conversion.core.workflow.UserTaskConversion;
import com.arsdigita.portation.conversion.core.workflow.WorkflowConversion;
/**
* This main converter class calls all the conversions from trunk-objects
* to ng-objects in a specific order to guarantee a correct dependency
* recreation in the ng-objects. All the created objects are going to be
* stored in maps as <id, object>-pairs in the {@link NgCollection}-class.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 6/27/16
*/
public class MainConverter {
/**
* Method, to start all the different converter classes in a specific
* order, so that dependencies can only be set, where the objects have
* already been created.
*/
public static void startConversionToNg() {
CategoryConversion.convertAll();
UserConversion.convertAll();
GroupConversion.convertAll();
RoleConversion.convertAll();
WorkflowConversion.convertAll();
UserTaskConversion.convertAll();
PermissionConversion.convertAll();
}
}

View File

@ -37,8 +37,11 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* Storage class for all ng-objects after conversion. This also helps for an
* easier access for the restoration of the dependencies.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 6/27/16 * @version created the 27.6.16
*/ */
public class NgCollection { public class NgCollection {
@ -51,17 +54,18 @@ public class NgCollection {
public static Map<Long, Group> groups = new HashMap<>(); public static Map<Long, Group> groups = new HashMap<>();
public static Map<Long, GroupMembership> groupMemberships = new HashMap<>(); public static Map<Long, GroupMembership> groupMemberships = new HashMap<>();
public static Map<Long, Workflow> workflows = new HashMap<>();
public static Map<Long, Task> tasks = new HashMap<>();
public static Map<Long, UserTask> userTasks = new HashMap<>();
public static Map<Long, Role> roles = new HashMap<>(); public static Map<Long, Role> roles = new HashMap<>();
public static Map<Long, RoleMembership> roleMemberships = new HashMap<>(); public static Map<Long, RoleMembership> roleMemberships = new HashMap<>();
public static Map<Long, Workflow> workflows = new HashMap<>();
public static Map<Long, Task> tasks = new HashMap<>();
public static Map<Long, UserTask> userTasks = new HashMap<>();
public static Map<Long, TaskAssignment> taskAssignments = new HashMap<>(); public static Map<Long, TaskAssignment> taskAssignments = new HashMap<>();
public static Map<Long, Permission> permissions = new HashMap<>(); public static Map<Long, Permission> permissions = new HashMap<>();
/**
* Private constructor to prevent the instantiation of this class.
*/
private NgCollection() {} private NgCollection() {}
} }

View File

@ -28,45 +28,62 @@ import com.arsdigita.portation.modules.core.core.CcmObject;
import java.util.List; import java.util.List;
/** /**
* Class for converting all
* trunk-{@link com.arsdigita.categorization.Category}s into
* ng-{@link Category}s as preparation for a successful export of all trunk
* classes into the new ng-system.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 6/29/16 * @version created the 29.6.16
*/ */
public class CategoryConversion { public class CategoryConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.categorization.Category}s from
* the persistent storage and collects them in a list. Then calls for
* creating the equivalent ng-{@link Category}s focusing on keeping all the
* associations in tact.
*/
public static void convertAll() { public static void convertAll() {
List<com.arsdigita.categorization.Category> trunkCategories = com List<com.arsdigita.categorization.Category> trunkCategories = com
.arsdigita.categorization.Category.getAllObjectCategories(); .arsdigita.categorization.Category.getAllObjectCategories();
// create categories createCategoryAndSetAssociations(trunkCategories);
trunkCategories.forEach(Category::new);
setAssociations(trunkCategories);
} }
/** /**
* Sets associations. Needs to be separate, so that all categories have * Creates the equivalent ng-class of the {@code Category} and restores
* been converted before. Otherwise it will be complex to get parent. * the associations to other classes.
* *
* @param trunkCategories * @param trunkCategories List of all
* {@link com.arsdigita.categorization.Category}s
* from this old trunk-system.
*/ */
private static void setAssociations( private static void createCategoryAndSetAssociations(
List<com.arsdigita.categorization.Category> trunkCategories) { List<com.arsdigita.categorization.Category> trunkCategories) {
for (com.arsdigita.categorization.Category for (com.arsdigita.categorization.Category
trunkCategory : trunkCategories) { trunkCategory : trunkCategories) {
Category category = NgCollection.categories.get(trunkCategory // create categories
.getID() Category category = new Category(trunkCategory);
.longValue());
// set parent associations
Category parentCategory = NgCollection.categories.get(trunkCategory
.getDefaultParentCategory().getID().longValue());
if (category != null && parentCategory != null) {
// set parent and opposed association // set parent and opposed association
Category parentCategory = null;
try {
com.arsdigita.categorization.Category defaultParent =
trunkCategory.getDefaultParentCategory();
if (defaultParent != null) {
parentCategory = NgCollection.categories.get(
defaultParent.getID().longValue());
}
} catch (Exception e) {}
if (parentCategory != null) {
category.setParentCategory(parentCategory); category.setParentCategory(parentCategory);
parentCategory.addSubCategory(category); parentCategory.addSubCategory(category);
} }
// create categorizations only for category typed objects // categorizations only for category typed objects
CategorizedCollection categorizedCollection = trunkCategory CategorizedCollection categorizedCollection = trunkCategory
.getObjects(com.arsdigita.categorization.Category .getObjects(com.arsdigita.categorization.Category
.BASE_DATA_OBJECT_TYPE); .BASE_DATA_OBJECT_TYPE);
@ -74,6 +91,15 @@ public class CategoryConversion {
} }
} }
/**
* Method for creating {@link Categorization}s between {@link Category}s
* and {@link CcmObject}s which is an association-class and has not been
* existent in this old system.
*
* @param category The {@link Category}
* @param categorizedObjects A collection of the {@code Categorization}s
* as they are represented in this trunk-system
*/
private static void createCategorizations(Category category, private static void createCategorizations(Category category,
CategorizedCollection CategorizedCollection
categorizedObjects) { categorizedObjects) {

View File

@ -28,11 +28,22 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Class for converting all trunk-{@link com.arsdigita.kernel.Group}s into
* ng-{@link Group}s as preparation for a successful export of all trunk
* classes into the new ng-system.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 7/4/16 * @version created the 4.7.16
*/ */
public class GroupConversion { public class GroupConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.kernel.Group}s from the
* persistent storage, collects them in a list and removes all groups
* representing actually a {@link com.arsdigita.kernel.Role} in the
* trunk-system. Then calls for creating the equivalent ng-{@link Group}s
* focusing on keeping all the associations in tact.
*/
public static void convertAll() { public static void convertAll() {
List<com.arsdigita.kernel.Group> trunkGroups, List<com.arsdigita.kernel.Group> trunkGroups,
roleGroups = new ArrayList<>(); roleGroups = new ArrayList<>();
@ -45,24 +56,38 @@ public class GroupConversion {
// remove subgroups representing roles // remove subgroups representing roles
trunkGroups.removeAll(roleGroups); trunkGroups.removeAll(roleGroups);
// create groups createGroupsAndSetAssociations(trunkGroups);
trunkGroups.forEach(Group::new);
setAssociations(trunkGroups);
} }
private static void setAssociations( /**
* Creates the equivalent ng-class of the {@code Category} and restores
* the associations to other classes.
*
* @param trunkGroups List of all {@link com.arsdigita.kernel.Group}s
* from this old trunk-system.
*/
private static void createGroupsAndSetAssociations(
List<com.arsdigita.kernel.Group> trunkGroups) { List<com.arsdigita.kernel.Group> trunkGroups) {
for (com.arsdigita.kernel.Group trunkGroup : trunkGroups) { for (com.arsdigita.kernel.Group trunkGroup : trunkGroups) {
Group group = NgCollection.groups.get(trunkGroup.getID() // create groups
.longValue()); Group group = new Group(trunkGroup);
// create groupMemberships // groupMemberships
UserCollection userCollection = trunkGroup.getMemberUsers(); UserCollection userCollection = trunkGroup.getMemberUsers();
createGroupMemberships(group, userCollection); createGroupMemberships(group, userCollection);
} }
} }
/**
* Method for creating {@link GroupMembership}s between {@link Group}s
* and {@link User}s which is an association-class and has not been
* existent in this old trunk-system.
*
* @param group The {@link Group}
* @param userCollection A collection of the
* {@link com.arsdigita.kernel.User}s belonging to
* the given group
*/
private static void createGroupMemberships(Group group, UserCollection private static void createGroupMemberships(Group group, UserCollection
userCollection) { userCollection) {
while (userCollection.next()) { while (userCollection.next()) {
@ -73,7 +98,7 @@ public class GroupConversion {
// create groupMemeberships // create groupMemeberships
GroupMembership groupMembership = new GroupMembership(group, member); GroupMembership groupMembership = new GroupMembership(group, member);
// set adverse associations // set opposed associations
group.addMembership(groupMembership); group.addMembership(groupMembership);
member.addGroupMembership(groupMembership); member.addGroupMembership(groupMembership);
} }

View File

@ -18,29 +18,57 @@
*/ */
package com.arsdigita.portation.conversion.core.security; package com.arsdigita.portation.conversion.core.security;
import com.arsdigita.kernel.Group;
import com.arsdigita.kernel.Party;
import com.arsdigita.kernel.RoleCollection;
import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.conversion.NgCollection;
import com.arsdigita.portation.modules.core.core.CcmObject; import com.arsdigita.portation.modules.core.core.CcmObject;
import com.arsdigita.portation.modules.core.security.Permission; import com.arsdigita.portation.modules.core.security.Permission;
import com.arsdigita.portation.modules.core.security.Role; import com.arsdigita.portation.modules.core.security.Role;
import com.arsdigita.portation.modules.core.security.RoleMembership;
import com.arsdigita.portation.modules.core.security.User; import com.arsdigita.portation.modules.core.security.User;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/** /**
* Class for converting all
* trunk-{@link com.arsdigita.kernel.permissions.Permission}s into
* ng-{@link Permission}s as preparation for a successful export of all trunk
* classes into the new ng-system.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 7/14/16 * @version created the 14.7.16
*/ */
public class PermissionConversion { public class PermissionConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.kernel.permissions.Permission}s
* from the persistent storage and collects them in a list. Then calls for
* creating the equivalent ng-{@link Permission}s focusing on keeping all
* the associations in tact. The association to the {@code
* grantee}-{@link Role} has to be recreated separately.
*/
public static void convertAll() { public static void convertAll() {
List<com.arsdigita.kernel.permissions.Permission> trunkPermissions = List<com.arsdigita.kernel.permissions.Permission> trunkPermissions =
com.arsdigita.kernel.permissions.Permission com.arsdigita.kernel.permissions.Permission
.getAllObjectPermissions(); .getAllObjectPermissions();
createPermissionsAndSetAssociations(trunkPermissions); createPermissionsAndSetAssociations(trunkPermissions);
setGranteeDependency(trunkPermissions);
} }
/**
* Creates the equivalent ng-class of the {@code Permission} and restores
* the associations to other classes.
*
* @param trunkPermissions List of all
* {@link com.arsdigita.kernel.permissions.Permission}s
* from the old trunk-system
*/
private static void createPermissionsAndSetAssociations(List<com private static void createPermissionsAndSetAssociations(List<com
.arsdigita.kernel.permissions.Permission> trunkPermissions) { .arsdigita.kernel.permissions.Permission> trunkPermissions) {
for (com.arsdigita.kernel.permissions.Permission trunkPermission : for (com.arsdigita.kernel.permissions.Permission trunkPermission :
@ -57,13 +85,6 @@ public class PermissionConversion {
object.addPermission(permission); object.addPermission(permission);
} }
// set grantee and opposed associations
Role role = NgCollection.roles.get(0); //Todo: fix "0"
if (role != null) {
permission.setGrantee(role);
role.addPermission(permission);
}
// set creationUser // set creationUser
User creationUser = NgCollection.users.get(trunkPermission User creationUser = NgCollection.users.get(trunkPermission
.getCreationUser().getID().longValue()); .getCreationUser().getID().longValue());
@ -71,4 +92,82 @@ public class PermissionConversion {
permission.setCreationUser(creationUser); permission.setCreationUser(creationUser);
} }
} }
/**
* Method recreating the association to class {@link Role} representing the
* {@code grantee} of a Permission. Because the {@code grantee} in the
* trunk-{@link com.arsdigita.kernel.permissions.Permission} is instance
* of the trunk-{@link Party}-class, there need to be separated two
* cases:
* a) were the {@code grantee} of the trunk-system is of class
* {@link com.arsdigita.kernel.Group} therefore listing {@code
* Roles}, represented by this {@code Group}, which represent
* the {@code grantee} of ng-{@link Permission}s.
* b) were the {@code grantee} of the trunk-system is of class
* {@link com.arsdigita.kernel.User} therefore having no {@code
* Role}-representation, which has specifically to be created.
*
* @param trunkPermissions List of all
* {@link com.arsdigita.kernel.permissions.Permission}s
* from the old trunk-system
*/
private static void setGranteeDependency(List<com.arsdigita.kernel
.permissions.Permission> trunkPermissions) {
for (com.arsdigita.kernel.permissions.Permission trunkPermission :
trunkPermissions) {
Permission permission = NgCollection.permissions.get
(trunkPermission.getID().longValue());
BigDecimal trunkGranteeId = (BigDecimal) trunkPermission
.getPartyOID().get("id");
List<Party> trunkParties = Party.getAllObjectParties();
trunkParties.stream().filter(p -> Objects.equals(p.getID(),
trunkGranteeId)).collect(Collectors.toList());
for (Party trunkGranteeParty : trunkParties) {
// grantee instance of Group, possibly multiple roles
if (trunkGranteeParty instanceof Group) {
RoleCollection granteeCollection = ((Group)
trunkGranteeParty).getRoles();
boolean multipleGrantees = false;
while (granteeCollection.next()) {
Role role = NgCollection.roles.get(granteeCollection
.getRole().getID().longValue());
// set grantee and opposed associations
if (!multipleGrantees) {
permission.setGrantee(role);
role.addPermission(permission);
multipleGrantees = true;
} else {
Permission duplicatePermission = new Permission
(permission);
duplicatePermission.setGrantee(role);
role.addPermission(duplicatePermission);
}
}
// grantee instance of User, new Role necessary
} else if (trunkGranteeParty instanceof com.arsdigita.kernel
.User) {
com.arsdigita.kernel.User trunkGranteeUser = (com
.arsdigita.kernel.User) trunkGranteeParty;
// create new role for this user and its membership
User member = NgCollection.users.get
(trunkGranteeUser.getID().longValue());
// might cause problems cause the
// task assignments are missing
Role granteeRole = new Role(member.getName() + "_role");
RoleMembership roleMembership = new RoleMembership
(granteeRole, member);
member.addRoleMembership(roleMembership);
granteeRole.addMembership(roleMembership);
// set grantee and opposed association
permission.setGrantee(granteeRole);
granteeRole.addPermission(permission);
}
}
}
}
} }

View File

@ -28,33 +28,57 @@ import com.arsdigita.portation.modules.core.security.RoleMembership;
import java.util.List; import java.util.List;
/** /**
* Class for converting all trunk-{@link com.arsdigita.kernel.Role}s into
* ng-{@link Role}s as preparation for a successful export of all trunk
* classes into the new ng-system.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 7/4/16 * @version created the 4.7.16
*/ */
public class RoleConversion { public class RoleConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.kernel.Role}s from the
* persistent storage and collects them in a list. Then calls for
* creating the equivalent ng-{@link Role}s focusing on keeping all the
* associations in tact.
*/
public static void convertAll() { public static void convertAll() {
List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel
.Role.getAllObjectRoles(); .Role.getAllObjectRoles();
// create roles createRolesAndSetAssociations(trunkRoles);
trunkRoles.forEach(Role::new);
// set associations
setAssociations(trunkRoles);
} }
private static void setAssociations(List<com.arsdigita.kernel.Role> /**
trunkRoles) { * Creates the equivalent ng-class of the {@code Role} and restores
* the associations to other classes.
*
* @param trunkRoles List of all {@link com.arsdigita.kernel.Role}s from
* this old trunk-system.
*/
private static void createRolesAndSetAssociations(
List<com.arsdigita.kernel.Role> trunkRoles) {
for (com.arsdigita.kernel.Role trunkRole : trunkRoles) { for (com.arsdigita.kernel.Role trunkRole : trunkRoles) {
Role role = NgCollection.roles.get(trunkRole.getID().longValue()); // create roles
Role role = new Role(trunkRole);
// create roleMemberships // roleMemberships
PartyCollection partyCollection = trunkRole.getContainedParties(); PartyCollection partyCollection = trunkRole.getContainedParties();
createRoleMemberships(role, partyCollection); createRoleMemberships(role, partyCollection);
} }
} }
/**
* Method for creating {@link RoleMembership}s between {@link Role}s
* and {@link Party}s which is an association-class and has not been
* existent in this old trunk-system.
*
* @param role The {@link Role}
* @param partyCollection A collection of the
* {@link com.arsdigita.kernel.Party}s belonging to
* the given group
*/
private static void createRoleMemberships(Role role, PartyCollection private static void createRoleMemberships(Role role, PartyCollection
partyCollection) { partyCollection) {
while (partyCollection.next()) { while (partyCollection.next()) {
@ -65,7 +89,7 @@ public class RoleConversion {
// create roleMemberships // create roleMemberships
RoleMembership roleMembership = new RoleMembership(role, member); RoleMembership roleMembership = new RoleMembership(role, member);
// set adverse associations // set opposed associations
role.addMembership(roleMembership); role.addMembership(roleMembership);
member.addRoleMembership(roleMembership); member.addRoleMembership(roleMembership);
} }

View File

@ -23,11 +23,20 @@ import com.arsdigita.portation.modules.core.security.User;
import java.util.List; import java.util.List;
/** /**
* Class for converting all trunk-{@link com.arsdigita.kernel.User}s into
* ng-{@link User}s as preparation for a successful export of all trunk
* classes into the new ng-system.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 7/4/16 * @version created the 4.7.16
*/ */
public class UserConversion { public class UserConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.kernel.User}s from the
* persistent storage and collects them in a list. Then calls for
* creating the equivalent ng-{@link User}s.
*/
public static void convertAll() { public static void convertAll() {
List<com.arsdigita.kernel.User> trunkUsers = com.arsdigita.kernel List<com.arsdigita.kernel.User> trunkUsers = com.arsdigita.kernel
.User.getAllObjectUsers(); .User.getAllObjectUsers();

View File

@ -19,9 +19,12 @@
package com.arsdigita.portation.conversion.core.workflow; package com.arsdigita.portation.conversion.core.workflow;
import com.arsdigita.kernel.UserCollection; import com.arsdigita.kernel.GroupCollection;
import com.arsdigita.kernel.RoleCollection;
import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.conversion.NgCollection;
import com.arsdigita.portation.modules.core.security.Role;
import com.arsdigita.portation.modules.core.security.User; import com.arsdigita.portation.modules.core.security.User;
import com.arsdigita.portation.modules.core.workflow.TaskAssignment;
import com.arsdigita.portation.modules.core.workflow.UserTask; import com.arsdigita.portation.modules.core.workflow.UserTask;
import com.arsdigita.portation.modules.core.workflow.Workflow; import com.arsdigita.portation.modules.core.workflow.Workflow;
import com.arsdigita.workflow.simple.Task; import com.arsdigita.workflow.simple.Task;
@ -30,11 +33,23 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* Class for converting all
* trunk-{@link com.arsdigita.workflow.simple.UserTask}s into
* ng-{@link UserTask}s as preparation for a successful export of all trunk
* classes into the new ng-system.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 6/29/16 * @version created the 29.6.16
*/ */
public class UserTaskConversion { public class UserTaskConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.workflow.simple.UserTask}s from
* the persistent storage and collects them in a list. Then calls for
* creating the equivalent ng-{@link UserTask}s focusing on keeping all the
* associations in tact. The ring dependencies of class {@code Task} have
* to be recreated once all ng-{@link UserTask}s have been created.
*/
public static void convertAll() { public static void convertAll() {
List<com.arsdigita.workflow.simple.UserTask> trunkUserTasks = com List<com.arsdigita.workflow.simple.UserTask> trunkUserTasks = com
.arsdigita.workflow.simple.UserTask.getAllObjectUserTasks(); .arsdigita.workflow.simple.UserTask.getAllObjectUserTasks();
@ -44,6 +59,14 @@ public class UserTaskConversion {
setTaskRingDependencies(trunkUserTasks); setTaskRingDependencies(trunkUserTasks);
} }
/**
* Creates the equivalent ng-class of the {@code UserTask} and restores
* the associations to other classes.
*
* @param trunkUserTasks List of all
* {@link com.arsdigita.workflow.simple.UserTask}s
* from this old trunk-system.
*/
private static void createUserTasksAndSetAssociations(List<com.arsdigita private static void createUserTasksAndSetAssociations(List<com.arsdigita
.workflow.simple.UserTask> trunkUserTasks) { .workflow.simple.UserTask> trunkUserTasks) {
for (com.arsdigita.workflow.simple.UserTask trunkUserTask : for (com.arsdigita.workflow.simple.UserTask trunkUserTask :
@ -71,33 +94,70 @@ public class UserTaskConversion {
if (notificationSender != null) if (notificationSender != null)
userTask.setNotificationSender(notificationSender); userTask.setNotificationSender(notificationSender);
// create taskAssignments // taskAssignments
UserCollection userCollection = trunkUserTask GroupCollection groupCollection = trunkUserTask
.getAssignedUserCollection(); .getAssignedGroupCollection();
createTaskAssignments(userTask, userCollection); createTaskAssignments(userTask, groupCollection);
} }
} }
/**
* Method for creating {@link TaskAssignment}s between {@link UserTask}s
* and {@link Role}s which is an association-class and has not been
* existent in this old system. The {@link Role}s are represented by the
* given groups.
*
* @param userTask The {@link UserTask}
* @param groupCollection A collection of the
* {@link com.arsdigita.kernel.Group}s representing
* {@link com.arsdigita.kernel.Role}s belonging to
* the userTask
*/
private static void createTaskAssignments(UserTask userTask, private static void createTaskAssignments(UserTask userTask,
UserCollection userCollection) { GroupCollection groupCollection) {
while (userCollection.next()) { while (groupCollection.next()) {
// Role role = NgCollection.users.get(userCollection.getUser().getID RoleCollection roleCollection = groupCollection.getGroup().getRoles();
// ().longValue()).getRoleMemberships().; while (roleCollection.next()) {
Role role = NgCollection.roles.get(roleCollection.getRole()
.getID().longValue());
if (userTask != null && role != null) {
// create taskAssignments
TaskAssignment taskAssignment = new TaskAssignment
(userTask, role);
// set opposed associations
userTask.addAssignment(taskAssignment);
role.addAssignedTask(taskAssignment);
}
}
} }
} }
/**
* Method for recreating the
* ng-{@link com.arsdigita.portation.modules.core.workflow.Task}s ring-like
* dependencies between dependentTask and dependsOn. Because all
* ng-{@link com.arsdigita.portation.modules.core.workflow.Task}s have
* already been created, it is possible e.g. to find the dependsOn-{@code
* Tasks} and bind them for association.
*
* @param trunkUserTasks List of all
* {@link com.arsdigita.workflow.simple.UserTask}s
* from this old trunk-system.
*/
private static void setTaskRingDependencies(List<com.arsdigita.workflow private static void setTaskRingDependencies(List<com.arsdigita.workflow
.simple.UserTask> trunkUserTasks) { .simple.UserTask> trunkUserTasks) {
UserTask userTask, dependency;
for (com.arsdigita.workflow.simple.UserTask trunkUserTask : for (com.arsdigita.workflow.simple.UserTask trunkUserTask :
trunkUserTasks) { trunkUserTasks) {
userTask = NgCollection.userTasks.get(trunkUserTask.getID() UserTask userTask = NgCollection.userTasks.get(trunkUserTask.getID()
.longValue()); .longValue());
Iterator it = trunkUserTask.getDependencies(); Iterator it = trunkUserTask.getDependencies();
while (it.hasNext()) { while (it.hasNext()) {
dependency = NgCollection.userTasks.get(((Task) it.next()) UserTask dependency = NgCollection.userTasks.get(((Task) it
.next())
.getID().longValue()); .getID().longValue());
if (userTask != null && dependency != null) { if (userTask != null && dependency != null) {
@ -106,7 +166,6 @@ public class UserTaskConversion {
dependency.addDependentTask(userTask); dependency.addDependentTask(userTask);
} }
} }
} }
} }
} }

View File

@ -23,11 +23,21 @@ import com.arsdigita.portation.modules.core.workflow.Workflow;
import java.util.List; import java.util.List;
/** /**
* lass for converting all
* trunk-{@link com.arsdigita.workflow.simple.Workflow}s into
* ng-{@link Workflow}s as preparation for a successful export of all trunk
* classes into the new ng-system.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 6/27/16 * @version created the 27.6.16
*/ */
public class WorkflowConversion { public class WorkflowConversion {
/**
* Retrieves all trunk-{@link com.arsdigita.workflow.simple.Workflow}s from
* the persistent storage and collects them in a list. Then calls for
* creating the equivalent ng-{@link Workflow}s.
*/
public static void convertAll() { public static void convertAll() {
List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows = List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows =
com.arsdigita.workflow.simple.Workflow.getAllObjectWorkflows(); com.arsdigita.workflow.simple.Workflow.getAllObjectWorkflows();

View File

@ -19,6 +19,7 @@
package com.arsdigita.portation.modules.core.categorization; package com.arsdigita.portation.modules.core.categorization;
import com.arsdigita.categorization.CategoryLocalization; import com.arsdigita.categorization.CategoryLocalization;
import com.arsdigita.categorization.CategoryLocalizationCollection;
import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.AbstractMarshaller;
import com.arsdigita.portation.Identifiable; import com.arsdigita.portation.Identifiable;
import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.conversion.NgCollection;
@ -66,11 +67,17 @@ public class Category extends CcmObject {
this.uniqueId = trunkCategory.getID().toString(); this.uniqueId = trunkCategory.getID().toString();
this.name = trunkCategory.getName(); this.name = trunkCategory.getName();
CategoryLocalizationCollection categoryLocalizationCollection =
trunkCategory.getCategoryLocalizationCollection();
if (categoryLocalizationCollection != null &&
categoryLocalizationCollection.next()) {
CategoryLocalization categoryLocalization = trunkCategory CategoryLocalization categoryLocalization = trunkCategory
.getCategoryLocalizationCollection().getCategoryLocalization(); .getCategoryLocalizationCollection().getCategoryLocalization();
Locale locale = new Locale(categoryLocalization.getLocale()); Locale locale = new Locale(categoryLocalization.getLocale());
this.title.addValue(locale, categoryLocalization.getName()); this.title.addValue(locale, categoryLocalization.getName());
this.description.addValue(locale, categoryLocalization.getDescription()); this.description.addValue(locale, categoryLocalization.getDescription());
}
this.enabled = trunkCategory.isEnabled(); this.enabled = trunkCategory.isEnabled();
this.visible = trunkCategory.isVisible(); this.visible = trunkCategory.isVisible();
@ -81,8 +88,13 @@ public class Category extends CcmObject {
//this.parentCategory //this.parentCategory
this.categoryOrder = trunkCategory.getDefaultParentCategory() com.arsdigita.categorization.Category defaultParent = null;
.getNumberOfChildCategories() + 1; try {
defaultParent = trunkCategory.getDefaultParentCategory();
} catch (Exception e) {}
this.categoryOrder = defaultParent != null
? defaultParent.getNumberOfChildCategories() + 1
: 0;
NgCollection.categories.put(this.getObjectId(), this); NgCollection.categories.put(this.getObjectId(), this);
} }

View File

@ -55,6 +55,21 @@ public class Permission implements Identifiable {
NgCollection.permissions.put(this.permissionId, this); NgCollection.permissions.put(this.permissionId, this);
} }
public Permission(final Permission ngPermission) {
this.permissionId = NgCollection.permissions.size() + 1;
this.grantedPrivilege = ngPermission.getGrantedPrivilege();
this.object = ngPermission.getObject();
this.grantee = ngPermission.getGrantee();
this.creationUser = ngPermission.getCreationUser();
this.creationDate = ngPermission.getCreationDate();
this.creationIp = ngPermission.getCreationIp();
NgCollection.permissions.put(this.permissionId, this);
}
@Override @Override
public AbstractMarshaller<? extends Identifiable> getMarshaller() { public AbstractMarshaller<? extends Identifiable> getMarshaller() {
return new PermissionMarshaller(); return new PermissionMarshaller();

View File

@ -42,7 +42,7 @@ public class Role implements Identifiable {
private List<Permission> permissions; private List<Permission> permissions;
private List<TaskAssignment> assignedTasks; private List<TaskAssignment> assignedTasks;
public Role(com.arsdigita.kernel.Role trunkRole) { public Role(final com.arsdigita.kernel.Role trunkRole) {
this.roleId = trunkRole.getID().longValue(); this.roleId = trunkRole.getID().longValue();
this.name = trunkRole.getName(); this.name = trunkRole.getName();
@ -54,6 +54,18 @@ public class Role implements Identifiable {
NgCollection.roles.put(this.roleId, this); NgCollection.roles.put(this.roleId, this);
} }
public Role(final String name) {
this.roleId = NgCollection.roles.size() + 1;
this.name = name;
this.memberships = new HashSet<>();
this.permissions = new ArrayList<>();
this.assignedTasks = new ArrayList<>();
NgCollection.roles.put(this.roleId, this);
}
@Override @Override
public AbstractMarshaller<? extends Identifiable> getMarshaller() { public AbstractMarshaller<? extends Identifiable> getMarshaller() {
return new RoleMarshaller(); return new RoleMarshaller();