date format configuration in dozer.xml - mapping

I am using Dozer mapper to map Service objects to Value objects. I am mapping the date by means of the following:
<mapping date-format="dd-MM-yyyy">
<class-a>MySo</class-a>
<class-b>MyVO</class-b>
<field>
<a>dateStr</a>
<b>dateObj</b>
</field>
</mapping>
However, I need to specify the format for the date each time. Is there some other approach to map string date directly?

In dozer.xml we can specify some default configuration.
for eg.
<configuration>
<stop-on-errors>true</stop-on-errors>
<date-format>dd-MM-yy</date-format>
<wildcard>true</wildcard>
</configuration>
here is Link to refer.

Related

Show Localized value for HybrisEnumValue in Hybris Backoffice

We are trying to show the localized value for a "dynamic" enum.
In our backoffice-config.xml We have something like this
<context type="CustomeType" component="base" merge-by="type">
<y:base xmlns:y="http://www.hybris.com/cockpit/config/hybris">
<y:labels>
<y:label>customProperty.hybrisEnumValueProperty.name</y:label>
</y:labels>
</y:base>
</context>
With this we receive the default TypeName(Pk) in backoffice instead of the localized name. For the code it works just fine. Also for hmc it works as well.
You need to add localization text for these enums like below.
mycoreextension-items.xml
<enumtype code="myenum" generate="true" dynamic="true">
<value code="ENUM1" />
<value code="ENUM2" />
</enumtype>
mycoreextension-locales_en.properties
type.myenum.name=My Enum Name
type.myenum.description=My enum description
type.myenum.enum1.name=My enum value 1
type.myenum.enum2.name=My enum value 1

Is the mapping in sequential order in Dozer?

I have Dozer mapping as follows
<mapping>
<class-a>Class1</class-a>
<class-b>Class2</class-b>
<field> <a>C1.field1</a> <b>C2.field1</b> </field>
<field custom-converter="converterField2"> <a>C1.field2</a> <b>C2.field2</b> </field>
<field> <a custom-converter="converterField3"> C1.field3</a> <b>C2.field3</b> </field>
<field> <a>C1.field4</a> <b>C2.field4</b> </field>
</mapping>
I have four mappings mapping file. Does the Dozer maps in order like field1 is mapped first, followed by field2 and then by field3?
Or will do map in any order?
Yes, the mapping happens in order. The field names are fetched from the files by Reflection and added to Lists. These lists are then iterated over and the values mapped one by one.
Specifically, the names are fetched here and the mapping starts here.

Scriptella - Date format conversion not working

I am having a problem in date format conversion while I am exporting data from MySQL to CSV.
I am using scriptelaa.1.1, the latest one I guess.
Here is my etl.properties file:
driver=mysql
url=jdbc:mysql://localhost:3306/<my_DB_name>
user=<user_name>
password=<password>
classpath=/path/to/mysql-connector-java-5.1.19.jar;
here is my etl.xml file:
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
<description>Scriptella ETL File Template.</description>
<properties>
<include href="/path/to/etl.properties"/> <!--Load from external properties file-->
</properties>
<!-- Connection declarations -->
<connection id="in" driver="${driver}" url="${url}" user="${user}" password="${password}" classpath="$classpath">
</connection>
<connection id="out" driver="csv" url="report.csv">
#Use empty quote to turn off quoting
quote=
null_string=\\N
format.dob.type=date
format.dob.pattern=yyyy-MM-dd HH:mm:ss
</connection>
<query connection-id="in">
SELECT * FROM test;
<script connection-id="out">
$1,$2,$3,$4
</script>
</query>
</etl>
dob is my column name in MySQL table, it is datetime type column there.
Now when I export the data from MySQL the time comes in the format yyyy-MM-dd HH:mm:ss.S
But I want yyyy-MM-dd HH:mm:ss, so I have used
format.dob.type=date
format.dob.pattern=yyyy-MM-dd HH:mm:ss
As it is suggested scriptella.1.1 has the feature and to use it, in the following link:
http://scriptella.javaforge.com/reference/index.html
But it is not working.
Can anyone help me out.
Thanks. :)
Formatting rules are applied to the variable name, therefore exactly the same variable name should be used for both format description and the expansion placeholder. In your cause, try using $dob instead of the column number.

JAXB bindings generic converter

In JAXB binding i can change type of element from int to string and so on.
But i want not only data type conversion. I want replace integer Id's with they string equivalent.
This means that for every field i need write method.
Is anyway to get field name from parse method?
<!-- Resolve ID's -->
<jaxb:bindings node="/xs:schema/xs:element/xs:complexType/xs:sequence/xs:element[#name='Classification']/xs:complexType/xs:attribute[#name='id']">
<jaxb:property>
<jaxb:baseType>
<jaxb:javaType name="java.lang.String" parseMethod="com.company.lookup.Resolver.resolve" />
</jaxb:baseType>
</jaxb:property>
</jaxb:bindings>
Instead of defining the javaType on a per property basis you can override the Java type for an XML schema type in the global bindings section of the external binding document.
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings>
<jxb:globalBindings>
<jxb:javaType name="String" xmlType="xs:int"/>
</jxb:globalBindings>
</jxb:bindings>
</jxb:bindings>

