пятница, 11 января 2013 г.

JSF custom converter

Example of rather simple JSF converter to transform string with separated by semicolon words to the list of strings. In my case it was useful for mailbox application for email address input field with multiple email addresses.
/**
 * Custom converter to transform input string value to the list of strings.
 *
 * @author Maxim Baev
 */
@FacesConverter(value = "stringListConverter")
public class StringListConverter implements Converter {

    private static final Logger LOGGER = LoggerFactory.getLogger(StringListConverter.class);

    private static final String DELIMITER = ";";
    private static final String WHITESPACE = " ";

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getAsObject(final FacesContext context, final UIComponent component, final String value) {
        if (value == null || value.isEmpty()) {
            return null;
        }

        try {
            return Arrays.asList(value.replaceAll(WHITESPACE, StringUtils.EMPTY).split(DELIMITER));
        } catch (Exception e) {
            LOGGER.error("Failed to convert string to list", e);
            throw new ConverterException(new FacesMessage(String.format("Cannot convert %s to list", value)), e);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getAsString(final FacesContext context, final UIComponent component, final Object value) {
        if (!(value instanceof List)) {
            return null;
        }

        return StringUtils.join((List) value, DELIMITER + WHITESPACE);
    }
}


пятница, 18 мая 2012 г.

Oracle XE: changing HTTP port

To change default http port used by Oracle XE all you need is execute simple command. Run SQL Command line:

SQL> connect
Enter user-name: system
Enter password:
Connected.
SQL> exec dbms_xdb.sethttpport(8088); // or any other port you want

PL/SQL procedure successfully completed.

SQL> quit

That's it!

вторник, 31 января 2012 г.

Running executable jar file in windows vista or windows 7

In Windows Vista or Windows 7 the manual file association editor has been removed. So you can have problems with running executable jar by double-clicking it. You can solve it in different ways:
1) Most easiest way is to use program Jarfix
2) Also you can add file association in your command prompt window using "Run as administrator”:
          C:\>assoc .jar=jarfile
          C:\>ftype jarfile="C:\path\to\your\javaw.exe" -jar "%1" %*

среда, 25 января 2012 г.

Resolving problems with running Apache Nutch on Windows. Part 2.

When Nutch crawling process started with '-solr' argument you can face a problem with Solr schema.xml.Some fields can be absent and you will see errors in log:
2012-01-25 11:03:46,484 WARN  mapred.LocalJobRunner - job_local_0020
org.apache.solr.common.SolrException: ERROR: [doc=http://business.ngs.ru/] unknown field 'content'

ERROR: [doc=http://business.ngs.ru/] unknown field 'content'

request: http://localhost:8983/solr/update?wt=javabin&version=2
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:436)
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:245)
    at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105)
    at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:49)
    at org.apache.nutch.indexer.solr.SolrWriter.close(SolrWriter.java:93)
    at org.apache.nutch.indexer.IndexerOutputFormat$1.close(IndexerOutputFormat.java:48)
    at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:474)
    at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:411)
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:216)



To fix this I've copied schema.xml for Solr from http://svn.apache.org/viewvc/nutch/branches/branch-1.4/conf/schema.xml?view=markup.

вторник, 24 января 2012 г.

Resolving problems with running Apache Nutch on Windows. Part 1.

First root of some problems with running Apache Nutch on Windows is Cygwin, as Nutch has bash scripts to run. So, install Cygwin and add its root directory to 'path' system variable (e.g. C:\Cygwin). But if you added only root directory to path you can see exception in Nutch log:

java.io.IOException: Expecting a line not the end of stream
    at org.apache.hadoop.fs.DF.parseExecResult(DF.java:109)
    at org.apache.hadoop.util.Shell.runCommand(Shell.java:179)
    at org.apache.hadoop.util.Shell.run(Shell.java:134)
    at org.apache.hadoop.fs.DF.getAvailable(DF.java:73)
    at org.apache.hadoop.fs.LocalDirAllocator$AllocatorPerContext.getLocalPathForWrite(LocalDirAllocator.java:329)
    at org.apache.hadoop.fs.LocalDirAllocator.getLocalPathForWrite(LocalDirAllocator.java:124)
    at org.apache.hadoop.mapred.MapOutputFile.getSpillFileForWrite(MapOutputFile.java:107)
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:1221)
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1129)
    at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:359)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:307)
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:177)


To resolve this you should add Cygwin 'bin' directory to your system path (e.g. C:\Cygwin\bin)

среда, 18 января 2012 г.

Disabled fields in ExtJS form

If you want to disable input field in your form, don't make it:


disabled: true
In this case value of the field won't be submitted (this is standard
behaviour for HTML forms). Insted of this use: 

readOnly: true,
fieldClass: "x-item-disabled"
 In this case field value will be submitted but field itself will look
 like disabled and will be not editable. 

среда, 11 января 2012 г.

GIT - working on a side branch

It is best to work on a side branch and follow the “merge master/merge side” delivery procedure.  The overall flow is defined here:
Here is refined set of commands, which details branch switch, and substitutes rebases on the side branch instead of merges:

1. Starting on local master, update from remote master then create a side branch

git pull origin
git checkout -b JIRA-1122 origin/master
2. Now on side branch named JIRA-1122

git commit -m "blah"
git pull --rebase origin/master
Notice that I’ve told it to rebase

3. Back to local master branch

git checkout master
git pull origin
This updates your local master to mirror what the upstream master looks like.
 4.

git merge JIRA-1122
Your changes are merged onto master not the other way around: 
git push origin master

5. You may now throw away the side branch.

git branch -d JIRA-1122