Adding a document to another document via java service

I am writing a java service where I create a document for output. But my structure should be: OutPut Doc is a top-level document. Inside, what I want another Doc to say is an Intermediate doc, and in this intermediate document I want Key values.

But my question is: how can I insert one document into another. I see that IDataUtil has a put method that requests the key as a string and the value can be an object.

My IDataUtil.put(idcvalueDoc, "Body", FullValue.toString()); code IDataUtil.put(idcvalueDoc, "Body", FullValue.toString());

But this Body should not be a line, it should be a document. I want to insert one Doc into another.

Please help me

Image of output doc structure

+6
source share
4 answers

To accomplish what you need, you will need to do the following:

  • Create an IDD Intermediate Document Object
  • Add key tuple values ​​to middleDoc as needed
  • Create IDDDoc Object
  • Add intermediate doc as root key value in outputDoc
  • Add outputDoc to the pipeline

The following is an example of a Java service that demonstrates this (note that the root key values ​​added to middleDoc are hardcoded here for convenience):

 public static final void exampleService(IData pipeline) throws ServiceException { IDataCursor pipelineCursor = pipeline.getCursor(); try { // create an intermediateDoc IData object IData intermediateDoc = IDataFactory.create(); // create a cursor to use to add key value tuples to the intermediateDoc IDataCursor intermediateCursor = intermediateDoc.getCursor(); // add key value tuples as required to the intermediateDoc IDataUtil.put(intermediateCursor, "key1", "value1"); IDataUtil.put(intermediateCursor, "key2", "value2"); // ... // destroy the intermediateCursor when done adding key value tuples intermediateCursor.destroy(); // create an outputDoc IData object IData outputDoc = IDataFactory.create(); // create a cursor to use to add key value tuples to the outputDoc IDataCursor outputCursor = outputDoc.getCursor(); // add the intermediateDoc to the outputDoc IDataUtil.put(outputCursor, "intermediateDoc", intermediateDoc); // destroy the outputCursor when done adding key value tuples outputCursor.destroy(); // add the outputDoc to the pipeline IDataUtil.put(pipelineCursor, "outputDoc", outputDoc); } finally { // destroy the pipelineCursor pipelineCursor.destroy(); } } 
+6
source

With wmboost-data, you can write the following:

 public static final void exampleService(IData pipeline) throws ServiceException { Document outputDoc = Documents.create(); Document intermediateDoc = outputDoc.docEntry("intermediateDoc").putNew(); intermediateDoc.entry("key1").put("value1"); intermediateDoc.entry("key2").put("value2"); Documents.wrap(pipeline).entry("outputDoc").put(outputDoc); } 

Code:

  • Creates a top-level document, outputDoc
  • Creates a middleDoc as a subdocument (an alternative is to create it yourself and attach it to the parent content)
  • Assigns input values ​​to an intermediate Doc
  • Adds outputDoc to the pipeline

Disclaimer: I am the author of wmboost data.

0
source

Input / output assumptions and design

Assuming that

  • A ValuesInput[] document is input that is the same as Values[] output.
  • The columnValue document in the Document ValuesInput[] document has a string variable called additionalString (which would be pointless if there is no variable inside / under the document)

So, in general, it would be like this:

Input / output documents

Of course, you can generate the code after designing the input / output by right-clicking with the mouse and generate the code β†’ To implement this service.

Code generation

But instead of using the generated code, I'm trying to give an example with IDataMap, which you can find in webMethods Javadoc com.softwareag.util.IDataMap . Which is very convenient to use.

IDataMap

IDataMap combines the functionality of IData , IDataCursor , IDataUtil , and IDataFactory . IDataMap implements the java.util.Map Java Collections Framework interface, providing a familiar and simple interface. IDataMap extends the map interface by adding getAs<Type> methods that convert the return value to a specific type.

And this happens as follows:

 public static final void mapDocument(IData pipeline) throws ServiceException { // pipeline input by IDataMap IDataMap pipelineMap = new IDataMap(pipeline); // extracting Values input into IData[] variable array IData[] ValuesInput = pipelineMap.getAsIDataArray("ValuesInput"); // Initiate OutDoc.Values length based on ValuesInput length IData[] Values = new IData[ValuesInput.length]; // OutDoc.Values // Iterate and copying all ValuesInputDoc into OutDoc.Values for (int i = 0; i < ValuesInput.length; i++) { Values[i] = IDataUtil.clone(ValuesInput[i]); } // OutDoc IData OutDoc = IDataFactory.create(); IDataMap outDocMap = new IDataMap(OutDoc); // OutDoc IDataMap String TableName = "TableName is Never assigned"; outDocMap.put("TableName", TableName); // OutDoc.Values outDocMap.put("Values", Values); // Wrap the OutDoc into pipeline pipelineMap.put("OutDoc", OutDoc); } 

And the result

Result

0
source

Just check if any of the following actions in the WmPublic package help:

 pub.list:appendToDocumentList 

or

 pub.document:insertDocument 
-1
source

All Articles