List of usage examples for com.google.gson JsonObject toString
@Override
public String toString()
From source file:com.confighub.core.store.diff.AbsoluteFilePathDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalAbsFilePath o = (OriginalAbsFilePath) getIfRecorded(obj); if (null == o || !(obj instanceof AbsoluteFilePath)) return;//w w w . java 2 s . c o m JsonObject json = new JsonObject(); AbsoluteFilePath absoluteFilePath = (AbsoluteFilePath) obj; if (!Utils.equal(o.absFilePath, absoluteFilePath.getAbsPath())) json.addProperty("absPath", o.absFilePath); absoluteFilePath.diffJson = json.toString(); }
From source file:com.confighub.core.store.diff.AccessRuleDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalAccessRule o = (OriginalAccessRule) getIfRecorded(obj); if (null == o || !(obj instanceof AccessRule)) return;// w w w . j a va2 s. c o m AccessRule rule = (AccessRule) obj; JsonObject json = new JsonObject(); if (o.priority != rule.getPriority()) json.addProperty("priority", o.priority); if (!Utils.same(o.ruleTarget, rule.getRuleTarget())) json.addProperty("type", Utils.jsonString(o.ruleTarget)); if (AccessRule.RuleTarget.Key.equals(o.ruleTarget)) { if (!Utils.same(o.keyMatchType, rule.getKeyMatchType())) json.addProperty("match", Utils.jsonString(o.keyMatchType)); if (!Utils.same(o.matchValue, rule.getMatchValue())) json.addProperty("key", Utils.jsonString(o.matchValue)); } else { if (!Utils.same(o.contextMatchType, rule.getContextMatchType())) json.addProperty("match", Utils.jsonString(o.contextMatchType)); if (!Utils.same(o.contextJson, rule.getContextJsonObj().toString())) json.add("context", new Gson().fromJson(o.contextJson, JsonObject.class)); } if (!Utils.same(o.matchValue, rule.getMatchValue())) json.addProperty("key", Utils.jsonString(o.matchValue)); if (o.canEdit != rule.isCanEdit()) json.addProperty("access", o.canEdit ? "rw" : "ro"); markForNotification(); rule.diffJson = json.toString(); }
From source file:com.confighub.core.store.diff.LevelDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalLevel o = (OriginalLevel) getIfRecorded(obj); if (null == o || !(obj instanceof CtxLevel)) return;/*from w ww . j a v a 2 s .com*/ CtxLevel ctxLevel = (CtxLevel) obj; JsonObject json = new JsonObject(); if (!Utils.equal(ctxLevel.getName(), o.name)) json.addProperty("name", o.name); if (ctxLevel.getDepth() != o.depth) json.addProperty("o.depth", o.depth.getPlacement()); if (ctxLevel.getType() != o.levelType) { json.addProperty("type", o.levelType.name()); } boolean hadAssignments = null != o.assigned && o.assigned.size() > 0; boolean hasAssignments = null != ctxLevel.getMembers() && ctxLevel.getMembers().size() > 0; // did not have assignments, and still does not // ---> do nothing if (!hadAssignments && !hasAssignments) ; // had assignments, but now it does not // ---> add old assignments to JSON else if (hadAssignments && !hasAssignments) { JsonArray assignments = new JsonArray(); o.assigned.forEach(c -> assignments.add(c)); json.add("assignments", assignments); } // did not have assignments, but now it does // ---> add empty list for assignments else if (!hadAssignments && hasAssignments) { json.add("assignments", new JsonArray()); } else { Set<String> current = new HashSet<>(); ctxLevel.getMembers().forEach(k -> current.add(k.getName())); current.removeAll(o.assigned); // different assignments // ---> add old assignments to JSON if (current.size() > 0) { JsonArray assignments = new JsonArray(); o.assigned.forEach(c -> assignments.add(c)); json.add("assignments", assignments); } else { Set<String> clone = new HashSet<>(); o.assigned.forEach(ln -> clone.add(new String(ln))); current.clear(); ctxLevel.getMembers().forEach(k -> current.add(k.getName())); clone.removeAll(current); if (clone.size() > 0) { JsonArray assignments = new JsonArray(); o.assigned.forEach(c -> assignments.add(c)); json.add("assignments", assignments); } // assignments the same // ---> do nothing } } ctxLevel.diffJson = json.toString(); }
From source file:com.confighub.core.store.diff.PropertyDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalProperty o = (OriginalProperty) getIfRecorded(obj); if (null == o || !(obj instanceof Property)) return;/* ww w . java 2 s .c o m*/ Property property = (Property) obj; PropertyKey key = property.getPropertyKey(); JsonObject json = new JsonObject(); if (!Utils.equal(o.value, property.getValue())) { if (o.encrypted) json.addProperty("value", o.value); else { switch (o.valueDataType) { case Map: try { json.add("value", new Gson().fromJson(o.value, JsonObject.class)); } catch (Exception e) { json.addProperty("value", o.value); } break; case List: try { json.add("value", new Gson().fromJson(o.value, JsonArray.class)); } catch (Exception e) { json.addProperty("value", o.value); } break; default: json.addProperty("value", o.value); break; } } } if (!Utils.equal(o.contextJson, property.getContextJson())) json.add("context", new Gson().fromJson(o.contextJson, JsonArray.class)); if (o.valueDataType != key.valueDataType) json.addProperty("vdt", o.valueDataType.name()); property.diffJson = json.toString(); setSearchKey(((Property) obj).getKey()); }
From source file:com.confighub.core.store.diff.PropertyKeyDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalPropertyKey o = (OriginalPropertyKey) getIfRecorded(obj); if (null == o || !(obj instanceof PropertyKey)) return;//from www . j a va 2 s . c o m PropertyKey propertyKey = (PropertyKey) obj; JsonObject json = new JsonObject(); if (!Utils.equal(propertyKey.getKey(), o.key)) { json.addProperty("key", o.key); markForNotification(); } if (!Utils.equal(propertyKey.getReadme(), o.readme)) json.addProperty("readme", o.readme); if (propertyKey.isDeprecated() != o.deprecated) { json.addProperty("deprecated", o.deprecated); markForNotification(); } if (propertyKey.isPushValueEnabled() != o.push) { json.addProperty("pushEnabled", o.push); markForNotification(); } String spName = null == propertyKey.getSecurityProfile() ? null : propertyKey.getSecurityProfile().getName(); if (!Utils.equal(spName, o.spName)) { json.addProperty("spName", null == o.spName ? "" : o.spName); markForNotification(); } if (propertyKey.getValueDataType() != o.valueDataType) json.addProperty("vdt", null == o.valueDataType ? PropertyKey.ValueDataType.Text.name() : o.valueDataType.name()); propertyKey.diffJson = json.toString(); setSearchKey(propertyKey.getKey()); }
From source file:com.confighub.core.store.diff.RepoFileDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalRepoFile o = (OriginalRepoFile) getIfRecorded(obj); if (null == o || !(obj instanceof RepoFile)) return;//from w w w . jav a2 s. c o m RepoFile file = (RepoFile) obj; JsonObject json = new JsonObject(); if (!Utils.equal(o.content, file.getContent())) { json.addProperty("content", o.content); json.addProperty("encrypted", o.encrypted); } if (!Utils.equal(o.absPath, file.getAbsPath())) json.addProperty("absPath", o.absPath); if (!Utils.equal(o.contextJson, file.getContextJson())) json.add("context", new Gson().fromJson(o.contextJson, JsonArray.class)); if (!Utils.isBlank(o.spName)) json.addProperty("spName", o.spName); if (o.active != file.isActive()) json.addProperty("active", o.active); file.diffJson = json.toString(); }
From source file:com.confighub.core.store.diff.RepositoryDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { if (!isTracked() || !(obj instanceof Repository)) return;//from ww w. ja va 2 s . co m OriginalRepository o = (OriginalRepository) getIfRecorded(obj); if (null == o) return; JsonObject json = new JsonObject(); Repository repository = (Repository) obj; if (null == repository.getAccount()) json.addProperty("deleted", true); else if (!repository.getAccount().getName().equalsIgnoreCase(o.accountName)) json.addProperty("owner", o.accountName); if (!Utils.equal(repository.getName(), o.name)) json.addProperty("name", o.name); if (!Utils.equal(repository.getDescription(), o.description)) json.addProperty("description", o.description); if (repository.isAccessControlEnabled() != o.accessControlEnabled) json.addProperty("accessControlEnabled", o.accessControlEnabled); if (repository.isValueTypeEnabled() != o.valueTypeEnabled) json.addProperty("valueTypeEnabled", o.valueTypeEnabled); if (repository.isSecurityProfilesEnabled() != o.securityProfilesEnabled) json.addProperty("securityProfilesEnabled", o.securityProfilesEnabled); if (repository.isContextClustersEnabled() != o.contextClustersEnabled) json.addProperty("contextClustersEnabled", o.contextClustersEnabled); if (repository.isPrivate() != o.isPrivate) json.addProperty("private", o.isPrivate); if (repository.getDepth() != o.depth) { JsonObject labels = new JsonObject(); for (Depth depth : repository.getDepth().getDepths()) labels.addProperty(String.valueOf(depth.getPlacement()), o.labels.get(depth)); json.add("labels", labels); json.addProperty("depth", repository.getDepth().name()); setContextResize(); } for (Depth depth : repository.getDepth().getDepths()) { if (!Utils.equal(o.labels.get(depth), repository.getLabel(depth))) { JsonObject labels = new JsonObject(); for (Depth d : repository.getDepth().getDepths()) labels.addProperty(String.valueOf(d.getPlacement()), o.labels.get(d)); json.add("labels", labels); break; } } markForNotification(); repository.diffJson = json.toString(); }
From source file:com.confighub.core.store.diff.SecurityProfileDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalSecurityProfile o = (OriginalSecurityProfile) getIfRecorded(obj); if (null == o || !(obj instanceof SecurityProfile)) return;//from w ww . j a va 2 s. c o m SecurityProfile sp = (SecurityProfile) obj; JsonObject json = new JsonObject(); if (!Utils.equal(sp.getName(), o.name)) json.addProperty("name", o.name); if (!Utils.equal(sp.getSpPassword(), o.password)) json.addProperty("password", true); if (sp.getCipher() != o.cipher) json.addProperty("cipher", null == o.cipher ? "" : o.cipher.getName()); if (sp.encryptionEnabled() != o.encrypted) json.addProperty("encrypted", o.encrypted); markForNotification(); sp.diffJson = json.toString(); }
From source file:com.confighub.core.store.diff.TagDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalTag o = (OriginalTag) getIfRecorded(obj); if (null == o || !(obj instanceof Tag)) return;//w ww . j a v a2 s . c om Tag tag = (Tag) obj; JsonObject json = new JsonObject(); if (!Utils.equal(tag.getName(), o.name)) json.addProperty("name", o.name); if (!Utils.equal(tag.getReadme(), o.readme)) json.addProperty("readme", o.readme); if (!Utils.equal(tag.getTs(), o.ts)) json.addProperty("ts", o.ts); markForNotification(); tag.diffJson = json.toString(); }
From source file:com.confighub.core.store.diff.TeamDiffTracker.java
License:Open Source License
@PreUpdate public void preUpdate(APersisted obj) { OriginalTeam o = (OriginalTeam) getIfRecorded(obj); if (null == o || !(obj instanceof Team)) return;// ww w . j av a 2 s .c o m Team team = (Team) obj; JsonObject json = new JsonObject(); if (!Utils.equal(team.getName(), o.name)) json.addProperty("name", o.name); if (team.isStopOnFirstMatch() != o.stopOnFirstMatch) json.addProperty("stopOnFirstMatch", o.stopOnFirstMatch); if (team.isUnmatchedEditable() != o.unmatchedEditable) json.addProperty("unmatchedEditable", o.unmatchedEditable); Set<UserAccount> currentMembers = team.getMembers(); if (null == o.members || o.members.size() == 0) { if (null != currentMembers && currentMembers.size() > 0) { JsonArray added = new JsonArray(); currentMembers.forEach(m -> added.add(userToJson(m))); json.add("newMembers", added); } } else { if (null == currentMembers || currentMembers.size() == 0) { JsonArray removed = new JsonArray(); o.members.forEach(m -> removed.add(userToJson(m))); json.add("removedMembers", removed); } else { Set<UserAccount> copyOfCurrent = new HashSet<>(); currentMembers.forEach(m -> copyOfCurrent.add(m)); copyOfCurrent.removeAll(o.members); if (copyOfCurrent.size() > 0) { JsonArray added = new JsonArray(); copyOfCurrent.forEach(m -> added.add(userToJson(m))); json.add("newMembers", added); } o.members.removeAll(currentMembers); if (o.members.size() > 0) { JsonArray removed = new JsonArray(); o.members.forEach(m -> removed.add(userToJson(m))); json.add("removedMembers", removed); } } } markForNotification(); team.diffJson = json.toString(); }