Author: tchemit Date: 2012-01-25 11:50:25 +0100 (Wed, 25 Jan 2012) New Revision: 289 Url: http://forge.codelutin.com/repositories/revision/echobase/289 Log: rename EchoBaseTopiaRootContextSupplierFactory to EchoBaseTopiaRootContextFactory, introduce getTransit method on Voyage, add Transect#stratum field Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/VoyageImpl.java Removed: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java Modified: trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties trunk/echobase-entities/src/main/xmi/echobase.zargo Copied: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java (from rev 288, trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java) =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java 2012-01-25 10:50:25 UTC (rev 289) @@ -0,0 +1,148 @@ +/* + * #%L + * Extranet NF-Logement :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Cerqual + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase; + +import com.google.common.base.Supplier; +import com.google.common.collect.Sets; +import com.google.common.io.Closeables; +import fr.ifremer.echobase.entities.EchoBaseDAOHelper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.TopiaRuntimeException; +import org.nuiton.topia.replication.TopiaReplicationService; +import org.nuiton.topia.replication.TopiaReplicationServiceImpl; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.Set; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class EchoBaseTopiaRootContextFactory { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(EchoBaseTopiaRootContextFactory.class); + + protected static class EchoBaseTopiaRootContextSupplier implements Supplier<TopiaContext> { + + protected TopiaContext rootContext; + + public EchoBaseTopiaRootContextSupplier(TopiaContext rootContext) { + this.rootContext = rootContext; + } + + @Override + public TopiaContext get() { + return rootContext; + } + } + + public Supplier<TopiaContext> newEmbeddedDatabase(File dir) { + + File databaseFile = new File(dir, "db"); + + String databaseAbsolutePath = databaseFile.getAbsolutePath(); + + // prepare call to topia-context factory + Properties properties = new Properties(); + InputStream input = null; + try { + input = getClass().getResourceAsStream("/topia-h2.properties"); + properties.load(input); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + Closeables.closeQuietly(input); + } + properties.setProperty( + TopiaContextFactory.CONFIG_URL, + "jdbc:h2:file:" + databaseAbsolutePath + "/echobase"); + + // add entities to the context + properties.setProperty( + TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, + EchoBaseDAOHelper.getImplementationClassesAsString()); + + // add topiaReplicationService in the context + properties.setProperty(TopiaReplicationService.TOPIA_SERVICE_NAME, + TopiaReplicationServiceImpl.class.getName()); + + TopiaContext rootContext; + try { + rootContext = TopiaContextFactory.getContext(properties); + } catch (TopiaNotFoundException e) { + throw new TopiaRuntimeException(e); + } + + if (log.isDebugEnabled()) { + log.debug("will output database in " + databaseAbsolutePath); + } + + return new EchoBaseTopiaRootContextSupplier(rootContext); + } + + public Supplier<TopiaContext> newDatabaseFromConfig(EchoBaseConfiguration config) { + + Properties properties = config.getProperties(); + + return newDatabaseFromProperties(properties); + } + + public Supplier<TopiaContext> newDatabaseFromProperties(Properties properties) { + + if (log.isDebugEnabled()) { + log.debug("Database settings are :"); + Set<String> keysToDisplay = Sets.newHashSet( + "hibernate.dialect", + "hibernate.connection.driver_class", + "hibernate.connection.url", + "hibernate.connection.username"); + for (String key : keysToDisplay) { + log.debug(String.format("%s=%s", key, properties.getProperty(key))); + } + } + + // add entities to the context + String classesKey = TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES; + String classesValue = EchoBaseDAOHelper.getImplementationClassesAsString(); + properties.setProperty(classesKey, classesValue); + + TopiaContext rootContext; + try { + rootContext = TopiaContextFactory.getContext(properties); + } catch (TopiaNotFoundException e) { + throw new TopiaRuntimeException(e); + } + + return new EchoBaseTopiaRootContextSupplier(rootContext); + } +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java 2012-01-17 18:00:35 UTC (rev 288) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java 2012-01-25 10:50:25 UTC (rev 289) @@ -1,148 +0,0 @@ -/* - * #%L - * Extranet NF-Logement :: Entities - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Cerqual - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase; - -import com.google.common.base.Supplier; -import com.google.common.collect.Sets; -import com.google.common.io.Closeables; -import fr.ifremer.echobase.entities.EchoBaseDAOHelper; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.TopiaRuntimeException; -import org.nuiton.topia.replication.TopiaReplicationService; -import org.nuiton.topia.replication.TopiaReplicationServiceImpl; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.util.Set; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class EchoBaseTopiaRootContextSupplierFactory { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(EchoBaseTopiaRootContextSupplierFactory.class); - - protected static class EchoBaseTopiaRootContextSupplier implements Supplier<TopiaContext> { - - protected TopiaContext rootContext; - - public EchoBaseTopiaRootContextSupplier(TopiaContext rootContext) { - this.rootContext = rootContext; - } - - @Override - public TopiaContext get() { - return rootContext; - } - } - - public Supplier<TopiaContext> newEmbeddedDatabase(File dir) { - - File databaseFile = new File(dir, "db"); - - String databaseAbsolutePath = databaseFile.getAbsolutePath(); - - // prepare call to topia-context factory - Properties properties = new Properties(); - InputStream input = null; - try { - input = getClass().getResourceAsStream("/topia-h2.properties"); - properties.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - Closeables.closeQuietly(input); - } - properties.setProperty( - TopiaContextFactory.CONFIG_URL, - "jdbc:h2:file:" + databaseAbsolutePath + "/echobase"); - - // add entities to the context - properties.setProperty( - TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, - EchoBaseDAOHelper.getImplementationClassesAsString()); - - // add topiaReplicationService in the context - properties.setProperty(TopiaReplicationService.TOPIA_SERVICE_NAME, - TopiaReplicationServiceImpl.class.getName()); - - TopiaContext rootContext; - try { - rootContext = TopiaContextFactory.getContext(properties); - } catch (TopiaNotFoundException e) { - throw new TopiaRuntimeException(e); - } - - if (log.isDebugEnabled()) { - log.debug("will output database in " + databaseAbsolutePath); - } - - return new EchoBaseTopiaRootContextSupplier(rootContext); - } - - public Supplier<TopiaContext> newDatabaseFromConfig(EchoBaseConfiguration config) { - - Properties properties = config.getProperties(); - - return newDatabaseFromProperties(properties); - } - - public Supplier<TopiaContext> newDatabaseFromProperties(Properties properties) { - - if (log.isDebugEnabled()) { - log.debug("Database settings are :"); - Set<String> keysToDisplay = Sets.newHashSet( - "hibernate.dialect", - "hibernate.connection.driver_class", - "hibernate.connection.url", - "hibernate.connection.username"); - for (String key : keysToDisplay) { - log.debug(String.format("%s=%s", key, properties.getProperty(key))); - } - } - - // add entities to the context - String classesKey = TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES; - String classesValue = EchoBaseDAOHelper.getImplementationClassesAsString(); - properties.setProperty(classesKey, classesValue); - - TopiaContext rootContext; - try { - rootContext = TopiaContextFactory.getContext(properties); - } catch (TopiaNotFoundException e) { - throw new TopiaRuntimeException(e); - } - - return new EchoBaseTopiaRootContextSupplier(rootContext); - } -} Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/VoyageImpl.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/VoyageImpl.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/VoyageImpl.java 2012-01-25 10:50:25 UTC (rev 289) @@ -0,0 +1,65 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.entities.data; + +import org.apache.commons.collections.CollectionUtils; + +import java.util.Date; + +/** + * Default implementation of {@link Voyage}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class VoyageImpl extends VoyageAbstract { + + private static final long serialVersionUID = 1L; + + @Override + public Transit getTransit(Date startTime, Date endDate) { + + Transit result = null; + if (CollectionUtils.isNotEmpty(getTransit())) { + for (Transit t : getTransit()) { + Date transitStartTime = t.getStartTime(); + Date transitEndTime = t.getEndTime(); + if (transitEndTime.before(startTime)) { + // transit before required range + continue; + } + if (transitStartTime.after(endDate)) { + + // transit after required range + continue; + } + + // ok transit contains required range + result = t; + break; + } + } + return result; + } +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/VoyageImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties =================================================================== --- trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2012-01-17 18:00:35 UTC (rev 288) +++ trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2012-01-25 10:50:25 UTC (rev 289) @@ -217,6 +217,7 @@ echobase.common.startTime= echobase.common.status= echobase.common.strata= +echobase.common.stratum= echobase.common.swimbladder= echobase.common.swimbladderType= echobase.common.taxonCode= Modified: trunk/echobase-entities/src/main/xmi/echobase.zargo =================================================================== (Binary files differ)