List of usage examples for com.google.gson JsonArray JsonArray
public JsonArray()
From source file:com.confighub.api.user.GetAccount.java
License:Open Source License
private void getOrganizationManagement(JsonObject json, Organization organization) { JsonArray adminsJson = new JsonArray(); if (null != organization.getAdministrators()) organization.getAdministrators().forEach(admin -> adminsJson.add(getUser(admin))); JsonArray ownersJson = new JsonArray(); if (null != organization.getOwners()) organization.getOwners().forEach(owner -> ownersJson.add(getUser(owner))); json.add("admins", adminsJson); json.add("owners", ownersJson); }
From source file:com.confighub.api.user.GetAccount.java
License:Open Source License
private void getOrganizationAccountData(JsonObject json, UserAccount loggedInUser, Account account, Store store) throws ConfigException { Organization organization = account.getOrganization(); json.addProperty("t", "o"); json.addProperty("un", organization.getAccountName()); json.addProperty("name", organization.getName()); json.addProperty("creationTs", organization.getCreateDate().getTime()); boolean adminOrOwner = false; if (organization.isAdmin(loggedInUser)) { adminOrOwner = true;//from w w w. j a va2 s.c o m json.addProperty("own", "adm"); } else if (organization.isOwner(loggedInUser)) { adminOrOwner = true; json.addProperty("own", "own"); } if (adminOrOwner) { getOrganizationManagement(json, organization); } JsonArray repos = new JsonArray(); if (null != account.getRepositories()) { for (Repository repo : account.getRepositories()) { if (adminOrOwner || repo.hasReadAccess(loggedInUser)) { JsonObject rj = getRepoJson(repo); boolean canLeave = false; if (repo.isOwner(loggedInUser)) rj.addProperty("role", "Owner"); else if (repo.isAdmin(loggedInUser)) rj.addProperty("role", "Admin"); else if (repo.isMember(loggedInUser)) { rj.addProperty("role", "Team Member"); canLeave = true; } rj.addProperty("ut", repo.getUserType(loggedInUser).name()); rj.addProperty("demo", repo.isDemo()); rj.addProperty("canLeave", canLeave); Team team = store.getTeamForMember(repo, loggedInUser); if (null != team) rj.add("team", GsonHelper.teamToJson(team)); repos.add(rj); } } } json.add("repos", repos); }
From source file:com.confighub.api.user.GetAdministeredAccounts.java
License:Open Source License
@GET @Produces("application/json") public Response get(@HeaderParam("Authorization") String token) { Store store = new Store(); try {/*from w ww .j ava 2 s . c o m*/ UserAccount user = TokenState.getUser(token, store); if (null == user) return Response.status(401).build(); JsonArray json = new JsonArray(); JsonObject i = new JsonObject(); i.addProperty("un", user.getUsername()); i.addProperty("type", "user"); json.add(i); Set<Organization> orgs = user.getOrganizations(); if (null != orgs) { for (Organization o : orgs) { i = new JsonObject(); i.addProperty("un", o.getAccountName()); i.addProperty("type", "org"); json.add(i); } } Gson gson = new Gson(); return Response.ok(gson.toJson(json), MediaType.APPLICATION_JSON).build(); } finally { store.close(); } }
From source file:com.confighub.api.user.UserSearch.java
License:Open Source License
@GET @Produces("application/json") public Response getAssignments(@QueryParam("t") String searchTerm) { Store store = new Store(); try {//from www. j av a 2s. c om JsonArray jsonUsers = new JsonArray(); searchTerm = searchTerm.contains(",") ? searchTerm.split(",")[0] : searchTerm; List<UserAccount> users = store.searchUsers(searchTerm, 10); if (null != users) { for (UserAccount user : users) { JsonObject jsonUser = new JsonObject(); jsonUser.addProperty("un", user.getUsername()); jsonUser.addProperty("name", user.getName()); jsonUsers.add(jsonUser); } } Gson gson = new Gson(); return Response.ok(gson.toJson(jsonUsers), MediaType.APPLICATION_JSON).build(); } finally { store.close(); } }
From source file:com.confighub.api.util.FileHelper.java
License:Open Source License
/** * * @param properties/*www . jav a 2 s . co m*/ * @param includeComments * @return */ public static JsonArray getJsonArray(final List<Property> properties, final boolean includeComments) { JsonArray arr = new JsonArray(); for (Property property : properties) { JsonObject p = new JsonObject(); PropertyKey key = property.getPropertyKey(); if (key.isDeprecated()) p.addProperty("deprecated", true); if (key.isEncrypted()) p.addProperty("encryption", key.getSecurityProfile().getName()); if (includeComments && !Utils.isBlank(property.getReadme())) p.addProperty("comment", Utils.jsonString(property.getReadme())); p.addProperty("key", property.getKey()); if (PropertyKey.ValueDataType.List.equals(key.getValueDataType())) { JsonArray r = new Gson().fromJson(property.getValue(), JsonArray.class); p.add("value", r); } else p.addProperty("value", property.getValue()); arr.add(p); } return arr; }
From source file:com.confighub.api.util.GsonHelper.java
License:Open Source License
public static JsonArray propertyListToGSON(Repository repository, AccessRuleWrapper accessRuleWrapper, Collection<Property> properties, SecurityProfile ep, Pair<String, String>... attributes) { JsonArray jsonArray = new JsonArray(); if (null == properties) return jsonArray; for (Property property : properties) jsonArray.add(propertyToGSON(repository, property, accessRuleWrapper, ep, null, attributes)); return jsonArray; }
From source file:com.confighub.api.util.GsonHelper.java
License:Open Source License
public static JsonObject levelAuditToGSON(CtxLevel l) { JsonObject json = levelToGSON(l);// ww w . j a v a 2s . c o m String diff = l.getDiffJson(); if (Utils.isBlank(diff)) json.add("diff", null); else json.add("diff", new Gson().fromJson(diff, JsonObject.class)); switch (l.getType()) { case Group: { JsonArray assignments = new JsonArray(); l.getMembers().forEach(c -> assignments.add(c.getName())); json.add("assignments", assignments); break; } case Member: { JsonArray assignments = new JsonArray(); l.getGroups().forEach(c -> assignments.add(c.getName())); json.add("assignments", assignments); break; } } return json; }
From source file:com.confighub.api.util.GsonHelper.java
License:Open Source License
public static JsonObject toJson(final SecurityProfile ep, String profile, Collection<PropertyKey> keys) { JsonObject jProfile = new JsonObject(); jProfile.addProperty("name", ep.getName()); if (null != ep.getCipher()) { jProfile.addProperty("cipher", ep.getCipher().getName()); jProfile.addProperty("max", ep.getCipher().getMax()); jProfile.addProperty("min", ep.getCipher().getMin()); } else//from w w w . j a v a 2 s .c o m jProfile.addProperty("cipher", "None"); JsonArray jKeys = new JsonArray(); if (null != keys) { for (PropertyKey key : keys) jKeys.add(keyToGSON(key)); jProfile.add("keys", jKeys); } return jProfile; }
From source file:com.confighub.api.util.GsonHelper.java
License:Open Source License
public static JsonArray getTeams(Set<Team> teams) { JsonArray teamsJ = new JsonArray(); if (null != teams) { for (Team team : teams) { JsonObject teamJ = new JsonObject(); teamJ.addProperty("name", team.getName()); teamJ.addProperty("description", Utils.jsonString(team.getDescription())); teamJ.addProperty("stopOnFirstMatch", team.isStopOnFirstMatch()); teamJ.addProperty("unmatchedEditable", team.isUnmatchedEditable()); teamsJ.add(teamJ);//from ww w . j a v a2s . c o m } } return teamsJ; }
From source file:com.confighub.api.util.GsonHelper.java
License:Open Source License
public static JsonArray teamMembers(Team team) { JsonArray membersJ = new JsonArray(); Set<UserAccount> members = team.getMembers(); if (null == members) return membersJ; for (UserAccount member : members) { JsonObject memberJ = new JsonObject(); memberJ.addProperty("un", member.getUsername()); memberJ.addProperty("name", member.getName()); membersJ.add(memberJ);//from w w w . j a v a 2s. c om } return membersJ; }