[TRUNK][FEATURE]

- adds working export of ldn-terms' ResourceType, CcmApplication, Domain and DomainOwnership
- optimizes imports of some core packages

git-svn-id: https://svn.libreccm.org/ccm/trunk@4986 8810af33-2d31-482b-a856-94f89814c4df
master
tosmers 2017-09-06 13:43:17 +00:00
parent 9cdab4335c
commit 06487845bb
18 changed files with 103 additions and 67 deletions

View File

@ -108,7 +108,7 @@ public class ExportCliTool extends Program {
private void convert() { private void convert() {
try { try {
System.err.println("Started conversions of systems objects to " + System.err.println("Started conversions of systems objects to " +
"ng-objects..."); "ng-objects:");
// Core conversions // Core conversions
CoreConverter.getInstance().startConversionToNg(); CoreConverter.getInstance().startConversionToNg();
@ -148,13 +148,13 @@ public class ExportCliTool extends Program {
//final String moduleClass = args[1]; //final String moduleClass = args[1];
//System.err.printf("module-class: %s\n", moduleClass); //System.err.printf("module-class: %s\n", moduleClass);
final String pathName = args[1]; final String pathName = args[1];
System.err.printf("path: %s\n", pathName); System.err.printf("path for export: %s\n", pathName);
CoreExporter.setPath(pathName); CoreExporter.setPath(pathName);
System.err.printf("\n"); System.err.printf("\n");
try { try {
System.out.println("Started exporting all ng-objects..."); System.out.println("Started exporting all ng-objects:");
// Core // Core
CoreExporter.startExport(); CoreExporter.startExport();

View File

@ -26,6 +26,7 @@ import com.arsdigita.portation.conversion.core.security.RoleConversion;
import com.arsdigita.portation.conversion.core.security.UserConversion; import com.arsdigita.portation.conversion.core.security.UserConversion;
import com.arsdigita.portation.conversion.core.workflow.AssignableTaskConversion; import com.arsdigita.portation.conversion.core.workflow.AssignableTaskConversion;
import com.arsdigita.portation.conversion.core.workflow.WorkflowConversion; import com.arsdigita.portation.conversion.core.workflow.WorkflowConversion;
import com.arsdigita.portation.conversion.core.workflow.WorkflowTemplateConversion;
import com.arsdigita.portation.modules.core.security.Permission; import com.arsdigita.portation.modules.core.security.Permission;
@ -55,23 +56,11 @@ public class CoreConverter extends AbstractConverter {
public void startConversionToNg() { public void startConversionToNg() {
UserConversion.convertAll(); UserConversion.convertAll();
GroupConversion.convertAll(); GroupConversion.convertAll();
RoleConversion.convertAll(); RoleConversion.convertAll();
CategoryConversion.convertAll(); CategoryConversion.convertAll();
NgCoreCollection.sortCategories();
// Verify categories
/*for (Category category : NgCoreCollection.sortedCategories) {
System.err.printf("\t\t\tCategory %s with parent category %s\n",
category.getName(), category.getParentCategory().getName()
);
}*/
WorkflowConversion.convertAll();
AssignableTaskConversion.convertAll();
PermissionConversion.convertAll(); PermissionConversion.convertAll();
// Verify permissions // Verify permissions
for (Permission permission : NgCoreCollection.permissions.values()) { for (Permission permission : NgCoreCollection.permissions.values()) {
if (permission.getGrantee() == null) { if (permission.getGrantee() == null) {
@ -80,6 +69,10 @@ public class CoreConverter extends AbstractConverter {
System.exit(-1); System.exit(-1);
} }
} }
WorkflowConversion.convertAll();
WorkflowTemplateConversion.convertAll();
AssignableTaskConversion.convertAll();
} }
/** /**

View File

@ -61,6 +61,7 @@ public class NgCoreCollection {
// if lists need to be sorted in specific way to work with import // if lists need to be sorted in specific way to work with import
public static ArrayList<Category> sortedCategories; public static ArrayList<Category> sortedCategories;
/** /**
* Private constructor to prevent the instantiation of this class. * Private constructor to prevent the instantiation of this class.
*/ */
@ -68,26 +69,24 @@ public class NgCoreCollection {
/** /**
* Sorts values of category-map to ensure that the parent-categories will * Sorts values of category-map to ensure that the parent-categories will
* be listed befor their childs in the export file. * be listed before their childs in the export file.
* *
* Runs once over the unsorted list and iterates over each their parents * Runs once over the unsorted list and iterates over each their parents
* to add them to the sorted list. After being added to sorted the * to add them to the sorted list. After being added to the sorted list the
* category will be removed from the unsorted list and therefore ignored * category will be removed from the unsorted list and therefore ignored
* in this foreach run. * in this foreach run.
*/ */
static void sortCategories() { public static void sortCategories() {
ArrayList<Category> unsortedCategories = new ArrayList<>(categories.values()); ArrayList<Category> unsortedCategories =
new ArrayList<>(categories.values());
sortedCategories = new ArrayList<>(unsortedCategories.size()); sortedCategories = new ArrayList<>(unsortedCategories.size());
System.err.printf("\tSorting categorizes...\n"); int runs = 0;
int count = 1;
for (Category anUnsorted : unsortedCategories) { for (Category anUnsorted : unsortedCategories) {
//System.err.printf("\t\tNumber: %d\n", count++); add(anUnsorted);
//System.err.printf("\t\tCategory: %s\n", anUnsorted.getName()); runs++;
add(anUnsorted, "\t\t");
//System.err.println("");
} }
System.err.printf("\tdone. Count: %d\n", sortedCategories.size()); System.err.printf("\t\tSorted categories in %d runs.\n", runs);
} }
/** /**
@ -96,25 +95,15 @@ public class NgCoreCollection {
* *
* @param category the current category in the unsorted list * @param category the current category in the unsorted list
*/ */
private static void add(Category category, String indent) { private static void add(Category category) {
Category parent = category.getParentCategory(); Category parent = category.getParentCategory();
//System.err.printf("%s\tHas missing parent?...", indent);
if (parent != null && !sortedCategories.contains(parent)) { if (parent != null && !sortedCategories.contains(parent)) {
//System.err.println("YES."); add(parent);
//System.err.printf("%s\tParent: %s\n", indent, parent.getName());
add(parent, String.format("%s\t", indent));
} else {
//System.err.println("NO.");
} }
//System.err.printf("%sAdded to sorted list?...", indent);
if (!sortedCategories.contains(category)) { if (!sortedCategories.contains(category)) {
sortedCategories.add(category); sortedCategories.add(category);
//System.err.println("YES.");
} else {
//System.err.println("NO.");
} }
} }
} }

View File

@ -53,7 +53,11 @@ public class CategoryConversion {
System.err.printf("\tConverting categories and categorizations...\n"); System.err.printf("\tConverting categories and categorizations...\n");
createCategoryAndCategorizations(trunkCategories); createCategoryAndCategorizations(trunkCategories);
setRingAssociations(trunkCategories); setRingAssociations(trunkCategories);
System.err.printf("\tdone.\n");
System.err.printf("\tSorting categories...\n");
NgCoreCollection.sortCategories();
System.err.println("\tdone.\n");
} }
/** /**

View File

@ -51,7 +51,7 @@ public class GroupConversion {
System.err.printf("\tConverting groups and group memberships...\n"); System.err.printf("\tConverting groups and group memberships...\n");
createGroupsAndSetAssociations(trunkGroups); createGroupsAndSetAssociations(trunkGroups);
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }
/** /**

View File

@ -68,7 +68,7 @@ public class PermissionConversion {
System.exit(-1); System.exit(-1);
} }
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }
/** /**
@ -254,9 +254,9 @@ public class PermissionConversion {
permission.getPermissionId());*/ permission.getPermissionId());*/
} }
} }
System.err.printf("\t\tCreated %d duplicate permissions.\n", System.err.printf("\t\t(Created %d duplicates.)\n",
duplicates); duplicates);
System.err.printf("\t\tCreated %d new roles.\n", System.err.printf("\t\t(Created %d new roles.)\n",
rolesCreated); rolesCreated);
} }

View File

@ -51,7 +51,7 @@ public class RoleConversion {
System.err.printf("\tCreating roles and role memberships...\n"); System.err.printf("\tCreating roles and role memberships...\n");
createRolesAndSetAssociations(trunkRoles); createRolesAndSetAssociations(trunkRoles);
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }
/** /**

View File

@ -51,6 +51,6 @@ public class UserConversion {
processed++; processed++;
} }
System.out.printf("\t\tCreated %d users.\n", processed); System.out.printf("\t\tCreated %d users.\n", processed);
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }
} }

View File

@ -61,7 +61,7 @@ public class AssignableTaskConversion {
"assignments...\n"); "assignments...\n");
createAssignableTasksAndSetAssociations(trunkUserTasks); createAssignableTasksAndSetAssociations(trunkUserTasks);
setTaskRingDependencies(trunkUserTasks); setTaskRingDependencies(trunkUserTasks);
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }

View File

@ -50,7 +50,7 @@ public class WorkflowConversion {
System.err.printf("\tConverting workflows...\n"); System.err.printf("\tConverting workflows...\n");
createWorkflowAndSetAssociations(trunkWorkflows); createWorkflowAndSetAssociations(trunkWorkflows);
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }
private static void createWorkflowAndSetAssociations( private static void createWorkflowAndSetAssociations(

View File

@ -54,7 +54,7 @@ public class WorkflowTemplateConversion {
new WorkflowTemplate(trunkWorkflowTemplate); new WorkflowTemplate(trunkWorkflowTemplate);
processed++; processed++;
} }
System.out.printf("\t\t Created %d workflow templates.", processed); System.out.printf("\t\t Created %d workflow templates.\n", processed);
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }
} }

View File

@ -72,9 +72,10 @@ public class Category extends CcmObject implements Portable {
this.uniqueId = trunkCategory.getID().toString(); this.uniqueId = trunkCategory.getID().toString();
this.name = trunkCategory.getName(); this.name = trunkCategory.getName();
this.title = new LocalizedString();
this.description = new LocalizedString();
CategoryLocalizationCollection categoryLocalizationCollection = CategoryLocalizationCollection categoryLocalizationCollection =
trunkCategory.getCategoryLocalizationCollection(); trunkCategory.getCategoryLocalizationCollection();
if (categoryLocalizationCollection != null && if (categoryLocalizationCollection != null &&
categoryLocalizationCollection.next()) { categoryLocalizationCollection.next()) {
@ -82,9 +83,7 @@ public class Category extends CcmObject implements Portable {
categoryLocalizationCollection.getCategoryLocalization(); categoryLocalizationCollection.getCategoryLocalization();
if (categoryLocalization != null) { if (categoryLocalization != null) {
Locale locale = new Locale(categoryLocalization.getLocale()); Locale locale = new Locale(categoryLocalization.getLocale());
this.title = new LocalizedString();
this.title.addValue(locale, categoryLocalization.getName()); this.title.addValue(locale, categoryLocalization.getName());
this.description = new LocalizedString();
this.description.addValue(locale, categoryLocalization.getDescription()); this.description.addValue(locale, categoryLocalization.getDescription());
} }
} }

View File

@ -24,6 +24,7 @@ import com.arsdigita.london.terms.portation.modules.core.core.Resource;
import com.arsdigita.london.terms.portation.modules.core.core.ResourceType; import com.arsdigita.london.terms.portation.modules.core.core.ResourceType;
import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication; import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -39,8 +40,53 @@ public class NgCoreCollection {
public static Map<Long, Domain> domains = new HashMap<>(); public static Map<Long, Domain> domains = new HashMap<>();
public static Map<Long, DomainOwnership> domainOwnerships = new HashMap<>(); public static Map<Long, DomainOwnership> domainOwnerships = new HashMap<>();
// if lists need to be sorted in specific way to work with import
public static ArrayList<CcmApplication> sortedCcmApplications;
/** /**
* Private constructor to prevent the instantiation of this class. * Private constructor to prevent the instantiation of this class.
*/ */
private NgCoreCollection() {} private NgCoreCollection() {}
/**
* Sorts values of resource-map to ensure that the parent-resources will
* be listed before their childs in the export file.
*
* Runs once over the unsorted list and iterates over each their parents
* to add them to the sorted list. After being added to the sorted list the
* resource will be removed from the unsorted list and therefore ignored
* in this foreach run.
*/
public static void sortCcmApplications() {
ArrayList<CcmApplication> unsortedCcmApplications =
new ArrayList<>(ccmApplications.values());
sortedCcmApplications = new ArrayList<>(unsortedCcmApplications.size());
int runs = 0;
for (CcmApplication anUnsorted : unsortedCcmApplications) {
add(anUnsorted);
runs++;
}
System.err.printf("\t\tSorted ccm applications in %d runs.\n", runs);
}
/**
* Helper method to recursively add all parent resources before their
* childs.
*
* @param ccmApplication the current resource in the unsorted list
*/
private static void add(CcmApplication ccmApplication) {
CcmApplication parent = (CcmApplication) ccmApplication.getParent();
if (parent != null && !sortedCcmApplications.contains(parent)) {
add(parent);
}
if (!sortedCcmApplications.contains(ccmApplication)) {
sortedCcmApplications.add(ccmApplication);
}
}
} }

