Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Friday, April 19, 2013

cdk and grails - why don't get they along. This time using maven for dependency management...

...

Recently I posted about grails2 and the CDK using the BuildConfig.groovy approach.

Now it's only fair that I show the maven approach as alternative. It's aint pretty...

But it works and allows you to build grails 2.1 project with the CDK. Now i just need to integrate scala into the mix...


<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>edu.ucdavis.fiehnlab.cts</groupId>
    <artifactId>cts</artifactId>
    <packaging>grails-app</packaging>
    <version>2.0-beta-2</version>
    <name>cts</name>
    <description>2.0-beta-2</description>

    <parent>
        <artifactId>web</artifactId>
        <groupId>edu.ucdavis.fiehnlab.cts.web</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.grails</groupId>
            <artifactId>grails-dependencies</artifactId>
            <version>${grails.version}</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>org.grails</groupId>
            <artifactId>grails-test</artifactId>
            <version>${grails.version}</version>
            <type>pom</type>
        </dependency>


        <dependency>
            <groupId>org.grails</groupId>
            <artifactId>grails-plugin-testing</artifactId>
            <version>${grails.version}</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>net.sf.jni-inchi</groupId>
            <artifactId>jni-inchi</artifactId>
            <version>${jni.inchi.version}</version>
        </dependency>

        <dependency>

            <groupId>org.openscience.cdk</groupId>
            <artifactId>cdk-inchi</artifactId>
            <version>${cdk.version}</version>

            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xmlParserAPIs</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xalan</groupId>
                    <artifactId>xalan</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>java3d</groupId>
                    <artifactId>vecmath</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xmlpull</groupId>
                    <artifactId>xmlpull</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>cml</groupId>
                    <artifactId>cmlxom</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xom</groupId>
                    <artifactId>xom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>jdom</groupId>
                    <artifactId>jdom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xpp3</groupId>
                    <artifactId>xpp3</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>jama</groupId>
                    <artifactId>jama</artifactId>
                </exclusion>

            </exclusions>
        </dependency>

        <dependency>

            <groupId>org.openscience.cdk</groupId>
            <artifactId>cdk-fingerprint</artifactId>
            <version>${cdk.version}</version>

            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xmlParserAPIs</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xalan</groupId>
                    <artifactId>xalan</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>java3d</groupId>
                    <artifactId>vecmath</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xmlpull</groupId>
                    <artifactId>xmlpull</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>cml</groupId>
                    <artifactId>cmlxom</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xom</groupId>
                    <artifactId>xom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>jdom</groupId>
                    <artifactId>jdom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xpp3</groupId>
                    <artifactId>xpp3</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>jama</groupId>
                    <artifactId>jama</artifactId>
                </exclusion>

            </exclusions>
        </dependency>
        <dependency>

            <groupId>org.openscience.cdk</groupId>
            <artifactId>cdk-renderawt</artifactId>
            <version>${cdk.version}</version>

            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xmlParserAPIs</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xalan</groupId>
                    <artifactId>xalan</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>java3d</groupId>
                    <artifactId>vecmath</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xmlpull</groupId>
                    <artifactId>xmlpull</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>cml</groupId>
                    <artifactId>cmlxom</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xom</groupId>
                    <artifactId>xom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>jdom</groupId>
                    <artifactId>jdom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xpp3</groupId>
                    <artifactId>xpp3</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>jama</groupId>
                    <artifactId>jama</artifactId>
                </exclusion>

            </exclusions>
        </dependency>


        <dependency>

            <groupId>org.openscience.cdk</groupId>
            <artifactId>cdk-render</artifactId>
            <version>${cdk.version}</version>

            <scope>runtime</scope>


            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xmlParserAPIs</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xalan</groupId>
                    <artifactId>xalan</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>java3d</groupId>
                    <artifactId>vecmath</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xmlpull</groupId>
                    <artifactId>xmlpull</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>cml</groupId>
                    <artifactId>cmlxom</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xom</groupId>
                    <artifactId>xom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>jdom</groupId>
                    <artifactId>jdom</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xpp3</groupId>
                    <artifactId>xpp3</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>jama</groupId>
                    <artifactId>jama</artifactId>
                </exclusion>

            </exclusions>
        </dependency>


        <dependency>
            <groupId>org.codehaus.groovy.modules.http-builder</groupId>
            <artifactId>http-builder</artifactId>
            <version>0.5.2</version>
            <scope>runtime</scope>

            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xmlParserAPIs</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>xalan</groupId>
                    <artifactId>xalan</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>8.2-504.jdbc3</version>
        </dependency>


        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>cache</artifactId>
            <version>1.0.1</version>
            <type>zip</type>
        </dependency>


        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>jquery-ui</artifactId>
            <version>1.8.24</version>
            <type>zip</type>
        </dependency>


        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>jquery</artifactId>
            <version>1.8.3</version>
            <type>zip</type>
        </dependency>


        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>export</artifactId>
            <version>1.5</version>
            <type>zip</type>
        </dependency>


        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>resources</artifactId>
            <version>1.1.6</version>
            <type>zip</type>
        </dependency>


        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>jquery-ui-extensions</artifactId>
            <version>0.5.8</version>
            <type>zip</type>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>hibernate</artifactId>
            <version>${grails.version}</version>
            <type>zip</type>

        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>spock</artifactId>
            <version>0.6</version>
            <type>zip</type>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-grails-support</artifactId>
            <version>0.6-groovy-1.8</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>functional-test</artifactId>
            <version>1.2.7</version>
            <type>zip</type>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>webxml</artifactId>
            <version>1.4.1</version>
            <type>zip</type>
        </dependency>

        <dependency>
            <groupId>org.grails.plugins</groupId>
            <artifactId>tomcat</artifactId>
            <version>2.1.0</version>
            <type>zip</type>
            <scope>runime</scope>
        </dependency>


    </dependencies>

    <build>
        <pluginManagement/>

        <plugins>
            <!-- Disables the Maven surefire plugin for Grails applications, as we have our own test runner -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>surefire-it</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>plugins</directory>
                            <includes>
                                <include>**/*</include>
                            </includes>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.grails</groupId>
                <artifactId>grails-maven-plugin</artifactId>
                <version>${grails.version}</version>
                <configuration>
                    <!-- Whether for Fork a JVM to run Grails commands -->
                    <fork>true</fork>
                </configuration>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>grails</id>
            <name>grails</name>
            <url>http://repo.grails.org/grails/core</url>
        </repository>
        <repository>
            <id>grails-plugins</id>
            <name>grails-plugins</name>
            <url>http://repo.grails.org/grails/plugins</url>
        </repository>

        <repository>
            <id>ambit-public</id>
            <name>ambit-public</name>
            <url>http://ambit.uni-plovdiv.bg:8083/nexus/content/repositories/public/</url>
        </repository>


        <repository>
            <id>ambit-thirdparty</id>
            <name>ambit-thirdparty</name>
            <url>http://ambit.uni-plovdiv.bg:8083/nexus/content/repositories/thirdparty/</url>
        </repository>


        <repository>
            <id>codehaus</id>
            <name>codehaus</name>
            <url>http://snapshots.repository.codehaus.org</url>
        </repository>


    </repositories>
</project>


Thursday, March 14, 2013

cdk and grails, why don't they get along...

so apperently the cdk depends on some xml libaries, which causes us all kind of error messages like this in grails:


| Loading Grails 2.1.0
| Configuring classpath
| Error Error executing script Help: loader constraint violation: when resolving overridden method "org.apache.tools.ant.helper.ProjectHelper2$RootHandler.setDocumentLocator(Lorg/xml/sax/Locator;)V" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the current class, org/apache/tools/ant/helper/ProjectHelper2$RootHandler, and its superclass loader (instance of ), have different Class objects for the type org/xml/sax/Locator used in the signature (Use --stacktrace to see the full trace)

IDEA hook: Grails not found!
| Error java.lang.NullPointerException
| Error  at org.jetbrains.groovy.grails.rt.Agent$2.run(Agent.java:135)
| Error  at java.lang.Thread.run(Thread.java:680)




which are rather annoying since all the mailing list say, to just run the dependency report to see what causes this problem. Great idea exact that grails crashes before it can generate the report...

So after a while of searching and goggling and shouting random words at my imac, I found an ugly solution which works rather well for now.
Basically make your BuildConfig.groovy file look like this and it should fix your current issues...
    dependencies {
        
        runtime 'postgresql:postgresql:8.2-504.jdbc3'

        compile('xmlpull:xmlpull:1.1.3.1')

        compile('org.openscience.cdk:cdk-fingerprint:1.4.16') {
            transitive = false
        }
        compile('org.openscience.cdk:cdk-inchi:1.4.16') {
            transitive = false
        }
        compile('org.openscience.cdk:cdk-standard:1.4.16')
        compile('org.openscience.cdk:cdk-interfaces:1.4.16')
        compile('org.openscience.cdk:cdk-annotation:1.4.16')
        compile('org.openscience.cdk:cdk-io:1.4.16')
        compile('org.openscience.cdk:cdk-isomorphism:1.4.16')
        compile('org.openscience.cdk:cdk-render:1.4.16')
        compile('org.openscience.cdk:cdk-renderbasic:1.4.16')
        compile('org.openscience.cdk:cdk-renderawt:1.4.16')
        compile('org.openscience.cdk:cdk-smarts:1.4.16')  {
            transitive = false
        }
        compile('org.openscience.cdk:cdk-extra:1.4.16')  {
            transitive = false
        }
        compile('org.openscience.cdk:cdk-dict:1.4.16')  {
            transitive = false
        }
        compile('jama:jama:1.0.2')  {
            transitive = false
        }
        compile('org.openscience.cdk:cdk-formula:1.4.16')
        compile('org.openscience.cdk:cdk-smsd:1.4.16')
        compile('xpp3:xpp3:1.1.4c')
        compile('java3d:vecmath:1.3.1')
        compile('net.sf.jni-inchi:jni-inchi:0.7')
    }
Maybe this help someone, who has the same issues with old XML-Apis and Xerces and so

Monday, March 11, 2013

Lift - getting access to a database

Since I recently started to play more and more with lift. I discovered that it's not always as easy as you think it is and once you find a solution it was easy indeed.

For example I want to connect to my database server, but have no desire to actually use any form of OR mapping.

So after googleing a bit and woundering how todo this. It's all rather simple.

In your Boot.scala file


def boot {
    // where to search snippet
    LiftRules.addToPackages("code")

    // Build SiteMap
    LiftRules.setSiteMap(sitemap)

    //rest based stuff

    /**
     * connection url for lift
     */
    val vendor = new StandardDBVendor("org.postgresql.Driver","jdbc:postgresql://****/****",Full("username"),Full("password")) with ProtoDBVendor{
      override def maxPoolSize = 100
      override def doNotExpandBeyond = 200
    }
    
    DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)

  }

