Java Code Examples for com.fasterxml.jackson.databind.node.ObjectNode#objectNode()

The following examples show how to use com.fasterxml.jackson.databind.node.ObjectNode#objectNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONHelper.java    From ethereumj with MIT License 6 votes vote down vote up
public static void dumpState(ObjectNode statesNode, String address, AccountState state, ContractDetails details) {  	

        List<DataWord> storageKeys = new ArrayList<>(details.getStorage().keySet());
		Collections.sort((List<DataWord>) storageKeys);

        ObjectNode account = statesNode.objectNode();
        ObjectNode storage = statesNode.objectNode();
                
        for (DataWord key : storageKeys) {
        	storage.put("0x" + Hex.toHexString(key.getData()),
					"0x" + Hex.toHexString(details.getStorage().get(key).getNoLeadZeroesData()));
        }
        account.put("balance", state.getBalance() == null ? "0" : state.getBalance().toString());
//        account.put("codeHash", details.getCodeHash() == null ? "0x" : "0x" + Hex.toHexString(details.getCodeHash()));
        account.put("code", details.getCode() == null ? "0x" : "0x" + Hex.toHexString(details.getCode()));
        account.put("nonce", state.getNonce() == null ? "0" : state.getNonce().toString());
        account.put("storage", storage);
        account.put("storage_root", state.getStateRoot() == null ? "" : Hex.toHexString(state.getStateRoot()));
        
        statesNode.put(address, account);
    }
 
Example 2
Source File: HttpOperatorFactory.java    From digdag with Apache License 2.0 6 votes vote down vote up
private static JsonNode resolveSecrets(JsonNode node, SecretProvider secrets)
{
    if (node.isObject()) {
        ObjectNode object = (ObjectNode) node;
        ObjectNode newObject = object.objectNode();
        object.fields().forEachRemaining(entry -> newObject.set(
                UserSecretTemplate.of(entry.getKey()).format(secrets),
                resolveSecrets(entry.getValue(), secrets)));
        return newObject;
    }
    else if (node.isArray()) {
        ArrayNode array = (ArrayNode) node;
        ArrayNode newArray = array.arrayNode();
        array.elements().forEachRemaining(element -> newArray.add(resolveSecrets(element, secrets)));
        return newArray;
    }
    else if (node.isTextual()) {
        return new TextNode(UserSecretTemplate.of(node.textValue()).format(secrets));
    }
    else {
        return node;
    }
}
 
Example 3
Source File: JsonExport.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
public ObjectNode toJson(WorkflowBundle wfBundle) {
        
        ObjectNode root = mapper.createObjectNode();
        ArrayNode contextList = root.arrayNode();
        root.put("@context", contextList);
        ObjectNode context = root.objectNode();
        contextList.add("https://w3id.org/scufl2/context");
        contextList.add(context);
        URI base = wfBundle.getGlobalBaseURI();
        context.put("@base", base.toASCIIString());
        root.put("id", base.toASCIIString());
       
//        root.put("name", wfBundle.getName());
//        root.put("revisions", toJson(wfBundle.getCurrentRevision()));
        
        root.put("workflow", toJson(wfBundle.getMainWorkflow()));
        root.put("profile", toJson(wfBundle.getMainProfile()));
        
        return root;
    }
 
Example 4
Source File: ToJson.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
public ObjectNode toJson(WorkflowBundle wfBundle) {

		ObjectNode root = mapper.createObjectNode();
		ArrayNode contextList = root.arrayNode();
		root.put("@context", contextList);
		ObjectNode context = root.objectNode();
		contextList.add("https://w3id.org/scufl2/context");
		contextList.add(context);
		URI base = wfBundle.getGlobalBaseURI();
		context.put("@base", base.toASCIIString());
		root.put("id", base.toASCIIString());

		// root.put("name", wfBundle.getName());
		// root.put("revisions", toJson(wfBundle.getCurrentRevision()));

		root.put("workflow", toJson(wfBundle.getMainWorkflow()));
		root.put("profile", toJson(wfBundle.getMainProfile()));

		return root;
	}
 
