Package com.dotmarketing.util.json

Examples of com.dotmarketing.util.json.JSONObject$Null


        //If the actionBean wasn't pick up.
        if(isMissing){
          //We need to save it as failed.
          actionBean.setCompleted(true);
          actionBean.setFailed(true);
          actionBean.setResponse(new JSONObject().put(ServerAction.ERROR_STATE, "Server did NOT respond on time"));
          APILocator.getServerActionAPI().saveServerActionBean(actionBean);
         
          //Add it to the results.
          resultActionBeans.add(actionBean);
        }
      }
    }
   
    //Iterate over all the results gathered.
    for (ServerActionBean resultActionBean : resultActionBeans) {
      JSONObject jsonNodeStatusObject = null;
     
      //If the result is failed we need to gather the info available.
      if(resultActionBean.isFailed()){
        Logger.error(ClusterResource.class,
            "Error trying to get Node Status for server " + resultActionBean.getServerId());
       
        jsonNodeStatusObject =
            ClusterUtilProxy.createFailedJson(APILocator.getServerAPI().getServer(resultActionBean.getServerId()));
     
        //If the result is OK we need to get the response object.
      } else {
        jsonNodeStatusObject = resultActionBean.getResponse().getJSONObject(NodeStatusServerAction.JSON_NODE_STATUS);
        jsonNodeStatusObject.put("myself", myServerId.equals(resultActionBean.getServerId()));
       
        //Check Test File Asset
        if(jsonNodeStatusObject.has("assetsStatus")
            && jsonNodeStatusObject.getString("assetsStatus").equals("green")
            && jsonNodeStatusObject.has("assetsTestPath")){
         
          //Get the file Name from the response.
          File testFile = new File(jsonNodeStatusObject.getString("assetsTestPath"));
          //If exist we need to check if we can delete it.
          if (testFile.exists()) {
            //If we can't delete it, it is a problem.
            if(!testFile.delete()){
              jsonNodeStatusObject.put("assetsStatus", "red");
              jsonNodeStatusObject.put("status", "red");
            }
          } else {
            jsonNodeStatusObject.put("assetsStatus", "red");
            jsonNodeStatusObject.put("status", "red");
          }
        }
      }
     
      //Add the status of the node to the list of other nodes.
View Full Code Here


        InitDataObject initData = init( params, true, request, false, "9" );
        ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );

        AdminClient client=null;

        JSONObject jsonNode = new JSONObject();

        try {
          client = new ESClient().getClient().admin();
        } catch (Exception e) {
          Logger.error(ClusterResource.class, "Error getting ES Client", e);
          jsonNode.put("error", e.getMessage());
          return responseResource.response( jsonNode.toString() );
        }

    ClusterHealthRequest clusterReq = new ClusterHealthRequest();
    ActionFuture<ClusterHealthResponse> afClusterRes = client.cluster().health(clusterReq);
    ClusterHealthResponse clusterRes = afClusterRes.actionGet();


    jsonNode.put("clusterName", clusterRes.getClusterName());
    jsonNode.put("numberOfNodes", clusterRes.getNumberOfNodes());
    jsonNode.put("activeShards", clusterRes.getActiveShards());
    jsonNode.put("activePrimaryShards", clusterRes.getActivePrimaryShards());
    jsonNode.put("unasignedPrimaryShards", clusterRes.getUnassignedShards());
    ClusterHealthStatus clusterStatus = clusterRes.getStatus();
    jsonNode.put("status", clusterStatus);

        return responseResource.response( jsonNode.toString() );

    }
