For cases one does not want or need (because it would never find reuse!) to create wrapper class for pairing two values of any types (a 2-tuple) in Java, Map.Entry
public inner interface in java.util.Map
container can be acceptable alternative. Code relying on java.util.Collections.singletonMap
(constant additional space use!) to return a pair from Java method can be written as such:
// returns pair (2-tuple)
private Map.Entry<Integer, Record> bar() {
// ... recordCount and record created
return Collections.singletonMap(recordCount, record).entrySet().iterator().next();
}
// 2-tuple extraction with getKey()/getValue()
public void foo() {
Map.Entry<Integer, Record> pair = bar();
Integer recordCount = pair.getKey();
Record record = pair.getValue();
// use paired values ...
}
Sunday, December 28, 2014
Quick 2-tuples in Java
Tuesday, July 29, 2014
Locales in Liferay

I wanted to configure the languages available in Liferay 6.2 runtime interface site settings (Site Administration → Configuration → Site Settings → Display Settings → Language) to include Russian and Azerbaijani — but these were not even listed among available languages. From portal source I verified that language pack for Russian indeed exists (not for Azerbaijani though!).
Having had a look at portal.properties gives a hint that interface languages in Liferay runtime depend on locales.enabled
setting, which can be overriden in one of the Liferay configuration files (reading order: portal.properties, portal-bundle.properties, portal-ext.properties & portal-setup-wizard.properties). So e.g. locales.enabled=en_US,ru_RU
in portal-ext.properties will do the trick for making Russian locale available, for Azerbaijani, one would need to start translating.
And later I found that available locales can also be set from Control Panel → Configuration → Portal Settings → Display Settings → Available Languages :)
Friday, July 18, 2014
Liferay 6.2 archetypes
Maven (build tool and a Trickster) provides several Liferay specific archetypes with com.liferay.maven.archetypes
archetypeGroupId. Some of these are tied to MVC frameworks to be used in Liferay portlet (e.g liferay-portlet-jsf-archetype), others assembled for more generic functionality. Sample command line to generate Liferay portlet project structure without any MVC specifics added:
mvn archetype:generate \ -DarchetypeGroupId=com.liferay.maven.archetypes \ -DarchetypeArtifactId=liferay-portlet-archetype \ -DarchetypeVersion=6.2.10.6 \ -DgroupId=thecompany.com \ -DartifactId=company-portlet-one \ -Dversion=0.1-SNAPSHOT \ -DinteractiveMode=false
The list of all available Maven archetypes can be seen with: mvn archetype:generate
command. Following MVC agnostic archetypes are available in com.liferay.maven.archetypes
group.
liferay-ext-archetype — for creating customizations as Liferay extension, also called ext plugin. With ext plugins Liferay core functionality can be replaced with modifications separate from Liferay's code. Jamie L Sammons writes:
Liferay Ext Plugins are often considered a last resort in the Liferay Plugin world due to the complexity and the lack of hot deploy as well as the inability to remove them once they are deployed.
liferay-hook-archetype — for Liferay customization, a hook has advantage of hot deploy. Web resources, JSPs, portal services, etc can be overridden with hooks. Hooks can also be defined in portlets.
liferay-layouttpl-archetype — layout templates allow definition of new page layouts, embedding commonly used portlets in layouts, specifying CSS, etc.
liferay-portlet-archetype — minimalistic Liferay portlet to be deployed in portal.
liferay-servicebuilder-archetype — to generate a basic service layer. It comes with promise of CRUD and SOAP all in place for the entities.
liferay-theme-archetype — Liferay theme plugin archetype for user interface customization of sites in Liferay.
liferay-web-archetype — creates a minimal web application skeleton, Liferay specific addition being WEB-INF/liferay-plugin-package.properties file, allowing to manage that application from Liferay Control Panel.
Saturday, July 12, 2014
Liferay Editions
Ambitiously named Liferay provides open-source "enterprise" Java portal environment for JSR-286 portlets.
Current Liferay version is 6.2, distributed in two editions:
- Community Edition (CE)
- Enterprise Edition (EE)
Liferay has partner programs for redistribution, support and service. Componence is one of the partners that has provided more detailed list of EE features.
Pricing of Liferay EE is opaque, their get pricing link opens up a form requesting all kinds of information about the potential client, including short description of project use case, including an estimated scale (total users, concurrent users, integrations and redundancy planned) plus any current infrastructure estimations for OS, DB, IdM, integration.
Friday, March 7, 2014
SVN diff of the day
Shell script to first show the list of modified files and then the corresponding diffs:
#!/bin/sh
TODAY="date +%Y-%m-%d"
DIFFCMD="svn diff -r{`$TODAY -d yesterday`}:{`$TODAY`}"
$DIFFCMD --summarize # file list report
$DIFFCMD --no-diff-deleted # diffs