Example 5
Source File: AbstractTemplateStepHandlerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private static String createSpec(Collection<Symbol> symbols) throws JsonProcessingException {
    final ObjectNode schema = JsonNodeFactory.instance.objectNode();
    schema.put("$schema", "http://json-schema.org/schema#");
    schema.put("type", "object");
    schema.put("title", "Template JSON Schema");

    ObjectNode properties = schema.objectNode();
    for (Symbol symbol : symbols) {
        ObjectNode property = schema.objectNode();
        property.put("type", symbol.type);
        properties.set(symbol.id, property);
    }
    schema.set("properties", properties);
    String inSpec = MAPPER.writeValueAsString(schema);
    return inSpec;
}
 
Example 6
Source File: SpreadsheetActivityParser.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
private void makeRange(SpreadsheetRange range, ObjectNode rangeJson) {
	rangeJson.put("start", range.getStart().longValue());
       rangeJson.put("end", range.getEnd().longValue());
       
       ArrayNode excludes = rangeJson.arrayNode();
	for (SpreadsheetRange excludesRange : range.getExcludes().getExclude()) {
		ObjectNode exclude = rangeJson.objectNode();
		makeRange(excludesRange, exclude);
	    excludes.add(exclude);
	}
	if (excludes.size() > 0)
	    rangeJson.put("excludes", excludes);
}
 
Example 7
Source File: JSONHelper.java    From ethereumj with MIT License 5 votes vote down vote up
public static void dumpBlock(ObjectNode blockNode, Block block,
			long gasUsed, byte[] state, List<ByteArrayWrapper> keys,
			Repository repository) {
    	
    	blockNode.put("coinbase", Hex.toHexString(block.getCoinbase()));
    	blockNode.put("difficulty", new BigInteger(1, block.calcDifficulty()).toString());
    	blockNode.put("extra_data", "0x");
    	blockNode.put("gas_limit", String.valueOf(block.calcGasLimit()));
    	blockNode.put("gas_used", String.valueOf(gasUsed));
    	blockNode.put("min_gas_price", String.valueOf(block.getMinGasPrice()));
    	blockNode.put("nonce", "0x" + Hex.toHexString(block.getNonce()));
    	blockNode.put("number", String.valueOf(block.getNumber()));
    	blockNode.put("prevhash", "0x" + Hex.toHexString(block.getParentHash()));
        
        ObjectNode statesNode = blockNode.objectNode();
        for (ByteArrayWrapper key : keys) {
            byte[] keyBytes = key.getData();
            AccountState    accountState    = repository.getAccountState(keyBytes);
            ContractDetails details  = repository.getContractDetails(keyBytes);
            JSONHelper.dumpState(statesNode, Hex.toHexString(keyBytes), accountState, details);
        }       
        blockNode.put("state", statesNode);
        
        blockNode.put("state_root", Hex.toHexString(state));
        blockNode.put("timestamp", String.valueOf(block.getTimestamp()));
        
        ArrayNode transactionsNode = blockNode.arrayNode();
        blockNode.put("transactions", transactionsNode);
        
        blockNode.put("tx_list_root", ByteUtil.toHexString(block.getTxTrieRoot()));
        blockNode.put("uncles_hash", "0x" + Hex.toHexString(block.getUnclesHash()));
        
//		JSONHelper.dumpTransactions(blockNode,
//				stateRoot, codeHash, code, storage);
    }
 
Example 8
Source File: ConfigEvalEngine.java    From digdag with Apache License 2.0 5 votes vote down vote up
private ObjectNode evalObjectRecursive(ObjectNode local)
    throws TemplateException
{
    ObjectNode built = local.objectNode();
    for (Map.Entry<String, JsonNode> pair : ImmutableList.copyOf(local.fields())) {
        JsonNode value = pair.getValue();
        JsonNode evaluated;
        if (noEvaluatedKeys.contains(pair.getKey())) {
            // don't evaluate _do parameters
            evaluated = value;
        }
        else if (value.isObject()) {
            evaluated = evalObjectRecursive((ObjectNode) value);
        }
        else if (value.isArray()) {
            evaluated = evalArrayRecursive(built, (ArrayNode) value);
        }
        else if (value.isTextual()) {
            // eval using template engine
            String code = value.textValue();
            evaluated = evalValue(built, code);
        }
        else {
            evaluated = value;
        }
        built.set(pair.getKey(), evaluated);
    }
    return built;
}
 
Example 9
Source File: Secrets.java    From digdag with Apache License 2.0 5 votes vote down vote up
public static ObjectNode resolveSecrets(ObjectNode node, SecretProvider secrets)
{
    ObjectNode newNode = node.objectNode();
    node.fields().forEachRemaining(entry -> newNode.set(
            UserSecretTemplate.of(entry.getKey()).format(secrets),
            resolveSecrets(entry.getValue(), secrets)));
    return newNode;
}
 
