Examples of OJSONWriter


Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

        db = OSharedDocumentDatabase.acquire(urlParts[1], urlParts[2], urlParts[3]);
      } else
        db = getProfiledDatabaseInstance(iRequest);

      final StringWriter buffer = new StringWriter();
      final OJSONWriter json = new OJSONWriter(buffer);

      json.beginObject();
      if (db.getMetadata().getSchema().getClasses() != null) {
        json.beginCollection(1, false, "classes");
        Set<String> exportedNames = new HashSet<String>();
        for (OClass cls : db.getMetadata().getSchema().getClasses()) {
          if (!exportedNames.contains(cls.getName()))
            try {
              exportClass(db, json, cls);
              exportedNames.add(cls.getName());
            } catch (Exception e) {
              OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
            }
        }
        json.endCollection(1, true);
      }

      if (db.getStorage() instanceof OStorageLocal) {
        json.beginCollection(1, false, "dataSegments");
        for (ODataLocal data : ((OStorageLocal) db.getStorage()).getDataSegments()) {
          json.beginObject(2, true, null);
          json.writeAttribute(3, false, "id", data.getId());
          json.writeAttribute(3, false, "name", data.getName());
          json.writeAttribute(3, false, "size", data.getSize());
          json.writeAttribute(3, false, "filled", data.getFilledUpTo());
          json.writeAttribute(3, false, "maxSize", data.getConfig().maxSize);
          json.writeAttribute(3, false, "files", Arrays.toString(data.getConfig().infoFiles));
          json.endObject(2, false);
        }
        json.endCollection(1, true);
      }

      if (db.getClusterNames() != null) {
        json.beginCollection(1, false, "clusters");
        OCluster cluster;
        for (String clusterName : db.getClusterNames()) {
          cluster = ((OStorageEmbedded) db.getStorage()).getClusterById(db.getClusterIdByName(clusterName));

          try {
            json.beginObject(2, true, null);
            json.writeAttribute(3, false, "id", cluster.getId());
            json.writeAttribute(3, false, "name", clusterName);
            json.writeAttribute(3, false, "type", cluster.getType());
            json.writeAttribute(3, false, "records", cluster.getEntries());
            if (cluster instanceof OClusterLocal) {
              json.writeAttribute(3, false, "size", ((OClusterLocal) cluster).getSize());
              json.writeAttribute(3, false, "filled", ((OClusterLocal) cluster).getFilledUpTo());
              json.writeAttribute(3, false, "maxSize", ((OClusterLocal) cluster).getConfig().maxSize);
              json.writeAttribute(3, false, "files", Arrays.toString(((OClusterLocal) cluster).getConfig().infoFiles));
            } else {
              json.writeAttribute(3, false, "size", "-");
              json.writeAttribute(3, false, "filled", "-");
              json.writeAttribute(3, false, "maxSize", "-");
              json.writeAttribute(3, false, "files", "-");
            }
          } catch (Exception e) {
            json.writeAttribute(3, false, "records", "? (Unauthorized)");
          }
          json.endObject(2, false);
        }
        json.endCollection(1, true);
      }

      if (db.getStorage() instanceof OStorageLocal) {
        json.beginCollection(1, false, "txSegment");
        final OTxSegment txSegment = ((OStorageLocal) db.getStorage()).getTxManager().getTxSegment();
        json.beginObject(2, true, null);
        json.writeAttribute(3, false, "totalLogs", txSegment.getTotalLogCount());
        json.writeAttribute(3, false, "size", txSegment.getSize());
        json.writeAttribute(3, false, "filled", txSegment.getFilledUpTo());
        json.writeAttribute(3, false, "maxSize", txSegment.getConfig().maxSize);
        json.writeAttribute(3, false, "file", txSegment.getConfig().path);
        json.endObject(2, false);
        json.endCollection(1, true);
      }

      json.beginCollection(1, false, "users");
      OUser user;
      for (ODocument doc : db.getMetadata().getSecurity().getUsers()) {
        user = new OUser(doc);
        json.beginObject(2, true, null);
        json.writeAttribute(3, false, "name", user.getName());
        json.writeAttribute(3, false, "roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
        json.endObject(2, false);
      }
      json.endCollection(1, true);

      json.beginCollection(1, true, "roles");
      ORole role;
      for (ODocument doc : db.getMetadata().getSecurity().getRoles()) {
        role = new ORole(doc);
        json.beginObject(2, true, null);
        json.writeAttribute(3, false, "name", role.getName());
        json.writeAttribute(3, false, "mode", role.getMode().toString());

        json.beginCollection(3, true, "rules");
        for (Entry<String, Byte> rule : role.getRules().entrySet()) {
          json.beginObject(4);
          json.writeAttribute(4, true, "name", rule.getKey());
          json.writeAttribute(4, false, "create", role.allow(rule.getKey(), ORole.PERMISSION_CREATE));
          json.writeAttribute(4, false, "read", role.allow(rule.getKey(), ORole.PERMISSION_READ));
          json.writeAttribute(4, false, "update", role.allow(rule.getKey(), ORole.PERMISSION_UPDATE));
          json.writeAttribute(4, false, "delete", role.allow(rule.getKey(), ORole.PERMISSION_DELETE));
          json.endObject(4, true);
        }
        json.endCollection(3, false);

        json.endObject(2, true);
      }
      json.endCollection(1, true);

      json.beginObject(1, true, "config");

      json.beginCollection(2, true, "values");
      json.writeObjects(3, true, null,
          new Object[] { "name", "dateFormat", "value", db.getStorage().getConfiguration().dateFormat }, new Object[] { "name",
              "dateTimeFormat", "value", db.getStorage().getConfiguration().dateTimeFormat }, new Object[] { "name",
              "localeCountry", "value", db.getStorage().getConfiguration().localeCountry }, new Object[] { "name",
              "localeLanguage", "value", db.getStorage().getConfiguration().localeLanguage }, new Object[] { "name",
              "definitionVersion", "value", db.getStorage().getConfiguration().version });
      json.endCollection(2, true);

      json.beginCollection(2, true, "properties");
      if (db.getStorage().getConfiguration().properties != null)
        for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().properties) {
          if (entry != null) {
            json.beginObject(3, true, null);
            json.writeAttribute(4, false, "name", entry.name);
            json.writeAttribute(4, false, "value", entry.value);
            json.endObject(3, true);
          }
        }
      json.endCollection(2, true);

      json.endObject(1, true);
      json.endObject();
      json.flush();

      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_JSON, buffer.toString());
    } finally {
      if (db != null)
        OSharedDocumentDatabase.release(db);
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

          OHttpUtils.CONTENT_TEXT_PLAIN, "Content stream is null or empty");
    } else {
      database = getProfiledDatabaseInstance(iRequest);
      try {
        buffer = new StringWriter();
        writer = new OJSONWriter(buffer);
        writer.beginObject();
        parse(iRequest, new OHttpMultipartContentBaseParser(), new OHttpMultipartFileToRecordContentParser(), database);
        saveRecord(iRequest);
        writer.flush();
        sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_JSON, buffer.toString());
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  @Override
  public InputStream parse(final OHttpRequest iRequest, final Map<String, String> headers,
      final OHttpMultipartContentInputStream in, ODatabaseRecord database) throws IOException {
    final StringWriter buffer = new StringWriter();
    final OJSONWriter json = new OJSONWriter(buffer);
    json.beginObject();
    String fileName = headers.get(OHttpUtils.MULTIPART_CONTENT_FILENAME);
    int fileSize = 0;

    if (fileName.charAt(0) == '"')
      fileName = fileName.substring(1);

    if (fileName.charAt(fileName.length() - 1) == '"')
      fileName = fileName.substring(0, fileName.length() - 1);

    fileName = path + fileName;

    if (!overwrite)
      // CHANGE THE FILE NAME TO AVOID OVERWRITING
      if (new File(fileName).exists()) {
        final String fileExt = fileName.substring(fileName.lastIndexOf("."));
        final String fileNoExt = fileName.substring(0, fileName.lastIndexOf("."));

        for (int i = 1;; ++i) {
          if (!new File(fileNoExt + "_" + i + fileExt).exists()) {
            fileName = fileNoExt + "_" + i + fileExt;
            break;
          }
        }
      }

    // WRITE THE FILE
    final OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName.toString()));
    try {
      int b;
      while ((b = in.read()) > -1) {
        out.write(b);
        fileSize++;
      }
    } finally {
      out.flush();
      out.close();
    }

    // FORMAT THE RETURNING DOCUMENT
    json.writeAttribute(1, true, "name", fileName);
    json.writeAttribute(1, true, "type", headers.get(OHttpUtils.MULTIPART_CONTENT_TYPE));
    json.writeAttribute(1, true, "size", fileSize);
    json.endObject();
    return new ByteArrayInputStream(buffer.toString().getBytes());
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

          "Content stream is null or empty", null);
    } else {
      database = getProfiledDatabaseInstance(iRequest);
      try {
        buffer = new StringWriter();
        writer = new OJSONWriter(buffer);
        writer.beginObject();
        parse(iRequest, iResponse, new OHttpMultipartContentBaseParser(), new OHttpMultipartFileToRecordContentParser(), database);
        boolean ok = saveRecord(iRequest, iResponse);
        writer.endObject();
        writer.flush();
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  }

  protected void sendDatabaseInfo(final OHttpRequest iRequest, final OHttpResponse iResponse, final ODatabaseDocumentTx db)
      throws IOException {
    final StringWriter buffer = new StringWriter();
    final OJSONWriter json = new OJSONWriter(buffer);

    json.beginObject();
    if (db.getMetadata().getSchema().getClasses() != null) {
      json.beginCollection(1, false, "classes");
      Set<String> exportedNames = new HashSet<String>();
      for (OClass cls : db.getMetadata().getSchema().getClasses()) {
        if (!exportedNames.contains(cls.getName()))
          try {
            exportClass(db, json, cls);
            exportedNames.add(cls.getName());
          } catch (Exception e) {
            OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
          }
      }
      json.endCollection(1, true);
    }

    if (db.getClusterNames() != null) {
      json.beginCollection(1, false, "clusters");
      OCluster cluster;
      for (String clusterName : db.getClusterNames()) {
        cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));

        try {
          json.beginObject(2, true, null);
          json.writeAttribute(3, false, "id", cluster.getId());
          json.writeAttribute(3, false, "name", clusterName);
          json.writeAttribute(3, false, "records", cluster.getEntries() - cluster.getTombstonesCount());
          json.writeAttribute(3, false, "size", "-");
          json.writeAttribute(3, false, "filled", "-");
          json.writeAttribute(3, false, "maxSize", "-");
          json.writeAttribute(3, false, "files", "-");
        } catch (Exception e) {
          json.writeAttribute(3, false, "records", "? (Unauthorized)");
        }
        json.endObject(2, false);
      }
      json.endCollection(1, true);
    }

    json.writeAttribute(1, false, "currentUser", db.getUser().getName());

    json.beginCollection(1, false, "users");
    OUser user;
    for (ODocument doc : db.getMetadata().getSecurity().getAllUsers()) {
      user = new OUser(doc);
      json.beginObject(2, true, null);
      json.writeAttribute(3, false, "name", user.getName());
      json.writeAttribute(3, false, "roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
      json.endObject(2, false);
    }
    json.endCollection(1, true);

    json.beginCollection(1, true, "roles");
    ORole role;
    for (ODocument doc : db.getMetadata().getSecurity().getAllRoles()) {
      role = new ORole(doc);
      json.beginObject(2, true, null);
      json.writeAttribute(3, false, "name", role.getName());
      json.writeAttribute(3, false, "mode", role.getMode().toString());

      json.beginCollection(3, true, "rules");
      for (Entry<String, Byte> rule : role.getRules().entrySet()) {
        json.beginObject(4);
        json.writeAttribute(4, true, "name", rule.getKey());
        json.writeAttribute(4, false, "create", role.allow(rule.getKey(), ORole.PERMISSION_CREATE));
        json.writeAttribute(4, false, "read", role.allow(rule.getKey(), ORole.PERMISSION_READ));
        json.writeAttribute(4, false, "update", role.allow(rule.getKey(), ORole.PERMISSION_UPDATE));
        json.writeAttribute(4, false, "delete", role.allow(rule.getKey(), ORole.PERMISSION_DELETE));
        json.endObject(4, true);
      }
      json.endCollection(3, false);

      json.endObject(2, true);
    }
    json.endCollection(1, true);

    json.beginObject(1, true, "config");

    json.beginCollection(2, true, "values");
    json.writeObjects(3, true, null, new Object[] { "name", "dateFormat", "value", db.getStorage().getConfiguration().dateFormat },
        new Object[] { "name", "dateTimeFormat", "value", db.getStorage().getConfiguration().dateTimeFormat }, new Object[] {
            "name", "localeCountry", "value", db.getStorage().getConfiguration().getLocaleCountry() }, new Object[] { "name",
            "localeLanguage", "value", db.getStorage().getConfiguration().getLocaleLanguage() }, new Object[] { "name",
            "definitionVersion", "value", db.getStorage().getConfiguration().version });
    json.endCollection(2, true);

    json.beginCollection(2, true, "properties");
    if (db.getStorage().getConfiguration().properties != null)
      for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().properties) {
        if (entry != null) {
          json.beginObject(3, true, null);
          json.writeAttribute(4, false, "name", entry.name);
          json.writeAttribute(4, false, "value", entry.value);
          json.endObject(3, true);
        }
      }
    json.endCollection(2, true);

    json.endObject(1, true);
    json.endObject();
    json.flush();

    iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

         iFormat = JSON_FORMAT;
       else
         iFormat = JSON_FORMAT + "," + iFormat;

       final StringWriter buffer = new StringWriter();
       final OJSONWriter json = new OJSONWriter(buffer, iFormat);
       json.beginObject();

       final String format = iFetchPlan != null ? iFormat + ",fetchPlan:" + iFetchPlan : iFormat;

       // WRITE RECORDS
       json.beginCollection(-1, true, "result");
       formatMultiValue(it, buffer, format);
       json.endCollection(-1, true);

       json.endObject();
       send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
     }
   }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

   }

   protected void sendDatabaseInfo(final OHttpRequest iRequest, final OHttpResponse iResponse, final ODatabaseDocumentTx db)
       throws IOException {
     final StringWriter buffer = new StringWriter();
     final OJSONWriter json = new OJSONWriter(buffer);

     json.beginObject();
     if (db.getMetadata().getSchema().getClasses() != null) {
       json.beginCollection(1, false, "classes");
       Set<String> exportedNames = new HashSet<String>();
       for (OClass cls : db.getMetadata().getSchema().getClasses()) {
         if (!exportedNames.contains(cls.getName()))
           try {
             exportClass(db, json, cls);
             exportedNames.add(cls.getName());
           } catch (Exception e) {
             OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
           }
       }
       json.endCollection(1, true);
     }

     if (db.getClusterNames() != null) {
       json.beginCollection(1, false, "clusters");
       OCluster cluster;
       for (String clusterName : db.getClusterNames()) {
         cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));

         try {
           json.beginObject(2, true, null);
           json.writeAttribute(3, false, "id", cluster.getId());
           json.writeAttribute(3, false, "name", clusterName);
           json.writeAttribute(3, false, "records", cluster.getEntries() - cluster.getTombstonesCount());
           json.writeAttribute(3, false, "size", "-");
           json.writeAttribute(3, false, "filled", "-");
           json.writeAttribute(3, false, "maxSize", "-");
           json.writeAttribute(3, false, "files", "-");
         } catch (Exception e) {
           json.writeAttribute(3, false, "records", "? (Unauthorized)");
         }
         json.endObject(2, false);
       }
       json.endCollection(1, true);
     }

     json.writeAttribute(1, false, "currentUser", db.getUser().getName());

     json.beginCollection(1, false, "users");
     OUser user;
     for (ODocument doc : db.getMetadata().getSecurity().getAllUsers()) {
       user = new OUser(doc);
       json.beginObject(2, true, null);
       json.writeAttribute(3, false, "name", user.getName());
       json.writeAttribute(3, false, "roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
       json.endObject(2, false);
     }
     json.endCollection(1, true);

     json.beginCollection(1, true, "roles");
     ORole role;
     for (ODocument doc : db.getMetadata().getSecurity().getAllRoles()) {
       role = new ORole(doc);
       json.beginObject(2, true, null);
       json.writeAttribute(3, false, "name", role.getName());
       json.writeAttribute(3, false, "mode", role.getMode().toString());

       json.beginCollection(3, true, "rules");
       for (Entry<String, Byte> rule : role.getRules().entrySet()) {
         json.beginObject(4);
         json.writeAttribute(4, true, "name", rule.getKey());
         json.writeAttribute(4, false, "create", role.allow(rule.getKey(), ORole.PERMISSION_CREATE));
         json.writeAttribute(4, false, "read", role.allow(rule.getKey(), ORole.PERMISSION_READ));
         json.writeAttribute(4, false, "update", role.allow(rule.getKey(), ORole.PERMISSION_UPDATE));
         json.writeAttribute(4, false, "delete", role.allow(rule.getKey(), ORole.PERMISSION_DELETE));
         json.endObject(4, true);
       }
       json.endCollection(3, false);

       json.endObject(2, true);
     }
     json.endCollection(1, true);

     json.beginObject(1, true, "config");

     json.beginCollection(2, true, "values");
     json.writeObjects(3, true, null, new Object[] { "name", "dateFormat", "value", db.getStorage().getConfiguration().dateFormat },
         new Object[] { "name", "dateTimeFormat", "value", db.getStorage().getConfiguration().dateTimeFormat }, new Object[] {
             "name", "localeCountry", "value", db.getStorage().getConfiguration().getLocaleCountry() }, new Object[] { "name",
             "localeLanguage", "value", db.getStorage().getConfiguration().getLocaleLanguage() }, new Object[] { "name",
             "definitionVersion", "value", db.getStorage().getConfiguration().version });
     json.endCollection(2, true);

     json.beginCollection(2, true, "properties");
     if (db.getStorage().getConfiguration().properties != null)
       for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().properties) {
         if (entry != null) {
           json.beginObject(3, true, null);
           json.writeAttribute(4, false, "name", entry.name);
           json.writeAttribute(4, false, "value", entry.value);
           json.endObject(3, true);
         }
       }
     json.endCollection(2, true);

     json.endObject(1, true);
     json.endObject();
     json.flush();

     iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
   }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  public StringBuilder toString(final ORecord iRecord, final StringBuilder iOutput, final String iFormat,
      final OUserObject2RecordHandler iObjHandler, final Set<ODocument> iMarshalledRecords, boolean iOnlyDelta,
      boolean autoDetectCollectionType) {
    try {
      final StringWriter buffer = new StringWriter(INITIAL_SIZE);
      final OJSONWriter json = new OJSONWriter(buffer, iFormat);
      final FormatSettings settings = new FormatSettings(iFormat);

      json.beginObject();
      OJSONFetchContext context = new OJSONFetchContext(json, settings);
      context.writeSignature(json, iRecord);

      if (iRecord instanceof ODocument) {

        OFetchHelper.fetch(iRecord, null, OFetchHelper.buildFetchPlan(settings.fetchPlan), new OJSONFetchListener(), context,
            iFormat);
      } else if (iRecord instanceof ORecordStringable) {

        // STRINGABLE
        final ORecordStringable record = (ORecordStringable) iRecord;
        json.writeAttribute(settings.indentLevel + 1, true, "value", record.value());

      } else if (iRecord instanceof ORecordBytes) {
        // BYTES
        final ORecordBytes record = (ORecordBytes) iRecord;
        json.writeAttribute(settings.indentLevel + 1, true, "value", OBase64Utils.encodeBytes(record.toStream()));
      } else

        throw new OSerializationException("Error on marshalling record of type '" + iRecord.getClass()
            + "' to JSON. The record type cannot be exported to JSON");

      json.endObject(0, true);

      iOutput.append(buffer);
      return iOutput;
    } catch (IOException e) {
      throw new OSerializationException("Error on marshalling of record to JSON", e);
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

      {
        def.setLevel(compressionLevel);
      }
    };

    writer = new OJSONWriter(new OutputStreamWriter(gzipOS));
    writer.beginObject();
    iDatabase.getLocalCache().setEnable(false);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  public ODatabaseExport(final ODatabaseRecordInternal iDatabase, final OutputStream iOutputStream,
      final OCommandOutputListener iListener) throws IOException {
    super(iDatabase, "streaming", iListener);

    writer = new OJSONWriter(new OutputStreamWriter(iOutputStream));
    writer.beginObject();
    iDatabase.getLocalCache().setEnable(false);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.