WebSphere Portal decode url

How I can decode WebSphere Portal url?
For example this url: /wps/portal/!ut/p/c5/dY7LdoIwAAW_hS9ICEnEZSBaKBSKkUfZcAKtKRYMKo-2X197XHtnObO4oAQ3TnJulRxbfZIdKEBJK2wn24ylATUpWUNfhLt9anHTJgg8g1J1ur6VOX_T31wzxRk_4NHZobEvzs5Vu6o3942nbJRTEpNl-UHmoK5JGlfvpOHThtV04ksmNlac5oHuz-HWb4QMcTQHr11SE3xZTUPdz9GvKwkTRfsydMdJHrQTd-vPizIMkP8_p5X7xDy8CiGMUQYhiohIYCos6Ft3Dx-MQRB5uv8Aw1cNj5gZfxocKIs!/dl3/d3/L2dJQSEvUUt3QS9ZQnZ3LzZfNDhRRlZBVUs2UEZMRDBJU1RDTEZIRTEwTDM!/
Is it possible?
Try the following:
/wps/poc?uri=state:URL&mode=download
where URL is your original URL for example:
/wps/poc?uri=state:/wps/portal/!ut/p/c5/dY7LdoIwAAW_hS9ICEnEZSBaKBSKkUfZcAKtKRYMKo-2X197XHtnObO4oAQ3TnJulRxbfZIdKEBJK2wn24ylATUpWUNfhLt9anHTJgg8g1J1ur6VOX_T31wzxRk_4NHZobEvzs5Vu6o3942nbJRTEpNl-UHmoK5JGlfvpOHThtV04ksmNlac5oHuz-HWb4QMcTQHr11SE3xZTUPdz9GvKwkTRfsydMdJHrQTd-vPizIMkP8_p5X7xDy8CiGMUQYhiohIYCos6Ft3Dx-MQRB5uv8Aw1cNj5gZfxocKIs!/dl3/d3/L2dJQSEvUUt3QS9ZQnZ3LzZfNDhRRlZBVUs2UEZMRDBJU1RDTEZIRTEwTDM!/&mode=download
I do not have a running portal to check that but according to my notes it should work.
Michal's answer is correct, calling the POC servlet that way will decode the state information in the URL and produce an XML representation.
The format of this XML is not published, but is pretty easy to decipher, here's an example of how it can look:
<root session="1977644512">
<state type="navigational">
<portlet id="Z7_C2ORULUV0G8BD0IR4S6TP030G6">
<window-state>minimized</window-state>
</portlet>
<selection selection-node="Z6_C2ORULUV00A520IBF1FAOO10G6">
<mapping src="Z6_C2ORULUV0GP520IBIUSMBS0040" dst="Z6_C2ORULUV00A520IBF1FAOO10G6"/>
<mapping src="Z6_000000000000000000000000A0" dst="Z6_C2ORULUV001S30IR8FCN1Q3001"/>
<mapping src="Z6_C2ORULUV001S30IR8FCN1Q3001" dst="Z6_C2ORULUV0GP520IBIUSMBS0040"/>
</selection>
<expansions>
<node id="Z6_C2ORULUV0GP520IBIUSMBS00O5"/>
<node id="Z6_CGAH47L008LG50IAHUR9Q330A3"/>
<node id="Z6_000000000000000000000000A0"/>
</expansions>
<theme-template>Home</theme-template>
<portlet id="Z7_CGAH47L008LG50IAHUR9Q33803" portlet-type="legacy"/>
</state>
<target portlet-type="legacy" portlet-id="Z7_CGAH47L008LG50IAHUR9Q33803" id="LSzyY48160027">
<target-type>action</target-type>
<action-ref>sa.spf_ActionListener</action-ref>
</target>
</root>
Inspecting the XML allows you to do qualified guesses as to what the different information actually means. The <portlet> section(s) for example, clearly contains information about the window state and can probably also contain information about portlet mode. The <selection> section contains the selection path that the user has traveled, and so on.
Since I don't know what you are planning to use the decoded information for, I can't give you any specific guidelines, but consider the XML representation of the state information internal and do not base any application logic on it, since it can change at any point in time.
It can be useful to decode it for troubleshooting though, and to get a general insight in the URL handling of the Portal.
This worked for me...http:server:port/context root/contenthandler?uri=state:

Resources