Wao-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
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
June 2010
- 3 participants
- 97 discussions
[Suiviobsmer-commits] r554 - in trunk/wao-ui/src/main: java/fr/ifremer/wao/ui/components java/fr/ifremer/wao/ui/pages resources/fr/ifremer/wao/ui/components webapp
by fdesbois@users.labs.libre-entreprise.org 21 Jun '10
by fdesbois@users.labs.libre-entreprise.org 21 Jun '10
21 Jun '10
Author: fdesbois
Date: 2010-06-21 09:23:28 +0000 (Mon, 21 Jun 2010)
New Revision: 554
Log:
Evo #2247 : Add access to administration page for coordinators. They can only manage "observer" and "coordinator" users for their own company.
Modified:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml
trunk/wao-ui/src/main/webapp/Administration.tml
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java 2010-06-18 16:15:34 UTC (rev 553)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java 2010-06-21 09:23:28 UTC (rev 554)
@@ -136,7 +136,7 @@
}
public String getAdminClass() {
- return getCurrentUser().isAdmin() ? " admin" : "";
+ return !isAdministrationHidden() ? " admin" : "";
}
public String getSamplingSelected() {
@@ -159,6 +159,10 @@
return this.contentId.equals("so-admin") ? "selected" : "";
}
+ public boolean isAdministrationHidden() {
+ return !getCurrentUser().isAdmin() && !getCurrentUser().isCoordinator();
+ }
+
public String getAccessText() {
String text = getCurrentUser().getRole().getLabel();
if (getCurrentUser().isReadOnly()) {
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-18 16:15:34 UTC (rev 553)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-21 09:23:28 UTC (rev 554)
@@ -50,11 +50,14 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.EventContext;
+import org.apache.tapestry5.OptionModel;
+import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
@@ -65,6 +68,8 @@
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.corelib.components.BeanEditForm;
import org.apache.tapestry5.corelib.components.Zone;
+import org.apache.tapestry5.internal.OptionModelImpl;
+import org.apache.tapestry5.internal.SelectModelImpl;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.services.PropertyAccess;
@@ -81,7 +86,7 @@
*
* @author fdesbois <fdesbois at codelutin.com>
*/
- at RequiresAuthentication(value = UserRole.ADMIN, readOnlyAllowed = false)
+ at RequiresAuthentication(value = {UserRole.ADMIN, UserRole.COORDINATOR}, readOnlyAllowed = false)
@IncludeStylesheet("context:css/administration.css")
public class Administration {
@@ -148,6 +153,8 @@
if (ec.getCount() > 1) {
userId = ec.get(String.class, 1);
}
+ } else if (currentUser.isCoordinator()) {
+ companyId = currentUser.getCompany().getId();
}
}
@@ -477,6 +484,8 @@
@InjectComponent
private Zone userRoleZone;
+ private SelectModel userRoleSelectModel;
+
@Persist
@Property
private UserRole userRole;
@@ -494,6 +503,25 @@
@Property
private boolean refreshUserRoleZone;
+ public SelectModel getUserRoleSelectModel() {
+ if (userRoleSelectModel == null) {
+ List<OptionModel> options = new ArrayList<OptionModel>();
+ options.add(newUserRoleOption(UserRole.OBSERVER));
+ options.add(newUserRoleOption(UserRole.COORDINATOR));
+ // Only admin can set ADMIN and GUEST role
+ if (currentUser.isAdmin()) {
+ options.add(newUserRoleOption(UserRole.ADMIN));
+ options.add(newUserRoleOption(UserRole.GUEST));
+ }
+ userRoleSelectModel = new SelectModelImpl(null, options);
+ }
+ return userRoleSelectModel;
+ }
+
+ private OptionModel newUserRoleOption(UserRole role) {
+ return new OptionModelImpl(role.getLabel(), role);
+ }
+
public String getRoleReadOnly() {
String text = "";
if (user.isReadOnly(role)) {
@@ -502,10 +530,6 @@
return text;
}
-// void onSelectedFromUser() {
-// refreshUserRoleZone = false;
-// }
-
@Log
void onChangeFromUserRole(String value) {
if (StringUtils.isNotEmpty(value)) {
Modified: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml
===================================================================
--- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml 2010-06-18 16:15:34 UTC (rev 553)
+++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml 2010-06-21 09:23:28 UTC (rev 554)
@@ -113,7 +113,7 @@
</li>
</p:else>
</t:unless>
- <t:if t:test="currentUser.admin">
+ <t:unless t:test="administrationHidden">
<li class="sep"> </li>
<t:if t:test="currentUser.readOnly">
<li class="disabled${adminClass}" title="Administration inaccessible">
@@ -125,7 +125,7 @@
</li>
</p:else>
</t:if>
- </t:if>
+ </t:unless>
</ul>
<div id="${contentId}">
Modified: trunk/wao-ui/src/main/webapp/Administration.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/Administration.tml 2010-06-18 16:15:34 UTC (rev 553)
+++ trunk/wao-ui/src/main/webapp/Administration.tml 2010-06-21 09:23:28 UTC (rev 554)
@@ -54,24 +54,38 @@
</t:unless>
</t:if>
- <form class="actions clearfix" t:type="form" t:id="actionsForm">
- <div class="fields fleft">
- <t:label t:for="companies" /> :
- <input t:type="select" t:id="companies" t:model="companiesSelectModel" t:value="companyId" />
- </div>
- <div class="icons fleft">
- <input t:type="submit" t:id="showUsers" class="ico search" value="Show Details" t:title="Afficher détails" />
- <input t:type="submit" t:id="addNewCompany" class="ico add" value="Add new company" t:title="Ajouter une nouvelle société" />
- </div>
- </form>
+ <t:if t:test="currentUser.admin">
+ <form class="actions clearfix" t:type="form" t:id="actionsForm">
+ <div class="fields fleft">
+ <t:label t:for="companies" /> :
+ <input t:type="select" t:id="companies" t:model="companiesSelectModel" t:value="companyId" />
+ </div>
+ <div class="icons fleft">
+ <input t:type="submit" t:id="showUsers" class="ico search" value="Show Details" t:title="Afficher détails" />
+ <input t:type="submit" t:id="addNewCompany" class="ico add" value="Add new company" t:title="Ajouter une nouvelle société" />
+ </div>
+ </form>
+ </t:if>
<fieldset class="user-form clearfix">
<form t:type="beaneditform" class="clearfix" t:id="company"
t:include="name, address1, address2, postalCode, city, phoneNumber, email, active">
<p:name>
- <t:label t:for="name" />
- <input t:type="textfield" t:id="name" t:validate="required" value="company.name" />
+ <t:if t:test="currentUser.admin">
+ <t:label t:for="name" />
+ <input t:type="textfield" t:id="name" t:validate="required" value="company.name" />
+ <p:else>
+ <label>Nom</label>
+ <strong>${company.name}</strong>
+ </p:else>
+ </t:if>
</p:name>
+ <p:active>
+ <t:if t:test="currentUser.admin">
+ <t:label t:for="active" />
+ <input t:type="checkbox" t:id="active" value="company.active" />
+ </t:if>
+ </p:active>
</form>
</fieldset>
@@ -117,13 +131,13 @@
<label t:type="label" for="generatePassword" />
<input t:type="checkbox" t:id="generatePassword" value="generatePassword" />
<span> ou définir manuellement : </span>
- <input t:type="passwordfield" t:id="password2" value="password" />
+ <input t:type="passwordfield" t:id="password2" class="width100" value="password" />
</p:password>
<p:userRole>
<t:zone id="so-admin-userRoleZone" t:id="userRoleZone" t:update="show">
<t:nuiton.subForm t:visible="refreshUserRoleZone">
<label t:type="label" for="userRole" />
- <select t:type="select" t:id="userRole" t:value="userRole"
+ <select t:type="select" t:id="userRole" t:value="userRole" t:model="userRoleSelectModel"
t:mixins="ck/onEvent" t:event="change"/>
<span>Lecture seule : </span>
1
0
[Suiviobsmer-commits] r553 - in trunk: wao-business/src/main/xmi wao-ui/src/main/java/fr/ifremer/wao/ui/components wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/resources/fr/ifremer/wao/ui/components wao-ui/src/main/webapp
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
18 Jun '10
Author: fdesbois
Date: 2010-06-18 16:15:34 +0000 (Fri, 18 Jun 2010)
New Revision: 553
Log:
Evo #2018 : Add LogFile component used for ActivityCalendar + move imports from boats page
Added:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/LogFile.java
trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/LogFile.tml
Modified:
trunk/wao-business/src/main/xmi/wao.zargo
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java
trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml
trunk/wao-ui/src/main/webapp/Administration.tml
trunk/wao-ui/src/main/webapp/Boats.tml
Modified: trunk/wao-business/src/main/xmi/wao.zargo
===================================================================
(Binary files differ)
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-18 14:46:07 UTC (rev 552)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-18 16:15:34 UTC (rev 553)
@@ -16,7 +16,10 @@
import org.apache.tapestry5.upload.services.UploadedFile;
import org.slf4j.Logger;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
+import java.util.zip.GZIPInputStream;
/**
* This component is used to import a {@code csvFile} using a form. The page
@@ -33,8 +36,12 @@
public class CsvImport {
/** Event triggered after form submission success */
- static final String EVENT_IMPORTED = "imported";
+ protected static final String EVENT_IMPORTED = "imported";
+ protected static final String MIMETYPE_GZIP = "application/x-gzip";
+
+ protected static final String MIMETYPE_CSV = "text/csv";
+
/** Label to display on fieldset and in submit button title */
@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
@Property
@@ -72,15 +79,18 @@
try {
// Execute import using the engine
- ImportResults result = engine.execute(csvFile.getStream());
+ ImportResults result = engine.execute(getStream());
- // Add info on nbRows imported and refused
- errorReport.addInfo(result.getNbRowsImported() + " lignes importées, " +
- result.getNbRowsRefused() + " refusées.");
+ if (result != null) {
+ // Add info on nbRows imported and refused
+ errorReport.addInfo(result.getNbRowsImported() + " lignes importées dont " +
+ result.getNbRowsImportedNew() + " nouvelles, " +
+ result.getNbRowsRefused() + " refusées.");
- // Add import errors
- List<String> errors = result.getErrors();
- errorReport.addError(errors.toArray(new String[errors.size()]));
+ // Add import errors
+ List<String> errors = result.getErrors();
+ errorReport.addError(errors.toArray(new String[errors.size()]));
+ }
} catch (WaoBusinessException eee) {
@@ -92,9 +102,33 @@
String[] errors =
manager.getErrorMessages(eee, messages, logger);
errorReport.addError(errors);
+
+ } catch (IOException eee) {
+ errorReport.addError("Erreur de format du fichier ! Seul les formats [csv, gz] sont autorisés.");
+ logger.error("Error on import csv file", eee);
}
// Trigger event "imported" with ErroReport in argument
resources.triggerEvent(EVENT_IMPORTED, new Object[] {errorReport}, null);
}
+
+ protected InputStream getStream() throws IOException {
+ InputStream input = csvFile.getStream();
+ String contentType = csvFile.getContentType();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Content type : " + csvFile.getContentType());
+ }
+
+ if (contentType.equals(MIMETYPE_GZIP)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Gzip file");
+ }
+ input = new GZIPInputStream(input);
+
+ } else if (!contentType.equals(MIMETYPE_CSV)) {
+ throw new IOException("unsupported format : " + contentType);
+ }
+ return input;
+ }
}
Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/LogFile.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/LogFile.java (rev 0)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/LogFile.java 2010-06-18 16:15:34 UTC (rev 553)
@@ -0,0 +1,52 @@
+package fr.ifremer.wao.ui.components;
+
+import org.apache.tapestry5.Asset;
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.StreamResponse;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.services.Response;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created: 18 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class LogFile {
+
+ @Parameter(required = true)
+ @Property
+ private InputStream source;
+
+ @Parameter(defaultPrefix = BindingConstants.LITERAL)
+ @Property
+ private String title;
+
+ @Parameter(defaultPrefix = BindingConstants.ASSET)
+ @Property
+ private Asset icon;
+
+ public StreamResponse onActionFromShowLogFile() {
+ return new StreamResponse() {
+
+ @Override
+ public String getContentType() {
+ return "text/plain;charset=utf-8";
+ }
+
+ @Override
+ public InputStream getStream() throws IOException {
+ return source;
+ }
+
+ @Override
+ public void prepareResponse(Response response) {
+ }
+ };
+ }
+}
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-18 14:46:07 UTC (rev 552)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-18 16:15:34 UTC (rev 553)
@@ -28,6 +28,7 @@
import fr.ifremer.wao.WaoBusinessException;
import fr.ifremer.wao.WaoBusinessException.Type;
import fr.ifremer.wao.WaoException;
+import fr.ifremer.wao.WaoProperty;
import fr.ifremer.wao.bean.ConnectedUser;
import fr.ifremer.wao.bean.ImportResults;
import fr.ifremer.wao.bean.ImportResultsImpl;
@@ -35,6 +36,7 @@
import fr.ifremer.wao.entity.Company;
import fr.ifremer.wao.entity.CompanyImpl;
import fr.ifremer.wao.entity.WaoUser;
+import fr.ifremer.wao.service.ServiceBoat;
import fr.ifremer.wao.service.ServiceReferential;
import fr.ifremer.wao.service.ServiceSampling;
import fr.ifremer.wao.service.ServiceUser;
@@ -45,10 +47,15 @@
import fr.ifremer.wao.ui.data.RequiresAuthentication;
import fr.ifremer.wao.ui.services.WaoManager;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.util.List;
+import java.util.zip.GZIPInputStream;
+
import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.EventContext;
+import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Log;
@@ -63,6 +70,7 @@
import org.apache.tapestry5.ioc.services.PropertyAccess;
import org.apache.tapestry5.ioc.services.TypeCoercer;
import org.apache.tapestry5.services.BeanModelSource;
+import org.apache.tapestry5.services.Response;
import org.apache.tapestry5.upload.services.UploadedFile;
import org.slf4j.Logger;
@@ -81,6 +89,7 @@
private Layout layout;
@SessionState
+ @Property
private ConnectedUser currentUser;
@Inject
@@ -151,10 +160,15 @@
@Inject
private ServiceSampling serviceSampling;
+ @Inject
+ private ServiceBoat serviceBoat;
+
public ImportEngine getFishingZoneImportEngine() {
return new ImportEngine() {
+
@Override
- public ImportResults execute(InputStream input) throws WaoException, WaoBusinessException {
+ public ImportResults execute(InputStream input)
+ throws WaoException, WaoBusinessException {
int nbImported = serviceReferential.importFishingZoneCsv(input);
ImportResults results = new ImportResultsImpl();
results.setNbRowsImported(nbImported);
@@ -165,8 +179,10 @@
public ImportEngine getSamplingPlanImportEngine() {
return new ImportEngine() {
+
@Override
- public ImportResults execute(InputStream input) throws WaoException, WaoBusinessException {
+ public ImportResults execute(InputStream input)
+ throws WaoException, WaoBusinessException {
ImportResults results = serviceSampling.importSamplingPlanCsv(input);
return results;
}
@@ -174,6 +190,65 @@
}
@Log
+ public ImportEngine getBoatImportEngine() {
+ return new ImportEngine() {
+
+ @Override
+ public ImportResults execute(InputStream input)
+ throws WaoException, WaoBusinessException {
+ int[] result = serviceBoat.importBoatCsv(input);
+ ImportResults results = new ImportResultsImpl();
+ results.setNbRowsImported(result[0]);
+ results.setNbRowsImportedNew(result[1]);
+ return results;
+ }
+ };
+ }
+
+ public ImportEngine getActivityCalendarImportEngine() {
+ return new ImportEngine() {
+
+ @Override
+ public ImportResults execute(InputStream input)
+ throws WaoException, WaoBusinessException {
+ // Will execute a thread to import activityCalendars
+ serviceBoat.importActivityCalendarCsv(input);
+ // Errors will be written in an activityCalendarLogFile
+ return null;
+ }
+ };
+ }
+
+ public InputStream getActivityCalendarLogFile() {
+ return getActivityCalendarLogFile(WaoProperty.FILENAME_LOG_ACTIVITY_IMPORT);
+ }
+
+ public InputStream getActivityCalendarAccessLogFile() {
+ return getActivityCalendarLogFile(WaoProperty.FILENAME_LOG_ACTIVITY_ACCESS);
+ }
+
+ private InputStream getActivityCalendarLogFile(WaoProperty property) {
+ InputStream result = null;
+ try {
+ switch (property) {
+ case FILENAME_LOG_ACTIVITY_ACCESS:
+ result = serviceBoat.getActivityCalendarLogAccessFile(); break;
+ case FILENAME_LOG_ACTIVITY_IMPORT:
+ result = serviceBoat.getActivityCalendarLogFile();
+ }
+ } catch (FileNotFoundException eee) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Not existing log file for " + property);
+ }
+ }
+ return result;
+ }
+
+ public boolean isActivityCalendarImportRun() {
+ return manager.isActivityCalendarImportRun();
+ }
+
+ @Log
void onImported(ErrorReport report) {
for (String info : report.getInfos()) {
layout.addInfo(info);
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-18 14:46:07 UTC (rev 552)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-18 16:15:34 UTC (rev 553)
@@ -186,142 +186,139 @@
/**************************** Import Forms ********************************/
- @Inject
- private Messages messages;
+// /** Csv file for boats import */
+// @Property
+// private UploadedFile boatsCsvFile;
+//
+// /** Csv file for activityCalendar import, can be a Gzip file */
+// @Property
+// private UploadedFile activityCalendarsCsvFile;
+//
+// private InputStream activityCalendarLogFile;
+//
+// private InputStream activityCalendarLogAccessFile;
+//
+// protected static final String GZIP_MIMETYPE = "application/x-gzip";
+//
+// public boolean canImportReferentials() {
+// return user.isAdmin() && !user.isReadOnly();
+// }
+//
+// @Log
+// void onSuccessFromImportBoatsForm() {
+// if (canImportReferentials()) {
+// try {
+// int[] result = serviceBoat.importBoatCsv(
+// boatsCsvFile.getStream());
+// // Suppress persitant list of boats
+// boats = null;
+// layout.addInfo(result[0] + " navires importés dont " +
+// result[1] + " nouveaux");
+// } catch (WaoBusinessException eee) {
+// layout.addError(eee.getMessage());
+// }
+// }
+// }
+//
+// InputStream getActivityCalendarLogFile() throws FileNotFoundException {
+// if (activityCalendarLogFile == null) {
+// activityCalendarLogFile = serviceBoat.getActivityCalendarLogFile();
+// }
+// return activityCalendarLogFile;
+// }
+//
+// public boolean isLogFileExists() {
+// try {
+// getActivityCalendarLogFile();
+// return true;
+// } catch (FileNotFoundException eee) {
+// if (log.isInfoEnabled()) {
+// log.info("Aucun fichier de log existant pour les calendriers d'activité");
+// }
+// return false;
+// }
+// }
+//
+// InputStream getActivityCalendarLogAccessFile() throws FileNotFoundException {
+// if (activityCalendarLogAccessFile == null) {
+// activityCalendarLogAccessFile =
+// serviceBoat.getActivityCalendarLogAccessFile();
+// }
+// return activityCalendarLogAccessFile;
+// }
+//
+// public boolean isLogAccessFileExists() {
+// try {
+// getActivityCalendarLogAccessFile();
+// return true;
+// } catch (FileNotFoundException eee) {
+// if (log.isInfoEnabled()) {
+// log.info("Aucun fichier de log existant pour les accès " +
+// "utilisateurs aux calendriers d'activité");
+// }
+// return false;
+// }
+// }
+//
+// @Log
+// void onSuccessFromImportActivityCalendarsForm()
+// throws WaoException, IOException {
+// if (canImportReferentials()) {
+// InputStream input = activityCalendarsCsvFile.getStream();
+// if (log.isDebugEnabled()) {
+// log.debug("Content type : " +
+// activityCalendarsCsvFile.getContentType());
+// }
+// if (activityCalendarsCsvFile.getContentType().
+// equals(GZIP_MIMETYPE)) {
+// if (log.isDebugEnabled()) {
+// log.debug("Gzip file");
+// }
+// input = new GZIPInputStream(input);
+// }
+// serviceBoat.importActivityCalendarCsv(input);
+// companyBoatInfos = null;
+// }
+// }
+//
+// public StreamResponse onActionFromShowActivityCalendarLogFile() {
+// return new StreamResponse() {
+//
+// @Override
+// public String getContentType() {
+// return "text/plain;charset=utf-8";
+// }
+//
+// @Override
+// public InputStream getStream() throws IOException {
+// return getActivityCalendarLogFile();
+// }
+//
+// @Override
+// public void prepareResponse(Response response) {
+// }
+// };
+// }
+//
+// public StreamResponse onActionFromShowActivityCalendarLogAccessFile() {
+// return new StreamResponse() {
+//
+// @Override
+// public String getContentType() {
+// return "text/plain;charset=utf-8";
+// }
+//
+// @Override
+// public InputStream getStream() throws IOException {
+// return getActivityCalendarLogAccessFile();
+// }
+//
+// @Override
+// public void prepareResponse(Response response) {
+// }
+// };
+// }
- /** Csv file for boats import */
- @Property
- private UploadedFile boatsCsvFile;
-
- /** Csv file for activityCalendar import, can be a Gzip file */
- @Property
- private UploadedFile activityCalendarsCsvFile;
-
- private InputStream activityCalendarLogFile;
-
- private InputStream activityCalendarLogAccessFile;
-
- protected static final String GZIP_MIMETYPE = "application/x-gzip";
-
- public boolean canImportReferentials() {
- return user.isAdmin() && !user.isReadOnly();
- }
-
- @Log
- void onSuccessFromImportBoatsForm() {
- if (canImportReferentials()) {
- try {
- int[] result = serviceBoat.importBoatCsv(
- boatsCsvFile.getStream());
- // Suppress persitant list of boats
- boats = null;
- layout.addInfo(result[0] + " navires importés dont " +
- result[1] + " nouveaux");
- } catch (WaoBusinessException eee) {
- layout.addError(eee.getMessage());
- }
- }
- }
-
- InputStream getActivityCalendarLogFile() throws FileNotFoundException {
- if (activityCalendarLogFile == null) {
- activityCalendarLogFile = serviceBoat.getActivityCalendarLogFile();
- }
- return activityCalendarLogFile;
- }
-
- public boolean isLogFileExists() {
- try {
- getActivityCalendarLogFile();
- return true;
- } catch (FileNotFoundException eee) {
- if (log.isInfoEnabled()) {
- log.info("Aucun fichier de log existant pour les calendriers d'activité");
- }
- return false;
- }
- }
-
- InputStream getActivityCalendarLogAccessFile() throws FileNotFoundException {
- if (activityCalendarLogAccessFile == null) {
- activityCalendarLogAccessFile =
- serviceBoat.getActivityCalendarLogAccessFile();
- }
- return activityCalendarLogAccessFile;
- }
-
- public boolean isLogAccessFileExists() {
- try {
- getActivityCalendarLogAccessFile();
- return true;
- } catch (FileNotFoundException eee) {
- if (log.isInfoEnabled()) {
- log.info("Aucun fichier de log existant pour les accès " +
- "utilisateurs aux calendriers d'activité");
- }
- return false;
- }
- }
-
- @Log
- void onSuccessFromImportActivityCalendarsForm()
- throws WaoException, IOException {
- if (canImportReferentials()) {
- InputStream input = activityCalendarsCsvFile.getStream();
- if (log.isDebugEnabled()) {
- log.debug("Content type : " +
- activityCalendarsCsvFile.getContentType());
- }
- if (activityCalendarsCsvFile.getContentType().
- equals(GZIP_MIMETYPE)) {
- if (log.isDebugEnabled()) {
- log.debug("Gzip file");
- }
- input = new GZIPInputStream(input);
- }
- serviceBoat.importActivityCalendarCsv(input);
- companyBoatInfos = null;
- }
- }
-
- public StreamResponse onActionFromShowActivityCalendarLogFile() {
- return new StreamResponse() {
-
- @Override
- public String getContentType() {
- return "text/plain;charset=utf-8";
- }
-
- @Override
- public InputStream getStream() throws IOException {
- return getActivityCalendarLogFile();
- }
-
- @Override
- public void prepareResponse(Response response) {
- }
- };
- }
-
- public StreamResponse onActionFromShowActivityCalendarLogAccessFile() {
- return new StreamResponse() {
-
- @Override
- public String getContentType() {
- return "text/plain;charset=utf-8";
- }
-
- @Override
- public InputStream getStream() throws IOException {
- return getActivityCalendarLogAccessFile();
- }
-
- @Override
- public void prepareResponse(Response response) {
- }
- };
- }
-
/**************************** Filters Form *****************************************/
/** Filters to apply on boats list */
Modified: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml
===================================================================
--- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml 2010-06-18 14:46:07 UTC (rev 552)
+++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml 2010-06-18 16:15:34 UTC (rev 553)
@@ -9,6 +9,7 @@
<label for="csvFile">Fichier CSV ${label}</label> :
<input t:type="upload" t:id="csvFile" t:validate="required" />
<input t:type="submit" class="ico import" value="OK" title="Import ${label} (format CSV avec encodage UTF-8)" />
+ <t:body />
</fieldset>
</form>
</div>
Added: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/LogFile.tml
===================================================================
--- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/LogFile.tml (rev 0)
+++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/LogFile.tml 2010-06-18 16:15:34 UTC (rev 553)
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
+
+ <t:if t:test="source">
+ <div class="fright">
+ <a t:type="actionlink" t:id="showLogFile" target="blank">
+ <img src="${icon}" alt="Fichier de log" title="Afficher le fichier de log ${title}" />
+ </a>
+ </div>
+ </t:if>
+
+</html>
Modified: trunk/wao-ui/src/main/webapp/Administration.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/Administration.tml 2010-06-18 14:46:07 UTC (rev 552)
+++ trunk/wao-ui/src/main/webapp/Administration.tml 2010-06-18 16:15:34 UTC (rev 553)
@@ -31,10 +31,29 @@
<t:layout t:pageTitle="Administration" t:contentId="so-admin"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
- <t:csvImport t:label="des zones de pêche" t:engine="fishingZoneImportEngine" />
+ <t:if t:test="currentUser.admin">
+ <t:csvImport t:label="des zones de pêche" t:engine="fishingZoneImportEngine" />
- <t:csvImport t:label="du plan d'échantillonnage" t:engine="samplingPlanImportEngine" />
+ <t:csvImport t:label="du plan d'échantillonnage" t:engine="samplingPlanImportEngine" />
+ <t:csvImport t:label="des navires" t:engine="boatImportEngine" />
+
+ <t:unless t:test="activityCalendarImportRun">
+ <div class="clearfix">
+ <t:csvImport t:label="des calendriers d'activité" t:engine="activityCalendarImportEngine">
+ <t:logFile t:source="activityCalendarAccessLogFile" t:title="des accès utilisateurs aux calendriers d'activité" t:icon="context:img/text-access-32px.png" />
+ <t:logFile t:source="activityCalendarLogFile" t:title="de l'import des calendriers d'activité" t:icon="context:img/text-32px.png" />
+ </t:csvImport>
+ </div>
+ <p:else>
+ <div class="fb-info">
+ Import des calendriers d'activité en cours. <br />
+ Vous pouvez continuer à naviguer sur le site en attendant la fin du chargement.
+ </div>
+ </p:else>
+ </t:unless>
+ </t:if>
+
<form class="actions clearfix" t:type="form" t:id="actionsForm">
<div class="fields fleft">
<t:label t:for="companies" /> :
Modified: trunk/wao-ui/src/main/webapp/Boats.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/Boats.tml 2010-06-18 14:46:07 UTC (rev 552)
+++ trunk/wao-ui/src/main/webapp/Boats.tml 2010-06-18 16:15:34 UTC (rev 553)
@@ -31,57 +31,57 @@
<t:layout t:pageTitle="Navires" t:contentId="so-boats"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
- <t:if t:test="canImportReferentials()">
- <div class="so-import">
- <fieldset>
- <legend>Import des navires</legend>
- <!--t:zone t:id="importZone"-->
- <form t:type="form" t:id="importBoatsForm">
- <t:errors />
- <t:label for="boatsCsvFile" /> :
- <input t:type="upload" t:id="boatsCsvFile" t:validate="required" />
- <input t:type="submit" class="ico import" value="OK" title="Importer une liste de navires (format CSV avec encodage UTF-8)" />
- </form>
- <!--/t:zone-->
- </fieldset>
- </div>
- <t:unless t:test="activityCalendarImportRun">
- <div class="so-import clearfix">
- <fieldset>
- <legend>Import des calendriers d'activité</legend>
- <form t:type="form" t:id="importActivityCalendarsForm">
- <t:errors />
- <t:label for="activityCalendarsCsvFile" /> :
- <input t:type="upload" t:id="activityCalendarsCsvFile" t:validate="required" />
- <input t:type="submit" class="ico import" value="OK"
- title="Importer les calendriers d'activité des navires (format CSV avec encodage UTF-8)" />
- </form>
- <t:if t:test="logAccessFileExists">
- <div class="fright">
- <a t:type="actionlink" t:id="showActivityCalendarLogAccessFile" target="blank">
- <img src="${asset:context:}/img/text-access-32px.png"
- title="Afficher le fichier de log des accès utilisateurs aux calendriers d'activité"/>
- </a>
- </div>
- </t:if>
- <t:if t:test="logFileExists">
- <div class="fright">
- <a t:type="actionlink" t:id="showActivityCalendarLogFile">
- <img src="${asset:context:}/img/text-32px.png"
- title="Afficher le fichier de log de l'import des calendriers d'activité"/>
- </a>
- </div>
- </t:if>
- </fieldset>
- </div>
- <p:else>
- <div class="fb-info">
- Import des calendriers d'activité en cours. <br />
- Vous pouvez continuer à naviguer sur le site en attendant la fin du chargement.
- </div>
- </p:else>
- </t:unless>
- </t:if>
+ <!--<t:if t:test="canImportReferentials()">-->
+ <!--<div class="so-import">-->
+ <!--<fieldset>-->
+ <!--<legend>Import des navires</legend>-->
+ <!--<!–t:zone t:id="importZone"–>-->
+ <!--<form t:type="form" t:id="importBoatsForm">-->
+ <!--<t:errors />-->
+ <!--<t:label for="boatsCsvFile" /> :-->
+ <!--<input t:type="upload" t:id="boatsCsvFile" t:validate="required" />-->
+ <!--<input t:type="submit" class="ico import" value="OK" title="Importer une liste de navires (format CSV avec encodage UTF-8)" />-->
+ <!--</form>-->
+ <!--<!–/t:zone–>-->
+ <!--</fieldset>-->
+ <!--</div>-->
+ <!--<t:unless t:test="activityCalendarImportRun">-->
+ <!--<div class="so-import clearfix">-->
+ <!--<fieldset>-->
+ <!--<legend>Import des calendriers d'activité</legend>-->
+ <!--<form t:type="form" t:id="importActivityCalendarsForm">-->
+ <!--<t:errors />-->
+ <!--<t:label for="activityCalendarsCsvFile" /> :-->
+ <!--<input t:type="upload" t:id="activityCalendarsCsvFile" t:validate="required" />-->
+ <!--<input t:type="submit" class="ico import" value="OK"-->
+ <!--title="Importer les calendriers d'activité des navires (format CSV avec encodage UTF-8)" />-->
+ <!--</form>-->
+ <!--<t:if t:test="logAccessFileExists">-->
+ <!--<div class="fright">-->
+ <!--<a t:type="actionlink" t:id="showActivityCalendarLogAccessFile" target="blank">-->
+ <!--<img src="${asset:context:}/img/text-access-32px.png"-->
+ <!--title="Afficher le fichier de log des accès utilisateurs aux calendriers d'activité"/>-->
+ <!--</a>-->
+ <!--</div>-->
+ <!--</t:if>-->
+ <!--<t:if t:test="logFileExists">-->
+ <!--<div class="fright">-->
+ <!--<a t:type="actionlink" t:id="showActivityCalendarLogFile">-->
+ <!--<img src="${asset:context:}/img/text-32px.png"-->
+ <!--title="Afficher le fichier de log de l'import des calendriers d'activité"/>-->
+ <!--</a>-->
+ <!--</div>-->
+ <!--</t:if>-->
+ <!--</fieldset>-->
+ <!--</div>-->
+ <!--<p:else>-->
+ <!--<div class="fb-info">-->
+ <!--Import des calendriers d'activité en cours. <br />-->
+ <!--Vous pouvez continuer à naviguer sur le site en attendant la fin du chargement.-->
+ <!--</div>-->
+ <!--</p:else>-->
+ <!--</t:unless> -->
+ <!--</t:if>-->
<!-- Filtres -->
<!--t:filters t:title="Filtres de recherche" t:mainId="so-boats-filters"-->
1
0
[Suiviobsmer-commits] r552 - in trunk/wao-ui/src/main/java/fr/ifremer/wao/ui: components data
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
18 Jun '10
Author: fdesbois
Date: 2010-06-18 14:46:07 +0000 (Fri, 18 Jun 2010)
New Revision: 552
Log:
Evo #2018 : Add javadoc for CsvImport component and ImportEngine
Modified:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-18 14:35:41 UTC (rev 551)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-18 14:46:07 UTC (rev 552)
@@ -19,6 +19,12 @@
import java.util.List;
/**
+ * This component is used to import a {@code csvFile} using a form. The page
+ * using this component must provide a {@link ImportEngine} to execute the
+ * import when csv file is uploaded. An event "imported" will be triggered
+ * after success. The page can use an "onImported(ErrorReport report)" method
+ * to display errors and informations from import.
+ *
* Created: 18 juin 2010
*
* @author fdesbois <fdesbois at codelutin.com>
@@ -26,12 +32,15 @@
*/
public class CsvImport {
+ /** Event triggered after form submission success */
static final String EVENT_IMPORTED = "imported";
+ /** Label to display on fieldset and in submit button title */
@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
@Property
private String label;
+ /** engine to execute the import */
@Parameter(required = true)
private ImportEngine engine;
@@ -50,24 +59,42 @@
@Property
private UploadedFile csvFile;
+ /**
+ * ON_SUCCESS :: Callback method called when success event was triggered from
+ * importCsv form submission. The import will be executed using the engine
+ * in parameter. Errors will be reported in a {@link ErrorReport} object
+ * to be managed after import success. An event "imported" will be triggered"
+ * to manage those errors.
+ */
@Log
void onSuccessFromImportCsv() {
final ErrorReport errorReport = new ErrorReport();
try {
+ // Execute import using the engine
ImportResults result = engine.execute(csvFile.getStream());
+
+ // Add info on nbRows imported and refused
errorReport.addInfo(result.getNbRowsImported() + " lignes importées, " +
result.getNbRowsRefused() + " refusées.");
+
+ // Add import errors
List<String> errors = result.getErrors();
errorReport.addError(errors.toArray(new String[errors.size()]));
+
} catch (WaoBusinessException eee) {
+
+ // Add fatal errors
errorReport.addError(eee.getMessage());
} catch (WaoException eee) {
+
+ // Add unpredictable errors
String[] errors =
manager.getErrorMessages(eee, messages, logger);
errorReport.addError(errors);
}
+ // Trigger event "imported" with ErroReport in argument
resources.triggerEvent(EVENT_IMPORTED, new Object[] {errorReport}, null);
}
}
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java 2010-06-18 14:35:41 UTC (rev 551)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java 2010-06-18 14:46:07 UTC (rev 552)
@@ -3,6 +3,7 @@
import fr.ifremer.wao.WaoBusinessException;
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.ui.components.CsvImport;
import fr.ifremer.wao.ui.components.Layout;
import java.io.InputStream;
@@ -10,6 +11,10 @@
import java.util.List;
/**
+ * This interface is used for {@link CsvImport} component to execute an import.
+ * The page need to implement the {@link #execute(InputStream)} method to use
+ * the component.
+ *
* Created: 18 juin 2010
*
* @author fdesbois <fdesbois at codelutin.com>
@@ -17,5 +22,16 @@
*/
public interface ImportEngine {
+ /**
+ * Excute an import from an {@code input} stream. This method was called
+ * in {@link CsvImport} when file are successfully uploaded. This method
+ * to to return an {@link ImportResults} that contains stats and errors
+ * from import.
+ *
+ * @param input InputStream of the file to import
+ * @return an ImportResults that contains statistics and errors from import
+ * @throws WaoException for unknown errors
+ * @throws WaoBusinessException for known errors
+ */
ImportResults execute(InputStream input) throws WaoException, WaoBusinessException;
}
1
0
[Suiviobsmer-commits] r551 - in trunk/wao-ui/src/main: java/fr/ifremer/wao/ui/components java/fr/ifremer/wao/ui/data java/fr/ifremer/wao/ui/pages resources/fr/ifremer/wao/ui/components webapp
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
18 Jun '10
Author: fdesbois
Date: 2010-06-18 14:35:41 +0000 (Fri, 18 Jun 2010)
New Revision: 551
Log:
Evo #2018 : refactor imports, all admin imports need to be on administration page. Use ImportEngine interface + CsvImport component.
Added:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ErrorReport.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java
trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml
Modified:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java
trunk/wao-ui/src/main/webapp/Administration.tml
trunk/wao-ui/src/main/webapp/SamplingPlan.tml
Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java (rev 0)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-18 14:35:41 UTC (rev 551)
@@ -0,0 +1,73 @@
+package fr.ifremer.wao.ui.components;
+
+import fr.ifremer.wao.WaoBusinessException;
+import fr.ifremer.wao.WaoException;
+import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.ui.data.ErrorReport;
+import fr.ifremer.wao.ui.data.ImportEngine;
+import fr.ifremer.wao.ui.services.WaoManager;
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.annotations.Log;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.upload.services.UploadedFile;
+import org.slf4j.Logger;
+
+import java.util.List;
+
+/**
+ * Created: 18 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class CsvImport {
+
+ static final String EVENT_IMPORTED = "imported";
+
+ @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
+ @Property
+ private String label;
+
+ @Parameter(required = true)
+ private ImportEngine engine;
+
+ @Inject
+ private WaoManager manager;
+
+ @Inject
+ private ComponentResources resources;
+
+ @Inject
+ private Messages messages;
+
+ @Inject
+ private Logger logger;
+
+ @Property
+ private UploadedFile csvFile;
+
+ @Log
+ void onSuccessFromImportCsv() {
+ final ErrorReport errorReport = new ErrorReport();
+
+ try {
+ ImportResults result = engine.execute(csvFile.getStream());
+ errorReport.addInfo(result.getNbRowsImported() + " lignes importées, " +
+ result.getNbRowsRefused() + " refusées.");
+ List<String> errors = result.getErrors();
+ errorReport.addError(errors.toArray(new String[errors.size()]));
+ } catch (WaoBusinessException eee) {
+ errorReport.addError(eee.getMessage());
+ } catch (WaoException eee) {
+ String[] errors =
+ manager.getErrorMessages(eee, messages, logger);
+ errorReport.addError(errors);
+ }
+
+ resources.triggerEvent(EVENT_IMPORTED, new Object[] {errorReport}, null);
+ }
+}
Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ErrorReport.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ErrorReport.java (rev 0)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ErrorReport.java 2010-06-18 14:35:41 UTC (rev 551)
@@ -0,0 +1,41 @@
+package fr.ifremer.wao.ui.data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created: 18 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class ErrorReport {
+
+ protected List<String> infos;
+
+ protected List<String> errors;
+
+ public void addInfo(String info) {
+ getInfos().add(info);
+ }
+
+ public void addError(String... errors) {
+ for (String error : errors) {
+ getErrors().add(error);
+ }
+ }
+
+ public List<String> getInfos() {
+ if (infos == null) {
+ infos = new ArrayList<String>();
+ }
+ return infos;
+ }
+
+ public List<String> getErrors() {
+ if (errors == null) {
+ errors = new ArrayList<String>();
+ }
+ return errors;
+ }
+}
Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java (rev 0)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java 2010-06-18 14:35:41 UTC (rev 551)
@@ -0,0 +1,21 @@
+package fr.ifremer.wao.ui.data;
+
+import fr.ifremer.wao.WaoBusinessException;
+import fr.ifremer.wao.WaoException;
+import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.ui.components.Layout;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created: 18 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public interface ImportEngine {
+
+ ImportResults execute(InputStream input) throws WaoException, WaoBusinessException;
+}
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-18 13:39:46 UTC (rev 550)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-18 14:35:41 UTC (rev 551)
@@ -28,21 +28,27 @@
import fr.ifremer.wao.WaoBusinessException;
import fr.ifremer.wao.WaoBusinessException.Type;
import fr.ifremer.wao.WaoException;
+import fr.ifremer.wao.bean.ConnectedUser;
+import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.bean.ImportResultsImpl;
import fr.ifremer.wao.bean.UserRole;
import fr.ifremer.wao.entity.Company;
import fr.ifremer.wao.entity.CompanyImpl;
import fr.ifremer.wao.entity.WaoUser;
import fr.ifremer.wao.service.ServiceReferential;
+import fr.ifremer.wao.service.ServiceSampling;
import fr.ifremer.wao.service.ServiceUser;
+import fr.ifremer.wao.ui.data.ErrorReport;
import fr.ifremer.wao.ui.data.GenericSelectModel;
import fr.ifremer.wao.ui.components.Layout;
+import fr.ifremer.wao.ui.data.ImportEngine;
import fr.ifremer.wao.ui.data.RequiresAuthentication;
import fr.ifremer.wao.ui.services.WaoManager;
+
+import java.io.InputStream;
import java.util.List;
import org.apache.commons.lang.StringUtils;
-import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.EventContext;
-import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Log;
@@ -51,7 +57,6 @@
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.corelib.components.BeanEditForm;
-import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
@@ -72,16 +77,19 @@
@IncludeStylesheet("context:css/administration.css")
public class Administration {
- @Inject
- private Logger logger;
-
@InjectComponent
private Layout layout;
@SessionState
- private WaoUser currentUser;
+ private ConnectedUser currentUser;
@Inject
+ private Logger logger;
+
+ @Inject
+ private WaoManager manager;
+
+ @Inject
private ServiceUser serviceUser;
@Inject
@@ -90,6 +98,9 @@
@Inject
private TypeCoercer typeCoercer;
+ @Inject
+ private Messages messages;
+
@Property
private String companyId;
@@ -135,31 +146,41 @@
return new String[] {companyId, userId};
}
- /**************************** IMPORT (ADMIN) *******************************/
+ /**************************** IMPORTS (ADMIN) *******************************/
- /**
- * CSV File which contains fishing zones
- */
- @Property
- private UploadedFile fishingZoneCsvFile;
-
@Inject
- private Messages messages;
+ private ServiceSampling serviceSampling;
- @Inject
- private WaoManager manager;
+ public ImportEngine getFishingZoneImportEngine() {
+ return new ImportEngine() {
+ @Override
+ public ImportResults execute(InputStream input) throws WaoException, WaoBusinessException {
+ int nbImported = serviceReferential.importFishingZoneCsv(input);
+ ImportResults results = new ImportResultsImpl();
+ results.setNbRowsImported(nbImported);
+ return results;
+ }
+ };
+ }
+ public ImportEngine getSamplingPlanImportEngine() {
+ return new ImportEngine() {
+ @Override
+ public ImportResults execute(InputStream input) throws WaoException, WaoBusinessException {
+ ImportResults results = serviceSampling.importSamplingPlanCsv(input);
+ return results;
+ }
+ };
+ }
+
@Log
- void onSuccessFromImportFishingZones() {
- try {
- int result = serviceReferential.importFishingZoneCsv(
- fishingZoneCsvFile.getStream());
- layout.addInfo(result + " zones de pêche importées");
- } catch (WaoException eee) {
- String[] errors =
- manager.getErrorMessages(eee, messages, logger);
- layout.addError(errors);
+ void onImported(ErrorReport report) {
+ for (String info : report.getInfos()) {
+ layout.addInfo(info);
}
+ for (String error : report.getErrors()) {
+ layout.addError(error);
+ }
}
/**************************** FORMS ****************************************/
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-06-18 13:39:46 UTC (rev 550)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-06-18 14:35:41 UTC (rev 551)
@@ -118,33 +118,33 @@
/**************************** IMPORT (ADMIN) *******************************/
- /**
- * Fichier CSV contenant un plan d'échantillonnage
- */
- @Property
- private UploadedFile samplingPlanCsvFile;
-
- public boolean canImportSamplingPlan() {
- return user.isAdmin() && !user.isReadOnly();
- }
-
- @Log
- void onSuccessFromImportSamplingPlan() throws WaoException {
- if (canImportSamplingPlan()) {
- try {
- ImportResults result = serviceSampling.importSamplingPlanCsv(
- samplingPlanCsvFile.getStream());
- layout.addInfo(result.getNbRowsImported() +
- " lignes du plan importés, " +
- result.getNbRowsRefused() + " refusés.");
- for (String error : result.getErrors()) {
- layout.addInfo(error);
- }
- } catch (WaoBusinessException eee) {
- layout.addError(eee.getMessage());
- }
- }
- }
+// /**
+// * Fichier CSV contenant un plan d'échantillonnage
+// */
+// @Property
+// private UploadedFile samplingPlanCsvFile;
+//
+// public boolean canImportSamplingPlan() {
+// return user.isAdmin() && !user.isReadOnly();
+// }
+//
+// @Log
+// void onSuccessFromImportSamplingPlan() throws WaoException {
+// if (canImportSamplingPlan()) {
+// try {
+// ImportResults result = serviceSampling.importSamplingPlanCsv(
+// samplingPlanCsvFile.getStream());
+// layout.addInfo(result.getNbRowsImported() +
+// " lignes du plan importés, " +
+// result.getNbRowsRefused() + " refusés.");
+// for (String error : result.getErrors()) {
+// layout.addInfo(error);
+// }
+// } catch (WaoBusinessException eee) {
+// layout.addError(eee.getMessage());
+// }
+// }
+// }
/**************************** EXPORT **************************************/
Added: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml
===================================================================
--- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml (rev 0)
+++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml 2010-06-18 14:35:41 UTC (rev 551)
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
+
+ <div class="so-import">
+ <form t:type="form" t:id="importCsv" action="post">
+ <fieldset>
+ <legend>Import ${label}</legend>
+ <t:errors />
+ <label for="csvFile">Fichier CSV ${label}</label> :
+ <input t:type="upload" t:id="csvFile" t:validate="required" />
+ <input t:type="submit" class="ico import" value="OK" title="Import ${label} (format CSV avec encodage UTF-8)" />
+ </fieldset>
+ </form>
+ </div>
+
+</html>
\ No newline at end of file
Modified: trunk/wao-ui/src/main/webapp/Administration.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/Administration.tml 2010-06-18 13:39:46 UTC (rev 550)
+++ trunk/wao-ui/src/main/webapp/Administration.tml 2010-06-18 14:35:41 UTC (rev 551)
@@ -31,18 +31,10 @@
<t:layout t:pageTitle="Administration" t:contentId="so-admin"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
- <div class="so-import">
- <fieldset>
- <legend>Import des zones de pêche</legend>
- <form t:type="form" t:id="importFishingZones">
- <t:errors />
- <t:label for="fishingZoneCsvFile" /> :
- <input t:type="upload" t:id="fishingZoneCsvFile" t:validate="required" />
- <input t:type="submit" class="ico import" value="OK" title="Importer des zones de pêche (format CSV avec encodage UTF-8)" />
- </form>
- </fieldset>
- </div>
+ <t:csvImport t:label="des zones de pêche" t:engine="fishingZoneImportEngine" />
+ <t:csvImport t:label="du plan d'échantillonnage" t:engine="samplingPlanImportEngine" />
+
<form class="actions clearfix" t:type="form" t:id="actionsForm">
<div class="fields fleft">
<t:label t:for="companies" /> :
Modified: trunk/wao-ui/src/main/webapp/SamplingPlan.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-06-18 13:39:46 UTC (rev 550)
+++ trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-06-18 14:35:41 UTC (rev 551)
@@ -31,19 +31,19 @@
<t:layout t:pageTitle="Plan d'Echantillonnage" t:contentId="so-sampling"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
<div class="${mainClass}">
- <t:if t:test="canImportSamplingPlan()">
- <div class="so-import">
- <form t:type="form" t:id="importSamplingPlan" action="post">
- <fieldset>
- <legend>Import d'un nouveau plan d'échantillonnage</legend>
- <t:errors />
- <t:label for="samplingPlanCsvFile" /> :
- <input t:type="upload" t:id="samplingPlanCsvFile" t:validate="required" />
- <input t:type="submit" class="ico import" value="OK" title="Importer un plan d'échantillonnage (format CSV avec encodage UTF-8)" />
- </fieldset>
- </form>
- </div>
- </t:if>
+ <!--<t:if t:test="canImportSamplingPlan()">-->
+ <!--<div class="so-import">-->
+ <!--<form t:type="form" t:id="importSamplingPlan" action="post">-->
+ <!--<fieldset>-->
+ <!--<legend>Import d'un nouveau plan d'échantillonnage</legend>-->
+ <!--<t:errors />-->
+ <!--<t:label for="samplingPlanCsvFile" /> :-->
+ <!--<input t:type="upload" t:id="samplingPlanCsvFile" t:validate="required" />-->
+ <!--<input t:type="submit" class="ico import" value="OK" title="Importer un plan d'échantillonnage (format CSV avec encodage UTF-8)" />-->
+ <!--</fieldset>-->
+ <!--</form>-->
+ <!--</div>-->
+ <!--</t:if>-->
<div class="clearfix mbottom10">
<div class="clearfix">
<h1 class="fleft">Plan d'échantillonnage</h1>
1
0
[Suiviobsmer-commits] r550 - in trunk/wao-ui/src/main: java/fr/ifremer/wao/ui/data java/fr/ifremer/wao/ui/pages java/fr/ifremer/wao/ui/services webapp
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
18 Jun '10
Author: fdesbois
Date: 2010-06-18 13:39:46 +0000 (Fri, 18 Jun 2010)
New Revision: 550
Log:
- Evo #2332 : Add display text for validation comments
- Remove BusinessUtils, use WaoManager instead
Removed:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/BusinessUtils.java
Modified:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java
trunk/wao-ui/src/main/webapp/Contacts.tml
Deleted: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/BusinessUtils.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/BusinessUtils.java 2010-06-18 13:11:09 UTC (rev 549)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/BusinessUtils.java 2010-06-18 13:39:46 UTC (rev 550)
@@ -1,161 +0,0 @@
-/*
- * #%L
- * Wao :: Web Interface
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 Ifremer
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.wao.ui.data;
-
-import fr.ifremer.wao.bean.ContactState;
-import fr.ifremer.wao.bean.SamplingFilter;
-import fr.ifremer.wao.entity.Boat;
-import fr.ifremer.wao.entity.Contact;
-import fr.ifremer.wao.entity.FishingZone;
-import fr.ifremer.wao.entity.Profession;
-import fr.ifremer.wao.entity.SampleRow;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import org.apache.commons.lang.BooleanUtils;
-import org.apache.commons.lang.StringUtils;
-
-/**
- * DataUtils
- *
- * Created: 3 déc. 2009
- *
- * @author fdesbois <fdesbois at codelutin.com>
- */
-public class BusinessUtils {
-
-
- public static String getTooltipSampleRow(SampleRow row) {
- StringBuilder result = new StringBuilder();
- DateFormat dateFormat = new SimpleDateFormat("MM/yyyy");
- Profession profession = row.getProfession();
- result.append("<strong>Métier : </strong>").
- append(profession.getCodeDCF5());
- if (!StringUtils.isEmpty(profession.getMeshSize())) {
- result.append(' ').append(profession.getMeshSize());
- }
- if (!StringUtils.isEmpty(profession.getSize())) {
- result.append(' ').append(profession.getSize());
- }
- if (!StringUtils.isEmpty(profession.getOther())) {
- result.append(' ').append(profession.getOther());
- }
- result.append(" - ").append(profession.getLibelle());
- if (!StringUtils.isEmpty(profession.getSpecies())) {
- result.append("<br /><strong>Espèces cibles : </strong>").
- append(profession.getSpecies());
- }
- result.append("<br /><strong>Programme : </strong>").
- append(row.getProgramName()).
- append("<br /><strong>Période : </strong> du ").
- append(dateFormat.format(row.getPeriodBegin())).append(" au ").
- append(dateFormat.format(row.getPeriodEnd()));
-
- for (FishingZone zone : row.getFishingZone()) {
- result.append("<br /><strong>Zone de pêche : </strong>").
- append(zone.getCode());
- }
-
- return result.toString();
- }
-
- public static String getTooltipBoat(Boat boat) {
- StringBuilder result = new StringBuilder("<strong>").
- append(boat.getImmatriculation()).append("</strong>").
- append("<br /><strong>Quartier : </strong>").
- append(boat.getDistrictCode()).
- append("<br /><strong>Longueur : </strong>").
- append(boat.getBoatLength()).append(" m").
- append("<br /><strong>Année de construction : </strong>").
- append(boat.getBuildYear());
- return result.toString();
- }
-
- public static String getDataSamplingTitle(SamplingFilter filter) {
- StringBuilder result = new StringBuilder("Données des marées");
- String separator = " : ";
- if (filter.getCompany() != null) {
- //result.append(!filtered ? " : " : ", ";
- result.append(separator).
- append("\nSociété ").append(filter.getCompany().getName());
- separator = ", ";
- }
- if (StringUtils.isNotEmpty(filter.getProgramName())) {
- result.append(separator).
- append("\nProgramme ").append(filter.getProgramName());
- separator = ", ";
- }
- if (filter.getSampleRow() != null) {
- Profession profession = filter.getSampleRow().getProfession();
- result.append(separator).
- append("\nMétier ").append(profession.getCode());
- if (StringUtils.isNotEmpty(profession.getLibelle())) {
- result.append(" - ").append(profession.getLibelle());
- }
- if (StringUtils.isNotEmpty(profession.getSpecies())) {
- result.append("\nEspèces (").
- append(profession.getSpecies()).append(")");
- }
- result.append("\nZones de pêche (");
- for (FishingZone zone : filter.getSampleRow().getFishingZone()) {
- result.append(zone.getDistrictCode()).append(' ');
- }
- result.append(")");
- separator = ", ";
- } else {
- if (filter.getFacadeName() != null) {
- result.append(separator).
- append("\nFaçade ").append(filter.getFacadeName());
- separator = ", ";
- }
- if (filter.getSectorName() != null) {
- result.append(separator).
- append("\nZone ").append(filter.getSectorName());
- }
- }
- return result.toString();
- }
-
- public static String getContactStyle(Contact contact, boolean admin) {
- String result = "";
- boolean accepted = BooleanUtils.isTrue(contact.getValidationProgram()) ||
- (!admin && BooleanUtils.isTrue(contact.getValidationCompany()));
-
- ContactState state = contact.getContactState();
- if (BooleanUtils.isFalse(contact.getValidationProgram()) ||
- (!admin && BooleanUtils.isFalse(contact.getValidationCompany()))) {
- result = "refused";
- } else if (accepted && state.equals(ContactState.BOARDING_DONE)) {
- result = "accepted";
- } else if (accepted && state.isUnfinishedState()) {
- result = "unfinished";
- } else if (state.isFinalState()) {
- result = "even";
- } else {
- result = "odd";
- }
- return result;
- }
-}
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-18 13:11:09 UTC (rev 549)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-18 13:39:46 UTC (rev 550)
@@ -48,7 +48,6 @@
import fr.ifremer.wao.ui.components.FeedBack;
import fr.ifremer.wao.ui.components.Layout;
import fr.ifremer.wao.ui.data.BoatDataSource;
-import fr.ifremer.wao.ui.data.BusinessUtils;
import fr.ifremer.wao.ui.data.ExportStreamResponse;
import fr.ifremer.wao.ui.data.GenericSelectModel;
import fr.ifremer.wao.ui.data.RequiresAuthentication;
@@ -722,17 +721,17 @@
*
* @return the CSS style to apply on contact block
* @throws WaoException
- * @see BusinessUtils#getContactStyle(Contact, boolean)
+ * @see WaoManager#getContactStyle(Contact, boolean)
*/
public String getlastContactStyle() throws WaoException {
Contact contact = getCompanyBoatInfos().getLastContact();
- return BusinessUtils.getContactStyle(contact, user.isAdmin());
+ return manager.getContactStyle(contact, user.isAdmin());
}
/** /////////////////////// FOR EACH ELLIGIBLEBOAT ROW ///////////////// **/
public String getElligibleRowInfos() {
- return BusinessUtils.getTooltipSampleRow(elligibleBoat.getSampleRow());
+ return manager.getTooltipSampleRow(elligibleBoat.getSampleRow());
}
public boolean isElligibleBoatCompanyActiveFalse() {
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-06-18 13:11:09 UTC (rev 549)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-06-18 13:39:46 UTC (rev 550)
@@ -345,23 +345,23 @@
return userSelectModel;
}
- public String getCommentDisplayed() {
- if (contact.getComment() != null && contact.getComment().length() > 20) {
- return contact.getComment().substring(0, 20) + "...";
+ public String getCommentDisplayText(String comment) {
+ if (comment != null && comment.length() > 20) {
+ return comment.substring(0, 20) + "...";
}
- return contact.getComment();
+ return comment;
}
- public String getCommentTooltip() {
- return contact.getComment().replaceAll("\n", "<br />").replaceAll("\r", "");
+ public String getCommentTooltip(String comment) {
+ return manager.getTooltipText(comment);
}
public String getSampleRowDescription() {
- return BusinessUtils.getTooltipSampleRow(contact.getSampleRow());
+ return manager.getTooltipSampleRow(contact.getSampleRow());
}
public String getBoatDescription() {
- return BusinessUtils.getTooltipBoat(contact.getBoat());
+ return manager.getTooltipBoat(contact.getBoat());
}
public String getTooltipExportFrom() throws WaoException {
@@ -376,7 +376,7 @@
}
public String getRowClass() {
- String result = BusinessUtils.getContactStyle(contact, user.isAdmin());
+ String result = manager.getContactStyle(contact, user.isAdmin());
if (contact.getTopiaId().equals(contactSelectedId)) {
result = "selected";
}
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-06-18 13:11:09 UTC (rev 549)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-06-18 13:39:46 UTC (rev 550)
@@ -37,11 +37,11 @@
import fr.ifremer.wao.entity.Company;
import fr.ifremer.wao.service.ServiceSynthesis;
import fr.ifremer.wao.ui.base.AbstractFilteredPage;
-import fr.ifremer.wao.ui.data.BusinessUtils;
import fr.ifremer.wao.ui.data.ChartUtils;
import fr.ifremer.wao.ui.data.ChartUtils.ChartType;
import fr.ifremer.wao.ui.data.RequiresAuthentication;
import fr.ifremer.wao.ui.data.SynthesisId;
+import fr.ifremer.wao.ui.services.WaoManager;
import org.apache.commons.collections.CollectionUtils;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
@@ -78,6 +78,9 @@
@RequiresAuthentication({UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER})
@IncludeStylesheet("context:css/synthesis.css")
public class Synthesis extends AbstractFilteredPage {
+
+ @Inject
+ private WaoManager manager;
@Inject
private ServiceSynthesis serviceSynthesis;
@@ -201,7 +204,7 @@
String realText =
getFilter().getEstimatedTides() ? "Estimé" : "Réalisé";
data.put(realText, res.get(1));
- String title = BusinessUtils.getDataSamplingTitle(getFilter());
+ String title = manager.getDataSamplingTitle(getFilter());
return ChartUtils.createCategoryChart(title, "Nb marées", "Mois", getDataSamplingChartType(), data);
}
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2010-06-18 13:11:09 UTC (rev 549)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2010-06-18 13:39:46 UTC (rev 550)
@@ -29,8 +29,21 @@
import fr.ifremer.wao.WaoContext;
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.WaoProperty;
+import fr.ifremer.wao.bean.ContactState;
+import fr.ifremer.wao.bean.SamplingFilter;
+import fr.ifremer.wao.entity.Boat;
+import fr.ifremer.wao.entity.Contact;
+import fr.ifremer.wao.entity.FishingZone;
+import fr.ifremer.wao.entity.Profession;
+import fr.ifremer.wao.entity.SampleRow;
import fr.ifremer.wao.service.ServiceUser;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Date;
+
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.nuiton.util.ApplicationConfig;
@@ -157,6 +170,126 @@
return eee.getMessage();
}
+ public String getTooltipText(String input) {
+ if (input != null) {
+ return input.replaceAll("\n", "<br />").replaceAll("\r", "");
+ }
+ return "";
+ }
+
+
+ public String getTooltipSampleRow(SampleRow row) {
+ StringBuilder result = new StringBuilder();
+ DateFormat dateFormat = new SimpleDateFormat("MM/yyyy");
+ Profession profession = row.getProfession();
+ result.append("<strong>Métier : </strong>").
+ append(profession.getCodeDCF5());
+ if (!StringUtils.isEmpty(profession.getMeshSize())) {
+ result.append(' ').append(profession.getMeshSize());
+ }
+ if (!StringUtils.isEmpty(profession.getSize())) {
+ result.append(' ').append(profession.getSize());
+ }
+ if (!StringUtils.isEmpty(profession.getOther())) {
+ result.append(' ').append(profession.getOther());
+ }
+ result.append(" - ").append(profession.getLibelle());
+ if (!StringUtils.isEmpty(profession.getSpecies())) {
+ result.append("\n<strong>Espèces cibles : </strong>").
+ append(profession.getSpecies());
+ }
+ result.append("\n<strong>Programme : </strong>").
+ append(row.getProgramName()).
+ append("\n<strong>Période : </strong> du ").
+ append(dateFormat.format(row.getPeriodBegin())).append(" au ").
+ append(dateFormat.format(row.getPeriodEnd()));
+
+ for (FishingZone zone : row.getFishingZone()) {
+ result.append("\n<strong>Zone de pêche : </strong>").
+ append(zone.getCode());
+ }
+
+ return getTooltipText(result.toString());
+ }
+
+ public String getTooltipBoat(Boat boat) {
+ StringBuilder result = new StringBuilder("<strong>").
+ append(boat.getImmatriculation()).append("</strong>").
+ append("\n<strong>Quartier : </strong>").
+ append(boat.getDistrictCode()).
+ append("\n<strong>Longueur : </strong>").
+ append(boat.getBoatLength()).append(" m").
+ append("\n<strong>Année de construction : </strong>").
+ append(boat.getBuildYear());
+ return getTooltipText(result.toString());
+ }
+
+ public String getDataSamplingTitle(SamplingFilter filter) {
+ StringBuilder result = new StringBuilder("Données des marées");
+ String separator = " : ";
+ if (filter.getCompany() != null) {
+ //result.append(!filtered ? " : " : ", ";
+ result.append(separator).
+ append("\nSociété ").append(filter.getCompany().getName());
+ separator = ", ";
+ }
+ if (StringUtils.isNotEmpty(filter.getProgramName())) {
+ result.append(separator).
+ append("\nProgramme ").append(filter.getProgramName());
+ separator = ", ";
+ }
+ if (filter.getSampleRow() != null) {
+ Profession profession = filter.getSampleRow().getProfession();
+ result.append(separator).
+ append("\nMétier ").append(profession.getCode());
+ if (StringUtils.isNotEmpty(profession.getLibelle())) {
+ result.append(" - ").append(profession.getLibelle());
+ }
+ if (StringUtils.isNotEmpty(profession.getSpecies())) {
+ result.append("\nEspèces (").
+ append(profession.getSpecies()).append(")");
+ }
+ result.append("\nZones de pêche (");
+ for (FishingZone zone : filter.getSampleRow().getFishingZone()) {
+ result.append(zone.getDistrictCode()).append(' ');
+ }
+ result.append(")");
+ separator = ", ";
+ } else {
+ if (filter.getFacadeName() != null) {
+ result.append(separator).
+ append("\nFaçade ").append(filter.getFacadeName());
+ separator = ", ";
+ }
+ if (filter.getSectorName() != null) {
+ result.append(separator).
+ append("\nZone ").append(filter.getSectorName());
+ }
+ }
+ return result.toString();
+ }
+
+ public String getContactStyle(Contact contact, boolean admin) {
+ String result = "";
+ boolean accepted = BooleanUtils.isTrue(contact.getValidationProgram()) ||
+ (!admin && BooleanUtils.isTrue(contact.getValidationCompany()));
+
+ ContactState state = contact.getContactState();
+ if (BooleanUtils.isFalse(contact.getValidationProgram()) ||
+ (!admin && BooleanUtils.isFalse(contact.getValidationCompany()))) {
+ result = "refused";
+ } else if (accepted && state.equals(ContactState.BOARDING_DONE)) {
+ result = "accepted";
+ } else if (accepted && state.isUnfinishedState()) {
+ result = "unfinished";
+ } else if (state.isFinalState()) {
+ result = "even";
+ } else {
+ result = "odd";
+ }
+ return result;
+ }
+
}
Modified: trunk/wao-ui/src/main/webapp/Contacts.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/Contacts.tml 2010-06-18 13:11:09 UTC (rev 549)
+++ trunk/wao-ui/src/main/webapp/Contacts.tml 2010-06-18 13:39:46 UTC (rev 550)
@@ -273,13 +273,23 @@
<p:else>
<t:if t:test="contact.comment">
- <span t:type="ck/Tooltip" title="Commentaire" t:value="prop:commentTooltip" t:effect="appear">
- ${commentDisplayed}
+ <span t:type="ck/Tooltip" title="Commentaire" t:value="${getCommentTooltip(contact.comment)}" t:effect="appear">
+ ${getCommentDisplayText(contact.comment)}
</span>
</t:if>
</p:else>
</t:if>
</p:commentCell>
+ <p:commentCoordinatorCell>
+ <span t:type="ck/Tooltip" title="Commentaire société" t:value="${getCommentTooltip(contact.commentCoordinator)}" t:effect="appear">
+ ${getCommentDisplayText(contact.commentCoordinator)}
+ </span>
+ </p:commentCoordinatorCell>
+ <p:commentAdminCell>
+ <span t:type="ck/Tooltip" title="Commentaire admin" t:value="${getCommentTooltip(contact.commentAdmin)}" t:effect="appear">
+ ${getCommentDisplayText(contact.commentAdmin)}
+ </span>
+ </p:commentAdminCell>
<p:actionsCell>
<t:if t:test="hasActions()">
<t:if t:test="editionMode">
1
0
[Suiviobsmer-commits] r549 - in trunk/wao-business/src: main/java/fr/ifremer/wao main/java/fr/ifremer/wao/entity main/java/fr/ifremer/wao/service test/java/fr/ifremer/wao/service
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
18 Jun '10
Author: fdesbois
Date: 2010-06-18 13:11:09 +0000 (Fri, 18 Jun 2010)
New Revision: 549
Log:
- Evo #2336 : Add test + use concat to find on both firstName and lastName
- Refactor WaoQueryBuilder usage + add WaoQueryHelper (it would be nice to generate this class)
Added:
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryHelper.java
Removed:
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactProperty.java
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/EntityProperty.java
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/FishingZoneProperty.java
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleMonthProperty.java
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowProperty.java
Modified:
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java
trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -134,6 +134,8 @@
*/
Date getCurrentDate();
+ WaoQueryBuilder newQueryBuilder();
+
/**
* Retrieve the activityCalendarAccessLogger to manage logging for user
* which access to boat activity calendars. This method will create the
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -94,6 +94,11 @@
return currentDate;
}
+ @Override
+ public WaoQueryBuilder newQueryBuilder() {
+ return new WaoQueryBuilder();
+ }
+
public void setCurrentDate(Date date) {
currentDate = date;
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -11,6 +11,8 @@
import java.util.*;
+import static fr.ifremer.wao.WaoQueryHelper.$;
+
//import static fr.ifremer.wao.TopiaQueryExtra.$;
//import static fr.ifremer.wao.TopiaQueryExtra.$P;
@@ -24,274 +26,107 @@
private static final Logger logger = LoggerFactory.getLogger(WaoQueryBuilder.class);
- public static String ALIAS_SAMPLE_ROW = "SR";
+ WaoQueryHelper.SampleRowProperty sampleRowProperty;
- public static String ALIAS_CONTACT = "C";
+ WaoQueryHelper.SampleMonthProperty sampleMonthProperty;
- public static String ALIAS_FISHING_ZONE = "FZ";
+ WaoQueryHelper.FishingZoneProperty fishingZoneProperty;
- public static String ALIAS_ELLIGIBLE_BOAT = "EB";
+ WaoQueryHelper.BoatProperty boatProperty;
- public static String ALIAS_BOAT = "B";
+ WaoQueryHelper.ContactProperty contactProperty;
- public static String ALIAS_ACTIVITY_CALENDAR = "AC";
+ WaoQueryHelper.ShipOwnerProperty shipOwnerProperty;
- public static String ALIAS_SHIP_OWNER = "SO";
+ WaoQueryHelper.ElligibleBoatProperty elligibleBoatProperty;
- String sampleRowProperty;
-
- String fishingZoneProperty;
-
- String boatProperty;
-
- String contactProperty;
-
- String shipOwnerProperty;
-
- String elligibleBoatProperty;
-
protected TopiaQuery query;
- public WaoQueryBuilder(Class<?> entityClass) {
- initialize(entityClass);
+ protected WaoQueryBuilder() {
}
- public WaoQueryBuilder(TopiaQuery query) {
- this.query = query;
- }
+ public WaoQueryHelper.BoatProperty initializeForBoat() {
+ boatProperty = WaoQueryHelper.newBoatProperty();
+ shipOwnerProperty = boatProperty.shipOwnerProperty();
+ elligibleBoatProperty = WaoQueryHelper.newElligibleBoatProperty();
+ sampleRowProperty = elligibleBoatProperty.sampleRowProperty();
- private void initialize(Class<?> entityClass) {
- if (Boat.class.isAssignableFrom(entityClass)) {
- boatProperty = ALIAS_BOAT;
- query = createQuery(Boat.class, boatProperty);
+ query = WaoQueryHelper.createQuery(boatProperty);
- } else if (SampleRow.class.isAssignableFrom(entityClass)) {
- sampleRowProperty = ALIAS_SAMPLE_ROW;
- query = createQuery(SampleRow.class, sampleRowProperty);
-
- } else if (FishingZone.class.isAssignableFrom(entityClass)) {
- fishingZoneProperty = ALIAS_FISHING_ZONE;
- query = createQuery(FishingZone.class, fishingZoneProperty);
-
- } else if (Contact.class.isAssignableFrom(entityClass)) {
- contactProperty = ALIAS_CONTACT;
- query = createQuery(Contact.class, contactProperty);
-
- } else if (ShipOwner.class.isAssignableFrom(entityClass)) {
- shipOwnerProperty = ALIAS_SHIP_OWNER;
- query = createQuery(ShipOwner.class, shipOwnerProperty);
- }
- }
-
- protected TopiaQuery createQuery(Class<?> entityClass, String alias) {
- return new TopiaQuery((Class<? extends TopiaEntity>)entityClass, alias);
+ return boatProperty;
}
- public TopiaQuery toQuery() {
- return query;
- }
+ public WaoQueryHelper.ShipOwnerProperty initializeForShipOwner() {
+ shipOwnerProperty = WaoQueryHelper.newShipOwnerProperty();
- public void setSampleRowProperty(String sampleRowProperty) {
- this.sampleRowProperty = sampleRowProperty;
- }
+ query = WaoQueryHelper.createQuery(shipOwnerProperty);
- public void setFishingZoneProperty(String fishingZoneProperty) {
- this.fishingZoneProperty = fishingZoneProperty;
+ return shipOwnerProperty;
}
- public String getSampleRowProperty() {
- return sampleRowProperty;
- }
+ public WaoQueryHelper.SampleRowProperty initializeForSampleRow(boolean fishingZone) {
+ sampleRowProperty = WaoQueryHelper.newSampleRowProperty();
- public String getShipOwnerProperty() {
- if (StringUtils.isNotEmpty(boatProperty)) {
- shipOwnerProperty = getProperty(boatProperty, Boat.SHIP_OWNER);
+ if (fishingZone) {
+ fishingZoneProperty = WaoQueryHelper.newFishingZoneProperty();
}
- return shipOwnerProperty;
- }
- public String getSectorNameProperty() {
- String result = getProperty(fishingZoneProperty,
- FishingZone.SECTOR_NAME);
- return result;
- }
+ query = WaoQueryHelper.createQuery(sampleRowProperty);
- public String getFacadeNameProperty() {
- String result = getProperty(fishingZoneProperty,
- FishingZone.FACADE_NAME);
- return result;
+ return sampleRowProperty;
}
- public String getFishingZoneSampleRowProperty() {
- String result = getProperty(fishingZoneProperty,
- FishingZone.SAMPLE_ROW);
- return result;
- }
+ public WaoQueryHelper.SampleMonthProperty initializeForSampleMonth() {
+ sampleMonthProperty = WaoQueryHelper.newSampleMonthProperty();
+ sampleRowProperty = sampleMonthProperty.sampleRowProperty();
- public String getFishingZoneDistrictProperty() {
- String result = getProperty(fishingZoneProperty,
- FishingZone.DISTRICT_CODE);
- return result;
- }
+ query = WaoQueryHelper.createQuery(sampleMonthProperty);
- public String getCodeDCF5Property() {
- String result = getProperty(sampleRowProperty,
- SampleRow.PROFESSION,
- Profession.CODE_DCF5);
- return result;
+ return sampleMonthProperty;
}
- public String getProgramNameProperty() {
- String result = getProperty(sampleRowProperty,
- SampleRow.PROGRAM_NAME);
- return result;
- }
+ public WaoQueryHelper.FishingZoneProperty initializeForFishingZone() {
+ fishingZoneProperty = WaoQueryHelper.newFishingZoneProperty();
- public String getSampleRowCodeProperty() {
- String result = getProperty(sampleRowProperty,
- SampleRow.CODE);
- return result;
- }
+ query = WaoQueryHelper.createQuery(fishingZoneProperty);
- public String getSampleRowBeginProperty() {
- String result = getProperty(sampleRowProperty,
- SampleRow.PERIOD_BEGIN);
- return result;
+ return fishingZoneProperty;
}
- public String getSampleRowEndProperty() {
- String result = getProperty(sampleRowProperty,
- SampleRow.PERIOD_END);
- return result;
- }
+ public WaoQueryHelper.ContactProperty initializeForContact() {
+ contactProperty = WaoQueryHelper.newContactProperty();
+ sampleRowProperty = contactProperty.sampleRowProperty();
+ boatProperty = contactProperty.boatProperty();
- public String getSampleRowCompanyProperty() {
- String result = getProperty(sampleRowProperty,
- SampleRow.COMPANY);
- return result;
- }
+ query = WaoQueryHelper.createQuery(contactProperty);
- public String getSampleRowFishingZoneProperty() {
- String result = getProperty(sampleRowProperty,
- SampleRow.FISHING_ZONE);
- return result;
+ return contactProperty;
}
- public String getBoatImmatriculationProperty() {
- String result = getProperty(boatProperty,
- Boat.IMMATRICULATION);
- return result;
+ public WaoQueryHelper.SampleRowProperty getSampleRowProperty() {
+ return sampleRowProperty;
}
- public String getBoatNameProperty() {
- String result = getProperty(boatProperty,
- Boat.NAME);
- return result;
+ public WaoQueryHelper.SampleMonthProperty getSampleMonthProperty() {
+ return sampleMonthProperty;
}
- public String getBoatDistrictProperty() {
- String result = getProperty(boatProperty,
- Boat.DISTRICT_CODE);
- return result;
+ public WaoQueryHelper.FishingZoneProperty getFishingZoneProperty() {
+ return fishingZoneProperty;
}
- public String getBoatElligibleProperty() {
- String result = getProperty(boatProperty,
- Boat.ELLIGIBLE_BOAT);
- return result;
+ public WaoQueryHelper.ShipOwnerProperty getShipOwnerProperty() {
+ return shipOwnerProperty;
}
- public String getBoatOrderProperty(String order) {
- String result = getProperty(boatProperty,
- order);
- return result;
- }
-
- public String getContactObserverProperty() {
- String result = getProperty(contactProperty,
- Contact.OBSERVER);
- return result;
- }
-
- public String getContactSampleRowProperty() {
- String result = getProperty(contactProperty,
- Contact.SAMPLE_ROW);
- return result;
- }
-
- public String getContactBoatProperty() {
- String result = getProperty(contactProperty,
- Contact.BOAT);
- return result;
- }
-
- public String getMammalsObservationProperty() {
- String result = getProperty(contactProperty,
- Contact.MAMMALS_OBSERVATION);
- return result;
- }
-
- public String getMammalsCaptureProperty() {
- String result = getProperty(contactProperty,
- Contact.MAMMALS_CAPTURE);
- return result;
- }
-
- public String getValidationProgramProperty() {
- String result = getProperty(contactProperty,
- Contact.VALIDATION_PROGRAM);
- return result;
- }
-
- public String getValidationCompanyProperty() {
- String result = getProperty(contactProperty,
- Contact.VALIDATION_COMPANY);
- return result;
- }
-
- public String getContactStateProperty() {
- String result = getProperty(contactProperty,
- Contact.STATE);
- return result;
- }
-
- public String getContactCreateDateProperty() {
- String result = getProperty(contactProperty,
- Contact.TOPIA_CREATE_DATE);
- return result;
- }
-
- public String getElligibleSampleRowProperty() {
- String result = getProperty(elligibleBoatProperty,
- ElligibleBoat.SAMPLE_ROW);
- return result;
- }
-
- public String getElligibleCompanyActiveProperty() {
- String result = getProperty(elligibleBoatProperty,
- ElligibleBoat.COMPANY_ACTIVE);
- return result;
- }
-
- public String getElligibleGlobalActiveProperty() {
- String result = getProperty(elligibleBoatProperty,
- ElligibleBoat.GLOBAL_ACTIVE);
- return result;
- }
-
- private String getProperty(String... properties) {
- // Add property cache managment ??
- return TopiaQuery.getProperty(properties);
- }
-
- public WaoQueryBuilder applyUserFilter(TopiaQuery query, UserFilter filter) {
+ public TopiaQuery applyUserFilter(UserFilter filter) {
Integer startIndex = filter.getStartIndex();
Integer endIndex = filter.getEndIndex();
if (startIndex != null && endIndex != null) {
query.setLimit(startIndex, endIndex);
}
- return this;
+ return query;
}
/**
@@ -301,7 +136,7 @@
* @return the query with elements added
* @since 1.1.2
*/
- public WaoQueryBuilder applySimpleFishingZoneFilter(SamplingFilter filter, TopiaQuery query) {
+ public TopiaQuery applySimpleFishingZoneFilter(SamplingFilter filter, TopiaQuery query) {
// need fishingZoneProperty
@@ -313,34 +148,34 @@
String facadeName = filter.getFacadeName();
if (StringUtils.isNotEmpty(sectorName)) {
- query.addEquals(getSectorNameProperty(), sectorName);
+ query.addEquals(fishingZoneProperty.sectorName(), sectorName);
} else if (StringUtils.isNotEmpty(facadeName)) {
- query.addEquals(getFacadeNameProperty(), facadeName);
+ query.addEquals(fishingZoneProperty.facadeName(), facadeName);
}
- return this;
+ return query;
}
- public WaoQueryBuilder applyFishingZoneFilter(SamplingFilter filter) {
+ public TopiaQuery applyFishingZoneFilter(SamplingFilter filter) {
Company company = filter.getCompany();
String programName = filter.getProgramName();
if (company != null || StringUtils.isNotEmpty(programName)) {
- sampleRowProperty = ALIAS_SAMPLE_ROW;
+ sampleRowProperty = WaoQueryHelper.newSampleRowProperty();
- query.addFrom(SampleRow.class, sampleRowProperty).
- addInElements(sampleRowProperty, getFishingZoneSampleRowProperty());
+ query.addFrom(SampleRow.class, sampleRowProperty.$alias()).
+ addInElements(sampleRowProperty.$alias(), fishingZoneProperty.sampleRow());
}
if (company != null) {
- query.addEquals(getSampleRowCompanyProperty(), company);
+ query.addEquals(sampleRowProperty.company(), company);
}
if (programName != null) {
- query.addEquals(getProgramNameProperty(), programName);
+ query.addEquals(sampleRowProperty.programName(), programName);
}
- return this;
+ return query;
}
/**
@@ -350,7 +185,7 @@
*
* @return the query with filtered elements added
*/
- public WaoQueryBuilder applySamplingFilter(SamplingFilter filter) {
+ public TopiaQuery applySamplingFilter(SamplingFilter filter) {
// need sampleRowProperty, may have fishingZoneProperty
@@ -365,7 +200,7 @@
// SampleRow filter depends on SampleRow OR sectorName OR facadeName
// sectorName and facadeName are the two FishingZone filters known
if (sampleRow != null) {
- query.addEquals(sampleRowProperty, sampleRow);
+ query.addEquals(sampleRowProperty.$alias(), sampleRow);
// FishingZone filter (sectorName OR facadeName)
} else if (StringUtils.isNotEmpty(filter.getSectorName()) ||
@@ -378,46 +213,49 @@
} else {
// Otherwise, create a subquery to retrieve sampleRows
// corresponding to fishingZone filters
- String sampleRowSubAlias = "SR2";
- String sampleRowFishingZoneProperty =
- TopiaQuery.getProperty(sampleRowSubAlias, SampleRow.FISHING_ZONE);
+// String sampleRowSubAlias = "SR2";
+// String sampleRowFishingZoneProperty =
+// TopiaQuery.getProperty(sampleRowSubAlias, SampleRow.FISHING_ZONE);
- fishingZoneProperty = ALIAS_FISHING_ZONE;
+ WaoQueryHelper.SampleRowProperty subSampleRowProperty =
+ WaoQueryHelper.newSampleRowProperty("SR2");
- TopiaQuery subquery = createQuery(SampleRow.class, sampleRowSubAlias).
- setSelect(sampleRowSubAlias).addDistinct().
- addLeftJoin(sampleRowFishingZoneProperty, fishingZoneProperty,
- false);
+ fishingZoneProperty = WaoQueryHelper.newFishingZoneProperty();
+ TopiaQuery subquery = WaoQueryHelper.createQuery(subSampleRowProperty).
+ setSelect(subSampleRowProperty.$alias()).addDistinct().
+ addLeftJoin(subSampleRowProperty.fishingZone(), fishingZoneProperty.$alias(), false);
+
// Apply filter for fishingZone on subQuery
applySimpleFishingZoneFilter(filter, subquery);
- query.addSubQuery(sampleRowProperty + " IN (?)", subquery);
+ query.addSubQuery($("$1 IN (?)", sampleRowProperty.$alias()), subquery);
}
}
// CodeDCF5 filter
if (codeDCF5 != null) {
- query.addWhere(getCodeDCF5Property(), TopiaQuery.Op.LIKE, "%" + codeDCF5 + "%");
+ query.addWhere(sampleRowProperty.professionProperty().codeDCF5(),
+ TopiaQuery.Op.LIKE, "%" + codeDCF5 + "%");
}
// Program filter
if (programName != null) {
- query.addEquals(getProgramNameProperty(), programName);
+ query.addEquals(sampleRowProperty.programName(), programName);
}
// Period filter on sampleRow dates
if (period != null) {
period.initDayOfMonthExtremities();
- query.addWhere(getSampleRowBeginProperty(), TopiaQuery.Op.LT, period.getThruDate()).
- addWhere(getSampleRowEndProperty(), TopiaQuery.Op.GT, period.getFromDate());
+ query.addWhere(sampleRowProperty.periodBegin(), TopiaQuery.Op.LT, period.getThruDate()).
+ addWhere(sampleRowProperty.periodEnd(), TopiaQuery.Op.GT, period.getFromDate());
} else if (fromDate != null) {
- query.addWhere(getSampleRowEndProperty(), TopiaQuery.Op.GE, fromDate);
+ query.addWhere(sampleRowProperty.periodEnd(), TopiaQuery.Op.GE, fromDate);
}
// Company
if (company != null) {
- query.addEquals(getSampleRowCompanyProperty(), company);
+ query.addEquals(sampleRowProperty.company(), company);
}
if (nbMonthsFinishedFromToday != null) {
@@ -425,12 +263,12 @@
Calendar calendar = Calendar.getInstance();
calendar.setTime(WaoUtils.getCurrentDate());
calendar.add(Calendar.MONTH, nbMonthsFinishedFromToday);
- query.addWhere(getSampleRowEndProperty(), TopiaQuery.Op.GE, calendar.getTime());
+ query.addWhere(sampleRowProperty.periodEnd(), TopiaQuery.Op.GE, calendar.getTime());
}
- return this;
+ return query;
}
- public WaoQueryBuilder applySimpleBoatFilter(BoatFilter filter) {
+ public TopiaQuery applySimpleBoatFilter(BoatFilter filter) {
// need boatProperty
@@ -439,39 +277,36 @@
Integer boatImmatriculation = filter.getBoatImmatriculation();
// Limit
- applyUserFilter(query, filter);
+ applyUserFilter(filter);
if (StringUtils.isNotEmpty(boatName)) {
- query.addWhere(getBoatNameProperty(), TopiaQuery.Op.LIKE, boatName.trim() + "%");
+ query.addWhere(boatProperty.name(), TopiaQuery.Op.LIKE, boatName.trim() + "%");
}
if (StringUtils.isNotEmpty(boatDistrictCode)) {
- query.addEquals(getBoatDistrictProperty(), boatDistrictCode.trim());
+ query.addEquals(boatProperty.districtCode(), boatDistrictCode.trim());
}
if (boatImmatriculation != null) {
- query.addEquals(getBoatImmatriculationProperty(), boatImmatriculation);
+ query.addEquals(boatProperty.immatriculation(), boatImmatriculation);
}
- return this;
+ return query;
}
- public WaoQueryBuilder applyShipOwnerFilter(String shipOwnerName) {
+ public TopiaQuery applyShipOwnerFilter(String shipOwnerName) {
if (StringUtils.isNotEmpty(shipOwnerName)) {
String input = '%' + StringUtils.upperCase(shipOwnerName) + '%';
- String firstNameProperty =
- getProperty(getShipOwnerProperty(), ShipOwner.FIRST_NAME);
- String lastNameProperty =
- getProperty(getShipOwnerProperty(), ShipOwner.LAST_NAME);
-
query.addWhere(
- $("$1 LIKE :input OR $2 LIKE :input", firstNameProperty, lastNameProperty)
+ $("CONCAT(CONCAT($1, ' '), $2) LIKE :input",
+ shipOwnerProperty.firstName(),
+ shipOwnerProperty.lastName())
).addParam("input", input);
}
- return this;
+ return query;
}
/**
@@ -482,7 +317,7 @@
* @return the WaoQueryBuilder
* @since 1.3
*/
- public WaoQueryBuilder applyBoatFilter(BoatFilter filter) {
+ public TopiaQuery applyBoatFilter(BoatFilter filter) {
//boatProperty = query.getMainAlias();
@@ -496,32 +331,31 @@
if (filter.isSamplingFiltered()) {
// Add join for ElligibleBoat
- elligibleBoatProperty = ALIAS_ELLIGIBLE_BOAT;
- query.addLeftJoin(getBoatElligibleProperty(), elligibleBoatProperty,
- false);
+// elligibleBoatProperty = WaoQueryHelper.newElligibleBoatProperty();
+ query.addLeftJoin(boatProperty.elligibleBoat(), elligibleBoatProperty.$alias(), false);
// To be sure to have no doubloons
- query.setSelect(boatProperty).addDistinct();
+ query.setSelect(boatProperty.$alias()).addDistinct();
// Apply filter for sampling
- sampleRowProperty = getElligibleSampleRowProperty();
+// sampleRowProperty = elligibleBoatProperty.sampleRowProperty();
applySamplingFilter(filter);
// Company
if (company != null) {
// Test only valid ElligibleBoat for that company
query.addWhere($("$1 = :booleanTrue OR ($1 IS NULL AND $2 = :booleanTrue)",
- getElligibleCompanyActiveProperty(),
- getElligibleGlobalActiveProperty())
+ elligibleBoatProperty.companyActive(),
+ elligibleBoatProperty.globalActive())
).addParam("booleanTrue", Boolean.TRUE);
}
}
if (StringUtils.isNotEmpty(orderBy)) {
- query.addOrder(getBoatOrderProperty(orderBy));
+ query.addOrder(boatProperty.$property(orderBy));
}
- return this;
+ return query;
}
/**
@@ -532,7 +366,7 @@
* @return the WaoQueryBuilder
* @since 1.3
*/
- public WaoQueryBuilder applyContactFilter(ContactFilter filter) {
+ public TopiaQuery applyContactFilter(ContactFilter filter) {
// need contactProperty
@@ -551,7 +385,7 @@
// OBSERVER
if (observer != null) {
- query.addEquals(getContactObserverProperty(), observer);
+ query.addEquals(contactProperty.observer(), observer);
}
// Company filter is managed by SamplingFilter because the company is
@@ -561,23 +395,25 @@
filter.setFromDate(null);
if (filter.isSamplingFiltered() || company != null) {
- sampleRowProperty = getContactSampleRowProperty();
+// sampleRowProperty = contactProperty.sampleRowProperty();
+
applySamplingFilter(filter);
}
- boatProperty = getContactBoatProperty();
+// boatProperty = contactProperty.boatProperty();
+
applySimpleBoatFilter(filter);
// MAMMALS_OBSERVATION and MAMMALS_CAPTURE
if (mammalsObservation && mammalsCapture) {
query.addWhere($("$1 = :mammals OR $2 = :mammals",
- getMammalsObservationProperty(),
- getMammalsCaptureProperty())
+ contactProperty.mammalsObservation(),
+ contactProperty.mammalsCapture())
).addParam("mammals", Boolean.TRUE);
} else if (mammalsObservation) {
- query.addEquals(getMammalsObservationProperty(), Boolean.TRUE);
+ query.addEquals(contactProperty.mammalsObservation(), Boolean.TRUE);
} else if (mammalsCapture) {
- query.addEquals(getMammalsCaptureProperty(), Boolean.TRUE);
+ query.addEquals(contactProperty.mammalsCapture(), Boolean.TRUE);
}
// VALIDATION_PROGRAM
@@ -591,7 +427,7 @@
if (programUndefined) {
programValidValues.add(null);
}
- query.addEquals(getValidationProgramProperty(), programValidValues.toArray());
+ query.addEquals(contactProperty.validationProgram(), programValidValues.toArray());
// VALIDATION_COMPANY
List<Object> companyValidValues = new ArrayList<Object>();
@@ -604,31 +440,24 @@
if (companyUndefined) {
companyValidValues.add(null);
}
- query.addEquals(getValidationCompanyProperty(), companyValidValues.toArray());
+ query.addEquals(contactProperty.validationCompany(), companyValidValues.toArray());
// STATE
if (contactState != null) {
- query.addEquals(getContactStateProperty(), contactState.ordinal());
+ query.addEquals(contactProperty.state(), contactState.ordinal());
}
// FROM_DATE
if (fromDate != null) {
- query.addWhere(getContactCreateDateProperty(), TopiaQuery.Op.GE, fromDate);
+ query.addWhere(contactProperty.topiaCreateDate(), TopiaQuery.Op.GE, fromDate);
}
// Reinitialize fromDate of the filter, don't know if it's really needed
filter.setFromDate(fromDate);
// ORDER_BY
- query.addOrderDesc(getContactCreateDateProperty());
+ query.addOrderDesc(contactProperty.topiaCreateDate());
- return this;
+ return query;
}
-
- public static String $(String statement, String... properties) {
- for (int i = 1; i <= properties.length; i++) {
- statement = statement.replace("$" + i, properties[i-1]);
- }
- return statement;
- }
}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryHelper.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryHelper.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryHelper.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -0,0 +1,520 @@
+package fr.ifremer.wao;
+
+import fr.ifremer.wao.entity.Boat;
+import fr.ifremer.wao.entity.Contact;
+import fr.ifremer.wao.entity.ElligibleBoat;
+import fr.ifremer.wao.entity.FishingZone;
+import fr.ifremer.wao.entity.Profession;
+import fr.ifremer.wao.entity.SampleMonth;
+import fr.ifremer.wao.entity.SampleRow;
+import fr.ifremer.wao.entity.ShipOwner;
+import fr.ifremer.wao.entity.WaoUser;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created: 18 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class WaoQueryHelper {
+
+ public static String ALIAS_SHIP_OWNER = "SO";
+
+ public static String ALIAS_BOAT = "B";
+
+ public static String ALIAS_ELLIGIBLE_BOAT = "EB";
+
+ public static String ALIAS_SAMPLE_ROW = "SR";
+
+ public static String ALIAS_SAMPLE_MONTH = "SM";
+
+ public static String ALIAS_PROFESSION = "P";
+
+ public static String ALIAS_FISHING_ZONE = "FZ";
+
+ public static String ALIAS_CONTACT = "C";
+
+ public static String ALIAS_WAO_USER = "WU";
+
+ public static String ALIAS_ACTIVITY_CALENDAR = "AC";
+
+ public static TopiaQuery createQuery(EntityProperty property) {
+ return new TopiaQuery((Class<? extends TopiaEntity>)property.getEntityClass(), property.$alias());
+ }
+
+ public static String $(String statement, String... properties) {
+ for (int i = 1; i <= properties.length; i++) {
+ statement = statement.replace("$" + i, properties[i-1]);
+ }
+ return statement;
+ }
+
+ private static <P extends EntityProperty> P newEntityProperty(Class<P> propertyClass) throws WaoException {
+ return newEntityProperty(propertyClass, null);
+ }
+
+ private static <P extends EntityProperty> P newEntityProperty(Class<P> propertyClass, String alias) throws WaoException {
+ try {
+ P property = propertyClass.newInstance();
+ if (alias == null) {
+ alias = property.defaultAlias();
+ }
+ property.setAlias(alias);
+ return property;
+ } catch (Exception eee) {
+ throw new WaoException(eee, "Error instantiate " + propertyClass.getName());
+ }
+ }
+
+ public static SampleRowProperty newSampleRowProperty() throws WaoException {
+ return newSampleRowProperty(null);
+ }
+
+ public static SampleRowProperty newSampleRowProperty(String alias) throws WaoException {
+ return newEntityProperty(SampleRowProperty.class, alias);
+ }
+
+ public static SampleMonthProperty newSampleMonthProperty() throws WaoException {
+ return newSampleMonthProperty(null);
+ }
+
+ public static SampleMonthProperty newSampleMonthProperty(String alias) throws WaoException {
+ return newEntityProperty(SampleMonthProperty.class, alias);
+ }
+
+ public static ContactProperty newContactProperty() throws WaoException {
+ return newContactProperty(null);
+ }
+
+ public static ContactProperty newContactProperty(String alias) throws WaoException {
+ return newEntityProperty(ContactProperty.class, alias);
+ }
+
+ public static FishingZoneProperty newFishingZoneProperty() throws WaoException {
+ return newFishingZoneProperty(null);
+ }
+
+ public static FishingZoneProperty newFishingZoneProperty(String alias) throws WaoException {
+ return newEntityProperty(FishingZoneProperty.class, alias);
+ }
+
+ public static ElligibleBoatProperty newElligibleBoatProperty() throws WaoException {
+ return newElligibleBoatProperty(null);
+ }
+
+ public static ElligibleBoatProperty newElligibleBoatProperty(String alias) throws WaoException {
+ return newEntityProperty(ElligibleBoatProperty.class, alias);
+ }
+
+ public static BoatProperty newBoatProperty() throws WaoException {
+ return newBoatProperty(null);
+ }
+
+ public static BoatProperty newBoatProperty(String alias) throws WaoException {
+ return newEntityProperty(BoatProperty.class, alias);
+ }
+
+ public static ShipOwnerProperty newShipOwnerProperty() throws WaoException {
+ return newShipOwnerProperty(null);
+ }
+
+ public static ShipOwnerProperty newShipOwnerProperty(String alias) throws WaoException {
+ return newEntityProperty(ShipOwnerProperty.class, alias);
+ }
+
+ public static WaoUserProperty newWaoUserProperty() throws WaoException {
+ return newWaoUserProperty(null);
+ }
+
+ public static WaoUserProperty newWaoUserProperty(String alias) throws WaoException {
+ return newEntityProperty(WaoUserProperty.class, alias);
+ }
+
+ protected static abstract class EntityProperty<E> {
+ protected String alias;
+
+ protected Map<String, String> propertiesCache;
+
+ public EntityProperty() {
+ propertiesCache = new HashMap<String, String>();
+ }
+
+ protected void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+ public String $alias() {
+ return alias;
+ }
+
+ public String $property(String propertyName) {
+ String result = propertiesCache.get(propertyName);
+ if (result == null) {
+ result = TopiaQuery.getProperty(alias, propertyName);
+ propertiesCache.put(propertyName, result);
+ }
+ return result;
+ }
+
+ public String topiaCreateDate() {
+ return $property(TopiaEntity.TOPIA_CREATE_DATE);
+ }
+
+ public String topiaId() {
+ return $property(TopiaEntity.TOPIA_ID);
+ }
+
+ public String topiaVersion() {
+ return $property(TopiaEntity.TOPIA_VERSION);
+ }
+
+ public abstract Class<E> getEntityClass();
+
+ public abstract String defaultAlias();
+ }
+
+ public static class ShipOwnerProperty extends EntityProperty<ShipOwner> {
+
+ protected ShipOwnerProperty() {
+ }
+
+ public String firstName() {
+ return $property(ShipOwner.FIRST_NAME);
+ }
+
+ public String lastName() {
+ return $property(ShipOwner.LAST_NAME);
+ }
+
+ @Override
+ public Class<ShipOwner> getEntityClass() {
+ return ShipOwner.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_SHIP_OWNER;
+ }
+ }
+
+ public static class BoatProperty extends EntityProperty<Boat> {
+
+ protected BoatProperty() {
+ }
+
+ public String immatriculation() {
+ return $property(Boat.IMMATRICULATION);
+ }
+
+ public String name() {
+ return $property(Boat.NAME);
+ }
+
+ public String districtCode() {
+ return $property(Boat.DISTRICT_CODE);
+ }
+
+ public String boatLength() {
+ return $property(Boat.BOAT_LENGTH);
+ }
+
+ public String buildYear() {
+ return $property(Boat.BUILD_YEAR);
+ }
+
+ public String active() {
+ return $property(Boat.ACTIVE);
+ }
+
+ public String shipOwner() {
+ return $property(Boat.SHIP_OWNER);
+ }
+
+ public ShipOwnerProperty shipOwnerProperty() {
+ return newShipOwnerProperty(shipOwner());
+ }
+
+ public String elligibleBoat() {
+ return $property(Boat.ELLIGIBLE_BOAT);
+ }
+
+ @Override
+ public Class<Boat> getEntityClass() {
+ return Boat.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_BOAT;
+ }
+ }
+
+ public static class ElligibleBoatProperty extends EntityProperty<ElligibleBoat> {
+
+ protected ElligibleBoatProperty() {
+ }
+
+ public String companyActive() {
+ return $property(ElligibleBoat.COMPANY_ACTIVE);
+ }
+
+ public String globalActive() {
+ return $property(ElligibleBoat.GLOBAL_ACTIVE);
+ }
+
+ public String sampleRow() {
+ return $property(ElligibleBoat.SAMPLE_ROW);
+ }
+
+ public SampleRowProperty sampleRowProperty() {
+ return newEntityProperty(SampleRowProperty.class, sampleRow());
+ }
+
+ @Override
+ public Class<ElligibleBoat> getEntityClass() {
+ return ElligibleBoat.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_ELLIGIBLE_BOAT;
+ }
+ }
+
+ public static class SampleRowProperty extends EntityProperty<SampleRow> {
+
+ protected SampleRowProperty() {
+ }
+
+ public String programName() {
+ return $property(SampleRow.PROGRAM_NAME);
+ }
+
+ public String code() {
+ return $property(SampleRow.CODE);
+ }
+
+ public String periodBegin() {
+ return $property(SampleRow.PERIOD_BEGIN);
+ }
+
+ public String periodEnd() {
+ return $property(SampleRow.PERIOD_END);
+ }
+
+ public String profession() {
+ return $property(SampleRow.PROFESSION);
+ }
+
+ public ProfessionProperty professionProperty() {
+ return newEntityProperty(ProfessionProperty.class, profession());
+ }
+
+ public String company() {
+ return $property(SampleRow.COMPANY);
+ }
+
+ public String fishingZone() {
+ return $property(SampleRow.FISHING_ZONE);
+ }
+
+ public String sampleMonth() {
+ return $property(SampleRow.SAMPLE_MONTH);
+ }
+
+ @Override
+ public Class<SampleRow> getEntityClass() {
+ return SampleRow.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_SAMPLE_ROW;
+ }
+ }
+
+ public static class SampleMonthProperty extends EntityProperty<SampleMonth> {
+
+ protected SampleMonthProperty() {
+ }
+
+ public String periodDate() {
+ return $property(SampleMonth.PERIOD_DATE);
+ }
+
+ public String realTidesValue() {
+ return $property(SampleMonth.REAL_TIDES_VALUE);
+ }
+
+ public String expectedTidesValue() {
+ return $property(SampleMonth.EXPECTED_TIDES_VALUE);
+ }
+
+ public String estimatedTidesValue() {
+ return $property(SampleMonth.ESTIMATED_TIDES_VALUE);
+ }
+
+ public String sampleRow() {
+ return $property(SampleMonth.SAMPLE_ROW);
+ }
+
+ public SampleRowProperty sampleRowProperty() {
+ return newEntityProperty(SampleRowProperty.class, sampleRow());
+ }
+
+ @Override
+ public Class<SampleMonth> getEntityClass() {
+ return SampleMonth.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_SAMPLE_MONTH;
+ }
+ }
+
+ public static class ProfessionProperty extends EntityProperty<Profession> {
+
+ protected ProfessionProperty() {
+ }
+
+ public String codeDCF5() {
+ return $property(Profession.CODE_DCF5);
+ }
+
+ @Override
+ public Class<Profession> getEntityClass() {
+ return Profession.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_PROFESSION;
+ }
+ }
+
+ public static class FishingZoneProperty extends EntityProperty<FishingZone> {
+
+ protected FishingZoneProperty() {
+ }
+
+ public String sectorName() {
+ return $property(FishingZone.SECTOR_NAME);
+ }
+
+ public String facadeName() {
+ return $property(FishingZone.FACADE_NAME);
+ }
+
+ public String districtCode() {
+ return $property(FishingZone.DISTRICT_CODE);
+ }
+
+ public String sampleRow() {
+ return $property(FishingZone.SAMPLE_ROW);
+ }
+
+ @Override
+ public Class<FishingZone> getEntityClass() {
+ return FishingZone.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_FISHING_ZONE;
+ }
+ }
+
+ public static class ContactProperty extends EntityProperty<Contact> {
+
+ protected ContactProperty() {
+ }
+
+ public String mammalsObservation() {
+ return $property(Contact.MAMMALS_OBSERVATION);
+ }
+
+ public String mammalsCapture() {
+ return $property(Contact.MAMMALS_CAPTURE);
+ }
+
+ public String validationProgram() {
+ return $property(Contact.VALIDATION_PROGRAM);
+ }
+
+ public String validationCompany() {
+ return $property(Contact.VALIDATION_COMPANY);
+ }
+
+ public String tideBeginDate() {
+ return $property(Contact.TIDE_BEGIN_DATE);
+ }
+
+ public String state() {
+ return $property(Contact.STATE);
+ }
+
+ public String observer() {
+ return $property(Contact.OBSERVER);
+ }
+
+ public WaoUserProperty observerProperty() {
+ return newWaoUserProperty(observer());
+ }
+
+ public String sampleRow() {
+ return $property(Contact.SAMPLE_ROW);
+ }
+
+ public SampleRowProperty sampleRowProperty() {
+ return newSampleRowProperty(sampleRow());
+ }
+
+ public String boat() {
+ return $property(Contact.BOAT);
+ }
+
+ public BoatProperty boatProperty() {
+ return newBoatProperty(boat());
+ }
+
+ @Override
+ public Class<Contact> getEntityClass() {
+ return Contact.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_CONTACT;
+ }
+ }
+
+ public static class WaoUserProperty extends EntityProperty<WaoUser> {
+
+ protected WaoUserProperty() {
+ }
+
+ public String company() {
+ return $property(WaoUser.COMPANY);
+ }
+
+ @Override
+ public Class<WaoUser> getEntityClass() {
+ return WaoUser.class;
+ }
+
+ @Override
+ public String defaultAlias() {
+ return ALIAS_WAO_USER;
+ }
+ }
+}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -25,13 +25,13 @@
package fr.ifremer.wao.entity;
-import fr.ifremer.wao.WaoQueryBuilder;
+import fr.ifremer.wao.WaoQueryHelper;
import fr.ifremer.wao.bean.ContactState;
import java.util.Date;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaQuery.Op;
-import static fr.ifremer.wao.WaoQueryBuilder.$;
+import static fr.ifremer.wao.WaoQueryHelper.$;
/**
@@ -54,34 +54,52 @@
@Override
public TopiaQuery createQueryLastContactForBoat(Boat boat, Company company) {
+// // Prepare properties for queries
+// String mainContactAlias = WaoQueryBuilder.ALIAS_CONTACT + "1";
+// String mainBoatProperty =
+// TopiaQuery.getProperty(mainContactAlias, Contact.BOAT);
+// String mainCompanyProperty =
+// TopiaQuery.getProperty(mainContactAlias, Contact.OBSERVER, WaoUser.COMPANY);
+// String mainCreateDateProperty =
+// TopiaQuery.getProperty(mainContactAlias, Contact.TOPIA_CREATE_DATE);
+//
+// String subContactAlias = WaoQueryBuilder.ALIAS_CONTACT + "2";
+// String subBoatProperty =
+// TopiaQuery.getProperty(subContactAlias, Contact.BOAT);
+// String subCompanyProperty =
+// TopiaQuery.getProperty(subContactAlias, Contact.OBSERVER, WaoUser.COMPANY);
+// String subCreateDateProperty =
+// TopiaQuery.getProperty(subContactAlias, Contact.TOPIA_CREATE_DATE);
+//
+// // Construct subquery
+// TopiaQuery subquery = createQuery(subContactAlias).
+// setSelect($("MAX($1)", subCreateDateProperty)).
+// addWhere($("$1 = $2", subBoatProperty ,mainBoatProperty)).
+// addEquals(subCompanyProperty, company);
+//
+// // Construct mainquery
+// TopiaQuery query = createQuery(mainContactAlias).
+// addEquals(mainBoatProperty, boat).
+// addEquals(mainCompanyProperty, company).
+// addSubQuery($("$1 = (?)", mainCreateDateProperty), subquery);
+
// Prepare properties for queries
- String mainContactAlias = WaoQueryBuilder.ALIAS_CONTACT + "1";
- String mainBoatProperty =
- TopiaQuery.getProperty(mainContactAlias, Contact.BOAT);
- String mainCompanyProperty =
- TopiaQuery.getProperty(mainContactAlias, Contact.OBSERVER, WaoUser.COMPANY);
- String mainCreateDateProperty =
- TopiaQuery.getProperty(mainContactAlias, Contact.TOPIA_CREATE_DATE);
+ WaoQueryHelper.ContactProperty mainContactProperty =
+ WaoQueryHelper.newContactProperty("C1");
+ WaoQueryHelper.ContactProperty subContactProperty =
+ WaoQueryHelper.newContactProperty("C2");
- String subContactAlias = WaoQueryBuilder.ALIAS_CONTACT + "2";
- String subBoatProperty =
- TopiaQuery.getProperty(subContactAlias, Contact.BOAT);
- String subCompanyProperty =
- TopiaQuery.getProperty(subContactAlias, Contact.OBSERVER, WaoUser.COMPANY);
- String subCreateDateProperty =
- TopiaQuery.getProperty(subContactAlias, Contact.TOPIA_CREATE_DATE);
-
// Construct subquery
- TopiaQuery subquery = createQuery(subContactAlias).
- setSelect($("MAX($1)", subCreateDateProperty)).
- addWhere($("$1 = $2", subBoatProperty ,mainBoatProperty)).
- addEquals(subCompanyProperty, company);
+ TopiaQuery subquery = createQuery(subContactProperty.$alias()).
+ setSelect($("MAX($1)", subContactProperty.topiaCreateDate())).
+ addWhere($("$1 = $2", subContactProperty.boat(), mainContactProperty.boat())).
+ addEquals(subContactProperty.observerProperty().company(), company);
// Construct mainquery
- TopiaQuery query = createQuery(mainContactAlias).
- addEquals(mainBoatProperty, boat).
- addEquals(mainCompanyProperty, company).
- addSubQuery($("$1 = (?)", mainCreateDateProperty), subquery);
+ TopiaQuery query = createQuery(mainContactProperty.$alias()).
+ addEquals(mainContactProperty.boat(), boat).
+ addEquals(mainContactProperty.observerProperty().company(), company).
+ addSubQuery($("$1 = (?)", mainContactProperty.topiaCreateDate()), subquery);
return query;
}
@@ -99,31 +117,49 @@
@Override
public TopiaQuery createQueryDoneContactsFromDate(Boat boat, Date fromDate) {
+// // Prepare properties for query
+// String mainAlias = WaoQueryBuilder.ALIAS_CONTACT;
+// String stateProperty =
+// TopiaQuery.getProperty(mainAlias, Contact.STATE);
+// String validationCompanyProperty =
+// TopiaQuery.getProperty(mainAlias, Contact.VALIDATION_COMPANY);
+// String validationProgramProperty =
+// TopiaQuery.getProperty(mainAlias, Contact.VALIDATION_PROGRAM);
+// String boatProperty =
+// TopiaQuery.getProperty(mainAlias, Contact.BOAT);
+// String tideBeginProperty =
+// TopiaQuery.getProperty(mainAlias, Contact.TIDE_BEGIN_DATE);
+//
+// // Construct query
+// TopiaQuery query = createQuery(mainAlias).
+// addEquals(stateProperty, ContactState.BOARDING_DONE.ordinal()).
+// addEquals(validationCompanyProperty, Boolean.TRUE).
+// addNullOr(validationProgramProperty, Op.EQ, Boolean.TRUE);
+//
+// if (boat != null) {
+// query.addEquals(boatProperty, boat);
+// }
+//
+// if (fromDate != null) {
+// query.addWhere(tideBeginProperty, Op.GE, fromDate);
+// }
+
// Prepare properties for query
- String mainAlias = WaoQueryBuilder.ALIAS_CONTACT;
- String stateProperty =
- TopiaQuery.getProperty(mainAlias, Contact.STATE);
- String validationCompanyProperty =
- TopiaQuery.getProperty(mainAlias, Contact.VALIDATION_COMPANY);
- String validationProgramProperty =
- TopiaQuery.getProperty(mainAlias, Contact.VALIDATION_PROGRAM);
- String boatProperty =
- TopiaQuery.getProperty(mainAlias, Contact.BOAT);
- String tideBeginProperty =
- TopiaQuery.getProperty(mainAlias, Contact.TIDE_BEGIN_DATE);
+ WaoQueryHelper.ContactProperty contactProperty =
+ WaoQueryHelper.newContactProperty();
// Construct query
- TopiaQuery query = createQuery(mainAlias).
- addEquals(stateProperty, ContactState.BOARDING_DONE.ordinal()).
- addEquals(validationCompanyProperty, Boolean.TRUE).
- addNullOr(validationProgramProperty, Op.EQ, Boolean.TRUE);
+ TopiaQuery query = createQuery(contactProperty.$alias()).
+ addEquals(contactProperty.state(), ContactState.BOARDING_DONE.ordinal()).
+ addEquals(contactProperty.validationCompany(), Boolean.TRUE).
+ addNullOr(contactProperty.validationProgram(), Op.EQ, Boolean.TRUE);
if (boat != null) {
- query.addEquals(boatProperty, boat);
+ query.addEquals(contactProperty.boat(), boat);
}
if (fromDate != null) {
- query.addWhere(tideBeginProperty, Op.GE, fromDate);
+ query.addWhere(contactProperty.tideBeginDate(), Op.GE, fromDate);
}
return query;
}
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactProperty.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactProperty.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactProperty.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -1,53 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 Ifremer
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.wao.entity;
-
-/**
- * ContactProperty
- *
- * Created: 14 avr. 2010
- *
- * @author fdesbois <fdesbois at codelutin.com>
- */
-public class ContactProperty extends EntityProperty {
-
- public ContactProperty(String mainAlias) {
- super();
- setMainAlias(mainAlias);
- }
-
- public String nameSampleRow() {
- return nameProperty(Contact.SAMPLE_ROW);
- }
-
- public String nameState() {
- return nameProperty(Contact.STATE);
- }
-
- public String nameTideBeginDate() {
- return nameProperty(Contact.TIDE_BEGIN_DATE);
- }
-}
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/EntityProperty.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/EntityProperty.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/EntityProperty.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -1,64 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 Ifremer
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.wao.entity;
-
-import org.nuiton.topia.framework.TopiaQuery;
-
-/**
- * EntityProperty
- *
- * Created: 14 avr. 2010
- *
- * @author fdesbois <fdesbois at codelutin.com>
- */
-public abstract class EntityProperty {
-
- protected String mainAlias;
-
- public EntityProperty() {
- }
-
- public void setMainAlias(String mainAlias) {
- this.mainAlias = mainAlias;
- }
-
- public String getMainAlias() {
- return mainAlias;
- }
-
- public String name() {
- return getMainAlias();
- }
-
- protected String nameProperty(String propertyName) {
- return TopiaQuery.getProperty(mainAlias, propertyName);
- }
-
- @Override
- public String toString() {
- return name();
- }
-}
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/FishingZoneProperty.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/FishingZoneProperty.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/FishingZoneProperty.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -1,61 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 Ifremer
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.wao.entity;
-
-/**
- * FishingZoneProperty
- *
- * Created: 14 avr. 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class FishingZoneProperty extends EntityProperty {
-
- public FishingZoneProperty(String mainAlias) {
- super();
- setMainAlias(mainAlias);
- }
-
- public String nameFacadeName() {
- return nameProperty(FishingZone.FACADE_NAME);
- }
-
- public String nameSectorName() {
- return nameProperty(FishingZone.SECTOR_NAME);
- }
-
- public String nameDistrictCode() {
- return nameProperty(FishingZone.DISTRICT_CODE);
- }
-
- public String nameSampleRow() {
- return nameProperty(FishingZone.SAMPLE_ROW);
- }
-}
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleMonthProperty.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleMonthProperty.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleMonthProperty.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -1,49 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 Ifremer
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.wao.entity;
-
-/**
- * SampleMonthProperty
- *
- * Created: 14 avr. 2010
- *
- * @author fdesbois <fdesbois at codelutin.com>
- */
-public class SampleMonthProperty extends EntityProperty{
-
- public SampleMonthProperty(String mainAlias) {
- super();
- setMainAlias(mainAlias);
- }
-
- public String nameSampleRow() {
- return nameProperty(SampleMonth.SAMPLE_ROW);
- }
-
- public String namePeriodDate() {
- return nameProperty(SampleMonth.PERIOD_DATE);
- }
-}
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowProperty.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowProperty.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowProperty.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -1,50 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2009 - 2010 Ifremer
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.wao.entity;
-
-/**
- * SampleRowProperty
- *
- * Created: 14 avr. 2010
- *
- * @author fdesbois <fdesbois at codelutin.com>
- */
-public class SampleRowProperty extends EntityProperty {
-
- public SampleRowProperty(String mainAlias) {
- super();
- setMainAlias(mainAlias);
- }
-
- public String nameCode() {
- return nameProperty(SampleRow.CODE);
- }
-
- public String nameCompany() {
- return nameProperty(SampleRow.COMPANY);
- }
-
-}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -59,7 +59,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static fr.ifremer.wao.WaoQueryBuilder.$;
+import static fr.ifremer.wao.WaoQueryHelper.$;
/**
* ServiceBoatImpl
@@ -103,10 +103,11 @@
BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction);
- TopiaQuery query = new WaoQueryBuilder(Boat.class).
- applyBoatFilter(filter).
- toQuery();
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ builder.initializeForBoat();
+ TopiaQuery query = builder.applyBoatFilter(filter);
+
query.addLoad(Boat.ACTIVITY_CALENDAR);
if (logger.isDebugEnabled()) {
@@ -125,10 +126,11 @@
BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction);
- TopiaQuery query = new WaoQueryBuilder(Boat.class).
- applyBoatFilter(filter).
- toQuery();
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ builder.initializeForBoat();
+ TopiaQuery query = builder.applyBoatFilter(filter);
+
int count = dao.countByQuery(query);
return count;
@@ -320,15 +322,18 @@
ShipOwnerDAO dao = WaoDAOHelper.getShipOwnerDAO(transaction);
- TopiaQuery query = dao.createQuery().
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ WaoQueryHelper.ShipOwnerProperty shipOwnerProperty =
+ builder.initializeForShipOwner();
+
+ TopiaQuery query = builder.
+ applyShipOwnerFilter(shipOwnerName).
addDistinct().
setSelect($("CONCAT(CONCAT($1,' '), $2)",
- ShipOwner.FIRST_NAME,
- ShipOwner.LAST_NAME)
+ shipOwnerProperty.firstName(),
+ shipOwnerProperty.lastName())
);
- new WaoQueryBuilder(query).applyShipOwnerFilter(shipOwnerName);
-
List<String> shipOwnerNames = transaction.findByQuery(query);
return shipOwnerNames;
@@ -486,10 +491,11 @@
// Get boats from database filterd by filter in argument
BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction);
- TopiaQuery query = new WaoQueryBuilder(Boat.class).
- applyBoatFilter(filter).
- toQuery();
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ builder.initializeForBoat();
+ TopiaQuery query = builder.applyBoatFilter(filter);
+
// Reset limit : no pagination needed for results
query.resetLimit();
@@ -575,7 +581,7 @@
ActivityCalendarDAO dao = WaoDAOHelper.getActivityCalendarDAO(transaction);
// Properties needed for query and subQuery
- String calendarAlias = WaoQueryBuilder.ALIAS_ACTIVITY_CALENDAR;
+ String calendarAlias = WaoQueryHelper.ALIAS_ACTIVITY_CALENDAR;
String calendarBoatProperty =
TopiaQuery.getProperty(calendarAlias, ActivityCalendar.BOAT);
String calendarYearProperty =
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -129,18 +129,30 @@
ContactDAO dao = WaoDAOHelper.getContactDAO(transaction);
// Use QueryBuilder to apply filter
- TopiaQuery query = new WaoQueryBuilder(Contact.class).
- applyContactFilter(filter).
- toQuery();
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ WaoQueryHelper.ContactProperty contactProperty =
+ builder.initializeForContact();
- // Loading properties
- String observerCompanyProperty =
- TopiaQuery.getProperty(Contact.OBSERVER, WaoUser.COMPANY);
- String sampleMonthProperty =
- TopiaQuery.getProperty(Contact.SAMPLE_ROW, SampleRow.SAMPLE_MONTH);
+ TopiaQuery query = builder.applyContactFilter(filter).
+// addLoad(contactProperty.observerProperty().company(),
+// contactProperty.sampleRowProperty().sampleMonth());
+ // TODO-fdesbois-2010-06-18 : manage aliases in addLoad
+ addLoad(TopiaQuery.getProperty(Contact.OBSERVER, WaoUser.COMPANY),
+ TopiaQuery.getProperty(Contact.SAMPLE_ROW, SampleRow.SAMPLE_MONTH));
- query.addLoad(observerCompanyProperty, sampleMonthProperty);
+// TopiaQuery query = new WaoQueryBuilder(Contact.class).
+// applyContactFilter(filter).
+// toQuery();
+//
+// // Loading properties
+// String observerCompanyProperty =
+// TopiaQuery.getProperty(Contact.OBSERVER, WaoUser.COMPANY);
+// String sampleMonthProperty =
+// TopiaQuery.getProperty(Contact.SAMPLE_ROW, SampleRow.SAMPLE_MONTH);
+//
+// query.addLoad(observerCompanyProperty, sampleMonthProperty);
+
Map<String, Contact> results = dao.findAllMappedByQuery(query);
return results;
@@ -152,10 +164,11 @@
ContactDAO dao = WaoDAOHelper.getContactDAO(transaction);
- TopiaQuery query = new WaoQueryBuilder(Contact.class).
- applyContactFilter(filter).
- toQuery();
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ builder.initializeForContact();
+ TopiaQuery query = builder.applyContactFilter(filter);
+
int count = dao.countByQuery(query);
return count;
@@ -343,10 +356,11 @@
// // No page limit in this case
// query = filter.prepareQueryForContact(query).resetLimit();
- TopiaQuery query = new WaoQueryBuilder(Contact.class).
- applyContactFilter(filter).
- toQuery();
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ builder.initializeForContact();
+ TopiaQuery query = builder.applyContactFilter(filter);
+
// No page limit in this case
query.resetLimit();
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -30,12 +30,12 @@
import fr.ifremer.wao.WaoDAOHelper;
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.WaoQueryBuilder;
+import fr.ifremer.wao.WaoQueryHelper;
import fr.ifremer.wao.bean.SamplingFilter;
import fr.ifremer.wao.entity.FishingZone;
import fr.ifremer.wao.entity.FishingZoneDAO;
import fr.ifremer.wao.entity.Profession;
import fr.ifremer.wao.entity.ProfessionDAO;
-import fr.ifremer.wao.entity.SampleRow;
import fr.ifremer.wao.io.ImportHelper;
import fr.ifremer.wao.io.WaoCsvHeader.FISHING_ZONE;
import java.io.IOException;
@@ -88,7 +88,7 @@
public List<String> executeGetFacades(TopiaContext transaction,
SamplingFilter filter) throws TopiaException {
-// FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction);
+ FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction);
// TopiaQuery query = dao.createQuery("F");
//
// query = prepareQueryForFishingZoneFilter(query, filter);
@@ -96,12 +96,20 @@
// query.addDistinct().
// setSelect("F." + FishingZone.FACADE_NAME);
- WaoQueryBuilder queryBuilder = new WaoQueryBuilder(FishingZone.class).
- applyFishingZoneFilter(filter);
+// WaoQueryBuilder queryBuilder = new WaoQueryBuilder(FishingZone.class).
+// applyFishingZoneFilter(filter);
+//
+// TopiaQuery query = queryBuilder.toQuery().
+// addDistinct().
+// setSelect(queryBuilder.getFacadeNameProperty());
- TopiaQuery query = queryBuilder.toQuery().
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ WaoQueryHelper.FishingZoneProperty fishingZoneProperty =
+ builder.initializeForFishingZone();
+
+ TopiaQuery query = builder.applyFishingZoneFilter(filter).
addDistinct().
- setSelect(queryBuilder.getFacadeNameProperty());
+ setSelect(fishingZoneProperty.facadeName());
List<String> results = transaction.findByQuery(query);
@@ -123,15 +131,16 @@
// query.addDistinct().
// setSelect("F." + FishingZone.SECTOR_NAME);
- WaoQueryBuilder queryBuilder = new WaoQueryBuilder(FishingZone.class).
- applyFishingZoneFilter(filter);
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ WaoQueryHelper.FishingZoneProperty fishingZoneProperty =
+ builder.initializeForFishingZone();
- TopiaQuery query = queryBuilder.toQuery().
- addDistinct().
- setSelect(queryBuilder.getSectorNameProperty());
+ TopiaQuery query = builder.applyFishingZoneFilter(filter).
+ addDistinct().
+ setSelect(fishingZoneProperty.sectorName());
if (StringUtils.isNotEmpty(filter.getFacadeName())) {
- query.addEquals(queryBuilder.getFacadeNameProperty(), filter.getFacadeName());
+ query.addEquals(fishingZoneProperty.facadeName(), filter.getFacadeName());
}
List<String> results = transaction.findByQuery(query);
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -35,6 +35,7 @@
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.WaoProperty;
import fr.ifremer.wao.WaoQueryBuilder;
+import fr.ifremer.wao.WaoQueryHelper;
import fr.ifremer.wao.bean.ConnectedUser;
import fr.ifremer.wao.bean.FacadeRow;
import fr.ifremer.wao.bean.FacadeRowImpl;
@@ -373,24 +374,29 @@
//
// filter.prepareQueryForSampling(query, sampleRowAlias, fishingZoneAlias);
- String fishingZoneAlias = WaoQueryBuilder.ALIAS_FISHING_ZONE;
+ WaoQueryBuilder builder = context.newQueryBuilder();
- WaoQueryBuilder builder = new WaoQueryBuilder(SampleRow.class);
+ WaoQueryHelper.SampleRowProperty sampleRowProperty =
+ builder.initializeForSampleRow(true);
- // Set fishingZoneProperty : we want to control this association
- builder.setFishingZoneProperty(fishingZoneAlias);
- builder.applySamplingFilter(filter);
+ WaoQueryHelper.FishingZoneProperty fishingZoneProperty =
+ builder.getFishingZoneProperty();
+// new WaoQueryBuilder(SampleRow.class);
+//
+// // Set fishingZoneProperty : we want to control this association
+// builder.setFishingZoneProperty(fishingZoneProperty);
+// builder.applySamplingFilter(filter);
+
// Add join for FishingZone
- TopiaQuery query = builder.toQuery().
+ TopiaQuery query = builder.applySamplingFilter(filter).
addDistinct().
- addLeftJoin(builder.getSampleRowFishingZoneProperty(),
- fishingZoneAlias, false).
+ addLeftJoin(sampleRowProperty.fishingZone(), fishingZoneProperty.$alias(), false).
// Order By facade, sector, districtCode, sampleRowCode
- addOrder(builder.getFacadeNameProperty(),
- builder.getSectorNameProperty(),
- builder.getFishingZoneDistrictProperty(),
- builder.getSampleRowCodeProperty());
+ addOrder(fishingZoneProperty.facadeName(),
+ fishingZoneProperty.sectorName(),
+ fishingZoneProperty.districtCode(),
+ sampleRowProperty.code());
// Need fishingZone properties in Select to use them in orderBy
// addSelect(queryBuilder.getFacadeNameProperty(),
@@ -449,12 +455,14 @@
//
// return dao.findAllByQuery(query);
- WaoQueryBuilder builder = new WaoQueryBuilder(SampleRow.class).
- applySamplingFilter(filter);
+ WaoQueryBuilder builder = context.newQueryBuilder();
- TopiaQuery query = builder.toQuery().
+ WaoQueryHelper.SampleRowProperty sampleRowProperty =
+ builder.initializeForSampleRow(false);
+
+ TopiaQuery query = builder.applySamplingFilter(filter).
addDistinct().
- addOrder(builder.getSampleRowCodeProperty());
+ addOrder(sampleRowProperty.code());
List<SampleRow> rows = dao.findAllByQuery(query);
@@ -703,11 +711,12 @@
//
// query.addOrder(sampleRowCodeProperty);
- WaoQueryBuilder builder = new WaoQueryBuilder(SampleRow.class).
- applySamplingFilter(filter);
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ WaoQueryHelper.SampleRowProperty sampleRowProperty =
+ builder.initializeForSampleRow(false);
- TopiaQuery query = builder.toQuery().
- addOrder(builder.getSampleRowCodeProperty());
+ TopiaQuery query = builder.applySamplingFilter(filter).
+ addOrder(sampleRowProperty.code());
List<SampleRow> rows = dao.findAllByQuery(query);
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -29,8 +29,22 @@
import fr.ifremer.wao.WaoDAOHelper;
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.WaoQueryBuilder;
-import fr.ifremer.wao.bean.*;
-import fr.ifremer.wao.entity.*;
+import fr.ifremer.wao.WaoQueryHelper;
+import fr.ifremer.wao.bean.BoardingResult;
+import fr.ifremer.wao.bean.BoardingResultImpl;
+import fr.ifremer.wao.bean.ContactAverageReactivity;
+import fr.ifremer.wao.bean.ContactAverageReactivityImpl;
+import fr.ifremer.wao.bean.ContactState;
+import fr.ifremer.wao.bean.ContactStateStatistics;
+import fr.ifremer.wao.bean.ContactStateStatisticsImpl;
+import fr.ifremer.wao.bean.SamplingFilter;
+import fr.ifremer.wao.entity.Boat;
+import fr.ifremer.wao.entity.Company;
+import fr.ifremer.wao.entity.Contact;
+import fr.ifremer.wao.entity.ContactDAO;
+import fr.ifremer.wao.entity.SampleMonth;
+import fr.ifremer.wao.entity.SampleRow;
+import fr.ifremer.wao.entity.WaoUser;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
@@ -42,8 +56,18 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import static fr.ifremer.wao.WaoQueryHelper.$;
+
/**
* ServiceSynthesisImpl
*
@@ -105,26 +129,35 @@
serie2.put(month, 0);
}
- SampleMonthDAO dao = WaoDAOHelper.getSampleMonthDAO(transaction);
- String periodDateProperty = "M." + SampleMonth.PERIOD_DATE;
+ WaoQueryBuilder builder = context.newQueryBuilder();
+ WaoQueryHelper.SampleMonthProperty sampleMonthProperty =
+ builder.initializeForSampleMonth();
+
String realTidesProperty = filter.getEstimatedTides() ?
- SampleMonth.ESTIMATED_TIDES_VALUE : SampleMonth.REAL_TIDES_VALUE;
- TopiaQuery query = dao.createQuery("M").
- setSelect(periodDateProperty).
- addSelect("SUM(M." + realTidesProperty + ")").
- addSelect("SUM(M." + SampleMonth.EXPECTED_TIDES_VALUE + ")").
-// addWhere(periodDate + " BETWEEN :fromDate AND :thruDate").
-// addParam("fromDate", period.getFromDate()).
-// addParam("thruDate", period.getThruDate()).
- addBetween(periodDateProperty, period.getFromDate(), period.getThruDate()).
- addGroup(periodDateProperty).addOrder(periodDateProperty);
+ sampleMonthProperty.estimatedTidesValue() : sampleMonthProperty.realTidesValue();
-// query = filter.prepareQueryForSampling(query,
-// "M." + SampleMonth.SAMPLE_ROW);
+ TopiaQuery query = builder.applySamplingFilter(filter).
+ setSelect(sampleMonthProperty.periodDate()).
+ addSelect($("SUM($1)", realTidesProperty)).
+ addSelect($("SUM($1)", sampleMonthProperty.expectedTidesValue())).
+ addBetween(sampleMonthProperty.periodDate(), period.getFromDate(), period.getThruDate()).
+ addGroup(sampleMonthProperty.periodDate()).
+ addOrder(sampleMonthProperty.periodDate());
- WaoQueryBuilder builder = new WaoQueryBuilder(query);
- builder.setSampleRowProperty("M." + SampleMonth.SAMPLE_ROW);
- builder.applySamplingFilter(filter);
+// SampleMonthDAO dao = WaoDAOHelper.getSampleMonthDAO(transaction);
+// String periodDateProperty = "M." + SampleMonth.PERIOD_DATE;
+// String realTidesProperty = filter.getEstimatedTides() ?
+// SampleMonth.ESTIMATED_TIDES_VALUE : SampleMonth.REAL_TIDES_VALUE;
+// TopiaQuery query = dao.createQuery("M").
+// setSelect(periodDateProperty).
+// addSelect("SUM(M." + realTidesProperty + ")").
+// addSelect("SUM(M." + SampleMonth.EXPECTED_TIDES_VALUE + ")").
+// addBetween(periodDateProperty, period.getFromDate(), period.getThruDate()).
+// addGroup(periodDateProperty).addOrder(periodDateProperty);
+//
+// WaoQueryBuilder builder = new WaoQueryBuilder(query);
+// builder.setSampleRowProperty("M." + SampleMonth.SAMPLE_ROW);
+// builder.applySamplingFilter(filter);
if (log.isTraceEnabled()) {
log.trace("Exec query : " + query);
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java 2010-06-18 13:09:39 UTC (rev 548)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java 2010-06-18 13:11:09 UTC (rev 549)
@@ -50,7 +50,6 @@
import org.nuiton.topia.TopiaException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.Assert.*;
/**
*
@@ -114,38 +113,48 @@
// Exec with no filter
Map<Integer, Boat> boats = service.getBoatsByFilter(filter);
- assertEquals(6, boats.size());
+ Assert.assertEquals(6, boats.size());
// first boat of the file
Boat boat = boats.get(273129);
- assertNotNull(boat);
+ Assert.assertNotNull(boat);
// Exec with filter on Immatriculation
filter.setBoatImmatriculation(273129);
boats = service.getBoatsByFilter(filter);
- assertEquals(1, boats.size());
+ Assert.assertEquals(1, boats.size());
// Exec with filter on Name : start with "M"
filter = new BoatFilterImpl();
filter.setBoatName("M");
boats = service.getBoatsByFilter(filter);
- assertEquals(2, boats.size());
+ Assert.assertEquals(2, boats.size());
// Exec with filter on DistrictCode
filter = new BoatFilterImpl();
filter.setBoatDistrictCode("UN");
boats = service.getBoatsByFilter(filter);
- assertEquals(4, boats.size());
+ Assert.assertEquals(4, boats.size());
// Exec with filter on SampleRowCode and company
filter = new BoatFilterImpl();
filter.setSampleRow(rows.get(0)); // Code = 2009_03
filter.setCompany(company);
boats = service.getBoatsByFilter(filter);
- assertEquals(2, boats.size());
+ Assert.assertEquals(2, boats.size());
+
+ // Exec with filter on shipOwnerName
+ filter = new BoatFilterImpl();
+ filter.setShipOwnerName("JEAN");
+ boats = service.getBoatsByFilter(filter);
+ Assert.assertEquals(4, boats.size());
+
+ filter.setShipOwnerName("JEAN PIERRE POUTRE");
+ boats = service.getBoatsByFilter(filter);
+ Assert.assertEquals(2, boats.size());
}
@Test
- public void testGetBoats() throws Exception {
+ public void testGetBoatsByImmatriculations() throws Exception {
log.info("getBoats");
InputStream input = getClass().getResourceAsStream("/import/navires.csv");
@@ -153,10 +162,10 @@
String immatriculations = "174592 978419 273129";
List<Boat> results = service.getBoatsByImmatriculations(immatriculations);
- assertEquals(3, results.size());
+ Assert.assertEquals(3, results.size());
immatriculations = "174592 \\ èè-- ç999 àà \n\n 978419 00 ççç 273129";
results = service.getBoatsByImmatriculations(immatriculations);
- assertEquals(3, results.size());
+ Assert.assertEquals(3, results.size());
}
/**
@@ -183,11 +192,11 @@
/** EXEC METHOD **/
CompanyBoatInfos result = service.getCompanyBoatInfos(174592, company);
- assertNotNull(result);
- assertEquals(174592, result.getBoatInfos().getBoat().getImmatriculation());
- assertEquals("TARTANPION", result.getCompany().getName());
+ Assert.assertNotNull(result);
+ Assert.assertEquals(174592, result.getBoatInfos().getBoat().getImmatriculation());
+ Assert.assertEquals("TARTANPION", result.getCompany().getName());
// only row1 is getting
- assertEquals(1, result.getElligibleBoatsValues().size());
+ Assert.assertEquals(1, result.getElligibleBoatsValues().size());
}
private List<SampleRow> prepareSampleRows(Company company)
@@ -290,14 +299,14 @@
companyBoatInfos = service.getCompanyBoatInfos(174592, company);
Map<String, ElligibleBoat> results = companyBoatInfos.getElligibleBoats();
- assertEquals(2, results.size());
+ Assert.assertEquals(2, results.size());
ElligibleBoat elligible = companyBoatInfos.getElligibleBoat("2009_0003");
- assertNotNull(elligible.getCompanyActive());
- assertFalse(elligible.getCompanyActive());
+ Assert.assertNotNull(elligible.getCompanyActive());
+ Assert.assertFalse(elligible.getCompanyActive());
elligible = companyBoatInfos.getElligibleBoat("2010_0004");
- assertTrue(elligible.getCompanyActive());
+ Assert.assertTrue(elligible.getCompanyActive());
/** TEST2 **/
// Suppression ligne lié elligible pour la société
@@ -310,11 +319,11 @@
companyBoatInfos = service.getCompanyBoatInfos(174592, company);
results = companyBoatInfos.getElligibleBoats();
- assertEquals(1, results.size());
+ Assert.assertEquals(1, results.size());
elligible = companyBoatInfos.getElligibleBoat("2009_0003");
- assertNull(elligible.getCompanyActive());
- assertTrue(elligible.getGlobalActive());
+ Assert.assertNull(elligible.getCompanyActive());
+ Assert.assertTrue(elligible.getGlobalActive());
/** EXEC METHOD **/
Contact result = companyBoatInfos.getLastContact();
@@ -331,14 +340,14 @@
InputStream input = getClass().getResourceAsStream("/import/navires.csv");
int[] nbBoats = service.importBoatCsv(input);
- assertEquals(6, nbBoats[0]);
+ Assert.assertEquals(6, nbBoats[0]);
// new boats added
- assertEquals(6, nbBoats[1]);
+ Assert.assertEquals(6, nbBoats[1]);
// Check boat 174592 is active &nd boat 177474 is inactive
List<Boat> results = service.getBoatsByImmatriculations("174592 177474");
- assertTrue(results.get(0).getActive());
- assertFalse(results.get(1).getActive());
+ Assert.assertTrue(results.get(0).getActive());
+ Assert.assertFalse(results.get(1).getActive());
}
@Test
1
0
[Suiviobsmer-commits] r548 - in trunk/wao-ui/src/main: java/fr/ifremer/wao/ui/base java/fr/ifremer/wao/ui/pages webapp
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
18 Jun '10
Author: fdesbois
Date: 2010-06-18 13:09:39 +0000 (Fri, 18 Jun 2010)
New Revision: 548
Log:
Evo #2336 : Add filter in boats page
Modified:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/AbstractFilteredPage.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java
trunk/wao-ui/src/main/webapp/Boats.tml
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/AbstractFilteredPage.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/AbstractFilteredPage.java 2010-06-18 08:16:29 UTC (rev 547)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/AbstractFilteredPage.java 2010-06-18 13:09:39 UTC (rev 548)
@@ -350,7 +350,7 @@
public String[] onProvideCompletionsFromBoatName(String input) throws WaoException {
List<String> results = serviceBoat.getBoatNamesStartWith(input);
- return results.toArray(new String[0]);
+ return results.toArray(new String[results.size()]);
}
/**
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-18 08:16:29 UTC (rev 547)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-18 13:09:39 UTC (rev 548)
@@ -421,6 +421,11 @@
return filtersZone.getBody();
}
+ public String[] onProvideCompletionsFromShipOwnerName(String input) {
+ List<String> results = serviceBoat.getShipOwnerNamesContains(input);
+ return results.toArray(new String[results.size()]);
+ }
+
/**
* EVENT_SELECTED :: reset submit button for filtersForm. Reset filters and sampleRow from context.
*/
Modified: trunk/wao-ui/src/main/webapp/Boats.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/Boats.tml 2010-06-18 08:16:29 UTC (rev 547)
+++ trunk/wao-ui/src/main/webapp/Boats.tml 2010-06-18 13:09:39 UTC (rev 548)
@@ -127,6 +127,8 @@
<input t:type="textfield" t:id="boatImmatriculation" class="width50" t:value="boatFilter.boatImmatriculation" />
<span> code quartier </span>
<input t:type="textfield" t:id="boatDistrictCode" class="width50" t:value="boatFilter.boatDistrictCode" />
+ <span> armateur </span>
+ <input t:type="textfield" t:id="shipOwnerName" class="width150" t:value="boatFilter.shipOwnerName" t:mixins="Autocomplete" />
</div>
<div class="t-beaneditor-row aright">
<input t:type="submit" class="ico search-32px" t:id="search" value="Search" title="Rechercher les navires correspondants aux filtres saisies" />
1
0
[Suiviobsmer-commits] r547 - in trunk/wao-business/src/main: java/fr/ifremer/wao java/fr/ifremer/wao/entity java/fr/ifremer/wao/service resources/i18n xmi
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
by fdesbois@users.labs.libre-entreprise.org 18 Jun '10
18 Jun '10
Author: fdesbois
Date: 2010-06-18 08:16:29 +0000 (Fri, 18 Jun 2010)
New Revision: 547
Log:
Evo #2336 : Add filter for shipOwnerName
Modified:
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties
trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties
trunk/wao-business/src/main/xmi/wao.zargo
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-17 15:17:21 UTC (rev 546)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-18 08:16:29 UTC (rev 547)
@@ -3,7 +3,6 @@
import fr.ifremer.wao.bean.*;
import fr.ifremer.wao.entity.*;
import org.apache.commons.lang.StringUtils;
-import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.PeriodDates;
@@ -12,6 +11,9 @@
import java.util.*;
+//import static fr.ifremer.wao.TopiaQueryExtra.$;
+//import static fr.ifremer.wao.TopiaQueryExtra.$P;
+
/**
* Created: 7 juin 2010
*
@@ -34,6 +36,8 @@
public static String ALIAS_ACTIVITY_CALENDAR = "AC";
+ public static String ALIAS_SHIP_OWNER = "SO";
+
String sampleRowProperty;
String fishingZoneProperty;
@@ -42,6 +46,8 @@
String contactProperty;
+ String shipOwnerProperty;
+
String elligibleBoatProperty;
protected TopiaQuery query;
@@ -70,6 +76,10 @@
} else if (Contact.class.isAssignableFrom(entityClass)) {
contactProperty = ALIAS_CONTACT;
query = createQuery(Contact.class, contactProperty);
+
+ } else if (ShipOwner.class.isAssignableFrom(entityClass)) {
+ shipOwnerProperty = ALIAS_SHIP_OWNER;
+ query = createQuery(ShipOwner.class, shipOwnerProperty);
}
}
@@ -93,6 +103,13 @@
return sampleRowProperty;
}
+ public String getShipOwnerProperty() {
+ if (StringUtils.isNotEmpty(boatProperty)) {
+ shipOwnerProperty = getProperty(boatProperty, Boat.SHIP_OWNER);
+ }
+ return shipOwnerProperty;
+ }
+
public String getSectorNameProperty() {
String result = getProperty(fishingZoneProperty,
FishingZone.SECTOR_NAME);
@@ -439,6 +456,24 @@
return this;
}
+ public WaoQueryBuilder applyShipOwnerFilter(String shipOwnerName) {
+
+ if (StringUtils.isNotEmpty(shipOwnerName)) {
+ String input = '%' + StringUtils.upperCase(shipOwnerName) + '%';
+
+ String firstNameProperty =
+ getProperty(getShipOwnerProperty(), ShipOwner.FIRST_NAME);
+ String lastNameProperty =
+ getProperty(getShipOwnerProperty(), ShipOwner.LAST_NAME);
+
+ query.addWhere(
+ $("$1 LIKE :input OR $2 LIKE :input", firstNameProperty, lastNameProperty)
+ ).addParam("input", input);
+ }
+
+ return this;
+ }
+
/**
* Apply {@code filter} on current query. Used to retrieve boats filtered.
* Need boatProperty to be defined using for example new WaoQueryBuilder(Boat.class)
@@ -455,6 +490,7 @@
String orderBy = filter.getOrderBy();
applySimpleBoatFilter(filter);
+ applyShipOwnerFilter(filter.getShipOwnerName());
// Sampling filter
if (filter.isSamplingFiltered()) {
@@ -474,16 +510,7 @@
// Company
if (company != null) {
// Test only valid ElligibleBoat for that company
-// query.addWhere(new StringBuilder(getElligibleCompanyActiveProperty()).
-// append(" = :booleanTrue ").
-// append("OR (").
-// append(getElligibleCompanyActiveProperty()).
-// append(" IS NULL AND ").
-// append(getElligibleGlobalActiveProperty()).
-// append(" = :booleanTrue)").
-// toString()
-// ).addParam("booleanTrue", Boolean.TRUE);
- query.addWhere(_parse("$1 = :booleanTrue OR ($1 IS NULL AND $2 = :booleanTrue)",
+ query.addWhere($("$1 = :booleanTrue OR ($1 IS NULL AND $2 = :booleanTrue)",
getElligibleCompanyActiveProperty(),
getElligibleGlobalActiveProperty())
).addParam("booleanTrue", Boolean.TRUE);
@@ -543,13 +570,7 @@
// MAMMALS_OBSERVATION and MAMMALS_CAPTURE
if (mammalsObservation && mammalsCapture) {
-// query.addWhere(new StringBuilder(getMammalsObservationProperty()).
-// append(" = :mammals OR ").
-// append(getMammalsCaptureProperty()).
-// append(" = :mammals").
-// toString()
-// ).addParam("mammals", Boolean.TRUE);
- query.addWhere(_parse("$1 = :mammals OR $2 = :mammals",
+ query.addWhere($("$1 = :mammals OR $2 = :mammals",
getMammalsObservationProperty(),
getMammalsCaptureProperty())
).addParam("mammals", Boolean.TRUE);
@@ -604,7 +625,7 @@
return this;
}
- public static String _parse(String statement, String... properties) {
+ public static String $(String statement, String... properties) {
for (int i = 1; i <= properties.length; i++) {
statement = statement.replace("$" + i, properties[i-1]);
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java 2010-06-17 15:17:21 UTC (rev 546)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java 2010-06-18 08:16:29 UTC (rev 547)
@@ -31,7 +31,7 @@
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaQuery.Op;
-import static fr.ifremer.wao.WaoQueryBuilder._parse;
+import static fr.ifremer.wao.WaoQueryBuilder.$;
/**
@@ -73,15 +73,15 @@
// Construct subquery
TopiaQuery subquery = createQuery(subContactAlias).
- setSelect(_parse("MAX($1)", subCreateDateProperty)).
- addWhere(_parse("$1 = $2", subBoatProperty ,mainBoatProperty)).
+ setSelect($("MAX($1)", subCreateDateProperty)).
+ addWhere($("$1 = $2", subBoatProperty ,mainBoatProperty)).
addEquals(subCompanyProperty, company);
// Construct mainquery
TopiaQuery query = createQuery(mainContactAlias).
addEquals(mainBoatProperty, boat).
addEquals(mainCompanyProperty, company).
- addSubQuery(_parse("$1 = (?)", mainCreateDateProperty), subquery);
+ addSubQuery($("$1 = (?)", mainCreateDateProperty), subquery);
return query;
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-17 15:17:21 UTC (rev 546)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-18 08:16:29 UTC (rev 547)
@@ -59,6 +59,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static fr.ifremer.wao.WaoQueryBuilder.$;
+
/**
* ServiceBoatImpl
*
@@ -311,6 +313,27 @@
return boatNames;
}
+ @Override
+ public List<String> executeGetShipOwnerNamesContains(TopiaContext transaction,
+ String shipOwnerName)
+ throws TopiaException {
+
+ ShipOwnerDAO dao = WaoDAOHelper.getShipOwnerDAO(transaction);
+
+ TopiaQuery query = dao.createQuery().
+ addDistinct().
+ setSelect($("CONCAT(CONCAT($1,' '), $2)",
+ ShipOwner.FIRST_NAME,
+ ShipOwner.LAST_NAME)
+ );
+
+ new WaoQueryBuilder(query).applyShipOwnerFilter(shipOwnerName);
+
+ List<String> shipOwnerNames = transaction.findByQuery(query);
+
+ return shipOwnerNames;
+ }
+
/**
* Import boats from a CSV file. Warning, must be UTF-8 encoding.
* Use of CsvReader to manage InputStream and create or update boats.
Modified: trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties
===================================================================
--- trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-06-17 15:17:21 UTC (rev 546)
+++ trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-06-18 08:16:29 UTC (rev 547)
@@ -22,6 +22,7 @@
wao.error.serviceBoat.getCompanyBoatInfos=
wao.error.serviceBoat.getLastActivityCalendar=
wao.error.serviceBoat.getNbBoatsByFilter=
+wao.error.serviceBoat.getShipOwnerNamesContains=
wao.error.serviceBoat.importActivityCalendarCsv=
wao.error.serviceBoat.importBoatCsv=
wao.error.serviceContact.exportContactCsv=
Modified: trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties
===================================================================
--- trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-06-17 15:17:21 UTC (rev 546)
+++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-06-18 08:16:29 UTC (rev 547)
@@ -21,6 +21,7 @@
wao.error.serviceBoat.getCompanyBoatInfos=Impossible de r\u00E9cup\u00E9rer les informations du navire immatricul\u00E9 %1$d pour la soci\u00E9t\u00E9 %2$s
wao.error.serviceBoat.getLastActivityCalendar=Impossible de charger le dernier calendrier d'activit\u00E9 du navire %1$s (%2$d)
wao.error.serviceBoat.getNbBoatsByFilter=Impossible de filtrer la liste des navires
+wao.error.serviceBoat.getShipOwnerNamesContains=
wao.error.serviceBoat.importActivityCalendarCsv=Probl\u00E8me d'import du fichier CSV des calendriers d'activit\u00E9
wao.error.serviceBoat.importBoatCsv=Probl\u00E8me d'import du fichier CSV. V\u00E9rifiez l'en-t\u00EAte du fichier \: [ NAVS_COD,CARN_NOM,CARN_LONGUEUR_HT,CARN_ANNEE,QUARTIER_IMMA,PER_COD,PER_NOM,PER_PRENOM,NAVS_ACTIVE ]. Voir documentation pour plus de d\u00E9tails.
wao.error.serviceContact.exportContactCsv=Impossible d'exporter les contacts
Modified: trunk/wao-business/src/main/xmi/wao.zargo
===================================================================
(Binary files differ)
1
0
[Suiviobsmer-commits] r546 - in trunk/wao-ui/src/main: java/fr/ifremer/wao/ui/pages webapp
by fdesbois@users.labs.libre-entreprise.org 17 Jun '10
by fdesbois@users.labs.libre-entreprise.org 17 Jun '10
17 Jun '10
Author: fdesbois
Date: 2010-06-17 15:17:21 +0000 (Thu, 17 Jun 2010)
New Revision: 546
Log:
Evo #2334 : Add text for inactive boat
Modified:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java
trunk/wao-ui/src/main/webapp/Boats.tml
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-17 15:09:46 UTC (rev 545)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-17 15:17:21 UTC (rev 546)
@@ -524,6 +524,10 @@
return result;
}
+ public String getBoatInactive() {
+ return !boat.getActive() ? "(inactif)" : "";
+ }
+
public DateFormat getDateFormat() {
return new SimpleDateFormat("dd/MM/yyyy");
}
Modified: trunk/wao-ui/src/main/webapp/Boats.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/Boats.tml 2010-06-17 15:09:46 UTC (rev 545)
+++ trunk/wao-ui/src/main/webapp/Boats.tml 2010-06-17 15:17:21 UTC (rev 546)
@@ -156,7 +156,7 @@
<img src="${asset:context:}/img/contact-22px.png" title="Créer un nouveau contact pour ce navire et la ligne sélectionnée dans les filtres"/>
</a>
</t:if>
- <a t:type="actionlink" t:id="showBoatInfos" t:context="boat.immatriculation" t:zone="boatsZone">${boat.name}</a>
+ <a t:type="actionlink" t:id="showBoatInfos" t:context="boat.immatriculation" t:zone="boatsZone">${boat.name}</a> ${boatInactive}
</p:nameCell>
<p:boatLengthCell>
${boat.boatLength} m
1
0
[Suiviobsmer-commits] r545 - trunk/wao-ui/src/main/webapp/js
by fdesbois@users.labs.libre-entreprise.org 17 Jun '10
by fdesbois@users.labs.libre-entreprise.org 17 Jun '10
17 Jun '10
Author: fdesbois
Date: 2010-06-17 15:09:46 +0000 (Thu, 17 Jun 2010)
New Revision: 545
Log:
Evo #2333 : Use proper Javascript NewsHider class to hide news details
Added:
trunk/wao-ui/src/main/webapp/js/NewsHider.js
Added: trunk/wao-ui/src/main/webapp/js/NewsHider.js
===================================================================
--- trunk/wao-ui/src/main/webapp/js/NewsHider.js (rev 0)
+++ trunk/wao-ui/src/main/webapp/js/NewsHider.js 2010-06-17 15:09:46 UTC (rev 545)
@@ -0,0 +1,80 @@
+/**
+ * This class is used to hide news details depends on an anchor. This anchor
+ * must be called 'details' and be surrounded by a paragraph block (<p>) in
+ * the news content. The anchor will be transformed in a clickable link, then
+ * the rest of the news will be hidden using NewsDetails object.
+ */
+NewsHider = Class.create({
+ initialize: function() {
+ this.allNews = $('so-news').select('div.news-content');
+ this.anchorPattern = 'a[name="details"]';
+ },
+ /**
+ * Method to call to hide all news that contains the anchor 'details'
+ */
+ hideAllNewsDetails: function() {
+ for (j = 0; j < this.allNews.length; j++) {
+ this.hideNewsDetails(this.allNews[j]);
+ }
+ },
+ /**
+ * Hide a {news} if contains an anchor called 'details'. A NewsDetails object
+ * will be instantiate to transform the anchor found and hide the rest of
+ * the news in a hiddenBlock.
+ */
+ hideNewsDetails: function(news) {
+ // Select all paragraphs in the news
+ var paragraphs = news.select('p');
+ //Tapestry.debug('nb paragraphs in news : ' + paragraphs.length);
+
+ for (i = 0; i < paragraphs.length; i++) {
+ var paragraph = paragraphs[i];
+
+ // Check the firstDescendant in the paragraph, we take only anchor called 'details'
+ if (paragraph.firstDescendant() && paragraph.firstDescendant().match(this.anchorPattern)) {
+ var anchor = paragraph.firstDescendant();
+
+ //Tapestry.debug('Find anchor !');
+
+ // paragraphs to hide are the next siblings of current paragraph
+ var paragraphsToHide = paragraph.nextSiblings();
+
+ var details = new NewsDetails(anchor, paragraphsToHide);
+
+ // append the hidden block to the news
+ news.appendChild(details.hiddenBlock);
+ break;
+ }
+ }
+ }
+});
+
+/**
+ * This class is used to transform an {anchor} in clickable link to display a
+ * hidden block as news details. The {paragraphsToHide} will be wrapped into
+ * a div hidden element. When user will click on the {anchor}, the hidden
+ * block will be toggled to be displayed or not.
+ */
+NewsDetails = Class.create({
+ initialize: function(anchor, paragraphsToHide) {
+
+ //Tapestry.debug('create NewsDetails');
+
+ // Update params of the anchor to be clickable
+ anchor.update('Lire la suite...');
+ anchor.addClassName('news-details-link');
+ // Bind the click on the anchor with the toggle on hiddenBlock
+ anchor.observe('click', this.toggleDetails.bind(this));
+
+ // Create hidden block
+ this.hiddenBlock = document.createElement('div');
+ this.hiddenBlock.addClassName('hidden');
+
+ for (i = 0; i < paragraphsToHide.length; i++) {
+ this.hiddenBlock.appendChild(paragraphsToHide[i]);
+ }
+ },
+ toggleDetails: function(event) {
+ this.hiddenBlock.toggleClassName('hidden');
+ }
+});
\ No newline at end of file
1
0