Example 10
Source File: AbstractActivityParser.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
protected ObjectNode parseAndAddOutputPortDefinition(
			ActivityPortDefinitionBean portBean, Configuration configuration,
			Activity activity) {
		ObjectNode configResource = (ObjectNode) configuration.getJson();
		OutputActivityPort outputPort = new OutputActivityPort();

		outputPort.setName(getPortElement(portBean, "name", String.class));
		outputPort.setParent(activity);

		BigInteger depth = getPortElement(portBean, "depth", BigInteger.class);
		if (depth != null)
			outputPort.setDepth(depth.intValue());
		
		BigInteger granularDepth = getPortElement(portBean, "granularDepth",
				BigInteger.class);
		if (granularDepth != null)
			outputPort.setGranularDepth(granularDepth.intValue());
		
		ObjectNode portConfig = configResource.objectNode();
//		PropertyResource portConfig = configResource.addPropertyAsNewResource(
//				Scufl2Tools.PORT_DEFINITION.resolve("#outputPortDefinition"),
//				Scufl2Tools.PORT_DEFINITION.resolve("#OutputPortDefinition"));

		@SuppressWarnings("unused")
		URI portUri = new URITools().relativeUriForBean(outputPort, configuration);
//		portConfig.addPropertyReference(Scufl2Tools.PORT_DEFINITION.resolve("#definesOutputPort"), portUri);

	      // Legacy duplication of port details for XMLSplitter activities
        portConfig.put("name", outputPort.getName());
        portConfig.put("depth", outputPort.getDepth());
        portConfig.put("granularDepth", outputPort.getDepth());
		
		parseMimeTypes(portBean, portConfig);
		return portConfig;
	}
 
Example 11
Source File: GetCapabilitiesResponseEncoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
private void encodeScalarCapabilities(ObjectNode jfc, FilterCapabilities fc) {
    ObjectNode sfc = jfc.objectNode();
    // FIXME scalar filter capabilities

    if (sfc.size() > 0) {
        jfc.set(JSONConstants.SCALAR, sfc);
    }
}
 
Example 12
Source File: BeanSerializerBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
    throws JsonMappingException
{
    ObjectNode o = createSchemaNode("object", true);
    // [JACKSON-813]: Add optional JSON Schema id attribute, if found
    // NOTE: not optimal, does NOT go through AnnotationIntrospector etc:
    JsonSerializableSchema ann = _handledType.getAnnotation(JsonSerializableSchema.class);
    if (ann != null) {
        String id = ann.id();
        if (id != null && id.length() > 0) {
            o.put("id", id);
        }
    }
 
    //todo: should the classname go in the title?
    //o.put("title", _className);
    ObjectNode propertiesNode = o.objectNode();
    final PropertyFilter filter;
    if (_propertyFilterId != null) {
        filter = findPropertyFilter(provider, _propertyFilterId, null);
    } else {
        filter = null;
    }
    		
    for (int i = 0; i < _props.length; i++) {
        BeanPropertyWriter prop = _props[i];
        if (filter == null) {
            prop.depositSchemaProperty(propertiesNode, provider);
        } else {
            filter.depositSchemaProperty(prop, propertiesNode, provider);
        }

    }
    o.set("properties", propertiesNode);
    return o;
}
 
Example 13
Source File: ServiceNowMetadataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private static SyndesisMetadata adaptTableDefinitionMetadata(String actionId, Map<String, Object> properties, MetaDataExtension.MetaData metadata) {
    try {
        final Object table = ConnectorOptions.extractOption(properties, "table");
        final ObjectNode schema = (ObjectNode) metadata.getPayload();

        DataShape.Builder shapeBuilder = new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA)
            .type("servicenow." + table)
            .name("ServiceNow Import Set (" + table + ")");

        if (ObjectHelper.equal("io.syndesis:servicenow-action-retrieve-record", actionId)) {
            ObjectNode collectionSchema = schema.objectNode();
            collectionSchema.put("$schema", "http://json-schema.org/schema#");
            collectionSchema.put("type", "array");
            collectionSchema.set("items", schema);

            shapeBuilder.specification(JsonUtils.writer().writeValueAsString(collectionSchema));
            return SyndesisMetadata.outOnly(shapeBuilder.build());
        }
        if (ObjectHelper.equal("io.syndesis:servicenow-action-create-record", actionId)) {
            shapeBuilder.specification(JsonUtils.writer().writeValueAsString(schema));
            return SyndesisMetadata.inOnly(shapeBuilder.build());
        }
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }

    return SyndesisMetadata.EMPTY;
}
 
