Echobase-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
November 2011
- 3 participants
- 137 discussions
r119 - in trunk: echobase-entities/src/main/java/fr/ifremer/echobase/entities echobase-entities/src/main/resources/i18n echobase-entities/src/main/xmi echobase-entities/src/test/java/fr/ifremer/echobase echobase-entities/src/test/java/fr/ifremer/echobase/entities echobase-services/src/main/java/fr/ifremer/echobase/services
by tchemit@users.forge.codelutin.com 25 Nov '11
by tchemit@users.forge.codelutin.com 25 Nov '11
25 Nov '11
Author: tchemit
Date: 2011-11-25 10:00:46 +0100 (Fri, 25 Nov 2011)
New Revision: 119
Url: http://forge.codelutin.com/repositories/revision/echobase/119
Log:
- fix model (some properties are reserved keyword on pg)
- add tests
- prune some empty directories
Added:
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java
Removed:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java
trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties
trunk/echobase-entities/src/main/xmi/echobase.zargo
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-11-24 23:43:49 UTC (rev 118)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-11-25 09:00:46 UTC (rev 119)
@@ -24,9 +24,7 @@
package fr.ifremer.echobase.entities;
import com.google.common.collect.Lists;
-import org.nuiton.topia.persistence.TopiaEntity;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -38,11 +36,13 @@
public class EntitiesUtil {
/**
- * @return the entity types of reference in correct order for replication
+ * @return the entity types of data in correct order for replication
* purpose.
*/
- public static EchoBaseEntityEnum[] getReferenceTypes() {
+ public static EchoBaseEntityEnum[] getDataTypes() {
+
List<EchoBaseEntityEnum> result = Lists.newLinkedList();
+
result.add(EchoBaseEntityEnum.Voyage);
result.add(EchoBaseEntityEnum.Echotype);
result.add(EchoBaseEntityEnum.EchotypeDepthStratum);
@@ -69,10 +69,10 @@
}
/**
- * @return the entity types of data in correct order for replication
+ * @return the entity types of reference in correct order for replication
* purpose.
*/
- public static EchoBaseEntityEnum[] getDataTypes() {
+ public static EchoBaseEntityEnum[] getReferenceTypes() {
List<EchoBaseEntityEnum> result = Lists.newLinkedList();
result.add(EchoBaseEntityEnum.Mission);
result.add(EchoBaseEntityEnum.AcousticInstrument);
@@ -97,7 +97,6 @@
result.add(EchoBaseEntityEnum.Localisation);
result.add(EchoBaseEntityEnum.MeasurementMetadata);
result.add(EchoBaseEntityEnum.MeasureType);
- result.add(EchoBaseEntityEnum.Mission);
result.add(EchoBaseEntityEnum.OperationMetadata);
result.add(EchoBaseEntityEnum.OperationType);
result.add(EchoBaseEntityEnum.ReferenceDatum);
@@ -108,23 +107,5 @@
return result.toArray(new EchoBaseEntityEnum[result.size()]);
}
- /**
- * Used to get all contract of a package
- *
- * @param entitiesPackage package contening desired entities
- * @return contracts contained in entitiesPackage
- */
- public static EchoBaseEntityEnum[] getContractsOf(Package entitiesPackage) {
- EchoBaseEntityEnum[] echoBaseEntityEnums = EchoBaseEntityEnum.values();
- List<EchoBaseEntityEnum> refClasses = new ArrayList<EchoBaseEntityEnum>();
- for (EchoBaseEntityEnum echoBaseEntityEnum : echoBaseEntityEnums) {
- // Get all entities in package fr.ifremer.echobase.entities.references
- Class<? extends TopiaEntity> contract = echoBaseEntityEnum.getContract();
- if (contract.getPackage().equals(entitiesPackage)) {
- refClasses.add(echoBaseEntityEnum);
- }
- }
- return refClasses.toArray(new EchoBaseEntityEnum[refClasses.size()]);
- }
}
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java 2011-11-24 23:43:49 UTC (rev 118)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java 2011-11-25 09:00:46 UTC (rev 119)
@@ -40,7 +40,7 @@
result.setEntityId(getEntityId());
result.setModificationDate(getModificationDate());
result.setModificationText(getModificationText());
- result.setUser(getUser().toDTO());
+ result.setModificationUser(getModificationUser().toDTO());
return result;
}
}
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 2011-11-24 23:43:49 UTC (rev 118)
+++ trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2011-11-25 09:00:46 UTC (rev 119)
@@ -160,8 +160,10 @@
echobase.common.mission=mission
echobase.common.missionAbstract=
echobase.common.missionName=
+echobase.common.missionReferences=
echobase.common.modificationDate=Date de modification
echobase.common.modificationText=Modification
+echobase.common.modificationUser=
echobase.common.name=Nom
echobase.common.notes=
echobase.common.numberAtAge=
Modified: trunk/echobase-entities/src/main/xmi/echobase.zargo
===================================================================
(Binary files differ)
Added: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java
===================================================================
--- trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java (rev 0)
+++ trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java 2011-11-25 09:00:46 UTC (rev 119)
@@ -0,0 +1,74 @@
+package fr.ifremer.echobase.entities;
+
+import com.google.common.collect.Lists;
+import fr.ifremer.echobase.entities.data.Voyage;
+import fr.ifremer.echobase.entities.references.Mission;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * To test the class {@link EntitiesUtil}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class EntitiesUtilTest {
+
+ @Test
+ public void getReferenceTypes() {
+
+ EchoBaseEntityEnum[] types = EntitiesUtil.getReferenceTypes();
+
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(getContractsOf(Mission.class.getPackage()));
+
+ Assert.assertNotNull(types);
+ Assert.assertEquals(expectedTypes.size(), types.length);
+
+ for (EchoBaseEntityEnum referenceType : types) {
+ Assert.assertTrue("Missing type : " + referenceType,
+ expectedTypes.contains(referenceType));
+ }
+ }
+
+ @Test
+ public void getDataTypes() {
+
+ EchoBaseEntityEnum[] types = EntitiesUtil.getDataTypes();
+
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(getContractsOf(Voyage.class.getPackage()));
+
+ Assert.assertNotNull(types);
+ Assert.assertEquals(expectedTypes.size(), types.length);
+
+ for (EchoBaseEntityEnum referenceType : types) {
+ Assert.assertTrue("Missing type : " + referenceType,
+ expectedTypes.contains(referenceType));
+ }
+ }
+
+ /**
+ * Used to get all contract of a package
+ *
+ * @param entitiesPackage package contening desired entities
+ * @return contracts contained in entitiesPackage
+ */
+ public static EchoBaseEntityEnum[] getContractsOf(Package entitiesPackage) {
+ EchoBaseEntityEnum[] echoBaseEntityEnums = EchoBaseEntityEnum.values();
+ List<EchoBaseEntityEnum> refClasses = new ArrayList<EchoBaseEntityEnum>();
+ for (EchoBaseEntityEnum echoBaseEntityEnum : echoBaseEntityEnums) {
+
+ // Get all entities in package fr.ifremer.echobase.entities.references
+ Class<? extends TopiaEntity> contract = echoBaseEntityEnum.getContract();
+ if (entitiesPackage.equals(contract.getPackage())) {
+ refClasses.add(echoBaseEntityEnum);
+ }
+ }
+ return refClasses.toArray(new EchoBaseEntityEnum[refClasses.size()]);
+ }
+}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-24 23:43:49 UTC (rev 118)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-25 09:00:46 UTC (rev 119)
@@ -427,7 +427,7 @@
dao.create(
EntityModificationLog.PROPERTY_ENTITY_TYPE, tableMeta.getEntityEnum().name(),
EntityModificationLog.PROPERTY_ENTITY_ID, topiaId,
- EntityModificationLog.PROPERTY_USER, user,
+ EntityModificationLog.PROPERTY_MODIFICATION_USER, user,
EntityModificationLog.PROPERTY_MODIFICATION_DATE, newDate(),
EntityModificationLog.PROPERTY_MODIFICATION_TEXT, buffer.toString()
);
1
0
Author: tchemit
Date: 2011-11-25 00:43:49 +0100 (Fri, 25 Nov 2011)
New Revision: 118
Url: http://forge.codelutin.com/repositories/revision/echobase/118
Log:
optimize dependencies
Modified:
trunk/echobase-entities/pom.xml
Modified: trunk/echobase-entities/pom.xml
===================================================================
--- trunk/echobase-entities/pom.xml 2011-11-24 23:42:22 UTC (rev 117)
+++ trunk/echobase-entities/pom.xml 2011-11-24 23:43:49 UTC (rev 118)
@@ -56,10 +56,10 @@
<artifactId>commons-collections</artifactId>
</dependency-->
- <dependency>
+ <!--dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- </dependency>
+ </dependency-->
<dependency>
<groupId>com.google.guava</groupId>
1
0
24 Nov '11
Author: tchemit
Date: 2011-11-25 00:42:22 +0100 (Fri, 25 Nov 2011)
New Revision: 117
Url: http://forge.codelutin.com/repositories/revision/echobase/117
Log:
- do not expose entities module as test just to obtain basedir :(
- avoid to create a class for one method
- do NOT use a none hand build entity types for replication
- optimize dependencies
Added:
trunk/echobase-services/src/test/java/fr/ifremer/echobase/TestHelper.java
Removed:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java
Modified:
trunk/echobase-entities/pom.xml
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
trunk/echobase-services/pom.xml
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
trunk/echobase-ui/pom.xml
Modified: trunk/echobase-entities/pom.xml
===================================================================
--- trunk/echobase-entities/pom.xml 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-entities/pom.xml 2011-11-24 23:42:22 UTC (rev 117)
@@ -54,12 +54,12 @@
<!--dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
- </dependency>
+ </dependency-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- </dependency-->
+ </dependency>
<dependency>
<groupId>com.google.guava</groupId>
@@ -132,19 +132,8 @@
<build>
<plugins>
+
<plugin>
- <artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-test</id>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
<groupId>org.nuiton.eugene</groupId>
<artifactId>maven-eugene-plugin</artifactId>
<configuration>
@@ -212,13 +201,6 @@
</plugins>
- <testResources>
- <testResource>
- <directory>${maven.src.dir}/test/resources</directory>
- <filtering>true</filtering>
- </testResource>
- </testResources>
-
</build>
</project>
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-11-24 23:42:22 UTC (rev 117)
@@ -23,13 +23,14 @@
*/
package fr.ifremer.echobase.entities;
+import com.google.common.collect.Lists;
import org.nuiton.topia.persistence.TopiaEntity;
import java.util.ArrayList;
import java.util.List;
/**
- * Utility method for enities
+ * Utility method for entities.
*
* @author sletellier <letellier(a)codelutin.com>
* @since 0.2
@@ -37,6 +38,77 @@
public class EntitiesUtil {
/**
+ * @return the entity types of reference in correct order for replication
+ * purpose.
+ */
+ public static EchoBaseEntityEnum[] getReferenceTypes() {
+ List<EchoBaseEntityEnum> result = Lists.newLinkedList();
+ result.add(EchoBaseEntityEnum.Voyage);
+ result.add(EchoBaseEntityEnum.Echotype);
+ result.add(EchoBaseEntityEnum.EchotypeDepthStratum);
+ result.add(EchoBaseEntityEnum.Transit);
+ result.add(EchoBaseEntityEnum.TransitVessel);
+ result.add(EchoBaseEntityEnum.Transect);
+ result.add(EchoBaseEntityEnum.TransectAcousticInstrument);
+ result.add(EchoBaseEntityEnum.DataAcquisition);
+ result.add(EchoBaseEntityEnum.DataProcessing);
+ result.add(EchoBaseEntityEnum.Cell);
+ result.add(EchoBaseEntityEnum.Data);
+ result.add(EchoBaseEntityEnum.Operation);
+ result.add(EchoBaseEntityEnum.OperationMetadataValue);
+ result.add(EchoBaseEntityEnum.OperationMeasurementMetadataValue);
+ result.add(EchoBaseEntityEnum.Individual);
+ result.add(EchoBaseEntityEnum.OperationGearMetadataValue);
+ result.add(EchoBaseEntityEnum.Sample);
+ result.add(EchoBaseEntityEnum.SampleAge);
+ result.add(EchoBaseEntityEnum.SampleLength);
+ result.add(EchoBaseEntityEnum.SampleAggregation);
+ result.add(EchoBaseEntityEnum.AggregationLevel);
+
+ return result.toArray(new EchoBaseEntityEnum[result.size()]);
+ }
+
+ /**
+ * @return the entity types of data in correct order for replication
+ * purpose.
+ */
+ public static EchoBaseEntityEnum[] getDataTypes() {
+ List<EchoBaseEntityEnum> result = Lists.newLinkedList();
+ result.add(EchoBaseEntityEnum.Mission);
+ result.add(EchoBaseEntityEnum.AcousticInstrument);
+ result.add(EchoBaseEntityEnum.AreaOfOperation);
+ result.add(EchoBaseEntityEnum.Calibration);
+ result.add(EchoBaseEntityEnum.Category);
+ result.add(EchoBaseEntityEnum.CategoryMeaning);
+ result.add(EchoBaseEntityEnum.CategoryRef);
+ result.add(EchoBaseEntityEnum.CategoryType);
+ result.add(EchoBaseEntityEnum.CellMethod);
+ result.add(EchoBaseEntityEnum.CellType);
+ result.add(EchoBaseEntityEnum.DataMetadata);
+ result.add(EchoBaseEntityEnum.DataMetadataName);
+ result.add(EchoBaseEntityEnum.DataQuality);
+ result.add(EchoBaseEntityEnum.DepthStratum);
+ result.add(EchoBaseEntityEnum.DepthStratumType);
+ result.add(EchoBaseEntityEnum.Gear);
+ result.add(EchoBaseEntityEnum.GearMetadata);
+ result.add(EchoBaseEntityEnum.GearMetadataValue);
+ result.add(EchoBaseEntityEnum.GearType);
+ result.add(EchoBaseEntityEnum.Impacte);
+ result.add(EchoBaseEntityEnum.Localisation);
+ result.add(EchoBaseEntityEnum.MeasurementMetadata);
+ result.add(EchoBaseEntityEnum.MeasureType);
+ result.add(EchoBaseEntityEnum.Mission);
+ result.add(EchoBaseEntityEnum.OperationMetadata);
+ result.add(EchoBaseEntityEnum.OperationType);
+ result.add(EchoBaseEntityEnum.ReferenceDatum);
+ result.add(EchoBaseEntityEnum.ReferencingMethod);
+ result.add(EchoBaseEntityEnum.Species);
+ result.add(EchoBaseEntityEnum.Station);
+ result.add(EchoBaseEntityEnum.Vessel);
+ return result.toArray(new EchoBaseEntityEnum[result.size()]);
+ }
+
+ /**
* Used to get all contract of a package
*
* @param entitiesPackage package contening desired entities
Deleted: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java 2011-11-24 23:42:22 UTC (rev 117)
@@ -1,45 +0,0 @@
-/*
- * #%L
- * EchoBase :: Entities
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 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 fr.ifremer.echobase.entities.EchoBaseEntityEnum;
-import fr.ifremer.echobase.entities.EntitiesUtil;
-
-/**
- * Data method utility
- *
- * @author sletellier <letellier(a)codelutin.com>
- * @since 0.2
- */
-public class DataUtil {
-
- /**
- * Used to get all contract of a data package
- *
- * @return contracts in package data
- */
- public static EchoBaseEntityEnum[] getDataContracts() {
- return EntitiesUtil.getContractsOf(DataUtil.class.getPackage());
- }
-}
Deleted: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java 2011-11-24 23:42:22 UTC (rev 117)
@@ -1,45 +0,0 @@
-/*
- * #%L
- * EchoBase :: Entities
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 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.references;
-
-import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
-import fr.ifremer.echobase.entities.EntitiesUtil;
-
-/**
- * References method utility
- *
- * @author sletellier <letellier(a)codelutin.com>
- * @since 0.2
- */
-public class ReferencesUtil {
-
- /**
- * Used to get all contract of a referenciel package
- *
- * @return contracts in package referenciel
- */
- public static EchoBaseEntityEnum[] getReferencielContracts() {
- return EntitiesUtil.getContractsOf(ReferencesUtil.class.getPackage());
- }
-}
Deleted: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java
===================================================================
--- trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java 2011-11-24 23:42:22 UTC (rev 117)
@@ -1,54 +0,0 @@
-/*
- * #%L
- * EchoBase :: Entities
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 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;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Ignore;
-
-import java.io.File;
-
-/**
- * Utility methods for tests
- *
- * @author sletellier <letellier(a)codelutin.com>
- * @since 0.2
- */
-@Ignore
-public class TestHelper {
-
- protected static File basedir;
-
- public static File getBasedir() {
- if (basedir == null) {
-// String tmp = System.getProperty("basedir");
-// if (tmp == null) {
-// tmp = new File("").getAbsolutePath();
-// }
-// basedir = new File(tmp);
- basedir = FileUtils.getTempDirectory();
- }
- return basedir;
- }
-
-}
Modified: trunk/echobase-services/pom.xml
===================================================================
--- trunk/echobase-services/pom.xml 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-services/pom.xml 2011-11-24 23:42:22 UTC (rev 117)
@@ -24,14 +24,6 @@
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>echobase-entities</artifactId>
- <version>${project.version}</version>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
-
<!--dependency>
<groupId>fr.ird</groupId>
<artifactId>msaccess-importer</artifactId>
@@ -51,10 +43,10 @@
<artifactId>nuiton-csv</artifactId>
</dependency>
- <!--dependency>
+ <dependency>
<groupId>org.nuiton.i18n</groupId>
<artifactId>nuiton-i18n</artifactId>
- </dependency-->
+ </dependency>
<!-- comons dependencies -->
@@ -68,10 +60,10 @@
<artifactId>xwork-core</artifactId>
</dependency-->
- <!--dependency>
+ <dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
- </dependency-->
+ </dependency>
<dependency>
<groupId>commons-logging</groupId>
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-11-24 23:42:22 UTC (rev 117)
@@ -28,9 +28,8 @@
import fr.ifremer.echobase.EchoBaseTopiaRootContextSupplierFactory;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
+import fr.ifremer.echobase.entities.EntitiesUtil;
import fr.ifremer.echobase.entities.ExportQuery;
-import fr.ifremer.echobase.entities.data.DataUtil;
-import fr.ifremer.echobase.entities.references.ReferencesUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
@@ -251,7 +250,7 @@
protected void replicateVoyages(TopiaContext topiaContextDest, String... voyagesIds) throws TopiaException {
TopiaReplicationService service = getTransaction().getService(TopiaReplicationService.class);
- ReplicationModel replicationModel = service.prepare(DataUtil.getDataContracts(), true, voyagesIds);
+ ReplicationModel replicationModel = service.prepare(EntitiesUtil.getDataTypes(), true, voyagesIds);
try {
service.doReplicate(replicationModel, topiaContextDest);
} catch (Exception eee) {
@@ -263,7 +262,7 @@
protected void replicateReferentiel(TopiaContext topiaContextDest) throws TopiaException {
// Get all referenciel contracts
- EchoBaseEntityEnum[] referencielClass = ReferencesUtil.getReferencielContracts();
+ EchoBaseEntityEnum[] referencielClass = EntitiesUtil.getReferenceTypes();
TopiaReplicationService service = getTransaction().getService(TopiaReplicationService.class);
ReplicationModel replicationModel = service.prepareForAll(referencielClass);
try {
Copied: trunk/echobase-services/src/test/java/fr/ifremer/echobase/TestHelper.java (from rev 116, trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java)
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/TestHelper.java (rev 0)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/TestHelper.java 2011-11-24 23:42:22 UTC (rev 117)
@@ -0,0 +1,56 @@
+/*
+ * #%L
+ * EchoBase :: Entities
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Ignore;
+
+import java.io.File;
+
+/**
+ * Utility methods for tests
+ *
+ * @author sletellier <letellier(a)codelutin.com>
+ * @since 0.2
+ */
+@Ignore
+public class TestHelper {
+
+ protected static File basedir;
+
+ public static File getBasedir() {
+ //FIXME : No we do not want to go in tmp directory :( We want to stay
+ // inside of the project. So a mvn clean will remove all tests data.
+ if (basedir == null) {
+// String tmp = System.getProperty("basedir");
+// if (tmp == null) {
+// tmp = new File("").getAbsolutePath();
+// }
+// basedir = new File(tmp);
+ basedir = FileUtils.getTempDirectory();
+ }
+ return basedir;
+ }
+
+}
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java 2011-11-24 23:42:22 UTC (rev 117)
@@ -47,7 +47,8 @@
public class MockEntityVisitorCreator implements EntityVisitor {
/** Logger. */
- private static final Log log = LogFactory.getLog(MockEntityVisitorCreator.class);
+ private static final Log log =
+ LogFactory.getLog(MockEntityVisitorCreator.class);
protected TopiaContext transaction;
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java 2011-11-24 23:42:22 UTC (rev 117)
@@ -57,7 +57,6 @@
@After
public void after() throws TopiaException {
if (transaction != null && !transaction.isClosed()) {
- transaction.rollbackTransaction();
transaction.closeContext();
}
}
Modified: trunk/echobase-ui/pom.xml
===================================================================
--- trunk/echobase-ui/pom.xml 2011-11-24 23:06:43 UTC (rev 116)
+++ trunk/echobase-ui/pom.xml 2011-11-24 23:42:22 UTC (rev 117)
@@ -135,6 +135,11 @@
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
1
0
24 Nov '11
Author: tchemit
Date: 2011-11-25 00:06:43 +0100 (Fri, 25 Nov 2011)
New Revision: 116
Url: http://forge.codelutin.com/repositories/revision/echobase/116
Log:
- cinematic for import data
- use generic dao methods in services
- add svn properties
- add topia connection provider in configuration (there is still some problems in pg)
Added:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage-validation.xml
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureFiles.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureVoyage.jsp
Removed:
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.java
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/ImportAction-doImport-validation.xml
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java
trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchoBaseService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java
trunk/echobase-services/src/main/resources/embedded/startEchobase.bat
trunk/echobase-services/src/main/resources/embedded/startEchobase.sh
trunk/echobase-services/src/main/resources/i18n/echobase-services_fr_FR.properties
trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java
trunk/echobase-services/src/test/resources/echobase.properties
trunk/echobase-ui/pom.xml
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/CreateEmbeddedApplication.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java
trunk/echobase-ui/src/main/resources/config/struts-import.xml
trunk/echobase-ui/src/main/resources/echobase.properties
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/export/ManageExportQuery-saveExportQuery-validation.xml
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/user/LoginAction-login-validation.xml
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/user/ManageUser-validation.xml
trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties
trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/importProgress.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/importResult.jsp
trunk/pom.xml
trunk/src/doc/reunions/reunion-2011-11-15.txt
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -113,8 +113,8 @@
return file;
}
- public char getCsvCharSeparator() {
- char csvSeparator = applicationConfig.getOption(char.class, EchoBaseConfigurationOption.CSV_CHAR_SEPARATOR.key);
+ public char getCsvSeparator() {
+ char csvSeparator = applicationConfig.getOption(char.class, EchoBaseConfigurationOption.CSV_SEPARATOR.key);
Preconditions.checkNotNull(csvSeparator);
return csvSeparator;
}
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -50,7 +50,7 @@
SITE_URL("project.siteUrl",
"URL du site de l'application",
"", URL.class),
- CSV_CHAR_SEPARATOR("csv.separator",
+ CSV_SEPARATOR("csv.separator",
"Caractère de séparation pour les fichiers csv",
";", char.class),
WAR_DIRECTORY("war.directory",
Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.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 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2011-11-24 23:06:43 UTC (rev 116)
@@ -61,7 +61,7 @@
echobase.common.dataQualityFlagValue=
echobase.common.dataValue=
echobase.common.dateCreated=
-echobase.common.datum=
+echobase.common.datum=datum
echobase.common.depthStratum=depthStratum
echobase.common.depthStratumId=
echobase.common.depthStratumMeaning=
@@ -283,11 +283,11 @@
echobase.common.vesselTransit=
echobase.common.vesselType=
echobase.common.voyage=Campagne
-echobase.common.voyageDescription=
-echobase.common.voyageEndDate=
-echobase.common.voyageEndHarbour=
-echobase.common.voyageName=
-echobase.common.voyageStartDate=
-echobase.common.voyageStartHarbour=
+echobase.common.voyageDescription=Description de campagne
+echobase.common.voyageEndDate=Date de fin de campagne
+echobase.common.voyageEndHarbour=Port de fin de campagne
+echobase.common.voyageName=Nom de la campagne
+echobase.common.voyageStartDate=Date de début de campagne
+echobase.common.voyageStartHarbour=Port de début de campagne
echobase.common.weight=
echobase.config.data.directory.description=Chemin de l'application
Property changes on: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,86 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * Object to receive a uploaded file.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class InputFile implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Name of the file (from the client side). */
+ protected String fileName;
+
+ /** Location of the uploaded file (from the server side). */
+ protected File file;
+
+ /** Content type of the uploaded file. */
+ protected String contentType;
+
+ /** Label of the import. */
+ protected String label;
+
+ public InputFile(String label) {
+ this.label = label;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchoBaseService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchoBaseService.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchoBaseService.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -23,11 +23,13 @@
*/
package fr.ifremer.echobase.services;
+import com.google.common.base.Preconditions;
import fr.ifremer.echobase.EchoBaseConfiguration;
import fr.ifremer.echobase.EchoBaseTechnicalException;
import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.meta.DbMeta;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
@@ -35,6 +37,7 @@
import org.nuiton.topia.persistence.TopiaEntity;
import java.util.Date;
+import java.util.List;
import java.util.Locale;
/**
@@ -50,6 +53,30 @@
this.serviceContext = serviceContext;
}
+ public <E extends TopiaEntity> List<E> getEntities(Class<E> entityType) {
+ Preconditions.checkNotNull(entityType);
+ try {
+ List<E> result = getDAO(entityType).findAll();
+ return result;
+ } catch (TopiaException eee) {
+ throw new EchoBaseTechnicalException(
+ "Could not obtain data for type " + entityType, eee);
+ }
+ }
+
+ public <E extends TopiaEntity> E getEntityById(Class<E> entityType, String id) {
+ Preconditions.checkNotNull(entityType);
+ Preconditions.checkArgument(StringUtils.isNotEmpty(id));
+ try {
+ E result = getDAO(entityType).findByTopiaId(id);
+ return result;
+ } catch (TopiaException eee) {
+ throw new EchoBaseTechnicalException(
+ "Could not obtain data of id [" + id + "] for type " +
+ entityType, eee);
+ }
+ }
+
protected TopiaContext getTransaction() {
return serviceContext.getTransaction();
}
@@ -94,7 +121,7 @@
protected Date newDate() {
Date result = new Date();
- DateUtils.setMilliseconds(result,0);
+ DateUtils.setMilliseconds(result, 0);
return result;
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -461,7 +461,7 @@
protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForImport(TableMeta tableMetas) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvCharSeparator(),
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvSeparator(),
tableMetas);
ModelBuilder<E> modelBuilder = model.modelBuilder;
@@ -488,7 +488,7 @@
protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForSave(TableMeta tableMetas) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvCharSeparator(),
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvSeparator(),
tableMetas);
ModelBuilder<E> modelBuilder = model.modelBuilder;
@@ -519,7 +519,7 @@
protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForExport(TableMeta tableMetas) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvCharSeparator(),
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvSeparator(),
tableMetas);
ModelBuilder<E> modelBuilder = model.modelBuilder;
@@ -546,7 +546,7 @@
protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForLoad(TableMeta tableMetas,
boolean addDecorated) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvCharSeparator(),
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvSeparator(),
tableMetas);
ModelBuilder<E> modelBuilder = model.modelBuilder;
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -140,7 +140,7 @@
for (StartFiles startFile : StartFiles.values()) {
InputStream inputStream =
- getClass().getResourceAsStream(startFile.getFilePath());
+ getClass().getResourceAsStream(startFile.getFilePath());
File startFileDest = new File(zipDirectory, startFile.getFileName());
OutputStream outputStream = new FileOutputStream(startFileDest);
@@ -172,7 +172,7 @@
}
protected TopiaContext createH2Batabase(File zipDirectory,
- String... voyageIds) throws IOException, TopiaException {
+ String... voyageIds) throws IOException, TopiaException {
return createH2Batabase(zipDirectory, true, voyageIds);
}
@@ -212,7 +212,7 @@
newService(ExportSqlService.class);
// get all export queries from application
- List<ExportQuery> queries = exportSqlService.getQueries();
+ List<ExportQuery> queries = exportSqlService.getEntities(ExportQuery.class);
// remove link to application user
for (ExportQuery query : queries) {
@@ -227,7 +227,7 @@
newServiceContext.newService(ExportSqlService.class);
// get all queries from h2 db
- queries = exportSqlService.getQueries();
+ queries = exportSqlService.getEntities(ExportQuery.class);
// attach them to default created admin user in the db
for (ExportQuery query : queries) {
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -24,10 +24,8 @@
package fr.ifremer.echobase.services;
import fr.ifremer.echobase.EchoBaseTechnicalException;
-import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.ExportQuery;
-import fr.ifremer.echobase.entities.ExportQueryDAO;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -35,6 +33,7 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaSQLQuery;
+import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.util.csv.Export;
import java.sql.Connection;
@@ -55,28 +54,10 @@
/** Logger. */
private static final Log log = LogFactory.getLog(ExportSqlService.class);
- public List<ExportQuery> getQueries() {
+ public ExportQuery createOrUpdate(ExportQuery exportQuery,
+ EchoBaseUser user) {
try {
- List<ExportQuery> result = getDAO().findAll();
- return result;
- } catch (TopiaException eee) {
- throw new EchoBaseTechnicalException("Could not obtain export queries", eee);
- }
- }
-
- public ExportQuery getQueryById(String queryId) {
-
- try {
- ExportQuery result = getDAO().findByTopiaId(queryId);
- return result;
- } catch (TopiaException eee) {
- throw new EchoBaseTechnicalException("Could not obtain export query with id " + queryId, eee);
- }
- }
-
- public ExportQuery createOrUpdate(ExportQuery exportQuery, EchoBaseUser user) {
- try {
- ExportQueryDAO dao = getDAO();
+ TopiaDAO<ExportQuery> dao = getDAO(ExportQuery.class);
ExportQuery entityToSave;
// No id, creating new one entity
@@ -103,7 +84,7 @@
public void delete(String topiaId) {
try {
- ExportQueryDAO dao = getDAO();
+ TopiaDAO<ExportQuery> dao = getDAO(ExportQuery.class);
ExportQuery entityToDelete = dao.findByTopiaId(topiaId);
dao.delete(entityToDelete);
@@ -118,7 +99,8 @@
// get a query to count all rows for the request
GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, pager);
try {
- List<Map<String, Object>> result = sqlQuery.getResult(getTransaction());
+ List<Map<String, Object>> result =
+ sqlQuery.getResult(getTransaction());
return result.toArray(new Map[result.size()]);
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException("Could not execute sql query", eee);
@@ -152,22 +134,17 @@
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException("Could not execute sql query", eee);
}
- ExportSqlCsvModel csvModel = sqlQuery.generateCsvModel(getConfiguration().getCsvCharSeparator());
+ char csvSeparator = getConfiguration().getCsvSeparator();
+ ExportSqlCsvModel csvModel = sqlQuery.generateCsvModel(csvSeparator);
Export<Map<String, Object>> exporter = Export.newExport(csvModel, rows);
- String content = null;
try {
- content = exporter.startExportAsString();
+ String content = exporter.startExportAsString();
return content;
} catch (Exception eee) {
throw new EchoBaseTechnicalException("Could not export sql", eee);
}
-
}
- protected ExportQueryDAO getDAO() throws TopiaException {
- return EchoBaseDAOHelper.getExportQueryDAO(getTransaction());
- }
-
private static class GenericSQLQuery extends TopiaSQLQuery<Map<String, Object>> {
protected String[] columnNames;
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,134 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.services;
+
+import fr.ifremer.echobase.InputFile;
+import fr.ifremer.echobase.entities.data.Voyage;
+
+import java.io.Serializable;
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+
+/**
+ * Configuration of an import data action.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ImportDataConfiguration implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Voyage used for the import (may not be in db if needed to be created). */
+ protected Voyage voyage;
+
+ protected InputFile acousticFile;
+
+ protected InputFile captureFile;
+
+ protected InputFile lectureAgeGenFile;
+
+ protected InputFile eventsFile;
+
+ protected InputFile typeEchoSpeciesFile;
+
+ protected int nbSteps;
+
+ private float stepIncrement;
+
+ protected float progression;
+
+ public ImportDataConfiguration(Locale locale) {
+ acousticFile = new InputFile(l_(locale, "echobase.common.acousticImport"));
+ captureFile = new InputFile(l_(locale, "echobase.common.captureImport"));
+ lectureAgeGenFile = new InputFile(l_(locale, "echobase.common.lectureAgeGenImport"));
+ eventsFile = new InputFile(l_(locale, "echobase.common.eventsImport"));
+ typeEchoSpeciesFile = new InputFile(l_(locale, "echobase.common.typeEchoSpeciesImport"));
+ }
+
+ public Voyage getVoyage() {
+ return voyage;
+ }
+
+ public InputFile getAcousticFile() {
+ return acousticFile;
+ }
+
+ public InputFile getCaptureFile() {
+ return captureFile;
+ }
+
+ public InputFile getLectureAgeGenFile() {
+ return lectureAgeGenFile;
+ }
+
+ public InputFile getEventsFile() {
+ return eventsFile;
+ }
+
+ public InputFile getTypeEchoSpeciesFile() {
+ return typeEchoSpeciesFile;
+ }
+
+ public int getNbSteps() {
+ return nbSteps;
+ }
+
+ public float getProgression() {
+ return progression;
+ }
+
+ public void setVoyage(Voyage voyage) {
+ this.voyage = voyage;
+ }
+
+ public void setProgression(float progression) {
+ this.progression = progression;
+ }
+
+ public void incrementsProgression() {
+ setProgression(progression + stepIncrement);
+ }
+
+ public void computeSteps() {
+ nbSteps = 0;
+ if (acousticFile.getFile() != null) {
+ nbSteps++;
+ }
+ if (captureFile.getFile() != null) {
+ nbSteps++;
+ }
+ if (lectureAgeGenFile.getFile() != null) {
+ nbSteps++;
+ }
+ if (eventsFile.getFile() != null) {
+ nbSteps++;
+ }
+ if (typeEchoSpeciesFile.getFile() != null) {
+ nbSteps++;
+ }
+ stepIncrement = 100f / nbSteps;
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,198 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.services;
+
+import com.google.common.collect.Maps;
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import fr.ifremer.echobase.InputFile;
+import fr.ifremer.echobase.entities.data.Voyage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * Service to import datas.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ImportDataService extends AbstractEchoBaseService {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ImportDataService.class);
+
+ public Map<InputFile, CsvImportResult> startImport(ImportDataConfiguration configuration) {
+
+ Map<InputFile, CsvImportResult> result = Maps.newHashMap();
+
+ Voyage voyage = configuration.getVoyage();
+
+ // compute nb step to treate (means nb imports to do)
+ configuration.computeSteps();
+
+ if (log.isInfoEnabled()) {
+ log.info("Starts data import with voyage " +
+ voyage.getVoyageName());
+ }
+
+ InputFile acousticFile = configuration.getAcousticFile();
+ if (acousticFile.getFile() != null) {
+
+ // do acoustic import
+ try {
+ CsvImportResult importResult = importAcoustic(voyage, acousticFile);
+ configuration.incrementsProgression();
+ result.put(acousticFile, importResult);
+ } finally {
+ deleteFile(acousticFile);
+ }
+ }
+
+ InputFile captureFile = configuration.getCaptureFile();
+ if (captureFile.getFile() != null) {
+
+ // do capture import
+ try {
+ CsvImportResult importResult = importCapture(voyage, captureFile);
+ configuration.incrementsProgression();
+ result.put(captureFile, importResult);
+ } finally {
+ deleteFile(captureFile);
+ }
+ }
+
+ InputFile eventsFile = configuration.getEventsFile();
+ if (eventsFile.getFile() != null) {
+
+ // do events import
+ try {
+ CsvImportResult importResult = importEvents(voyage, eventsFile);
+ configuration.incrementsProgression();
+ result.put(eventsFile, importResult);
+ } finally {
+ deleteFile(eventsFile);
+ }
+ }
+
+ InputFile lectureAgeGenFile = configuration.getLectureAgeGenFile();
+ if (lectureAgeGenFile.getFile() != null) {
+
+ // do lecture age gen import
+ try {
+ CsvImportResult importResult = importLectureAgeGen(voyage, lectureAgeGenFile);
+ configuration.incrementsProgression();
+ result.put(lectureAgeGenFile, importResult);
+ } finally {
+ deleteFile(lectureAgeGenFile);
+ }
+ }
+
+ InputFile typeEchoSpeciesFile = configuration.getTypeEchoSpeciesFile();
+ if (typeEchoSpeciesFile.getFile() != null) {
+
+ // do echo species import
+ try {
+ CsvImportResult importResult = importTypeEchoSpecies(voyage, typeEchoSpeciesFile);
+ configuration.incrementsProgression();
+ result.put(typeEchoSpeciesFile, importResult);
+ } finally {
+ deleteFile(typeEchoSpeciesFile);
+ }
+ }
+
+ return result;
+ }
+
+ protected void deleteFile(InputFile input) {
+ File file = input.getFile();
+
+ if (log.isInfoEnabled()) {
+ log.info("Will delete import file " + file);
+ }
+ boolean wasDel = file.delete();
+ if (!wasDel) {
+ throw new EchoBaseTechnicalException("Could not delete file " + file);
+ }
+ }
+
+ protected CsvImportResult importAcoustic(Voyage voyage, InputFile importFile) {
+ if (log.isInfoEnabled()) {
+ log.info("Starts " + importFile.getLabel() + " with file " +
+ importFile.getFile());
+ }
+ CsvImportResult result = new CsvImportResult();
+ prepareImport();
+ return result;
+ }
+
+ protected CsvImportResult importCapture(Voyage voyage, InputFile importFile) {
+ if (log.isInfoEnabled()) {
+ log.info("Starts " + importFile.getLabel() + " with file " +
+ importFile.getFile());
+ }
+ CsvImportResult result = new CsvImportResult();
+ prepareImport();
+ return result;
+ }
+
+ protected CsvImportResult importEvents(Voyage voyage, InputFile importFile) {
+ if (log.isInfoEnabled()) {
+ log.info("Starts " + importFile.getLabel() + " with file " +
+ importFile.getFile());
+ }
+ CsvImportResult result = new CsvImportResult();
+ prepareImport();
+ return result;
+ }
+
+ protected CsvImportResult importLectureAgeGen(Voyage voyage, InputFile importFile) {
+ if (log.isInfoEnabled()) {
+ log.info("Starts " + importFile.getLabel() + " with file " +
+ importFile.getFile());
+ }
+ CsvImportResult result = new CsvImportResult();
+ prepareImport();
+ return result;
+ }
+
+ protected CsvImportResult importTypeEchoSpecies(Voyage voyage, InputFile importFile) {
+ if (log.isInfoEnabled()) {
+ log.info("Starts " + importFile.getLabel() + " with file " +
+ importFile.getFile());
+ }
+ CsvImportResult result = new CsvImportResult();
+ prepareImport();
+ return result;
+ }
+
+ protected void prepareImport() {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -26,7 +26,6 @@
import com.google.common.base.Preconditions;
import fr.ifremer.echobase.EchoBaseConfiguration;
import fr.ifremer.echobase.EchoBaseTechnicalException;
-import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.EchoBaseUserDAO;
import fr.ifremer.echobase.entities.EchoBaseUserDTO;
@@ -76,15 +75,6 @@
}
}
- public EchoBaseUser getUserById(String topiaId) {
- try {
- EchoBaseUser user = getDAO().findByTopiaId(topiaId);
- return user;
- } catch (TopiaException eee) {
- throw new EchoBaseTechnicalException(eee);
- }
- }
-
public EchoBaseUser getUserByEmail(String email) {
Preconditions.checkNotNull(email);
try {
@@ -162,6 +152,6 @@
}
protected EchoBaseUserDAO getDAO() throws TopiaException {
- return EchoBaseDAOHelper.getEchoBaseUserDAO(getTransaction());
+ return (EchoBaseUserDAO) getDAO(EchoBaseUser.class);
}
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/VoyageService.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -24,39 +24,25 @@
package fr.ifremer.echobase.services;
import fr.ifremer.echobase.EchoBaseTechnicalException;
-import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
import fr.ifremer.echobase.entities.data.Voyage;
-import fr.ifremer.echobase.entities.data.VoyageDAO;
import org.nuiton.topia.TopiaException;
-import java.util.List;
-
/**
- * Service to manage all concerning voayges.
+ * Service to manage all concerning voyages.
*
* @author sletellier <letellier(a)codelutin.com>
*/
public class VoyageService extends AbstractEchoBaseService {
- public List<Voyage> getVoyages() {
+ public Voyage createVoyage(Voyage voyage) {
try {
- List<Voyage> voyages = getDAO().findAll();
- return voyages;
+ Voyage result = getDAO(Voyage.class).create(voyage);
+ commitTransaction("Could not create voyage " +
+ voyage.getVoyageName());
+ return result;
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException(eee);
}
}
- public Voyage getVoyageById(String topiaId) {
- try {
- Voyage voyage = getDAO().findByTopiaId(topiaId);
- return voyage;
- } catch (TopiaException eee) {
- throw new EchoBaseTechnicalException(eee);
- }
- }
-
- protected VoyageDAO getDAO() throws TopiaException {
- return EchoBaseDAOHelper.getVoyageDAO(getTransaction());
- }
}
Property changes on: trunk/echobase-services/src/main/resources/embedded/startEchobase.bat
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/echobase-services/src/main/resources/embedded/startEchobase.sh
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-services/src/main/resources/i18n/echobase-services_fr_FR.properties
===================================================================
--- trunk/echobase-services/src/main/resources/i18n/echobase-services_fr_FR.properties 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/main/resources/i18n/echobase-services_fr_FR.properties 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,5 @@
+echobase.common.acousticImport=Import Acoustique
+echobase.common.captureImport=Import Pêcherie
+echobase.common.eventsImport=Import Evènements
+echobase.common.lectureAgeGenImport=Import Lecture Agen Gen
+echobase.common.typeEchoSpeciesImport=Import Type EchoSpecies
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -51,7 +51,7 @@
protected TopiaContext transaction;
- private static final int NB_ASSOCIATIONS = 2;
+ private static final int NB_ASSOCIATIONS = 1;
public MockEntityVisitorCreator(TopiaContext transaction) {
this.transaction = transaction;
Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -28,6 +28,7 @@
import fr.ifremer.echobase.entities.MockEntityVisitorCreator;
import fr.ifremer.echobase.entities.data.Voyage;
import fr.ifremer.echobase.entities.data.VoyageDAO;
+import org.junit.Ignore;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
@@ -39,6 +40,7 @@
* @author sletellier <letellier(a)codelutin.com>
* @since 0.2
*/
+@Ignore
public class EmbeddedApplicationServiceTest extends AbstractEchoBaseServiceTest {
public static final String TEST_ECHOBASE_EMBEDDED = "test-echobase-embedded";
Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/echobase-services/src/test/resources/echobase.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/pom.xml
===================================================================
--- trunk/echobase-ui/pom.xml 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/pom.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -262,6 +262,7 @@
<executions>
<execution>
<goals>
+ <goal>parserValidation</goal>
<goal>parserJava</goal>
<goal>gen</goal>
<goal>bundle</goal>
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -24,6 +24,7 @@
package fr.ifremer.echobase.ui;
import fr.ifremer.echobase.entities.EchoBaseUser;
+import fr.ifremer.echobase.services.ImportDataConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -44,6 +45,9 @@
/** Key to set User connected in this session. */
protected static final String PROPERTY_ECHO_BASE_USER = "echobaseUser";
+ /** Key to keep import configuration in this session. */
+ protected static final String PROPERTY_IMPORT_DATA_CONFIGURATION = "importDataConfiguration";
+
/** To store all properties in this session. */
protected Map<String, Object> store;
@@ -65,6 +69,14 @@
set(PROPERTY_ECHO_BASE_USER, echoBaseUser);
}
+ public ImportDataConfiguration getImportDataConfiguration() {
+ return get(PROPERTY_IMPORT_DATA_CONFIGURATION, ImportDataConfiguration.class);
+ }
+
+ public void setImportDataConfiguration(ImportDataConfiguration configuration) {
+ set(PROPERTY_IMPORT_DATA_CONFIGURATION, configuration);
+ }
+
/**
* Remove form this session, the object from his given key and returns it.
*
@@ -121,9 +133,13 @@
* @param value the object to store in this session
*/
protected void set(String key, Object value) {
- store.put(key, value);
- if (log.isInfoEnabled()) {
- log.info("Set in user session data [" + key + "] = " + value);
+ if (value == null) {
+ remove(key);
+ } else {
+ store.put(key, value);
+ if (log.isInfoEnabled()) {
+ log.info("Set in user session data [" + key + "] = " + value);
+ }
}
}
}
Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/ImportAction.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -1,94 +0,0 @@
-/*
- * #%L
- * EchoBase :: UI
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 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.ui.actions;
-
-import com.opensymphony.xwork2.Preparable;
-import fr.ifremer.echobase.entities.data.Voyage;
-import fr.ifremer.echobase.services.VoyageService;
-import fr.ifremer.echobase.services.models.ImportModel;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Action to manage imports
- *
- * @author sletellier <letellier(a)codelutin.com>
- * @since 0.1
- */
-public class ImportAction extends EchoBaseActionSupport implements Preparable {
-
- private static final long serialVersionUID = 1L;
-
- protected static final Log log = LogFactory.getLog(ImportAction.class);
-
- protected ImportModel importModel;
-
- protected Map<String, String> voyages;
-
- public ImportModel getImportModel() {
- if (importModel == null) {
- importModel = new ImportModel();
- }
- return importModel;
- }
-
- public String getSelectedVoyageId() {
- String selectedVoyageId = getImportModel().getSelectedVoyageId();
- return selectedVoyageId;
- }
-
- public void setSelectedVoyageId(String selectedVoyageId) {
- VoyageService service = newService(VoyageService.class);
- Voyage selectedVoyage = service.getVoyageById(selectedVoyageId);
- getImportModel().setSelectedVoyage(selectedVoyage);
- }
-
- public Map<String, String> getVoyages() {
- return voyages;
- }
-
- @Override
- public void prepare() throws Exception {
- VoyageService service = newService(VoyageService.class);
- List<Voyage> allVoyages = service.getVoyages();
- voyages = sortAndDecorate(allVoyages, null);
- }
-
- @Override
- public String execute() throws Exception {
- log.info("Will import : " + getImportModel().toString());
- return SUCCESS;
- }
-
-// @Override
-// public void validate() {
-// //FIXME : do a real validation with a xml validation file.
-// if (!importModel.validate()) {
-// addActionError(_("echobase.error.importArgument"));
-// }
-// }
-}
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/CreateEmbeddedApplication.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/CreateEmbeddedApplication.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/CreateEmbeddedApplication.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -73,7 +73,7 @@
public String execute() throws Exception {
VoyageService service = newService(VoyageService.class);
- List<Voyage> allVoyages = service.getVoyages();
+ List<Voyage> allVoyages = service.getEntities(Voyage.class);
voyages = sortAndDecorate(allVoyages, null);
EchoBaseConfiguration configuration = getConfiguration();
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -100,7 +100,8 @@
public void prepare() throws Exception {
ExportSqlService service = newService(ExportSqlService.class);
- Collection<ExportQuery> sqlQueries = service.getQueries();
+ Collection<ExportQuery> sqlQueries =
+ service.getEntities(ExportQuery.class);
queries = sortAndDecorate(sqlQueries, null);
if (sqlQueries.isEmpty()) {
@@ -117,7 +118,7 @@
} else {
// load query from database
- query = service.getQueryById(selectedQueryId);
+ query = service.getEntityById(ExportQuery.class, selectedQueryId);
}
}
}
\ No newline at end of file
Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,187 @@
+/*
+ * #%L
+ * EchoBase :: UI
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.ui.actions.importData;
+
+import com.opensymphony.xwork2.Preparable;
+import fr.ifremer.echobase.InputFile;
+import fr.ifremer.echobase.entities.data.Voyage;
+import fr.ifremer.echobase.services.ImportDataConfiguration;
+import fr.ifremer.echobase.services.VoyageService;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Action to load input files to import.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ConfigureFiles extends EchoBaseActionSupport implements Preparable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ConfigureFiles.class);
+
+ /** Import data configuration to push in session. */
+ protected ImportDataConfiguration model;
+
+ /** Id of selected voyage used in import. */
+ protected String voyageId;
+
+ public void setVoyageId(String voyageId) {
+ this.voyageId = voyageId;
+ }
+
+ public void setAcoustic(File file) {
+ getModel().getAcousticFile().setFile(file);
+ }
+
+ public void setAcousticContentType(String contentType) {
+ getModel().getAcousticFile().setContentType(contentType);
+ }
+
+ public void setAcousticFileName(String fileName) {
+ getModel().getAcousticFile().setFileName(fileName);
+ }
+
+ public void setCapture(File file) {
+ getModel().getCaptureFile().setFile(file);
+ }
+
+ public void setCaptureContentType(String contentType) {
+ getModel().getCaptureFile().setContentType(contentType);
+ }
+
+ public void setCaptureFileName(String fileName) {
+ getModel().getCaptureFile().setFileName(fileName);
+ }
+
+ public void setLectureAgeGen(File file) {
+ getModel().getLectureAgeGenFile().setFile(file);
+ }
+
+ public void setLectureAgeGenContentType(String contentType) {
+ getModel().getLectureAgeGenFile().setContentType(contentType);
+ }
+
+ public void setLectureAgeGenFileName(String fileName) {
+ getModel().getLectureAgeGenFile().setFileName(fileName);
+ }
+
+ public void setEvents(File file) {
+ getModel().getEventsFile().setFile(file);
+ }
+
+ public void setEventsContentType(String contentType) {
+ getModel().getEventsFile().setContentType(contentType);
+ }
+
+ public void setEventsFileName(String fileName) {
+ getModel().getEventsFile().setFileName(fileName);
+ }
+
+ public void setTypeEchoSpecies(File file) {
+ getModel().getTypeEchoSpeciesFile().setFile(file);
+ }
+
+ public void setTypeEchoSpeciesContentType(String contentType) {
+ getModel().getTypeEchoSpeciesFile().setContentType(contentType);
+ }
+
+ public void setTypeEchoSpeciesFileName(String fileName) {
+ getModel().getTypeEchoSpeciesFile().setFileName(fileName);
+ }
+
+ public String getVoyageId() {
+ return voyageId;
+ }
+
+ public ImportDataConfiguration getModel() {
+ if (model == null) {
+ model = new ImportDataConfiguration(getLocale());
+ }
+ return model;
+ }
+
+ @Override
+ public String input() throws Exception {
+
+ // remove configuration from session
+ getEchoBaseSession().setImportDataConfiguration(null);
+
+ return INPUT;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ ImportDataConfiguration importModel = getModel();
+ File tempDirectory = FileUtils.getTempDirectory();
+ File dataDirectory = new File(tempDirectory, "echobase-import" + System.currentTimeMillis());
+ FileUtil.createDirectoryIfNecessary(dataDirectory);
+ if (log.isInfoEnabled()) {
+ log.info("Temporary directory to use : " + dataDirectory);
+ }
+ copyFile(importModel.getAcousticFile(), dataDirectory);
+ copyFile(importModel.getCaptureFile(), dataDirectory);
+ copyFile(importModel.getEventsFile(), dataDirectory);
+ copyFile(importModel.getLectureAgeGenFile(), dataDirectory);
+ copyFile(importModel.getTypeEchoSpeciesFile(), dataDirectory);
+
+ getEchoBaseSession().setImportDataConfiguration(importModel);
+ return SUCCESS;
+ }
+
+ @Override
+ public void prepare() throws Exception {
+
+ VoyageService service = newService(VoyageService.class);
+
+ Voyage voyage = service.getEntityById(Voyage.class, voyageId);
+ getModel().setVoyage(voyage);
+ }
+
+ protected void copyFile(InputFile inputFile, File dataDirectory) throws IOException {
+ File source = inputFile.getFile();
+ if (source != null) {
+
+ File target = new File(dataDirectory, inputFile.getFileName());
+ if (log.isInfoEnabled()) {
+ log.info("Copy file " + source + " to " + target);
+ }
+ FileUtils.copyFile(source, target);
+
+ // keep target (source file will be removed at the end of this action)
+ inputFile.setFile(target);
+ }
+
+ }
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,170 @@
+/*
+ * #%L
+ * EchoBase :: UI
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.ui.actions.importData;
+
+import com.google.common.collect.Maps;
+import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
+import fr.ifremer.echobase.entities.data.Voyage;
+import fr.ifremer.echobase.entities.data.VoyageImpl;
+import fr.ifremer.echobase.entities.references.AreaOfOperation;
+import fr.ifremer.echobase.entities.references.Mission;
+import fr.ifremer.echobase.services.VoyageService;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Configure the step 1 of import data (says which campagne to use).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ConfigureVoyage extends EchoBaseActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ConfigureVoyage.class);
+
+ /** Universe of existing voyages. */
+ protected Map<String, String> voyages;
+
+ /** Universe of existing missions. */
+ protected Map<String, String> missions;
+
+ /** Universe of existing areaOfOperations. */
+ protected Map<String, String> areaOfOperations;
+
+ /** Universe of possible import modes. */
+ protected Map<String, String> importModes;
+
+ /** Selected import mode. */
+ protected ImportMode importMode;
+
+ /** Voyage to use. */
+ protected Voyage voyage;
+
+ /** Mission selected id. */
+ protected String missionId;
+
+ /** Area of operation selected id. */
+ protected String areaOfOperationId;
+
+ public Voyage getVoyage() {
+ if (voyage == null) {
+ voyage = new VoyageImpl();
+ }
+ return voyage;
+ }
+
+ public Map<String, String> getImportModes() {
+ return importModes;
+ }
+
+ public Map<String, String> getVoyages() {
+ return voyages;
+ }
+
+ public Map<String, String> getMissions() {
+ return missions;
+ }
+
+ public Map<String, String> getAreaOfOperations() {
+ return areaOfOperations;
+ }
+
+ public ImportMode getImportMode() {
+ return importMode;
+ }
+
+ public void setMissionId(String missionId) {
+ this.missionId = missionId;
+ }
+
+ public void setAreaOfOperationId(String areaOfOperationId) {
+ this.areaOfOperationId = areaOfOperationId;
+ }
+
+ public void setImportMode(ImportMode importMode) {
+ this.importMode = importMode;
+ }
+
+ @Override
+ public String input() throws Exception {
+ importModes = Maps.newLinkedHashMap();
+ for (ImportMode mode : ImportMode.values()) {
+ importModes.put(mode.name(), _(mode.getI18nKey()));
+ }
+
+ if (importMode == null) {
+ importMode = ImportMode.USE_EXISTING_VOYAGE;
+ }
+
+ VoyageService service = newService(VoyageService.class);
+ List<Voyage> allVoyages = service.getEntities(Voyage.class);
+ voyages = sortAndDecorate(allVoyages, null);
+
+ List<Mission> allMissions = service.getEntities(Mission.class);
+ missions = sortAndDecorate(allMissions, null);
+
+ List<AreaOfOperation> allAreaOfOperations =
+ service.getEntities(AreaOfOperation.class);
+ areaOfOperations = sortAndDecorate(allAreaOfOperations, null);
+ if (log.isInfoEnabled()) {
+ log.info("File errors : "+getFieldErrors());
+ }
+ return INPUT;
+ }
+
+ @InputConfig(methodName = "input")
+ @Override
+ public String execute() throws Exception {
+
+ if (importMode == ImportMode.CREATE_NEW_VOYAGE) {
+
+ // create voyage in db
+ VoyageService service = newService(VoyageService.class);
+ Voyage voyageToCreate = getVoyage();
+ //TODO Remove this test when references will be ok
+ if (StringUtils.isNotEmpty(missionId)) {
+ Mission mission =
+ service.getEntityById(Mission.class, missionId);
+ voyage.setMission(mission);
+ }
+ //TODO Remove this test when references will be ok
+ if (StringUtils.isNotEmpty(areaOfOperationId)) {
+ AreaOfOperation area = service.getEntityById(AreaOfOperation.class,
+ areaOfOperationId);
+ voyage.setAreaOfOperation(area);
+ }
+ voyage = service.createVoyage(voyageToCreate);
+ }
+ return SUCCESS;
+ }
+
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,49 @@
+/*
+ * #%L
+ * EchoBase :: UI
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.ui.actions.importData;
+
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Define import mode (use an existing voayge, or create a new one.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public enum ImportMode {
+
+ CREATE_NEW_VOYAGE(n_("echobase.common.importMode.createNewVoyage")),
+ USE_EXISTING_VOYAGE(n_("echobase.common.importMode.useExistingVoyage"));
+
+
+ private final String i18nKey;
+
+ ImportMode(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ public String getI18nKey() {
+ return i18nKey;
+ }
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,90 @@
+/*
+ * #%L
+ * EchoBase :: UI
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.ui.actions.importData;
+
+import com.opensymphony.xwork2.Preparable;
+import fr.ifremer.echobase.InputFile;
+import fr.ifremer.echobase.services.CsvImportResult;
+import fr.ifremer.echobase.services.ImportDataConfiguration;
+import fr.ifremer.echobase.services.ImportDataService;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+/**
+ * To launch the import data process.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class LaunchImport extends EchoBaseActionSupport implements Preparable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(LaunchImport.class);
+
+ /** Import data configuration to push in session. */
+ protected ImportDataConfiguration model;
+
+ protected Map<InputFile, CsvImportResult> importResult;
+
+ transient ImportDataService service;
+
+ public ImportDataConfiguration getModel() {
+ return model;
+ }
+
+ public Map<InputFile, CsvImportResult> getImportResult() {
+ return importResult;
+ }
+
+ @Override
+ public void prepare() throws Exception {
+
+ model = getEchoBaseSession().getImportDataConfiguration();
+
+ service = newService(ImportDataService.class);
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ try {
+ if (log.isInfoEnabled()) {
+ log.info("Start imports with voyage " +
+ model.getVoyage().getVoyageName());
+ }
+
+ importResult = service.startImport(model);
+ return SUCCESS;
+ } finally {
+
+ // remove configuration from session
+ getEchoBaseSession().setImportDataConfiguration(null);
+ }
+ }
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ManageUser.java 2011-11-24 23:06:43 UTC (rev 116)
@@ -76,7 +76,7 @@
if (!StringUtils.isEmpty(userId)) {
// load user
- user = getUserService().getUserById(userId).toDTO();
+ user = getUserService().getEntityById(EchoBaseUser.class, userId).toDTO();
log.info("Selected user " + user.getEmail());
}
Modified: trunk/echobase-ui/src/main/resources/config/struts-import.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/config/struts-import.xml 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/resources/config/struts-import.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -32,20 +32,40 @@
<package name="import" extends="loggued" namespace="/import">
- <!-- Display import page -->
- <action name="import" class="fr.ifremer.echobase.ui.actions.ImportAction"
- method="input">
- <result name="input">/WEB-INF/jsp/import/import.jsp</result>
+ <!-- Configure import voyage -->
+ <action name="configureVoyage"
+ class="fr.ifremer.echobase.ui.actions.importData.ConfigureVoyage">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result name="input">/WEB-INF/jsp/import/configureVoyage.jsp</result>
+ <result type="redirectAction">
+ <param name="namespace">/import</param>
+ <param name="actionName">configureFiles</param>
+ <param name="method">input</param>
+ <param name="voyageId">${voyage.topiaId}</param>
+ </result>
</action>
- <!-- Display import page -->
- <action name="doImport" class="fr.ifremer.echobase.ui.actions.ImportAction">
+ <!-- Configure import files -->
+ <action name="configureFiles"
+ class="fr.ifremer.echobase.ui.actions.importData.ConfigureFiles">
<interceptor-ref name="paramsPrepareParamsStackLoggued"/>
- <!--<result name="wait">/WEB-INF/jsp/import/importProgress.jsp</result>-->
- <result name="input">/WEB-INF/jsp/import/import.jsp</result>
- <result>/WEB-INF/jsp/import/importProgress.jsp</result>
+ <result name="input">/WEB-INF/jsp/import/configureFiles.jsp</result>
+ <result type="redirectAction">
+ <param name="namespace">/import</param>
+ <param name="actionName">doImport</param>
+ </result>
</action>
+ <!-- Starts import -->
+ <action name="doImport"
+ class="fr.ifremer.echobase.ui.actions.importData.LaunchImport"
+ method="execute">
+ <interceptor-ref name="basicStackLoggued"/>
+ <interceptor-ref name="execAndWait"/>
+ <result name="wait">/WEB-INF/jsp/import/importProgress.jsp</result>
+ <result>/WEB-INF/jsp/import/importResult.jsp</result>
+ </action>
+
</package>
</struts>
Modified: trunk/echobase-ui/src/main/resources/echobase.properties
===================================================================
--- trunk/echobase-ui/src/main/resources/echobase.properties 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/resources/echobase.properties 2011-11-24 23:06:43 UTC (rev 116)
@@ -29,6 +29,7 @@
hibernate.hbm2ddl.auto=none
hibernate.show_sql=false
hibernate.dialect=org.hibernate.dialect.H2Dialect
+hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider
hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:file:${data.directory}/db/echobase
Deleted: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/ImportAction-doImport-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/ImportAction-doImport-validation.xml 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/ImportAction-doImport-validation.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -1,36 +0,0 @@
-<!--
- #%L
- EchoBase :: UI
-
- $Id$
- $HeadURL$
- %%
- Copyright (C) 2011 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%
- -->
-<!DOCTYPE validators PUBLIC
- "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
- "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
-<validators>
-
- <field name="importModel.accessImport">
- <field-validator type="expression">
- <param name="expression">(importModel.accessImport == null ^ importModel.selectedVoyage == null) == 1</param>
- <message key="echobase.validation.import.selectedVoyageOrAccessImport.required"/>
- </field-validator>
- </field>
-
-</validators>
\ No newline at end of file
Modified: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/export/ManageExportQuery-saveExportQuery-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/export/ManageExportQuery-saveExportQuery-validation.xml 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/export/ManageExportQuery-saveExportQuery-validation.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -29,27 +29,27 @@
<field name="query.name">
<field-validator type="requiredstring">
- <message key="echobase.validation.export.name.requiredstring"/>
+ <message key="echobase.error.export.name.requiredstring"/>
</field-validator>
</field>
<field name="query.description">
<field-validator type="requiredstring">
- <message key="echobase.validation.export.description.requiredstring"/>
+ <message key="echobase.error.export.description.requiredstring"/>
</field-validator>
</field>
<field name="query.sqlQuery">
<field-validator type="requiredstring">
- <message key="echobase.validation.export.sqlQuery.requiredstring"/>
+ <message key="echobase.error.export.sqlQuery.requiredstring"/>
</field-validator>
<field-validator type="regex">
<!-- TODO sletellier 2011/11/14 : Find a better regex exression to define sql query -->
<param name="expression">^\s*select\s+.+\s+from\s+.+$</param>
<param name="caseSensitive">false</param>
- <message key="echobase.validation.export.sqlQuery.wrongformat"/>
+ <message key="echobase.error.export.sqlQuery.wrongformat"/>
</field-validator>
</field>
Added: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml (rev 0)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,35 @@
+<!--
+ #%L
+ EchoBase :: UI
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2011 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%
+ -->
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+
+ <field name="voyageId">
+ <field-validator type="requiredstring">
+ <message key="echobase.error.import.voyage.required"/>
+ </field-validator>
+ </field>
+
+</validators>
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage-validation.xml (rev 0)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage-validation.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,92 @@
+<!--
+ #%L
+ EchoBase :: UI
+
+ $Id $
+ $HeadURL $
+ %%
+ Copyright (C) 2011 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%
+ -->
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+
+ <field name="importMode">
+ <field-validator type="required">
+ <message key="echobase.error.import.importMode.required"/>
+ </field-validator>
+ </field>
+
+ <field name="voyage.topiaId">
+ <field-validator type="requiredstring">
+ <param name="skip">importMode.name() != "USE_EXISTING_VOYAGE"</param>
+ <message key="echobase.error.import.voyage.required"/>
+ </field-validator>
+ </field>
+
+ <field name="voyage.voyageName">
+ <field-validator type="requiredstring">
+ <param name="skip">importMode.name() != "CREATE_NEW_VOYAGE"</param>
+ <message key="echobase.error.import.voyageName.required"/>
+ </field-validator>
+ </field>
+
+ <field name="voyage.datum">
+ <field-validator type="requiredstring">
+ <param name="skip">importMode.name() != "CREATE_NEW_VOYAGE"</param>
+ <message key="echobase.error.import.datum.required"/>
+ </field-validator>
+ </field>
+
+ <field name="voyage.voyageDescription">
+ <field-validator type="requiredstring">
+ <param name="skip">importMode.name() != "CREATE_NEW_VOYAGE"</param>
+ <message key="echobase.error.import.voyageDescription.required"/>
+ </field-validator>
+ </field>
+
+ <!-- TODO Reput this when references are in db -->
+ <!--field name="missionId">
+ <field-validator type="requiredstring">
+ <param name="skip">${importMode.name} != "CREATE_NEW_VOYAGE"</param>
+ <message key="echobase.error.import.missionId.required"/>
+ </field-validator>
+ </field-->
+
+ <!--field name="areaOfOperationId">
+ <field-validator type="requiredstring">
+ <param name="skip">importMode.name() != "CREATE_NEW_VOYAGE"</param>
+ <message key="echobase.error.import.areaOfOperationId.required"/>
+ </field-validator>
+ </field-->
+
+ <field name="voyage.voyageStartDate">
+ <field-validator type="required">
+ <param name="skip">importMode.name() != "CREATE_NEW_VOYAGE"</param>
+ <message key="echobase.error.import.voyageStartDate.required"/>
+ </field-validator>
+ </field>
+
+ <field name="voyage.voyageEndDate">
+ <field-validator type="required">
+ <param name="skip">importMode.name() != "CREATE_NEW_VOYAGE"</param>
+ <message key="echobase.error.import.voyageEndDate.required"/>
+ </field-validator>
+ </field>
+
+</validators>
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureVoyage-validation.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/user/LoginAction-login-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/user/LoginAction-login-validation.xml 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/user/LoginAction-login-validation.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -29,7 +29,7 @@
<field name="email">
<field-validator type="login">
- <message key="echobase.validation.login.wrongLogin"/>
+ <message key="echobase.error.login.wrongLogin"/>
</field-validator>
</field>
Modified: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/user/ManageUser-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/user/ManageUser-validation.xml 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/user/ManageUser-validation.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -29,14 +29,14 @@
<field name="user.email">
<field-validator type="login">
- <message key="echobase.validation.login.wrongLogin"/>
+ <message key="echobase.error.login.wrongLogin"/>
</field-validator>
</field>
<field name="user.password">
<field-validator type="requiredstring">
- <message key="echobase.validation.login.password.requiredstring"/>
+ <message key="echobase.error.login.password.requiredstring"/>
</field-validator>
</field>
Modified: trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties
===================================================================
--- trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-24 23:06:43 UTC (rev 116)
@@ -18,16 +18,19 @@
echobase.action.return=Retour
echobase.action.save=Sauvegarder
echobase.action.saveSqlQuery=Enregistrer la requête
+echobase.action.validateImportVoyage=Valider la campagne
echobase.common.admin=Administrateur
echobase.common.comment=Commentaire
echobase.common.email=Email
echobase.common.entityType=Type d'entité
+echobase.common.importMode=Type de campagne
+echobase.common.importMode.createNewVoyage=Créer une nouvelle campagne
+echobase.common.importMode.useExistingVoyage=Utiliser une campagne existante
echobase.common.jdbcLogin=Login de connexion
echobase.common.jdbcPassword=Mot de passe
echobase.common.jdbcUrl=Url de connexion
echobase.common.password=Mot de passe
echobase.common.user=Utilisateur
-echobase.common.voyage=Voyage
echobase.error.bad.password=Mot de passe incorrrect
echobase.error.email.already.used=
echobase.error.export.description.requiredstring=La description de l'export est obligatoire
@@ -36,7 +39,7 @@
echobase.error.export.sqlQuery.wrongformat=La requêtes n'est pas valide
echobase.error.fileDontExist=
echobase.error.fileNotFound=
-echobase.error.import.selectedVoyageOrAccessImport.required=Merci de selectionner un voyage ou un import access
+echobase.error.import.selectedVoyageOrAccessImport.required=Merci de selectionner un campagne
echobase.error.importArgument=
echobase.error.importFile.required=Fichier d'import obligatoire
echobase.error.login.password.requiredstring=Le mot de passe est obligatoire
@@ -47,7 +50,7 @@
echobase.error.warlocation.notFound=L'application n'a pas été trouvé à l'emplacement suivant %s
echobase.header.request.result=Résultat de la requête sql
echobase.header.user.gridTitle=Liste des utilisateurs
-echobase.header.voyageSelect=Selectionnez un voyage
+echobase.header.voyageSelect=Selectionnez une campagne
echobase.info.dbeditor.propertyDiffsResult=Résultat d'import de données
echobase.info.no.sqlQuery.saved=Aucune requête d'export sql enregistré
echobase.info.no.sqlQuery.selected=Aucune requête d'export sql sélectionnée
@@ -79,6 +82,10 @@
echobase.legend.dbeditor.edit=Edition de '%s'
echobase.legend.embeddedApplication.configuration=Configuration de l'application embarquée
echobase.legend.import=Import configuration
+echobase.legend.import.configuration.files=Choix des fichiers d'import
+echobase.legend.import.configuration.voyage=Configurer la campagne
+echobase.legend.import.configuration.voyage.resume=Résumé de la campagne à utiliser
+echobase.legend.importFileResult=Résultat de l'import %s
echobase.legend.sqlQuery.configuration=Configuration de la requête
echobase.legend.sqlQuery.result=Résultats de la requête
echobase.menu.connectToDbInformations=Se connecter à la base
@@ -104,6 +111,7 @@
echobase.title.export=Export
echobase.title.exportTable=Exporter une table
echobase.title.import=Imports
+echobase.title.import.configuration=Configuration d'un import
echobase.title.importProgress=Import en cours
echobase.title.importResult=Résultats de l'import
echobase.title.importTable=Importer une table
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp 2011-11-24 23:06:43 UTC (rev 116)
@@ -55,7 +55,7 @@
<div class="cleanBoth">
<ul>
<li>
- <s:a action="import" namespace="/import">
+ <s:a action="configureVoyage" namespace="/import" method="input">
<s:text name="echobase.menu.import"/></s:a>
</li>
<li>
Added: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureFiles.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureFiles.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureFiles.jsp 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,71 @@
+<%--
+ #%L
+ EchoBase :: UI
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2011 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%
+ --%>
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<title><s:text name="echobase.title.import"/></title>
+
+<s:form namespace="/import" method="POST" enctype="multipart/form-data">
+
+ <fieldset>
+ <legend>
+ <s:text name="echobase.legend.import.configuration.voyage.resume"/>
+ </legend>
+ <s:label value="%{model.voyage.voyageName}"
+ key='echobase.common.voyageName'/>
+
+ <s:label value="%{model.voyage.voyageDescription}"
+ key='echobase.common.voyageDescription'/>
+ </fieldset>
+
+ <hr/>
+ <fieldset>
+ <legend>
+ <s:text name="echobase.legend.import.configuration.files"/>
+ </legend>
+
+ <s:hidden key="voyageId" label=''/>
+
+ <s:file name="acoustic"
+ key="echobase.label.import.accoustique"/>
+
+ <s:file name="capture"
+ key="echobase.label.import.pecherie"/>
+
+ <s:file name="lectureAgeGen"
+ key="echobase.label.import.lectureAgeGen"/>
+
+ <s:file name="events"
+ key="echobase.label.import.events"/>
+
+ <s:file name="typeEchoSpecies"
+ key="echobase.label.import.typeEchoSpecies"/>
+
+ </fieldset>
+ <br/>
+ <s:submit id="addFilesSubmit" action="configureFiles"
+ value='%{getText("echobase.action.import")}'/>
+
+
+</s:form>
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureFiles.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureVoyage.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureVoyage.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureVoyage.jsp 2011-11-24 23:06:43 UTC (rev 116)
@@ -0,0 +1,127 @@
+<%--
+ #%L
+ EchoBase :: UI
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2011 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%
+ --%>
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
+
+<script type="text/javascript">
+
+ jQuery(document).ready(function () {
+
+ var importMode = $('[name="importMode"]');
+ importMode.change(function(event) {
+ $('[class="importMode"]').hide();
+ $('#' + this.value).show();
+ });
+ var val = $('[name="importMode"][checked="checked"]').val();
+ $('[class="importMode"]').hide();
+ $("#"+val).show();
+ });
+</script>
+<title><s:text name="echobase.title.import.configuration"/></title>
+
+<s:form id="importForm" namespace="/import" method="POST">
+
+ <fieldset>
+ <legend>
+ <s:text name="echobase.legend.import.configuration.voyage"/>
+ </legend>
+
+ <s:radio key='importMode' list="importModes"
+ label='%{getText("echobase.common.importMode")}'
+ required="true" />
+
+ <hr/>
+
+ <div id='USE_EXISTING_VOYAGE' class='importMode'>
+ <s:select name="voyage.topiaId" value="''"
+ label='%{getText("echobase.common.voyage")}'
+ list="voyages" headerKey="" headerValue=""/>
+ </div>
+
+ <div id='CREATE_NEW_VOYAGE' class='importMode'>
+
+ <%--
+ String PROPERTY_VOYAGE_NAME = "voyageName";
+
+ String PROPERTY_VOYAGE_START_DATE = "voyageStartDate";
+
+ String PROPERTY_VOYAGE_END_DATE = "voyageEndDate";
+
+ String PROPERTY_VOYAGE_START_HARBOUR = "voyageStartHarbour";
+
+ String PROPERTY_VOYAGE_END_HARBOUR = "voyageEndHarbour";
+
+ String PROPERTY_VOYAGE_DESCRIPTION = "voyageDescription";
+
+ String PROPERTY_DATUM = "datum";
+
+ String PROPERTY_MISSION = "mission";
+
+ String PROPERTY_AREA_OF_OPERATION = "areaOfOperation";
+
+ String PROPERTY_TRANSIT = "transit";
+
+ String PROPERTY_ECHOTYPE = "echotype";
+ --%>
+
+ <s:textfield key="voyage.voyageName"
+ label='%{getText("echobase.common.voyageName")}'/>
+
+ <s:textfield key="voyage.voyageStartHarbour"
+ label='%{getText("echobase.common.voyageStartHarbour")}'/>
+
+ <s:textfield key="voyage.voyageEndHarbour"
+ label='%{getText("echobase.common.voyageEndHarbour")}'/>
+
+ <s:textfield key="voyage.datum"
+ label='%{getText("echobase.common.datum")}'/>
+
+ <s:textarea key="voyage.voyageDescription"
+ label='%{getText("echobase.common.voyageDescription")}'/>
+
+ <s:select name="missionId" value="''"
+ label='%{getText("echobase.common.mission")}'
+ list="missions" headerKey="" headerValue=""/>
+
+ <s:select name="areaOfOperationId" value="''"
+ label='%{getText("echobase.common.areaOfOperation")}'
+ list="areaOfOperations" headerKey="" headerValue=""/>
+
+ <sj:datepicker key="voyage.voyageStartDate"
+ label='%{getText("echobase.common.voyageStartDate")}'
+ value="%{new java.util.Date()}"
+ displayFormat="dd/mm/yy"/>
+
+ <sj:datepicker key="voyage.voyageEndDate"
+ label='%{getText("echobase.common.voyageEndDate")}'
+ value="%{new java.util.Date()}"
+ displayFormat="dd/mm/yy"/>
+ </div>
+
+ </fieldset>
+ <br/>
+ <s:submit value='%{getText("echobase.action.validateImportVoyage")}'
+ action="configureVoyage" />
+</s:form>
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/configureVoyage.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/importProgress.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/importProgress.jsp 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/importProgress.jsp 2011-11-24 23:06:43 UTC (rev 116)
@@ -25,9 +25,16 @@
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
+<s:url id="url" action="doImport" namespace="/import"/>
+<meta http-equiv="refresh" content="1;url=${url}"/>
+
<title><s:text name="echobase.title.importProgress"/></title>
-<sj:progressbar value="%{EchoBaseActionContext.progression}"/>
+<%-- TODO letellier 20111104 : Add warn icon --%>
+<p><s:text name="echobase.message.warnImportInProgress"/></p>
-<%-- TODO letellier 20111104 : Add warn icon --%>
-<p><s:text name="echobase.message.warnImportInProgress"/></p>
\ No newline at end of file
+<br/>
+
+<div>
+ <sj:progressbar value="%{model.progression}"/>
+</div>
\ No newline at end of file
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/importResult.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/importResult.jsp 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/importResult.jsp 2011-11-24 23:06:43 UTC (rev 116)
@@ -26,4 +26,23 @@
<title><s:text name="echobase.title.importResult"/></title>
-<%-- TODO letellier 20111104 : Add import results --%>
\ No newline at end of file
+<s:iterator value="importResult" var="entry">
+ <s:set var="inputFile" value="%{#entry.key}"/>
+ <s:set var="result" value="%{#entry.value}"/>
+ <fieldset>
+ <legend>
+ <s:text name="echobase.legend.importFileResult">
+ <s:param><strong><s:property value="%{#inputFile.label}"/></strong></s:param>
+ </s:text>
+ </legend>
+
+ <s:label value="%{#inputFile.fileName}"
+ label="%{getText('echobase.label.importFile')}"/>
+
+ <s:label value="%{#result.numberCreated}"
+ label="%{getText('echobase.label.numberOfCreatedEntities')}"/>
+
+ <s:label value="%{#result.numberUpdated}"
+ label="%{getText('echobase.label.numberOfUpdatedEntities')}"/>
+ </fieldset>
+</s:iterator>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/pom.xml 2011-11-24 23:06:43 UTC (rev 116)
@@ -27,8 +27,6 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
- <name>EchoBase</name>
-
<description>Projet EchoBase</description>
<inceptionYear>2011</inceptionYear>
<url>http://maven-site.forge.codelutin.com/echobase</url>
Modified: trunk/src/doc/reunions/reunion-2011-11-15.txt
===================================================================
--- trunk/src/doc/reunions/reunion-2011-11-15.txt 2011-11-24 14:18:03 UTC (rev 115)
+++ trunk/src/doc/reunions/reunion-2011-11-15.txt 2011-11-24 23:06:43 UTC (rev 116)
@@ -23,7 +23,7 @@
- DataMetadataName
- CategoryMeaning
- CategoryType
- - CellMEthod
+ - CellMethod
- discussion autour de la modélisation des *Class* que l'on renomme en *Category*
- suppression de l'entité du référentiel *Region* qui sera au final remplacée
1
0
r115 - trunk/echobase-services/src/main/resources/embedded
by sletellier@users.forge.codelutin.com 24 Nov '11
by sletellier@users.forge.codelutin.com 24 Nov '11
24 Nov '11
Author: sletellier
Date: 2011-11-24 15:18:03 +0100 (Thu, 24 Nov 2011)
New Revision: 115
Url: http://forge.codelutin.com/repositories/revision/echobase/115
Log:
Fix startScripts
Modified:
trunk/echobase-services/src/main/resources/embedded/startEchobase.bat
trunk/echobase-services/src/main/resources/embedded/startEchobase.sh
Modified: trunk/echobase-services/src/main/resources/embedded/startEchobase.bat
===================================================================
--- trunk/echobase-services/src/main/resources/embedded/startEchobase.bat 2011-11-24 13:31:55 UTC (rev 114)
+++ trunk/echobase-services/src/main/resources/embedded/startEchobase.bat 2011-11-24 14:18:03 UTC (rev 115)
@@ -1 +1 @@
-java -jar ${project.build.finalName}.war
\ No newline at end of file
+java -jar echobase-ui-${project.version}.war
\ No newline at end of file
Modified: trunk/echobase-services/src/main/resources/embedded/startEchobase.sh
===================================================================
--- trunk/echobase-services/src/main/resources/embedded/startEchobase.sh 2011-11-24 13:31:55 UTC (rev 114)
+++ trunk/echobase-services/src/main/resources/embedded/startEchobase.sh 2011-11-24 14:18:03 UTC (rev 115)
@@ -2,9 +2,9 @@
MX=512M
cd `dirname $0`
if [ -n "$JAVA_HOME" ]; then
- $JAVA_HOME/bin/java -Xmx$MX -Xms$MX -jar ${project.build.finalName}.war $*
+ $JAVA_HOME/bin/java -Xmx$MX -Xms$MX -jar echobase-ui-${project.version}.war $*
else
- java -Xmx$MX -Xms$MX -jar ${project.build.finalName}.war $*
+ java -Xmx$MX -Xms$MX -jar echobase-ui-${project.version}.war $*
fi
cd "$OLDPWD"
1
0
24 Nov '11
Author: sletellier
Date: 2011-11-24 14:31:55 +0100 (Thu, 24 Nov 2011)
New Revision: 114
Url: http://forge.codelutin.com/repositories/revision/echobase/114
Log:
- Add topia-service-replication
- Add service test structure (AbstractEchoBaseServiceTest)
- Add tests for embeddedApplication service
- Creating visitor to create mocked entities (MokeEntityVisitorCreator)
- Copy start files (.sh and .bat) in embedded application
- Replicate referenciel and voyage selected creating embedded application
Added:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java
trunk/echobase-services/src/main/resources/embedded/startEchobase.bat
trunk/echobase-services/src/main/resources/embedded/startEchobase.sh
trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/
trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java
trunk/echobase-services/src/test/resources/echobase.properties
Removed:
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/
Modified:
trunk/echobase-entities/pom.xml
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java
trunk/echobase-entities/src/test/resources/echobase.properties
trunk/echobase-services/pom.xml
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
trunk/echobase-ui/src/main/resources/echobase.properties
trunk/pom.xml
Modified: trunk/echobase-entities/pom.xml
===================================================================
--- trunk/echobase-entities/pom.xml 2011-11-23 19:08:01 UTC (rev 113)
+++ trunk/echobase-entities/pom.xml 2011-11-24 13:31:55 UTC (rev 114)
@@ -74,6 +74,11 @@
</dependency>
<dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-service-replication</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
@@ -127,6 +132,17 @@
<build>
<plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-test</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.nuiton.eugene</groupId>
@@ -196,6 +212,13 @@
</plugins>
+ <testResources>
+ <testResource>
+ <directory>${maven.src.dir}/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
+
</build>
</project>
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java 2011-11-23 19:08:01 UTC (rev 113)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextSupplierFactory.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -33,6 +33,8 @@
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;
@@ -90,6 +92,10 @@
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);
Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java (rev 0)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,58 @@
+/*
+ * #%L
+ * EchoBase :: Entities
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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;
+
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Utility method for enities
+ *
+ * @author sletellier <letellier(a)codelutin.com>
+ * @since 0.2
+ */
+public class EntitiesUtil {
+
+ /**
+ * Used to get all contract of a package
+ *
+ * @param entitiesPackage package contening desired entities
+ * @return contracts contained in entitiesPackage
+ */
+ public static EchoBaseEntityEnum[] getContractsOf(Package entitiesPackage) {
+ EchoBaseEntityEnum[] echoBaseEntityEnums = EchoBaseEntityEnum.values();
+ List<EchoBaseEntityEnum> refClasses = new ArrayList<EchoBaseEntityEnum>();
+ for (EchoBaseEntityEnum echoBaseEntityEnum : echoBaseEntityEnums) {
+
+ // Get all entities in package fr.ifremer.echobase.entities.references
+ Class<? extends TopiaEntity> contract = echoBaseEntityEnum.getContract();
+ if (contract.getPackage().equals(entitiesPackage)) {
+ refClasses.add(echoBaseEntityEnum);
+ }
+ }
+ return refClasses.toArray(new EchoBaseEntityEnum[refClasses.size()]);
+ }
+}
Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java (rev 0)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/DataUtil.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,45 @@
+/*
+ * #%L
+ * EchoBase :: Entities
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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 fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.EntitiesUtil;
+
+/**
+ * Data method utility
+ *
+ * @author sletellier <letellier(a)codelutin.com>
+ * @since 0.2
+ */
+public class DataUtil {
+
+ /**
+ * Used to get all contract of a data package
+ *
+ * @return contracts in package data
+ */
+ public static EchoBaseEntityEnum[] getDataContracts() {
+ return EntitiesUtil.getContractsOf(DataUtil.class.getPackage());
+ }
+}
Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java (rev 0)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/references/ReferencesUtil.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,45 @@
+/*
+ * #%L
+ * EchoBase :: Entities
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.references;
+
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.EntitiesUtil;
+
+/**
+ * References method utility
+ *
+ * @author sletellier <letellier(a)codelutin.com>
+ * @since 0.2
+ */
+public class ReferencesUtil {
+
+ /**
+ * Used to get all contract of a referenciel package
+ *
+ * @return contracts in package referenciel
+ */
+ public static EchoBaseEntityEnum[] getReferencielContracts() {
+ return EntitiesUtil.getContractsOf(ReferencesUtil.class.getPackage());
+ }
+}
Added: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java
===================================================================
--- trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java (rev 0)
+++ trunk/echobase-entities/src/test/java/fr/ifremer/echobase/TestHelper.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,54 @@
+/*
+ * #%L
+ * EchoBase :: Entities
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Ignore;
+
+import java.io.File;
+
+/**
+ * Utility methods for tests
+ *
+ * @author sletellier <letellier(a)codelutin.com>
+ * @since 0.2
+ */
+@Ignore
+public class TestHelper {
+
+ protected static File basedir;
+
+ public static File getBasedir() {
+ if (basedir == null) {
+// String tmp = System.getProperty("basedir");
+// if (tmp == null) {
+// tmp = new File("").getAbsolutePath();
+// }
+// basedir = new File(tmp);
+ basedir = FileUtils.getTempDirectory();
+ }
+ return basedir;
+ }
+
+}
Modified: trunk/echobase-entities/src/test/resources/echobase.properties
===================================================================
--- trunk/echobase-entities/src/test/resources/echobase.properties 2011-11-23 19:08:01 UTC (rev 113)
+++ trunk/echobase-entities/src/test/resources/echobase.properties 2011-11-24 13:31:55 UTC (rev 114)
@@ -29,3 +29,6 @@
hibernate.connection.url=jdbc:h2:file:${data.directory}/echobase/h2data
hibernate.connection.username=sa
hibernate.connection.password=sa
+
+war.directory=${data.directory}/war
+war.location=${war.directory}/echobase-ui-${project.version}.war
\ No newline at end of file
Modified: trunk/echobase-services/pom.xml
===================================================================
--- trunk/echobase-services/pom.xml 2011-11-23 19:08:01 UTC (rev 113)
+++ trunk/echobase-services/pom.xml 2011-11-24 13:31:55 UTC (rev 114)
@@ -24,6 +24,14 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>echobase-entities</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
<!--dependency>
<groupId>fr.ird</groupId>
<artifactId>msaccess-importer</artifactId>
@@ -97,6 +105,11 @@
<artifactId>topia-service-migration</artifactId>
</dependency-->
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-service-replication</artifactId>
+ </dependency>
+
<!-- test dependencies -->
<dependency>
@@ -153,6 +166,7 @@
</includes>
<excludes>
<exclude>echobase-config</exclude>
+ <exclude>embedded/*</exclude>
</excludes>
</resource>
<resource>
@@ -162,6 +176,11 @@
</includes>
<filtering>true</filtering>
</resource>
+ <resource>
+ <directory>src/main/resources/embedded</directory>
+ <targetPath>embedded</targetPath>
+ <filtering>true</filtering>
+ </resource>
</resources>
<plugins>
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-11-23 19:08:01 UTC (rev 113)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -24,18 +24,21 @@
package fr.ifremer.echobase.services;
import com.google.common.base.Supplier;
-import com.google.common.collect.Lists;
import fr.ifremer.echobase.EchoBaseTechnicalException;
import fr.ifremer.echobase.EchoBaseTopiaRootContextSupplierFactory;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.ExportQuery;
-import fr.ifremer.echobase.entities.data.Voyage;
+import fr.ifremer.echobase.entities.data.DataUtil;
+import fr.ifremer.echobase.entities.references.ReferencesUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.replication.TopiaReplicationService;
+import org.nuiton.topia.replication.model.ReplicationModel;
import org.nuiton.util.FileUtil;
import org.nuiton.util.ZipUtil;
@@ -44,12 +47,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URISyntaxException;
import java.util.List;
/**
* To create embedded application.
*
* @author tchemit <chemit(a)codelutin.com>
+ * @author sletellier <letellier(a)codelutin.com>
* @since 0.1
*/
public class EmbeddedApplicationService extends AbstractEchoBaseService {
@@ -58,7 +63,27 @@
private static final Log log =
LogFactory.getLog(EmbeddedApplicationService.class);
+ public static final String EMBEDDED_PATH = "/embedded/";
+ public enum StartFiles {
+ BAT("startEchobase.sh"),
+ SH("startEchobase.bat");
+
+ protected String fileName;
+
+ StartFiles(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public String getFilePath() {
+ return EMBEDDED_PATH + fileName;
+ }
+ }
+
public File createEmbeddedApplication(String fileName, String... voyageIds) {
File warLocation = getConfiguration().getWarLocation();
@@ -82,6 +107,9 @@
// copy configuration file to /
copyConfigurationFile(zipDirectory);
+ // copy start scripts
+ copyStartFiles(zipDirectory);
+
// copy war to /
FileUtil.copy(warLocation, new File(zipDirectory, warLocation.getName()));
@@ -107,6 +135,24 @@
return zipFile;
}
+ protected void copyStartFiles(File zipDirectory) throws IOException, URISyntaxException {
+
+ for (StartFiles startFile : StartFiles.values()) {
+
+ InputStream inputStream =
+ getClass().getResourceAsStream(startFile.getFilePath());
+
+ File startFileDest = new File(zipDirectory, startFile.getFileName());
+ OutputStream outputStream = new FileOutputStream(startFileDest);
+ try {
+ IOUtils.copy(inputStream, outputStream);
+ } finally {
+ IOUtils.closeQuietly(inputStream);
+ IOUtils.closeQuietly(outputStream);
+ }
+ }
+ }
+
protected void copyConfigurationFile(File zipDirectory) throws IOException {
File configurationfile = new File(zipDirectory, "echobase.properties");
@@ -114,7 +160,8 @@
log.info("Copy configuration to " + configurationfile);
}
InputStream configInputStream =
- getClass().getResourceAsStream("/embedded/echobase-embedded.properties");
+ getClass().getResourceAsStream(EMBEDDED_PATH + "echobase-embedded.properties");
+
OutputStream configOutputStream = new FileOutputStream(configurationfile);
try {
IOUtils.copy(configInputStream, configOutputStream);
@@ -124,9 +171,17 @@
}
}
- protected void createH2Batabase(File zipDirectory,
+ protected TopiaContext createH2Batabase(File zipDirectory,
String... voyageIds) throws IOException, TopiaException {
+ return createH2Batabase(zipDirectory, true, voyageIds);
+ }
+
+
+ // Use it only for tests
+ protected TopiaContext createH2Batabase(File zipDirectory, boolean closeRootContext,
+ String... voyageIds) throws IOException, TopiaException {
+
// create new h2 db
Supplier<TopiaContext> topiaContextSupplier =
new EchoBaseTopiaRootContextSupplierFactory().newEmbeddedDatabase(zipDirectory);
@@ -180,22 +235,43 @@
}
// replicate referentiel to new h2 db
- //TODO
+ replicateReferentiel(topiaContext);
if (voyageIds != null) {
// replicate selected voyage to new h2 db
- VoyageService voyageService = newService(VoyageService.class);
- List<Voyage> voyages = Lists.newArrayList();
- for (String voyageId : voyageIds) {
- Voyage voyage = voyageService.getVoyageById(voyageId);
- voyages.add(voyage);
- }
- getTransaction().replicateEntities(topiaContext, voyages);
+ replicateVoyages(topiaContext, voyageIds);
}
} finally {
- rootContext.closeContext();
+ if (closeRootContext) {
+ rootContext.closeContext();
+ }
}
+ return rootContext;
+ }
+ protected void replicateVoyages(TopiaContext topiaContextDest, String... voyagesIds) throws TopiaException {
+ TopiaReplicationService service = getTransaction().getService(TopiaReplicationService.class);
+ ReplicationModel replicationModel = service.prepare(DataUtil.getDataContracts(), true, voyagesIds);
+ try {
+ service.doReplicate(replicationModel, topiaContextDest);
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException(
+ "Failed to replicate referentiel : ", eee);
+ }
}
+ protected void replicateReferentiel(TopiaContext topiaContextDest) throws TopiaException {
+
+ // Get all referenciel contracts
+ EchoBaseEntityEnum[] referencielClass = ReferencesUtil.getReferencielContracts();
+ TopiaReplicationService service = getTransaction().getService(TopiaReplicationService.class);
+ ReplicationModel replicationModel = service.prepareForAll(referencielClass);
+ try {
+ service.doReplicate(replicationModel, topiaContextDest);
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException(
+ "Failed to replicate referentiel : ", eee);
+ }
+ }
+
}
Added: trunk/echobase-services/src/main/resources/embedded/startEchobase.bat
===================================================================
--- trunk/echobase-services/src/main/resources/embedded/startEchobase.bat (rev 0)
+++ trunk/echobase-services/src/main/resources/embedded/startEchobase.bat 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1 @@
+java -jar ${project.build.finalName}.war
\ No newline at end of file
Added: trunk/echobase-services/src/main/resources/embedded/startEchobase.sh
===================================================================
--- trunk/echobase-services/src/main/resources/embedded/startEchobase.sh (rev 0)
+++ trunk/echobase-services/src/main/resources/embedded/startEchobase.sh 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,11 @@
+#!/bin/sh
+MX=512M
+cd `dirname $0`
+if [ -n "$JAVA_HOME" ]; then
+ $JAVA_HOME/bin/java -Xmx$MX -Xms$MX -jar ${project.build.finalName}.war $*
+else
+ java -Xmx$MX -Xms$MX -jar ${project.build.finalName}.war $*
+fi
+cd "$OLDPWD"
+
+
Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java (rev 0)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/entities/MockEntityVisitorCreator.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,229 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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;
+
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import fr.ifremer.echobase.entities.data.Cell;
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.EntityVisitor;
+import org.nuiton.topia.persistence.TopiaDAO;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * Visitor to create mocked entities
+ *
+ * @author sletellier <letellier(a)codelutin.com>
+ * @since 0.2
+ */
+public class MockEntityVisitorCreator implements EntityVisitor {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(MockEntityVisitorCreator.class);
+
+ protected TopiaContext transaction;
+
+ private static final int NB_ASSOCIATIONS = 2;
+
+ public MockEntityVisitorCreator(TopiaContext transaction) {
+ this.transaction = transaction;
+ }
+
+ public enum DefaultSimpleValues {
+ DATE(Date.class, new Date()),
+ STRING(String.class, "string"),
+ INTEGER(int.class, 1),
+ FLOAT(float.class, 1f),
+ LONG(long.class, 1l);
+
+ protected Class<?> type;
+ protected Object defaultValue;
+
+ DefaultSimpleValues(Class<?> type, Object defaultValue) {
+ this.type = type;
+ this.defaultValue = defaultValue;
+ }
+
+ protected Class<?> getType() {
+ return type;
+ }
+
+ public Object getDefaultValue() {
+ return defaultValue;
+ }
+
+ public static <E> E getDefaultValue(Class<E> type) {
+ DefaultSimpleValues defaultSimpleValues = getDefaultSimpleValues(type);
+ return (E) defaultSimpleValues.getDefaultValue();
+ }
+
+ protected static <E> DefaultSimpleValues getDefaultSimpleValues(Class<E> type) {
+ for (DefaultSimpleValues values : values()) {
+ if (type.isAssignableFrom(values.getType())) {
+ return values;
+ }
+ }
+ throw new IllegalArgumentException("No default value found for type : " + type);
+ }
+ }
+
+ @Override
+ public void start(TopiaEntity topiaEntity) {
+ // Do nothing
+ }
+
+ @Override
+ public void end(TopiaEntity topiaEntity) {
+ // Do nothing
+ }
+
+ @Override
+ public final void visit(TopiaEntity entity,
+ String propertyName,
+ Class<?> type,
+ Object value) {
+
+ if (TopiaEntity.class.isAssignableFrom(type)) {
+
+ // chargement d'une composition
+ visitComposition(entity, propertyName, (Class<? extends TopiaEntity>) type);
+
+ } else {
+
+ // visite d'une propriété simple
+ visitSimpleProperty(entity, propertyName, type);
+ }
+ }
+
+ @Override
+ public void visit(TopiaEntity entity,
+ String propertyName,
+ Class<?> collectionType,
+ Class<?> type,
+ Object value) {
+
+ if (!TopiaEntity.class.isAssignableFrom(type)) {
+
+ // ce n'est pas une association (ce cas ne devrait jamais arrivé)
+ return;
+ }
+
+ visitAssociation(entity, propertyName, (Class<? extends TopiaEntity>) type);
+ }
+
+ @Override
+ public final void visit(TopiaEntity entity,
+ String propertyName,
+ Class<?> collectionType,
+ Class<?> type,
+ int index,
+ Object value) {
+ // Never append
+ }
+
+ @Override
+ public void clear() {
+ // Do nothing
+ }
+
+ protected void visitSimpleProperty(TopiaEntity entity,
+ String propertyName,
+ Class<?> type) {
+
+ Object defaultValue = DefaultSimpleValues.getDefaultValue(type);
+ setProperty(entity, propertyName, defaultValue);
+ }
+
+ protected void visitComposition(TopiaEntity entity,
+ String propertyName,
+ Class<? extends TopiaEntity> type) {
+
+ // Do not continue for parent of Cell entities
+ if (Cell.class.isAssignableFrom(entity.getClass()) && Cell.class.equals(type)) {
+ return;
+ }
+
+ TopiaEntity value = createEntity(type);
+ setProperty(entity, propertyName, value);
+ }
+
+ protected void visitAssociation(TopiaEntity entity,
+ String propertyName,
+ Class<? extends TopiaEntity> type) {
+
+ Collection<TopiaEntity> values = new ArrayList<TopiaEntity>();
+ for (int i=0;i<NB_ASSOCIATIONS;i++) {
+ TopiaEntity value = createEntity(type);
+ values.add(value);
+ }
+ setProperty(entity, propertyName, values);
+ }
+
+ protected void setProperty(TopiaEntity entity,
+ String propertyName,
+ Object value) {
+ try {
+ BeanUtils.setProperty(entity, propertyName, value);
+ } catch (Exception eee) {
+ throw new RuntimeException("Failed to set property '" + propertyName +
+ "' with value '" + value +
+ "' for entity : " + entity, eee);
+ }
+ }
+
+ public <T extends TopiaEntity> T createEntity(Class<T> type) {
+
+ TopiaDAO<T> dao = getDAO(type);
+ try {
+
+ // Creating new entity
+ T created = dao.create();
+ try {
+ // Visit created entity
+ created.accept(this);
+ } catch (TopiaException eee) {
+ throw new EchoBaseTechnicalException("Failed to visit composition", eee);
+ }
+ return created;
+ } catch (TopiaException eee) {
+ throw new RuntimeException("Failed to create entity type '" + type.getName() + "'", eee);
+ }
+ }
+
+ protected <T extends TopiaEntity, D extends TopiaDAO<? super T>> D getDAO(Class<T> type) {
+
+ try {
+ return EchoBaseDAOHelper.getDAO(transaction, type);
+ } catch (TopiaException eee) {
+ throw new RuntimeException("Failed to get dao for type '" + type.getName() + "'", eee);
+ }
+ }
+}
Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java (rev 0)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,116 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.services;
+
+import com.google.common.base.Supplier;
+import com.google.common.collect.Lists;
+import fr.ifremer.echobase.EchoBaseConfiguration;
+import fr.ifremer.echobase.EchoBaseTopiaRootContextSupplierFactory;
+import fr.ifremer.echobase.TestHelper;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.MockEntityVisitorCreator;
+import fr.ifremer.echobase.entities.meta.DbMeta;
+import junit.framework.Assert;
+import org.junit.After;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import java.io.File;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Common methods (manage transaction, services...) to have on EchoBase tests.
+ *
+ * @author sletellier <letellier(a)codelutin.com>
+ * @since 0.2
+ */
+public abstract class AbstractEchoBaseServiceTest extends Assert {
+
+ protected TopiaContext transaction;
+ protected EchoBaseConfiguration config;
+ protected EchoBaseServiceFactory serviceFactory;
+ protected DbMeta dbMeta;
+
+ @After
+ public void after() throws TopiaException {
+ if (transaction != null && !transaction.isClosed()) {
+ transaction.rollbackTransaction();
+ transaction.closeContext();
+ }
+ }
+
+ public TopiaContext getTransaction() throws Exception {
+ if (transaction == null || transaction.isClosed()) {
+ EchoBaseTopiaRootContextSupplierFactory factory =
+ new EchoBaseTopiaRootContextSupplierFactory();
+ File basedir = TestHelper.getBasedir();
+ File target = new File(basedir, "/target");
+ Supplier<TopiaContext> topiaContextSupplier = factory.newEmbeddedDatabase(target);
+ TopiaContext rootContext = topiaContextSupplier.get();
+ transaction = rootContext.beginTransaction();
+ }
+ return transaction;
+ }
+
+ public EchoBaseServiceFactory getServiceFactory() {
+ if (serviceFactory == null) {
+ serviceFactory = new EchoBaseServiceFactory();
+ }
+ return serviceFactory;
+ }
+
+ public EchoBaseConfiguration getConfig() {
+ if (config == null) {
+ config = new EchoBaseConfiguration();
+ }
+ return config;
+ }
+
+ public DbMeta getDbMeta() {
+ if (dbMeta == null) {
+ List<EchoBaseEntityEnum> entityEnums =
+ Lists.newArrayList(EchoBaseEntityEnum.values());
+ dbMeta = new DbMeta(entityEnums.toArray(new EchoBaseEntityEnum[entityEnums.size()]));
+ }
+ return dbMeta;
+ }
+
+ protected <E extends EchoBaseService> E getService(Class<E> clazz) throws Exception {
+ EchoBaseServiceContext serviceContext = EchoBaseServiceContextImpl.newContext(
+ Locale.getDefault(),
+ getTransaction(),
+ getConfig(),
+ getDbMeta(),
+ new EchoBaseServiceFactory()
+ );
+ return getServiceFactory().newService(clazz, serviceContext);
+ }
+
+ public <T extends TopiaEntity> T createMockedEntity(Class<T> type) throws Exception {
+ MockEntityVisitorCreator visitor = new MockEntityVisitorCreator(getTransaction());
+ return visitor.createEntity(type);
+ }
+}
Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java (rev 0)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceTest.java 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,97 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.services;
+
+import fr.ifremer.echobase.TestHelper;
+import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
+import fr.ifremer.echobase.entities.MockEntityVisitorCreator;
+import fr.ifremer.echobase.entities.data.Voyage;
+import fr.ifremer.echobase.entities.data.VoyageDAO;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+
+import java.io.File;
+
+/**
+ * Test all fuctionnality of {@link EmbeddedApplicationService}
+ *
+ * @author sletellier <letellier(a)codelutin.com>
+ * @since 0.2
+ */
+public class EmbeddedApplicationServiceTest extends AbstractEchoBaseServiceTest {
+
+ public static final String TEST_ECHOBASE_EMBEDDED = "test-echobase-embedded";
+
+ public EmbeddedApplicationService getEmbeddedApplicationService() throws Exception {
+ return getService(EmbeddedApplicationService.class);
+ }
+
+ @Test
+ public void testCreateEmbeddedApplication() throws Exception {
+ File embeddedApplication = getEmbeddedApplicationService().createEmbeddedApplication(TEST_ECHOBASE_EMBEDDED);
+ assertTrue(embeddedApplication.exists());
+ }
+
+ @Test
+ public void testCreateVoyageMock() throws Exception {
+ Voyage mockedVoyage = createMockedEntity(Voyage.class);
+ assertNotNull(mockedVoyage);
+ }
+
+ @Test
+ public void testReplicateVoyageEntity() throws Exception {
+
+ // creating mocked voyage
+ Voyage voyageMocked = createMockedEntity(Voyage.class);
+
+ // commit
+ getTransaction().commitTransaction();
+
+ // create new H2 dataBase in target/voyageId
+ String voyageId = voyageMocked.getTopiaId();
+ File testBaseDir = new File(TestHelper.getBasedir(), voyageId);
+ TopiaContext rootContextDest = getEmbeddedApplicationService().createH2Batabase(testBaseDir, false, voyageId);
+
+ // verify that replicated voyage is in new base
+ TopiaContext transactionDest = null;
+ try {
+ transactionDest = rootContextDest.beginTransaction();
+ VoyageDAO voyageDAO = EchoBaseDAOHelper.getVoyageDAO(transactionDest);
+ Object stringDefaultValue = MockEntityVisitorCreator.DefaultSimpleValues.STRING.getDefaultValue();
+ Voyage voyageReplicated = voyageDAO.findByVoyageName((String) stringDefaultValue);
+
+ // assert voyage is in new base
+ assertNotNull(voyageReplicated);
+
+ // and same ids
+ assertEquals(voyageMocked, voyageReplicated);
+
+ // TODO sletellier 20111124 : try to test deph equality between entities
+ } finally {
+ if (transactionDest != null) {
+ transactionDest.closeContext();
+ }
+ }
+ }
+}
Added: trunk/echobase-services/src/test/resources/echobase.properties
===================================================================
--- trunk/echobase-services/src/test/resources/echobase.properties (rev 0)
+++ trunk/echobase-services/src/test/resources/echobase.properties 2011-11-24 13:31:55 UTC (rev 114)
@@ -0,0 +1,24 @@
+###
+# #%L
+# EchoBase :: Services
+#
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2011 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%
+###
+data.directory=${java.io.tmpdir}
\ No newline at end of file
Modified: trunk/echobase-ui/src/main/resources/echobase.properties
===================================================================
--- trunk/echobase-ui/src/main/resources/echobase.properties 2011-11-23 19:08:01 UTC (rev 113)
+++ trunk/echobase-ui/src/main/resources/echobase.properties 2011-11-24 13:31:55 UTC (rev 114)
@@ -24,6 +24,7 @@
project.version=${project.version}
project.site.url=${project.url}
+topia.service.replication=org.nuiton.topia.replication.TopiaReplicationServiceImpl
hibernate.hbm2ddl.auto=none
hibernate.show_sql=false
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-23 19:08:01 UTC (rev 113)
+++ trunk/pom.xml 2011-11-24 13:31:55 UTC (rev 114)
@@ -226,6 +226,13 @@
</dependency>
<dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-service-replication</artifactId>
+ <version>${topiaVersion}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernateVersion}</version>
1
0
r113 - in trunk: echobase-entities/src/main/java/fr/ifremer/echobase echobase-services/src/main/java/fr/ifremer/echobase/services echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export
by tchemit@users.forge.codelutin.com 23 Nov '11
by tchemit@users.forge.codelutin.com 23 Nov '11
23 Nov '11
Author: tchemit
Date: 2011-11-23 20:08:01 +0100 (Wed, 23 Nov 2011)
New Revision: 113
Url: http://forge.codelutin.com/repositories/revision/echobase/113
Log:
use csv model for export sql
Added:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2011-11-23 18:02:27 UTC (rev 112)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2011-11-23 19:08:01 UTC (rev 113)
@@ -113,6 +113,12 @@
return file;
}
+ public char getCsvCharSeparator() {
+ char csvSeparator = applicationConfig.getOption(char.class, EchoBaseConfigurationOption.CSV_CHAR_SEPARATOR.key);
+ Preconditions.checkNotNull(csvSeparator);
+ return csvSeparator;
+ }
+
public Version getApplicationVersion() {
String versionStr =
applicationConfig.getOption(EchoBaseConfigurationOption.VERSION.key);
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java 2011-11-23 18:02:27 UTC (rev 112)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java 2011-11-23 19:08:01 UTC (rev 113)
@@ -50,6 +50,9 @@
SITE_URL("project.siteUrl",
"URL du site de l'application",
"", URL.class),
+ CSV_CHAR_SEPARATOR("csv.separator",
+ "Caractère de séparation pour les fichiers csv",
+ ";", char.class),
WAR_DIRECTORY("war.directory",
"Répertoire où est stoqué le war",
"${data.directory}/war", File.class),
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-23 18:02:27 UTC (rev 112)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-23 19:08:01 UTC (rev 113)
@@ -67,8 +67,6 @@
/** Logger. */
private static final Log log = LogFactory.getLog(DbEditorService.class);
- public static final char CSV_CHAR_SEPARATOR = ';';
-
protected DecoratorService decoratorService;
protected DecoratorService getDecoratorService() {
@@ -463,7 +461,7 @@
protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForImport(TableMeta tableMetas) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(CSV_CHAR_SEPARATOR,
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvCharSeparator(),
tableMetas);
ModelBuilder<E> modelBuilder = model.modelBuilder;
@@ -490,7 +488,7 @@
protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForSave(TableMeta tableMetas) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(CSV_CHAR_SEPARATOR,
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvCharSeparator(),
tableMetas);
ModelBuilder<E> modelBuilder = model.modelBuilder;
@@ -521,7 +519,7 @@
protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForExport(TableMeta tableMetas) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(CSV_CHAR_SEPARATOR,
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvCharSeparator(),
tableMetas);
ModelBuilder<E> modelBuilder = model.modelBuilder;
@@ -548,7 +546,7 @@
protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForLoad(TableMeta tableMetas,
boolean addDecorated) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(CSV_CHAR_SEPARATOR,
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvCharSeparator(),
tableMetas);
ModelBuilder<E> modelBuilder = model.modelBuilder;
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java 2011-11-23 19:08:01 UTC (rev 113)
@@ -0,0 +1,84 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.services;
+
+import org.nuiton.util.csv.ExportableColumn;
+import org.nuiton.util.csv.ImportExportModel;
+import org.nuiton.util.csv.ImportableColumn;
+import org.nuiton.util.csv.ModelBuilder;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Csv model to export sql in {@link ExportSqlService}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ExportSqlCsvModel implements ImportExportModel<Map<String, Object>> {
+
+
+ protected final char separator;
+
+ protected final ModelBuilder<?> modelBuilder;
+
+ public ExportSqlCsvModel(char separator, String[] columnHeaders) {
+ this.separator = separator;
+ modelBuilder = new ModelBuilder<Object>();
+ for (String columnHeader : columnHeaders) {
+ modelBuilder.newColumnForExport(
+ columnHeader,
+ columnHeader
+ );
+ }
+ }
+
+ @Override
+ public char getSeparator() {
+ return separator;
+ }
+
+ @Override
+ public Collection<ExportableColumn<Map<String, Object>, Object>> getColumnsForExport() {
+ return (Collection) modelBuilder.getColumnsForExport();
+ }
+
+ @Override
+ public Collection<ImportableColumn<Map<String, Object>, Object>> getColumnsForImport() {
+ // never do import from this model
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void pushCsvHeaderNames(List<String> headerNames) {
+ }
+
+ @Override
+ public Map<String, Object> newEmptyInstance() {
+ // never do import from this model
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-11-23 18:02:27 UTC (rev 112)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-11-23 19:08:01 UTC (rev 113)
@@ -35,6 +35,7 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaSQLQuery;
+import org.nuiton.util.csv.Export;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -117,8 +118,8 @@
// get a query to count all rows for the request
GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, pager);
try {
- Map<String, Object>[] result = sqlQuery.getResult(getTransaction());
- return result;
+ List<Map<String, Object>> result = sqlQuery.getResult(getTransaction());
+ return result.toArray(new Map[result.size()]);
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException("Could not execute sql query", eee);
}
@@ -142,26 +143,25 @@
}
}
- public String createCsvFileContent(String sql, EchoBaseUser echoBaseUser) {
+ public String createCsvFileContent(String sql) {
GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, null);
- Map<String, Object>[] rows;
- String[] columnNames;
+ List<Map<String, Object>> rows;
try {
rows = sqlQuery.getResult(getTransaction());
- columnNames = sqlQuery.getColumnNames();
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException("Could not execute sql query", eee);
}
- StringBuilder buffer = new StringBuilder();
- int rowCount = rows.length;
- buffer.append(StringUtils.join(columnNames, ";"));
- for (int i = 0; i < rowCount; i++) {
- Map<String, Object> row = rows[i];
- buffer.append('\n').append(StringUtils.join(row.values(), ";"));
+ ExportSqlCsvModel csvModel = sqlQuery.generateCsvModel(getConfiguration().getCsvCharSeparator());
+ Export<Map<String, Object>> exporter = Export.newExport(csvModel, rows);
+ String content = null;
+ try {
+ content = exporter.startExportAsString();
+ return content;
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Could not export sql", eee);
}
- return buffer.toString();
}
protected ExportQueryDAO getDAO() throws TopiaException {
@@ -185,10 +185,18 @@
return columnNames;
}
- public Map<String, Object>[] getResult(TopiaContext tx) throws TopiaException {
+ public ExportSqlCsvModel generateCsvModel(char charSeparator) {
+ ExportSqlCsvModel model = new ExportSqlCsvModel(
+ charSeparator,
+ columnNames
+ );
+ return model;
+ }
+
+ public List<Map<String, Object>> getResult(TopiaContext tx) throws TopiaException {
List<Map<String, Object>> rows =
findMultipleResult((TopiaContextImplementor) tx);
- return rows.toArray(new Map[rows.size()]);
+ return rows;
}
public String[] getColumnNames(TopiaContext tx) throws TopiaException {
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java 2011-11-23 18:02:27 UTC (rev 112)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java 2011-11-23 19:08:01 UTC (rev 113)
@@ -84,10 +84,7 @@
ExportSqlService service = newService(ExportSqlService.class);
contentType = "text/csv";
- String content = service.createCsvFileContent(
- sql,
- getEchoBaseSession().getEchoBaseUser()
- );
+ String content = service.createCsvFileContent(sql);
contentLength = content.length();
inputStream = new ByteArrayInputStream(content.getBytes());
1
0
r112 - in trunk: . src/doc/model src/site/resources src/site/rst
by tchemit@users.forge.codelutin.com 23 Nov '11
by tchemit@users.forge.codelutin.com 23 Nov '11
23 Nov '11
Author: tchemit
Date: 2011-11-23 19:02:27 +0100 (Wed, 23 Nov 2011)
New Revision: 112
Url: http://forge.codelutin.com/repositories/revision/echobase/112
Log:
update pom + add svn properties
Modified:
trunk/pom.xml
trunk/src/doc/model/EchoBase_structure_V5.mm
trunk/src/site/resources/echobase.properties
trunk/src/site/rst/install.rst
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-23 18:01:02 UTC (rev 111)
+++ trunk/pom.xml 2011-11-23 18:02:27 UTC (rev 112)
@@ -171,6 +171,12 @@
</dependency>
<dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-csv</artifactId>
+ <version>${nuitonUtilsVersion}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.nuiton.web</groupId>
<artifactId>nuiton-struts2</artifactId>
<version>${nuitonWebVersion}</version>
Property changes on: trunk/src/doc/model/EchoBase_structure_V5.mm
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/src/site/resources/echobase.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/src/site/rst/install.rst
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r111 - in trunk/echobase-ui: . src/main/java/fr/ifremer/echobase/ui/actions/dbeditor src/main/resources/config src/main/resources/i18n src/main/webapp/WEB-INF src/main/webapp/WEB-INF/jsp/dbeditor
by tchemit@users.forge.codelutin.com 23 Nov '11
by tchemit@users.forge.codelutin.com 23 Nov '11
23 Nov '11
Author: tchemit
Date: 2011-11-23 19:01:02 +0100 (Wed, 23 Nov 2011)
New Revision: 111
Url: http://forge.codelutin.com/repositories/revision/echobase/111
Log:
finish dbeditor (import-export is ok now) + use the final csv api
Added:
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/csvImportResult.jsp
Removed:
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/modifImportResult.jsp
Modified:
trunk/echobase-ui/pom.xml
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/AbstractLoadPage.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntity.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetForeignEntities.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java
trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml
trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties
trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp
Modified: trunk/echobase-ui/pom.xml
===================================================================
--- trunk/echobase-ui/pom.xml 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/pom.xml 2011-11-23 18:01:02 UTC (rev 111)
@@ -286,7 +286,27 @@
</configuration>
</plugin>
- <plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <profiles>
+
+ <profile>
+ <id>do-release</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <properties>
+ <env>prod</env>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
@@ -311,23 +331,8 @@
</overlays>
</configuration>
</plugin>
- </plugins>
- </pluginManagement>
- </build>
-
- <profiles>
-
- <profile>
- <id>do-release</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- <properties>
- <env>prod</env>
- </properties>
+ </plugins>
+ </build>
</profile>
<profile>
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/AbstractLoadPage.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/AbstractLoadPage.java 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/AbstractLoadPage.java 2011-11-23 18:01:02 UTC (rev 111)
@@ -24,18 +24,16 @@
package fr.ifremer.echobase.ui.actions.dbeditor;
import com.google.common.collect.Maps;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.meta.ColumnMeta;
import fr.ifremer.echobase.entities.meta.DbMeta;
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.DbEditorService;
import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
-import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.Map;
-import static org.nuiton.i18n.I18n.l_;
-
/**
* A abstract action which can load the table names and a selected table
* meta datas.
@@ -47,40 +45,40 @@
private static final long serialVersionUID = 1L;
- /** Name of the table to load. */
- protected String tableName;
+ /** Type of entity to load. */
+ protected EchoBaseEntityEnum entityType;
- /** All tables availables */
- protected Map<String, String> tableNames;
+ /** All entities availables. */
+ protected Map<String, String> entityTypes;
- /** Metas of the table */
+ /** Metas of the table. */
protected TableMeta tableMeta;
- public Map<String, String> getTableNames() {
- return tableNames;
+ public Map<String, String> getEntityTypes() {
+ return entityTypes;
}
public List<ColumnMeta> getColumnMetas() {
return tableMeta.getColumns();
}
- public void setTableName(String tableName) {
- this.tableName = tableName;
+ public void setEntityType(EchoBaseEntityEnum entityType) {
+ this.entityType = entityType;
}
- public String getTableName() {
- return tableName;
+ public EchoBaseEntityEnum getEntityType() {
+ return entityType;
}
public void load() throws Exception {
- tableNames = Maps.newTreeMap();
+ entityTypes = Maps.newTreeMap();
DbMeta dbMeta = getEchoBaseApplicationContext().getDbMeta();
for (TableMeta tableMeta : dbMeta) {
String name = tableMeta.getName();
String i18nKey = tableMeta.getI18nKey();
- tableNames.put(name, l_(getLocale(), i18nKey));
+ entityTypes.put(name, _(i18nKey));
}
- if (StringUtils.isEmpty(tableName)) {
+ if (entityType == null) {
// no table selected
addActionMessage(_("echobase.info.no.table.selected"));
@@ -88,7 +86,7 @@
// load table metas
DbEditorService dbEditorService = newService(DbEditorService.class);
- tableMeta = dbEditorService.getTableMetas(tableName);
+ tableMeta = dbEditorService.getTableMetas(entityType);
}
}
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java 2011-11-23 18:01:02 UTC (rev 111)
@@ -23,13 +23,13 @@
*/
package fr.ifremer.echobase.ui.actions.dbeditor;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.services.DbEditorService;
import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
/**
@@ -45,14 +45,14 @@
/** Logger. */
private static final Log log = LogFactory.getLog(ImportTable.class);
- /** Name of the table to load. */
- protected String tableName;
+ /** Type of entity to export. */
+ protected EchoBaseEntityEnum entityType;
/** Default file name to create. */
protected String exportFileName;
/** Stream of the file to export. */
- protected InputStream inputStream;
+ protected transient InputStream inputStream;
/** Length of the file to export. */
protected long contentLength;
@@ -60,8 +60,8 @@
/** Type of the file to export. */
protected String contentType;
- public void setTableName(String tableName) {
- this.tableName = tableName;
+ public void setEntityType(EchoBaseEntityEnum entityType) {
+ this.entityType = entityType;
}
public void setExportFileName(String exportFileName) {
@@ -87,14 +87,16 @@
@Override
public String execute() throws Exception {
- DbEditorService dbEditorService = newService(DbEditorService.class);
+ DbEditorService service = newService(DbEditorService.class);
- File file = dbEditorService.exportDatas(tableName);
+ String content = service.exportDatas(entityType);
+ if (log.isDebugEnabled()) {
+ log.debug("file to export " + content);
+ }
+ contentLength = content.length();
contentType = "text/csv";
- contentLength = file.length();
- inputStream = new FileInputStream(file);
-
+ inputStream = new ByteArrayInputStream(content.getBytes());
return SUCCESS;
}
}
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntities.java 2011-11-23 18:01:02 UTC (rev 111)
@@ -23,7 +23,7 @@
*/
package fr.ifremer.echobase.ui.actions.dbeditor;
-import fr.ifremer.echobase.entities.EntityModificationLogImpl;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.services.DbEditorService;
import fr.ifremer.echobase.ui.actions.AbstractJSONPaginedAction;
import org.apache.commons.logging.Log;
@@ -44,8 +44,8 @@
/** Logger. */
private static final Log log = LogFactory.getLog(ImportTable.class);
- /** Name of the table to load. */
- protected String tableName;
+ /** Type of entity to load. */
+ protected EchoBaseEntityEnum entityType;
/** Datas of the given table. */
protected Map<?, ?>[] datas;
@@ -54,6 +54,10 @@
super("datas_");
}
+ public void setEntityType(EchoBaseEntityEnum entityType) {
+ this.entityType = entityType;
+ }
+
public Map<?, ?>[] getDatas() {
return datas;
}
@@ -78,10 +82,6 @@
return pager.getRecords();
}
- public void setTableName(String tableName) {
- this.tableName = tableName;
- }
-
@Override
public String execute() throws Exception {
@@ -96,10 +96,10 @@
log.debug("sord = " + ascendantOrder);
}
- DbEditorService dbEditorService = newService(DbEditorService.class);
+ DbEditorService service = newService(DbEditorService.class);
- datas = dbEditorService.getDatas(
- tableName,
+ datas = service.getDatas(
+ entityType,
pager,
sortColumn,
ascendantOrder
@@ -114,7 +114,7 @@
public String entityModificationLogs() throws Exception {
- tableName = EntityModificationLogImpl.class.getName();
+ entityType = EchoBaseEntityEnum.EntityModificationLog;
execute();
return SUCCESS;
}
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntity.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntity.java 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntity.java 2011-11-23 18:01:02 UTC (rev 111)
@@ -24,6 +24,7 @@
package fr.ifremer.echobase.ui.actions.dbeditor;
import com.google.common.collect.Maps;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.meta.ColumnMeta;
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.DbEditorService;
@@ -42,8 +43,8 @@
private static final long serialVersionUID = 1L;
- /** Name of the table to load. */
- protected String tableName;
+ /** Type of entity to load. */
+ protected EchoBaseEntityEnum entityType;
/** Id of entity to load. */
protected String id;
@@ -54,8 +55,8 @@
/** Universe of columns metat datas of the selected entity type. */
protected Map<String, ColumnMeta> metas;
- public void setTableName(String tableName) {
- this.tableName = tableName;
+ public void setEntityType(EchoBaseEntityEnum entityType) {
+ this.entityType = entityType;
}
public void setId(String id) {
@@ -73,11 +74,12 @@
@Override
public String execute() throws Exception {
- DbEditorService dbEditorService = newService(DbEditorService.class);
+ DbEditorService service = newService(DbEditorService.class);
- datas = dbEditorService.getData(tableName, id);
+ TableMeta table = serviceContext.getDbMeta().getTable(entityType);
+
+ datas = service.getData(table, id);
- TableMeta table = serviceContext.getDbMeta().getTable(tableName);
List<ColumnMeta> columnMetas = table.getColumns();
metas = Maps.newHashMap();
for (ColumnMeta columnMeta : columnMetas) {
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetForeignEntities.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetForeignEntities.java 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetForeignEntities.java 2011-11-23 18:01:02 UTC (rev 111)
@@ -23,6 +23,7 @@
*/
package fr.ifremer.echobase.ui.actions.dbeditor;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.services.DbEditorService;
import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -40,11 +41,13 @@
private static final long serialVersionUID = 1L;
+ /** Type of entity to load. */
+ protected EchoBaseEntityEnum entityType;
+
+ /** Entities loaded (key are id, values are decoration of entity). */
protected Map<String, String> entities;
- protected String entityType;
-
- public void setEntityType(String entityType) {
+ public void setEntityType(EchoBaseEntityEnum entityType) {
this.entityType = entityType;
}
@@ -56,7 +59,8 @@
public String execute() throws Exception {
DbEditorService service = newService(DbEditorService.class);
- List<TopiaEntity> foreignEntities = service.getForeignDatas(entityType);
+ List<? extends TopiaEntity> foreignEntities =
+ service.getForeignDatas(entityType.getContract());
entities = sortAndDecorate(foreignEntities, null);
return SUCCESS;
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java 2011-11-23 18:01:02 UTC (rev 111)
@@ -24,15 +24,13 @@
package fr.ifremer.echobase.ui.actions.dbeditor;
import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
+import fr.ifremer.echobase.services.CsvImportResult;
import fr.ifremer.echobase.services.DbEditorService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.beans.PropertyDiff;
import java.io.File;
-import java.util.List;
/**
* To import datas from import file.
@@ -53,15 +51,22 @@
/** WTF ? */
protected File importFile;
+ /** Flag to authorize to create an entity if not found in db. */
+ protected boolean createIfNotFound = true;
+
/** WTF ? */
protected String importFileContentType;
/** WTF ? */
protected String importFileFileName;
- /** WTF ? */
- protected List<PropertyDiff[]> propertyDiffs;
+ /** CSV import result */
+ private CsvImportResult result;
+ public CsvImportResult getResult() {
+ return result;
+ }
+
public File getImportFile() {
return importFile;
}
@@ -86,16 +91,14 @@
this.importFileFileName = importFileFileName;
}
- public List<PropertyDiff[]> getPropertyDiffs() {
- if (propertyDiffs == null) {
- return Lists.newArrayList();
- }
- return propertyDiffs;
+
+ public boolean isCreateIfNotFound() {
+ return createIfNotFound;
}
-// public void setPropertyDiffs(List<PropertyDiff[]> propertyDiffs) {
-// this.propertyDiffs = propertyDiffs;
-// }
+ public void setCreateIfNotFound(boolean createIfNotFound) {
+ this.createIfNotFound = createIfNotFound;
+ }
@Override
public String input() throws Exception {
@@ -111,9 +114,11 @@
DbEditorService dbEditorService = newService(DbEditorService.class);
try {
- propertyDiffs = dbEditorService.importDatas(tableName,
- importFile,
- getEchoBaseSession().getEchoBaseUser());
+ result = dbEditorService.importDatas(getEntityType(),
+ importFileFileName,
+ importFile,
+ createIfNotFound,
+ getEchoBaseSession().getEchoBaseUser());
} catch (Exception eee) {
String message = "Failed to import datas : ";
@@ -122,19 +127,7 @@
return ERROR;
}
- for (PropertyDiff[] diffs : propertyDiffs) {
- for (PropertyDiff diff : diffs) {
- String msg = _("echobase.message.modified.property",
- diff.getSourceProperty(),
- diff.getSourceValue(),
- diff.getTargetValue());
- log.info(msg);
-
- addActionMessage(msg);
- }
- }
-
return SUCCESS;
}
}
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java 2011-11-23 18:01:02 UTC (rev 111)
@@ -35,6 +35,7 @@
private static final long serialVersionUID = 1L;
+ /** Default name of the export file. */
protected String exportFileName;
public String getExportFileName() {
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/SaveEntity.java 2011-11-23 18:01:02 UTC (rev 111)
@@ -24,12 +24,12 @@
package fr.ifremer.echobase.ui.actions.dbeditor;
import com.google.common.collect.Maps;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.DbEditorService;
import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.interceptor.ParameterAware;
-import org.nuiton.util.beans.PropertyDiff;
import java.util.List;
import java.util.Map;
@@ -44,8 +44,8 @@
private static final long serialVersionUID = 1L;
- /** Name of the table to load. */
- protected String tableName;
+ /** Type of entity to save. */
+ protected EchoBaseEntityEnum entityType;
/** id of entity to save. */
protected String id;
@@ -55,14 +55,10 @@
protected Map<String, String[]> params;
- public void setTableName(String tableName) {
- this.tableName = tableName;
+ public void setEntityType(EchoBaseEntityEnum entityType) {
+ this.entityType = entityType;
}
- public String getTableName() {
- return tableName;
- }
-
public void setId(String id) {
this.id = id;
}
@@ -70,8 +66,8 @@
@Override
public String execute() throws Exception {
- DbEditorService dbEditorService = newService(DbEditorService.class);
- TableMeta tableMeta = dbEditorService.getTableMetas(tableName);
+ DbEditorService service = newService(DbEditorService.class);
+ TableMeta tableMeta = service.getTableMetas(entityType);
Map<String, String> properties = Maps.newHashMap();
List<String> columnNames = tableMeta.getColumnNames();
for (String columnName : columnNames) {
@@ -93,19 +89,12 @@
}
}
- PropertyDiff[] diffs =
- dbEditorService.saveEntity(tableMeta,
- id,
- properties,
- getEchoBaseSession().getEchoBaseUser());
+ service.saveEntity(tableMeta,
+ id,
+ properties,
+ getEchoBaseSession().getEchoBaseUser());
- for (PropertyDiff diff : diffs) {
- addActionMessage(_("echobase.message.modified.property",
- diff.getSourceProperty(),
- diff.getSourceValue(),
- diff.getTargetValue())
- );
- }
+
return SUCCESS;
}
Modified: trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/resources/config/struts-dbeditor.xml 2011-11-23 18:01:02 UTC (rev 111)
@@ -75,9 +75,8 @@
<!-- Import some entities from a csv file -->
<action name="doImport" class="fr.ifremer.echobase.ui.actions.dbeditor.ImportTable">
<interceptor-ref name="paramsPrepareParamsStackLoggued"/>
- <result>/WEB-INF/jsp/dbeditor/modifImportResult.jsp</result>
+ <result>/WEB-INF/jsp/dbeditor/csvImportResult.jsp</result>
<result name="input">/WEB-INF/jsp/dbeditor/dbeditor.jsp</result>
- <result name="error">/WEB-INF/jsp/dbeditor/modifImportResult.jsp</result>
</action>
<!-- Export a selected entity type to a csv file -->
Modified: trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties
===================================================================
--- trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-23 18:01:02 UTC (rev 111)
@@ -21,6 +21,7 @@
echobase.common.admin=Administrateur
echobase.common.comment=Commentaire
echobase.common.email=Email
+echobase.common.entityType=Type d'entité
echobase.common.jdbcLogin=Login de connexion
echobase.common.jdbcPassword=Mot de passe
echobase.common.jdbcUrl=Url de connexion
@@ -47,10 +48,11 @@
echobase.header.request.result=Résultat de la requête sql
echobase.header.user.gridTitle=Liste des utilisateurs
echobase.header.voyageSelect=Selectionnez un voyage
-echobase.info.dbeditor.propertyDiffsResult=Nombres d'entrées modifiés \: %s
+echobase.info.dbeditor.propertyDiffsResult=Résultat d'import de données
echobase.info.no.sqlQuery.saved=Aucune requête d'export sql enregistré
echobase.info.no.sqlQuery.selected=Aucune requête d'export sql sélectionnée
echobase.info.no.table.selected=Aucune table sélectionnée
+echobase.label.createIfNotFound=Créer les entités non trouvées en base
echobase.label.embeddedApplicationFileName=Nom de l'archive à télécharger
echobase.label.embeddedWarFileName=Nom du war à utiliser
echobase.label.exportFileName=Nom du fichier d'export
@@ -66,11 +68,12 @@
echobase.label.locale.english=Anglais
echobase.label.locale.french=Français
echobase.label.login=Connexion
+echobase.label.numberOfCreatedEntities=Nombre d'entitiés créées
+echobase.label.numberOfUpdatedEntities=Nombre d'entitiés mises à jour
echobase.label.query.description=Description
echobase.label.query.name=Nom
echobase.label.query.sql=SQL
echobase.label.sqlQueries=Requêtes enregistrées
-echobase.label.tableName=Nom de la table
echobase.label.user.login=Utilisateur \: %s
echobase.label.voyageToSelect=Voyage à exporter
echobase.legend.dbeditor.edit=Edition de '%s'
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml 2011-11-23 18:01:02 UTC (rev 111)
@@ -30,6 +30,7 @@
<pattern>/user/login*</pattern>
<pattern>/index*</pattern>
<pattern>/dbeditor/getForeignEntities*</pattern>
+ <pattern>/dbeditor/doExport*</pattern>
<pattern>/export/exportSqlResult*</pattern>
</excludes>
Copied: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/csvImportResult.jsp (from rev 107, trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/modifImportResult.jsp)
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/csvImportResult.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/csvImportResult.jsp 2011-11-23 18:01:02 UTC (rev 111)
@@ -0,0 +1,49 @@
+<%--
+ #%L
+ EchoBase :: UI
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2011 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%
+ --%>
+<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<title><s:text name="echobase.title.dbEditor"/></title>
+
+<h2>
+ <s:text name="echobase.info.dbeditor.propertyDiffsResult"/>
+</h2>
+
+<fieldset>
+ <s:label key="result.entityType"
+ label="%{getText('echobase.common.entityType')}"/>
+
+ <s:label key="result.importFileName"
+ label="%{getText('echobase.label.importFile')}"/>
+
+ <s:label key="result.numberCreated"
+ label="%{getText('echobase.label.numberOfCreatedEntities')}"/>
+
+ <s:label key="result.numberUpdated"
+ label="%{getText('echobase.label.numberOfUpdatedEntities')}"/>
+</fieldset>
+
+<s:a namespace="/dbeditor" action="dbeditor">
+ <s:param name="entityType" value="%{result.entityType}"/>
+ <s:text name="echobase.action.return"/>
+</s:a>
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/csvImportResult.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp 2011-11-23 18:01:02 UTC (rev 111)
@@ -31,7 +31,7 @@
<s:url id="reloadUrl" action="dbeditor" namespace="/dbeditor"/>
<s:url id="getTableData" action="getTableData" namespace="/dbeditor"/>
-<s:set name="tableSelected" value="%{tableName != null && tableName != ''}"/>
+<s:set name="tableSelected" value="%{entityType != null}"/>
<title><s:text name="echobase.title.dbEditor"/></title>
@@ -51,8 +51,8 @@
});
// on table name change, let's reload reload this page
- $('[name="tableName"]').change(function(event) {
- var url = "${reloadUrl}?" + $.param({tableName:this.value});
+ $('[name="entityType"]').change(function(event) {
+ var url = "${reloadUrl}?" + $.param({entityType:this.value});
window.location = url;
});
@@ -78,11 +78,11 @@
var id = jQuery.struts2_jquery['datas']['selectedRow'];
// get table name
- var tableName = "${tableName}";
+ var entityType = "${entityType}";
// get entity value from json
jQuery.getJSON("${getTableData}",
- { "tableName":tableName, "id":id }, function (result) {
+ { "entityType":entityType, "id":id }, function (result) {
// get metadatas from the response
var metas = result.metas;
@@ -182,8 +182,8 @@
}
</script>
-<s:select key="tableName" label='%{getText("echobase.label.tableName")}'
- list="tableNames" headerKey="" headerValue=""/>
+<s:select key="entityType" label='%{getText("echobase.common.entityType")}'
+ list="entityTypes" headerKey="" headerValue=""/>
<br class="clearBoth"/>
@@ -199,16 +199,19 @@
<s:form id="importForm" namespace="/dbeditor" method="post"
enctype="multipart/form-data">
- <s:hidden key="tableName" label=''/>
+ <s:hidden key="entityType" label=''/>
<s:file key="importFile" required="true"
label="%{getText('echobase.label.importFile')}"/>
+
+ <s:checkbox key='createIfNotFound' value='true'
+ label='%{getText("echobase.label.createIfNotFound")}'/>
<br/>
<s:submit key="echobase.action.importTable" action="doImport"
align="right"/>
</s:form>
<s:form id="exportForm" namespace="/dbeditor" method="post">
- <s:hidden key="tableName" label=''/>
+ <s:hidden key="entityType" label=''/>
<s:textfield key="exportFileName" required="true" size="100"
label="%{getText('echobase.label.exportFileName')}"/>
@@ -225,11 +228,11 @@
<s:if test="tableSelected">
<s:url id="loadUrl" action="getTableDatas" namespace="/dbeditor"
escapeAmp="false">
- <s:param name="tableName" value="%{tableName}"/>
+ <s:param name="entityType" value="%{entityType}"/>
</s:url>
<s:set var="tableI18nName"
- value="%{getText('echobase.common.tableDatas', tableNames[tableName])}"/>
+ value="%{getText('echobase.common.tableDatas', entityTypes[entityType])}"/>
<sjg:grid id="datas" dataType="json" href="%{loadUrl}" gridModel="datas"
caption="%{tableI18nName}"
@@ -284,9 +287,9 @@
</s:text>
</legend>
- <s:hidden key="tableName" label=''/>
+ <s:hidden key="entityType" label=''/>
- <s:hidden id="id" name="id"/>
+ <s:hidden key="id" label=''/>
<s:iterator value="columnMetas" var="meta" status="status">
<s:if test="#meta.fK">
Deleted: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/modifImportResult.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/modifImportResult.jsp 2011-11-23 17:51:57 UTC (rev 110)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/modifImportResult.jsp 2011-11-23 18:01:02 UTC (rev 111)
@@ -1,36 +0,0 @@
-<%--
- #%L
- EchoBase :: UI
-
- $Id$
- $HeadURL$
- %%
- Copyright (C) 2011 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%
- --%>
-<%@ page language="java" contentType="text/html" pageEncoding="utf-8" %>
-<%@ taglib prefix="s" uri="/struts-tags" %>
-<title><s:text name="echobase.title.dbEditor"/></title>
-
-<h2>
- <s:text name="echobase.info.dbeditor.propertyDiffsResult">
- <s:param value="%{propertyDiffs.size}"/>
- </s:text>
-</h2>
-<s:a namespace="/dbeditor" action="dbeditor">
- <s:param name="tableName" value="%{tableName}"/>
- <s:text name="echobase.action.return"/>
-</s:a>
1
0
r110 - in trunk/echobase-services: . src/main/java/fr/ifremer/echobase/services
by tchemit@users.forge.codelutin.com 23 Nov '11
by tchemit@users.forge.codelutin.com 23 Nov '11
23 Nov '11
Author: tchemit
Date: 2011-11-23 18:51:57 +0100 (Wed, 23 Nov 2011)
New Revision: 110
Url: http://forge.codelutin.com/repositories/revision/echobase/110
Log:
using csv model for all dbeditor commands
Added:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java
Modified:
trunk/echobase-services/pom.xml
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchoBaseService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java
Modified: trunk/echobase-services/pom.xml
===================================================================
--- trunk/echobase-services/pom.xml 2011-11-23 17:50:27 UTC (rev 109)
+++ trunk/echobase-services/pom.xml 2011-11-23 17:51:57 UTC (rev 110)
@@ -38,6 +38,11 @@
<artifactId>nuiton-utils</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-csv</artifactId>
+ </dependency>
+
<!--dependency>
<groupId>org.nuiton.i18n</groupId>
<artifactId>nuiton-i18n</artifactId>
@@ -55,10 +60,10 @@
<artifactId>xwork-core</artifactId>
</dependency-->
- <dependency>
+ <!--dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
- </dependency>
+ </dependency-->
<dependency>
<groupId>commons-logging</groupId>
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchoBaseService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchoBaseService.java 2011-11-23 17:50:27 UTC (rev 109)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchoBaseService.java 2011-11-23 17:51:57 UTC (rev 110)
@@ -24,9 +24,17 @@
package fr.ifremer.echobase.services;
import fr.ifremer.echobase.EchoBaseConfiguration;
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.meta.DbMeta;
+import org.apache.commons.lang3.time.DateUtils;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaDAO;
+import org.nuiton.topia.persistence.TopiaEntity;
+import java.util.Date;
import java.util.Locale;
/**
@@ -63,5 +71,31 @@
return e;
}
+ protected <E extends TopiaEntity> TopiaDAO<E> getDAO(EchoBaseEntityEnum entityEnum) throws TopiaException {
+ TopiaDAO<E> dao = getDAO((Class<E>) entityEnum.getContract());
+ return dao;
+ }
+ protected <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityType) throws TopiaException {
+ TopiaDAO<E> dao = EchoBaseDAOHelper.<E, TopiaDAO<E>>getDAO(
+ getTransaction(),
+ entityType);
+
+ return dao;
+ }
+
+ protected void commitTransaction(String errorMessage) {
+ try {
+ getTransaction().commitTransaction();
+ } catch (TopiaException eee) {
+ throw new EchoBaseTechnicalException(errorMessage, eee);
+ }
+ }
+
+ protected Date newDate() {
+ Date result = new Date();
+ DateUtils.setMilliseconds(result,0);
+ return result;
+ }
+
}
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java 2011-11-23 17:51:57 UTC (rev 110)
@@ -0,0 +1,98 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.services;
+
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+
+import java.io.Serializable;
+
+/**
+ * A simple csv result bean just to keep the number of created or
+ * updated entities.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class CsvImportResult implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** type of entity to import csv datas. */
+ protected EchoBaseEntityEnum entityType;
+
+ /** Name of the csv file to import. */
+ protected String importFileName;
+
+ /** Count of created entities. */
+
+ protected int numberCreated;
+
+ /** Count of updated entities. */
+ protected int numberUpdated;
+
+ /** Flag to authorize to create entities not found in db. */
+ protected boolean createIfNotFound;
+
+
+ public EchoBaseEntityEnum getEntityType() {
+ return entityType;
+ }
+
+
+ public String getImportFileName() {
+ return importFileName;
+ }
+
+ public int getNumberCreated() {
+ return numberCreated;
+ }
+
+ public int getNumberUpdated() {
+ return numberUpdated;
+ }
+
+ public boolean isCreateIfNotFound() {
+ return createIfNotFound;
+ }
+
+ public void incrementsNumberCreated() {
+ numberCreated++;
+ }
+
+ public void incrementsNumberUpdated() {
+ numberUpdated++;
+ }
+
+ public void setEntityType(EchoBaseEntityEnum entityType) {
+ this.entityType = entityType;
+ }
+
+ public void setImportFileName(String importFileName) {
+ this.importFileName = importFileName;
+ }
+
+ public void setCreateIfNotFound(boolean createIfNotFound) {
+ this.createIfNotFound = createIfNotFound;
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java 2011-11-23 17:51:57 UTC (rev 110)
@@ -0,0 +1,134 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.services;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Maps;
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.csv.Common;
+import org.nuiton.util.csv.ValueFormatter;
+import org.nuiton.util.csv.ValueParserFormatter;
+
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Usefull class to build csv import-export models.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class CsvModelUtil extends Common {
+
+ public static <E extends TopiaEntity> ForeignKeyValue<E> newForeignKeyValue(Class<E> type) {
+ return new ForeignKeyValue<E>(type);
+ }
+
+ public static <E extends TopiaEntity> ForeignKeyValue<E> newForeignKeyValue(Class<E> type, Collection<E> entitites) {
+ return new ForeignKeyValue<E>(type, entitites);
+ }
+
+ public static <E extends TopiaEntity> ForeignKeyDecoratedValue<E> newForeignKeyDecoratedValue(Class<E> entityType, DecoratorService decoratorService, Locale locale) {
+ return new ForeignKeyDecoratedValue<E>(entityType, decoratorService, locale);
+ }
+
+ public static class ForeignKeyValue<E extends TopiaEntity> implements ValueParserFormatter<E> {
+
+ protected final Class<E> entityType;
+
+ protected final Map<String, E> universe;
+
+ public ForeignKeyValue(Class<E> entityType, Collection<E> entitites) {
+ this.entityType = entityType;
+ universe = Maps.uniqueIndex(entitites, new Function<E, String>() {
+ @Override
+ public String apply(E input) {
+ return input.getTopiaId();
+ }
+ });
+ }
+
+ public ForeignKeyValue(Class<E> entityType) {
+ this.entityType = entityType;
+ universe = Maps.newHashMap();
+ }
+
+ @Override
+ public E parse(String value) throws ParseException {
+ E result = null;
+ if (StringUtils.isNotBlank(value)) {
+
+ // get entity from universe
+ result = universe.get(value);
+
+ if (result == null) {
+
+ // can not find entity this is a big problem for us...
+ throw new EchoBaseTechnicalException(
+ "Could not find entity with name " + value);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String format(E e) {
+ String value = "";
+ if (e != null) {
+ value = e.getTopiaId();
+ }
+ return value;
+ }
+ }
+
+ public static class ForeignKeyDecoratedValue<E extends TopiaEntity> implements ValueFormatter<E> {
+
+ protected final Class<E> entityType;
+
+ protected final DecoratorService decoratorService;
+
+ protected final Locale locale;
+
+ public ForeignKeyDecoratedValue(Class<E> entityType, DecoratorService decoratorService, Locale locale) {
+ this.entityType = entityType;
+ this.decoratorService = decoratorService;
+ this.locale = locale;
+
+ }
+
+ @Override
+ public String format(E e) {
+ String value = "";
+ if (e != null) {
+
+ value = decoratorService.decorate(locale, e, null);
+ }
+ return value;
+ }
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java 2011-11-23 17:51:57 UTC (rev 110)
@@ -0,0 +1,159 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 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.services;
+
+import fr.ifremer.echobase.entities.meta.TableMeta;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.csv.ExportableColumn;
+import org.nuiton.util.csv.ImportExportModel;
+import org.nuiton.util.csv.ImportableColumn;
+import org.nuiton.util.csv.ModelBuilder;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Import/Export csv model.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class DbEditorCsvModel<E extends TopiaEntity> implements ImportExportModel<E> {
+
+ protected final char separator;
+
+ protected final TableMeta tableMeta;
+
+ protected ModelBuilder<E> modelBuilder;
+
+ public DbEditorCsvModel(char separator, TableMeta tableMeta) {
+ this.separator = separator;
+ this.tableMeta = tableMeta;
+ modelBuilder = new ModelBuilder<E>();
+ }
+
+ @Override
+ public char getSeparator() {
+ return separator;
+ }
+
+ @Override
+ public Collection<ExportableColumn<E, Object>> getColumnsForExport() {
+ return (Collection)
+ modelBuilder.getColumnsForExport();
+ }
+
+ @Override
+ public Collection<ImportableColumn<E, Object>> getColumnsForImport() {
+ return (Collection)
+ modelBuilder.getColumnsForImport();
+ }
+
+ @Override
+ public void pushCsvHeaderNames(List<String> headerNames) {
+ }
+
+ @Override
+ public E newEmptyInstance() {
+ return (E) tableMeta.newEntity();
+ }
+
+ public void addForeignKeyForExport(String propertyName,
+ Class<TopiaEntity> entityType) {
+
+ modelBuilder.newColumnForExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.newForeignKeyValue(entityType)
+ );
+ }
+
+ public void addForeignKeyForImport(String propertyName,
+ Class<TopiaEntity> entityType,
+ Collection<TopiaEntity> universe) {
+
+ modelBuilder.newMandatoryColumn(
+ propertyName,
+ propertyName,
+ CsvModelUtil.newForeignKeyValue(entityType, universe)
+ );
+ }
+
+ public <E extends TopiaEntity> void addDefaultColumn(String propertyName,
+ Class<?> type) {
+
+ if (Date.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.DAY_TIME_SECOND
+ );
+ } else if (float.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.PRIMITIVE_FLOAT
+ );
+ } else if (Float.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.FLOAT
+ );
+ } else if (int.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.PRIMITIVE_INTEGER
+ );
+ } else if (Integer.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.INTEGER
+ );
+ } else if (boolean.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.PRIMITIVE_BOOLEAN
+ );
+ } else if (Boolean.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.BOOLEAN
+ );
+ } else {
+
+ // string
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName
+ );
+ }
+ }
+
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-23 17:50:27 UTC (rev 109)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-23 17:51:57 UTC (rev 110)
@@ -24,19 +24,15 @@
package fr.ifremer.echobase.services;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import fr.ifremer.echobase.EchoBaseTechnicalException;
-import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.EntityModificationLog;
-import fr.ifremer.echobase.entities.EntityModificationLogDAO;
import fr.ifremer.echobase.entities.meta.ColumnMeta;
import fr.ifremer.echobase.entities.meta.DbMeta;
import fr.ifremer.echobase.entities.meta.TableMeta;
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -44,18 +40,19 @@
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.topia.persistence.util.EntityOperator;
-import org.nuiton.util.StringUtil;
import org.nuiton.util.beans.BeanMonitor;
import org.nuiton.util.beans.PropertyDiff;
+import org.nuiton.util.csv.Export;
+import org.nuiton.util.csv.ExportableColumn;
+import org.nuiton.util.csv.Import;
+import org.nuiton.util.csv.ImportableColumn;
+import org.nuiton.util.csv.ModelBuilder;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -70,14 +67,9 @@
/** Logger. */
private static final Log log = LogFactory.getLog(DbEditorService.class);
- public static final String EXPORT_FILE_PREFIX = "modifExport-";
- public static final String SCV_EXT = ".csv";
- public static final String EXPORT_FILE_FORMAT_DATE = "yyyyMMddHHmmss";
- public static final String BASE_EDITOR_FORMAT_DATE = "dd/MM/yyyy HH:mm:ss";
- public static final String CSV_SEPARATOR = ";";
+ public static final char CSV_CHAR_SEPARATOR = ';';
protected DecoratorService decoratorService;
- protected SimpleDateFormat dateFormat;
protected DecoratorService getDecoratorService() {
if (decoratorService == null) {
@@ -86,67 +78,50 @@
return decoratorService;
}
- public SimpleDateFormat getDateFormat() {
- if (dateFormat == null) {
- dateFormat = new SimpleDateFormat(BASE_EDITOR_FORMAT_DATE);
- }
- return dateFormat;
- }
-
- public List<TopiaEntity> getForeignDatas(String entityType) {
+ public <E extends TopiaEntity> List<E> getForeignDatas(Class<E> entityType) {
Preconditions.checkNotNull(entityType);
- EchoBaseEntityEnum entityEnum = EchoBaseEntityEnum.valueOf(entityType);
- Preconditions.checkNotNull(entityEnum);
- Class<? extends TopiaEntity> contract = entityEnum.getContract();
try {
- TopiaDAO dao = EchoBaseDAOHelper.getDAO(getTransaction(), contract);
+ TopiaDAO<E> dao = getDAO(entityType);
- List result = dao.findAll();
+ List<E> result = dao.findAll();
return result;
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException("Could not obtain data", eee);
}
}
- public TableMeta getTableMetas(String tableName) {
+ public TableMeta getTableMetas(EchoBaseEntityEnum tableName) {
DbMeta dbMeta = getDbMeta();
TableMeta result = dbMeta.getTable(tableName);
return result;
}
- public Map<?, ?>[] getAllDatas(String tableName, boolean addDecorated) {
- return getDatas(tableName, null, null, null, addDecorated);
- }
-
//TODO Use an object to filter datas
- public Map<?, ?>[] getDatas(String tableName,
+ public Map<?, ?>[] getDatas(EchoBaseEntityEnum entityType,
Pager pager,
String sidx,
Boolean ascendantOrder) {
- return getDatas(tableName, pager, sidx, ascendantOrder, true);
+ return getDatas(entityType, pager, sidx, ascendantOrder, true);
}
- public Map<?, ?>[] getDatas(String tableName,
- Pager pager,
- String sidx,
- Boolean ascendantOrder,
- boolean addDecorated) {
- DbMeta dbMeta = getDbMeta();
- TableMeta tableMeta = dbMeta.getTable(tableName);
+ public <E extends TopiaEntity> List<E> getEntities(TableMeta tableMeta,
+ Pager pager,
+ String sidx,
+ Boolean ascendantOrder) {
+
+ List<E> result;
EchoBaseEntityEnum entityEnum = tableMeta.getEntityEnum();
Class<? extends TopiaEntity> contract = entityEnum.getContract();
try {
- TopiaDAO dao = EchoBaseDAOHelper.getDAO(getTransaction(), contract);
+ TopiaDAO dao = getDAO(contract);
// first query to count datas
TopiaQuery countQuery = dao.createQuery("e");
countQuery.addSelect("count(*)");
int count = dao.countByQuery(countQuery);
- List<?> all;
- int resultSize;
if (pager != null) {
pager.setRecords(count);
pager.computeIndexesAndPageCount();
@@ -154,8 +129,6 @@
int from = pager.getStartIndex();
int to = pager.getEndIndex();
- resultSize = to - from;
-
if (log.isDebugEnabled()) {
log.debug("Count = " + count);
log.debug("page = " + pager.getPageNumber());
@@ -174,319 +147,445 @@
}
}
query.setLimit(from, to - 1);
- all = dao.findAllByQuery(query);
+ result = dao.findAllByQuery(query);
} else {
// Get all
- all = dao.findAll();
- resultSize = count;
+ result = dao.findAll();
}
- Map<?, ?>[] rows = new Map[resultSize];
-
- int i = 0;
- for (Object o : all) {
- TopiaEntity entity = (TopiaEntity) o;
- Map<String, Object> row = loadRow(tableMeta, entity, addDecorated);
- rows[i++] = row;
- }
- return rows;
+ return result;
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException("Could not obtain data", eee);
}
}
- public Map<?, ?> getData(String tableName,
- String topiaId) {
+ public Map<?, ?>[] getDatas(EchoBaseEntityEnum entityType,
+ Pager pager,
+ String sidx,
+ Boolean ascendantOrder,
+ boolean addDecorated) {
- DbMeta dbMeta = getDbMeta();
- TableMeta tableMeta = dbMeta.getTable(tableName);
+ TableMeta tableMeta = getTableMetas(entityType);
+
+ List<TopiaEntity> entities = getEntities(tableMeta,
+ pager,
+ sidx,
+ ascendantOrder
+ );
+
+ Map<?, ?>[] rows = new Map[entities.size()];
+
+ DbEditorCsvModel<TopiaEntity> model =
+ buildForLoad(tableMeta, addDecorated);
+
+ int i = 0;
+ for (Object o : entities) {
+ TopiaEntity entity = (TopiaEntity) o;
+ Map<String, Object> row = loadRow(entity, model);
+ rows[i++] = row;
+ }
+ return rows;
+ }
+
+ public Map<?, ?> getData(TableMeta tableMeta, String topiaId) {
+
EchoBaseEntityEnum entityEnum = tableMeta.getEntityEnum();
- Class<? extends TopiaEntity> contract = entityEnum.getContract();
try {
- TopiaDAO dao = EchoBaseDAOHelper.getDAO(getTransaction(), contract);
+ TopiaDAO<?> dao = getDAO(entityEnum.getContract());
TopiaEntity entity = dao.findByTopiaId(topiaId);
- return loadRow(tableMeta, entity, true);
+ DbEditorCsvModel<TopiaEntity> model = buildForLoad(tableMeta, true);
+ return loadRow(entity, model);
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException("Could not obtain data", eee);
}
}
- public PropertyDiff[] saveEntity(TableMeta tableMeta,
- String id,
- Map<String, String> properties,
- EchoBaseUser user) {
+ public void saveEntity(TableMeta tableMeta,
+ String id,
+ Map<String, String> properties,
+ EchoBaseUser user) {
- return saveEntity(tableMeta, id, properties, user, true);
+ // transform properties entity
+ DbEditorCsvModel<TopiaEntity> model = buildForSave(tableMeta);
+
+ TopiaEntity entity = model.newEmptyInstance();
+ entity.setTopiaId(id);
+
+ for (ImportableColumn<TopiaEntity, Object> column : model.getColumnsForImport()) {
+ String propertyName = column.getHeaderName();
+ String stringValue = properties.get(propertyName);
+ Object o;
+ try {
+ o = column.parseValue(stringValue);
+ } catch (Exception e) {
+ throw new EchoBaseTechnicalException("Could not parse property [" + propertyName + "] with value " + stringValue);
+ }
+ try {
+ column.setValue(entity, o);
+ } catch (Exception e) {
+ throw new EchoBaseTechnicalException("Could not set property [" + propertyName + "] with value " + stringValue + " to entity " + entity);
+ }
+ }
+
+ saveEntity(
+ tableMeta,
+ "Modification utilisateur",
+ entity,
+ user,
+ false,
+ null
+ );
+ commitTransaction("Could not commit transaction");
}
- public PropertyDiff[] saveEntity(TableMeta tableMeta,
- String id,
- Map<String, String> properties,
- EchoBaseUser user,
- boolean commit) {
+ public CsvImportResult importDatas(EchoBaseEntityEnum entityType,
+ String importFileName,
+ File importFile,
+ boolean createIfNotFound,
+ EchoBaseUser user) {
+ TableMeta tableMeta = getTableMetas(entityType);
+ DbEditorCsvModel<TopiaEntity> csvModel = buildForImport(tableMeta);
+ String messagePrefix = "Import du fichier " + importFileName;
- Class<? extends TopiaEntity> entityType = tableMeta.getEntityType();
+ CsvImportResult result = new CsvImportResult();
+ result.setImportFileName(importFileName);
+ result.setEntityType(entityType);
+ BufferedReader bf = null;
+ try {
+
+ bf = new BufferedReader(new FileReader(importFile));
+
+ Import<TopiaEntity> importer = Import.newImport(csvModel, bf);
+
+ Iterator<TopiaEntity> iterator = importer.startImport();
+
+ try {
+ while (iterator.hasNext()) {
+ TopiaEntity entity = iterator.next();
+ saveEntity(tableMeta,
+ messagePrefix,
+ entity,
+ user,
+ createIfNotFound,
+ result
+ );
+ }
+ } finally {
+
+ importer.stopImport();
+ }
+
+ commitTransaction("Could not commit transaction");
+ } catch (EchoBaseTechnicalException eee) {
+ throw eee;
+ } catch (Exception eee) {
+ log.error("Failed to read import file " + importFile.getName(), eee);
+ throw new EchoBaseTechnicalException(eee);
+ } finally {
+ IOUtils.closeQuietly(bf);
+ }
+
+ return result;
+ }
+
+ public String exportDatas(EchoBaseEntityEnum entityType) {
+
+ TableMeta tableMeta = getTableMetas(entityType);
+
+ List<TopiaEntity> datas = getEntities(tableMeta, null, null, null);
+
+ DbEditorCsvModel<TopiaEntity> model = buildForExport(tableMeta);
+
+ Export<TopiaEntity> export = Export.newExport(model, datas);
+
+ try {
+ return export.startExportAsString();
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Can not export datas", eee);
+ }
+ }
+
+ protected void saveEntity(TableMeta tableMeta,
+ String messagePrefix,
+ TopiaEntity entity,
+ EchoBaseUser user,
+ boolean createIfNotFound,
+ CsvImportResult result) {
+
String[] columnNames = tableMeta.getColumnNamesAsArray();
- BeanMonitor monitor = new BeanMonitor(columnNames);
+ BeanMonitor monitor = null;
+ String id = entity.getTopiaId();
+
try {
- TopiaDAO dao = EchoBaseDAOHelper.getDAO(
- getTransaction(),
- entityType);
+ TopiaDAO<TopiaEntity> dao = getDAO(tableMeta.getEntityEnum());
TopiaEntity entityToSave;
// Find or create entity if no id
boolean create = StringUtils.isEmpty(id);
if (create) {
+
entityToSave = dao.create();
+ result.incrementsNumberCreated();
} else {
+
entityToSave = dao.findByTopiaId(id);
- }
- monitor.setBean(entityToSave);
- for (Map.Entry<String, String> entry : properties.entrySet()) {
- String propertyName = entry.getKey();
- String propertyValue = entry.getValue();
- Object value;
- ColumnMeta columnMeta = tableMeta.getColumns(propertyName);
- if (columnMeta.isFK()) {
+ if (entityToSave == null) {
- // let's find the entity
- TopiaDAO daoFK = EchoBaseDAOHelper.getDAO(
- getTransaction(),
- (Class<? extends TopiaEntity>) columnMeta.getType());
- value = daoFK.findByTopiaId(propertyValue);
+ if (!createIfNotFound) {
- } else if (Date.class.equals(columnMeta.getType())) {
- value = getDateFormat().parse(propertyValue);
- } else {
- value = propertyValue;
+ // this is an error
+ throw new EchoBaseTechnicalException("Could not found entity with id " + id);
+ } else {
+ entityToSave = dao.create(TopiaEntity.TOPIA_ID, id);
+
+ }
}
- BeanUtils.setProperty(entityToSave,
- propertyName,
- value);
+ // monitor the existing bean
+ monitor = new BeanMonitor(columnNames);
+ monitor.setBean(entityToSave);
+
+ result.incrementsNumberUpdated();
}
- PropertyDiff[] propertyDiffs = monitor.getPropertyDiffs();
+ tableMeta.copy(entity, entityToSave);
- int length = propertyDiffs.length;
+ PropertyDiff[] propertyDiffs = monitor == null ? null :
+ monitor.getPropertyDiffs();
- if (length > 0) {
+ createEntityModificationLog(
+ tableMeta,
+ messagePrefix,
+ entityToSave,
+ user,
+ propertyDiffs
+ );
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Could not update entity", eee);
+ } finally {
+ if (monitor != null) {
+ monitor.setBean(null);
+ }
+ }
+ }
- // something was modified on the entity
+ protected void createEntityModificationLog(
+ TableMeta tableMeta,
+ String messagePrefix,
+ TopiaEntity entity,
+ EchoBaseUser user,
+ PropertyDiff[] propertyDiffs) throws TopiaException {
- EntityModificationLogDAO dao1 =
- EchoBaseDAOHelper.getEntityModificationLogDAO(
- getTransaction()
- );
+ StringBuilder buffer;
- StringBuilder buffer;
+ String topiaId = entity.getTopiaId();
- if (create) {
- buffer = new StringBuilder("Une entité à été crée :");
- } else {
- if (length == 1) {
- buffer = new StringBuilder("Une propriété a été modifiée :");
- } else {
- buffer = new StringBuilder(length + " propriétés ont été modifiées :");
- }
- }
- for (int i = 0; i < length; i++) {
- PropertyDiff diff = propertyDiffs[i];
+ boolean create = propertyDiffs == null;
- Object sourceValue = diff.getSourceValue();
- Object targetValue = diff.getTargetValue();
+ buffer = new StringBuilder(messagePrefix + "\n");
+ if (create) {
+ buffer.append("Une entité à été crée d'identifiant ").append(topiaId);
+ } else {
- String propertyName = diff.getSourceProperty();
+ int length = propertyDiffs.length;
- if (tableMeta.getColumns(propertyName).isFK()) {
+ if (length == 1) {
+ buffer.append("Une propriété a été modifiée :");
+ } else {
+ buffer.append(length).append(" propriétés ont été modifiées :");
+ }
+ for (int i = 0; i < length; i++) {
+ PropertyDiff diff = propertyDiffs[i];
- // replace by the decorate value
- if (sourceValue != null) {
- sourceValue = getDecoratorService().decorate(
- getLocale(), sourceValue, null);
- }
- if (targetValue != null) {
- targetValue = getDecoratorService().decorate(
- getLocale(), targetValue, null);
- }
+ Object sourceValue = diff.getSourceValue();
+ Object targetValue = diff.getTargetValue();
- }
+ String propertyName = diff.getSourceProperty();
- if (create) {
- buffer.append(String.format("\n Propriété '%s', valeur : %s",
- propertyName,
- targetValue
- ));
- } else {
- buffer.append(String.format("\n Propriété '%s', ancienne valeur : %s, nouvelle valeur : %s",
- propertyName,
- sourceValue,
- targetValue
- ));
+ if (tableMeta.getColumns(propertyName).isFK()) {
+
+ // replace by the decorate value
+ if (sourceValue != null) {
+ sourceValue = getDecoratorService().decorate(
+ getLocale(), sourceValue, null);
}
+ if (targetValue != null) {
+ targetValue = getDecoratorService().decorate(
+ getLocale(), targetValue, null);
+ }
+ buffer.append(String.format("\n Propriété '%s', ancienne valeur : %s, nouvelle valeur : %s",
+ propertyName,
+ sourceValue,
+ targetValue
+ ));
}
- dao1.create(
- EntityModificationLog.PROPERTY_ENTITY_TYPE, entityType.getSimpleName(),
- EntityModificationLog.PROPERTY_ENTITY_ID, id,
- EntityModificationLog.PROPERTY_USER, user,
- EntityModificationLog.PROPERTY_MODIFICATION_DATE, new Date(),
- EntityModificationLog.PROPERTY_MODIFICATION_TEXT, buffer.toString()
- );
-
- if (commit) {
- getTransaction().commitTransaction();
- }
}
- return propertyDiffs;
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Could not update entity", eee);
- } finally {
- monitor.setBean(null);
}
+
+ TopiaDAO<EntityModificationLog> dao =
+ getDAO(EntityModificationLog.class);
+
+ dao.create(
+ EntityModificationLog.PROPERTY_ENTITY_TYPE, tableMeta.getEntityEnum().name(),
+ EntityModificationLog.PROPERTY_ENTITY_ID, topiaId,
+ EntityModificationLog.PROPERTY_USER, user,
+ EntityModificationLog.PROPERTY_MODIFICATION_DATE, newDate(),
+ EntityModificationLog.PROPERTY_MODIFICATION_TEXT, buffer.toString()
+ );
}
- protected Map<String, Object> loadRow(TableMeta tableMeta,
- TopiaEntity entity,
- boolean addDecorated) {
+ protected <E extends TopiaEntity> Map<String, Object> loadRow(
+ E entity,
+ DbEditorCsvModel<E> loadModel) {
+
Map<String, Object> row = Maps.newLinkedHashMap();
- EntityOperator<TopiaEntity> operator =
- (EntityOperator<TopiaEntity>) tableMeta.getOperator();
- row.put("id", entity.getTopiaId());
- for (ColumnMeta columnMeta : tableMeta) {
- String propertyName = columnMeta.getName();
- // get property value
- Object property = operator.get(propertyName, entity);
- if (columnMeta.isFK() && property != null) {
+ Collection<ExportableColumn<E, Object>> columns =
+ loadModel.getColumnsForExport();
- // this is a foreign key, just keep the topiaid
- String topiaId = ((TopiaEntity) property).getTopiaId();
+ for (ExportableColumn<E, Object> column : columns) {
+ String propertyName = column.getHeaderName();
+ Object value;
+ try {
+ value = column.getValue(entity);
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException(
+ "Could not obtain property [" + propertyName +
+ "] value ", eee);
+ }
+ String formatedValue = column.formatValue(value);
+ row.put(propertyName, formatedValue);
- if (addDecorated) {
- // decorate the entity
- String decorate = getDecoratorService().decorate(
- getLocale(), property, null);
+ }
+ return row;
+ }
- // keep the decorate value
- row.put(propertyName + "_lib", decorate);
- }
+ protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForImport(TableMeta tableMetas) {
- // use as the property his topiaid
- property = topiaId;
- }
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(CSV_CHAR_SEPARATOR,
+ tableMetas);
- // Format date
- if (columnMeta.isDate() && property != null) {
- Date date = (Date) property;
- property = getDateFormat().format(date);
+ ModelBuilder<E> modelBuilder = model.modelBuilder;
+
+ modelBuilder.newColumnForImportExport(
+ TopiaEntity.TOPIA_ID,
+ TopiaEntity.TOPIA_ID
+ );
+
+ for (ColumnMeta columnMeta : model.tableMeta) {
+ String propertyName = columnMeta.getName();
+ Class<?> type = columnMeta.getType();
+ if (columnMeta.isFK()) {
+
+ Class<TopiaEntity> entityType = (Class<TopiaEntity>) type;
+ Collection<TopiaEntity> universe = getForeignDatas(entityType);
+ model.addForeignKeyForImport(propertyName, entityType, universe);
+ } else {
+ model.addDefaultColumn(propertyName, type);
}
- row.put(propertyName, property);
}
- return row;
+ return model;
}
- public List<PropertyDiff[]> importDatas(String tableName,
- File importFile,
- EchoBaseUser user) {
- TableMeta tableMetas = getTableMetas(tableName);
- BufferedReader bf = null;
- List<PropertyDiff[]> result = Lists.newArrayList();
- try {
- bf = new BufferedReader(new FileReader(importFile));
- String csvHeader = bf.readLine();
- String[] properties = csvHeader.split(CSV_SEPARATOR);
+ protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForSave(TableMeta tableMetas) {
- String line = bf.readLine();
- while (line != null) {
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(CSV_CHAR_SEPARATOR,
+ tableMetas);
- Map<String, String> valuesMap = Maps.newLinkedHashMap();
+ ModelBuilder<E> modelBuilder = model.modelBuilder;
- String[] values = line.split(CSV_SEPARATOR);
+ modelBuilder.newColumnForExport(
+ TopiaEntity.TOPIA_ID,
+ TopiaEntity.TOPIA_ID
+ );
- String id = values[0];
- for (int i=1;i<values.length;i++) {
- valuesMap.put(properties[i], values[i]);
- }
+ for (ColumnMeta columnMeta : model.tableMeta) {
+ String propertyName = columnMeta.getName();
+ Class<?> type = columnMeta.getType();
+ if (columnMeta.isFK()) {
- // Save entity
- PropertyDiff[] propertyDiffs = saveEntity(tableMetas, id, valuesMap, user, false);
- result.add(propertyDiffs);
+ Class<TopiaEntity> entityType = (Class<TopiaEntity>) type;
- line = bf.readLine();
- }
+ Collection<TopiaEntity> universe = getForeignDatas(entityType);
- // Commit
- getTransaction().commitTransaction();
- } catch (Exception eee) {
- log.error("Failed to read import file " + importFile.getName(), eee);
- throw new EchoBaseTechnicalException(eee);
- } finally {
- if (bf != null) {
- try {
- bf.close();
- } catch (IOException eee) {
- log.error("Failed to close import file " + importFile.getName(), eee);
- throw new EchoBaseTechnicalException(eee);
- }
+ // translate foreign key to his id
+ model.addForeignKeyForImport(propertyName, entityType, universe);
+
+ } else {
+ model.addDefaultColumn(propertyName, type);
}
}
- return result;
+ return model;
}
- public File exportDatas(String tableName) {
+ protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForExport(TableMeta tableMetas) {
- Map<?, ?>[] datas = getAllDatas(tableName, false);
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(CSV_CHAR_SEPARATOR,
+ tableMetas);
- StringBuilder csvContent = new StringBuilder();
+ ModelBuilder<E> modelBuilder = model.modelBuilder;
- // Build csv
- boolean headerCompleted = false;
+ modelBuilder.newColumnForImportExport(
+ TopiaEntity.TOPIA_ID,
+ TopiaEntity.TOPIA_ID
+ );
- // To escape value if csv special char is found
- StringUtil.ToString csvConvertor = new StringUtil.ToCSV(CSV_SEPARATOR);
- for (Map<?, ?> data : datas) {
+ for (ColumnMeta columnMeta : model.tableMeta) {
+ String propertyName = columnMeta.getName();
+ Class<?> type = columnMeta.getType();
+ if (columnMeta.isFK()) {
- // Write header
- if (!headerCompleted) {
- String keys = StringUtil.join(data.keySet(), csvConvertor, CSV_SEPARATOR, false);
- csvContent.append(keys);
- csvContent.append("\n");
- headerCompleted = true;
+ Class<TopiaEntity> entityType = (Class<TopiaEntity>) type;
+ model.addForeignKeyForExport(propertyName, entityType);
+ } else {
+ model.addDefaultColumn(propertyName, type);
}
-
- // Write content
- String values = StringUtil.join(data.values(), csvConvertor, CSV_SEPARATOR, false);
- csvContent.append(values);
- csvContent.append("\n");
}
+ return model;
+ }
- // Write export file
- SimpleDateFormat format = new SimpleDateFormat(EXPORT_FILE_FORMAT_DATE);
- String now = format.format(new Date());
+ protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForLoad(TableMeta tableMetas,
+ boolean addDecorated) {
- // Write in tmp dir
- File tempDirectory = FileUtils.getTempDirectory();
- File file = new File(tempDirectory, EXPORT_FILE_PREFIX + now + SCV_EXT);
- file.deleteOnExit();
+ DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(CSV_CHAR_SEPARATOR,
+ tableMetas);
- FileWriter writer = null;
- try {
- writer = new FileWriter(file, true);
- writer.write(csvContent.toString());
- } catch (IOException eee) {
- log.error("Failed to write modif export file", eee);
- throw new EchoBaseTechnicalException(eee);
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException eee) {
- log.error("Failed to close modif export file", eee);
- throw new EchoBaseTechnicalException(eee);
+ ModelBuilder<E> modelBuilder = model.modelBuilder;
+
+ modelBuilder.newColumnForImportExport(
+ "id",
+ TopiaEntity.TOPIA_ID
+ );
+
+ for (ColumnMeta columnMeta : model.tableMeta) {
+ String propertyName = columnMeta.getName();
+ Class<?> type = columnMeta.getType();
+ if (columnMeta.isFK()) {
+
+ Class<TopiaEntity> entityType = (Class<TopiaEntity>) type;
+
+ // translate foreign key to his id
+ model.addForeignKeyForExport(propertyName, entityType);
+
+ if (addDecorated) {
+
+ // translate foreign key to his decorated value
+ modelBuilder.newColumnForExport(
+ propertyName + "_lib",
+ propertyName,
+ CsvModelUtil.newForeignKeyDecoratedValue(
+ entityType,
+ getDecoratorService(),
+ getLocale())
+ );
}
+
+ } else {
+ model.addDefaultColumn(propertyName, type);
}
}
- return file;
+ return model;
}
+
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-11-23 17:50:27 UTC (rev 109)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-11-23 17:51:57 UTC (rev 110)
@@ -40,7 +40,6 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -90,7 +89,7 @@
entityToSave.setName(exportQuery.getName());
entityToSave.setDescription(exportQuery.getDescription());
entityToSave.setSqlQuery(exportQuery.getSqlQuery());
- entityToSave.setLastModifiedDate(new Date());
+ entityToSave.setLastModifiedDate(newDate());
entityToSave.setLastModifiedUser(user);
dao.update(entityToSave);
@@ -156,8 +155,7 @@
}
StringBuilder buffer = new StringBuilder();
int rowCount = rows.length;
- buffer.append("#Created at ").append(new Date()).append(" by user ").append(echoBaseUser.getEmail());
- buffer.append("\n#").append(StringUtils.join(columnNames, ";"));
+ buffer.append(StringUtils.join(columnNames, ";"));
for (int i = 0; i < rowCount; i++) {
Map<String, Object> row = rows[i];
buffer.append('\n').append(StringUtils.join(row.values(), ";"));
1
0