Author: fdesbois Date: 2009-12-17 18:55:43 +0000 (Thu, 17 Dec 2009) New Revision: 130 Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/BoatImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo Log: - Add index on immatriculation attribute in Boat entity - All data from ActivityCalendar is always updated (even they already exist) - Change default return value for canCreateContact method : waiting for business validation on create contact conditions. Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/BoatImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/BoatImpl.java 2009-12-17 09:35:21 UTC (rev 129) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/BoatImpl.java 2009-12-17 18:55:43 UTC (rev 130) @@ -142,10 +142,13 @@ @Override public boolean canCreateContact(Company company, SampleRow row) throws SuiviObsmerException { TopiaContext transaction = null; - boolean result = true; + // FIXME depends on condition over double creation on the same sampleRow for the same company. + // Normally, the default value is true (if no contact exist for this boat, it's possible to create one) + boolean result = false; try { transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); + // Return the last contact for this boat, sampleRow and company List results = transaction.find( "FROM ContactImpl C1" + " WHERE C1.user.company = :company" + Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java 2009-12-17 09:35:21 UTC (rev 129) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java 2009-12-17 18:55:43 UTC (rev 130) @@ -96,8 +96,6 @@ Boat boat = boatDAO.findByImmatriculation(boatImmatriculation); - - if (boat != null) { ActivityCalendarDAO dao = SuiviObsmerModelDAOHelper.getActivityCalendarDAO(transaction); @@ -118,123 +116,130 @@ calendar.setActivityMonth(new ArrayList<ActivityMonth>()); - info("Création d'un calendrier " + year + + if (log.isDebugEnabled()) { + info("Création d'un calendrier " + year + " pour le navire immatriculé " + boatImmatriculation, currRow); - - //transaction.commitTransaction(); + } } String calendarCode = "[ calendrier " + year + ", navire " + boatImmatriculation + " ]"; int monthNum = Integer.parseInt(reader.get("SYNA_MOI").trim()); String harbourCode = reader.get("SYNA_POR_COD").trim(); + boolean active = !harbourCode.equals("INA"); ActivityMonth month = calendar.getActivityMonth(monthNum); if (month == null) { - boolean active = !harbourCode.equals("INA"); - ActivityMonthDAO monthDAO = SuiviObsmerModelDAOHelper.getActivityMonthDAO(transaction); month = monthDAO.create( ActivityMonth.ACTIVITY_CALENDAR, calendar, - ActivityMonth.MONTH, monthNum, - ActivityMonth.ACTIVE, active); + ActivityMonth.MONTH, monthNum); month.setActivityProfession(new ArrayList<ActivityProfession>()); - info("Création du mois " + monthNum + " actif(" + active + ") " + calendarCode, currRow); + if (log.isDebugEnabled()) { + info("Création du mois " + monthNum + " actif(" + active + ") " + calendarCode, currRow); + } - if (active) { - String nbSeaDaysString = reader.get("SYNA_NOMJDM").trim(); - Integer nbSeaDays = !nbSeaDaysString.equals("NA") ? - Integer.valueOf(nbSeaDaysString) : null; + calendar.addActivityMonth(month); + } - String nbFishingDaysString = reader.get("SYNA_NOMJDP").trim(); - Integer nbFishingDays = !nbFishingDaysString.equals("NA") ? - Integer.valueOf(nbFishingDaysString) : null; + month.setActive(active); - String nbBoardingPersonsString = reader.get("SYNA_NOMHE").trim(); - Integer nbBoardingPersons = !nbBoardingPersonsString.equals("NA") ? - Integer.valueOf(nbBoardingPersonsString) : null; + if (active) { + String nbSeaDaysString = reader.get("SYNA_NOMJDM").trim(); + Integer nbSeaDays = !nbSeaDaysString.equals("NA") ? + Integer.valueOf(nbSeaDaysString) : null; - int harbourId = Integer.parseInt(reader.get("SYNA_TPOR_COD").trim()); - String harbourLibelle = reader.get("SYNA_POR_LIB").trim(); - //String harbourCode = reader.get("SYNA_POR_COD").trim(); + String nbFishingDaysString = reader.get("SYNA_NOMJDP").trim(); + Integer nbFishingDays = !nbFishingDaysString.equals("NA") ? + Integer.valueOf(nbFishingDaysString) : null; - month.setHarbourId(harbourId); - month.setHarbourCode(harbourCode); - month.setHarbourLibelle(harbourLibelle); - month.setNbBoardingPersons(nbBoardingPersons); - month.setNbFishingDays(nbFishingDays); - month.setNbSeaDays(nbSeaDays); - } else { - result++; - } + String nbBoardingPersonsString = reader.get("SYNA_NOMHE").trim(); + Integer nbBoardingPersons = !nbBoardingPersonsString.equals("NA") ? + Integer.valueOf(nbBoardingPersonsString) : null; - calendar.addActivityMonth(month); + int harbourId = Integer.parseInt(reader.get("SYNA_TPOR_COD").trim()); + String harbourLibelle = reader.get("SYNA_POR_LIB").trim(); + //String harbourCode = reader.get("SYNA_POR_COD").trim(); - //transaction.commitTransaction(); - } + month.setHarbourId(harbourId); + month.setHarbourCode(harbourCode); + month.setHarbourLibelle(harbourLibelle); + month.setNbBoardingPersons(nbBoardingPersons); + month.setNbFishingDays(nbFishingDays); + month.setNbSeaDays(nbSeaDays); - if (month.getActive()) { + int professionOrder = Integer.parseInt(reader.get("META_ORDRE").trim()); + String professionCode = reader.get("MET_COD").trim(); + int professionId = Integer.parseInt(reader.get("MET_ID").trim()); + String professionLibelle = reader.get("MET_LIB").trim(); - int professionOrder = Integer.parseInt(reader.get("META_ORDRE").trim()); ActivityProfession profession = month.getActivityProfession(professionOrder); if (profession == null) { - String professionCode = reader.get("MET_COD").trim(); - int professionId = Integer.parseInt(reader.get("MET_ID").trim()); - String professionLibelle = reader.get("MET_LIB").trim(); ActivityProfessionDAO professionDAO = SuiviObsmerModelDAOHelper.getActivityProfessionDAO(transaction); profession = professionDAO.create( ActivityProfession.ACTIVITY_MONTH, month, - ActivityProfession.PROFESSION_ORDER, professionOrder, - ActivityProfession.ID, professionId, - ActivityProfession.CODE, professionCode, - ActivityProfession.LIBELLE, professionLibelle); + ActivityProfession.PROFESSION_ORDER, professionOrder); profession.setActivityZone(new ArrayList<ActivityZone>()); - info("Création du métier " + professionOrder + " code(" + professionCode + ") " + + if (log.isDebugEnabled()) { + info("Création du métier " + professionOrder + " code(" + professionCode + ") " + "[ mois " + monthNum + " ] " + calendarCode, currRow); + } month.addActivityProfession(profession); } + profession.setId(professionId); + profession.setCode(professionCode); + profession.setLibelle(professionLibelle); + String zoneCode = reader.get("SECT_COD").trim(); + int gradiantCode = Integer.parseInt(reader.get("GRA_COD").trim()); + String gradiantLibelle = reader.get("GRA_LIB").trim(); + int zoneId = Integer.parseInt(reader.get("TSECT_COD").trim()); + String zoneLibelle = reader.get("SECT_LIB").trim(); ActivityZone zone = profession.getActivityZone(zoneCode); if (zone == null) { - int gradiantCode = Integer.parseInt(reader.get("GRA_COD").trim()); - String gradiantLibelle = reader.get("GRA_LIB").trim(); - int zoneId = Integer.parseInt(reader.get("TSECT_COD").trim()); - String zoneLibelle = reader.get("SECT_LIB").trim(); - ActivityZoneDAO zoneDAO = SuiviObsmerModelDAOHelper.getActivityZoneDAO(transaction); zone = zoneDAO.create( - ActivityZone.ACTIVITY_PROFESSION, profession, - ActivityZone.ZONE_ID, zoneId, - ActivityZone.GRADIANT_CODE, gradiantCode, - ActivityZone.GRADIANT_LIBELLE, gradiantLibelle, ActivityZone.ZONE_CODE, zoneCode, - ActivityZone.ZONE_LIBELLE, zoneLibelle); + ActivityZone.ACTIVITY_PROFESSION, profession); - info("Création de la zone " + zoneCode + " [ mois " + monthNum + " ] " + + if (log.isDebugEnabled()) { + info("Création de la zone " + zoneCode + " [ mois " + monthNum + " ] " + calendarCode, currRow); + } profession.addActivityZone(zone); - result++; } else { - warn("Zone déjà existante [" + zoneCode + "] ! :: " + Arrays.toString(reader.getValues()), currRow); + if (log.isDebugEnabled()) { + info("Ecrasement de la zone " + zoneCode + " [ mois " + monthNum + " ] " + + calendarCode, currRow); + } + //warn("Zone déjà existante [" + zoneCode + "] ! :: " + Arrays.toString(reader.getValues()), currRow); } + + zone.setZoneId(zoneId); + zone.setZoneLibelle(zoneLibelle); + zone.setGradiantCode(gradiantCode); + zone.setGradiantLibelle(gradiantLibelle); + } else { + info("Ligne inactif", currRow); } + result++; } else { warn("Navire inexistant dans le référentiel : " + boatImmatriculation, currRow); } @@ -244,10 +249,12 @@ log.debug("Time : " + DurationFormatUtils.formatDurationHMS(tic - firstTic)); } - transaction.commitTransaction(); - writer.flush(); + if (result%500 == 0 && log.isInfoEnabled()) { + log.info("RUNNING... Import calendrier d'activité ligne " + currRow); + } } + transaction.commitTransaction(); long stopTime = System.currentTimeMillis(); @@ -293,6 +300,7 @@ String ligne = numRow != -1 ? "Ligne (" + numRow + ") : " : ""; String msg = "[" + dateString + "] " + ligne + message; writer.write(msg + "\n"); + writer.flush(); if (log.isDebugEnabled()) { log.debug("write log activityCalendar : " + msg); } Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo =================================================================== (Binary files differ)