Example 14
Source File: SpreadsheetActivityParser.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
		ParserState parserState) throws ReaderException {
	SpreadsheetImportConfig config = unmarshallConfig(t2FlowParser, configBean, "xstream",
			SpreadsheetImportConfig.class);

	Configuration configuration = new Configuration();
	configuration.setParent(parserState.getCurrentProfile());

	ObjectNode json = (ObjectNode) configuration.getJson();
	configuration.setType(ACTIVITY_URI.resolve("#Config"));

	ObjectNode columnRange = json.objectNode();
	json.put("columnRange", columnRange);
	makeRange(config.getColumnRange(), columnRange);

	ObjectNode rowRange = json.objectNode();
       json.put("rowRange", rowRange);
       makeRange(config.getRowRange(), rowRange);

	if (config.getEmptyCellValue() != null)
	    json.put("emptyCellValue", config.getEmptyCellValue());
	
	ArrayNode columnNames = json.arrayNode();
       if (config.getColumnNames() != null && config.getColumnNames().getEntry() != null) {
   		for (SpreadsheetColumnNameEntry entry : config.getColumnNames().getEntry()) {
   		    ObjectNode mapping = json.objectNode();
   		    columnNames.add(mapping);
               mapping.put("column", entry.getString().get(0));
               mapping.put("port", entry.getString().get(1));
   		}
   		if (columnNames.size() > 0)
   		    json.put("columnNames", columnNames);
       }
	
	json.put("allRows", config.isAllRows());
	json.put("excludeFirstRow", config.isExcludeFirstRow());
	json.put("ignoreBlankRows", config.isIgnoreBlankRows());
	if (config.getEmptyCellPolicy() != null)
		json.put("emptyCellPolicy", config.getEmptyCellPolicy().value());
	if (config.getOutputFormat() != null)
		json.put("outputFormat", config.getOutputFormat().value());
	if (config.getCsvDelimiter() != null)
		json.put("csvDelimiter", config.getCsvDelimiter());

	return configuration;
}
 
Example 15
Source File: T2FlowParser.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
protected void parseDispatchStack(DispatchLayer dispatchLayer)
		throws ReaderException {
	URI typeUri = mapTypeFromRaven(dispatchLayer.getRaven(),
			dispatchLayer.getClazz());
	ObjectNode procConfig = parserState.get().getCurrentConfiguration().getJsonAsObjectNode();
	
	try {
		Configuration dispatchConfig = parseConfiguration(dispatchLayer.getConfigBean());
		URI relUri = INTERNAL_DISPATCH_PREFIX.relativize(typeUri);
		String name;
		if (!relUri.isAbsolute()) {
			/*
			 * It's an internal layer. We'll put it under the name which
			 * we'll cleverly fish out of the URI path, eg. "retry" or
			 * "parallelize"
			 */
               name = relUri.getPath().toLowerCase();
		    if (dispatchConfig != null && dispatchConfig.getJson().size() > 0)
		        // But only if non-empty (non-default)
		        procConfig.put(name, dispatchConfig.getJson());
		} else {
		    ObjectNode json;
		    if (dispatchConfig != null && dispatchConfig.getJson().isObject())
		        json = dispatchConfig.getJsonAsObjectNode();
		    else {
				/*
				 * We'll still need to create an objectNode to keep _type
				 * and _below
				 */
		        json = procConfig.objectNode();
		        if (dispatchConfig != null)
		            // We'll put the non-objectnode here
		            json.put("_config", dispatchConfig.getJson());
		    }
		    
			/*
			 * Not really much to go from here, we don't want to use the
			 * typeUri as the name as third-party layers in theory could be
			 * added several times for same type
			 */
		    name = randomUUID().toString();
			json.put("_type", typeUri.toString());
			// Might be null - meaning "top"
			json.put("_below", parserState.get()
					.getPreviousDispatchLayerName());
			procConfig.put(name, json);
		}
		parserState.get().setPreviousDispatchLayerName(name);			
	} catch (JAXBException ex) {
		String message = "Can't parse configuration for dispatch layer in "
				+ parserState.get().getCurrentProcessor();
		if (isStrict())
			throw new ReaderException(message, ex);
		logger.log(WARNING, message, ex);
	}
}
 