View Full Code Here

     
      //If the we don't have the info after the timeout
      if(!nodeStatusServerActionBean.isCompleted()){
        nodeStatusServerActionBean.setCompleted(true);
        nodeStatusServerActionBean.setFailed(true);
        nodeStatusServerActionBean.setResponse(new JSONObject().put(ServerAction.ERROR_STATE, "Server did NOT respond on time"));
        APILocator.getServerActionAPI().saveServerActionBean(nodeStatusServerActionBean);
      }
     
      JSONObject jsonNodeStatusObject = null;
     
      //If the we have a failed job.
      if(nodeStatusServerActionBean.isFailed()){
        jsonNodeStatusObject =
            ClusterUtilProxy.createFailedJson(APILocator.getServerAPI().getServer(nodeStatusServerActionBean.getServerId()));
         
      //If everything is OK.
      } else {
        jsonNodeStatusObject =
                nodeStatusServerActionBean.getResponse().getJSONObject(NodeStatusServerAction.JSON_NODE_STATUS);
       
        //Check Test File Asset
        if(jsonNodeStatusObject.has("assetsStatus")
            && jsonNodeStatusObject.getString("assetsStatus").equals("green")
            && jsonNodeStatusObject.has("assetsTestPath")){
         
          //Get the file Name from the response.
          File testFile = new File(jsonNodeStatusObject.getString("assetsTestPath"));
          //If exist we need to check if we can delete it.
          if (testFile.exists()) {
            //If we can't delete it, it is a problem.
            if(!testFile.delete()){
              jsonNodeStatusObject.put("assetsStatus", "red");
              jsonNodeStatusObject.put("status", "red");
            }
          } else {
            jsonNodeStatusObject.put("assetsStatus", "red");
            jsonNodeStatusObject.put("status", "red");
          }
        }
      }
         
      if(jsonNodeStatusObject != null){
        return responseResource.response( jsonNodeStatusObject.toString() );
      } else {
        return null;
      }
         
    } else {
View Full Code Here

    public Response getESConfigProperties ( @Context HttpServletRequest request, @PathParam ("params") String params ) throws DotStateException, DotDataException, DotSecurityException, JSONException {

        InitDataObject initData = init( params, true, request, false, "9" );
        ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );

        JSONObject jsonNode = new JSONObject();
        ServerAPI serverAPI = APILocator.getServerAPI();

        String serverId = serverAPI.readServerId();
        Server server = serverAPI.getServer(serverId);
        String cachePort = ClusterFactory.getNextAvailablePort(serverId, ServerPort.CACHE_PORT);
        String esPort = ClusterFactory.getNextAvailablePort(serverId, ServerPort.ES_TRANSPORT_TCP_PORT);

        jsonNode.put("BIND_ADDRESS", server!=null&&UtilMethods.isSet(server.getIpAddress())?server.getIpAddress():"");
        jsonNode.put("CACHE_BINDPORT", server!=null&&UtilMethods.isSet(server.getCachePort())?server.getCachePort():cachePort);
        jsonNode.put("ES_TRANSPORT_TCP_PORT", server!=null&&UtilMethods.isSet(server.getEsTransportTcpPort())?server.getEsTransportTcpPort():esPort);

        return responseResource.response( jsonNode.toString() );

    }
