[Suiviobsmer-commits] r492 - in trunk: . wao-business/src/main/java/fr/ifremer/wao/bean wao-business/src/main/java/fr/ifremer/wao/entity wao-business/src/main/java/fr/ifremer/wao/io wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/xmi wao-business/src/test/java/fr/ifremer/wao/service wao-ui/src/main/java/fr/ifremer/wao/ui/base wao-ui/src/main/java/fr/ifremer/wao/ui/data wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/resources/fr/ifremer/wao/ui/components wao-ui/src/main/
Author: fdesbois Date: 2010-06-07 18:36:10 +0000 (Mon, 07 Jun 2010) New Revision: 492 Log: Evo #2227 : Add Guest profile. Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/GenericSelectModel.java Removed: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/GenericSelectModel.java Modified: trunk/pom.xml trunk/wao-business/src/main/java/fr/ifremer/wao/bean/UserRole.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/WaoUserImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/io/ExportHelper.java trunk/wao-business/src/main/java/fr/ifremer/wao/io/SamplingExport.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/AbstractFilteredPage.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/RequiresAuthentication.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/BoatActivityCalendar.java 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/Index.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/pages/Administration.properties trunk/wao-ui/src/main/webapp/SamplingPlan.tml trunk/wao-ui/src/main/webapp/css/common.css trunk/wao-ui/src/main/webapp/css/main.css Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/pom.xml 2010-06-07 18:36:10 UTC (rev 492) @@ -235,8 +235,10 @@ <!-- libraries version --> <i18n.version>1.2.2</i18n.version> <nuitonutils.version>1.2.2</nuitonutils.version> - <topia.version>2.4-SNAPSHOT</topia.version> - <eugene.version>2.0.2-SNAPSHOT</eugene.version> + <topia.version>2.3.3</topia.version> + <eugene.version>2.0.1</eugene.version> + <!--<topia.version>2.4-SNAPSHOT</topia.version>--> + <!--<eugene.version>2.0.2-SNAPSHOT</eugene.version>--> <tapestry.version>5.1.0.5</tapestry.version> </properties> Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/UserRole.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/UserRole.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/UserRole.java 2010-06-07 18:36:10 UTC (rev 492) @@ -38,7 +38,9 @@ /** User/observer role **/ OBSERVER("Observateur"), /** Coordinator role **/ - COORDINATOR("Coordinateur"); + COORDINATOR("Coordinateur"), + /** Guest role **/ + GUEST("Invité"); private String libelle; Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/WaoUserImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/WaoUserImpl.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/WaoUserImpl.java 2010-06-07 18:36:10 UTC (rev 492) @@ -83,6 +83,11 @@ } @Override + public boolean isGuest() { + return getUserRole().equals(UserRole.GUEST); + } + + @Override public UserRole getUserRole() { return UserRole.valueOf(getRole()); } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/ExportHelper.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/io/ExportHelper.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/ExportHelper.java 2010-06-07 18:36:10 UTC (rev 492) @@ -27,6 +27,9 @@ import com.csvreader.CsvWriter; import fr.ifremer.wao.io.WaoCsvHeader.IOHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.IOException; /** @@ -58,6 +61,8 @@ */ public abstract class ExportHelper<H extends IOHeader> { + private static final Logger logger = LoggerFactory.getLogger(ExportHelper.class); + /** Writer used to record data **/ protected CsvWriter writer; @@ -82,7 +87,7 @@ /** * Record a value for a header corresponding to the H generic type from - * {@link WaoCsvReader } class. + * {@link IOHeader} class. * * @param header IOHeader used to record the value (column in the file) * @param value the value to record @@ -91,7 +96,7 @@ /** * Return the header String value based on index. All matching integers for - * headers are defined in {@link WaoCsvReader } class. + * headers are defined in {@link IOHeader} class. * * @param index of the header * @return the String value of the header @@ -108,7 +113,25 @@ */ public void writeHeaders() throws IOException { for (int i = 0; i < nbHeaders; i++) { + // Always use "" for headers +// String header = null; +// +// if (i == 0) { +// header = new StringBuilder("\""). +// append(getHeaderValue(i)). +// append("\""). +// toString(); +// } else { +// header = getHeaderValue(i); +// } +// +// if (logger.isDebugEnabled()) { +// logger.debug("Header " + i + " : " + getHeaderValue(i)); +// logger.debug("Header " + i + " with StringBuilder : " + header); +// } + String header = getHeaderValue(i); + writer.write(header); } writer.endRecord(); Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/SamplingExport.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/io/SamplingExport.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/SamplingExport.java 2010-06-07 18:36:10 UTC (rev 492) @@ -110,9 +110,10 @@ String real = String.valueOf(sampleMonth.getRealTidesValue()); // The admin as only expected value (to be the same as // in import) - if (user.isAdmin()) { - record(index, expected); //record[index] = expected; - // The user as both expected and real values + // Evo #2227 : Guest users have only access to expected values + if (user.isAdmin() || user.isGuest()) { + record(index, expected); + // Other users have both expected and real values } else { record(index, expected + " (" + real + ")"); } 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-07 13:51:31 UTC (rev 491) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-06-07 18:36:10 UTC (rev 492) @@ -315,8 +315,7 @@ @Override public FacadeRow executeGetSampleRowsOrderedByFishingZone( - TopiaContext transaction, - SamplingFilter filter, Company company) + TopiaContext transaction, SamplingFilter filter) throws TopiaException { FacadeRow result = new FacadeRowImpl(); result.setEstimatedTides(filter.getEstimatedTides()); @@ -324,23 +323,46 @@ SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); - TopiaQuery query = dao.createQuery("S").addDistinct(). - addFrom(FishingZone.class, "Z"). - add("S IN elements(Z." + FishingZone.SAMPLE_ROW + ")"); + // FishingZone properties + String fishingZoneAlias = "Z"; + String fishingZoneFacadeProperty = + TopiaQuery.getProperty(fishingZoneAlias, FishingZone.FACADE_NAME); + String fishingZoneSectorProperty = + TopiaQuery.getProperty(fishingZoneAlias, FishingZone.SECTOR_NAME); + String fishingZoneDistrictProperty = + TopiaQuery.getProperty(fishingZoneAlias, FishingZone.DISTRICT_CODE); + String fishingZoneSampleRowProperty = + TopiaQuery.getProperty(fishingZoneAlias, FishingZone.SAMPLE_ROW); - filter.prepareQueryForSampling(query, "S", "Z"); + // SampleRow properties + String sampleRowAlias = "S"; + String sampleRowCodeProperty = + TopiaQuery.getProperty(sampleRowAlias, SampleRow.CODE); - if (company != null) { - query.add("S." + SampleRow.COMPANY, company); - } + // Query + TopiaQuery query = dao.createQuery(sampleRowAlias).addDistinct(). + addFrom(FishingZone.class, fishingZoneAlias). + // TODO-fdesbois-2010-06-07 for ToPIA 2.4 : replace this statement by addInElements + add(sampleRowAlias + " IN elements(" + fishingZoneSampleRowProperty + ")"); + filter.prepareQueryForSampling(query, sampleRowAlias, fishingZoneAlias); + + // Company is now a part of filter and will be set in previous method +// if (company != null) { +// query.add("S." + SampleRow.COMPANY, company); +// } + // Order By facade, sector, districtCode, sampleRowCode - String zoneOrder = "Z." + FishingZone.FACADE_NAME + " , " + - "Z." + FishingZone.SECTOR_NAME + ", " + - "Z." + FishingZone.DISTRICT_CODE; - query.addOrder(zoneOrder, "S." + SampleRow.CODE). - addSelect(zoneOrder); + query.addOrder(fishingZoneFacadeProperty, + fishingZoneSectorProperty, + fishingZoneDistrictProperty, + sampleRowCodeProperty). + // Need fishingZone properties in Select to use them in orderBy + addSelect(fishingZoneFacadeProperty, + fishingZoneSectorProperty, + fishingZoneDistrictProperty); + if (log.isDebugEnabled()) { log.debug("Query : " + query); } @@ -572,7 +594,8 @@ SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); TopiaQuery query = dao.createQuery("S"); - if (!user.isAdmin()) { + // Evo #2227 : No filter on company for GUEST users, all samplingPlan can be exported + if (!user.isAdmin() && !user.isGuest()) { query.add("S." + SampleRow.COMPANY, user.getCompany()); } @@ -596,7 +619,9 @@ export.record(SAMPLING.PLAN_CODE, row.getCode()); Company company = row.getCompany(); - if (company != null) { + + // Evo #2227 : Guest users don't have access to companyName + if (company != null && !user.isGuest()) { export.record(SAMPLING.SOCIETE_NOM, company.getName()); } @@ -632,28 +657,6 @@ export.recordMonths(row); -// for (int i = 0; i < monthHeaders.size(); i++) { -// // Get date from monthHeaders list -// Date month = dateFormat.parse(monthHeaders.get(i)); -// // Retrieve sampleMonth corresponding -// SampleMonth sampleMonth = row.getSampleMonth(month); -// // Add it to the file if it exists -// if (sampleMonth != null) { -// // Prepare index for record -// int index = SAMPLING.getStartIndexForMonths() + i; -// String expected = String.valueOf(sampleMonth.getExpectedTidesValue()); -// String real = String.valueOf(sampleMonth.getRealTidesValue()); -// // The admin as only expected value (to be the same as -// // in import) -// if (user.getAdmin()) { -// export.record(index, expected); //record[index] = expected; -// // The user as both expected and real values -// } else { -// export.record(index, expected + " (" + real + ")"); -// } -// } -// } - export.writeRecord(); } @@ -857,7 +860,6 @@ * @throws IOException for CsvReader errors * @throws TopiaException for SampleMonthDAO errors * @throws ParseException for format errors - * @see #getMonthAndYear(java.lang.String) */ protected void updateRow(TopiaContext transaction, SampleRow sampleRow, CsvReader reader) throws IOException, TopiaException, ParseException { Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2010-06-07 18:36:10 UTC (rev 492) @@ -263,7 +263,7 @@ SamplingFilter filter = new SamplingFilterImpl(); filter.setPeriod(new PeriodDates(begin, end)); // RESULT : [2010_0002, 2010_0004, 2010_0001, 2010_0003] - FacadeRow facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter, null); + FacadeRow facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter); List<SampleRow> rows = facade.getValues(); assertEquals(4, rows.size()); SampleRow resultRow0 = rows.get(0); @@ -293,7 +293,7 @@ end = new GregorianCalendar(2020, 11, 31, 0, 0, 0); filter.setPeriod(new PeriodDates(begin, end)); // RESULT : [2010_0002, 2010_0004, 2010_0001] - facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter, null); + facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter); rows = facade.getValues(); assertEquals(3, rows.size()); resultRow0 = rows.get(0); 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-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/AbstractFilteredPage.java 2010-06-07 18:36:10 UTC (rev 492) @@ -36,6 +36,8 @@ import fr.ifremer.wao.service.ServiceUser; import java.util.ArrayList; import java.util.List; + +import fr.ifremer.wao.ui.data.GenericSelectModel; import org.apache.tapestry5.OptionModel; import org.apache.tapestry5.SelectModel; import org.apache.tapestry5.annotations.Persist; @@ -142,7 +144,8 @@ */ public void initCompanyFilter() { // Very very important to do that at beginning - if (!user.isAdmin()) { + // Evo #2227 : Guest user has no default company filter + if (!user.isAdmin() && !user.isGuest()) { if (log.isDebugEnabled()) { log.debug("Company filtered : " + user.getCompany().getName()); } Deleted: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/GenericSelectModel.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/GenericSelectModel.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/GenericSelectModel.java 2010-06-07 18:36:10 UTC (rev 492) @@ -1,163 +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.base; - -import java.util.ArrayList; -import java.util.List; - -import java.util.Map; -import org.apache.tapestry5.OptionGroupModel; -import org.apache.tapestry5.OptionModel; -import org.apache.tapestry5.internal.OptionGroupModelImpl; -import org.apache.tapestry5.internal.OptionModelImpl; -import org.apache.tapestry5.ioc.annotations.Inject; -import org.apache.tapestry5.ioc.services.PropertyAccess; -import org.apache.tapestry5.ioc.services.PropertyAdapter; -import org.apache.tapestry5.util.AbstractSelectModel; -import org.slf4j.Logger; - -/** - * GenericSelectModel.java - * - * Based on IdSelectModel from <http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/select/easyid> - * A generic selection model whose value is the id of the chosen object, not the object itself. - * - * @param <T> - * @author fdesbois <fdesbois at codelutin.com> - */ -public class GenericSelectModel<T> extends AbstractSelectModel { - - private List<T> list; - private Map<String, List<T>> map; - private PropertyAdapter labelFieldAdapter; - private PropertyAdapter idFieldAdapter; - - @Inject - private Logger log; - - /** - * @param list the list of objects you want modeled in a Select component. These objects MUST implement - * equals(Object obj) and hashCode(). If the objects are JPA entities, ensure their implementations of - * equals(Object obj) and hashCode() return the same thing for different instances of the same detached - * entity. - * @param clazz the class of objects in the list. - * @param labelField the name of the field you want displayed as the label in the selection list, eg. "name". - * @param idField the name of the field which is the unique identifier of each object in the list, eg. "id". This is - * used in the value property of the Select component. - * @param access Declare a PropertyAccess injected into your page (eg. Inject private PropertyAccess _access) then pass it in here. - * - */ - public GenericSelectModel(List<T> list, Class<T> clazz, String labelField, String idField, PropertyAccess access) { - init(clazz, labelField, idField, access); - - this.list = list; - } - - public GenericSelectModel(Map<String, List<T>> map, Class<T> clazz, String labelField, String idField, PropertyAccess access) { - init(clazz, labelField, idField, access); - - this.map = map; - } - - private void init(Class<T> clazz, String labelField, String idField, PropertyAccess access) { - if (clazz == null) { - throw new IllegalArgumentException("clazz is required."); - } - if (idField == null) { - throw new IllegalArgumentException("idField is required."); - } - if (labelField == null) { - throw new IllegalArgumentException("labelField is required."); - } - - this.idFieldAdapter = access.getAdapter(clazz).getPropertyAdapter(idField); - this.labelFieldAdapter = access.getAdapter(clazz).getPropertyAdapter(labelField); - - if (idFieldAdapter == null) { - throw new IllegalArgumentException("idField " + idField + " does not exist in class " + clazz + "."); - } - if (labelFieldAdapter == null) { - throw new IllegalArgumentException("labelField " + idField + " does not exist in class " + clazz + "."); - } - } - - @Override - public List<OptionGroupModel> getOptionGroups() { - if (list != null) { - return null; - } - List<OptionGroupModel> optionGroupModelList = new ArrayList<OptionGroupModel>(); - for (String key : map.keySet()) { - optionGroupModelList.add(new OptionGroupModelImpl(key, false, getOptions(map.get(key)))); - } - return optionGroupModelList; - } - - @Override - public List<OptionModel> getOptions() { - if (map != null) { - return null; - } - return getOptions(list); - } - - private List<OptionModel> getOptions(List<T> list) { - List<OptionModel> optionModelList = new ArrayList<OptionModel>(); - for (T obj : list) { - optionModelList.add(new OptionModelImpl(nvl(labelFieldAdapter.get(obj)), idFieldAdapter.get(obj))); - } - return optionModelList; - } - - public List<T> getList() { - List<T> results; - if (map != null) { - results = new ArrayList<T>(); - for (String key : map.keySet()) { - results.addAll(map.get(key)); - } - } else { - results = list; - } - return results; - } - - public T findObject(String id) { - if (id != null) { - for (T current : getList()) { - Object currentId = idFieldAdapter.get(current); - if (currentId.equals(id)) { - return current; - } - } - } - return null; - } - - private String nvl(Object o) { - return o == null ? "" : o.toString(); - } -} - Copied: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/GenericSelectModel.java (from rev 490, trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/base/GenericSelectModel.java) =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/GenericSelectModel.java (rev 0) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/GenericSelectModel.java 2010-06-07 18:36:10 UTC (rev 492) @@ -0,0 +1,163 @@ +/* + * #%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 java.util.ArrayList; +import java.util.List; + +import java.util.Map; +import org.apache.tapestry5.OptionGroupModel; +import org.apache.tapestry5.OptionModel; +import org.apache.tapestry5.internal.OptionGroupModelImpl; +import org.apache.tapestry5.internal.OptionModelImpl; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.ioc.services.PropertyAccess; +import org.apache.tapestry5.ioc.services.PropertyAdapter; +import org.apache.tapestry5.util.AbstractSelectModel; +import org.slf4j.Logger; + +/** + * GenericSelectModel.java + * + * Based on IdSelectModel from <http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/select/easyid> + * A generic selection model whose value is the id of the chosen object, not the object itself. + * + * @param <T> + * @author fdesbois <fdesbois at codelutin.com> + */ +public class GenericSelectModel<T> extends AbstractSelectModel { + + private List<T> list; + private Map<String, List<T>> map; + private PropertyAdapter labelFieldAdapter; + private PropertyAdapter idFieldAdapter; + + @Inject + private Logger log; + + /** + * @param list the list of objects you want modeled in a Select component. These objects MUST implement + * equals(Object obj) and hashCode(). If the objects are JPA entities, ensure their implementations of + * equals(Object obj) and hashCode() return the same thing for different instances of the same detached + * entity. + * @param clazz the class of objects in the list. + * @param labelField the name of the field you want displayed as the label in the selection list, eg. "name". + * @param idField the name of the field which is the unique identifier of each object in the list, eg. "id". This is + * used in the value property of the Select component. + * @param access Declare a PropertyAccess injected into your page (eg. Inject private PropertyAccess _access) then pass it in here. + * + */ + public GenericSelectModel(List<T> list, Class<T> clazz, String labelField, String idField, PropertyAccess access) { + init(clazz, labelField, idField, access); + + this.list = list; + } + + public GenericSelectModel(Map<String, List<T>> map, Class<T> clazz, String labelField, String idField, PropertyAccess access) { + init(clazz, labelField, idField, access); + + this.map = map; + } + + private void init(Class<T> clazz, String labelField, String idField, PropertyAccess access) { + if (clazz == null) { + throw new IllegalArgumentException("clazz is required."); + } + if (idField == null) { + throw new IllegalArgumentException("idField is required."); + } + if (labelField == null) { + throw new IllegalArgumentException("labelField is required."); + } + + this.idFieldAdapter = access.getAdapter(clazz).getPropertyAdapter(idField); + this.labelFieldAdapter = access.getAdapter(clazz).getPropertyAdapter(labelField); + + if (idFieldAdapter == null) { + throw new IllegalArgumentException("idField " + idField + " does not exist in class " + clazz + "."); + } + if (labelFieldAdapter == null) { + throw new IllegalArgumentException("labelField " + idField + " does not exist in class " + clazz + "."); + } + } + + @Override + public List<OptionGroupModel> getOptionGroups() { + if (list != null) { + return null; + } + List<OptionGroupModel> optionGroupModelList = new ArrayList<OptionGroupModel>(); + for (String key : map.keySet()) { + optionGroupModelList.add(new OptionGroupModelImpl(key, false, getOptions(map.get(key)))); + } + return optionGroupModelList; + } + + @Override + public List<OptionModel> getOptions() { + if (map != null) { + return null; + } + return getOptions(list); + } + + private List<OptionModel> getOptions(List<T> list) { + List<OptionModel> optionModelList = new ArrayList<OptionModel>(); + for (T obj : list) { + optionModelList.add(new OptionModelImpl(nvl(labelFieldAdapter.get(obj)), idFieldAdapter.get(obj))); + } + return optionModelList; + } + + public List<T> getList() { + List<T> results; + if (map != null) { + results = new ArrayList<T>(); + for (String key : map.keySet()) { + results.addAll(map.get(key)); + } + } else { + results = list; + } + return results; + } + + public T findObject(String id) { + if (id != null) { + for (T current : getList()) { + Object currentId = idFieldAdapter.get(current); + if (currentId.equals(id)) { + return current; + } + } + } + return null; + } + + private String nvl(Object o) { + return o == null ? "" : o.toString(); + } +} + Property changes on: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/GenericSelectModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/RequiresAuthentication.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/RequiresAuthentication.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/RequiresAuthentication.java 2010-06-07 18:36:10 UTC (rev 492) @@ -24,7 +24,7 @@ // By default everybody can access UserRole[] value() default - {UserRole.OBSERVER, UserRole.ADMIN, UserRole.COORDINATOR}; + {UserRole.OBSERVER, UserRole.ADMIN, UserRole.COORDINATOR, UserRole.GUEST}; boolean readOnlyAllowed() default true; } 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-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-07 18:36:10 UTC (rev 492) @@ -34,7 +34,7 @@ import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.service.ServiceReferential; import fr.ifremer.wao.service.ServiceUser; -import fr.ifremer.wao.ui.base.GenericSelectModel; +import fr.ifremer.wao.ui.data.GenericSelectModel; import fr.ifremer.wao.ui.components.Layout; import fr.ifremer.wao.ui.data.RequiresAuthentication; import fr.ifremer.wao.ui.services.WaoManager; Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/BoatActivityCalendar.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/BoatActivityCalendar.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/BoatActivityCalendar.java 2010-06-07 18:36:10 UTC (rev 492) @@ -27,6 +27,7 @@ import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoException; +import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.ActivityCalendar; import fr.ifremer.wao.entity.ActivityMonth; import fr.ifremer.wao.entity.ActivityProfession; @@ -55,7 +56,7 @@ * * @author fdesbois <fdesbois at codelutin.com> */ - at RequiresAuthentication + at RequiresAuthentication({UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER}) @IncludeStylesheet("context:css/boats.css") public class BoatActivityCalendar { 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-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-07 18:36:10 UTC (rev 492) @@ -27,11 +27,8 @@ import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.bean.BoatFilterImpl; +import fr.ifremer.wao.bean.*; import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.bean.BoatFilter; -import fr.ifremer.wao.bean.CompanyBoatInfos; -import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.entity.BoatInfos; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.Contact; @@ -44,13 +41,10 @@ import fr.ifremer.wao.service.ServiceSampling; import fr.ifremer.wao.service.ServiceUser; import fr.ifremer.wao.ui.base.AbstractFilteredPage; -import fr.ifremer.wao.ui.data.BusinessUtils; -import fr.ifremer.wao.ui.base.GenericSelectModel; +import fr.ifremer.wao.ui.data.*; +import fr.ifremer.wao.ui.data.GenericSelectModel; 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.ExportStreamResponse; -import fr.ifremer.wao.ui.data.RequiresAuthentication; import fr.ifremer.wao.ui.services.WaoManager; import java.io.FileNotFoundException; import java.io.IOException; @@ -92,7 +86,7 @@ * * @author fdesbois <fdesbois at codelutin.com> */ - at RequiresAuthentication + at RequiresAuthentication({UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER}) @IncludeStylesheet("context:css/boats.css") public class Boats extends AbstractFilteredPage { 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-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-06-07 18:36:10 UTC (rev 492) @@ -40,12 +40,9 @@ import fr.ifremer.wao.service.ServiceContact; import fr.ifremer.wao.service.ServiceUser; import fr.ifremer.wao.ui.base.AbstractFilteredPage; -import fr.ifremer.wao.ui.data.ContactDataSource; -import fr.ifremer.wao.ui.data.BusinessUtils; -import fr.ifremer.wao.ui.base.GenericSelectModel; +import fr.ifremer.wao.ui.data.*; +import fr.ifremer.wao.ui.data.GenericSelectModel; import fr.ifremer.wao.ui.components.Layout; -import fr.ifremer.wao.ui.data.ExportStreamResponse; -import fr.ifremer.wao.ui.data.RequiresAuthentication; import fr.ifremer.wao.ui.services.ContactModelFactory; import fr.ifremer.wao.ui.services.WaoManager; import java.io.IOException; @@ -84,7 +81,7 @@ * * @author fdesbois <fdesbois at codelutin.com> */ - at RequiresAuthentication + at RequiresAuthentication({UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER}) @IncludeStylesheet("context:css/contacts.css") public class Contacts extends AbstractFilteredPage { Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Index.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Index.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Index.java 2010-06-07 18:36:10 UTC (rev 492) @@ -26,6 +26,7 @@ package fr.ifremer.wao.ui.pages; import fr.ifremer.wao.WaoException; +import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.News; import fr.ifremer.wao.entity.NewsImpl; import fr.ifremer.wao.entity.WaoUser; Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2010-06-07 18:36:10 UTC (rev 492) @@ -41,7 +41,7 @@ import fr.ifremer.wao.service.ServiceReferential; import fr.ifremer.wao.service.ServiceSampling; import fr.ifremer.wao.service.ServiceUser; -import fr.ifremer.wao.ui.base.GenericSelectModel; +import fr.ifremer.wao.ui.data.GenericSelectModel; import fr.ifremer.wao.ui.data.RequiresAuthentication; import fr.ifremer.wao.ui.data.WaoPropertyChangeListener; import fr.ifremer.wao.ui.services.WaoManager; 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-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-06-07 18:36:10 UTC (rev 492) @@ -27,10 +27,7 @@ import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.bean.FacadeRow; -import fr.ifremer.wao.bean.ImportResults; -import fr.ifremer.wao.bean.SamplingFilter; -import fr.ifremer.wao.bean.SamplingFilterImpl; +import fr.ifremer.wao.bean.*; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.FishingZone; import fr.ifremer.wao.entity.SampleMonth; @@ -178,12 +175,6 @@ private boolean reset; -// @Property -// private Date periodBegin; -// -// @Property -// private Date periodEnd; - public PeriodDates getPeriod() { return getFilter().getPeriod(); } @@ -226,15 +217,9 @@ reset = true; } -// void onSuccessFromPeriodForm() { -// // Reset data -// data = null; -// } Object onSuccessFromFiltersForm() { if (isEdited()) { - // Reset data -// data = null; return filtersZone.getBody(); } if (reset) { @@ -303,14 +288,9 @@ * @throws WaoException */ public List<SampleRow> getData() throws WaoException { - if (data == null) { - Company company = null; - if (!user.isAdmin()) { - company = user.getCompany(); - } + if (data == null) { FacadeRow facade = - serviceSampling.getSampleRowsOrderedByFishingZone( - getFilter(), company); + serviceSampling.getSampleRowsOrderedByFishingZone(getFilter()); data = facade.getValues(); } return data; @@ -395,33 +375,11 @@ return validMonth && getNbTidesReal() != null; } -// public int getTotalTidesExpected() { -// long start = System.currentTimeMillis(); -// int total = 0; -// for (Date currentMonth : getMonths()) { -// SampleMonth sampleMonth = row.getSampleMonth(currentMonth); -// if (sampleMonth != null) { -// total += sampleMonth.getExpectedTidesValue(); -// } -// } -// long stop = System.currentTimeMillis(); -// totalTidesExpectedTime += (stop - start); -// return total; -// } -// -// public int getTotalTidesReal() { -// long start = System.currentTimeMillis(); -// int total = 0; -// for (Date currentMonth : getMonths()) { -// SampleMonth sampleMonth = row.getSampleMonth(currentMonth); -// if (sampleMonth != null) { -// total += sampleMonth.getRealTidesValue(); -// } -// } -// long stop = System.currentTimeMillis(); -// totalTidesRealTime += (stop - start); -// return total; -// } + public boolean canDisplayTidesReal() { + // Evo #2227 : Guest users can't have access to real tides values + boolean result = hasNbTidesReal() && !user.isGuest(); + return result; + } public String getTotalPercentage() { double result = 0; @@ -528,7 +486,7 @@ serviceSampling.deleteSampleRow(row); } - public boolean canAccessBoats() { + public boolean isRowNotFinished() { // Test if the row isFinished with a gap of 1 month (today - 1 month) return !row.isFinished(-1); } 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-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-06-07 18:36:10 UTC (rev 492) @@ -26,12 +26,7 @@ package fr.ifremer.wao.ui.pages; import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.bean.BoardingResult; -import fr.ifremer.wao.bean.ContactState; -import fr.ifremer.wao.bean.ContactStateStatistics; -import fr.ifremer.wao.bean.ContactAverageReactivity; -import fr.ifremer.wao.bean.SamplingFilter; -import fr.ifremer.wao.bean.SamplingFilterImpl; +import fr.ifremer.wao.bean.*; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.service.ServiceSynthesis; @@ -73,7 +68,7 @@ * * @author fdesbois <fdesbois at codelutin.com> */ - at RequiresAuthentication + at RequiresAuthentication({UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER}) @IncludeStylesheet("context:css/synthesis.css") public class Synthesis extends AbstractFilteredPage { 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-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml 2010-06-07 18:36:10 UTC (rev 492) @@ -86,17 +86,33 @@ Plan d'Echantillonnage </li> <li class="sep"> </li> - <li class="link${adminClass} ${boatsSelected}" onclick="location.href='${contextPath}/boats'" title="Liste des navires"> - Navires - </li> - <li class="sep"> </li> - <li class="link${adminClass} ${contactsSelected}" onclick="location.href='${contextPath}/contacts'" title="Liste des contacts"> - Contacts - </li> - <li class="sep"> </li> - <li class="link${adminClass} ${synthesisSelected}" onclick="location.href='${contextPath}/synthesis'" title="Synthèses et indicateurs"> - Synthèse - </li> + <t:unless t:test="currentUser.guest"> + <li class="link${adminClass} ${boatsSelected}" onclick="location.href='${contextPath}/boats'" title="Liste des navires"> + Navires + </li> + <li class="sep"> </li> + <li class="link${adminClass} ${contactsSelected}" onclick="location.href='${contextPath}/contacts'" title="Liste des contacts"> + Contacts + </li> + <li class="sep"> </li> + <li class="link${adminClass} ${synthesisSelected}" onclick="location.href='${contextPath}/synthesis'" title="Synthèses et indicateurs"> + Synthèse + </li> + <p:else> + <!-- Menu disabled for Guest user --> + <li class="disabled" title="Liste des navires"> + Navires + </li> + <li class="sep"> </li> + <li class="disabled" title="Liste des contacts"> + Contacts + </li> + <li class="sep"> </li> + <li class="disabled" title="Synthèses et indicateurs"> + Synthèse + </li> + </p:else> + </t:unless> <t:if t:test="currentUser.admin"> <li class="sep"> </li> <li class="link${adminClass} ${adminSelected}" onclick="location.href='${contextPath}/administration'" title="Administration"> Modified: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/pages/Administration.properties =================================================================== --- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/pages/Administration.properties 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/pages/Administration.properties 2010-06-07 18:36:10 UTC (rev 492) @@ -46,3 +46,4 @@ UserRole.ADMIN: Administrateur UserRole.OBSERVER: Observateur UserRole.COORDINATOR: Coordinateur +UserRole.GUEST: Invit\u00e9 Modified: trunk/wao-ui/src/main/webapp/SamplingPlan.tml =================================================================== --- trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-06-07 18:36:10 UTC (rev 492) @@ -54,18 +54,20 @@ title="Exporter le plan d'échantillonnage du ${dateFormat.format(period.fromDate)} au ${dateFormat.format(period.thruDate)}" /> </a> </span> - <span> - <a t:type="actionlink" t:id="changeFilterEstimatedTides"> - <t:if t:test="filter.estimatedTides"> - <img src="${asset:context:img/samplingPlan-real.png}" alt="Effort d'observations réalisé pour contacts validés" - title="Afficher l'effort d'observations réalisé pour les contacts validés seulement" /> - <p:else> - <img src="${asset:context:img/samplingPlan-estimated.png}" alt="Effort d'observations estimé pour contacts terminés" - title="Afficher l'effort d'observations estimé pour les contacts validés ou non par la société" /> - </p:else> - </t:if> - </a> - </span> + <t:unless t:test="user.guest"> + <span> + <a t:type="actionlink" t:id="changeFilterEstimatedTides"> + <t:if t:test="filter.estimatedTides"> + <img src="${asset:context:img/samplingPlan-real.png}" alt="Effort d'observations réalisé pour contacts validés" + title="Afficher l'effort d'observations réalisé pour les contacts validés seulement" /> + <p:else> + <img src="${asset:context:img/samplingPlan-estimated.png}" alt="Effort d'observations estimé pour contacts terminés" + title="Afficher l'effort d'observations estimé pour les contacts validés ou non par la société" /> + </p:else> + </t:if> + </a> + </span> + </t:unless> <t:if t:test="user.admin"> <span> <a t:type="actionlink" t:id="toggleDisplayMode"> @@ -241,14 +243,17 @@ <t:loop source="months" value="month"> <td class="width50 acenter ${monthCurrentClass}"> ${nbTidesExpected} - <t:if t:test="hasNbTidesReal()"> + <t:if t:test="canDisplayTidesReal()"> <span class="${realTidesClass}"><em>(${nbTidesReal})</em></span> </t:if> </td> </t:loop> <td class="width50 acenter bright"> <span t:type="ck/Tooltip" title="Infos" t:value="Total sur la période du ${dateFormat.format(period.fromDate)} au ${dateFormat.format(period.thruDate)}" t:effect="appear"> - ${row.totalTidesExpected} <em>(${row.totalTidesReal})</em><br /><strong>${totalPercentage}</strong> + ${row.totalTidesExpected} + <t:unless t:test="user.guest"> + <em>(${row.totalTidesReal})</em><br /><strong>${totalPercentage}</strong> + </t:unless> </span> </td> <td class="width60 acenter"><t:output t:value="row.averageTideTime" t:format="numberFormat" /></td> @@ -262,14 +267,16 @@ </td> <!-- Actions --> <td class="${actionsClass} bright"> - <t:if t:test="canAccessBoats()"> - <a t:type="pagelink" t:page="boats" t:context="row.topiaId"> - <img src="${asset:context:}/img/boat.png" alt="Navire" title="Voir les navires éligibles pour cette ligne"/> - </a> - <p:else> - <img src="${asset:context:}/img/boat-unavailable-22px.png" alt="Navire impossible" title="Accès aux navires impossible, ligne terminée"/> - </p:else> - </t:if> + <t:unless t:test="user.guest"> + <t:if t:test="rowNotFinished"> + <a t:type="pagelink" t:page="boats" t:context="row.topiaId"> + <img src="${asset:context:}/img/boat.png" alt="Navire" title="Voir les navires éligibles pour cette ligne"/> + </a> + <p:else> + <img src="${asset:context:}/img/boat-unavailable-22px.png" alt="Navire impossible" title="Accès aux navires impossible, ligne terminée"/> + </p:else> + </t:if> + </t:unless> <a t:type="pagelink" t:page="sampleRowHistoric" t:context="row.code"> <img src="${asset:context:}/img/clock-22px.png" alt="Historique" title="Voir historique de la ligne"/> </a> Modified: trunk/wao-ui/src/main/webapp/css/common.css =================================================================== --- trunk/wao-ui/src/main/webapp/css/common.css 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/webapp/css/common.css 2010-06-07 18:36:10 UTC (rev 492) @@ -122,6 +122,7 @@ input.ico { border: 0 none; font-size: 0; + color: transparent; width: 32px; height: 32px; cursor: pointer; @@ -131,6 +132,7 @@ input.ico22px { border: 0 none; font-size: 0; + color: transparent; width: 22px; height: 22px; cursor: pointer; @@ -140,6 +142,7 @@ input.ico16px { border: 0 none; font-size: 0; + color: transparent; width: 16px; height: 16px; cursor: pointer; @@ -259,6 +262,7 @@ fieldset.user-form div.t-beaneditor input.t-beaneditor-submit { border: 0 none; font-size: 0; + color: transparent; width: 32px; height: 32px; cursor: pointer; Modified: trunk/wao-ui/src/main/webapp/css/main.css =================================================================== --- trunk/wao-ui/src/main/webapp/css/main.css 2010-06-07 13:51:31 UTC (rev 491) +++ trunk/wao-ui/src/main/webapp/css/main.css 2010-06-07 18:36:10 UTC (rev 492) @@ -143,6 +143,13 @@ width: 23%; } +ul#so-menu li.disabled { + background-color: #e5e5e5; + color: white; + padding: 5px; + width: 23%; +} + ul#so-menu li.admin { width: 18% !important; }
participants (1)
-
fdesbois@users.labs.libre-entreprise.org