Example 16
Source File: AbstractActivityParser.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
protected ObjectNode parseAndAddInputPortDefinition(
			ActivityPortDefinitionBean portBean, Configuration configuration,
			Activity activity) {
		ObjectNode configResource = (ObjectNode) configuration.getJson();
		ObjectNode portConfig = configResource.objectNode();

		InputActivityPort inputPort = new InputActivityPort();
		inputPort.setName(getPortElement(portBean, "name", String.class));
		inputPort.setParent(activity);

		BigInteger depth = getPortElement(portBean, "depth", BigInteger.class);
		if (depth != null)
			inputPort.setDepth(depth.intValue());
		
//		PropertyResource portConfig = configResource.addPropertyAsNewResource(
//				Scufl2Tools.PORT_DEFINITION.resolve("#inputPortDefinition"),
//				Scufl2Tools.PORT_DEFINITION.resolve("#InputPortDefinition"));

		@SuppressWarnings("unused")
		URI portUri = new URITools().relativeUriForBean(inputPort, configuration);
//		portConfig.addPropertyReference(Scufl2Tools.PORT_DEFINITION.resolve("#definesInputPort"), portUri);

		parseMimeTypes(portBean, portConfig);
		
		String translated = getPortElement(portBean, "translatedElementType", String.class);
		if (translated != null) {
			// As "translated element type" is confusing, we'll instead use "dataType"
//			portConfig.addPropertyReference(Scufl2Tools.PORT_DEFINITION.resolve("#dataType"),
//					URI.create("java:" + translated));
			portConfig.put("dataType", "java:" + translated);

			// TODO: Include mapping to XSD types like xsd:string
		}
		// T2-1681: Ignoring isAllowsLiteralValues and handledReferenceScheme

		// Legacy duplication of port details for XMLSplitter activities
		portConfig.put("name", inputPort.getName());
		portConfig.put("depth", inputPort.getDepth());

		return portConfig;
	}
 
Example 17
Source File: XPathActivityParser.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser,
		ConfigBean configBean, ParserState parserState)
		throws ReaderException {

	XPathConfig xpathConfig = unmarshallConfig(t2FlowParser, configBean,
			"xstream", XPathConfig.class);

	Configuration configuration = new Configuration();
	configuration.setParent(parserState.getCurrentProfile());
	parserState.setCurrentConfiguration(configuration);

	try {
	    
	    ObjectNode json = (ObjectNode)configuration.getJson();
	    configuration.setType(ACTIVITY_URI.resolve("#Config"));

		String xmlDocument = xpathConfig.getXmlDocument();
		if (xmlDocument != null) {
		    json.put("exampleXmlDocument", xmlDocument);
		}

		String xpathExpression = xpathConfig.getXpathExpression();
		json.put("xpathExpression", xpathExpression);

		
		ArrayNode namespaceMap = json.arrayNode();
		json.put("xpathNamespaceMap", namespaceMap);

		// TODO look at why the schema translation here is so wrong
		for (Entry list : xpathConfig.getXpathNamespaceMap().getEntry()) {
			String namespacePrefix = list.getContent().get(0).getValue();
			String namespaceURI = list.getContent().get(1).getValue();

			ObjectNode map = json.objectNode();
			map.put("prefix", namespacePrefix);
			map.put("uri", namespaceURI);
			namespaceMap.add(map);
		}
	} finally {
		parserState.setCurrentConfiguration(null);
	}
	return configuration;
}
 
