use of org.cristalise.kernel.process.resource.ResourceImportHandler in project kernel by cristal-ise.
the class Bootstrap method verifyResource.
/**
* @param ns
* @param itemName
* @param version
* @param itemType
* @param itemPath
* @param outcomes
* @param dataLocation
* @param reset
* @return the Path of the resource either created or initialised from existing data
* @throws Exception
*/
private static DomainPath verifyResource(String ns, String itemName, int version, String itemType, ItemPath itemPath, Set<Outcome> outcomes, String dataLocation, boolean reset) throws Exception {
ResourceImportHandler typeImpHandler = Gateway.getResourceImportHandler(BuiltInResources.getValue(itemType));
Logger.msg(1, "Bootstrap.verifyResource() - Verifying " + typeImpHandler.getName() + " " + itemName + " v" + version);
// Find or create Item for Resource
ItemProxy thisProxy;
DomainPath modDomPath = typeImpHandler.getPath(itemName, ns);
if (modDomPath.exists()) {
Logger.msg(3, "Bootstrap.verifyResource() - Found " + typeImpHandler.getName() + " " + itemName + ".");
thisProxy = verifyPathAndModuleProperty(ns, itemType, itemName, itemPath, modDomPath, modDomPath);
} else {
if (itemPath == null)
itemPath = new ItemPath();
Logger.msg("Bootstrap.verifyResource() - " + typeImpHandler.getName() + " " + itemName + " not found. Creating new.");
thisProxy = createResourceItem(typeImpHandler, itemName, ns, itemPath);
}
// Verify/Import Outcomes, creating events and views as necessary
if (outcomes == null || outcomes.size() == 0) {
outcomes = typeImpHandler.getResourceOutcomes(itemName, ns, dataLocation, version);
}
if (outcomes.size() == 0)
Logger.warning("Bootstrap.verifyResource() - no Outcome found therefore nothing stored!");
for (Outcome newOutcome : outcomes) {
if (checkToStoreOutcomeVersion(thisProxy, newOutcome, version, reset)) {
// validate it, but not for kernel objects (ns == null) because those are to validate the rest
if (ns != null)
newOutcome.validateAndCheck();
storeOutcomeEventAndViews(thisProxy, newOutcome, version);
CollectionArrayList cols = typeImpHandler.getCollections(itemName, version, newOutcome);
for (Collection<?> col : cols.list) {
Gateway.getStorage().put(thisProxy.getPath(), col, thisProxy);
Gateway.getStorage().clearCache(thisProxy.getPath(), ClusterType.COLLECTION + "/" + col.getName());
col.setVersion(null);
Gateway.getStorage().put(thisProxy.getPath(), col, thisProxy);
}
}
}
Gateway.getStorage().commit(thisProxy);
return modDomPath;
}
use of org.cristalise.kernel.process.resource.ResourceImportHandler in project kernel by cristal-ise.
the class Gateway method getResourceImportHandler.
/**
* Retrieves the ResourceImportHandler available for the resource type. It creates a new if configured
* or falls back to the default one provided in the kernel
*
* @param resType the type o the Resource
* @return the initialised ResourceImportHandler
*/
public static ResourceImportHandler getResourceImportHandler(BuiltInResources resType) throws Exception {
if (resourceImportHandlerCache.containsKey(resType))
return resourceImportHandlerCache.get(resType);
ResourceImportHandler handler = null;
if (Gateway.getProperties().containsKey("ResourceImportHandler." + resType)) {
try {
handler = (ResourceImportHandler) Gateway.getProperties().getInstance("ResourceImportHandler." + resType);
} catch (Exception ex) {
Logger.error(ex);
Logger.error("Exception loading ResourceHandler for " + resType + ". Using default.");
}
}
if (handler == null)
handler = new DefaultResourceImportHandler(resType);
resourceImportHandlerCache.put(resType, handler);
return handler;
}
Aggregations