Package com.dotmarketing.util.json

Examples of com.dotmarketing.util.json.JSONArray


            //If we have errors lets return them in order to feedback the user
            if ( responseMap != null && !responseMap.isEmpty() ) {

                //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
View Full Code Here


            //If we have errors lets return them in order to feedback the user
            if ( responseMap != null && !responseMap.isEmpty() ) {

                //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" ) );

                //And send it back to the user
                response.getWriter().println( jsonResponse.toString() );
View Full Code Here

      Structure specificStructure = StructureCache.getStructureByInode(inodeFilter);
      if(specificStructure != null)
        structures.add(specificStructure);
    }
   
    JSONArray jsonStructures = new JSONArray();
    JSONObject jsonStructureObject = new JSONObject();
   
    int structCount = 0;
    for(Structure st: structures)
    {
      if(!inodeFilter.isEmpty() || (!range.isEmpty() && structCount >= beginItem && structCount <= endItem)){
        jsonStructureObject = new JSONObject();
        jsonStructureObject.put("id", st.getInode());
        jsonStructureObject.put("name", st.getName());
      }
      if(inodeFilter.isEmpty()){
        jsonStructures.add(jsonStructureObject);
      }else{
        return responseResource.response(jsonStructureObject.toString());
      }
    }
    if(inodeFilter.isEmpty() && !range.isEmpty()) {
      response.addHeader("Content-Range", "items " + beginItem + "-" + Math.min(endItem, structCount -1) + "/" + structCount);
    }

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

    assertTrue(isValidJSONObject(response));
  }

  private boolean isValidJSONArray(String json) {
    try {
      new JSONArray(json);
    } catch (JSONException e) {
      Logger.error(this.getClass(), "Not Valid JSON Array");
      return false;
    }
View Full Code Here

      BufferedReader versionsReader = new BufferedReader(new InputStreamReader(versionsInputStream, Charset.forName("UTF-8")));
      String filesText = UtilMethods.getStringFromReader(filesReader);
      JSONObject filesJSON  = new JSONObject(filesText);
      String versionsText = UtilMethods.getStringFromReader(versionsReader);
      JSONObject versionsJSON  = new JSONObject(versionsText);
      JSONArray majorArr = versionsJSON.getJSONArray("contentlets");
      JSONArray minorArr = filesJSON.getJSONArray("contentlets");
     
      if(minorArr.size()>0){
        String versionsFilesQuery = "http://dotcms.com/JSONContent/?type=json&q="+
        URLEncoder.encode("+Parent_Versions-Child_Files:"+minorArr.getJSONObject(0).getString("identifier")+" +deleted:false +live:true","UTF-8")+
        "&limit=1&orderBy=AutoupdaterFiles.releasedDate%20desc";
        versionsFilesQueryIs = new URL(versionsFilesQuery).openStream();
        BufferedReader versionsFilesReader = new BufferedReader(new InputStreamReader(versionsFilesQueryIs, Charset.forName("UTF-8")));
        String versionsFilesText = UtilMethods.getStringFromReader(versionsFilesReader);
        JSONObject versionsFilesJSON  = new JSONObject(versionsFilesText);
        JSONArray versionsFilesArr = versionsFilesJSON.getJSONArray("contentlets");
        if(versionsFilesArr.size()>0){
          if(versionsFilesQueryIs!=null){
            versionsFilesQueryIs.close();
          }
          versionsFilesQuery = "http://dotcms.com/JSONContent/?type=json&q="+
          URLEncoder.encode("+Parent_Versions-Child_Files:"+versionsFilesArr.getJSONObject(0).getString("identifier")+" -AutoupdaterFiles.minor:autoupdater_* +AutoupdaterFiles.released:true +deleted:false +working:true", "UTF-8")+
          "&limit=1&orderBy=AutoupdaterFiles.releasedDate%20desc";
          versionsFilesQueryIs = new URL(versionsFilesQuery).openStream();
          versionsFilesReader = new BufferedReader(new InputStreamReader(versionsFilesQueryIs, Charset.forName("UTF-8")));
          versionsFilesText = UtilMethods.getStringFromReader(versionsFilesReader);
          versionsFilesJSON  = new JSONObject(versionsFilesText);
          versionsFilesArr = versionsFilesJSON.getJSONArray("contentlets");
          minor = versionsFilesArr.getJSONObject(0).getString("minor");
        }


      }
      if(majorArr.size()>0){
        for(int i=0;i<majorArr.size();i++){
          if(versionsFilesQueryIs!=null){
            versionsFilesQueryIs.close();
          }
          major = majorArr.getJSONObject(i).getString("major");
          String majorIdentifier = majorArr.getJSONObject(i).getString("identifier");
          String versionsFilesQuery = "http://dotcms.com/JSONContent/?type=json&q="+
          URLEncoder.encode("+Parent_Versions-Child_Files:"+majorIdentifier+" +AutoupdaterFiles.released:true -AutoupdaterFiles.minor:autoupdater_* +deleted:false +live:true","UTF-8")+
          "&limit=1&orderBy=AutoupdaterFiles.releasedDate%20desc";
          versionsFilesQueryIs = new URL(versionsFilesQuery).openStream();
          BufferedReader versionsFilesReader = new BufferedReader(new InputStreamReader(versionsFilesQueryIs, Charset.forName("UTF-8")));
          String versionsFilesText = UtilMethods.getStringFromReader(versionsFilesReader);
          JSONObject versionsFilesJSON  = new JSONObject(versionsFilesText);
          JSONArray versionsFilesArr = versionsFilesJSON.getJSONArray("contentlets");
          if(versionsFilesArr.size()>0){
            break;
          }else{
            major = "";
          }
        }
View Full Code Here

        wfActions = APILocator.getWorkflowAPI().findAvailableActions( con, currentUser );
      } catch ( Exception e ) {
                Logger.error( this, "Could not load workflow actions : ", e );
            }

      JSONArray wfActionMapList = new JSONArray();

      for ( WorkflowAction action : wfActions ) {
        boolean hasPushPublishActionlet = false;
                if ( action.requiresCheckout() )
                    continue;

                JSONObject wfActionMap = new JSONObject();
                try {
          wfActionMap.put( "name", action.getName() );
                  wfActionMap.put( "id", action.getId() );
                  wfActionMap.put( "icon", action.getIcon() );
                  wfActionMap.put( "assignable", action.isAssignable() );
                  wfActionMap.put( "commentable", action.isCommentable() || UtilMethods.isSet( action.getCondition() ) );
                  wfActionMap.put( "requiresCheckout", action.requiresCheckout() );

                  List<WorkflowActionClass> actionlets = APILocator.getWorkflowAPI().findActionClasses(action);
                  for(WorkflowActionClass actionlet : actionlets){
                    if(actionlet.getActionlet() != null
                        && actionlet.getActionlet().getClass().getCanonicalName().equals(PushPublishActionlet.class.getCanonicalName())){
                      hasPushPublishActionlet = true;
                    }
                  }
                  wfActionMap.put( "hasPushPublishActionlet", hasPushPublishActionlet );
                  try {
            wfActionMap.put( "wfActionNameStr", LanguageUtil.get( currentUser, action.getName() ) );
          } catch (LanguageException e) {
            Logger.error( this, "Could not load language key : " + action.getName() );
          }
                  wfActionMapList.add( wfActionMap );

                } catch (JSONException e1) {
          Logger.error(this,  "Could not put property in JSONObject");
        }
            }


      searchResult.put( "wfActionMapList", wfActionMapList.toString() );

            // End Workflow Actions

      //searchResult.put("structureName", st.getVelocityVarName());
      Long LanguageId=con.getLanguageId();
View Full Code Here

        List<Server> servers = serverAPI.getAllServers();
        String myServerId = serverAPI.readServerId();

        List<ServerActionBean> actionBeans = new ArrayList<ServerActionBean>();
        List<ServerActionBean> resultActionBeans = new ArrayList<ServerActionBean>();
        JSONArray jsonNodes = new JSONArray();
       
        NodeStatusServerAction nodeStatusServerAction = new NodeStatusServerAction();
        Long timeoutSeconds = new Long(1);
   
    for (Server server : servers) {
     
      ServerActionBean nodeStatusServerActionBean =
          nodeStatusServerAction.getNewServerAction(myServerId, server.getServerId(), timeoutSeconds);
     
      nodeStatusServerActionBean =
          APILocator.getServerActionAPI().saveServerActionBean(nodeStatusServerActionBean);
     
      actionBeans.add(nodeStatusServerActionBean);
    }
   
    //Waits for 3 seconds in order server respond.
    int maxWaitTime =
        timeoutSeconds.intValue() * 1000 + Config.getIntProperty("CLUSTER_SERVER_THREAD_SLEEP", 2000) ;
    int passedWaitTime = 0;
   
    //Trying to NOT wait whole time for returning the info.
    while (passedWaitTime <= maxWaitTime){
      try {
          Thread.sleep(10);
          passedWaitTime += 10;
         
          resultActionBeans = new ArrayList<ServerActionBean>();
         
          //Iterates over the Actions in order to see if we have it all.
          for (ServerActionBean actionBean : actionBeans) {
            ServerActionBean resultActionBean =
                APILocator.getServerActionAPI().findServerActionBean(actionBean.getId());
           
            //Add the ActionBean to the list of results.
            if(resultActionBean.isCompleted()){
              resultActionBeans.add(resultActionBean);
            }
        }
         
          //No need to wait if we have all Action results.
          if(resultActionBeans.size() == servers.size()){
            passedWaitTime = maxWaitTime + 1;
          }
         
      } catch(InterruptedException ex) {
          Thread.currentThread().interrupt();
          passedWaitTime = maxWaitTime + 1;
      }
    }
   
    //If some of the server didn't pick up the action, means they are down.
    if(resultActionBeans.size() != actionBeans.size()){
      //Need to find out which is missing?
      for(ServerActionBean actionBean : actionBeans){
        boolean isMissing = true;
        for(ServerActionBean resultActionBean : resultActionBeans){
          if(resultActionBean.getId().equals(actionBean.getId())){
            isMissing = false;
          }
        }
        //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.
      if(jsonNodeStatusObject != null){
        jsonNodes.add( jsonNodeStatusObject );
      }
    } 

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

            } else {
                bundleName = bundleName.replaceAll( "\\*", "" );
            }
        }

        JSONArray jsonBundles = new JSONArray();

        //Find the unsend bundles
        List<Bundle> bundles;
        if ( bundleName == null ) {
            //Find all the bundles for this user
            bundles = APILocator.getBundleAPI().getUnsendBundles( userId, offset, start );
        } else {
            //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
      //we need to specify that is an object (API bug)
      jsonRoleObject.put("children", (Object)jsonChildren);
View Full Code Here

    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());
View Full Code Here

TOP

Related Classes of com.dotmarketing.util.json.JSONArray

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.