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

View File

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

View File

@ -56,7 +56,8 @@ public class MainConverter {
//Verify permissions
for(Permission permission : NgCollection.permissions.values()) {
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);
}
}

View File

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

View File

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

View File

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

View File

@ -47,7 +47,9 @@ public class RoleConversion {
List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel
.Role.getAllObjectRoles();
System.err.printf("\tCreating roles and role memberships...\n");
createRolesAndSetAssociations(trunkRoles);
System.err.printf("\tdone.\n");
}
/**
@ -59,14 +61,20 @@ public class RoleConversion {
*/
private static void createRolesAndSetAssociations(
List<com.arsdigita.kernel.Role> trunkRoles) {
long pRoles = 0, pMemberships = 0;
for (com.arsdigita.kernel.Role trunkRole : trunkRoles) {
// create roles
Role role = new Role(trunkRole);
// roleMemberships
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
* the given group
*/
private static void createRoleMemberships(Role role, PartyCollection
private static long createRoleMemberships(Role role, PartyCollection
partyCollection) {
long processed = 0;
while (partyCollection.next()) {
Party member = NgCollection.parties.get(partyCollection.getParty()
.getID().longValue());
@ -93,6 +103,9 @@ public class RoleConversion {
role.addMembership(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
.User.getAllObjectUsers();
System.err.printf("\tConverting users...\n");
// 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
.arsdigita.workflow.simple.UserTask.getAllObjectUserTasks();
System.err.printf("\tConverting assignable tasks and task " +
"assignments...\n");
createAssignableTasksAndSetAssociations(trunkUserTasks);
setTaskRingDependencies(trunkUserTasks);
System.err.printf("\tdone.\n");
}
/**
@ -70,6 +73,8 @@ public class AssignableTaskConversion {
*/
private static void createAssignableTasksAndSetAssociations(List<com.arsdigita
.workflow.simple.UserTask> trunkUserTasks) {
long pTasks = 0, pAssignments = 0;
for (com.arsdigita.workflow.simple.UserTask trunkUserTask :
trunkUserTasks) {
@ -123,8 +128,14 @@ public class AssignableTaskConversion {
// taskAssignments
GroupCollection groupCollection = trunkUserTask
.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
* the assignableTask
*/
private static void createTaskAssignments(AssignableTask assignableTask,
private static long createTaskAssignments(AssignableTask assignableTask,
GroupCollection groupCollection) {
long processed = 0;
while (groupCollection.next()) {
RoleCollection roleCollection = groupCollection.getGroup().getRoles();
while (roleCollection.next()) {
@ -157,7 +170,10 @@ public class AssignableTaskConversion {
role.addAssignedTask(taskAssignment);
}
}
processed++;
}
return processed;
}
/**

View File

@ -46,11 +46,15 @@ public class WorkflowConversion {
List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows =
com.arsdigita.workflow.simple.Workflow.getAllObjectWorkflows();
System.err.printf("\tConverting workflows...\n");
createWorkflowAndSetAssociations(trunkWorkflows);
System.err.printf("\tdone.\n");
}
private static void createWorkflowAndSetAssociations(
List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows) {
long processed = 0;
for (com.arsdigita.workflow.simple.Workflow
trunkWorkflow : trunkWorkflows) {
@ -74,6 +78,10 @@ public class WorkflowConversion {
.getID().longValue());
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
.WorkflowTemplate.getAllObjectWorkflowTemplates();
System.err.printf("\tConverting workflow templates...\n");
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.JsonIdentityReference;
import java.math.BigDecimal;
import java.util.Date;
/**
@ -49,18 +48,8 @@ public class Permission implements Portable {
private Date creationDate;
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) {
final String oldId = genOldId(trunkPermission);
//((BigDecimal) trunkPermission.getACSObject().get("id")).toString()
//+ "_" +
//((BigDecimal) trunkPermission.getPartyOID().get("id")).toString();
this.permissionId = ACSObject.generateID().longValue();
PermissionIdMapper.map.put(oldId, this.permissionId);
@ -73,15 +62,35 @@ public class Permission implements Portable {
this.creationDate = trunkPermission.getCreationDate();
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);
}
/**
* 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
* creating permissions for multiple grantees from the trunk object.