Search in sources :

Example 1 with OHttpMultipartDatabaseImportContentParser

use of com.orientechnologies.orient.server.network.protocol.http.multipart.OHttpMultipartDatabaseImportContentParser in project orientdb by orientechnologies.

the class OServerCommandPostImportDatabase method execute.

@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
    if (!iRequest.isMultipart) {
        database = getProfiledDatabaseInstance(iRequest);
        try {
            ODatabaseImport importer = new ODatabaseImport(database, new ByteArrayInputStream(iRequest.content.getBytes("UTF8")), this);
            for (Map.Entry<String, String> option : iRequest.getParameters().entrySet()) importer.setOption(option.getKey(), option.getValue());
            importer.importDatabase();
            iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, "{\"responseText\": \"Database imported Correctly, see server log for more informations.\"}", null);
        } catch (Exception e) {
            iResponse.send(OHttpUtils.STATUS_INTERNALERROR_CODE, e.getMessage() + ": " + e.getCause() != null ? e.getCause().getMessage() : "", OHttpUtils.CONTENT_JSON, "{\"responseText\": \"" + e.getMessage() + ": " + (e.getCause() != null ? e.getCause().getMessage() : "") + "\"}", null);
        } finally {
            if (database != null)
                database.close();
            database = null;
        }
    } else if (iRequest.multipartStream == null || iRequest.multipartStream.available() <= 0) {
        iResponse.send(OHttpUtils.STATUS_INVALIDMETHOD_CODE, "Content stream is null or empty", OHttpUtils.CONTENT_TEXT_PLAIN, "Content stream is null or empty", null);
    } else {
        database = getProfiledDatabaseInstance(iRequest);
        try {
            parse(iRequest, iResponse, new OHttpMultipartContentBaseParser(), new OHttpMultipartDatabaseImportContentParser(), database);
            ODatabaseImport importer = new ODatabaseImport(database, importData, this);
            for (Map.Entry<String, String> option : iRequest.getParameters().entrySet()) importer.setOption(option.getKey(), option.getValue());
            importer.importDatabase();
            iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, "{\"responseText\": \"Database imported Correctly, see server log for more informations.\"}", null);
        } catch (Exception e) {
            iResponse.send(OHttpUtils.STATUS_INTERNALERROR_CODE, e.getMessage() + ": " + e.getCause() != null ? e.getCause().getMessage() : "", OHttpUtils.CONTENT_JSON, "{\"responseText\": \"" + e.getMessage() + ": " + (e.getCause() != null ? e.getCause().getMessage() : "") + "\"}", null);
        } finally {
            if (database != null)
                database.close();
            database = null;
            if (importData != null)
                importData.close();
            importData = null;
        }
    }
    return false;
}
Also used : OHttpMultipartDatabaseImportContentParser(com.orientechnologies.orient.server.network.protocol.http.multipart.OHttpMultipartDatabaseImportContentParser) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) HashMap(java.util.HashMap) Map(java.util.Map) OHttpMultipartContentBaseParser(com.orientechnologies.orient.server.network.protocol.http.multipart.OHttpMultipartContentBaseParser)

Aggregations

ODatabaseImport (com.orientechnologies.orient.core.db.tool.ODatabaseImport)1 OHttpMultipartContentBaseParser (com.orientechnologies.orient.server.network.protocol.http.multipart.OHttpMultipartContentBaseParser)1 OHttpMultipartDatabaseImportContentParser (com.orientechnologies.orient.server.network.protocol.http.multipart.OHttpMultipartDatabaseImportContentParser)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1