[Suiviobsmer-commits] r762 - in trunk: wao-business/src/main/java/fr/ifremer/wao/service wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/webapp
Author: bleny Date: 2010-11-12 12:48:18 +0000 (Fri, 12 Nov 2010) New Revision: 762 Log: impact migration of DCF5Code in sample row form Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java trunk/wao-ui/src/main/webapp/SampleRowForm.tml 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-11-12 08:57:59 UTC (rev 761) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-11-12 12:48:18 UTC (rev 762) @@ -46,6 +46,7 @@ import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactDAO; import fr.ifremer.wao.entity.DCFFiveCode; +import fr.ifremer.wao.entity.DCFFiveCodeDAO; import fr.ifremer.wao.entity.ElligibleBoat; import fr.ifremer.wao.entity.ElligibleBoatDAO; import fr.ifremer.wao.entity.FishingZone; @@ -92,10 +93,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; +import java.util.Collection; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -138,6 +141,61 @@ // prepareBinderForProfession(); // } + /** given a collection of DCFCode (mixing some taken from DB and some + * other insciated), return the same collection but assure that all elements + * are now in the database. + * + * The method, insert all new codes in database, the others are already + * inserted so we reference them, so they will be used as foreign key. + */ + protected Collection<DCFFiveCode> insertOrSelect(TopiaContext transaction, + Collection<DCFFiveCode> codes) throws TopiaException { + Collection<DCFFiveCode> result = new LinkedList<DCFFiveCode>(); + + for (DCFFiveCode code : codes) { + + // try do find code in stored entities + DCFFiveCodeDAO dao = WaoDAOHelper.getDCFFiveCodeDAO(transaction); + + // both fishingGear and targetSpecies code have to be equals for + // DCF5 code to be considered equals. targetSpecies as to be null + // if asked + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(DCFFiveCode.FISHING_GEAR_DCF, code.getFishingGearDCF()); + + // next line may result in a "IS NULL", exactly what we want + properties.put(DCFFiveCode.TARGET_SPECIES_DCF, code.getTargetSpeciesDCF()); + + DCFFiveCode foundCode = dao.findByProperties(properties); + + if (log.isDebugEnabled()) { + log.debug("foundCode = " + foundCode); + } + + if (foundCode == null) { + if (log.isDebugEnabled()) { + log.debug(code + " is not already in DB, inserting"); + } + + // not found, let's insert a new row in database for this code + dao.create(code); + // add this new row in the result + result.add(code); + } else { + if (log.isDebugEnabled()) { + log.debug(code + " is already in DB, using"); + } + // found : a row for code is already present, so we don't + // insert anything and just use this row by adding it in the + // result + result.add(foundCode); + } + + } + + return result; + } + @Override public void executeCreateUpdateSampleRow(TopiaContext transaction, SampleRow row, List<Boat> boats, SampleRowLog rowLog) @@ -202,6 +260,11 @@ PeriodDates newPeriod = new PeriodDates(row.getPeriodBegin(), row.getPeriodEnd()); rowLog.addChangePeriod(oldPeriod, newPeriod, pattern); + // before saving profession + row.getProfession().setDcf5code( + insertOrSelect(transaction, + row.getProfession().getDcf5code())); + // Save Profession ProfessionDAO professionDAO = WaoDAOHelper.getProfessionDAO(transaction); context.prepareTopiaId(Profession.class, row.getProfession()); @@ -502,6 +565,14 @@ result.sizeSampleMonth(); result.sizeElligibleBoat(); + + + // XXX bleny 20101110 browse code to force load it from BD + // "lazy" directive doesn't seem to work + for (DCFFiveCode code : result.getProfession().getDcf5code()) { + log.debug("row " + result.getCode() + " has DCF5 code " + code.toString()); + } + return result; } 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-11-12 08:57:59 UTC (rev 761) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2010-11-12 12:48:18 UTC (rev 762) @@ -30,6 +30,8 @@ import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.DCFFiveCode; +import fr.ifremer.wao.entity.DCFFiveCodeImpl; import fr.ifremer.wao.entity.FishingZone; import fr.ifremer.wao.entity.Profession; import fr.ifremer.wao.entity.ProfessionImpl; @@ -58,6 +60,7 @@ import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.beaneditor.BeanModel; import org.apache.tapestry5.corelib.components.Form; +import org.apache.tapestry5.corelib.components.Zone; import org.apache.tapestry5.internal.OptionModelImpl; import org.apache.tapestry5.internal.SelectModelImpl; import org.apache.tapestry5.ioc.annotations.Inject; @@ -69,6 +72,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.List; @@ -214,6 +218,95 @@ edited = true; } + + + @Property + private boolean refreshDcf5CodeZone; + + @Property + private int dcf5CodeIndex; + + @Persist + private DCFFiveCode currentDcf5Code; + + @Property + private String currentDCFGear; + + @Property + private String currentDCFSpecies; + + @Property + private DCFFiveCode dcf5Code; + + @InjectComponent + private Zone dcf5CodeZone; + + private List<DCFFiveCode> rowDCF5codes; + + public DCFFiveCode getCurrentDcf5Code() { + if (currentDcf5Code == null) { + currentDcf5Code = new DCFFiveCodeImpl(); + } + return currentDcf5Code; + } + + public void setCurrentDcf5Code(DCFFiveCode currentDcf5Code) { + this.currentDcf5Code = currentDcf5Code; + } + + public List<DCFFiveCode> getRowDCF5codes() { + if (rowDCF5codes == null) { + Collection<DCFFiveCode> codes = getSampleRow().getProfession().getDcf5code(); + if (codes == null) { + rowDCF5codes = new ArrayList<DCFFiveCode>(); + } else { + rowDCF5codes = new ArrayList<DCFFiveCode>(codes); + } + getSampleRow().getProfession().setDcf5code(rowDCF5codes); + } + return rowDCF5codes; + } + + public void onChangeFromCurrentDCFGear(String currentDCFGear) { + getCurrentDcf5Code().setFishingGearDCF(currentDCFGear); + } + + public void onChangeFromCurrentDCFSpecies(String currentDCFSpecies) { + getCurrentDcf5Code().setTargetSpeciesDCF(currentDCFSpecies); + } + + public Object onActionFromAddCurrentDcf5Code() { + getRowDCF5codes().add(currentDcf5Code); + + log.debug("added " + currentDcf5Code.getFishingGearDCF() + "_" + + currentDcf5Code.getTargetSpeciesDCF()); + + getSampleRow().getProfession().setDcf5code(rowDCF5codes); + + currentDcf5Code = null; + + refreshDcf5CodeZone = true; + return dcf5CodeZone; + } + + public Object onActionFromRemoveDcf5Code(int dcf5CodeIndex) { + + if (log.isDebugEnabled()) { + log.debug("dcf5codes before removing " + dcf5CodeIndex + " : " + + getSampleRow().getProfession().getDcf5code()); + } + + getRowDCF5codes().remove(dcf5CodeIndex); + getSampleRow().getProfession().setDcf5code(rowDCF5codes); + + if (log.isDebugEnabled()) { + log.debug("dcf5codes after removing " + getSampleRow().getProfession().getDcf5code()); + } + + refreshDcf5CodeZone = true; + return dcf5CodeZone; + } + /*************************** FISHING ZONE *********************************/ /** Select model for the FishingZone list **/ Modified: trunk/wao-ui/src/main/webapp/SampleRowForm.tml =================================================================== --- trunk/wao-ui/src/main/webapp/SampleRowForm.tml 2010-11-12 08:57:59 UTC (rev 761) +++ trunk/wao-ui/src/main/webapp/SampleRowForm.tml 2010-11-12 12:48:18 UTC (rev 762) @@ -60,6 +60,27 @@ <t:beaneditor t:id="professionEditor" t:object="sampleRow.profession" t:include="codeDCF5, meshSize, size, other, libelle, species" /> </div> + <div class="t-beaneditor"> + <t:zone id="so-sampleRowForm-dcf5CodeZone" t:id="dcf5CodeZone" t:update="show"> + <t:nuiton.subForm t:visible="refreshDcf5CodeZone"> + <!--<t:label t:for="selectedDcf5Code" />: + <select t:type="select" t:id="selectedSampleRow" t:value="selectedSampleRow" t:model="sampleRowSelectModel" + t:mixins="ck/onEvent" t:event="change"/--> + <input t:type="textfield" t:value="currentDCFGear" size="3" t:id="currentDCFGear" t:mixins="ck/onEvent" t:event="change" />_<input t:type="textfield" t:value="currentDCFSpecies" size="3" t:id="currentDCFSpecies" t:mixins="ck/onEvent" t:event="change" /> + <a t:type="actionlink" t:id="addCurrentDcf5Code" title="Ajouter ce code DCF5" t:zone="so-sampleRowForm-dcf5CodeZone"> + <img src="${asset:context:img/add-16px.png}" /> + </a> + <ul> + <li t:type="loop" t:source="rowDCF5codes" t:value="dcf5Code" t:index="dcf5CodeIndex" t:volatile="true"> + ${dcf5Code.fishingGearDCF}_${dcf5Code.targetSpeciesDCF} + <a t:type="actionlink" t:id="removeDcf5Code" t:context="dcf5CodeIndex" title="Supprimer ce code DCF5" t:zone="so-sampleRowForm-dcf5CodeZone"> + <img src="${asset:context:img/remove-22px.png}" /> + </a> + </li> + </ul> + </t:nuiton.subForm> + </t:zone> + </div> </p:else> </t:if> </fieldset>
participants (1)
-
bleny@users.labs.libre-entreprise.org