Liferay Service Builder Table Auto Increment On Each Deployment - liferay

In liferay i have a entity as below:
<entity name="Foo" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="fooId" type="long" primary="true" />
<!-- Group instance -->
<column name="groupId" type="long" />
<!-- Audit fields -->
<column name="companyId" type="long" />
<column name="userId" type="long" />
<column name="userName" type="String" />
<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />
<!-- Other fields -->
<column name="field1" type="String" />
<column name="field2" type="boolean" />
<column name="field3" type="int" />
<column name="field4" type="Date" />
<column name="field5" type="String" />
<!-- Order -->
<order by="asc">
<order-column name="field1" />
</order>
<!-- Finder methods -->
<finder name="Field2" return-type="Collection">
<finder-column name="field2" />
</finder>
</entity>
When i change the code of the portlet. On each deployment its primary key increases by 100.
So there is anyway to set it auto increment by 1 only. And it must not be incremented by 100 on each deploy.

Option#1
Add this in your primary key column id-type="increment"
i.e
<column name="fooId" type="long" primary="true" id-type="increment" />
Cons:
This WILL BREAK IN CLUSTERED Environment
Option#2
add this in portal-ext.properties
#
# Set the number of increments between database updates to the Counter
# table. Set this value to a higher number for better performance.
#
counter.increment=1 //by default it is 100
Cons: this will impact your performance.

Related

XSLT - parse date and time

I am attempting to set the Type attribute of a cell in Excel via XSL. It should look at report/sheet/definition/column and see if there's a type attribute. If yes, it should set the Cell Type to that type and format it in full time (or datetime) manner.
My xml data:
<report>
<sheet>
<definition>
<columns>
<column name="Code" footerText="ISO Code" width="80" />
<column name="Time" footerText="Time" format="DateTime" width="58" type="DateTime" />
<column name="Country" footerText="Country" width="100" />
<column name="SomeNumber" footerText="Country" width="100" type="Number"/>
</columns>
</definition>
<data>
<table>
<row>
<column value="2020-04-02" key="DATE" />
</row>
<row>
<column value="123" />
<column value="10:30" />
<column value="Belarus" />
<column value="0" />
</row>
<row>
<column value="321" />
<column value="12:00" />
<column value="Austria" />
<column value="0" />
</row>
<row>
<column value="2020-04-03" key="DATE" />
</row>
<row>
<column value="456" />
<column value="08:00" />
<column value="USA" />
<column value="24" />
</row>
</table>
</data>
</sheet>
</report>
I have tried printing out $type and $index in the cell and they truly print out properly, but when I try to take the value of $type and use for <xsl:attribute name="ss:Type">, Excel provides me with an error saying it had problems during the load. After checking out the logs, it turns out that it can't parse values like 12:00 into a Time (or shall I say DateTime?). I have two questions:
Is that expected behavior that it can't parse timespan values into DateTime?
Is it normal behavior that it can't parse 2020-01-01 as DateTime as well?
<xsl:for-each select="data/table/row">
<ss:Row>
<xsl:variable name="set" select="column" />
<xsl:variable name="count" select="count($set)"/>
<xsl:for-each select="column">
<ss:Cell>
<xsl:variable name="index" select="position()"/>
<xsl:variable name="type" select="../../../definition/columns/column[$index]/#type"/>
<xsl:attribute name="ss:MergeAcross">
<xsl:choose>
<xsl:when test="$count>1">
<xsl:value-of select="0"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$mergeAcrossHeader"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<ss:Data>
<xsl:attribute name="ss:Type">
<xsl:choose>
<xsl:when test="$type!=''">
<xsl:value-of select="$type" />
</xsl:when>
<xsl:otherwise>
<xsl:text>String</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="#value" />
</ss:Data>
</ss:Cell>
</xsl:for-each>
</ss:Row>
</xsl:for-each>

Automatic generation of header p:columnGroup of p:dataTable

