Search in sources :

Example 11 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class ActivityDef method getBuiltInCollectionResource.

protected DescriptionObject[] getBuiltInCollectionResource(BuiltInCollections collection) throws ObjectNotFoundException, InvalidDataException {
    ArrayList<DescriptionObject> retArr = new ArrayList<DescriptionObject>();
    if (itemPath == null) {
        Logger.warning("ActivityDef.getBuiltInCollectionResource(actName:" + getName() + ", collection:" + collection + ") - itemPath is null! CANNOT resolve data in ClusterStorage");
        return retArr.toArray(new DescriptionObject[0]);
    // throw new InvalidDataException("actName:"+getName()+", collection:"+collection+" - itemPath is null! CANNOT resolve data in ClusterStorage");
    }
    Logger.msg(5, "ActivityDef.getBuiltInCollectionResource(actName:" + getName() + ") - Loading from collection:" + collection);
    Dependency resColl;
    try {
        String clusterPath = ClusterType.COLLECTION + "/" + collection + "/" + ((mVersion == null || mVersion == -1) ? "last" : String.valueOf(mVersion));
        String[] contents = Gateway.getStorage().getClusterContents(itemPath, clusterPath);
        if (contents != null && contents.length > 0)
            resColl = (Dependency) Gateway.getStorage().get(itemPath, clusterPath, null);
        else
            return retArr.toArray(new DescriptionObject[retArr.size()]);
    } catch (PersistencyException e) {
        Logger.error(e);
        throw new InvalidDataException("Error loading description collection " + collection);
    }
    for (DependencyMember resMem : resColl.getMembers().list) {
        String resUUID = resMem.getChildUUID();
        Integer resVer = deriveVersionNumber(resMem.getBuiltInProperty(VERSION));
        if (resVer == null) {
            throw new InvalidDataException("Version is null for Item:" + itemPath + ", Collection:" + collection + ", DependencyMember:" + resUUID);
        }
        if (collection != ACTIVITY && retArr.size() > 0) {
            throw new InvalidDataException("actName:" + getName() + " has an invalid dependency:" + collection);
        }
        switch(collection) {
            case SCHEMA:
                retArr.add(LocalObjectLoader.getSchema(resUUID, resVer));
                break;
            case SCRIPT:
                retArr.add(LocalObjectLoader.getScript(resUUID, resVer));
                break;
            case QUERY:
                retArr.add(LocalObjectLoader.getQuery(resUUID, resVer));
                break;
            case STATE_MACHINE:
                retArr.add(LocalObjectLoader.getStateMachine(resUUID, resVer));
                break;
            case ACTIVITY:
                retArr.add(LocalObjectLoader.getActDef(resUUID, resVer));
                break;
            default:
                throw new InvalidDataException("");
        }
    }
    return retArr.toArray(new DescriptionObject[retArr.size()]);
}
Also used : DependencyMember(org.cristalise.kernel.collection.DependencyMember) DescriptionObject(org.cristalise.kernel.utils.DescriptionObject) ArrayList(java.util.ArrayList) CollectionArrayList(org.cristalise.kernel.collection.CollectionArrayList) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) Dependency(org.cristalise.kernel.collection.Dependency)

Example 12 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class ActivityDef method export.

