List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsNodeSyncImpl.java
License:Apache License
/** * @see RemoteAssetsNodeSync#syncAssetNodes() *///from w w w.j a v a 2 s . c om @Override public void syncAssetNodes() { ResourceResolver remoteAssetsResolver = this.remoteAssetsConfig.getResourceResolver(); try { List<String> syncPaths = new ArrayList<>(); syncPaths.addAll(this.remoteAssetsConfig.getTagSyncPaths()); syncPaths.addAll(this.remoteAssetsConfig.getDamSyncPaths()); for (String syncPath : syncPaths) { LOG.info("Starting sync of nodes for {}", syncPath); remoteAssetsResolver.refresh(); JsonObject topLevelJsonWithChildren = getJsonFromUri(syncPath); String resourcePrimaryType = topLevelJsonWithChildren .getAsJsonPrimitive(JcrConstants.JCR_PRIMARYTYPE).getAsString(); Resource topLevelSyncResource = getOrCreateNode(remoteAssetsResolver, syncPath, resourcePrimaryType); createOrUpdateNodes(remoteAssetsResolver, topLevelJsonWithChildren, topLevelSyncResource); remoteAssetsResolver.commit(); LOG.info("Completed sync of nodes for {}", syncPath); } } catch (Exception e) { LOG.error("Unexpected error sync'ing remote asset nodes", e); } finally { this.remoteAssetsConfig.closeResourceResolver(remoteAssetsResolver); } }
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsNodeSyncImpl.java
License:Apache License
/** * Handler for when a JSON element is an Object, representing a resource. * * @param key String//from w w w . j a v a 2 s.c om * @param parentResource Resource * @throws IOException exception * @throws RepositoryException exception */ private void createOrUpdateNodesForJsonObject(final ResourceResolver remoteAssetsResolver, final String key, final Resource parentResource) throws IOException, RepositoryException { if (PROTECTED_NODES.contains(key)) { return; } String objectPath = String.format("%s/%s", parentResource.getPath(), key); JsonObject jsonObjectWithChildren = getJsonFromUri(objectPath); String resourcePrimaryType = jsonObjectWithChildren.getAsJsonPrimitive(JcrConstants.JCR_PRIMARYTYPE) .getAsString(); Resource resource = getOrCreateNode(remoteAssetsResolver, objectPath, resourcePrimaryType); createOrUpdateNodes(remoteAssetsResolver, jsonObjectWithChildren, resource); ValueMap resourceProperties = resource.adaptTo(ModifiableValueMap.class); if (DamConstants.NT_DAM_ASSET .equals(parentResource.getValueMap().get(JcrConstants.JCR_PRIMARYTYPE, String.class)) && DamConstants.NT_DAM_ASSETCONTENT .equals(resourceProperties.get(JcrConstants.JCR_PRIMARYTYPE, String.class))) { resourceProperties.put(RemoteAssets.IS_REMOTE_ASSET, true); LOG.trace("Property '{}' added for resource '{}'.", RemoteAssets.IS_REMOTE_ASSET, resource.getPath()); // Save and refresh the session after the save refresh count has reached the configured amount. this.saveRefreshCount++; if (this.saveRefreshCount == this.remoteAssetsConfig.getSaveInterval()) { this.saveRefreshCount = 0; remoteAssetsResolver.commit(); remoteAssetsResolver.refresh(); LOG.info("Executed incremental save of node sync."); } } }
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsNodeSyncImpl.java
License:Apache License
/** * Handler for when a JSON element represents a resource property. * * @param key String/*from w ww . ja v a 2 s. c o m*/ * @param json JsonObject * @param resource Resource * @throws RepositoryException exception */ private void setNodeProperty(final ResourceResolver remoteAssetsResolver, final String key, final JsonObject json, final Resource resource) throws RepositoryException { try { JsonElement value = json.get(key); if (":".concat(JcrConstants.JCR_DATA).equals(key)) { setNodeJcrDataProperty(remoteAssetsResolver, resource, json.getAsJsonPrimitive(JcrConstants.JCR_LASTMODIFIED).getAsString()); } else if (key.startsWith(":")) { // Skip binary properties, since they do not come across in JSON return; } else if (PROTECTED_PROPERTIES.contains(key)) { // Skipping due to the property being unmodifiable. return; } else if (resource.getValueMap().get(key) != null && resource.getValueMap().get(key, String.class).equals(value.getAsString())) { // Skipping due to the property already existing and being equal return; } else { setNodeSimpleProperty(value.getAsJsonPrimitive(), key, resource); } } catch (RepositoryException re) { LOG.warn("Repository exception thrown. Skipping '{}' single property for resource '{}'.", key, resource.getPath()); } }
From source file:com.android.tools.idea.gradle.structure.model.repositories.search.JCenterRepository.java
License:Apache License
SearchResult parse(@NotNull Reader response) { /*// www . ja v a 2 s. c o m Sample response: [ { "name": "com.atlassian.guava:guava", "repo": "jcenter", "owner": "bintray", "desc": null, "system_ids": [ "com.atlassian.guava:guava" ], "versions": [ "15.0" ], "latest_version": "15.0" }, { "name": "com.atlassian.bundles:guava", "repo": "jcenter", "owner": "bintray", "desc": null, "system_ids": [ "com.atlassian.bundles:guava" ], "versions": [ "8.1", "8.0", "1.0-actually-8.1" ], "latest_version": "8.1" }, { "name": "io.janusproject.guava:guava", "repo": "jcenter", "owner": "bintray", "desc": null, "system_ids": [ "io.janusproject.guava:guava" ], "versions": [ "19.0.0", "17.0.2", "17.0" ], "latest_version": "19.0.0" }, { "name": "com.google.guava:guava", "repo": "jcenter", "owner": "bintray", "desc": "Guava is a suite of core and expanded libraries that include\n utility classes, google's collections, io classes, and much\n much more.\n\n Guava has two code dependencies - javax.annotation\n per the JSR-305 spec and javax.inject per the JSR-330 spec.", "system_ids": [ "com.google.guava:guava" ], "versions": [ "19.0", "19.0-rc3", "19.0-rc2", "19.0-rc1", "18.0", "18.0-rc2", "18.0-rc1", "11.0.2-atlassian-02", "17.0", "17.0-rc2", "17.0-rc1", "16.0.1", "16.0", "16.0-rc1", "15.0", "15.0-rc1", "14.0.1", "14.0", "14.0-rc3", "14.0-rc2", "14.0-rc1", "13.0.1", "13.0", "13.0-final", "13.0-rc2", "13.0-rc1", "12.0.1", "12.0", "12.0-rc2", "12.0-rc1", "11.0.2-atlassian-01", "11.0.2", "11.0.1", "11.0", "11.0-rc1", "10.0.1", "10.0", "10.0-rc3", "10.0-rc2", "10.0-rc1", "r09", "r08", "r07", "r06", "r05", "r03" ], "latest_version": "19.0" } ] */ JsonParser parser = new JsonParser(); JsonArray array = parser.parse(response).getAsJsonArray(); int totalFound = array.size(); List<FoundArtifact> artifacts = Lists.newArrayListWithExpectedSize(totalFound); for (int i = 0; i < totalFound; i++) { JsonObject root = array.get(i).getAsJsonObject(); String name = root.getAsJsonPrimitive("name").getAsString(); List<GradleVersion> availableVersions = Lists.newArrayList(); JsonArray versions = root.getAsJsonArray("versions"); versions.forEach(element -> { String version = element.getAsString(); availableVersions.add(GradleVersion.parse(version)); }); List<String> coordinate = Splitter.on(GRADLE_PATH_SEPARATOR).splitToList(name); assert coordinate.size() == 2; artifacts.add(new FoundArtifact(getName(), coordinate.get(0), coordinate.get(1), availableVersions)); } return new SearchResult(getName(), artifacts, totalFound); }
From source file:com.arangodb.entity.EntityDeserializers.java
License:Apache License
private static <T extends BaseEntity> T deserializeBaseParameter(JsonObject obj, T entity) { if (obj.has("error") && obj.getAsJsonPrimitive("error").isBoolean()) { entity.error = obj.getAsJsonPrimitive("error").getAsBoolean(); }/*from ww w . j a v a 2 s . com*/ if (obj.has("code") && obj.getAsJsonPrimitive("code").isNumber()) { entity.code = obj.getAsJsonPrimitive("code").getAsInt(); } if (obj.has("errorNum") && obj.getAsJsonPrimitive("errorNum").isNumber()) { entity.errorNumber = obj.getAsJsonPrimitive("errorNum").getAsInt(); } if (obj.has("errorMessage")) { entity.errorMessage = obj.getAsJsonPrimitive("errorMessage").getAsString(); } if (obj.has("etag") && obj.getAsJsonPrimitive("errorNum").isNumber()) { entity.etag = obj.getAsJsonPrimitive("etag").getAsLong(); } return entity; }
From source file:com.arangodb.entity.EntityDeserializers.java
License:Apache License
private static <T extends DocumentHolder> T deserializeDocumentParameter(JsonObject obj, T entity) { if (obj.has("_rev")) { entity.setDocumentRevision(obj.getAsJsonPrimitive("_rev").getAsLong()); }// w ww .j a va 2 s . co m if (obj.has("_id")) { entity.setDocumentHandle(obj.getAsJsonPrimitive("_id").getAsString()); } if (obj.has("_key")) { entity.setDocumentKey(obj.getAsJsonPrimitive("_key").getAsString()); } if (true) { } return entity; }
From source file:com.bizosys.dataservice.sql.SqlSensor.java
License:Apache License
private void initializePool(Request request, Response response) { String jsonData = request.mapData.get("jsonData"); JsonObject jsonObject = new JsonParser().parse(jsonData).getAsJsonObject(); String agentIP = jsonObject.getAsJsonPrimitive("agentIP").getAsString(); String poolName = jsonObject.getAsJsonPrimitive("poolName").getAsString(); try {// w w w.j ava2s . com DbConfigUtil.setupPoolByPoolName(agentIP, poolName); response.writeTextWithNoHeaderAndFooter("OK"); } catch (Exception e) { LOG.warn("Error initializing drone user pool for ip - " + agentIP); } }
From source file:com.blackducksoftware.integration.hub.detect.detector.npm.NpmCliParser.java
License:Apache License
NpmParseResult convertNpmJsonFileToCodeLocation(final String sourcePath, final String npmLsOutput) { final JsonObject npmJson = new JsonParser().parse(npmLsOutput).getAsJsonObject(); final MutableDependencyGraph graph = new MutableMapDependencyGraph(); final JsonElement projectNameElement = npmJson.getAsJsonPrimitive(JSON_NAME); final JsonElement projectVersionElement = npmJson.getAsJsonPrimitive(JSON_VERSION); String projectName = null;//from w ww . j av a2s . c o m String projectVersion = null; if (projectNameElement != null) { projectName = projectNameElement.getAsString(); } if (projectVersionElement != null) { projectVersion = projectVersionElement.getAsString(); } populateChildren(graph, null, npmJson.getAsJsonObject(JSON_DEPENDENCIES), true); final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPM, projectName, projectVersion); final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NPM, sourcePath, externalId, graph).build(); return new NpmParseResult(projectName, projectVersion, codeLocation); }
From source file:com.blackducksoftware.integration.hub.detect.detector.npm.NpmCliParser.java
License:Apache License
private void populateChildren(final MutableDependencyGraph graph, final Dependency parentDependency, final JsonObject parentNodeChildren, final Boolean root) { if (parentNodeChildren == null) { return;/* w w w. jav a2 s .com*/ } final Set<Entry<String, JsonElement>> elements = parentNodeChildren.entrySet(); elements.forEach(it -> { if (it.getValue() != null && it.getValue().isJsonObject()) { } final JsonObject element = it.getValue().getAsJsonObject(); final String name = it.getKey(); String version = null; final JsonPrimitive versionPrimitive = element.getAsJsonPrimitive(JSON_VERSION); if (versionPrimitive != null && versionPrimitive.isString()) { version = versionPrimitive.getAsString(); } final JsonObject children = element.getAsJsonObject(JSON_DEPENDENCIES); if (name != null && version != null) { final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPM, name, version); final Dependency child = new Dependency(name, version, externalId); populateChildren(graph, child, children, false); if (root) { graph.addChildToRoot(child); } else { graph.addParentWithChild(parentDependency, child); } } }); }
From source file:com.builtbroken.builder.html.data.CategoryData.java
/** * Called to parse and build a category data object * * @param key - key the json entry was created with * @param catEntry - json entry data//w ww . ja v a 2s. c om * @return data object */ public static CategoryData parse(String key, JsonObject catEntry) { CategoryData categoryData = new CategoryData(key.toLowerCase()); categoryData.displayName = catEntry.getAsJsonPrimitive("text").getAsString(); if (catEntry.has("page")) { categoryData.pageID = catEntry.getAsJsonPrimitive("page").getAsString(); } if (catEntry.has("parent")) { categoryData.parent = catEntry.getAsJsonPrimitive("parent").getAsString(); } if (catEntry.has("index")) { categoryData.index = catEntry.getAsJsonPrimitive("index").getAsInt(); } return categoryData; }