This question is about p:dataTable header manipulation.
I want to find a way to manipulate the header p:dataTable (primefaces) from java code directly, to make something like this:
<p:dataTable id="genericReport" value="#{mb.lazyData}" >
<!-- header -->
<p:columnGroup type="header" binding="#{mb.header}" >
</p:columnGroup>
<!-- some data -->
<p:column>
<h:outputText value="..." />
</p:column>
</p:dataTable>
Where #{mb.header}" is a java code read from a XML, manipulated by a tree through XPath.
I want to do this because I have a lot of reports with a complex header; I mean, diferents levels, diferents conbination of cells.
UPDATE
The header could be with a lot of rows, not only one. Here is an example of a a table.
This header has to be generated by an xml configuration. Here is the XML.
<header id="report">
<column text="Granpa Pather">
<column text="Pather 1">
<column text="Child 1">
<column text="Grand Child 1" />
<column text="Grand Child 2" />
</column>
<column text="Child 2" />
<column text="Child 3" />
</column>
<column text="Pather 2">
<column text="Child 4" />
<column text="Child 5" />
</column>
<column text="Pather 3">
<column text="Child 6" />
<column text="Child 7" />
<column text="Child 8" />
</column>
</column>
</encabezado
The colspan and rowspan is calculated by tree theory, it is not the problem.
I achievement to do this in a PDF y XLS (Itext and ApachePOI, respectly), using XPath and tree manipulation. My problem here is that HTML it is not so easy to manipulate. I think it could be to make using the API Primefaces.

Solr Better search result with adjacent query keyword

I have configured solr for my ecommerce application (That mostly contains books data). The search result does not seem to return what I expect.
Following is the configuration.
schema.xml
`
<field name="namespace" type="string" indexed="true" stored="false" />
<field name="id" type="string" indexed="true" stored="true" />
<field name="productId" type="long" indexed="true" stored="true" />
<field name="skuId" type="long" indexed="true" stored="true" />
<field name="category" type="long" indexed="true" stored="false" multiValued="true" />
<field name="explicitCategory" type="long" indexed="true" stored="false" multiValued="true" />
<field name="searchable" type="text_general" indexed="true" stored="false" />
<dynamicField name="*_searchable" type="text_general" indexed="true" stored="false" />
<dynamicField name="*_i" type="int" indexed="true" stored="false" />
<dynamicField name="*_is" type="int" indexed="true" stored="false" multiValued="true" />
<dynamicField name="*_s" type="string" indexed="true" stored="false" />
<dynamicField name="*_ss" type="string" indexed="true" stored="false" multiValued="true" />
<dynamicField name="*_l" type="long" indexed="true" stored="false" />
<dynamicField name="*_ls" type="long" indexed="true" stored="false" multiValued="true" />
<dynamicField name="*_t" type="text_general" indexed="true" stored="false" />
<dynamicField name="*_txt" type="text_general" indexed="true" stored="false" multiValued="true" />
<dynamicField name="*_b" type="boolean" indexed="true" stored="false" />
<dynamicField name="*_bs" type="boolean" indexed="true" stored="false" multiValued="true" />
<dynamicField name="*_d" type="double" indexed="true" stored="false" />
<dynamicField name="*_ds" type="double" indexed="true" stored="false" multiValued="true" />
<dynamicField name="*_p" type="double" indexed="true" stored="false" />
<dynamicField name="*_dt" type="date" indexed="true" stored="false" />
<dynamicField name="*_dts" type="date" indexed="true" stored="false" multiValued="true" />
<!-- some trie-coded dynamic fields for faster range queries -->
<dynamicField name="*_ti" type="tint" indexed="true" stored="false" />
<dynamicField name="*_tl" type="tlong" indexed="true" stored="false" />
<dynamicField name="*_td" type="tdouble" indexed="true" stored="false" />
<dynamicField name="*_tdt" type="tdate" indexed="true" stored="false" />
<!-- Both field types required for geolocation searches. First stores the
lat and lon components for the "coordinate" FieldType. Second stores
the coordinate. -->
<dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false"/>
<dynamicField name="*_c" type="coordinate" indexed="true" stored="false"/>
</fields>
<uniqueKey>id</uniqueKey>
<types>
<!-- The StrField type is not analyzed, but indexed/stored verbatim. -->
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<!-- boolean type: "true" or "false" -->
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" />
<!-- Default numeric field types. For faster range queries, consider the
tint/tlong/tdouble types. -->
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0" />
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0" />
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0" />
<!-- Numeric field types that index each value at various levels of precision
to accelerate range queries when the number of values between the range endpoints
is large. See the javadoc for NumericRangeQuery for internal implementation
details. Smaller precisionStep values (specified in bits) will lead to more
tokens indexed per value, slightly larger index size, and faster range queries.
A precisionStep of 0 disables indexing at different precision levels. -->
<fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0" />
<fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0" />
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0" />
<!-- The format for this date field is of the form 1995-12-31T23:59:59Z,
and is a more restricted form of the canonical representation of dateTime
http://www.w3.org/TR/xmlschema-2/#dateTime The trailing "Z" designates UTC
time and is mandatory. Optional fractional seconds are allowed: 1995-12-31T23:59:59.999Z
All other components are mandatory. Expressions can also be used to denote
calculations that should be performed relative to "NOW" to determine the
value, ie... NOW/HOUR ... Round to the start of the current hour NOW-1DAY
... Exactly 1 day prior to now NOW/DAY+6MONTHS+3DAYS ... 6 months and 3 days
in the future from the start of the current day Consult the DateField javadocs
for more information. Note: For faster range queries, consider the tdate
type -->
<fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0" />
<!-- A Trie based date field for faster date range queries and date faceting. -->
<fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0" />
<!-- A general text field that has reasonable, generic cross-language defaults:
it tokenizes with StandardTokenizer and down cases. -->
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<!-- A specialized field for geospatial search. If indexed, this fieldType must not be multivalued. -->
<fieldType name="coordinate" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
</types>
`
solrconfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<luceneMatchVersion>4.10.3</luceneMatchVersion>
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}" />
<updateHandler class="solr.DirectUpdateHandler2" />
<query>
<maxBooleanClauses>1024</maxBooleanClauses>
<filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="0" />
<queryResultCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
<documentCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0" />
<cache name="perSegFilter" class="solr.search.LRUCache" size="10" initialSize="0" autowarmCount="10"
regenerator="solr.NoOpRegenerator" />
<enableLazyFieldLoading>true</enableLazyFieldLoading>
<queryResultWindowSize>20</queryResultWindowSize>
<queryResultMaxDocsCached>200</queryResultMaxDocsCached>
<listener event="newSearcher" class="solr.QuerySenderListener" />
<listener event="firstSearcher" class="solr.QuerySenderListener">
<arr name="queries">
<lst>
<str name="q">static firstSearcher warming in solrconfig.xml</str>
</lst>
</arr>
</listener>
<useColdSearcher>false</useColdSearcher>
<maxWarmingSearchers>2</maxWarmingSearchers>
</query>
<requestDispatcher handleSelect="false">
<requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048000" formdataUploadLimitInKB="2048"
addHttpRequestToContext="false"/>
<httpCaching never304="true" />
</requestDispatcher>
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rowsa">10</int>
<str name="df">name_t</str>
</lst>
</requestHandler>
<queryResponseWriter name="json" class="solr.JSONResponseWriter">
<str name="content-type">text/plain; charset=UTF-8</str>
</queryResponseWriter>
For example when I search for 2 states it gives me lot of random results, which does not even contain 2 states in the title.
However when I search for 2 states in phrase "2 States", I do get the relevant results"
I dont want to restrict every search into quotes, since user might search for some combination like "book by author" which certainly give 0 results if searched in phrase since it wont match the exact phrase.
How can I imporve my search so that I can list most relevant results on the top.
You can use the pf2 and pf3 parameters in the edismax handler to give boosts to documents where two (pf2) or three (pf3) of your terms are found after each other in the field.
defType=edismax&pf2=title^4
You also have the pf argument for the regular dismax handler, but that's built on the assumption that all the terms are close together. It might help, but pf2 or pf3 sounds better suited for what you need.