View Full Code Here

    @Path ("/wirenode/{params:.*}")
    @Produces ("application/json")
    public Response wireNode ( @Context HttpServletRequest request, @PathParam ("params") String params ) throws DotStateException, DotDataException, DotSecurityException, JSONException {
        InitDataObject initData = init( params, true, request, true, "9" );

        JSONObject jsonNode = new JSONObject();

        if(request.getContentType().startsWith(MediaType.APPLICATION_JSON)) {
            HashMap<String,String> map=new HashMap<String,String>();

            try {
              String payload = IOUtils.toString(request.getInputStream());
              JSONObject obj = new JSONObject(payload);

              Iterator<String> keys = obj.keys();
              while(keys.hasNext()) {
                  String key=keys.next();
                  Object value=obj.get(key);
                  map.put(key, value.toString());
              }

              ClusterFactory.addNodeToCluster(map, APILocator.getServerAPI().readServerId());

View Full Code Here

    @Path("/licenseRepoStatus")
    @Produces("application/json")
    public Response getLicenseRepoStatus(@Context HttpServletRequest request, @PathParam ("params") String params) throws DotDataException, JSONException {
        init( params, true, request, true );

        JSONObject json=new JSONObject();
        json.put("total", LicenseUtil.getLicenseRepoTotal());
        json.put("available", LicenseUtil.getLicenseRepoAvailableCount());

        return Response.ok(json.toString()).build();
    }
View Full Code Here

            //Filter by name
            bundles = APILocator.getBundleAPI().getUnsendBundlesByName( userId, bundleName, offset, start );
        }
        for ( Bundle b : bundles ) {

            JSONObject jsonBundle = new JSONObject();
            jsonBundle.put( "id", b.getId() );
            jsonBundle.put( "name", StringEscapeUtils.unescapeJava(b.getName()));
            //Added to the response list
            jsonBundles.add( jsonBundle );
        }

        //Prepare the response
        JSONObject jsonResponse = new JSONObject();
        jsonResponse.put( "identifier", "id" );
        jsonResponse.put( "label", "name" );
        jsonResponse.put( "items", jsonBundles.toArray() );
        jsonResponse.put( "numRows", bundles.size() );

        CacheControl nocache=new CacheControl();
        nocache.setNoCache(true);
        return Response.ok(jsonResponse.toString()).cacheControl(nocache).build();
    }
View Full Code Here

    CacheControl cc = new CacheControl();
        cc.setNoCache( true );

    if(!UtilMethods.isSet(roleId) || roleId.equals("root")) {  // Loads Root Roles
      JSONArray jsonRoles = new JSONArray();
      JSONObject jsonRoleObject = new JSONObject();
      jsonRoleObject.put("id", "root");
      jsonRoleObject.put("name", "Roles");
      jsonRoleObject.put("top", "true");
     
      List<Role> rootRoles = roleAPI.findRootRoles();
      JSONArray jsonChildren = new JSONArray();

      for(Role r : rootRoles) {
        JSONObject jsonRoleChildObject = new JSONObject();
        jsonRoleChildObject.put("id", r.getId());
        jsonRoleChildObject.put("$ref", r.getId());
        jsonRoleChildObject.put("name", UtilMethods.javaScriptify(r.getName()));
        jsonRoleChildObject.put("locked", r.isLocked());
        jsonRoleChildObject.put("children", true);
       
        jsonChildren.add(jsonRoleChildObject);
      }
      //In order to add a JsonArray to a JsonObject
      //we need to specify that is an object (API bug)
      jsonRoleObject.put("children", (Object)jsonChildren);
      jsonRoles.add(jsonRoleObject);
     
      return responseResource.response(jsonRoles.toString(), cc);
     
    } else // Loads Children Roles of given Role ID
      Role role = roleAPI.loadRoleById(roleId);
     
      JSONObject jsonRoleObject = new JSONObject();
      jsonRoleObject.put("id", role.getId());
      jsonRoleObject.put("name", UtilMethods.javaScriptify(role.getName()));
      jsonRoleObject.put("locked", role.isLocked());

      JSONArray jsonChildren = new JSONArray();
     
      List<String> children = role.getRoleChildren();
      if(children != null) {
        for(String childId : children) {
          Role r = roleAPI.loadRoleById(childId);

          JSONObject jsonRoleChildObject = new JSONObject();
          jsonRoleChildObject.put("id", r.getId());
          jsonRoleChildObject.put("$ref", r.getId());
          jsonRoleChildObject.put("name", UtilMethods.javaScriptify(r.getName()));
          jsonRoleChildObject.put("locked", r.isLocked());
          jsonRoleChildObject.put("children", true);
         
          jsonChildren.add(jsonRoleChildObject);
        }         
      }
      //In order to add a JsonArray to a JsonObject
View Full Code Here

    Map<String, String> paramsMap = initData.getParamsMap();
    String roleId = paramsMap.get("id");

    if(!UtilMethods.isSet(roleId) || roleId.equalsIgnoreCase("root")) {
      JSONObject jsonRoleObject = new JSONObject();
      jsonRoleObject.put("id", 0);
      jsonRoleObject.put("name", "Root Role");

            return responseResource.response(jsonRoleObject.toString());
    }

    RoleAPI roleAPI = APILocator.getRoleAPI();
    Role role = roleAPI.loadRoleById(roleId);

    JSONObject jsonRoleObject = new JSONObject();
    jsonRoleObject.put("DBFQN", UtilMethods.javaScriptify(role.getDBFQN()));
    jsonRoleObject.put("FQN", UtilMethods.javaScriptify(role.getFQN()));
    jsonRoleObject.put("children", (Object)new JSONArray());
    jsonRoleObject.put("description", UtilMethods.javaScriptify(role.getDescription()));
    jsonRoleObject.put("editLayouts", role.isEditLayouts());
    jsonRoleObject.put("editPermissions", role.isEditPermissions());
    jsonRoleObject.put("editUsers", role.isEditUsers());
    jsonRoleObject.put("id", role.getId());
    jsonRoleObject.put("locked", role.isLocked());
    jsonRoleObject.put("name", UtilMethods.javaScriptify(role.getName()));
    jsonRoleObject.put("parent", role.getParent());
    jsonRoleObject.put("roleKey", role.getRoleKey()!=null?UtilMethods.javaScriptify(role.getRoleKey()):"");
    jsonRoleObject.put("system", role.isSystem());

        return responseResource.response(jsonRoleObject.toString());
    }
View Full Code Here

      } else {
        resultTree.put(node,  null);
      }

    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("identifier", "id");
    jsonObject.put("label", "name");
   
    JSONArray jsonItems = new JSONArray();
   
    JSONObject jsonItemsObject = new JSONObject();
    jsonItemsObject.put("id", "root");
    jsonItemsObject.put("name", "Roles");
    jsonItemsObject.put("top", true);
    jsonItemsObject.put("children", (Object)buildFilteredJsonTree(resultTree));
   
    jsonItems.add(jsonItemsObject);
   
    jsonObject.put("items", (Object)jsonItems);
View Full Code Here

TOP

Related Classes of com.dotmarketing.util.json.JSONObject$Null

Copyright © 2018 www.massapicom. 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.