[Suiviobsmer-commits] r1355 - in trunk/wao-business/src/main: java/fr/ifremer/wao/entity java/fr/ifremer/wao/io/csv2/models/operations java/fr/ifremer/wao/service xmi
Author: bleny Date: 2011-06-27 14:19:54 +0000 (Mon, 27 Jun 2011) New Revision: 1355 Log: fix contacts after splitting ObsDebCode and labels Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ObsDebCodeImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv2/models/operations/ObsDebCodeParserFormatter.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java trunk/wao-business/src/main/xmi/wao.zargo Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ObsDebCodeImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ObsDebCodeImpl.java 2011-06-27 14:19:22 UTC (rev 1354) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ObsDebCodeImpl.java 2011-06-27 14:19:54 UTC (rev 1355) @@ -3,9 +3,31 @@ public class ObsDebCodeImpl extends ObsDebCodeAbstract { + /** The label to be used when printing this code, it depends on the + * region, so setLabel must be called before using this field + */ + protected String label; + @Override + public void setLabel(TerrestrialLocation region) { + ObsDebCodeDetails obsDebCodeDetailsForRegion = null; + for (ObsDebCodeDetails obsDebCodeDetails : getObsDebCodeDetails()) { + boolean match = obsDebCodeDetails.getRegion().getRegionIfremerCode() + .equals(region.getRegionIfremerCode()); + if (match) { + obsDebCodeDetailsForRegion = obsDebCodeDetails; + } + } + if (obsDebCodeDetailsForRegion == null) { + label = null; + } else { + label = obsDebCodeDetailsForRegion.getLabel(); + } + } + + @Override public String getDescription() { - return getCode(); + return getCode() + (label == null ? "" : " - " + label); } @Override Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv2/models/operations/ObsDebCodeParserFormatter.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv2/models/operations/ObsDebCodeParserFormatter.java 2011-06-27 14:19:22 UTC (rev 1354) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv2/models/operations/ObsDebCodeParserFormatter.java 2011-06-27 14:19:54 UTC (rev 1355) @@ -3,6 +3,7 @@ import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.entity.ObsDebCode; import fr.ifremer.wao.io.csv2.ValueParserFormatter; +import org.apache.commons.lang.StringUtils; import java.text.ParseException; import java.util.List; @@ -32,10 +33,13 @@ if (indexedObsDebCodes == null) { indexedObsDebCodes = WaoUtils.projectPropertyUnique(obsDebCodes, ObsDebCode.PROPERTY_CODE); } - ObsDebCode obsDebCode = indexedObsDebCodes.get(code); - if (obsDebCode == null) { - throw new IllegalArgumentException - (WaoUtils._("wao.import.failure.wrongObsDebCode", code)); + ObsDebCode obsDebCode = null; + if (StringUtils.isNotBlank(code)) { + obsDebCode = indexedObsDebCodes.get(code); + if (obsDebCode == null) { + throw new IllegalArgumentException + (WaoUtils._("wao.import.failure.wrongObsDebCode", code)); + } } return obsDebCode; } 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 2011-06-27 14:19:22 UTC (rev 1354) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2011-06-27 14:19:54 UTC (rev 1355) @@ -100,6 +100,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.swing.plaf.synth.Region; import java.io.IOException; import java.io.InputStream; import java.text.ParseException; @@ -175,11 +176,7 @@ } if (contact.getObsProgram() == ObsProgram.OBSDEB) { - if (sampleRow.isPhoneCall()) { - sampleRow.getTerrestrialLocation(); - } else if (sampleRow.isFieldWorkObservation()) { - sampleRow.getObservationUnit().getRegionIfremer(); - } + TerrestrialLocation region = getRegionForObsDebContact(contact); contact.getTerrestrialLocation(); contact.getObsDebCode(); } @@ -232,7 +229,7 @@ contact.getContactStateMotif(); } if (contact.getObsProgram() == ObsProgram.OBSDEB) { - contact.getObsDebCode(); + TerrestrialLocation region = getRegionForObsDebContact(contact); } } @@ -1510,20 +1507,8 @@ protected List<ObsDebCode> executeGetPossibleObsDebCodes( TopiaContext transaction, Contact contact) throws TopiaException { - // Set of possible codes for this contact depends on the region - // the contact was done, region is given in the sampling plan - TerrestrialLocation region; - SampleRow sampleRow = contact.getSampleRow(); - if (sampleRow.isFieldWorkObservation()) { - region = sampleRow.getObservationUnit().getRegionIfremer(); - } else { - region = sampleRow.getTerrestrialLocation(); - } + TerrestrialLocation region = getRegionForObsDebContact(contact); - if (region == null) { - throw new IllegalStateException("row has no region attached"); - } - WaoQueryHelper.ObsDebCodeProperty obsDebCodeProperty = WaoQueryHelper.newObsDebCodeProperty(); WaoQueryHelper.ObsDebCodeDetailsProperty obsDebCodeDetailsProperty = @@ -1535,6 +1520,10 @@ . addEquals(obsDebCodeDetailsProperty.region(), region); List<ObsDebCode> possibleObsDebCodes = dao.findAllByQuery(query); + for (ObsDebCode possibleObsDebCode : possibleObsDebCodes) { + possibleObsDebCode.setLabel(region); + } + if (log.isDebugEnabled()) { log.debug("For contact " + contact.getTopiaId() + ", region is " + region.getRegionIfremerCode() + @@ -1544,6 +1533,29 @@ return possibleObsDebCodes; } + protected TerrestrialLocation getRegionForObsDebContact(Contact contact) { + // Set of possible codes for this contact depends on the region + // the contact was done, region is given in the sampling plan + TerrestrialLocation region; + SampleRow sampleRow = contact.getSampleRow(); + if (sampleRow.isFieldWorkObservation()) { + region = sampleRow.getObservationUnit().getRegionIfremer(); + } else { + region = sampleRow.getTerrestrialLocation(); + } + + if (region == null) { + throw new IllegalStateException("row has no region attached"); + } + + ObsDebCode obsDebCode = contact.getObsDebCode(); + if (obsDebCode != null) { + obsDebCode.setLabel(region); + } + + return region; + } + @Override protected List<TerrestrialLocation> executeGetPossibleTerrestrialLocations(TopiaContext transaction, Contact contact) { List<TerrestrialLocation> terrestrialLocations; Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ)
participants (1)
-
bleny@users.labs.libre-entreprise.org