Search in sources :

Example 1 with ItemProxy

use of org.cristalise.kernel.entity.proxy.ItemProxy in project kernel by cristal-ise.

the class Bootstrap method verifyPathAndModuleProperty.

/**
 * Verify module property and location
 *
 * @param ns
 * @param itemType
 * @param itemName
 * @param itemPath
 * @param modDomPath
 * @param path
 * @return the ItemProxy either create or initialised for existing
 * @throws Exception
 */
private static ItemProxy verifyPathAndModuleProperty(String ns, String itemType, String itemName, ItemPath itemPath, DomainPath modDomPath, DomainPath path) throws Exception {
    LookupManager lookupManager = Gateway.getLookupManager();
    ItemProxy thisProxy = Gateway.getProxyManager().getProxy(path);
    if (itemPath != null && !path.getItemPath().equals(itemPath)) {
        Logger.warning("Resource " + itemType + "/" + itemName + " should have path " + itemPath + " but was found with path " + path.getItemPath());
        itemPath = path.getItemPath();
    }
    if (itemPath == null)
        itemPath = path.getItemPath();
    String moduleName = (ns == null ? "kernel" : ns);
    String itemModule;
    try {
        itemModule = thisProxy.getProperty("Module");
        if (itemModule != null && !itemModule.equals("") && !itemModule.equals("null") && !moduleName.equals(itemModule)) {
            String error = "Module clash! Resource '" + itemName + "' included in module " + moduleName + " but is assigned to '" + itemModule + "'.";
            Logger.error(error);
            throw new InvalidDataException(error);
        }
    } catch (ObjectNotFoundException ex) {
        itemModule = "";
    }
    if (!modDomPath.equals(path)) {
        // move item to module subtree
        Logger.msg("Module item " + itemName + " found with path " + path.toString() + ". Moving to " + modDomPath.toString());
        modDomPath.setItemPath(itemPath);
        if (!modDomPath.exists())
            lookupManager.add(modDomPath);
        lookupManager.delete(path);
    }
    return thisProxy;
}
Also used : ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 2 with ItemProxy

use of org.cristalise.kernel.entity.proxy.ItemProxy 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 3 with ItemProxy

use of org.cristalise.kernel.entity.proxy.ItemProxy in project kernel by cristal-ise.

the class Bootstrap method createResourceItem.

/**
 * @param impHandler
 * @param itemName
 * @param ns
 * @param itemPath
 * @return the ItemProxy representing the newly create Item
 * @throws Exception
 */
private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns, ItemPath itemPath) throws Exception {
    // create props
    PropertyDescriptionList pdList = impHandler.getPropDesc();
    PropertyArrayList props = new PropertyArrayList();
    LookupManager lookupManager = Gateway.getLookupManager();
    for (int i = 0; i < pdList.list.size(); i++) {
        PropertyDescription pd = pdList.list.get(i);
        String propName = pd.getName();
        String propVal = pd.getDefaultValue();
        if (propName.equals(NAME.toString()))
            propVal = itemName;
        else if (propName.equals(MODULE.toString()))
            propVal = (ns == null) ? "kernel" : ns;
        props.list.add(new Property(propName, propVal, pd.getIsMutable()));
    }
    CompositeActivity ca = new CompositeActivity();
    try {
        ca = (CompositeActivity) ((CompositeActivityDef) LocalObjectLoader.getActDef(impHandler.getWorkflowName(), 0)).instantiate();
    } catch (ObjectNotFoundException ex) {
        Logger.error(ex);
        Logger.error("Module resource workflow " + impHandler.getWorkflowName() + " not found. Using empty.");
    }
    Gateway.getCorbaServer().createItem(itemPath);
    lookupManager.add(itemPath);
    DomainPath newDomPath = impHandler.getPath(itemName, ns);
    newDomPath.setItemPath(itemPath);
    lookupManager.add(newDomPath);
    ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(itemPath);
    newItemProxy.initialise(systemAgents.get("system").getPath(), props, ca, null);
    return newItemProxy;
}
Also used : PropertyDescription(org.cristalise.kernel.property.PropertyDescription) DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) Property(org.cristalise.kernel.property.Property) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 4 with ItemProxy

use of org.cristalise.kernel.entity.proxy.ItemProxy in project kernel by cristal-ise.

the class DescriptionObjectCache method get.