This basically defines what to connect to and a connection pool with a max of 100 connections.

To actually access this connection and todo something with it, well this is remarkable easy.


          DB.performQuery("select * from data")

Tuesday, February 7, 2012

java6 on ubuntu

just a quick tip I found how to use apt-get to install sun-java and not open-java.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-plugin

You may want to also add the following

sudo update-alternatives --config java

You should get the following

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode

Press enter to keep the current choice[*], or type selection number: 2
Select (2) and press enter

Now running:

java -version
Returns:

java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Server VM (build 20.1-b02, mixed mode)

Taken from:

http://superuser.com/questions/353983/how-do-i-install-the-sun-java-sdk-in-ubuntu-11-10-oneric

Wednesday, November 30, 2011

scala and instanceOf -

I'm for some reason a fan of instanceOf in java and just love to be able to check at runtime of what kind a class is and do some action depending on this outcome.

But sometimes it's a bit tedios. For example



Object a = new String("tada");
Object result = null;

if(a instanceOf Number){
result = "its a number";
}
else if(a instanceOf String){
result = "its a string";
}


System.out.println(result);



ok it's a silly example, now the pretty scala approach using match



var a:Any = "tada..."

val result = a match {
case n:Number => "it's a number"
case s:String => "it's a string"
}
println(result)



