Example usage for com.google.gson JsonObject has

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

Introduction

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

Prototype

public boolean has(String memberName) 

Source Link

Document

Convenience method to check if a member with the specified name is present in this object.

Usage

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.BranchParser.java

License:Apache License

@Override
public Branch apply(JsonElement jsonElement) {
    JsonObject json = jsonElement.getAsJsonObject();
    final Branch branch = new Branch(json.get("id").getAsString(), json.get("displayId").getAsString(),
            json.get("latestChangeset").getAsString(), json.get("isDefault").getAsBoolean());
    if (json.has("metadata")) {
        branch.setMetadata(json.getAsJsonObject("metadata"));
    }//w  w w .  j a  va2  s.  com
    return branch;
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.CommentAnchorParser.java

License:Apache License

@Override
public CommentAnchor apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }//from   ww w . ja  v a  2  s  .com

    JsonObject json = jsonElement.getAsJsonObject();
    return new CommentAnchor(optionalJsonString(json, "fromHash"), json.get("toHash").getAsString(),
            optionalJsonLong(json, "line"),
            json.has("lineType") ? LineType.valueOf(json.get("lineType").getAsString()) : null,
            json.has("fileType") ? FileType.valueOf(json.get("fileType").getAsString()) : null,
            json.get("path").getAsString(), optionalJsonString(json, "srcPath"),
            json.get("orphaned").getAsBoolean());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.DiffParser.java

License:Apache License

@Override
public Diff apply(JsonElement jsonElement) {

    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }//from w  w  w  . java 2 s  .c  o m

    JsonObject json = jsonElement.getAsJsonObject();

    return new Diff(pathParser().apply(json.get("destination").getAsJsonObject()),
            listParser(diffHunkParser()).apply(json.get("hunks")),
            json.get("source").isJsonNull() ? null : pathParser().apply(json.get("source").getAsJsonObject()),
            json.has("binary") && json.get("binary").getAsBoolean(), json.get("truncated").getAsBoolean());
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.ProjectParser.java

License:Apache License

@Override
public Project apply(JsonElement jsonElement) {
    JsonObject json = jsonElement.getAsJsonObject();
    String selfUrl = null;//from  w w w .j  a v a2s.  c om

    if (json.has("links")) {
        selfUrl = linkParser().apply(json.getAsJsonObject("links").get("self").getAsJsonArray().get(0))
                .getHref();
    }

    return new Project(json.get("key").getAsString(), json.get("id").getAsLong(),
            json.get("name").getAsString(), optionalJsonString(json, "description"),
            optionalJsonBoolean(json, "public"), optionalJsonBoolean(json, "isPersonal"),
            ProjectType.valueOf(json.get("type").getAsString()), selfUrl);
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PullRequestActivityParser.java

License:Apache License

@Override
public PullRequestActivity apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }/*from ww  w .j  a  v  a 2 s.  c om*/
    JsonObject json = jsonElement.getAsJsonObject();

    PullRequestActivityActionType actionType = PullRequestActivityActionType
            .valueOf(json.get("action").getAsString());
    if (actionType == PullRequestActivityActionType.COMMENTED) {
        return new PullRequestCommentActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId, json.get("commentAction").getAsString(),
                commentParser().apply(json.getAsJsonObject("comment")),
                commentAnchorParser().apply(json.getAsJsonObject("commentAnchor")),
                json.has("diff") ? diffParser().apply(json.getAsJsonObject("diff")) : null

        );
    } else if (actionType == PullRequestActivityActionType.RESCOPED) {
        List<Commit> added = new ArrayList<>();
        List<Commit> removed = new ArrayList<>();
        if (json.has("added")) {
            added = getCommits(json.get("added").getAsJsonObject());
        }
        if (json.has("removed")) {
            removed = getCommits(json.get("removed").getAsJsonObject());
        }

        return new PullRequestRescopedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId, json.get("fromHash").getAsString(), json.get("previousFromHash").getAsString(),
                json.get("previousToHash").getAsString(), json.get("toHash").getAsString(), added, removed);

    } else if (actionType == PullRequestActivityActionType.MERGED) {
        return new PullRequestMergedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.APPROVED) {
        return new PullRequestApprovedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.DECLINED) {
        return new PullRequestDeclinedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.UNAPPROVED) {
        return new PullRequestUnapprovedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.OPENED) {
        return new PullRequestOpenedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.REOPENED) {
        return new PullRequestReOpenedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.UPDATED) {
        return new PullRequestUpdatedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else if (actionType == PullRequestActivityActionType.REVIEWED) {
        return new PullRequestReviewedActivity(json.get("id").getAsLong(),
                new Date(json.get("createdDate").getAsLong()), userParser().apply(json.getAsJsonObject("user")),
                pullRequestId);
    } else
        throw new RuntimeException("cannot parse action:" + actionType);

}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PullRequestActivityParser.java

License:Apache License