FetchXML View to Include Attributes from Nested Link-Entity

I would like to have a view that show attributes from 3 entities:
Statistics has a lookup to Account and Account has a lookup to Address.
The view is on Statistics and I want attributes from all 3 entities; is this even possible?
The problem is with the GridXML.
I want to include the attribute wl_city in the GridXML.
This is the FetchXML with link-entities:
<fetchxml>
<fetch version="1.0" output-format="xml-platform" mapping="logical">
<entity name="sb_statistics">
<order attribute="sb_amount" descending="false" />
<!-- It is easy to get these into the GridXML -->
<attribute name="sb_debtor" />
<attribute name="sb_date" />
<attribute name="sb_amount" />
<link-entity name="account" from="accountid" to="sb_debtor"
alias="relatedAccount" link-type="outer">
<!-- It is possible to get this into the GridXML
by using the link-entity alias: relatedAccount.wl_towncity -->
<attribute name="wl_towncity" />
<link-entity name="wl_postalcode" from="wl_postalcodeid"
to="wl_postaltowncity" alias="relatedAddress" link-type="outer">
<!-- I have trouble getting this attribute into the GridXML -->
<attribute name="wl_city" />
</link-entity>
</link-entity>
<attribute name="sb_statisticsid" />
</entity>
</fetch>
</fetchxml>
When I change the GridXML as below this error is displayed when the view is opened:
"To use this saved query, you must remove criteria and columns that refer to deleted or non-searchable items"
<layoutxml>
<grid name="resultset" object="10008" jump="sb_name" select="1" preview="1"
icon="1">
<row name="result" id="sb_statisticsid" multiobjectidfield="1">
<cell name="sb_amount" width="100" />
<cell name="sb_date" width="100" />
<cell name="sb_debtor" width="100" />
<cell name="relatedAccount.relatedAddress.wl_city" width="100" />
</row>
</grid>
</layoutxml>
The below GridXML shows this error when the view is opened:
"Unexpected Error An error has occured".
<layoutxml>
<grid name="resultset" object="10008" jump="sb_name" select="1" preview="1"
icon="1">
<row name="result" id="sb_statisticsid" multiobjectidfield="1">
<cell name="sb_amount" width="100" />
<cell name="sb_date" width="100" />
<cell name="sb_debtor" width="100" />
<cell name="relatedAddress.wl_city" width="100" />
</row>
</grid>
</layoutxml>
The GridXML below results in this error being shown when the view is opened:
"To use this saved view, you must remove criteria and columns that refer to deleted or non-searchable columns".
<layoutxml>
<grid name="resultset" object="10008" jump="sb_name" select="1" preview="1"
icon="1">
<row name="result" id="sb_statisticsid" multiobjectidfield="1">
<cell name="sb_amount" width="100" />
<cell name="sb_date" width="100" />
<cell name="sb_debtor" width="100" />
<cell name="wl_city" width="100" />
</row>
</grid>
</layoutxml>
This saved query works, but it only includes attributes from the primary entity and the first link-entity.
<savedquery>
<IsCustomizable>1</IsCustomizable>
<CanBeDeleted>0</CanBeDeleted>
<isquickfindquery>0</isquickfindquery>
<isprivate>0</isprivate>
<isdefault>0</isdefault>
<returnedtypecode>10008</returnedtypecode>
<savedqueryid>{df101ac4-2e4d-e311-9377-005056bd0001}</savedqueryid>
<layoutxml>
<grid name="resultset" object="10008" jump="sb_name" select="1" preview="1"
icon="1">
<row name="result" id="sb_statisticsid" multiobjectidfield="1">
<cell name="sb_amount" width="100" />
<cell name="sb_date" width="100" />
<cell name="sb_debtor" width="100" />
<cell name="relatedAccount.wl_city" width="100" />
</row>
</grid>
</layoutxml>
<querytype>0</querytype>
<fetchxml>
<fetch version="1.0" output-format="xml-platform" mapping="logical">
<entity name="sb_statistics">
<order attribute="sb_amount" descending="false" />
<attribute name="sb_debtor" />
<attribute name="sb_date" />
<attribute name="sb_amount" />
<link-entity name="account" from="accountid" to="sb_debtor"
alias="relatedAccount" link-type="outer">
<attribute name="wl_towncity" />
<link-entity name="wl_postalcode" from="wl_postalcodeid"
to="wl_postaltowncity" alias="relatedAddress" link-type="outer">
<attribute name="wl_city" />
</link-entity>
</link-entity>
<attribute name="sb_statisticsid" />
</entity>
</fetch>
</fetchxml>
<LocalizedNames>
<LocalizedName description="Statistics and Address" languagecode="1033" />
</LocalizedNames>
</savedquery>
Is GridXML limited to showing only attributes from the primary entity and the first link-entity?
This is not possible, according to the best of my knowledge, but please someone prove me wrong.
A limitation of GridXML appears to be that attributes can only be included that are from the first link-entity, not any nested link-entities.
It should work when using link-type="inner" for nested link.
<entity name="sb_statistics">
...
<link-entity name="account" from="accountid" to="sb_debtor"
alias="relatedAccount" link-type="outer">
<attribute name="wl_towncity" />
<link-entity name="wl_postalcode" from="wl_postalcodeid"
to="wl_postaltowncity" alias="relatedAddress" link-type="inner"> //link-type="inner"
<attribute name="wl_city" />
</link-entity>
</link-entity>
<attribute name="sb_statisticsid" />
</entity>
I have found no evidence that it can be done. With or without link-type='inner' the designer (in 2013) says, "The relatedAddress.wl_city column is no longer a valid column because it has been deleted as a column option. You need to remove this column and, if you want, add a different one."
It does NOT need multiple dereferrences, nor does that work. If you dump the keyValuePairs of the AttributeCollection returned by the fetch, you will see the key is relatedAddress.w1_city -- not its parent nor the combination.
Like the UI, it just appears the layout is limited to only root and children, no grandchildren nor further descendants.
I think it's a little late to answer this question, but maybe someone come to this post and find it helpful.
first thing you should know is that, fetchxml will return only column that are not null, so if you are querying a column that there is no data in that, then fetchxml automatically remove it from result set.
second thing is, if you have different table with different relationship, then alias name will be added to the column name, so in your case relatedAccount.wl_towncity and relatedAddress.wl_city is correct and not relatedAccount.relatedAddress.wl_city. in your example, you put alias name after each other that is not correct.
third thing that you should know is that when a nested result will return, the type is object, but original type AliasedValue , so first you have to cast the object to AliasedValue. then it become ready to cast it to OptionSetValue. after that you have to look for .Value that has the result of what you want
I made it work like this: I still have an issue with unresolved columnheaders.
<fetch distinct='true'>
<entity name='rdiac_riskobject'>
<attribute name='rdiac_riskobjectid' />
<attribute name='rdiac_name' />
<attribute name='rdiac_riskobjectproduct' />
<link-entity name='rdiac_riskobject_rdiac_propertydetail' from='rdiac_riskobjectid' to='rdiac_riskobjectid' intersect='true'>
<link-entity name='rdiac_propertydetail' alias='pd1' from='rdiac_propertydetailid' to='rdiac_propertydetailid'>
<attribute name='rdiac_valuestring' />
<link-entity name='rdiac_propertysvconfig' from='rdiac_property' to='rdiac_propertyid'>
<filter>
<condition attribute='rdiac_svfield' operator='eq' value='100000000'/>
</filter>
</link-entity>
</link-entity>
</link-entity>
<link-entity name='rdiac_riskobject_rdiac_propertydetail' from='rdiac_riskobjectid' to='rdiac_riskobjectid' intersect='true'>
<link-entity name='rdiac_propertydetail' alias='pd2' from='rdiac_propertydetailid' to='rdiac_propertydetailid'>
<attribute name='rdiac_valuestring' />
<link-entity name='rdiac_propertysvconfig' from='rdiac_property' to='rdiac_propertyid'>
<filter>
<condition attribute='rdiac_svfield' operator='eq' value='100000001'/>
</filter>
</link-entity>
</link-entity>
</link-entity>
</entity>
</fetch>
<grid name='resultset' object='10139' jump='rdiac_riskobjectproduct' select='1' preview='0' icon='1' >
<row name='result' id='rdiac_riskobjectid' >
<cell name='rdiac_riskobjectproduct' width='100' />
<cell name='pd1.rdiac_valuestring' width='200' />
<cell name='pd2.rdiac_valuestring' width='200' />
</row>
</grid>

