Example usage for com.google.gson JsonObject toString

List of usage examples for com.google.gson JsonObject toString

Introduction

In this page you can find the example usage for com.google.gson JsonObject toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns a String representation of this element.

Usage

From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java

License:Open Source License

private Map<Long, User> json2Users(JsonObject json) {
    HashMap<Long, User> users = new HashMap<Long, User>();
    JsonObject block = json.get(SECTION_U).getAsJsonObject();

    Set<Entry<String, JsonElement>> entries = block.entrySet();
    for (Entry<String, JsonElement> u : entries) {
        JsonObject jsUser = u.getValue().getAsJsonObject();
        System.out.println(jsUser.toString());
        String uname;//from ww w  . j av  a 2  s.c  om
        if (jsUser.has(NAME))
            uname = jsUser.get(NAME).getAsString();
        else
            uname = "";
        String uDescr;
        if (jsUser.has(DESCRIPTION))
            uDescr = jsUser.get(DESCRIPTION).getAsString();
        else
            uDescr = "";
        String externalUID;
        if (jsUser.has(E_UID))
            externalUID = jsUser.get(E_UID).getAsString();
        else
            externalUID = "";
        User user = new User(externalUID, uname, uDescr);
        users.put(Long.parseLong(u.getKey()), user);
    }
    return users;
}

From source file:au.edu.ausstage.tweetgatherer.MessageProcessor.java

License:Open Source License

/**
 * A method that is run in the thread/*from w  w  w  .  j  av  a  2  s.  c om*/
 * Takes a tweet from the queue and processes it
 */
public void run() {
    STweet tweet = null;

    try {

        // infinite loop to keep the thread running
        while (true) {

            // take a tweet from the queue
            tweet = newTweets.take();

            // get the tweet id number
            String tweetId = Long.toString(tweet.getStatusId());

            // get a hash of the tweet id
            String tweetIdHash = HashUtils.hashValue(tweetId);

            // get the user
            STweetUser user = tweet.getUser();

            // get the user id
            String userId = Long.toString(user.getUserId());

            // get a hash of the user id
            String userIdHash = HashUtils.hashValue(userId);

            // get the JSON value of the tweet
            JsonObject jsonTweetObject = sanitiseMessage(tweet.getJSON(), tweetIdHash);

            // get the JSON value of the user
            JsonObject jsonUserObject = sanitiseUser(user.getJSON(), userIdHash);

            // replace the user with the sanitised version
            jsonTweetObject.remove("user");
            jsonTweetObject.addProperty("user", "");

            /*
             * Write the file
             */

            if (FileUtils.writeNewFile(logFiles + "/" + tweetIdHash,
                    jsonTweetObject.toString() + "\n" + jsonUserObject.toString()) == false) {
                System.err.println("ERROR: Unable to write file to the specified log file");
                System.err.println("       twitter message with id '" + tweetId + "' is now lost");
            } else {
                System.out.println("INFO: New Message written to the log directory:");
                System.out.println("      " + tweetIdHash);
            }

            /*
             * get the hash tags from this message
             */

            // get the list of hash tags from the tweet
            JsonElement elem = jsonTweetObject.get("text");
            List<String> hashtags = extractHashTags.extractHashtags(elem.getAsString());

            // convert all of the found hash tags to lower case
            ListIterator<String> hashtagsIterator = hashtags.listIterator();

            while (hashtagsIterator.hasNext() == true) {

                // get the next tage in the list
                String tmp = (String) hashtagsIterator.next();

                tmp = tmp.toLowerCase();

                // replace the value we retrieved with this updated one
                hashtagsIterator.set(tmp);
            }

            // see if this is a company performance
            if (isCompanyPerformance(hashtags, jsonTweetObject, jsonUserObject, tweetIdHash) == false) {
                // this isn't a company performance
                // is it using a performance specific id?
                if (isPerformance(hashtags, jsonTweetObject, jsonUserObject, tweetIdHash) == false) {
                    //this isn't a valid performance
                    System.err.println("ERROR: Unable to find a matching performance for this message");

                    // send an exception report
                    if (emailManager.sendMessageWithAttachment(EMAIL_SUBJECT, EMAIL_MESSAGE,
                            logFiles + "/" + tweetIdHash) == false) {
                        System.err.println("ERROR: Unable to send the exception report");
                    }
                }
            }
        }

    } catch (InterruptedException ex) {
        // thread has been interrupted
        System.out.println("INFO: The Message processing thread has stopped");
    }
}

From source file:au.edu.unsw.cse.soc.federatedcloud.CloudResourceBaseDeploymentEngine.java

License:Open Source License