private List<Commit> getCommits(JsonObject json) {
    List<Commit> commits = new ArrayList<>();
    if (json.has("changesets")) {
        commits.addAll(listParser(commitParser()).apply(json.get("changesets")));
    }// w w  w . j  a  va2  s .  co  m
    if (json.has("commits")) {
        commits.addAll(listParser(commitParser()).apply(json.get("commits")));
    }
    return commits;
}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PullRequestChangeParser.java

License:Apache License

@Override
public PullRequestChange apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }//w  w w .j  a v  a 2s .c  om
    JsonObject json = jsonElement.getAsJsonObject();
    String selfUrl = null;
    if (json.has("links")) {
        selfUrl = linkParser().apply(json.getAsJsonObject("links").get("self").getAsJsonArray().get(0))
                .getHref();
    }
    return new PullRequestChange(json.get("contentId").getAsString(), optionalJsonString(json, "fromContentId"),
            pathParser().apply(json.getAsJsonObject("path")),
            pathParser().apply(json.getAsJsonObject("srcPath")),
            FileChangeType.valueOf(json.get("type").getAsString()), json.get("executable").getAsBoolean(),
            json.get("percentUnchanged").getAsInt(), NodeType.valueOf(json.get("nodeType").getAsString()),
            json.get("executable").getAsBoolean(), selfUrl);

}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PullRequestParser.java

License:Apache License

@Override
public PullRequest apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }//from  ww w. j a va2s . c o  m
    JsonObject json = jsonElement.getAsJsonObject();
    //PullRequest pullRequest = new PullRequest();

    PullRequestParticipant author = pullRequestParticipantParser().apply(json.getAsJsonObject("author"));
    List<PullRequestParticipant> reviewers = listParser(pullRequestParticipantParser())
            .apply(json.get("reviewers"));
    List<PullRequestParticipant> participants = listParser(pullRequestParticipantParser())
            .apply(json.get("participants"));
    PullRequestBranch from = pullRequestBranchParser().apply(json.getAsJsonObject("fromRef"));
    PullRequestBranch to = pullRequestBranchParser().apply(json.getAsJsonObject("toRef"));

    String selfUrl = null;

    if (json.has("links")) {
        selfUrl = linkParser().apply(json.getAsJsonObject("links").get("self").getAsJsonArray().get(0))
                .getHref();
    }

    return new PullRequest(json.get("id").getAsLong(), json.get("version").getAsLong(),
            json.get("title").getAsString(), optionalJsonString(json, "description"),
            PullRequestState.valueOf(json.get("state").getAsString()), json.get("open").getAsBoolean(),
            json.get("closed").getAsBoolean(), new Date(json.get("createdDate").getAsLong()),
            new Date(json.get("updatedDate").getAsLong()), from, to, optionalJsonBoolean(json, "locked"),
            author, reviewers, participants, selfUrl);

}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.RepositoryParser.java

License:Apache License

@Override
public Repository apply(JsonElement jsonElement) {
    if (jsonElement == null || !jsonElement.isJsonObject()) {
        return null;
    }/*from   w  w  w  . ja v a2 s . c  o m*/

    JsonObject json = jsonElement.getAsJsonObject();

    String sshCloneUrl = null;
    String httpCloneUrl = null;
    String selfUrl = null;

    if (json.has("links")) {
        JsonObject links = json.getAsJsonObject("links");
        selfUrl = linkParser("url", "text").apply(links.get("self").getAsJsonArray().get(0)).getHref();

        if (links.has("clone")) {
            JsonArray arrayCloneLinks = links.get("clone").getAsJsonArray();
            Link first = linkParser().apply(arrayCloneLinks.get(0));
            Link second = linkParser().apply(arrayCloneLinks.get(1));
            if (first.getName().equals("http")) {
                httpCloneUrl = first.getHref();
                sshCloneUrl = second.getHref();
            } else {
                sshCloneUrl = first.getHref();
                httpCloneUrl = second.getHref();
            }
        }
    }

    return new Repository(optionalJsonString(json, "hierarchyId"), json.get("id").getAsLong(),
            json.get("slug").getAsString(), json.get("name").getAsString(), optionalJsonBoolean(json, "public"),
            optionalJsonBoolean(json, "fork"), optionalJsonBoolean(json, "forkable"), sshCloneUrl, httpCloneUrl,
            selfUrl, projectParser().apply(json.getAsJsonObject("project")),
            json.has("origin") ? repositoryParser().apply(json.getAsJsonObject("origin")) : null,
            json.get("scmId").getAsString(), RepositoryState.valueOf(json.get("state").getAsString()),
            json.get("statusMessage").getAsString());

}

From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.UserSshKeyParser.java

License:Apache License

@Override
public UserSshKey apply(JsonElement jsonElement) {
    JsonObject json = jsonElement.getAsJsonObject();

    return new UserSshKey(json.get("id").getAsLong(), json.get("text").getAsString(),
            json.has(LABEL) ? json.get(LABEL).getAsString() : null);
}