How to write decoder from date to date in smooks java to java - smooks

I am preparing Java object from json using ObjectMapper. Here is the json data
"dateTimeSent" : "LongValue"
Source and target both java classes have field is java.util.Date type.
I tried mapping of like this
<jb:value property="dtSent" data="dateTimeSent" decoder="Date">
<jb:decodeParam name="format">EEE MMM dd HH:mm:ss z yyyy</jb:decodeParam>
</jb:value>
In documentation it is mentioned that this decoder used to encode/decode from String to java.util.Date. Is that i need to write custom decoder for that. If yes please let me know how to write. I am new to smooks.

As smooks encode/decode from String to java.util.Date/java.sql.Date/ java.util.Calendar/java.sql.Time/java.sql.Timestamp. My use case, i have to decode from date to date. So i had created one more variable in source class with setter and getter like - private String modeifiedDateTimeSent
I am mapping with modifiedDateTimeSent variable in smooks-config.xml
<jb:value property="dtSent" data="modeifiedDateTimeSent" decoder="Date">
<jb:decodeParam name="format">yyyy-MM-dd HH:mm:ss</jb:decodeParam>
</jb:value>
Next, I have to set the value in the variable before mapping java class A to Class B.
Date modifiedDtTimeSent = order.getLr().getAdminSection().getDateTimeSent();
String modifiedDtTimeSentString = getDateAsString(modifiedDtTimeSent,"yyyy-MM-dd HH:mm:ss");
object.setModifieddatetimesent(modifiedDtTimeSentString);
Then finally, do your smooks java to java convertion -
Smooks smooks = new Smooks("smooks-config.xml");
ExecutionContext executionContext = smooks.createExecutionContext();
JavaSource source = new JavaSource(object);
JavaResult result = new JavaResult();
smooks.filterSource(executionContext, source, result);
ConvertedClass cc = (IimLocalResponse) result.getBean("xyz");
Hope this will help.

Related

Cucumber 5 - How to parse data table with headers using default jackson transformer

I have cucumber data tables with headers, and I am wondering how to parse them with Jackson when they have headers. I have the following configuration. This seems to work as long as everything is a String. But if my object contains for instance a Double, then when it tries to parse the header for that column it will choke on the column name. How can I tell it to skip the header?
private final ObjectMapper csvMapper = new CsvMapper()//
.registerModule(new JavaTimeModule())//
.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)//
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)//
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
#DefaultParameterTransformer
#DefaultDataTableEntryTransformer
#DefaultDataTableCellTransformer
public Object defaultTransformer(Object fromValue, Type toValueType) {
JavaType javaType = csvMapper.constructType(toValueType);
return csvMapper.convertValue(fromValue, javaType);
}

Cannot serialize a string object with Microsoft.Bond

I am using Microsoft.Bond to serialize a class object which works perfectly fine. However, when I try to serialize a simple System.String object, the CompactBinaryWriter writes almost nothing to the output buffer. I am using this code:
string v = "test data";
var outputBuffer = new OutputBuffer();
var writer = new CompactBinaryWriter<OutputBuffer>(outputBuffer);
Serialize.To(writer, v);
var output = outputBuffer.Data;
output in this case is a one element array : {0}, irrespective of the value of v. Can someone point out why this doesn't work?
Bond requires a top-level Bond struct to perform serialization/deserialization.
If only one value needs to be passed/returned, the type bond.Box<T> can be used to quickly wrap a value in a Bond struct. (There's nothing special about bond.Box<T>, except that it ships with Bond.)
Try this:
Serialize.To(writer, Bond.Box.Create(v));
You'll need to deserialize into a bond.Box<string>.
There's an open issue about having better behavior in cases like this.

TIBCO BW6 custom function with dateTime return type

I'm building a custom function for BW6 that should parse ISO 8601 formatted string to a dateTime object.
So far I have built this function:
#XPathFunction(helpText = "Parse a ISO 8601 datetime string",
parameters = {
#XPathFunctionParameter(name = "isoDateTimeString", optional = false)
},
returnType = "dateTime")
public Date parseIsoDateTime(String isoDateTimeString) throws ParseException {
StringBuilder dateFormatBuilder = new StringBuilder();
dateFormatBuilder.append("yyyy-MM-dd'T'HH:mm:ss");
if (isoDateTimeString.contains(".")) {
dateFormatBuilder.append(".SSS");
}
DateFormat dateFormat = new SimpleDateFormat(dateFormatBuilder.toString());
return dateFormat.parse(isoDateTimeString);
}
When I run this function an exception is thrown by BW
09:02:42.412 ERROR [bwEngThread:In-Memory Process Worker-1] com.tibco.bw.core - TIBCO-BW-CORE-500050: The BW process [demo.parse-datetime.module.Process] instance faulted, JobId [bw0a100], ProcessInstanceId [bw0a100], ParentProcessInstanceId [-], Module [demo.parse-datetime.module:1.0.0.qualifier], Application [demo.parse-datetime:1.0].
<CausedBy> TIBCO-BW-CORE-500058: Activity [SetDateTimeValue] XML related error.
<CausedBy> com.tibco.pvm.dataexch.xml.util.exceptions.PmxException: PVM-XML-106017: Expression Evaluation Error: 'bxcom:parseIsoDateTime($dateTimeAsString)'
<CausedBy> java.lang.ClassCastException: java.util.Date cannot be cast to com.tibco.xml.data.primitive.XmlAtomicValue
So how can I return an XML dateTime object from a custom xslt function in BW6.
You need to create a Plug-in Project to allow Custom XPath Function. (You will need the ActiveMatrix BusinessWorks™ Plug-in Development Kit)
Create Custom XPath Functions
If you want to use them Design time, you'll need to export the Plugin Project and include the jar as a dependency.
Using Custom XPath Function at Design Time and Run Time

Hybris DataHub INVALID_LOCALE Exception

I have localized raw data item baseName. I want to send localized raw data item to DataHub. I read many documents, it writes send localized raw attribute value but I couldn't find the format of the localized attribute value. In the composition, it throws INVALID_LOCALE exception.
I am sending value for baseName, but how can I localized "XYZ"?
RawFragmentData rawFragmentData = new RawFragmentData();
final Map<String, String> line = new HashMap<>();
........
line.put("baseName", "XYZ");
........
rawFragmentData.setValueMap(line);
rawFragmentData.setType(type);
rawFragmentData.setDataFeedName(feedName);
rawFragmentData.setExtensionSource(Constants.DATAHUB_EXTENSION_SOURCE);
return rawFragmentData;
e.g OOTB :
DefaultPartnerContributor.Java :-
row.put(PartnerCsvColumns.COUNTRY_ISO_CODE, address.getCountry());
Same way you might have languageColumn for it, so just pass language value to it.

Is there way to pass in object into CmisExtensionElement?

I have a custom aspect, and I'm trying to update it's property through OpenCMIS with CmisExtensionElement.
Currently, I'm able to update custom properties having type String with following codes:
CmisExtensionElement extension = new CmisExtensionElementImpl(namespace, "value", null, String-value);
Question is, how will I able to update custom aspect having property with type datetime, as I'm not able to pass in other than string? (If I convert date object into a string, and pass it on, it throws an error...)
Judging by this : https://chemistry.apache.org/docs/cmis-samples/samples/properties/
You should probably use something like :
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("my:dateVar1", new GregorianCalendar());
// OR
properties.put("my:dateVar2", new Date());
// update
cmisObject.updateProperties(properties);
Here is an example of code provided by Jeff Potts that shows how to do it: https://gist.github.com/jpotts/6136702