@Path("/deploy")
@POST//from  w ww. j  ava 2 s . co m
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response deployCloudResourceDescription(@QueryParam("description_id") String description_id,
        @QueryParam("description_json") @DefaultValue("{}") String description) {
    log.info("Deployment Request Received for id: " + description_id);
    try {
        log.info("Input Resource description: " + URLDecoder.decode(description, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage(), e);
    }

    try {
        CloudResourceDescription desc = DataModelUtil.buildCouldResourceDescriptionFromJSON(description_id);
        CloudResourceBaseDeploymentEngine engine = new CloudResourceBaseDeploymentEngine();
        String response = engine.deployCloudResourceDescription(desc);
        log.info("Deployed Resource:" + desc.toString());

        JsonObject json = new JsonObject();
        json.addProperty("result", response);
        return Response.status(Response.Status.OK).entity(json.toString()).build();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return Response.status(Response.Status.OK).entity(e.getMessage()).build();
    }
}

From source file:au.edu.unsw.cse.soc.federatedcloud.cloudRessourceBase.RecommenderAPI.java

License:Open Source License

@Path("/getAll")
@GET//from  w w  w.  j ava 2s.  c o m
@Produces(MediaType.APPLICATION_JSON)
public Response getAllRecommendations() {
    JsonObject json = returnDummyObject();

    return Response.status(Response.Status.OK).entity(json.toString()).build();

}

From source file:au.edu.unsw.cse.soc.federatedcloud.cloudRessourceBase.RecommenderAPI.java

License:Open Source License

@Path("/getByName")
@GET/*from www .j ava 2  s. co m*/
@Produces(MediaType.APPLICATION_JSON)
public Response getRecommendationsByName(String name) {
    JsonObject json = returnDummyObject();

    return Response.status(Response.Status.OK).entity(json.toString()).build();
}

From source file:au.edu.unsw.cse.soc.federatedcloud.cloudRessourceBase.RecommenderAPI.java

License:Open Source License

@Path("/getByTaskCategory")
@GET/*w ww . j a va2 s.c o m*/
@Produces(MediaType.APPLICATION_JSON)
public Response getRecommendationsByTaskCategory(String taskCategory) {
    JsonObject json = returnDummyObject();

    return Response.status(Response.Status.OK).entity(json.toString()).build();
}

From source file:au.edu.unsw.cse.soc.federatedcloud.curator.CuratorAPI.java

License:Open Source License

@Path("/putResource")
@POST/*from w  ww. j a  v  a  2 s .  c  o m*/
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response putResource(CloudResourceDescription description) {
    persistResource(description);
    log.warn("Composite Resource handler is not yet implemented.");

    JsonObject json = new JsonObject();
    try {
        json.addProperty("cloudResourceDescriptionId", description.getID());
        return Response.status(Response.Status.OK).entity(json.toString()).build();
    } catch (Exception e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
}

From source file:au.edu.unsw.cse.soc.federatedcloud.curator.CuratorAPI.java

License:Open Source License

@Path("/putRule")
@POST/*from   w  ww  .  jav  a 2s  . c o  m*/
@Produces(MediaType.APPLICATION_JSON)
public Response putRule(RecommendationRule rule) {
    persistRecommendationRule(rule);
    log.warn("Composite Resource handler is not yet implemented.");

    JsonObject ruleID = new JsonObject();
    ruleID.addProperty("ruleID", rule.getId());
    return Response.status(Response.Status.OK).entity(ruleID.toString()).build();
}

From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.AWSS3Deployer.java

License:Open Source License

@Path("/deploy")
@POST/*from  w  ww. j av  a  2s  . c  om*/
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
/*@Override*/
public Response deploy(@QueryParam("descriptionid") String descriptionid) throws Exception {
    //Reading the credentials
    Properties properties = new Properties();
    properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties"));
    String accessKey = properties.getProperty("accessKey");
    String secretKey = properties.getProperty("secretKey");

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

    AmazonS3Client client = new AmazonS3Client(credentials);

    //String name = description.getAttributes().get("name");
    String name = "ddweerasiri-test-bucket";
    //client.createBucket(name);

    log.info("Bucket was created with name:" + name);
    System.out.println("Helooooooo:" + descriptionid);

    JsonObject json = new JsonObject();
    json.addProperty("cloudResourceDescriptionId", descriptionid);
    return Response.status(Response.Status.OK).entity(json.toString()).build();
}

From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.ClassForPaper.java

License:Open Source License

@Path("/deployResource")
@POST//from w  w  w.  jav  a  2s.  co m
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response deployResource(@QueryParam("description") CRCD resourceDescription) throws Exception {
    //Reading the credentials
    Properties properties = new Properties();
    properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties"));
    String accessKey = properties.getProperty("accessKey");
    String secretKey = properties.getProperty("secretKey");
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonS3Client client = new AmazonS3Client(credentials);

    String name = resourceDescription.getAttribute("bucket-name");
    Bucket bucket = client.createBucket(name);

    JsonObject json = new JsonObject();
    json.addProperty("resourceID", bucket.getName());
    return Response.status(Response.Status.OK).entity(json.toString()).build();
}