List of usage examples for com.google.gson JsonElement getAsJsonObject
public JsonObject getAsJsonObject()
From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PathParser.java
License:Apache License
@Override public Path apply(JsonElement json) { if (json == null || !json.isJsonObject()) { return null; }//from w w w.j a va 2 s . co m JsonObject jsonObject = json.getAsJsonObject(); JsonArray array = jsonObject.getAsJsonArray("components"); String[] components = new String[array.size()]; Iterator<JsonElement> it = array.iterator(); int i = 0; while (it.hasNext()) { components[i++] = it.next().getAsString(); } return new Path(components); }
From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.PermittedOperationsParser.java
License:Apache License
@Override public PermittedOperations apply(JsonElement jsonElement) { if (jsonElement == null || !jsonElement.isJsonObject()) { return null; }//w w w.j av a 2 s . c om JsonObject json = jsonElement.getAsJsonObject(); return new PermittedOperations(json.get("editable").getAsBoolean(), json.get("deletable").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 www . 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; }/* w ww. ja v a2 s. c o m*/ 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.PullRequestBranchParser.java
License:Apache License
@Override public PullRequestBranch apply(JsonElement json) { if (json == null || !json.isJsonObject()) { return null; }//w w w. j av a2 s . co m JsonObject jsonObject = json.getAsJsonObject(); JsonObject repository = jsonObject.getAsJsonObject("repository"); JsonObject project = repository.getAsJsonObject("project"); return new PullRequestBranch(jsonObject.get("id").getAsString(), repository.get("slug").getAsString(), optionalJsonString(repository, "name"), project.get("key").getAsString()); }
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 ava 2 s.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 www .j av a2 s . c om 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.PullRequestParticipantParser.java
License:Apache License
@Override public PullRequestParticipant apply(JsonElement jsonElement) { JsonObject jsonObject = jsonElement.getAsJsonObject(); User user = userParser().apply(jsonObject.getAsJsonObject("user")); return new PullRequestParticipant(user, PullRequestRole.valueOf(jsonObject.get("role").getAsString()), jsonObject.get("approved").getAsBoolean()); }
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; }/*w w w . j a v a 2 s. co 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.RepositorySshKeyParser.java
License:Apache License
@Override public RepositorySshKey apply(JsonElement json) { JsonObject jsonObject = json.getAsJsonObject(); JsonObject repositoryObject = jsonObject.getAsJsonObject("repository"); Repository repository = Parsers.repositoryParser().apply(repositoryObject); JsonObject key = jsonObject.getAsJsonObject("key"); return new RepositorySshKey(key.get("id").getAsLong(), key.get("text").getAsString(), key.get("label").getAsString(), repository, jsonObject.get("permission").getAsString()); }