Package com.dotmarketing.util.json

Examples of com.dotmarketing.util.json.JSONArray


    }
    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);

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


  }

  @SuppressWarnings("unchecked")
  private JSONArray buildFilteredJsonTree(LinkedHashMap<String, Object> map) throws DotDataException, JSONException {
    JSONArray jsonChildren = new JSONArray();
   
    RoleAPI roleAPI = APILocator.getRoleAPI();

    if(map != null) {
      for (String key : map.keySet()) {
        Role r = roleAPI.loadRoleById(key);
       
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", r.getId().replace('-', '_'));
        jsonObject.put("name", UtilMethods.javaScriptify(r.getName()));
        jsonObject.put("locked", r.isLocked());
       
        LinkedHashMap<String, Object> children = (LinkedHashMap<String, Object>) map.get(key);
       
        jsonObject.put("children", (Object)buildFilteredJsonTree(children));
        jsonChildren.add(jsonObject);
      }
    }
    return jsonChildren;
  }
View Full Code Here

                xmlBuilder.append( xstream.toXML( bundlesArray ) );

                responseMessage.append( xmlBuilder );
            } else {

                JSONArray bundlesArray = new JSONArray();
                for ( Bundle bundle : installedBundles ) {

                    if ( ignoreSystemBundles && systemBundles.contains( bundle.getSymbolicName() ) ) {
                        continue;
                    }

                    //Getting the jar file name
                    String separator = File.separator;
                    if ( bundle.getLocation().contains( "/" ) ) {
                        separator = "/";
                    }
                    String jarFile = bundle.getLocation().contains( separator ) ? bundle.getLocation().substring( bundle.getLocation().lastIndexOf( separator ) + 1 ) : "System";

                    //Build the version string
                    String version = bundle.getVersion().getMajor() + "." + bundle.getVersion().getMinor() + "." + bundle.getVersion().getMicro();

                    //Reading and setting bundle information
                    JSONObject jsonResponse = new JSONObject();
                    jsonResponse.put( "bundleId", bundle.getBundleId() );
                    jsonResponse.put( "symbolicName", bundle.getSymbolicName() );
                    jsonResponse.put( "location", bundle.getLocation() );
                    jsonResponse.put( "jarFile", jarFile );
                    jsonResponse.put( "state", bundle.getState() );
                    jsonResponse.put( "version", version );
                    jsonResponse.put( "separator", separator );

                    bundlesArray.add( jsonResponse );
                }

                responseMessage.append( bundlesArray.toString() );
            }


        } catch ( Exception e ) {
            Logger.error( this.getClass(), "Error getting installed OSGI bundles.", e );
View Full Code Here

            IntegrityUtil integrityUtil = new IntegrityUtil();

            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //Structures tab data
            JSONArray tabResponse = null;
            JSONObject errorContent = null;

            IntegrityType[] types = IntegrityType.values();
            boolean isThereAnyConflict = false;

            for (IntegrityType integrityType : types) {
                tabResponse = new JSONArray();
                errorContent = new JSONObject();

                errorContent.put( "title",   LanguageUtil.get( initData.getUser().getLocale(), integrityType.getLabel() )  );//Title of the check

                List<Map<String, Object>> results = integrityUtil.getIntegrityConflicts(endpointId, integrityType);

                JSONArray columns = new JSONArray();

                switch (integrityType) {
                    case STRUCTURES:
                        columns.add("velocity_name");
                        break;
                    case FOLDERS:
                        columns.add("folder");
                        break;
                    case SCHEMES:
                        columns.add("name");
                        break;
                }

                columns.add("local_inode");
                columns.add("remote_inode");

                errorContent.put( "columns", columns.toArray() );

                if(!results.isEmpty()) {
                    // the columns names are the keys in the results
                    isThereAnyConflict = isThereAnyConflict || true;

                    JSONArray values = new JSONArray();
                    for (Map<String, Object> result : results) {

                        JSONObject columnsContent = new JSONObject();

                        for (String keyName : result.keySet()) {
                            columnsContent.put(keyName, result.get(keyName));
                        }

                        values.put(columnsContent);
                    }

                    errorContent.put( "values", values.toArray() );
                } else {
                    errorContent.put( "values", new JSONArray().toArray() );
                }

                tabResponse.add( errorContent );
                //And prepare the response
                jsonResponse.put( integrityType.name().toLowerCase(), tabResponse.toArray() );
View Full Code Here

        offset = UtilMethods.isSet(range)?Long.parseLong(range.split("=")[1].split("-")[0]):offset;
        limit = UtilMethods.isSet(range)?Long.parseLong(range.split("=")[1].split("-")[1]):limit;
        limit += 1;

        JSONArray notificationsJSON = new JSONArray();

        NotificationAPI notificationAPI = APILocator.getNotificationAPI();

        // Let's get the total count
        Long total = notificationAPI.getNotificationsCount();

        // Let's mark the new notifications as read
        notificationAPI.markNotificationsAsRead(user.getUserId());

        List<Notification> notifications = allUsers?notificationAPI.getNotifications(offset, limit):notificationAPI.getNotifications(user.getUserId(), offset, limit);

        for (Notification n : notifications) {
          JSONObject notificationJSON = new JSONObject();
          notificationJSON.put("id", n.getId());
          notificationJSON.put("message", n.getMessage());
          notificationJSON.put("type", n.getType().name());
          notificationJSON.put("level", n.getLevel().name());
          notificationJSON.put("time_sent", DateUtil.prettyDateSince(n.getTimeSent()));
          notificationsJSON.add(notificationJSON);
    }

        return Response.ok( notificationsJSON.toString()).header("Content-Range", "items " + offset + "-" + limit + "/" + total).build() ;

    }
View Full Code Here

        ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );

    String roleId = initData.getParamsMap().get("roleid");

    //Using JsonArray instead of manually creating the json object
    JSONArray jsonEnvironments = new JSONArray();

    //First objects is expected to be blank
    JSONObject jsonEnvironmentFirst = new JSONObject();
    jsonEnvironmentFirst.put( "id", "0" );
    jsonEnvironmentFirst.put( "name", "");

    jsonEnvironments.add(jsonEnvironmentFirst);

    Role role = APILocator.getRoleAPI().loadRoleById(roleId);
    User user = APILocator.getUserAPI().loadUserById(role.getRoleKey());
    boolean isAdmin = APILocator.getUserAPI().isCMSAdmin(user);

    List<Role> roles = APILocator.getRoleAPI().loadRolesForUser(user.getUserId(),true);
    Set<Environment> environments = new HashSet<Environment>();
    if(isAdmin){
      List<Environment> app = APILocator.getEnvironmentAPI().findEnvironmentsWithServers();
      for(Environment e:app)
        environments.add(e);
    }
    else
      for(Role r: roles)
        environments.addAll(APILocator.getEnvironmentAPI().findEnvironmentsByRole(r.getId()));

    //For each env, create one json and add it to the array
    for(Environment e : environments) {

      JSONObject environmentBundle = new JSONObject();
      environmentBundle.put( "id", e.getId() );
      //Escape name for cases like: dotcms's
      environmentBundle.put( "name", StringEscapeUtils.unescapeJava( e.getName() ));

      jsonEnvironments.add(environmentBundle);
    }

    CacheControl cc = new CacheControl();
    cc.setNoCache(true);
    return Response.ok(jsonEnvironments.toString(), MediaType.APPLICATION_JSON_TYPE).cacheControl(cc).build();
  }
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.