Examples of JsonObject


Examples of com.cedarsoftware.util.io.JsonObject

            if (!(map.get("axes") instanceof JsonObject))
            {
                throw new IllegalArgumentException("Must specify a list of axes for the ncube, under the key 'axes' as [{axis 1}, {axis 2}, ... {axis n}].");
            }

            JsonObject axes = (JsonObject) map.get("axes");
            Object[] items = axes.getArray();

            if (ArrayUtilities.isEmpty(items))
            {
                throw new IllegalArgumentException("Must be at least one axis defined in the JSON format.");
            }

            // Read axes
            for (Object item : items)
            {
                Map obj = (Map) item;
                String name = getString(obj, "name");
                AxisType type = AxisType.valueOf(getString(obj, "type"));
                boolean hasDefault = getBoolean(obj, "hasDefault");
                AxisValueType valueType = AxisValueType.valueOf(getString(obj, "valueType"));
                final int preferredOrder = getLong(obj, "preferredOrder").intValue();
                final Boolean multiMatch = getBoolean(obj, "multiMatch");
                Axis axis = new Axis(name, type, valueType, hasDefault, preferredOrder, multiMatch);
                ncube.addAxis(axis);

                if (!(obj.get("columns") instanceof JsonObject))
                {
                    throw new IllegalArgumentException("'columns' must be specified, axis '" + name + "', NCube '" + cubeName + "'");
                }
                JsonObject colMap = (JsonObject) obj.get("columns");

                if (!colMap.isArray())
                {
                     throw new IllegalArgumentException("'columns' must be an array, axis '" + name + "', NCube '" + cubeName + "'");
                }

                // Read columns
                Object[] cols = colMap.getArray();
                for (Object col : cols)
                {
                    Map mapCol = (Map) col;
                    Object value = mapCol.get("value");
                    String colType = (String) mapCol.get("type");
                    Object id = parseJsonValue(mapCol.get("id"), colType);

                    if (value == null)
                    {
                        if (id == null)
                        {
                            throw new IllegalArgumentException("Missing 'value' field on column or it is null, axis '" + name + "', NCube '" + cubeName + "'");
                        }
                        else
                        {   // Allows you to skip setting both id and value to the same value.
                            value = id;
                        }
                    }
                    Column colAdded;

                    if (type == AxisType.DISCRETE || type == AxisType.NEAREST)
                    {
                        colAdded = ncube.addColumn(axis.getName(), (Comparable) parseJsonValue(value, colType));
                    }
                    else if (type == AxisType.RANGE)
                    {
                        Object[] rangeItems = ((JsonObject)value).getArray();
                        if (rangeItems.length != 2)
                        {
                            throw new IllegalArgumentException("Range must have exactly two items, axis '" + name +"', NCube '" + cubeName + "'");
                        }
                        Comparable low = (Comparable) parseJsonValue(rangeItems[0], colType);
                        Comparable high = (Comparable) parseJsonValue(rangeItems[1], colType);
                        colAdded = ncube.addColumn(axis.getName(), new Range(low, high));
                    }
                    else if (type == AxisType.SET)
                    {
                        Object[] rangeItems = ((JsonObject)value).getArray();
                        RangeSet rangeSet = new RangeSet();
                        for (Object pt : rangeItems)
                        {
                            if (pt instanceof Object[])
                            {
                                Object[] rangeValues = (Object[]) pt;
                                Comparable low = (Comparable) parseJsonValue(rangeValues[0], colType);
                                Comparable high = (Comparable) parseJsonValue(rangeValues[1], colType);
                                Range range = new Range(low, high);
                                rangeSet.add(range);
                            }
                            else
                            {
                                rangeSet.add((Comparable)parseJsonValue(pt, colType));
                            }
                        }
                        colAdded = ncube.addColumn(axis.getName(), rangeSet);
                    }
                    else if (type == AxisType.RULE)
                    {
                        Object cmd = parseJsonValue(value, colType);
                        if (!(cmd instanceof CommandCell))
                        {
                            throw new IllegalArgumentException("Column values on a RULE axis must be of type CommandCell, axis '" + name + "', NCube '" + cubeName + "'");
                        }
                        colAdded = ncube.addColumn(axis.getName(), (CommandCell)cmd);
                    }
                    else
                    {
                        throw new IllegalArgumentException("Unsupported Axis Type '" + type + "' for simple JSON input, axis '" + name + "', NCube '" + cubeName + "'");
                    }

                    if (id != null)
                    {
                        long sysId = colAdded.getId();
                        userIdToUniqueId.put(id, sysId);
                    }
                }
            }

            // Read cells
            if (!(map.get("cells") instanceof JsonObject))
            {
                throw new IllegalArgumentException("Must specify the 'cells' portion.  It can be empty but must be specified, NCube '" + cubeName + "'");
            }

            JsonObject cellMap = (JsonObject) map.get("cells");

            if (!cellMap.isArray())
            {
                throw new IllegalArgumentException("'cells' must be an []. It can be empty but must be specified, NCube '" + cubeName + "'");
            }

            Object[] cells = cellMap.getArray();

            for (Object cell : cells)
            {
                JsonObject cMap = (JsonObject) cell;
                Object ids = cMap.get("id");
                String type = (String) cMap.get("type");
                Object v = parseJsonValue(cMap.get("value"), type);
                if (v == null)
                {
                    String url = (String) cMap.get("url");
                    if (StringUtilities.isEmpty(url))
                    {
                        String uri = (String) cMap.get("uri");
                        if (StringUtilities.isEmpty(uri))
                        {
                            throw new IllegalArgumentException("Cell must have 'value', 'url', or 'uri' to specify its content, NCube '" + cubeName + "'");
                        }
                        url = baseUrl + uri;
                    }

                    boolean cache = true;
                    if (cMap.containsKey("cache"))
                    {
                        if (cMap.get("cache") instanceof Boolean)
                        {
                            cache = (Boolean) cMap.get("cache");
                        }
                        else
                        {
                            throw new IllegalArgumentException("'cache' parameter must be set to 'true' or 'false', or not used (defaults to 'true')");
                        }
                    }
                    CommandCell cmd;
                    if ("exp".equalsIgnoreCase(type))
                    {
                        cmd = new GroovyExpression("");
                    }
                    else if ("method".equalsIgnoreCase(type))
                    {
                        cmd = new GroovyMethod("");
                    }
                    else if ("template".equalsIgnoreCase(type))
                    {
                        cmd = new GroovyTemplate("");
                    }
                    else if ("string".equalsIgnoreCase(type))
                    {
                        cmd = new StringUrlCmd(cache);
                    }
                    else if ("binary".equalsIgnoreCase(type))
                    {
                        cmd = new BinaryUrlCmd(cache);
                    }
                    else
                    {
                        throw new IllegalArgumentException("url/uri can only be specified with 'exp', 'method', 'template', 'string', or 'binary' types");
                    }
                    cmd.setUrl(url);
                    v = cmd;
                }

                if (ids instanceof JsonObject)
                {   // If specified as ID array, build coordinate that way
                    Set<Long> colIds = new HashSet<Long>();
                    for (Object id : ((JsonObject)ids).getArray())
                    {
                        if (!userIdToUniqueId.containsKey(id))
                        {
                            throw new IllegalArgumentException("ID specified in cell does not match an ID in the columns, id: " + id);
                        }
                        colIds.add(userIdToUniqueId.get(id));
                    }
                    ncube.setCellById(v, colIds);
                }
                else
                {   // specified as key-values along each axis
                    if (!(cMap.get("key") instanceof JsonObject))
                    {
                        throw new IllegalArgumentException("'key' must be a JSON object {}, NCube '" + cubeName + "'");
                    }

                    JsonObject<String, Object> keys = (JsonObject<String, Object>) cMap.get("key");
                    for (Map.Entry<String, Object> entry : keys.entrySet())
                    {
                        keys.put(entry.getKey(), parseJsonValue(entry.getValue(), null));
                    }
                    ncube.setCell(v, keys);
View Full Code Here

Examples of com.couchbase.client.java.document.json.JsonObject

                public Observable<AsyncQueryResult> call(final GenericQueryResponse response) {
                    final Observable<AsyncQueryRow> rows = response.rows().map(new Func1<ByteBuf, AsyncQueryRow>() {
                        @Override
                        public AsyncQueryRow call(ByteBuf byteBuf) {
                            try {
                                JsonObject value = JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
                                return new DefaultAsyncQueryRow(value);
                            } catch (Exception e) {
                                throw new TranscodingException("Could not decode View Info.", e);
                            }
                        }
                    });
                    final Observable<JsonObject> info = response.info().map(new Func1<ByteBuf, JsonObject>() {
                        @Override
                        public JsonObject call(ByteBuf byteBuf) {
                            try {
                                return JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
                            } catch (Exception e) {
                                throw new TranscodingException("Could not decode View Info.", e);
                            }
                        }
                    });
                    if (response.status().isSuccess()) {
                        return Observable.just((AsyncQueryResult) new DefaultAsyncQueryResult(rows, info, null,
                            response.status().isSuccess()));
                    } else {
                        return response.info().map(new Func1<ByteBuf, AsyncQueryResult>() {
                            @Override
                            public AsyncQueryResult call(ByteBuf byteBuf) {
                                try {
                                    JsonObject error = JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
                                    return new DefaultAsyncQueryResult(rows, info, error, response.status().isSuccess());
                                } catch (Exception e) {
                                    throw new TranscodingException("Could not decode View Info.", e);
                                }
View Full Code Here

Examples of com.cumulocity.me.rest.json.JSONObject

        return SecondFragment.class;
    }

    @Override
    public JSONObject toJson(Object representation) {
        return new JSONObject();
    }
View Full Code Here

Examples of com.dotcms.repackage.org.codehaus.jettison.json.JSONObject

  private void doJSON(List<Contentlet> cons, HttpServletResponse response) throws IOException{
   
 
   
        // get our JSON Going
        JSONObject json = new JSONObject()
    JSONArray jsonCons = new JSONArray()

    for(Contentlet c : cons){
     
     
      try {
       
        jsonCons.put(contentletToJSON(c));
       
      } catch (Exception e) {
        Logger.error(this.getClass(), "unable JSON contentlet " + c.getIdentifier());
        Logger.debug(this.getClass(), "unable to find contentlet", e);
      }
    }


    try {
      json.put("contentlets", jsonCons);
    } catch (JSONException e) {
      Logger.error(this.getClass(), "unable to create JSONObject");
      Logger.debug(this.getClass(), "unable to create JSONObject", e);
    }

   
    
        response.getWriter().println(json.toString())
    response.getWriter().flush()
    response.getWriter().close()
   
   
  }
View Full Code Here

Examples of com.dotcms.repackage.org.json.JSONObject

        response.getWriter().flush();
    }

    private JSONObject getAllWordSuggestions(JSONObject params) throws SpellCheckException, JSONException {
        JSONObject suggestions = new JSONObject();
        JSONArray checkedWords = params.optJSONArray("words");
        String lang = params.optString("lang");
        lang = ("".equals(lang)) ? DEFAULT_LANGUAGE : lang;
        List<String> misspelledWords = findMisspelledWords(new JsonArrayIterator(checkedWords), lang);
        for (String misspelledWord : misspelledWords) {
            List<String> suggestionsList = findSuggestions(misspelledWord, lang, maxSuggestionsCount);
            suggestions.put(misspelledWord, suggestionsList);
        }
        return suggestions;
    }
View Full Code Here

Examples of com.dotmarketing.util.json.JSONObject

                //Error messages
                JSONArray jsonErrors = new JSONArray( (ArrayList) responseMap.get( "errorMessages" ) );

                //Prepare the Json response
                JSONObject jsonResponse = new JSONObject();
                jsonResponse.put( "errorMessages", jsonErrors.toArray() );
                jsonResponse.put( "errors", responseMap.get( "errors" ) );
                jsonResponse.put( "total", responseMap.get( "total" ) );
                jsonResponse.put( "bundleId", responseMap.get( "bundleId" ) );

                //And send it back to the user
                response.getWriter().println( jsonResponse.toString() );
            }
        } catch ( Exception e ) {
            Logger.error( RemotePublishAjaxAction.class, e.getMessage(), e );
            response.sendError( HttpStatus.SC_INTERNAL_SERVER_ERROR, "Error Publishing Bundle: " + e.getMessage() );
        }
View Full Code Here

Examples of com.dubture.getcomposer.core.objects.JsonObject

    if (json.containsKey(property)) {
      value = json.get(property);
      if (value instanceof JSONArray) {
        value = new JsonArray(value);
      } else if (value instanceof JSONObject) {
        value = new JsonObject(value);
      }
    }
    set(property, value);
  }
View Full Code Here

Examples of com.eclipsesource.json.JsonObject

  {
    try
    {
      System.out.println( "Using config : " + new File( configFile ).getName() );

      JsonObject config = Util.getJsonFromFile( configFile );

      mModel.setClassPackage( config.get( "package" ).asString() );
      mModel.setContentAuthority( config.get( "authority" ).asString() );
      mModel.setDbName( config.get( "databaseName" ).asString() );
      mModel.setDbVersion( config.get( "databaseVersion" ).asInt() );
      mModel.setContentProviderName( config.get( "contentproviderName" ).asString() );

    } catch ( IOException ex )
    {
      System.err.println( "Couldn't parse the config json file." );
      System.exit( 1 );
View Full Code Here

Examples of com.facebook.presto.hive.shaded.org.json.JSONObject

  public static final String METADATA_FORMAT_FORWARD_COMPATIBLE_VERSION = null;

  public static void createExportDump(FileSystem fs, Path metadataPath, org.apache.hadoop.hive.ql.metadata.Table tableHandle,
      List<org.apache.hadoop.hive.ql.metadata.Partition> partitions) throws SemanticException, IOException {
    try {
      JSONObject jsonContainer = new JSONObject();
      jsonContainer.put("version", METADATA_FORMAT_VERSION);
      if (METADATA_FORMAT_FORWARD_COMPATIBLE_VERSION != null) {
        jsonContainer.put("fcversion", METADATA_FORMAT_FORWARD_COMPATIBLE_VERSION);
      }
      TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
      try {
        String tableDesc = serializer.toString(tableHandle.getTTable(), "UTF-8");
        jsonContainer.put("table", tableDesc);
        JSONArray jsonPartitions = new JSONArray();
        if (partitions != null) {
          for (org.apache.hadoop.hive.ql.metadata.Partition partition : partitions) {
            String partDesc = serializer.toString(partition.getTPartition(), "UTF-8");
            jsonPartitions.put(partDesc);
          }
        }
        jsonContainer.put("partitions", jsonPartitions);
      } catch (TException e) {
        throw new SemanticException(
            ErrorMsg.GENERIC_ERROR
                .getMsg("Exception while serializing the metastore objects"), e);
      }
      OutputStream out = fs.create(metadataPath);
      out.write(jsonContainer.toString().getBytes("UTF-8"));
      out.close();

    } catch (JSONException e) {
      throw new SemanticException(ErrorMsg.GENERIC_ERROR.getMsg("Error in serializing metadata"), e);
    }
View Full Code Here

Examples of com.fins.org.json.JSONObject

   
    return info;
  }
 
  public static JSONObject generatePageInfoJSON(PageInfo pageInfo){
    JSONObject pageInfoJS = new JSONObject();
    pageInfoJS.put("endRowNum", pageInfo.getEndRowNum());
    pageInfoJS.put("pageNum", pageInfo.getPageNum());
    pageInfoJS.put("pageSize", pageInfo.getPageSize());
    pageInfoJS.put("startRowNum", pageInfo.getStartRowNum());
    pageInfoJS.put("totalPageNum", pageInfo.getTotalPageNum());
    pageInfoJS.put("totalRowNum", pageInfo.getTotalRowNum());
    return pageInfoJS;
  }
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.