Search in sources :

Example 11 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class OInternalGraphImporter method runImport.

public void runImport(String inputFile, String dbURL) throws IOException, FileNotFoundException {
    if (inputFile == null)
        throw new OSystemException("needed an input file as first argument");
    if (dbURL == null)
        throw new OSystemException("needed an database location as second argument");
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbURL);
    ODatabaseHelper.deleteDatabase(db, db.getStorage().getType());
    OrientBaseGraph g = OrientGraphFactory.getNoTxGraphImplFactory().getGraph(dbURL);
    System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "...");
    final long startTime = System.currentTimeMillis();
    OConsoleDatabaseApp console = new OGremlinConsole(new String[] { "import database " + inputFile }).setCurrentDatabase(g.getRawGraph());
    console.run();
    System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices());
    g.command(new OCommandSQL("alter database TIMEZONE 'GMT'")).execute();
    g.command(new OCommandSQL("alter database LOCALECOUNTRY 'UK'")).execute();
    g.command(new OCommandSQL("alter database LOCALELANGUAGE 'EN'")).execute();
    g.shutdown();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSystemException(com.orientechnologies.common.exception.OSystemException) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp)

Example 12 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method displayRecord.

@ConsoleCommand(aliases = { "display" }, description = "Display current record attributes", onlineHelp = "Console-Command-Display-Record")
public void displayRecord(@ConsoleParameter(name = "number", description = "The number of the record in the most recent result set") final String iRecordNumber) {
    checkForDatabase();
    if (iRecordNumber == null || currentResultSet == null)
        checkCurrentObject();
    else {
        int recNumber = Integer.parseInt(iRecordNumber);
        if (currentResultSet.size() == 0)
            throw new OSystemException("No result set where to find the requested record. Execute a query first.");
        if (currentResultSet.size() <= recNumber)
            throw new OSystemException("The record requested is not part of current result set (0" + (currentResultSet.size() > 0 ? "-" + (currentResultSet.size() - 1) : "") + ")");
        setCurrentRecord(recNumber);
    }
    dumpRecordDetails();
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 13 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class OChannelBinaryClientAbstract method createException.

@SuppressWarnings("unchecked")
private static RuntimeException createException(final String iClassName, final String iMessage, final Exception iPrevious) {
    RuntimeException rootException = null;
    Constructor<?> c = null;
    try {
        final Class<RuntimeException> excClass = (Class<RuntimeException>) Class.forName(iClassName);
        if (iPrevious != null) {
            try {
                c = excClass.getConstructor(String.class, Throwable.class);
            } catch (NoSuchMethodException e) {
                c = excClass.getConstructor(String.class, Exception.class);
            }
        }
        if (c == null)
            c = excClass.getConstructor(String.class);
    } catch (Exception e) {
        // UNABLE TO REPRODUCE THE SAME SERVER-SIZE EXCEPTION: THROW AN IO EXCEPTION
        rootException = OException.wrapException(new OSystemException(iMessage), iPrevious);
    }
    if (c != null)
        try {
            final Exception cause;
            if (c.getParameterTypes().length > 1)
                cause = (Exception) c.newInstance(iMessage, iPrevious);
            else
                cause = (Exception) c.newInstance(iMessage);
            rootException = OException.wrapException(new OSystemException("Data processing exception"), cause);
        } catch (InstantiationException ignored) {
        } catch (IllegalAccessException ignored) {
        } catch (InvocationTargetException ignored) {
        }
    return rootException;
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) OResponseProcessingException(com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException) OException(com.orientechnologies.common.exception.OException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ONetworkProtocolException(com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException) OSystemException(com.orientechnologies.common.exception.OSystemException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 14 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class OClientConnection method validateSession.

public void validateSession(byte[] tokenFromNetwork, OTokenHandler handler, ONetworkProtocolBinary protocol) {
    if (tokenFromNetwork == null || tokenFromNetwork.length == 0) {
        if (!protocols.contains(protocol))
            throw new OTokenSecurityException("No valid session found, provide a token");
    } else {
        //IF the byte from the network are the same of the one i have a don't check them
        if (tokenBytes != null && tokenBytes.length > 0) {
            if (// SAME SESSION AND TOKEN DO
            tokenBytes.equals(tokenFromNetwork))
                return;
        }
        OToken token = null;
        try {
            if (tokenFromNetwork != null)
                token = handler.parseBinaryToken(tokenFromNetwork);
        } catch (Exception e) {
            throw OException.wrapException(new OSystemException("Error on token parse"), e);
        }
        if (token == null || !token.getIsVerified()) {
            cleanSession();
            protocol.getServer().getClientConnectionManager().disconnect(this);
            throw new OTokenSecurityException("The token provided is not a valid token, signature does not match");
        }
        if (!handler.validateBinaryToken(token)) {
            cleanSession();
            protocol.getServer().getClientConnectionManager().disconnect(this);
            throw new OTokenSecurityException("The token provided is expired");
        }
        if (tokenBased == null) {
            tokenBased = Boolean.TRUE;
        }
        if (!Arrays.equals(this.tokenBytes, tokenFromNetwork))
            cleanSession();
        this.tokenBytes = tokenFromNetwork;
        this.token = token;
        protocols.add(protocol);
    }
}
Also used : OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OSystemException(com.orientechnologies.common.exception.OSystemException) OToken(com.orientechnologies.orient.core.metadata.security.OToken) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OSystemException(com.orientechnologies.common.exception.OSystemException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)

Example 15 with OSystemException

use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.

the class OHttpUtils method getParameters.

protected static Map<String, String> getParameters(final String iURL) {
    int begin = iURL.indexOf("?");
    if (begin > -1) {
        Map<String, String> params = new HashMap<String, String>();
        String parameters = iURL.substring(begin + 1);
        final String[] paramPairs = parameters.split("&");
        for (String p : paramPairs) {
            final String[] parts = p.split("=");
            if (parts.length == 2)
                try {
                    params.put(parts[0], URLDecoder.decode(parts[1], "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    throw OException.wrapException(new OSystemException("Can not parse HTTP parameters"), e);
                }
        }
        return params;
    }
    return Collections.emptyMap();
}
Also used : HashMap(java.util.HashMap) OSystemException(com.orientechnologies.common.exception.OSystemException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

OSystemException (com.orientechnologies.common.exception.OSystemException)17 OException (com.orientechnologies.common.exception.OException)6 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)3 OBinaryToken (com.orientechnologies.orient.server.binary.impl.OBinaryToken)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 OIOException (com.orientechnologies.common.io.OIOException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 ONetworkProtocolException (com.orientechnologies.orient.enterprise.channel.binary.ONetworkProtocolException)2 OResponseProcessingException (com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 OTimeoutException (com.orientechnologies.common.concur.OTimeoutException)1 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OLockException (com.orientechnologies.common.concur.lock.OLockException)1 OConsoleDatabaseApp (com.orientechnologies.orient.console.OConsoleDatabaseApp)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)1