oh so pretty and easy to read.

Monday, November 28, 2011

casting and scala

since a couple of month's I work more and more with scala and really start to like this language. But some of the concepts are really confusing and make me wounder if this really is necceasary.

A prime example would be the whole casting of variables.

In java you simple do:


String value = (String)object;


now in scala


val value:String = object.asInstanceOf[String]


now I admit it looks very clean, but sure took a while to find this one little details.

Otherwise it's always better to use matchers.

Monday, July 4, 2011

JSON and SSL in groovy, how to ignore certificates

In the last couple of days I became more and more interested in bitmining and the first thing I noticed was the utter lack of integrated tools and hence statistics I would like to associated with my miners.

This resulted in me creating a tiny grails application to synchronzie my deepbit statistics with the current market data from mtgox to calculate at which point it becomes pointless to mine these thing. I basically hope that this pays for the 700$ for my 2x6950 radeons and associated cooling the 100+F heat we have here in California.

Now originally you could assume that this is rather straightforward. After all you got json data, which just need to be parsed.


Map jsonArray = JSON.parse(new InputStreamReader(new URL("https://mtgox.com/code/data/ticker.php").openStream()))

println jsonArray



but sadly the java ssl security manager does not agree here with us and tosses a fit..



javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1649)



Now java is kinda smart, if want's to force you install a security certificate from the server you access and authorize yourself. But sometimes you don't want this. In this case it's overkill, since we are having a readonly transaction.

