Search in sources :

Example 1 with ResourceImportHandler

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;
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) ResourceImportHandler(org.cristalise.kernel.process.resource.ResourceImportHandler) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 2 with ResourceImportHandler

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;
}
Also used : DefaultResourceImportHandler(org.cristalise.kernel.process.resource.DefaultResourceImportHandler) DefaultResourceImportHandler(org.cristalise.kernel.process.resource.DefaultResourceImportHandler) ResourceImportHandler(org.cristalise.kernel.process.resource.ResourceImportHandler) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException)

Aggregations

ResourceImportHandler (org.cristalise.kernel.process.resource.ResourceImportHandler)2 MalformedURLException (java.net.MalformedURLException)1 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)1 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)1 PersistencyException (org.cristalise.kernel.common.PersistencyException)1 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)1 DomainPath (org.cristalise.kernel.lookup.DomainPath)1 ItemPath (org.cristalise.kernel.lookup.ItemPath)1 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)1 DefaultResourceImportHandler (org.cristalise.kernel.process.resource.DefaultResourceImportHandler)1