public D get(String name, int version) throws ObjectNotFoundException, InvalidDataException {
    D thisDef = null;
    synchronized (cache) {
        CacheEntry<D> thisDefEntry = cache.get(name + "_" + version);
        if (thisDefEntry == null) {
            Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " not found in cache. Checking id.");
            try {
                ItemPath defItemPath = findItem(name);
                String defId = defItemPath.getUUID().toString();
                thisDefEntry = cache.get(defId + "_" + version);
                if (thisDefEntry == null) {
                    Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " not found in cache. Loading from database.");
                    ItemProxy defItemProxy = Gateway.getProxyManager().getProxy(defItemPath);
                    if (name.equals(defId)) {
                        String itemName = defItemProxy.getName();
                        if (itemName != null)
                            name = itemName;
                    }
                    thisDef = loadObject(name, version, defItemProxy);
                    cache.put(defId + "_" + version, new CacheEntry<D>(thisDef, defItemProxy, this));
                }
            } catch (ObjectNotFoundException ex) {
                // for bootstrap and testing, try to load built-in kernel objects from resources
                if (version == 0) {
                    try {
                        return loadObjectFromBootstrap(name);
                    } catch (ObjectNotFoundException ex2) {
                    }
                }
                throw ex;
            }
        }
        if (thisDefEntry != null && thisDef == null) {
            Logger.msg(6, "DescriptionObjectCache.get() - " + name + " v" + version + " found in cache.");
            thisDef = thisDefEntry.def;
        }
    }
    return thisDef;
}
Also used : ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 5 with ItemProxy

use of org.cristalise.kernel.entity.proxy.ItemProxy in project kernel by cristal-ise.

the class Module method addImports.

/**
 * Adds the members of this Collection recursively to the imports of this Module. It checks if the Item
 * referenced by the member has a Collections or not, and adds all of members of those Collection as well.
 *
 * @param contents the Collection to be added as a list of imports
 * @throws ObjectNotFoundException the data was not found
 * @throws InvalidDataException the data was invalid
 */
public void addImports(Collection<?> contents) throws ObjectNotFoundException, InvalidDataException {
    for (CollectionMember mem : contents.getMembers().list) {
        if (mem.getItemPath() != null) {
            ItemProxy child = mem.resolveItem();
            String name = child.getName();
            Integer version = Integer.valueOf(mem.getProperties().get(VERSION.getName()).toString());
            String type = child.getProperty(TYPE);
            ModuleImport newImport;
            switch(type) {
                case "ActivityDesc":
                    String complex = child.getProperty(COMPLEXITY);
                    if (complex.equals("Elementary"))
                        newImport = new ModuleActivity(child, version);
                    else
                        newImport = new ModuleWorkflow(child, version);
                    break;
                case "Script":
                case "Query":
                case "StateMachine":
                case "Schema":
                    newImport = new ModuleResource();
                    break;
                default:
                    throw new InvalidDataException("Resource type '" + type + "' unknown for module export");
            }
            newImport.setName(name);
            newImport.setItemPath(mem.getItemPath());
            newImport.setNamespace(getNamespace());
            if (!imports.list.contains(newImport)) {
                try {
                    // check if child already assigned to a different module
                    String childModule = child.getProperty(MODULE);
                    if (StringUtils.isNotBlank(childModule) && !childModule.equals(getNamespace()))
                        return;
                }// no module property, ok to include
                 catch (ObjectNotFoundException ex) {
                }
                imports.list.add(newImport);
                for (String collName : child.getContents(ClusterType.COLLECTION)) {
                    Collection<?> childColl = child.getCollection(collName, version);
                    addImports(childColl);
                }
            }
        }
    }
}
Also used : ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) CollectionMember(org.cristalise.kernel.collection.CollectionMember) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Aggregations

ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)6 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)3 DomainPath (org.cristalise.kernel.lookup.DomainPath)3 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 LookupManager (org.cristalise.kernel.lookup.LookupManager)2 CollectionArrayList (org.cristalise.kernel.collection.CollectionArrayList)1 CollectionMember (org.cristalise.kernel.collection.CollectionMember)1 CompositeActivityDef (org.cristalise.kernel.lifecycle.CompositeActivityDef)1 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)1 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)1 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)1 ResourceImportHandler (org.cristalise.kernel.process.resource.ResourceImportHandler)1 Property (org.cristalise.kernel.property.Property)1 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)1 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)1 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)1 ScriptingEngineException (org.cristalise.kernel.scripting.ScriptingEngineException)1