So what has to be done?

you need to create your own security manager implementation. Which basically is a 3 step procedure


  1. implement an interface


    class TrustManager implements X509TrustManager {

    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    return null;
    }

    public void checkClientTrusted(
    java.security.cert.X509Certificate[] certs, String authType) {
    }

    public void checkServerTrusted(
    java.security.cert.X509Certificate[] certs, String authType) {
    }

    }




  2. register the interface and update the context configuration

    TrustManager[] trustAllCerts = new TrustManager[1]

    trustAllCerts[0] = new TrustManager()
    try {
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
    }

  3. and continue like always with your json script

    Map jsonArray = JSON.parse(new InputStreamReader(new URL("https://mtgox.com/code/data/ticker.php").openStream()))


and the result should be now the current ticker for the USD to BitCoin exchange rate.


    {"ticker":{"high":15.4989,"low":13.31415,"avg":14.726503862,"vol":42862,"last":13.31415,"buy":13.331,"sell":13.35999}}



    Tuesday, March 2, 2010

    jboss 4.2.1GA and Java6 and jboss based webservice

    thanks to this report I was able to fix this issue. Well it's not a fix, it's a workaround...

    Ariela Hui - 13/Aug/08 04:23 PM
    I was able to solve this problem. This is what environment I have:
    winXP
    JDK 1.6.0
    JBoss 4.2.1

    In the [jboss_home]/lib/endorsed add:
    jaxb-api.jar
    jboss-jaxrpc.jar
    jboss-jaxws.jar
    jboss-saaj.jar

    copy them from [jboss_home]/server/default/lib

    I've also added to endored jboss-logging-spi.jar
    This I copied from jboss-5.0.0 client folder. 

    Friday, February 26, 2010

    backup! we got REG Expressions!

    recently I got an interesting task handed
    please extract all words out of a text...
    ok simple enough, we know regular expression and we know word boundaries.

    So we just do

    \b\w+\b


    and this simple expression applied to the following sentence
    Glucose (Glc), a monosaccharide (or simple sugar) also...
    gives us the following list
    • Glucose
    • Glc
    • a
    • monosaccharide
    • or simple
    • sugar
    • also
    Sadly the sentence didn't stop at this and continued to include the following tricky statement...
    ...including as much as possible chemical names
    Ok time to read on the reg expressions in groovy and java
    Now let's discover a regular expression which helps us with this.

    Ok let's try this again with a different sentence
    ...as glucose, only one of which (D-glucose) is biologically...
    our first expression would miss
    • D-glucose
    and return for this
    • D
    • glucose
    so we need to modify it a bit to include the first seperation. So it becomes

    \b(\w\-)*\w+\b

    and the day is saved till we try a new sentence and try to discover compounds like

    1. 1,3-Diaminopropane
    2. N-(3S-hydroxydecanoyl)-L-serine
    3. 3,9-divinyl-2,4,8,10-tetraoxaspiro[5.5]undecane
    4. 2-(allyloxy)-1,3,5-trimethylbenzene
    5. 3-hydroxy-2-butanone
    6. 3,3'-Oxybis(1-propene)
    7. 1,1,1,2,2,3,3,4,4-nonafluoro-4-(1,1,2,2,3,3,4,4,4-nonafluorobutoxy)butane
    8. 2-(Formamido)-N1-(5-phospho-D-ribosyl)acetamidine
    9. 1,6,9,13-tetraoxadispiro[4.2.4.2]tetradecane
    10. 3-(N, N-Diethylamino)-1-propylamine
    11. D-Glucose
    12. (R)-3-Hydroxybutyric acid
    Or to make it more realistic, find all the words in this completely pointless and scientific wrong text
     bunch of rumble to find 1,3-Diaminopropane in D-Glucose and 1,1,1,2,2,3,3,4,4-nonafluoro-4-(1,1,2,2,3,3,4,4,4-nonafluorobutoxy)butane.
     It's also nice to have 3,3'-Oxybis(1-propene) or (R)-3-Hydroxybutyric acid. Last bot not least I'm a huge fan or 3,9-divinyl-2,4,8,10-tetraoxaspiro[5.5]undecane.
     Also it's a great feeling if we can find (glucose) in brakets without finding statement like (help i'm surrounded by brackets).

    So do you see a pattern here?
    • everything in () or [] or {} can be part of a chemical so we use ((\[.*\])|(\(.*\))) for this part 
    • everything separated by a ',' and followed by another character ending with a dash can be a chemical, so we use (\w+(,\w+)*\-) for this part
    • it ends all with a word \w+ or a ) (masked as \) )
    so this expression would work for all these

    (\([\w\+]+(,\w+)*\)-)?\b[(\w+(,\w+[\'])*\-)*((\[.*\])|(\(.*\))|(\{.*\}))*\w+]+(\b)( (acid)|(anhydride)|(\sbenzoate)|(\sketone)|(\sether)|(\sester)|(\scyanide))?


    except
    1. 3-(N, N-Diethylamino)-1-propylamine
    2. glucose instead we get 'glucose)'
    no solution for the 1 or 2 yet. Still trying to figure it out.

    now the nicest thing is the groovy closure + match example to get all the content in a text.


    def match = (text =~ pattern)


    congrats now all you words are in the match variable! Text is just a string containing our text.

    Wednesday, February 24, 2010

    playing around with threads

    currently I got back to my hobby and play a bit with multithreading to tune an algorithm.

    So the first step was to write a smpl class to test if the threading api works on my system and what is better than to calculate primes?



    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.TimeUnit;

    public class Test {

    public static void main(String args[]) throws InterruptedException {

    ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
    for (int i = 0; i < 500000000; i++) { final int postion = i; service.execute(new Runnable() { @Override public void run() { try { int i = postion; int i1 = (int) Math.ceil(Math.sqrt(i)); boolean isPrimeNumber = false; while (i1 > 1) {

    if ((i != i1) && (i % i1 == 0)) {
    isPrimeNumber = false;
    break;
    }
    else if (!isPrimeNumber) {
    isPrimeNumber = true;
    }

    --i1;
    }

    if (isPrimeNumber) {
    System.out.println(Thread.currentThread().getName() + " - prime " + i);
    }

    }
    catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }
    service.shutdown();
    service.awaitTermination(4000, TimeUnit.DAYS);
    }
    }




    and the output is nicely:

    pool-1-thread-2 - prime 469237
    pool-1-thread-2 - prime 469241
    pool-1-thread-2 - prime 469253
    pool-1-thread-4 - prime 466553
    pool-1-thread-4 - prime 469267
    pool-1-thread-4 - prime 469279
    pool-1-thread-2 - prime 469283
    pool-1-thread-3 - prime 467869
    pool-1-thread-3 - prime 469303
    pool-1-thread-2 - prime 469321

    while all 4 CPU's are at 100% use.

    translation, java executor api seems to work quite well.

    Now time to tune the binbase algorithm...

    Wednesday, February 3, 2010

    muss das sein?

    [INFO] [compiler:compile]
    [INFO] Compiling 399 source files to /Users/wohlgemuth/Documents/workspace-private/oscar3-chem/branches/cdk-1.3.1/target/classes
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Compilation failure
    Failure executing javac, but could not parse the error:
    An exception has occurred in the compiler (1.5.0_20). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
    com.sun.tools.javac.code.Symbol$CompletionFailure: file org/openscience/cdk/annotations/TestClass.class not found



    Failure executing javac, but could not parse the error:
    An exception has occurred in the compiler (1.5.0_20). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report.  Thank you.
    com.sun.tools.javac.code.Symbol$CompletionFailure: file org/openscience/cdk/annotations/TestClass.class not found

    I mean common, do I really have to deal with compiler bugs now...

    correction


    nvm forgot the cdk annotations library....



    Friday, January 22, 2010

    protecting jboss

    Protecting JBoss

    in the last couple of weeks we released more and more of our BinBase Tools to make it able to actually work with the database. Which means we have to protect our data better.

    Since I had no time at work for this and JBoss doesn't provide a convenient way, well I decided to write a little tool which does this for me.

    So I created yet another google code project, called 'jboss-ip-filter', which basically does nothing else than providing an interceptor, which intercepts all method calls and check's if the ip is in a list of registered IP Address.

    Features
    • protect ejb3.x services
    • protect ejb2.x services
    • ip can be defined as regular expression to support subnets
    Configuration/Installation

    First you need to download the latest release and copy it into the jboss library directory of your choosen configuration.

    Afterwards you need to register the interceptor in the jboss configuration.

    Example

    vim /usr/local/jboss/server/all/conf/standardjboss.xml

    Go to the part about the container configurations and register the interceptor in the first position for every ejb configuration you want to protect.

    The name of the class is: 'com.blogspot.codingandmore.jboss.filter.SessionInterceptor'


    <container-configuration>
    <container-name>Standard CMP 2.x EntityBean</container-name>
    <call-logging>false</call-logging>
    <invoker-proxy-binding-name>entity-unified-invoker</invoker-proxy-binding-name>
    <sync-on-commit-only>false</sync-on-commit-only>
    <insert-after-ejb-post-create>false</insert-after-ejb-post-create>
    <call-ejb-store-on-clean>true</call-ejb-store-on-clean>
    <container-interceptors>
    <interceptor>com.blogspot.codingandmore.jboss.filter.SessionInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.LogInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.SecurityInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.TxInterceptorCMT</interceptor>
    <interceptor>org.jboss.ejb.plugins.CallValidationInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.EntityCreationInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.EntityLockInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.EntityInstanceInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.EntityReentranceInterceptor</interceptor>
    <interceptor>org.jboss.resource.connectionmanager.CachedConnectionInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.EntitySynchronizationInterceptor</interceptor>
    <interceptor>org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor</interceptor>
    </container-interceptors>
    <instance-pool>org.jboss.ejb.plugins.EntityInstancePool</instance-pool>
    <instance-cache>org.jboss.ejb.plugins.InvalidableEntityInstanceCache</instance-cache>
    <persistence-manager>org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager</persistence-manager>
    <locking-policy>org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock</locking-policy>
    <container-cache-conf>
    <cache-policy>org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy</cache-policy>
    <cache-policy-conf>
    <min-capacity>50</min-capacity>
    <max-capacity>1000000</max-capacity>
    <overager-period>300</overager-period>
    <max-bean-age>600</max-bean-age>
    <resizer-period>400</resizer-period>
    <max-cache-miss-period>60</max-cache-miss-period>
    <min-cache-miss-period>1</min-cache-miss-period>
    <cache-load-factor>0.75</cache-load-factor>
    </cache-policy-conf>
    </container-cache-conf>
    <container-pool-conf>
    <MaximumSize>100</MaximumSize>
    </container-pool-conf>
    <commit-option>B</commit-option>
    </container-configuration>


    After this is done you need to restart your server and it should generate a property in the start directory after the next reboot. In this directory you configure your ip address. To be allowed.

    For example if you started the server in the bin directory, the file will be found there


    vim /usr/local/jboss/bin/ip-filter-config.properties


    The ip address of the local host is always registered.

    These following two lines allow it the host '128.120.136.154' to connect but refuses connections from any other hosts to the ejb's.


    128.120.136.154 = true
    \b(?:\d{1,3}\.){3}\d{1,3}\b = false


    If you encounter any problems, please don't hesitate to contact me and I try to help with the encountered problems.

    Friday, December 11, 2009

    maven assembly plugin

    sometimes you run into the issue that you want to generate jars for a simple project. For example when you want to create an executable jar for each method with a main class.

    What do you do?

    you call the maven assembly plugin to the rescue and define several executions

    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>

    <executions>
    <execution>
    <id>MatchLibrary</id>
    <phase>package</phase>
    <goals>
    <goal>single</goal>
    </goals>
    <configuration>

    <archive>
    <manifest>
    <mainClass>edu.ucdavis.genomics.metabolomics.binbase.binbase.external.tools.api.library.impl.application.ApplicationServerLibraryMatchingImplementation</mainClass>
    <packageName>edu.ucdavis.genomics.metabolomics.binbase.binbase.external.tools.api.library.impl.application</packageName>
    <addClasspath>true</addClasspath>
    </manifest>
    <manifestEntries>
    <mode>development</mode>
    <url>${pom.url}</url>
    </manifestEntries>
    <manifestFile>src/main/resources/manifest/ApplicationServerLibraryMatchingImplementation.MF</manifestFile>
    </archive>
    <descriptors>
    <descriptor>src/main/descriptor/jar.xml</descriptor>
    </descriptors>
    <finalName>MatchLibrary</finalName>
    <manifestFile>src/main/resources/manifest/ApplicationServerLibraryMatchingImplementation.MF</manifestFile>
    </configuration>
    </execution>

    <execution>
    <id>RegisterLibrary</id>
    <phase>package</phase>
    <goals>
    <goal>single</goal>
    </goals>
    <configuration>

    <archive>
    <manifest>
    <mainClass>edu.ucdavis.genomics.metabolomics.binbase.binbase.external.tools.api.library.impl.RegisterLibraryImpl</mainClass>
    <packageName>edu.ucdavis.genomics.metabolomics.binbase.binbase.external.tools.api.library.impl</packageName>
    <addClasspath>true</addClasspath>
    </manifest>
    <manifestEntries>
    <mode>development</mode>
    <url>${pom.url}</url>
    </manifestEntries>
    <manifestFile>src/main/resources/manifest/RegisterLibrary.MF</manifestFile>
    </archive>
    <descriptors>
    <descriptor>src/main/descriptor/jar.xml</descriptor>
    </descriptors>
    <finalName>RegisterLibrary</finalName>
    <manifestFile>src/main/resources/manifest/RegisterLibrary.MF</manifestFile>
    </configuration>
    </execution>
    </executions>
    </plugin>

    and this generates two executable jars for us.

    The used assembly descriptor is

    <assembly>
    <formats>
    <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
    <fileSet>
    <directory>target/classes</directory>
    <outputDirectory>/</outputDirectory>
    </fileSet>
    </fileSets>
    <dependencySets>
    <dependencySet>
    <outputDirectory>/</outputDirectory>
    <unpack>true</unpack>
    <scope>runtime</scope>
    </dependencySet>
    </dependencySets>
    </assembly>

    Wednesday, November 11, 2009

    hibernate - configure caching

    since the hibernate tools for eclipse need to have the caching enabled, something I'm not the biggest fan off for several reason.

    Well


    <property name="hibernate.cache.provider_class">
    org.hibernate.cache.EhCacheProvider
    </property>

    <property name="hibernate.cache.use_second_level_cache">true</property>
    <property name="hibernate.cache.use_query_cache">true</property>


    so this makes the binbase configuration run in the eclipse tools.

    Monday, November 2, 2009

    Log4J and eclipse

    sometimes you want to use the log4j system instead of the internal eclipse provide logging framework.

    The use of this is rather simple and straight forwarded. You only need to register an ILogListener at the platform object and implement it.

    An example would be:


    package edu.ucdavis.genomics.metabolomics.binbase.gui.swt.logging;

    import org.apache.log4j.Logger;
    import org.eclipse.core.runtime.ILogListener;
    import org.eclipse.core.runtime.IStatus;

    /**
    * used to forward eclipse logging to log4j
    *
    * @author wohlgemuth
    *
    */
    public class Log4JListener implements ILogListener {

    static Logger LOGGER = Logger.getLogger(Log4JListener.class);

    public void logging(IStatus status, String plugin) {
    if (status.getSeverity() == IStatus.WARNING) {
    if (status.getException() == null) {
    LOGGER.warn(status.getMessage() + "(" + status.getCode() + ")");
    } else {
    LOGGER.warn(status.getMessage() + "(" + status.getCode() + ")",
    status.getException());
    }
    } else if (status.getSeverity() == IStatus.ERROR) {
    if (status.getException() == null) {
    LOGGER
    .error(status.getMessage() + "(" + status.getCode()
    + ")");
    } else {
    LOGGER.error(
    status.getMessage() + "(" + status.getCode() + ")",
    status.getException());
    }

    } else if (status.getSeverity() == IStatus.INFO) {
    if (status.getException() == null) {
    LOGGER.info(status.getMessage() + "(" + status.getCode() + ")");
    } else {
    LOGGER.info(status.getMessage() + "(" + status.getCode() + ")",
    status.getException());
    }

    }
    }

    }



    and to register it


    this.listener = new Log4JListener();
    Platform.addLogListener(this.listener);

    Tuesday, October 27, 2009

    Eclipse SWT 3.5 and an annoying change...

    after I moved a part of my software over to eclipse 3.5 to take advantage of bug fixes and new features I noticed that some of my dialogs don't work anymore.

    For example the login dialog has 2 fiels. A username and a password. These fields are defiend like this:


    password = new Text(content, SWT.BORDER | SWT.PASSWORD);
    user = new Text(content, SWT.BORDER);

    user.addKeyListener(this);
    password.addKeyListener(this);


    and in the key listener I validate the inputs. But with version 3.5 key listener won't work on password fields anymore and I didn't find any documentation about it. So instead you need to use a modify listener now


    password.addModifyListener(new ModifyListener() {

    public void modifyText(ModifyEvent e) {
    }
    });

    Friday, October 16, 2009

    my trouble with snowleopard and java5

    well snow leopard messed up my java installation.

    Luckily there is an easy fix to it!

    taken from here


    cd /tmp/
    curl -o java.1.5.0-leopard.tar.gz http://www.cs.washington.edu/homes/isdal/snow_leopard_workaround/java.1.5.0-leopard.tar.gz
    tar -xvzf java.1.5.0-leopard.tar.gz
    sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leopard
    cd /System/Library/Frameworks/JavaVM.framework/Versions/
    sudo rm 1.5.0
    sudo ln -s 1.5.0-leopard 1.5.0
    open "/Applications/Utilities/Java Preferences.app"


    and move java5 to the top.

    Monday, August 31, 2009

    maven2 - define the context root of an webapp

    Basically I have an application (ear) based on several jars and a war which I want to easily access with a context root of my choice.

    Solution:


    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <configuration>
    <archive>
    <manifest>
    <addClasspath>true</addClasspath>
    </manifest>
    </archive>
    <jboss>
    <version>4</version>
    </jboss>
    <bundleFileName>
    binbase-quality-control.ear
    </bundleFileName>

    <modules>
    <webModule>
    <groupId>edu.ucdavis.genomics.metabolomics.binbase.quality
    </groupId>
    <artifactId>quality-war</artifactId>
    <contextRoot>/quality-war</contextRoot>
    </webModule>
    </modules>

    </configuration>
    </plugin>

    Monday, July 27, 2009

    Annoying maven bug

    well tonight I got an interesting error message from my bamboo build server


    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] Error installing artifact's metadata: Error installing metadata: Error updating group repository metadata

    input contained no data
    [INFO] ------------------------------------------------------------------------
    [INFO] For more information, run Maven with the -e switch


    without actually doing any changes at the pom.xml. The problem turned out that the repository was corrupt.

    So all I had todo was to delete my project from the local build repository.

    Monday, July 13, 2009

    SetupX - bug repository

    so the first step of taking an existing project over is to setup a repository to track bugs and changes to make it easier to discover problems by the users.

    The new setupx bug repository can now be found here