- adds progress output to terminal for export process

git-svn-id: https://svn.libreccm.org/ccm/trunk@4690 8810af33-2d31-482b-a856-94f89814c4df
master
tosmers 2017-04-26 16:53:20 +00:00
parent 5e12ad6b20
commit c6d4c5c88b
12 changed files with 252 additions and 135 deletions

View File

@ -76,7 +76,7 @@ public class ExportCliTool extends Program {
} }
final String command = args[0]; final String command = args[0];
System.out.printf("\nCommand is %s\n", command); System.out.printf("command: %s\n", command);
switch (command) { switch (command) {
case "help": case "help":
@ -100,13 +100,18 @@ public class ExportCliTool extends Program {
* @param args The secondary command line arguments * @param args The secondary command line arguments
*/ */
private void export(String[] args) { private void export(String[] args) {
if (args.length < 2) { if (args.length != 3) {
printUsage(); printUsage();
System.exit(-1); System.exit(-1);
} }
final String moduleClass = args[1]; final String moduleClass = args[1];
System.out.printf("\nModule class is %s\n", moduleClass); System.err.printf("module-class: %s\n", moduleClass);
final String pathName = args[2];
System.err.printf("path: %s\n", pathName);
ExportHelper.setPath(pathName);
System.err.printf("\n");
try { try {
switch (moduleClass) { switch (moduleClass) {
@ -166,11 +171,13 @@ public class ExportCliTool extends Program {
break; break;
case "permissions": case "permissions":
convert();
ExportHelper.exportPermissions(); ExportHelper.exportPermissions();
break; break;
case "all_core": case "all_core":
convert(); convert();
System.out.println("Started exporting all ng-objects...");
ExportHelper.exportCategories(); ExportHelper.exportCategories();
ExportHelper.exportCategorizations(); ExportHelper.exportCategorizations();
ExportHelper.exportUsers(); ExportHelper.exportUsers();
@ -183,6 +190,8 @@ public class ExportCliTool extends Program {
ExportHelper.exportAssignableTasks(); ExportHelper.exportAssignableTasks();
ExportHelper.exportTaskAssignments(); ExportHelper.exportTaskAssignments();
ExportHelper.exportPermissions(); ExportHelper.exportPermissions();
System.out.println("Finished exports.");
System.out.printf("\n");
break; break;
default: default:
@ -199,7 +208,11 @@ public class ExportCliTool extends Program {
*/ */
private void convert() { private void convert() {
try { try {
System.err.println("Started conversions of systems objects to " +
"ng-objects...");
MainConverter.startConversionToNg(); MainConverter.startConversionToNg();
System.err.println("Finished conversions.");
System.out.printf("\n");
} catch (Exception e) { } catch (Exception e) {
logger.error("ERROR while converting trunk-objects to " + logger.error("ERROR while converting trunk-objects to " +
"ng-objects", e); "ng-objects", e);
@ -216,13 +229,16 @@ public class ExportCliTool extends Program {
"\n" + "\n" +
"\t\t\t --- ExportCliTool ---\n" + "\t\t\t --- ExportCliTool ---\n" +
"\n" + "\n" +
"usage:\t<command> [<module-class>] \t (module class optional)\n" + "usage:\t<command> <module-class> <path>\n" +
"\n" + "\n" +
"Available commands:\n" + "Available commands:\n" +
"\thelp" + "\thelp" +
"\t\t\t\t Shows information on how to use this tool.\n" + "\t\t\t\t\t Shows information on how to use this tool.\n" +
"\texport <module-class> " + "\texport <module-class> <path>" +
"\t\t Exports the chosen module class to a file.\n" + "\t\t Exports the chosen module class to a file\n" +
"\t\t\t\t" +
"\t\t at the location specified by the given path." +
"\n" +
"\n" + "\n" +
"Available module-classes for export:\n" + "Available module-classes for export:\n" +
" \t\t categories \t\t all categories of the system\n" + " \t\t categories \t\t all categories of the system\n" +
@ -240,6 +256,8 @@ public class ExportCliTool extends Program {
" \n" + " \n" +
" \t\t all_core \t\t all objects of the entire core module" + " \t\t all_core \t\t all objects of the entire core module" +
"\n" + "\n" +
"\n" +
"" +
"Do use for exporting java objects of a specified class.\n" + "Do use for exporting java objects of a specified class.\n" +
"\n" "\n"
); );

View File

@ -44,112 +44,139 @@ import java.util.ArrayList;
*/ */
class ExportHelper { class ExportHelper {
private static String pathName = private static String pathName;
"/home/jensp/Downloads/tmp/iaw-exports";
private static boolean indentation = false; private static boolean indentation = false;
static void setPath(String path) {
pathName = path;
}
static void exportCategories() { static void exportCategories() {
System.out.printf("\tExporting categories...");
CategoryMarshaller categoryMarshaller = new CategoryMarshaller categoryMarshaller = new
CategoryMarshaller(); CategoryMarshaller();
categoryMarshaller.prepare(Format.XML, pathName, categoryMarshaller.prepare(Format.XML, pathName,
"categories", indentation); "categories", indentation);
categoryMarshaller.exportList(new ArrayList<>( categoryMarshaller.exportList(new ArrayList<>(
NgCollection.categories.values())); NgCollection.categories.values()));
System.out.printf("\t\tdone.\n");
} }
static void exportCategorizations() { static void exportCategorizations() {
System.out.printf("\tExporting categorizations...");
CategorizationMarshaller categorizationMarshaller = new CategorizationMarshaller categorizationMarshaller = new
CategorizationMarshaller(); CategorizationMarshaller();
categorizationMarshaller.prepare(Format.XML, pathName, categorizationMarshaller.prepare(Format.XML, pathName,
"categorizations", indentation); "categorizations", indentation);
categorizationMarshaller.exportList(new ArrayList<>( categorizationMarshaller.exportList(new ArrayList<>(
NgCollection.categorizations.values())); NgCollection.categorizations.values()));
System.out.printf("\tdone.\n");
} }
static void exportUsers() { static void exportUsers() {
System.out.printf("\tExporting users...");
UserMarshaller userMarshaller = new UserMarshaller(); UserMarshaller userMarshaller = new UserMarshaller();
userMarshaller.prepare(Format.XML, pathName, userMarshaller.prepare(Format.XML, pathName,
"users", indentation); "users", indentation);
userMarshaller.exportList(new ArrayList<>( userMarshaller.exportList(new ArrayList<>(
NgCollection.users.values())); NgCollection.users.values()));
System.out.printf("\t\tdone.\n");
} }
static void exportGroups() { static void exportGroups() {
System.out.printf("\tExporting groups...");
GroupMarshaller groupMarshaller = new GroupMarshaller(); GroupMarshaller groupMarshaller = new GroupMarshaller();
groupMarshaller.prepare(Format.XML, pathName, groupMarshaller.prepare(Format.XML, pathName,
"groups", indentation); "groups", indentation);
groupMarshaller.exportList(new ArrayList<>( groupMarshaller.exportList(new ArrayList<>(
NgCollection.groups.values())); NgCollection.groups.values()));
System.out.printf("\t\tdone.\n");
} }
static void exportGroupMemberships() { static void exportGroupMemberships() {
System.out.printf("\tExporting group memberships...");
GroupMembershipMarshaller groupMembershipMarshaller = new GroupMembershipMarshaller groupMembershipMarshaller = new
GroupMembershipMarshaller(); GroupMembershipMarshaller();
groupMembershipMarshaller.prepare(Format.XML, pathName, groupMembershipMarshaller.prepare(Format.XML, pathName,
"groupMemberships", indentation); "groupMemberships", indentation);
groupMembershipMarshaller.exportList(new ArrayList<>( groupMembershipMarshaller.exportList(new ArrayList<>(
NgCollection.groupMemberships.values())); NgCollection.groupMemberships.values()));
System.out.printf("\tdone.\n");
} }
static void exportRoles() { static void exportRoles() {
System.out.printf("\tExporting roles...");
RoleMarshaller roleMarshaller = new RoleMarshaller(); RoleMarshaller roleMarshaller = new RoleMarshaller();
roleMarshaller.prepare(Format.XML, pathName, roleMarshaller.prepare(Format.XML, pathName,
"roles", indentation); "roles", indentation);
roleMarshaller.exportList(new ArrayList<>(NgCollection roleMarshaller.exportList(new ArrayList<>(NgCollection
.roles.values())); .roles.values()));
System.out.printf("\t\tdone.\n");
} }
static void exportRoleMemberships() { static void exportRoleMemberships() {
System.out.printf("\tExporting role memberships...");
RoleMembershipMarshaller roleMembershipMarshaller = new RoleMembershipMarshaller roleMembershipMarshaller = new
RoleMembershipMarshaller(); RoleMembershipMarshaller();
roleMembershipMarshaller.prepare(Format.XML, pathName, roleMembershipMarshaller.prepare(Format.XML, pathName,
"roleMemberships", indentation); "roleMemberships", indentation);
roleMembershipMarshaller.exportList(new ArrayList<> roleMembershipMarshaller.exportList(new ArrayList<>
(NgCollection.roleMemberships.values())); (NgCollection.roleMemberships.values()));
System.out.printf("\tdone.\n");
} }
static void exportWorkflowTemplates() { static void exportWorkflowTemplates() {
System.out.printf("\tExporting workflow templates...");
WorkflowTemplateMarshaller workflowTemplateMarshaller = new WorkflowTemplateMarshaller workflowTemplateMarshaller = new
WorkflowTemplateMarshaller(); WorkflowTemplateMarshaller();
workflowTemplateMarshaller.prepare(Format.XML, pathName, workflowTemplateMarshaller.prepare(Format.XML, pathName,
"workflowTemplates", indentation); "workflowTemplates", indentation);
workflowTemplateMarshaller.exportList(new ArrayList<>(NgCollection workflowTemplateMarshaller.exportList(new ArrayList<>(NgCollection
.workflowTemplates.values())); .workflowTemplates.values()));
System.out.printf("\tdone.\n");
} }
static void exportWorkflows() { static void exportWorkflows() {
System.out.printf("\tExporting workflows...");
WorkflowMarshaller workflowMarshaller = new WorkflowMarshaller workflowMarshaller = new
WorkflowMarshaller(); WorkflowMarshaller();
workflowMarshaller.prepare(Format.XML, pathName, workflowMarshaller.prepare(Format.XML, pathName,
"workflows", indentation); "workflows", indentation);
workflowMarshaller.exportList(new ArrayList<> workflowMarshaller.exportList(new ArrayList<>
(NgCollection.workflows.values())); (NgCollection.workflows.values()));
System.out.printf("\t\tdone.\n");
} }
static void exportAssignableTasks() { static void exportAssignableTasks() {
System.out.printf("\tExporting assignable tasks...");
AssignableTaskMarshaller assignableTaskMarshaller = new AssignableTaskMarshaller assignableTaskMarshaller = new
AssignableTaskMarshaller(); AssignableTaskMarshaller();
assignableTaskMarshaller.prepare(Format.XML, pathName, assignableTaskMarshaller.prepare(Format.XML, pathName,
"assignableTasks", indentation); "assignableTasks", indentation);
assignableTaskMarshaller.exportList(new ArrayList<> assignableTaskMarshaller.exportList(new ArrayList<>
(NgCollection.assignableTasks.values())); (NgCollection.assignableTasks.values()));
System.out.printf("\tdone.\n");
} }
static void exportTaskAssignments() { static void exportTaskAssignments() {
System.out.printf("\tExporting task assignments...");
TaskAssignmentMarshaller taskAssignmentMarshaller = new TaskAssignmentMarshaller taskAssignmentMarshaller = new
TaskAssignmentMarshaller(); TaskAssignmentMarshaller();
taskAssignmentMarshaller.prepare(Format.XML, pathName, taskAssignmentMarshaller.prepare(Format.XML, pathName,
"taskAssignments", indentation); "taskAssignments", indentation);
taskAssignmentMarshaller.exportList(new ArrayList<> taskAssignmentMarshaller.exportList(new ArrayList<>
(NgCollection.taskAssignments.values())); (NgCollection.taskAssignments.values()));
System.out.printf("\tdone.\n");
} }
static void exportPermissions() { static void exportPermissions() {
System.out.printf("\tExporting permissions...");
PermissionMarshaller permissionMarshaller = new PermissionMarshaller permissionMarshaller = new
PermissionMarshaller(); PermissionMarshaller();
permissionMarshaller.prepare(Format.XML, pathName, permissionMarshaller.prepare(Format.XML, pathName,
"permissions", indentation); "permissions", indentation);
permissionMarshaller.exportList(new ArrayList<> permissionMarshaller.exportList(new ArrayList<>
(NgCollection.permissions.values())); (NgCollection.permissions.values()));
System.out.printf("\t\tdone.\n");
} }
} }

View File

@ -56,7 +56,8 @@ public class MainConverter {
//Verify permissions //Verify permissions
for(Permission permission : NgCollection.permissions.values()) { for(Permission permission : NgCollection.permissions.values()) {
if (permission.getGrantee() == null) { if (permission.getGrantee() == null) {
System.err.printf("MainConverter: Grantee for permission %d is null.%n", permission.getPermissionId()); System.err.printf("MainConverter: Grantee for permission %d " +
"is null.%n", permission.getPermissionId());
System.exit(-1); System.exit(-1);
} }
} }

View File

@ -48,8 +48,11 @@ public class CategoryConversion {
List<com.arsdigita.categorization.Category> trunkCategories = com List<com.arsdigita.categorization.Category> trunkCategories = com
.arsdigita.categorization.Category.getAllObjectCategories(); .arsdigita.categorization.Category.getAllObjectCategories();
System.err.printf("\tConverting categorizes and categorizations...\n");
createCategoryAndCategorizations(trunkCategories); createCategoryAndCategorizations(trunkCategories);
setRingAssociations(trunkCategories); setRingAssociations(trunkCategories);
System.err.printf("\tdone.\n");
} }
/** /**
@ -62,6 +65,9 @@ public class CategoryConversion {
*/ */
private static void createCategoryAndCategorizations( private static void createCategoryAndCategorizations(
List<com.arsdigita.categorization.Category> trunkCategories) { List<com.arsdigita.categorization.Category> trunkCategories) {
long pCategories = 0, pCategorizations = 0;
for (com.arsdigita.categorization.Category for (com.arsdigita.categorization.Category
trunkCategory : trunkCategories) { trunkCategory : trunkCategories) {
@ -72,8 +78,13 @@ public class CategoryConversion {
CategorizedCollection categorizedCollection = trunkCategory CategorizedCollection categorizedCollection = trunkCategory
.getObjects(com.arsdigita.categorization.Category .getObjects(com.arsdigita.categorization.Category
.BASE_DATA_OBJECT_TYPE); .BASE_DATA_OBJECT_TYPE);
createCategorizations(category, categorizedCollection); pCategorizations += createCategorizations(category,
categorizedCollection);
pCategories++;
} }
System.err.printf("\t\tCreated %d categories and %d categorizations." +
"\n", pCategories, pCategorizations);
} }
/** /**
@ -85,9 +96,11 @@ public class CategoryConversion {
* @param categorizedObjects A collection of the {@code Categorization}s * @param categorizedObjects A collection of the {@code Categorization}s
* as they are represented in this trunk-system * as they are represented in this trunk-system
*/ */
private static void createCategorizations(Category category, private static long createCategorizations(Category category,
CategorizedCollection CategorizedCollection
categorizedObjects) { categorizedObjects) {
long processed = 0;
while (categorizedObjects.next()) { while (categorizedObjects.next()) {
CcmObject categorizedObject = NgCollection.ccmObjects.get(((ACSObject) CcmObject categorizedObject = NgCollection.ccmObjects.get(((ACSObject)
categorizedObjects.getDomainObject()).getID().longValue()); categorizedObjects.getDomainObject()).getID().longValue());
@ -101,7 +114,11 @@ public class CategoryConversion {
category.addObject(categorization); category.addObject(categorization);
categorizedObject.addCategory(categorization); categorizedObject.addCategory(categorization);
} }
processed++;
} }
return processed;
} }
/** /**

View File

@ -49,14 +49,9 @@ public class GroupConversion {
roleGroups = new ArrayList<>(); roleGroups = new ArrayList<>();
trunkGroups = com.arsdigita.kernel.Group.getAllObjectGroups(); trunkGroups = com.arsdigita.kernel.Group.getAllObjectGroups();
// List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel System.err.printf("\tConverting groups and group memberships...\n");
// .Role.getAllObjectRoles();
// trunkRoles.forEach(role -> roleGroups.add(role.getGroup()));
// remove subgroups representing roles
// trunkGroups.removeAll(roleGroups);
createGroupsAndSetAssociations(trunkGroups); createGroupsAndSetAssociations(trunkGroups);
System.err.printf("\tdone.\n");
} }
/** /**
@ -68,14 +63,20 @@ public class GroupConversion {
*/ */
private static void createGroupsAndSetAssociations( private static void createGroupsAndSetAssociations(
List<com.arsdigita.kernel.Group> trunkGroups) { List<com.arsdigita.kernel.Group> trunkGroups) {
long pGroups = 0, pMemberships = 0;
for (com.arsdigita.kernel.Group trunkGroup : trunkGroups) { for (com.arsdigita.kernel.Group trunkGroup : trunkGroups) {
// create groups // create groups
Group group = new Group(trunkGroup); Group group = new Group(trunkGroup);
// groupMemberships // groupMemberships
UserCollection userCollection = trunkGroup.getMemberUsers(); UserCollection userCollection = trunkGroup.getMemberUsers();
createGroupMemberships(group, userCollection); pMemberships += createGroupMemberships(group, userCollection);
pGroups++;
} }
System.err.printf("\t\tCreated %d groups and %d group memberships.\n",
pGroups, pMemberships);
} }
/** /**
@ -88,8 +89,10 @@ public class GroupConversion {
* {@link com.arsdigita.kernel.User}s belonging to * {@link com.arsdigita.kernel.User}s belonging to
* the given group * the given group
*/ */
private static void createGroupMemberships(Group group, UserCollection private static long createGroupMemberships(Group group, UserCollection
userCollection) { userCollection) {
long processed = 0;
while (userCollection.next()) { while (userCollection.next()) {
User member = NgCollection.users.get(userCollection.getUser() User member = NgCollection.users.get(userCollection.getUser()
.getID().longValue()); .getID().longValue());
@ -102,7 +105,11 @@ public class GroupConversion {
group.addMembership(groupMembership); group.addMembership(groupMembership);
member.addGroupMembership(groupMembership); member.addGroupMembership(groupMembership);
} }
processed++;
} }
return processed;
} }
} }

View File

@ -57,9 +57,9 @@ public class PermissionConversion {
com.arsdigita.kernel.permissions.Permission com.arsdigita.kernel.permissions.Permission
.getAllObjectPermissions(); .getAllObjectPermissions();
System.err.println("Converting permissions..."); System.err.printf("\tConverting permissions...\n");
createPermissionsAndSetAssociations(trunkPermissions); createPermissionsAndSetAssociations(trunkPermissions);
System.err.println("Setting grantee on permissions...");
try { try {
setGranteeDependency(trunkPermissions); setGranteeDependency(trunkPermissions);
} catch(Throwable ex) { } catch(Throwable ex) {
@ -68,6 +68,8 @@ public class PermissionConversion {
ex.printStackTrace(System.err); ex.printStackTrace(System.err);
System.exit(-1); System.exit(-1);
} }
System.err.printf("\tdone.\n");
} }
/** /**
@ -78,20 +80,25 @@ public class PermissionConversion {
* {@link com.arsdigita.kernel.permissions.Permission}s * {@link com.arsdigita.kernel.permissions.Permission}s
* from the old trunk-system * from the old trunk-system
*/ */
private static void createPermissionsAndSetAssociations(List<com.arsdigita.kernel.permissions.Permission> trunkPermissions) { private static void createPermissionsAndSetAssociations(final List<com
.arsdigita.kernel.permissions.Permission> trunkPermissions) {
long processed = 0; long processed = 0, skipped = 0;
for (com.arsdigita.kernel.permissions.Permission trunkPermission : for (com.arsdigita.kernel.permissions.Permission trunkPermission :
trunkPermissions) { trunkPermissions) {
// Skip permissions generated by SQL install script. These are
//Skip permissions generated by SQL install script. These are system internal permissions which are not // system internal permissions which are not needed in the export
// needed in the export because they also exist in every other installation, // because they also exist in every other installation, including
// including LibreCCM 8 (LibreCCM NG). // LibreCCM 8 (LibreCCM NG).
if (-204 == ((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue() if (-204 == ((BigDecimal) trunkPermission.getPartyOID()
|| -300 == ((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue() .get("id")).longValue()
|| -200 == ((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue()) { || -300 == ((BigDecimal) trunkPermission.getPartyOID()
System.err.println("Skiping because it is a internal permission"); .get("id")).longValue()
|| -200 == ((BigDecimal) trunkPermission.getPartyOID()
.get("id")).longValue()) {
/*System.err.println(
"Skiping because it is a internal permission");*/
skipped++;
continue; continue;
} }
@ -120,7 +127,8 @@ public class PermissionConversion {
processed++; processed++;
} }
System.err.printf("Created %d permissions%n", processed); System.err.printf("\t\tCreated %d permissions and skipped: %d.\n",
processed, skipped);
} }
/** /**
@ -142,137 +150,114 @@ public class PermissionConversion {
* {@link com.arsdigita.kernel.permissions.Permission}s * {@link com.arsdigita.kernel.permissions.Permission}s
* from the old trunk-system * from the old trunk-system
*/ */
private static void setGranteeDependency(final List<com.arsdigita.kernel.permissions.Permission> trunkPermissions) { private static void setGranteeDependency(final List<com.arsdigita.kernel
.permissions.Permission> trunkPermissions) {
long duplicates = 0;
long processed = 0; for (com.arsdigita.kernel.permissions.Permission trunkPermission :
trunkPermissions) {
for (com.arsdigita.kernel.permissions.Permission trunkPermission : trunkPermissions) { // Skip permissions generated by SQL install script. These are
// system internal permissions which are not needed in the export
// Skip permissions generated by SQL install script. These are system internal permissions which are not // because they also exist in every other installation, including
// needed in the export because they also exist in every other installation, // LibreCCM 8 (LibreCCM NG).
// including LibreCCM 8 (LibreCCM NG). if (-204 == ((BigDecimal) trunkPermission.getPartyOID()
if (-204 == ((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue() .get("id")).longValue()
|| -300 == ((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue() || -300 == ((BigDecimal) trunkPermission.getPartyOID()
|| -200 == ((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue()) { .get("id")).longValue()
System.err.println("Skiping because it is a internal permission"); || -200 == ((BigDecimal) trunkPermission.getPartyOID()
.get("id")).longValue()) {
/*System.err.println(
"Skiping because it is a internal permission");*/
continue; continue;
} }
final String oldId = Permission.genOldId(trunkPermission); final String oldId = Permission.genOldId(trunkPermission);
final long permissionId = PermissionIdMapper.map.get(oldId); final long permissionId = PermissionIdMapper.map.get(oldId);
final Permission permission = NgCollection.permissions.get(permissionId); // get ng permission
final Permission permission = NgCollection.permissions.get(
permissionId);
// get all parties serving as the grantee of this permission // get all parties serving as the grantee of this permission
final BigDecimal trunkGranteeId = (BigDecimal) trunkPermission final BigDecimal trunkGranteeId = (BigDecimal) trunkPermission
.getPartyOID() .getPartyOID().get("id");
.get("id"); final List<com.arsdigita.kernel.Party> allTrunkParties =
System.err.printf("Trying to set grantee for permission with oldId = \"%s\" | objectId = %d | granteeId = %d | privilege = \"%s\" -> %d%n", com.arsdigita.kernel.Party.getAllObjectParties();
oldId, final List<com.arsdigita.kernel.Party> trunkGranteeParties =
((BigDecimal) trunkPermission.getACSObject().get("id")).longValue(), allTrunkParties
trunkGranteeId.longValue(),
trunkPermission.getPrivilege().getName(),
permissionId);
final List<com.arsdigita.kernel.Party> availableParties = com.arsdigita.kernel.Party.getAllObjectParties();
System.err.println("Got available parties...");
System.err.printf("Available parties:%d%n", availableParties.size());
for(com.arsdigita.kernel.Party party : availableParties) {
System.err.printf("\t%s%n", Objects.toString(party.getID()));
}
final List<com.arsdigita.kernel.Party> trunkParties = availableParties
.stream() .stream()
.filter(p -> { .filter(p->Objects.equals(p.getID(),trunkGranteeId))
/*System.err.printf("p = %s; trunkGranteeId = %s%n",
Objects.toString(p.getID(),
Objects.toString(trunkGranteeId)));*/
return Objects.equals(p.getID(), trunkGranteeId);
})
.collect(Collectors.toList()); .collect(Collectors.toList());
System.err.printf("Found %d parties associated with the permission%n", for (com.arsdigita.kernel.Party trunkGranteeParty :
trunkParties.size()); trunkGranteeParties) {
for (com.arsdigita.kernel.Party trunkGranteeParty : trunkParties) {
System.err.printf("Trying to set grantee for permission %d to party %s%n",
permission.getPermissionId(),
trunkGranteeParty.getName());
// grantee instance of Group, possibly multiple roles or none // grantee instance of Group, possibly multiple roles or none
if (trunkGranteeParty instanceof com.arsdigita.kernel.Group) { if (trunkGranteeParty instanceof com.arsdigita.kernel.Group) {
final com.arsdigita.kernel.Group trunkGranteeGroup = final com.arsdigita.kernel.Group trunkGranteeGroup =
(com.arsdigita.kernel.Group) trunkGranteeParty; (com.arsdigita.kernel.Group) trunkGranteeParty;
final RoleCollection roleCollection = trunkGranteeGroup.getRoles(); final RoleCollection roleCollection = trunkGranteeGroup
.getRoles();
// if group contains 1 or more roles // if group contains 1 or more roles
if (!roleCollection.isEmpty()) { if (!roleCollection.isEmpty()) {
while (roleCollection.next()) { while (roleCollection.next()) {
final Role grantee = NgCollection.roles.get(roleCollection final Role grantee = NgCollection.roles.get(
.getRole().getID().longValue()); roleCollection.getRole().getID().longValue());
final Permission duplicatePermission = new Permission // duplicate permission for found role as grantee
(permission); final Permission duplicatePermission = new Permission(
permission);
// set grantee and opposed association
duplicatePermission.setGrantee(grantee); duplicatePermission.setGrantee(grantee);
grantee.addPermission(duplicatePermission); grantee.addPermission(duplicatePermission);
final CcmObject object = duplicatePermission.getObject(); final String duplicateOldId = Permission.genOldId
long objectId = 0; (duplicatePermission);
if (object != null) {
objectId = object.getObjectId();
}
//final String duplicateOldId = Long.toString(objectId) + "_" + Long.toString(grantee.getRoleId() + "_" + permission.getGrantedPrivilege());
final String duplicateOldId = String.format("%d_%d_%s",
objectId,
grantee.getRoleId(),
permission.getGrantedPrivilege());
PermissionIdMapper.map.put(duplicateOldId, PermissionIdMapper.map.put(duplicateOldId,
duplicatePermission.getPermissionId()); duplicatePermission.getPermissionId());
duplicates++;
} }
} }
// new Role for this group // new Role for this group
final Group member = NgCollection.groups.get final Group member = NgCollection.groups.get
(trunkGranteeGroup.getID().longValue()); (trunkGranteeGroup.getID().longValue());
final Role granteeRole = createNewRole(member); final Role granteeRole = createNewRole(member);
// set grantee and opposed association // set grantee and opposed association
permission.setGrantee(granteeRole); permission.setGrantee(granteeRole);
granteeRole.addPermission(permission); granteeRole.addPermission(permission);
// grantee instance of User, new Role necessary // grantee instance of User, new Role necessary
} else if (trunkGranteeParty instanceof com.arsdigita.kernel.User) { } else if (trunkGranteeParty instanceof com.arsdigita.kernel.User) {
// new Role for this user
final com.arsdigita.kernel.User trunkGranteeUser = (com final com.arsdigita.kernel.User trunkGranteeUser = (com
.arsdigita.kernel.User) trunkGranteeParty; .arsdigita.kernel.User) trunkGranteeParty;
final User member = NgCollection.users.get final User member = NgCollection.users.get
(trunkGranteeUser.getID().longValue()); (trunkGranteeUser.getID().longValue());
final Role granteeRole = createNewRole(member); final Role granteeRole = createNewRole(member);
// set grantee and opposed association // set grantee and opposed association
permission.setGrantee(granteeRole); permission.setGrantee(granteeRole);
granteeRole.addPermission(permission); granteeRole.addPermission(permission);
} else { } else {
System.err.printf("!!!Failed to convert grantee for permission %s%n", System.err.printf("!!!Failed to convert grantee for " +
trunkPermission.getOID().toString()); "permission %s%n", trunkPermission.getOID()
.toString());
} }
} }
if(permission.getGrantee() == null) { if (permission.getGrantee() == null) {
System.err.printf("PermissionConversation: No Grantee for permission with database id %d%n", ((BigDecimal) trunkPermission.getACSObject().get("id")). System.err.printf("PermissionConversation: No Grantee for " +
longValue()); "permission with database id %d%n", ((BigDecimal)
trunkPermission.getACSObject().get("id")).longValue());
//System.exit(-1); //System.exit(-1);
} else { } else {
System.out.printf("Set grantee for permission %d%n%n", permission.getPermissionId()); /*System.out.printf("Set grantee for permission %d%n%n",
permission.getPermissionId());*/
} }
processed++;
} }
System.err.printf("\t\tCreated %d duplicate permissions.\n",
System.err.printf("Set grantee for %d permissions.%n", processed); duplicates);
} }
/** /**

View File

@ -47,7 +47,9 @@ public class RoleConversion {
List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel
.Role.getAllObjectRoles(); .Role.getAllObjectRoles();
System.err.printf("\tCreating roles and role memberships...\n");
createRolesAndSetAssociations(trunkRoles); createRolesAndSetAssociations(trunkRoles);
System.err.printf("\tdone.\n");
} }
/** /**
@ -59,14 +61,20 @@ public class RoleConversion {
*/ */
private static void createRolesAndSetAssociations( private static void createRolesAndSetAssociations(
List<com.arsdigita.kernel.Role> trunkRoles) { List<com.arsdigita.kernel.Role> trunkRoles) {
long pRoles = 0, pMemberships = 0;
for (com.arsdigita.kernel.Role trunkRole : trunkRoles) { for (com.arsdigita.kernel.Role trunkRole : trunkRoles) {
// create roles // create roles
Role role = new Role(trunkRole); Role role = new Role(trunkRole);
// roleMemberships // roleMemberships
PartyCollection partyCollection = trunkRole.getContainedParties(); PartyCollection partyCollection = trunkRole.getContainedParties();
createRoleMemberships(role, partyCollection); pMemberships += createRoleMemberships(role, partyCollection);
pRoles++;
} }
System.out.printf("\t\tCreated %d roles and %d role memberships.\n",
pRoles, pMemberships);
} }
/** /**
@ -79,8 +87,10 @@ public class RoleConversion {
* {@link com.arsdigita.kernel.Party}s belonging to * {@link com.arsdigita.kernel.Party}s belonging to
* the given group * the given group
*/ */
private static void createRoleMemberships(Role role, PartyCollection private static long createRoleMemberships(Role role, PartyCollection
partyCollection) { partyCollection) {
long processed = 0;
while (partyCollection.next()) { while (partyCollection.next()) {
Party member = NgCollection.parties.get(partyCollection.getParty() Party member = NgCollection.parties.get(partyCollection.getParty()
.getID().longValue()); .getID().longValue());
@ -93,6 +103,9 @@ public class RoleConversion {
role.addMembership(roleMembership); role.addMembership(roleMembership);
member.addRoleMembership(roleMembership); member.addRoleMembership(roleMembership);
} }
processed++;
} }
return processed;
} }
} }

View File

@ -41,7 +41,14 @@ public class UserConversion {
List<com.arsdigita.kernel.User> trunkUsers = com.arsdigita.kernel List<com.arsdigita.kernel.User> trunkUsers = com.arsdigita.kernel
.User.getAllObjectUsers(); .User.getAllObjectUsers();
System.err.printf("\tConverting users...\n");
// create users // create users
trunkUsers.forEach(User::new); long processed = 0;
for (com.arsdigita.kernel.User trunkUser : trunkUsers) {
new User(trunkUser);
processed++;
}
System.out.printf("\t\tCreated %d users.\n", processed);
System.err.printf("\tdone.\n");
} }
} }

View File

@ -55,9 +55,12 @@ public class AssignableTaskConversion {
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();
System.err.printf("\tConverting assignable tasks and task " +
"assignments...\n");
createAssignableTasksAndSetAssociations(trunkUserTasks); createAssignableTasksAndSetAssociations(trunkUserTasks);
setTaskRingDependencies(trunkUserTasks); setTaskRingDependencies(trunkUserTasks);
System.err.printf("\tdone.\n");
} }
/** /**
@ -70,6 +73,8 @@ public class AssignableTaskConversion {
*/ */
private static void createAssignableTasksAndSetAssociations(List<com.arsdigita private static void createAssignableTasksAndSetAssociations(List<com.arsdigita
.workflow.simple.UserTask> trunkUserTasks) { .workflow.simple.UserTask> trunkUserTasks) {
long pTasks = 0, pAssignments = 0;
for (com.arsdigita.workflow.simple.UserTask trunkUserTask : for (com.arsdigita.workflow.simple.UserTask trunkUserTask :
trunkUserTasks) { trunkUserTasks) {
@ -123,8 +128,14 @@ public class AssignableTaskConversion {
// taskAssignments // taskAssignments
GroupCollection groupCollection = trunkUserTask GroupCollection groupCollection = trunkUserTask
.getAssignedGroupCollection(); .getAssignedGroupCollection();
createTaskAssignments(assignableTask, groupCollection); pAssignments += createTaskAssignments(assignableTask,
groupCollection);
pTasks++;
} }
System.err.printf("\t\tCreated %d assignable tasks and %d task " +
"assignments.\n", pTasks, pAssignments);
} }
/** /**
@ -139,8 +150,10 @@ public class AssignableTaskConversion {
* {@link com.arsdigita.kernel.Role}s belonging to * {@link com.arsdigita.kernel.Role}s belonging to
* the assignableTask * the assignableTask
*/ */
private static void createTaskAssignments(AssignableTask assignableTask, private static long createTaskAssignments(AssignableTask assignableTask,
GroupCollection groupCollection) { GroupCollection groupCollection) {
long processed = 0;
while (groupCollection.next()) { while (groupCollection.next()) {
RoleCollection roleCollection = groupCollection.getGroup().getRoles(); RoleCollection roleCollection = groupCollection.getGroup().getRoles();
while (roleCollection.next()) { while (roleCollection.next()) {
@ -157,7 +170,10 @@ public class AssignableTaskConversion {
role.addAssignedTask(taskAssignment); role.addAssignedTask(taskAssignment);
} }
} }
processed++;
} }
return processed;
} }
/** /**

View File

@ -46,11 +46,15 @@ public class WorkflowConversion {
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();
System.err.printf("\tConverting workflows...\n");
createWorkflowAndSetAssociations(trunkWorkflows); createWorkflowAndSetAssociations(trunkWorkflows);
System.err.printf("\tdone.\n");
} }
private static void createWorkflowAndSetAssociations( private static void createWorkflowAndSetAssociations(
List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows) { List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows) {
long processed = 0;
for (com.arsdigita.workflow.simple.Workflow for (com.arsdigita.workflow.simple.Workflow
trunkWorkflow : trunkWorkflows) { trunkWorkflow : trunkWorkflows) {
@ -74,6 +78,10 @@ public class WorkflowConversion {
.getID().longValue()); .getID().longValue());
workflow.setObject(object); workflow.setObject(object);
} }
processed++;
} }
System.err.printf("\t\tCreated %d workflows.\n", processed);
} }
} }

View File

@ -44,6 +44,15 @@ public class WorkflowTemplateConversion {
trunkWorkflowTemplates = com.arsdigita.workflow.simple trunkWorkflowTemplates = com.arsdigita.workflow.simple
.WorkflowTemplate.getAllObjectWorkflowTemplates(); .WorkflowTemplate.getAllObjectWorkflowTemplates();
System.err.printf("\tConverting workflow templates...\n");
trunkWorkflowTemplates.forEach(WorkflowTemplate::new); trunkWorkflowTemplates.forEach(WorkflowTemplate::new);
long processed = 0;
for (com.arsdigita.workflow.simple.WorkflowTemplate
trunkWorkflowTemplate : trunkWorkflowTemplates) {
new WorkflowTemplate(trunkWorkflowTemplate);
processed++;
}
System.out.printf("\t\t Created %d workflow templates.", processed);
System.err.printf("\tdone.\n");
} }
} }

View File

@ -27,7 +27,6 @@ import com.arsdigita.portation.modules.core.security.util.PermissionIdMapper;
import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference; import com.fasterxml.jackson.annotation.JsonIdentityReference;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
/** /**
@ -49,18 +48,8 @@ public class Permission implements Portable {
private Date creationDate; private Date creationDate;
private String creationIp; private String creationIp;
public static String genOldId(com.arsdigita.kernel.permissions.Permission permission) {
return String.join("_",
permission.getACSObject().get("id").toString(),
permission.getPartyOID().get("id").toString(),
permission.getPrivilege().getName());
}
public Permission(final com.arsdigita.kernel.permissions.Permission trunkPermission) { public Permission(final com.arsdigita.kernel.permissions.Permission trunkPermission) {
final String oldId = genOldId(trunkPermission); final String oldId = genOldId(trunkPermission);
//((BigDecimal) trunkPermission.getACSObject().get("id")).toString()
//+ "_" +
//((BigDecimal) trunkPermission.getPartyOID().get("id")).toString();
this.permissionId = ACSObject.generateID().longValue(); this.permissionId = ACSObject.generateID().longValue();
PermissionIdMapper.map.put(oldId, this.permissionId); PermissionIdMapper.map.put(oldId, this.permissionId);
@ -73,15 +62,35 @@ public class Permission implements Portable {
this.creationDate = trunkPermission.getCreationDate(); this.creationDate = trunkPermission.getCreationDate();
this.creationIp = trunkPermission.getCreationIP(); this.creationIp = trunkPermission.getCreationIP();
System.out.printf("Permission oldId = \"%s\" | objectId = %d | granteeId = %d | privilege = \"%s\" -> permissionId = %d%n",
oldId,
((BigDecimal) trunkPermission.getACSObject().get("id")).longValue(),
((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue(),
this.grantedPrivilege,
permissionId);
NgCollection.permissions.put(this.permissionId, this); NgCollection.permissions.put(this.permissionId, this);
} }
/**
* Generates old id of all permissions.
*
* @param permission The permission object of this system
*
* @return String with the generated old id
*/
public static String genOldId(com.arsdigita.kernel.permissions.Permission
permission) {
return String.join("_",
permission.getPrivilege().getName(),
permission.getACSObject().get("id").toString(),
permission.getPartyOID().get("id").toString());
}
public static String genOldId(Permission permission) {
long objectId = 0;
if (permission.getObject() != null)
objectId = permission.getObject().getObjectId();
return String.format("%s_%d_%d",
permission.getGrantedPrivilege(),
objectId,
permission.getGrantee().getRoleId());
}
/** /**
* Constructor to copy a given Permission. Needed for purposes of * Constructor to copy a given Permission. Needed for purposes of
* creating permissions for multiple grantees from the trunk object. * creating permissions for multiple grantees from the trunk object.