Author: tchemit Date: 2013-07-26 11:37:07 +0200 (Fri, 26 Jul 2013) New Revision: 1157 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1157 Log: refs #2889: [TECH] - Prise en compte de nouvelles cat?\195?\169gories dans l'applicatif (validation des captures) Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/CancelEditFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/AbstractImportMultiPostAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/ImportPupitriAction.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -426,8 +426,10 @@ } if (sm != null) { - boolean isSamplingCategory = sampleCategoryModel.containsCategoryId(sm.getPmfm().getId()); - if (isSamplingCategory) { + boolean isFrequency = batchHelper.isFrequencyBatch(sampleCategoryModel, source); + +// boolean isSamplingCategory = sampleCategoryModel.containsCategoryId(sm.getPmfm().getId()); + if (!isFrequency) { Integer qualitativeId = null; if (sm.getQualitativeValue() != null) { qualitativeId = sm.getQualitativeValue().getId(); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -913,15 +913,16 @@ * @return {@code true} if given batch is a frequency batch, * {@code false} otherwise. */ - protected boolean isFrequencyBatch(SampleCategoryModel sampleCategoryModel, + public boolean isFrequencyBatch(SampleCategoryModel sampleCategoryModel, SortingBatch sortingBatch) { boolean result = false; if (sortingBatch.getSortingMeasurements().size() == 1) { SortingMeasurement sm = sortingBatch.getSortingMeasurements().iterator().next(); Pmfm pmfm = sm.getPmfm(); - result = !sampleCategoryModel.containsCategoryId(pmfm.getId()); + result = sortingBatch.getIndividualCount() != null && + !sampleCategoryModel.containsCategoryId(pmfm.getId()); } return result; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/CancelEditFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/CancelEditFishingOperationAction.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/CancelEditFishingOperationAction.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -83,6 +83,7 @@ // re-edit current fishing operation (but do not perform any check) action.setCheckPreviousEdit(false); action.setFishingOperation(getModel().getFishingOperation()); + action.setInternalAction(true); TuttiActionHelper.runInternalAction(action); } @@ -99,4 +100,9 @@ // } } + @Override + public void postSuccessAction() { + super.postSuccessAction(); + getEditAction().displayValidationErrors(); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -35,6 +35,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.catches.ComputeWeightsAction; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; @@ -44,6 +45,7 @@ import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.action.AbstractTuttiAction; import fr.ifremer.tutti.ui.swing.util.action.TuttiActionHelper; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -111,6 +113,20 @@ */ protected SaveCatchBatchAction saveCatchBatchAction; + /** + * To keep catch validation error while loading batches. + * + * @since 2.5 + */ + protected List<String> errorMessages = Lists.newArrayList(); + + /** + * Flag to know if this action is part of another action. + * + * @since 2.5 + */ + protected boolean internalAction; + private final PropertyChangeListener coordinatePropertiesListener = new PropertyChangeListener() { private List<String> properties = Lists.newArrayList( @@ -166,6 +182,7 @@ protected void releaseAction() { fishingOperation = null; checkPreviousEdit = true; + internalAction = false; super.releaseAction(); } @@ -282,7 +299,6 @@ // ok will revert any modification by // editing new fishing operation (if user says yes) canContinue = handler.askCancelEditBeforeLeaving(message); - } } } @@ -315,6 +331,8 @@ @Override protected void doAction() throws Exception { + errorMessages.clear(); + if (log.isInfoEnabled()) { log.info("Try to edit fishingOperation: " + fishingOperation); } @@ -333,7 +351,7 @@ loadFishingOperation(fishingOperation); - loadCatchBatch(fishingOperation, true); + loadCatchBatch(fishingOperation); JTabbedPane form = ui.getTabPane(); JLabel noContentPane = ui.getNoTraitPane(); @@ -369,8 +387,20 @@ super.postSuccessAction(); getUI().getFishingOperationTabContent().getModel().setModify(false); getUI().repaint(); + + if (!internalAction) { + displayValidationErrors(); + } } + public void displayValidationErrors() { + if (CollectionUtils.isNotEmpty(errorMessages)) { + for (String errorMessage : errorMessages) { + TuttiUIContext.getErrorHelper().showErrorDialog(errorMessage, null); + } + } + } + public void loadFishingOperation(FishingOperation bean) { EditFishingOperationUI ui = getUI().getFishingOperationTabContent(); @@ -466,8 +496,7 @@ handler.installCoordinatesListener(); } - public void loadCatchBatch(FishingOperation bean, - boolean loadOtherTabs) { + public void loadCatchBatch(FishingOperation bean) { boolean empty = bean == null || TuttiEntities.isNew(bean); @@ -485,6 +514,9 @@ List<Attachment> attachments; + boolean catchNotFound; + boolean catchEnabled; + if (empty) { // create a new CatchBatch @@ -496,7 +528,8 @@ attachments = Collections.emptyList(); - getModel().setCatchEnabled(true); + catchEnabled = true; + catchNotFound = false; } else { @@ -522,8 +555,8 @@ batch.setFishingOperation(bean); Integer objectId = Integer.valueOf(batch.getId()); attachments = persistenceService.getAllAttachments(catchesUIModel.getObjectType(), objectId); - getModel().setCatchNotFound(false); - getModel().setCatchEnabled(true); + catchNotFound = false; + catchEnabled = true; } catch (InvalidBatchModelException e) { @@ -534,7 +567,8 @@ batch = null; attachments = Collections.emptyList(); - getModel().setCatchEnabled(false); + catchEnabled = false; + catchNotFound = false; } } else { @@ -542,32 +576,104 @@ batch = null; attachments = Collections.emptyList(); - getModel().setCatchEnabled(false); - getModel().setCatchNotFound(true); + catchEnabled = false; + catchNotFound = true; } } - catchesUIModel.setCatchBatch(batch); - catchesUIModel.setFishingOperation(bean); - catchesUIModel.fromBean(batch); - catchesUIModel.addAllAttachment(attachments); - catchesUIModel.setModify(false); - catchBatchMonitor.clearModified(); + setCatch(bean, + attachments, + catchesUIModel, + catchBatchMonitor, + batch, + true, + catchEnabled, + catchNotFound); - if (loadOtherTabs) { - // 4) Propagate new selected fishingoperation to others tabs + // 4) Propagate new selected fishingoperation to others tabs - FishingOperation operationToLoad = batch == null ? null : bean; + FishingOperation operationToLoad = batch == null ? null : bean; + boolean catchValid = true; + + try { ui.getSpeciesTabContent().getHandler().selectFishingOperation(operationToLoad); + } catch (InvalidBatchModelException e) { + + // invalid sample category model + if (log.isDebugEnabled()) { + log.debug("Invalid sample category model", e); + } + errorMessages.add(e.getMessage()); + catchValid = false; + } + + try { ui.getBenthosTabContent().getHandler().selectFishingOperation(operationToLoad); + } catch (InvalidBatchModelException e) { + + // invalid sample category model + if (log.isDebugEnabled()) { + log.debug("Invalid sample category model", e); + } + errorMessages.add(e.getMessage()); + catchValid = false; + } + + if (catchValid) { + + // load other tabs + ui.getMarineLitterTabContent().getHandler().selectFishingOperation(operationToLoad); ui.getAccidentalTabContent().getHandler().selectFishingOperation(operationToLoad); ui.getIndividualObservationTabContent().getHandler().selectFishingOperation(operationToLoad); + + } else { + + // remove catch + setCatch(bean, + Collections.<Attachment>emptyList(), + catchesUIModel, + catchBatchMonitor, + null, + false, + false, + false); } catchesUIModel.setLoadingData(false); } + @Override + public void postFailedAction(Throwable error) { + super.postFailedAction(error); + } + + + protected void setCatch(FishingOperation bean, + List<Attachment> attachments, + EditCatchesUIModel catchesUIModel, + TuttiBeanMonitor<EditCatchesUIModel> catchBatchMonitor, + CatchBatch batch, + boolean sampleModelValid, + boolean catchEnabled, + boolean catchNotFound) { + + getModel().setCatchEnabled(catchEnabled); + getModel().setCatchNotFound(catchNotFound); + getModel().setSampleCatchModelValid(sampleModelValid); + + catchesUIModel.setCatchBatch(batch); + catchesUIModel.setFishingOperation(bean); + catchesUIModel.fromBean(batch); + catchesUIModel.addAllAttachment(attachments); + + catchesUIModel.setModify(false); + catchBatchMonitor.clearModified(); + } + + public void setInternalAction(boolean internalAction) { + this.internalAction = internalAction; + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.css 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUI.css 2013-07-26 09:37:07 UTC (rev 1157) @@ -63,7 +63,7 @@ #warningLabel { actionIcon: warning; border: {new javax.swing.border.EmptyBorder(5, 10, 5, 10)}; - text: {handler.getCatchWarningLabel(model.isCatchEnabled(), model.isCatchNotFound())}; + text: {handler.getCatchWarningLabel(model.isCatchEnabled(), model.isCatchNotFound(), model.isSampleCatchModelValid())}; } #catchesTab { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIHandler.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -275,8 +275,12 @@ //------------------------------------------------------------------------// public String getCatchWarningLabel(boolean catchEnabled, - boolean catchNotFound) { + boolean catchNotFound, + boolean catchSampleModelValid) { String result = null; + if (!catchSampleModelValid) { + result = _("tutti.fishingOperations.warn.catchBatch.invalidSampleCategoryModel"); + } else if (catchNotFound) { result = _("tutti.fishingOperations.warn.catchBatch.notFound"); } else if (!catchEnabled) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/FishingOperationsUIModel.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -58,6 +58,8 @@ public static final String PROPERTY_CATCH_NOT_FOUND = "catchNotFound"; + public static final String PROPERTY_SAMPLE_CATCH_MODEL_VALID = "sampleCatchModelValid"; + /** * List of existing fishing operation for the selected cruise. * <p/> @@ -118,6 +120,17 @@ protected boolean catchEnabled = true; /** + * Flag to know if sample catch model is valid or not on the selected + * fishing operation. + * <p/> + * <strong>Note:</strong> When value is {@code false}, then + * {@link #catchEnabled} is always to {@code false} too. + * + * @since 2.5 + */ + protected boolean sampleCatchModelValid = true; + + /** * Flag setted to true when no catch found. * * @since 2.2 @@ -234,4 +247,14 @@ this.catchNotFound = catchNotFound; firePropertyChange(PROPERTY_CATCH_NOT_FOUND, oldValue, catchNotFound); } + + public boolean isSampleCatchModelValid() { + return sampleCatchModelValid; + } + + public void setSampleCatchModelValid(boolean sampleCatchModelValid) { + boolean oldValue = isSampleCatchModelValid(); + this.sampleCatchModelValid = sampleCatchModelValid; + firePropertyChange(PROPERTY_SAMPLE_CATCH_MODEL_VALID, oldValue, sampleCatchModelValid); + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/AbstractImportMultiPostAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/AbstractImportMultiPostAction.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/AbstractImportMultiPostAction.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -107,7 +107,7 @@ importBatches(operation); - getEditAction().loadCatchBatch(operation, true); + getEditAction().loadCatchBatch(operation); } protected abstract void importBatches(FishingOperation operation); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/CancelEditCatchBatchAction.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -81,7 +81,7 @@ FishingOperation operation = getModel().getFishingOperation(); - getEditAction().loadCatchBatch(operation, true); + getEditAction().loadCatchBatch(operation); } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/ImportPupitriAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/ImportPupitriAction.java 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/ImportPupitriAction.java 2013-07-26 09:37:07 UTC (rev 1157) @@ -121,7 +121,7 @@ operation, catchBatch); - getEditAction().loadCatchBatch(operation, true); + getEditAction().loadCatchBatch(operation); sendMessage(_("tutti.editSpeciesBatch.action.importPupitri.success", getModel().getRootNumber(), rejectedSpeciesNb)); Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-07-26 09:37:07 UTC (rev 1157) @@ -922,6 +922,7 @@ tutti.fishingOperations.info.no.fishingOperation.selected= tutti.fishingOperations.title.edit.operations= tutti.fishingOperations.title.validate.operations= +tutti.fishingOperations.warn.catchBatch.invalidSampleCategoryModel= tutti.fishingOperations.warn.catchBatch.notFound= tutti.fishingOperations.warn.invalid.batch.model= tutti.flash.info.all.caractristic.exported= Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-07-25 17:32:14 UTC (rev 1156) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-07-26 09:37:07 UTC (rev 1157) @@ -922,6 +922,7 @@ tutti.fishingOperations.info.no.fishingOperation.selected=< Aucun trait sélectionné > tutti.fishingOperations.title.edit.operations=Saisie des opérations de pêches (%s) tutti.fishingOperations.title.validate.operations=Validation des opérations de pêches (%s) +tutti.fishingOperations.warn.catchBatch.invalidSampleCategoryModel=L'arbre d’échantillonnage n'est pas compatible (utilisation de catégories non configurées). Les captures ne seront pas visibles. tutti.fishingOperations.warn.catchBatch.notFound=Pas d'arbre d’échantillonnage associé à l'opération de pêche. tutti.fishingOperations.warn.invalid.batch.model=L'arbre d’échantillonnage n'est pas compatible. Les captures ne seront pas visibles. tutti.flash.info.all.caractristic.exported=Toutes les caractéristiques exportées dans le fichier <strong>%s</strong>.