Example 18
Source File: ExternalToolActivityParser.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
@Override
	public Configuration parseConfiguration(T2FlowParser t2FlowParser,
			ConfigBean configBean, ParserState parserState)
			throws ReaderException {
		ExternalToolConfig externalToolConfig = null;
		UsecaseConfig usecaseConfig = null;

		try {
			externalToolConfig = unmarshallConfig(t2FlowParser, configBean,
					"xstream", ExternalToolConfig.class);
		} catch (ReaderException ex) {
			usecaseConfig = unmarshallConfig(t2FlowParser, configBean,
					"xstream", UsecaseConfig.class);
		}

		Configuration configuration = new Configuration();
		configuration.setParent(parserState.getCurrentProfile());
		parserState.setCurrentConfiguration(configuration);
		try {
			ObjectNode json = configuration.getJsonAsObjectNode();

			configuration.setType(ACTIVITY_URI.resolve("#Config"));

			if (usecaseConfig != null) {
				if (usecaseConfig.getRepositoryUrl() != null)
					json.put("repositoryUrl", usecaseConfig.getRepositoryUrl());
				json.put("toolId", usecaseConfig.getUsecaseid());
			} else if (externalToolConfig != null) {
				if (externalToolConfig.getRepositoryUrl() != null)
					json.put("repositoryUrl",
							externalToolConfig.getRepositoryUrl());
				json.put("toolId", externalToolConfig.getExternaltoolid());
				if (externalToolConfig.isEdited())
					json.put("edited", externalToolConfig.isEdited());
			}

			if (externalToolConfig != null) {
				Group group = externalToolConfig.getGroup();
				if (group != null) {
					ObjectNode invocationGroup = json.objectNode();
					json.put("invocationGroup", invocationGroup);
					invocationGroup.put("name", group.getInvocationGroupName());
					invocationGroup.put("mechanismType",
							group.getMechanismType());
					invocationGroup.put("mechanismName",
							group.getMechanismName());
					invocationGroup
							.put("mechanismXML", group.getMechanismXML());
				} else {
					json.put("mechanismType",
							externalToolConfig.getMechanismType());
					json.put("mechanismName",
							externalToolConfig.getMechanismName());
					json.put("mechanismXML",
							externalToolConfig.getMechanismXML());
				}
//				URI mechanismTypeURI = ACTIVITY_URI.resolve("#"
//						+ uriTools.validFilename(mechanismType));
//				if (mappedMechanismTypes.containsKey(mechanismTypeURI)) {
//					mechanismTypeURI = mappedMechanismTypes.get(mechanismTypeURI);
//				}
//				invocation.addPropertyReference(ACTIVITY_URI.resolve("#mechanismType"),
//						mechanismTypeURI);
//
//				invocation.addPropertyAsString(ACTIVITY_URI.resolve("#mechanismName"),
//						mechanismName);
//				invocation.addProperty(ACTIVITY_URI.resolve("#mechanismXML"), new PropertyLiteral(
//						mechanismXML, PropertyLiteral.XML_LITERAL));
                
                // TODO: Extract SSH hostname etc. from mechanismXML
//				parseMechanismXML(json);

				ObjectNode toolDescription = json.objectNode();
				parseToolDescription(toolDescription,
						externalToolConfig.getUseCaseDescription(), parserState);
				json.put("toolDescription", toolDescription);

//				configResource.addProperty(ACTIVITY_URI.resolve("#invocationGroup"),
//						parseGroup(externalToolConfig.getGroup()));

			}

			return configuration;
		} finally {
			parserState.setCurrentConfiguration(null);
		}
	}
 
Example 19
Source File: YamlConfigLoader.java    From digdag with Apache License 2.0 4 votes vote down vote up
private ObjectNode evalObjectRecursive(ObjectNode object)
    throws IOException
{
    ObjectNode built = object.objectNode();
    for (Map.Entry<String, JsonNode> pair : ImmutableList.copyOf(object.fields())) {
        JsonNode value = pair.getValue();
        if (value.isObject()) {
            built.set(pair.getKey(), evalObjectRecursive((ObjectNode) value));
        }
        else if (value.isArray()) {
            built.set(pair.getKey(), evalArrayRecursive((ArrayNode) value));
        }
        else if (pair.getKey().startsWith("!include:")) {
            // !include tag is converted to !include:<UUID> by YamlParameterizedConstructor.
            // So, here actually includes the file and merges it to the parent object
            String name;
            if (value.isTextual()) {
                name = value.textValue();
            }
            else {
                name = value.toString();
            }
            ObjectNode included = include(name);
            for (Map.Entry<String, JsonNode> merging : ImmutableList.copyOf(included.fields())) {
                JsonNode dest = built.get(merging.getKey());
                if (dest != null && dest.isObject() && merging.getValue().isObject()) {
                    mergeObject((ObjectNode) dest, (ObjectNode) merging.getValue());
                }
                else {
                    built.set(merging.getKey(), merging.getValue());
                }
            }
        }
        else if (value.isTextual() && value.textValue().startsWith("!include:")) {
            built.set(pair.getKey(), include(value.textValue()));
        }
        else {
            built.set(pair.getKey(), value);
        }
    }
    return built;
}