当前位置: 首页>>代码示例>>Java>>正文


Java ObjectNode.path方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.node.ObjectNode.path方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectNode.path方法的具体用法?Java ObjectNode.path怎么用?Java ObjectNode.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.node.ObjectNode的用法示例。


在下文中一共展示了ObjectNode.path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getServiceRuntime

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
public ObjectNode getServiceRuntime ( String hostName, String serviceName_port ) {

		if ( hostResponseMap.containsKey( hostName ) ) {

			try {
				ObjectNode hostRuntime = hostResponseMap.get( hostName );

				if ( hostRuntime.has( "error" ) ) {
					return null;
				} else {
					ObjectNode serviceNode = (ObjectNode) hostRuntime
						.path( HostKeys.services.jsonId );
					if ( serviceNode == null || !serviceNode.has( serviceName_port ) ) {
						return null;
					}
					return (ObjectNode) serviceNode.path( serviceName_port );
				}
			} catch (Exception e) {
				logger.error( "Failed reading", e );
			}
		}

		return null;
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:25,代码来源:HostStatusManager.java

示例2: updateMetricData

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
private ObjectNode updateMetricData(long nowMs, String hostName, ObjectNode testData) {
	ObjectNode data;
	data = testData.deepCopy(); // copy test data, modify it

	ObjectNode attNode = (ObjectNode) data.path( "attributes" );
	attNode.put( "hostName", hostName );
	attNode.put( "currentTimeMillis", nowMs );

	ArrayNode timeStamps = (ArrayNode) data.path( "data" ).path( "timeStamp" );
	for (int i = 0; i < timeStamps.size(); i++) {
		long offset = i * 30000; // timeStamps in reverse order LIFO. latest
									// time is first
		timeStamps.set( i, LongNode.valueOf( nowMs - offset ) );
	}
	return data;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:17,代码来源:Agent_Capacity_Tests.java

示例3: getNetworks

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
 * Returns network information stored in Neutron.
 *
 * @return List of OpenstackNetwork
 */
public Collection<OpenstackNetwork> getNetworks() {

    Invocation.Builder builder = getClientBuilder(neutronUrl + URI_NETWORKS);
    String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
            header(HEADER_AUTH_TOKEN, getToken()).get(String.class);

    log.debug("networks response:" + response);

    ObjectMapper mapper = new ObjectMapper();
    List<OpenstackNetwork> openstackNetworks = Lists.newArrayList();
    try {
        ObjectNode node = (ObjectNode) mapper.readTree(response);
        ArrayNode networkList = (ArrayNode) node.path(PATH_NETWORKS);
        OpenstackNetworkCodec networkCodec = new OpenstackNetworkCodec();
        networkList.forEach(n -> openstackNetworks.add(networkCodec.decode((ObjectNode) n, null)));
    } catch (IOException e) {
        log.warn("getNetworks()", e);
    }

    openstackNetworks.removeAll(Collections.singleton(null));
    openstackNetworks.forEach(n -> log.debug("network ID: {}", n.id()));

    return openstackNetworks;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:30,代码来源:OpenstackInterfaceManager.java

示例4: getPorts

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
 * Returns port information stored in Neutron.
 *
 * @return List of OpenstackPort
 */
public Collection<OpenstackPort> getPorts() {

    Invocation.Builder builder = getClientBuilder(neutronUrl + URI_PORTS);
    String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
            header(HEADER_AUTH_TOKEN, getToken()).get(String.class);

    ObjectMapper mapper = new ObjectMapper();
    List<OpenstackPort> openstackPorts = Lists.newArrayList();
    try {
        ObjectNode node = (ObjectNode) mapper.readTree(response);
        ArrayNode portList = (ArrayNode) node.path(PATH_PORTS);
        OpenstackPortCodec portCodec = new OpenstackPortCodec();
        portList.forEach(p -> openstackPorts.add(portCodec.decode((ObjectNode) p, null)));
    } catch (IOException e) {
        log.warn("getPorts()", e);
    }

    log.debug("port response:" + response);
    openstackPorts.forEach(n -> log.debug("port ID: {}", n.id()));

    return openstackPorts;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:28,代码来源:OpenstackInterfaceManager.java

示例5: getRouters

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
public Collection<OpenstackRouter> getRouters() {
    Invocation.Builder builder = getClientBuilder(neutronUrl + PATH_ROUTERS);
    String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
            header(HEADER_AUTH_TOKEN, getToken()).get(String.class);

    ObjectMapper mapper = new ObjectMapper();
    List<OpenstackRouter> openstackRouters = Lists.newArrayList();

    try {
        ObjectNode node = (ObjectNode) mapper.readTree(response);
        ArrayNode routerList = (ArrayNode) node.path(PATH_ROUTERS);
        OpenstackRouterCodec openstackRouterCodec = new OpenstackRouterCodec();
        routerList.forEach(r -> openstackRouters
                .add(openstackRouterCodec.decode((ObjectNode) r, null)));
    } catch (IOException e) {
        log.warn("getRouters()", e);
    }

    log.debug("router response:" + response);
    openstackRouters.forEach(r -> log.debug("router ID: {}", r.id()));

    return openstackRouters;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:OpenstackInterfaceManager.java

示例6: getSubnets

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
 * Returns Subnet information in Neutron.
 *
 * @return List of OpenstackSubnet
 */
public Collection<OpenstackSubnet> getSubnets() {
    Invocation.Builder builder = getClientBuilder(neutronUrl + URI_SUBNETS);
    String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
            header(HEADER_AUTH_TOKEN, getToken()).get(String.class);

    ObjectMapper mapper = new ObjectMapper();
    List<OpenstackSubnet> subnets = Lists.newArrayList();
    try {
        ObjectNode node = (ObjectNode) mapper.readTree(response);
        ArrayNode subnetList = (ArrayNode) node.path(PATH_SUBNETS);
        OpenstackSubnetCodec subnetCodec = new OpenstackSubnetCodec();
        subnetList.forEach(s -> subnets.add(subnetCodec.decode((ObjectNode) s, null)));
    } catch (IOException e) {
        log.warn("getSubnets()", e);
    }

    log.debug("subnets response:" + response);
    subnets.forEach(s -> log.debug("subnet ID: {}", s.id()));

    return subnets;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:OpenstackInterfaceManager.java

示例7: isValid

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
 * Indicates whether a field in the node is present and of correct value or
 * not mandatory and absent.
 *
 * @param objectNode JSON object node containing field to validate
 * @param field name of field to validate
 * @param presence specified if field is optional or mandatory
 * @param validationFunction function which can be used to verify if the
 *                           node has the correct value
 * @return true if the field is as expected
 * @throws InvalidFieldException if the field is present but not valid
 */
private boolean isValid(ObjectNode objectNode, String field, FieldPresence presence,
                        Function<JsonNode, Boolean> validationFunction) {
    JsonNode node = objectNode.path(field);
    boolean isMandatory = presence == FieldPresence.MANDATORY;
    if (isMandatory && node.isMissingNode()) {
        throw new InvalidFieldException(field, "Mandatory field not present");
    }

    if (!isMandatory && (node.isNull() || node.isMissingNode())) {
        return true;
    }

    try {
        if (validationFunction.apply(node)) {
            return true;
        } else {
            throw new InvalidFieldException(field, "Validation error");
        }
    } catch (IllegalArgumentException e) {
        throw new InvalidFieldException(field, e);
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:35,代码来源:Config.java

示例8: alertsBuilder

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
 *
 * Add errors to errorList.
 *
 * @param hostName
 * @param errorList
 * @param responseFromHostStatusJson
 */
public ObjectNode alertsBuilder ( double alertLevel, String hostName, ObjectNode responseFromHostStatusJson ) {

	ObjectNode alertMessages = jacksonMapper.createObjectNode();
	ArrayNode errorArray = alertMessages.putArray( Application.VALIDATION_ERRORS );

	if ( responseFromHostStatusJson.has( "error" ) ) {
		errorArray.add( hostName + ": " + responseFromHostStatusJson
			.path( "error" )
			.textValue() );
		// return result;
		return alertMessages;
	}

	ObjectNode hostStatsNode = (ObjectNode) responseFromHostStatusJson.path( HostKeys.hostStats.jsonId );
	if ( hostStatsNode == null ) {
		errorArray.add( hostName + ": " + "Host response missing attribute: hostStats" );
		// return result;
		return alertMessages;
	}

	alertsForHostCpu( hostStatsNode, hostName, alertLevel, errorArray, alertMessages );

	alertsForHostMemory( hostStatsNode, hostName, errorArray, alertMessages );

	alertsForHostDisk( hostStatsNode, hostName, alertLevel, errorArray, alertMessages );

	ObjectNode serviceHealthCollected = (ObjectNode) responseFromHostStatusJson.path( "services" );
	if ( serviceHealthCollected == null ) {
		errorArray.add( hostName + ": " + "Host response missing attribute: services" );
		// return result;
		return alertMessages;
	}

	alertsForServices( hostName, serviceHealthCollected, errorArray, alertLevel, alertMessages );

	return alertMessages;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:46,代码来源:HostAlertProcessor.java

示例9: updateModelWithPackageSection

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
private boolean updateModelWithPackageSection (
												ReleasePackage testRootModel,
												ObjectNode testGlobalJson,
												File packageFile ) {

	JsonNode packageDefnJson = testGlobalJson.path( PARSER_PACKAGE_DEFN );
	if ( packageDefnJson.isMissingNode() ) {
		return false;
	}
	testRootModel.setReleaseInfo(
		packageDefnJson.get( PARSER_RELEASE_PACKAGE_NAME )
			.asText(),
		packageFile.getName() );

	if ( packageDefnJson.has( "architect" ) ) {
		testRootModel.setArchitect( packageDefnJson.path( "architect" ).asText() );
	}

	if ( packageDefnJson.has( "emailNotifications" ) ) {
		testRootModel.setEmailNotifications( packageDefnJson.path( "emailNotifications" ).asText() );
	}

	if ( packageDefnJson.has( "description" ) ) {
		testRootModel.setDescription( packageDefnJson.path( "description" ).asText() );
	}

	return true;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:29,代码来源:DefinitionParser.java

示例10: handlePackageJson

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
AddOnInfoAndVersions handlePackageJson(AddOnToIndex addOnToIndex, String packageJson) throws IOException {
	AddOnInfoAndVersions info = AddOnInfoAndVersions.from(addOnToIndex);
	info.setHostedUrl(hostedUrlFor(addOnToIndex));
	ObjectNode obj = new ObjectMapper().readValue(packageJson, ObjectNode.class);
	if (StringUtils.isEmpty(info.getName())) {
		info.setName(obj.get("name").asText());
	}
	if (StringUtils.isEmpty(info.getDescription())) {
		info.setDescription(obj.get("desc").asText());
	}
	String expectedFileExtension = "." + info.getType().getFileExtension();
	for (JsonNode node : obj.path("versions")) {
		String versionString = node.asText();
		// TODO do we need to GET the version and make sure it's published?
		ArrayNode arr = restTemplateBuilder.basicAuthorization(bintrayUsername, bintrayApiKey).build()
				.getForObject(getVersionFilesUrlFor(addOnToIndex, versionString), ArrayNode.class);
		for (JsonNode fileNode : arr) {
			if (fileNode.get("name").asText().endsWith(expectedFileExtension)) {
				// found the type of file we want, so assume this is the right file.
				// TODO maybe test that it has the version number in it?
				AddOnVersion version = new AddOnVersion();
				version.setVersion(new Version(versionString));
				version.setReleaseDatetime(OffsetDateTime.parse(fileNode.get("created").asText()));
				version.setDownloadUri(downloadUriFor(addOnToIndex, fileNode.get("path").asText()));
				info.addVersion(version);
				break;
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Skipping file: " + arr.get("name").asText());
			}
		}
	}
	return info;
}
 
开发者ID:openmrs,项目名称:openmrs-contrib-addonindex,代码行数:35,代码来源:Bintray.java

示例11: decode

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
@Override
public PortPairGroup decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }

    PortPairGroup.Builder resultBuilder = new DefaultPortPairGroup.Builder();

    CoreService coreService = context.getService(CoreService.class);

    String id = nullIsIllegal(json.get(ID),
                              ID + MISSING_MEMBER_MESSAGE).asText();
    resultBuilder.setId(PortPairGroupId.of(id));

    String tenantId = nullIsIllegal(json.get(TENANT_ID),
                                    TENANT_ID + MISSING_MEMBER_MESSAGE).asText();
    resultBuilder.setTenantId(TenantId.tenantId(tenantId));

    String name = nullIsIllegal(json.get(NAME),
                                NAME + MISSING_MEMBER_MESSAGE).asText();
    resultBuilder.setName(name);

    String description = nullIsIllegal(json.get(DESCRIPTION),
                                       DESCRIPTION + MISSING_MEMBER_MESSAGE).asText();
    resultBuilder.setDescription(description);

    List<PortPairId> list = Lists.newArrayList();
    ArrayNode arrayNode = (ArrayNode) json.path(PORT_PAIRS);
    arrayNode.forEach(i -> list.add(PortPairId.of(i.asText())));
    resultBuilder.setPortPairs(list);

    return resultBuilder.build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:34,代码来源:PortPairGroupCodec.java

示例12: decode

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
@Override
public DefaultTunnel decode(ObjectNode json, CodecContext context) {

    String tid = json.path(TUNNEL_ID).asText();
    List<Integer> labels = new ArrayList<>();

    if (!json.path(LABEL_PATH).isMissingNode()) {
        ArrayNode labelArray = (ArrayNode) json.path(LABEL_PATH);
        for (JsonNode o : labelArray) {
            labels.add(o.asInt());
        }
    }

    return new DefaultTunnel(tid, labels);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:TunnelCodec.java

示例13: extractIds

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
private Set<String> extractIds(ObjectNode payload) {
    ArrayNode array = (ArrayNode) payload.path(IDS);
    if (array == null || array.size() == 0) {
        return Collections.emptySet();
    }

    Set<String> ids = new HashSet<>();
    for (JsonNode node : array) {
        ids.add(node.asText());
    }
    return ids;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:13,代码来源:NodeSelection.java

示例14: decode

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
@Override
public PcePath decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        log.error("Empty json input");
        return null;
    }

    // build pce-path
    PcePath.Builder resultBuilder = new DefaultPcePath.Builder();

    // retrieve source
    JsonNode jNode = json.get(SOURCE);
    if (jNode != null) {
        String src = jNode.asText();
        resultBuilder.source(src);
    }

    // retrieve destination
    jNode = json.get(DESTINATION);
    if (jNode != null) {
        String dst = jNode.asText();
        resultBuilder.destination(dst);
    }

    // retrieve lsp-type
    jNode = json.get(LSP_TYPE);
    if (jNode != null) {
        String lspType = jNode.asText();
        resultBuilder.lspType(lspType);
    }

    // retrieve symbolic-path-name
    jNode = json.get(SYMBOLIC_PATH_NAME);
    if (jNode != null) {
        String name = jNode.asText();
        resultBuilder.name(name);
    }

    // retrieve constraint
    JsonNode constraintJNode = (JsonNode) json.path(CONSTRAINT);
    if ((constraintJNode != null) && (!constraintJNode.isMissingNode())) {
        // retrieve cost
        jNode = constraintJNode.get(COST);
        if (jNode != null) {
            String cost = jNode.asText();
            resultBuilder.costConstraint(cost);
        }

        // retrieve bandwidth
        jNode = constraintJNode.get(BANDWIDTH);
        if (jNode != null) {
            String bandwidth = jNode.asText();
            resultBuilder.bandwidthConstraint(bandwidth);
        }
    }

    return resultBuilder.build();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:59,代码来源:PcePathCodec.java

示例15: payload

import com.fasterxml.jackson.databind.node.ObjectNode; //导入方法依赖的package包/类
/**
 * Returns the payload from the specified event.
 *
 * @param event message event
 * @return extracted payload object
 */
public static ObjectNode payload(ObjectNode event) {
    return (ObjectNode) event.path("payload");
}
 
开发者ID:shlee89,项目名称:athena,代码行数:10,代码来源:JsonUtils.java


注:本文中的com.fasterxml.jackson.databind.node.ObjectNode.path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。