View File

@ -55,7 +55,7 @@ public class DomainConversion {
System.err.printf("\tConverting domains and domain ownerships...\n"); System.err.printf("\tConverting domains and domain ownerships...\n");
createDomainsAndSetAssociations(trunkDomains); createDomainsAndSetAssociations(trunkDomains);
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }
/** /**

View File

@ -52,6 +52,6 @@ public class ResourceTypeConversion {
processed++; processed++;
} }
System.out.printf("\t\tCreated %d resource types.\n", processed); System.out.printf("\t\tCreated %d resource types.\n", processed);
System.err.printf("\tdone.\n"); System.err.println("\tdone.\n");
} }
} }

View File

@ -52,7 +52,11 @@ public class CcmApplicationConversion {
// create ccm applications // create ccm applications
createCcmApplicationsAndSetAssociations(trunkApplications); createCcmApplicationsAndSetAssociations(trunkApplications);
setRingAssociations(trunkApplications); setRingAssociations(trunkApplications);
System.err.printf("\tdone.\n");
System.err.printf("\tSorting ccm applications...\n");
NgCoreCollection.sortCcmApplications();
System.err.println("\tdone.\n");
} }
/** /**

View File

@ -41,22 +41,12 @@ import java.util.ArrayList;
public class LdnTermsExporter extends AbstractExporter { public class LdnTermsExporter extends AbstractExporter {
public static void startExport() { public static void startExport() {
exportDomains();
exportResourceTypes(); exportResourceTypes();
exportCcmApplications(); exportCcmApplications();
exportDomains();
exportDomainOwnerships(); exportDomainOwnerships();
} }
private static void exportDomains() {
System.out.printf("\tExporting domains...");
DomainMarshaller domainMarshaller = new DomainMarshaller();
domainMarshaller.prepare(
Format.XML, pathName, "domains", indentation);
domainMarshaller.exportList(
new ArrayList<>(NgCoreCollection.domains.values()));
System.out.printf("\t\tdone.\n");
}
private static void exportResourceTypes() { private static void exportResourceTypes() {
System.out.printf("\tExporting resource types..."); System.out.printf("\tExporting resource types...");
ResourceTypeMarshaller resourceTypeMarshaller = new ResourceTypeMarshaller resourceTypeMarshaller = new
@ -79,6 +69,16 @@ public class LdnTermsExporter extends AbstractExporter {
System.out.printf("\tdone.\n"); System.out.printf("\tdone.\n");
} }
private static void exportDomains() {
System.out.printf("\tExporting domains...");
DomainMarshaller domainMarshaller = new DomainMarshaller();
domainMarshaller.prepare(
Format.XML, pathName, "domains", indentation);
domainMarshaller.exportList(
new ArrayList<>(NgCoreCollection.domains.values()));
System.out.printf("\t\tdone.\n");
}
private static void exportDomainOwnerships() { private static void exportDomainOwnerships() {
System.out.printf("\tExporting domain ownerships..."); System.out.printf("\tExporting domain ownerships...");
DomainOwnershipMarshaller domainOwnershipMarshaller = new DomainOwnershipMarshaller domainOwnershipMarshaller = new

View File

@ -32,7 +32,8 @@ public class DomainOwnershipIdGenerator extends ObjectIdGenerator<String> {
@Override @Override
public boolean canUseFor(ObjectIdGenerator gen) { public boolean canUseFor(ObjectIdGenerator gen) {
return gen instanceof DomainOwnershipIdGenerator; if (gen instanceof DomainOwnershipIdGenerator) return true;
else return false;
} }
@Override @Override