From 7c341c90d5d45ddf4b868f7ccec91d9cdd23792f Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 6 Mar 2014 16:32:29 +0100 Subject: Module resources get a 'Module' property set when they belong to a particular module. If they belong to a particular module, they are moved into the correct sub-context for that module. If the resource is already set to a different module, and error occurs. --- src/main/java/com/c2kernel/process/Bootstrap.java | 36 +++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/c2kernel') diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index 4f64adf..d472978 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -125,6 +125,33 @@ public class Bootstrap else { DomainPath path = (DomainPath)en.nextElement(); thisProxy = (ItemProxy)Gateway.getProxyManager().getProxy(path); + + DomainPath modDomPath = getResourceDomPath(itemType, ns, itemName); + String moduleName = (ns==null?"kernel":ns); + String itemModule; + try{ + itemModule = thisProxy.getProperty("Module"); + if (!itemModule.equals("") && !itemModule.equals("null") && !moduleName.equals(itemModule)) { + Logger.error("Bootstrap.verifyResource() - Resource '"+itemName+"' included in module "+moduleName+" but is assigned to '"+itemModule+"'. Not overwriting."); + return; + } + } catch (ObjectNotFoundException ex) { + itemModule = ""; + } + + if (!moduleName.equals(itemModule)) { // write module property + Gateway.getStorage().put(thisProxy.getSystemKey(), new Property("Module", moduleName, false), null); + } + + if (!modDomPath.equals(path)) { // move item to module subtree + Logger.msg("Module item "+itemName+" found with path "+path.toString()+". Moving to "+modDomPath.toString()); + modDomPath.setEntity(new EntityPath(thisProxy.getSystemKey())); + if (!modDomPath.exists()) + Gateway.getLDAPLookup().add(modDomPath); + Gateway.getLDAPLookup().delete(path); + } + + try { Viewpoint currentData = (Viewpoint)thisProxy.getObject(ClusterStorage.VIEWPOINT+"/"+getDataType(itemType)+"/"+version); Outcome oldData = currentData.getOutcome(); @@ -161,7 +188,12 @@ public class Bootstrap Gateway.getStorage().commit(thisProxy); } - /** + private static DomainPath getResourceDomPath(String itemType, String ns, + String itemName) throws Exception { + return new DomainPath(getTypeRoot(itemType).toString()+"/system/"+(ns==null?"kernel":ns)+"/"+itemName); + } + + /** * @param itemType * @param itemName * @param data @@ -195,7 +227,7 @@ public class Bootstrap 1, Gateway.getMarshaller().marshall(props), Gateway.getMarshaller().marshall(ca)); - DomainPath newDomPath = new DomainPath(getTypeRoot(itemType).toString()+"/system/"+(ns==null?"kernel":ns)+"/"+itemName); + DomainPath newDomPath = getResourceDomPath(itemType, ns, itemName); newDomPath.setEntity(entityPath); Gateway.getLDAPLookup().add(newDomPath); return (ItemProxy)Gateway.getProxyManager().getProxy(entityPath); -- cgit v1.2.3