From c78449fd2dee42ed340e5be702a42279b1856fc3 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 17 May 2013 16:48:52 +0200 Subject: Force order of imports to make sure roles and agents are in before items, so init push jobs will function. --- .../java/com/c2kernel/process/module/Module.java | 82 +++++++++++----------- .../com/c2kernel/process/module/ModuleImport.java | 2 +- .../com/c2kernel/process/module/ModuleImports.java | 39 ++++++++++ 3 files changed, 80 insertions(+), 43 deletions(-) (limited to 'src/main/java/com/c2kernel') diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java index 33180ae..16f2c29 100644 --- a/src/main/java/com/c2kernel/process/module/Module.java +++ b/src/main/java/com/c2kernel/process/module/Module.java @@ -77,52 +77,50 @@ public class Module { public void importAll(ItemProxy serverEntity, String moduleXML) throws Exception { addModuleItem(moduleXML); int systemAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey(); - for (ModuleImport thisImp : imports.list) { - Logger.msg(1, "Checking for "+thisImp.name+" "+thisImp.getClass().getSimpleName()); - if (thisImp instanceof ModuleResource) { - ModuleResource thisRes = (ModuleResource)thisImp; - try { - Bootstrap.verifyResource(ns, thisRes.name, thisRes.resourceType, Resource.getTextResource(ns, thisRes.resourceLocation)); - } catch (Exception ex) { - Logger.error(ex); - } - } - else if (thisImp instanceof NewItem) { - NewItem thisItem = (NewItem)thisImp; - thisItem.setNamespace(ns); - try { - new DomainPath(new DomainPath(thisItem.initialPath), thisItem.name).getEntity(); - Logger.msg(3, "Module.importAll() - Item '"+thisItem.name+"' found."); - continue; - } catch (ObjectNotFoundException ex) { } - Logger.msg("Module.importAll() - Item '"+thisItem.name+"' not found. Creating."); - thisItem.create(systemAgentId); + + for (ModuleResource thisRes : imports.getResources()) { + try { + Bootstrap.verifyResource(ns, thisRes.name, thisRes.resourceType, Resource.getTextResource(ns, thisRes.resourceLocation)); + } catch (Exception ex) { + Logger.error(ex); } - else if (thisImp instanceof NewRole) { - NewRole thisRole = (NewRole)thisImp; - RolePath rolePath; - try { - rolePath = Gateway.getLDAPLookup().getRoleManager().getRolePath(thisRole.name); - if (rolePath.hasJobList() != thisRole.jobList) { - Logger.msg("Module.importAll() - Role '"+thisRole.name+"' has incorrect joblist settings. Correcting."); - rolePath.setHasJobList(thisRole.jobList); - } - } catch (ObjectNotFoundException ex) { - Logger.msg("Module.importAll() - Role '"+thisRole.name+"' not found. Creating."); - thisRole.create(systemAgentId); + } + + for (NewRole thisRole : imports.getRoles()) { + RolePath rolePath; + try { + rolePath = Gateway.getLDAPLookup().getRoleManager().getRolePath(thisRole.name); + if (rolePath.hasJobList() != thisRole.jobList) { + Logger.msg("Module.importAll() - Role '"+thisRole.name+"' has incorrect joblist settings. Correcting."); + rolePath.setHasJobList(thisRole.jobList); } + } catch (ObjectNotFoundException ex) { + Logger.msg("Module.importAll() - Role '"+thisRole.name+"' not found. Creating."); + thisRole.create(systemAgentId); } - else if (thisImp instanceof NewAgent) { - NewAgent thisAgent = (NewAgent)thisImp; - try { - Gateway.getLDAPLookup().getRoleManager().getAgentPath(thisAgent.name); - Logger.msg(3, "Module.importAll() - User '"+thisAgent.name+"' found."); - continue; - } catch (ObjectNotFoundException ex) { } - Logger.msg("Module.importAll() - User '"+thisAgent.name+"' not found. Creating."); - thisAgent.create(systemAgentId); - } } + + for (NewAgent thisAgent : imports.getAgents()) { + try { + Gateway.getLDAPLookup().getRoleManager().getAgentPath(thisAgent.name); + Logger.msg(3, "Module.importAll() - User '"+thisAgent.name+"' found."); + continue; + } catch (ObjectNotFoundException ex) { } + Logger.msg("Module.importAll() - User '"+thisAgent.name+"' not found. Creating."); + thisAgent.create(systemAgentId); + } + + for (NewItem thisItem : imports.getItems()) { + thisItem.setNamespace(ns); + try { + new DomainPath(new DomainPath(thisItem.initialPath), thisItem.name).getEntity(); + Logger.msg(3, "Module.importAll() - Item '"+thisItem.name+"' found."); + continue; + } catch (ObjectNotFoundException ex) { } + Logger.msg("Module.importAll() - Item '"+thisItem.name+"' not found. Creating."); + thisItem.create(systemAgentId); + } + } public Properties getProperties(boolean isServer) { diff --git a/src/main/java/com/c2kernel/process/module/ModuleImport.java b/src/main/java/com/c2kernel/process/module/ModuleImport.java index 422b3d2..77bf3f6 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleImport.java +++ b/src/main/java/com/c2kernel/process/module/ModuleImport.java @@ -5,5 +5,5 @@ public abstract class ModuleImport { public String name; public abstract String getPath(String ns); - + } \ No newline at end of file diff --git a/src/main/java/com/c2kernel/process/module/ModuleImports.java b/src/main/java/com/c2kernel/process/module/ModuleImports.java index d8c56ce..5dfde42 100644 --- a/src/main/java/com/c2kernel/process/module/ModuleImports.java +++ b/src/main/java/com/c2kernel/process/module/ModuleImports.java @@ -2,6 +2,9 @@ package com.c2kernel.process.module; import java.util.ArrayList; +import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewAgent; +import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewItem; +import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewRole; import com.c2kernel.utils.CastorArrayList; public class ModuleImports extends CastorArrayList { @@ -15,4 +18,40 @@ public class ModuleImports extends CastorArrayList { { super(aList); } + + public ArrayList getResources() { + ArrayList subset = new ArrayList(); + for (ModuleImport imp : list) { + if (imp instanceof ModuleResource) + subset.add((ModuleResource)imp); + } + return subset; + } + + public ArrayList getItems() { + ArrayList subset = new ArrayList(); + for (ModuleImport imp : list) { + if (imp instanceof NewItem) + subset.add((NewItem)imp); + } + return subset; + } + + public ArrayList getAgents() { + ArrayList subset = new ArrayList(); + for (ModuleImport imp : list) { + if (imp instanceof NewAgent) + subset.add((NewAgent)imp); + } + return subset; + } + + public ArrayList getRoles() { + ArrayList subset = new ArrayList(); + for (ModuleImport imp : list) { + if (imp instanceof NewRole) + subset.add((NewRole)imp); + } + return subset; + } } -- cgit v1.2.3