@Override
public void export(Writer imports, File dir) throws InvalidDataException, ObjectNotFoundException, IOException {
    String actXML;
    String tc = ELEM_ACT_DESC_RESOURCE.getTypeCode();
    exportCollections(imports, dir);
    try {
        actXML = Gateway.getMarshaller().marshall(this);
    } catch (Exception e) {
        Logger.error(e);
        throw new InvalidDataException("Couldn't marshall activity def " + getActName());
    }
    FileStringUtility.string2File(new File(new File(dir, tc), getActName() + (getVersion() == null ? "" : "_" + getVersion()) + ".xml"), actXML);
    if (imports != null) {
        imports.write("<Activity " + getExportAttributes(tc) + ">" + getExportCollections() + "</Activity>\n");
    }
}
Also used : InvalidDataException(org.cristalise.kernel.common.InvalidDataException) File(java.io.File) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) IOException(java.io.IOException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Example 13 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException 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 14 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class Gateway method connect.

/**
 * Log in with the given username and password, and initialises the {@link Lookup}, {@link TransactionManager} and {@link ProxyManager}.
 * It shall be uses in client processes only.
 *
 * @param agentName - username
 * @param agentPassword - password
 * @return an AgentProxy on the requested user
 *
 * @throws InvalidDataException - bad params
 * @throws PersistencyException - error starting storages
 * @throws ObjectNotFoundException - object not found
 */
public static AgentProxy connect(String agentName, String agentPassword, String resource) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
    Authenticator auth = getAuthenticator();
    if (!auth.authenticate(agentName, agentPassword, resource))
        throw new InvalidDataException("Login failed");
    try {
        if (mLookup != null)
            mLookup.close();
        mLookup = (Lookup) mC2KProps.getInstance("Lookup");
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        Logger.error(ex);
        throw new InvalidDataException("Lookup " + mC2KProps.getString("Lookup") + " could not be instantiated");
    }
    mLookup.open(auth);
    mStorage = new TransactionManager(auth);
    mProxyManager = new ProxyManager();
    // find agent proxy
    AgentPath agentPath = mLookup.getAgentPath(agentName);
    AgentProxy agent = (AgentProxy) mProxyManager.getProxy(agentPath);
    agent.setAuthObj(auth);
    ScriptConsole.setUser(agent);
    // Run module startup scripts. Server does this during bootstrap
    mModules.setUser(agent);
    mModules.runScripts("startup");
    Logger.msg("Gateway.connect(agent) - DONE.");
    return agent;
}
Also used : TransactionManager(org.cristalise.kernel.persistency.TransactionManager) AgentPath(org.cristalise.kernel.lookup.AgentPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ProxyManager(org.cristalise.kernel.entity.proxy.ProxyManager) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) Authenticator(org.cristalise.kernel.process.auth.Authenticator)

Example 15 with InvalidDataException

use of org.cristalise.kernel.common.InvalidDataException in project kernel by cristal-ise.

the class Gateway method startServer.

/**
 * Makes this process capable of creating and managing server entities. Runs the
 * Creates the LookupManager, ProxyServer, initialises the ORB and CORBAServer
 */
public static void startServer() throws InvalidDataException, CannotManageException {
    try {
        // check top level directory contexts
        if (mLookup instanceof LookupManager) {
            mLookupManager = (LookupManager) mLookup;
            mLookupManager.initializeDirectory();
        } else {
            throw new CannotManageException("Lookup implementation is not a LookupManager. Cannot write to directory");
        }
        // start entity proxy server
        mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
        // Init ORB - set various config
        String serverName = mC2KProps.getProperty("ItemServer.name");
        // TODO: externalize this (or replace corba completely)
        if (serverName != null)
            mC2KProps.put("com.sun.CORBA.ORBServerHost", serverName);
        String serverPort = mC2KProps.getProperty("ItemServer.iiop", "1500");
        mC2KProps.put("com.sun.CORBA.ORBServerPort", serverPort);
        mC2KProps.put("com.sun.CORBA.POA.ORBServerId", "1");
        mC2KProps.put("com.sun.CORBA.POA.ORBPersistentServerPort", serverPort);
        // need to force UTF-8 in the Sun ORB
        mC2KProps.put("com.sun.CORBA.codeset.charsets", "0x05010001, 0x00010109");
        mC2KProps.put("com.sun.CORBA.codeset.wcharsets", "0x00010109, 0x05010001");
        // Standard initialisation of the ORB
        orbDestroyed = false;
        mORB = org.omg.CORBA.ORB.init(new String[0], mC2KProps);
        Logger.msg("Gateway.startServer() - ORB initialised. ORB class:'" + mORB.getClass().getName() + "'");
        // start corba server components
        mCorbaServer = new CorbaServer();
        Logger.msg("Gateway.startServer() - Server '" + serverName + "' STARTED.");
    } catch (Exception ex) {
        Logger.error(ex);
        Logger.die("Exception starting server components. Shutting down.");
    }
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) LookupManager(org.cristalise.kernel.lookup.LookupManager) CorbaServer(org.cristalise.kernel.entity.CorbaServer) 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) ProxyServer(org.cristalise.kernel.entity.proxy.ProxyServer)

Aggregations

InvalidDataException (org.cristalise.kernel.common.InvalidDataException)91 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)40 PersistencyException (org.cristalise.kernel.common.PersistencyException)33 IOException (java.io.IOException)14 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)11 DomainPath (org.cristalise.kernel.lookup.DomainPath)10 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 CannotManageException (org.cristalise.kernel.common.CannotManageException)8 AgentPath (org.cristalise.kernel.lookup.AgentPath)8 Schema (org.cristalise.kernel.persistency.outcome.Schema)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)7 ItemPath (org.cristalise.kernel.lookup.ItemPath)7 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 MappingException (org.exolab.castor.mapping.MappingException)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 ArrayList (java.util.ArrayList)5 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5