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