[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
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)
participants (1)
-
fdesbois@users.labs.libre-entreprise.org