TFS WorkItem Layout problem

I'm customizing a TFS Work Item Type, adding a 'Business Description' HTML Field, but I cannot get the Layout right:
<Tab Label="Details">
<Group>
<Column PercentWidth="60">
<Control FieldName="Customer.BusinessDescription" Type="HtmlFieldControl" Label="Business Description:" LabelPosition="Top" Dock="Fill" />
</Column>
<Column PercentWidth="40">
<Control FieldName="Microsoft.VSTS.CMMI.Symptom" Type="HtmlFieldControl" Label="Symptom:" LabelPosition="Top" />
<Control FieldName="System.History" Type="WorkItemLogControl" Label="&History:" LabelPosition="Top" />
</Column>
</Group>
</Tab>
This turns out like this:
While I really want this ('Photoshopped' with MSPaint):
I have played around with the Fill properties on all three fields, have already set the MinimumSize property on the BusinessDescription field, added a group inside the left column, but I do not seem to find a solution for this.
Is this at all possible?
You'll want to create a group inside both the left and right columns:
<Tab Label="Details">
<Group>
<Column PercentWidth="60">
<Group>
<Column PercentWidth="100">
<Control FieldName="Customer.BusinessDescription" Type="HtmlFieldControl" Label="Business Description:" LabelPosition="Top" Dock="Fill" />
</Column>
</Group>
</Column>
<Column PercentWidth="40">
<Group>
<Column PercentWidth="100">
<Control FieldName="Microsoft.VSTS.CMMI.Symptom" Type="HtmlFieldControl" Label="Symptom:" LabelPosition="Top" />
<Control FieldName="System.History" Type="WorkItemLogControl" Label="&History:" LabelPosition="Top" />
</Column>
</Group>
</Column>
</Group>
</Tab>
You may also want to check out the Process Editor Power Tool - this provides a GUI interface to editing work item types.

Resources