This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See http://git.codelutin.com/observe.git commit ed9282f78d784fe9472516a4b3510e30fbfb0ea7 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Oct 26 14:13:04 2015 +0100 migration de la composition detaillée de la ligne (refs #7615) --- .../entities/longline/SectionWithTemplate.java | 174 ++++++ .../entities/longline/SectionWithTemplates.java | 70 +++ .../ui/content/impl/longline/BranchlineUI.css | 4 +- .../ui/content/impl/longline/BranchlineUI.jaxx | 8 +- .../content/impl/longline/BranchlineUIHandler.java | 10 +- .../content/impl/longline/BranchlineUIModel.java | 31 - .../LonglineCompositionTableModelSupport.java | 12 +- .../impl/longline/LonglineDetailCompositionUI.jaxx | 8 +- .../LonglineDetailCompositionUIHandler.java | 665 +++++++-------------- .../LonglineDetailCompositionUIInitializer.java | 12 +- .../longline/LonglineDetailCompositionUIModel.java | 105 +--- ...onglineDetailCompositionUIValidationHelper.java | 44 +- .../impl/longline/SectionTemplatesTableModel.java | 127 ++-- .../content/impl/longline/SectionsTableModel.java | 172 +++--- .../BasketDto-n1-update-table-error-validation.xml | 68 +++ .../BranchlineDto-n1-update-error-validation.xml | 113 ++++ ...nchlineDto-n1-update-table-error-validation.xml | 68 +++ .../BranchlineDto-n1-update-warning-validation.xml | 47 ++ ...SectionDto-n1-update-table-error-validation.xml | 38 ++ ...LonglineDetailCompositionServiceController.java | 20 +- .../observe/entities/longline/BasketTopiaDao.java | 26 + .../entities/longline/BranchlineTopiaDao.java | 24 + .../observe/entities/longline/SectionTopiaDao.java | 23 + .../SetLonglineDetailCompositionService.java | 12 +- .../dto/longline/LonglineCompositionDto.java | 43 ++ .../main/xmi/observe-services-dto-longline.zargo | Bin 63218 -> 64399 bytes .../services/dto/ObserveDtosInitializer.java | 7 + .../SetLonglineDetailCompositionServiceTopia.java | 55 +- 28 files changed, 1192 insertions(+), 794 deletions(-) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/entities/longline/SectionWithTemplate.java b/observe-application-swing/src/main/java/fr/ird/observe/entities/longline/SectionWithTemplate.java new file mode 100644 index 0000000..ac36c83 --- /dev/null +++ b/observe-application-swing/src/main/java/fr/ird/observe/entities/longline/SectionWithTemplate.java @@ -0,0 +1,174 @@ +package fr.ird.observe.entities.longline; + +/* + * #%L + * ObServe :: Entities + * %% + * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit + * %% + * 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% + */ + +import fr.ird.observe.services.dto.longline.BasketDto; +import fr.ird.observe.services.dto.longline.SectionDto; + +import java.util.Collection; +import java.util.LinkedHashSet; + +/** + * Created on 12/12/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.10 + */ +public class SectionWithTemplate extends SectionDto { + + private static final long serialVersionUID = 1L; + + SectionTemplate sectionTemplate; + + private final SectionDto delegate; + + public SectionWithTemplate() { + this(new SectionDto()); + } + + public SectionWithTemplate(SectionDto delegate) { + this.delegate = delegate; + } + + public SectionDto getDelegate() { + return delegate; + } + + public SectionTemplate getSectionTemplate() { + return sectionTemplate; + } + + public void setSectionTemplate(SectionTemplate sectionTemplate) { + this.sectionTemplate = sectionTemplate; + } + + @Override + public Integer getSettingIdentifier() { + return delegate.getSettingIdentifier(); + } + + @Override + public void setSettingIdentifier(Integer settingIdentifier) { + delegate.setSettingIdentifier(settingIdentifier); + } + + @Override + public Integer getHaulingIdentifier() { + return delegate.getHaulingIdentifier(); + } + + @Override + public void setHaulingIdentifier(Integer haulingIdentifier) { + delegate.setHaulingIdentifier(haulingIdentifier); + } + + @Override + public BasketDto getBasket(int index) { + return delegate.getBasket(index); + } + + @Override + public boolean isBasketEmpty() { + return delegate.isBasketEmpty(); + } + + @Override + public int sizeBasket() { + return delegate.sizeBasket(); + } + + @Override + public void addBasket(BasketDto basket) { + delegate.addBasket(basket); + } + + @Override + public void addAllBasket(Collection<BasketDto> basket) { + delegate.addAllBasket(basket); + } + + @Override + public boolean removeBasket(BasketDto basket) { + return delegate.removeBasket(basket); + } + + @Override + public boolean removeAllBasket(Collection<BasketDto> basket) { + return delegate.removeAllBasket(basket); + } + + @Override + public boolean containsBasket(BasketDto basket) { + return delegate.containsBasket(basket); + } + + @Override + public boolean containsAllBasket(Collection<BasketDto> basket) { + return delegate.containsAllBasket(basket); + } + + @Override + public LinkedHashSet<BasketDto> getBasket() { + return delegate.getBasket(); + } + + @Override + public void setBasket(LinkedHashSet<BasketDto> basket) { + delegate.setBasket(basket); + } + + @Override + public boolean isPersisted() { + return delegate.isPersisted(); + } + + @Override + public boolean isNotPersisted() { + return delegate.isNotPersisted(); + } + + @Override + public boolean equals(Object o) { + return delegate.equals(o); + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + + @Override + public String toString() { + return delegate.toString(); + } + + @Override + public String getId() { + return delegate.getId(); + } + + @Override + public void setId(String id) { + delegate.setId(id); + } +} diff --git a/observe-application-swing/src/main/java/fr/ird/observe/entities/longline/SectionWithTemplates.java b/observe-application-swing/src/main/java/fr/ird/observe/entities/longline/SectionWithTemplates.java new file mode 100644 index 0000000..fea98e1 --- /dev/null +++ b/observe-application-swing/src/main/java/fr/ird/observe/entities/longline/SectionWithTemplates.java @@ -0,0 +1,70 @@ +package fr.ird.observe.entities.longline; + +/* + * #%L + * ObServe :: Entities + * %% + * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit + * %% + * 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% + */ + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; +import fr.ird.observe.services.dto.longline.SectionDto; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; + +/** + * Created on 12/12/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.10 + */ +public class SectionWithTemplates { + + protected static Function<SectionWithTemplate, SectionDto> GET_DELEGATE_FUNCTION = new Function<SectionWithTemplate, SectionDto>() { + @Override + public SectionDto apply(SectionWithTemplate input) { + return input.getDelegate(); + } + }; + + + public static List<SectionWithTemplate> getSectionTemplates(Collection<SectionDto> sections) { + + List<SectionWithTemplate> sectionTemplates = new ArrayList<SectionWithTemplate>(); + + if (sections != null) { + + for (SectionDto section1 : sections) { + SectionWithTemplate e = new SectionWithTemplate(section1); + sectionTemplates.add(e); + } + + } + + return sectionTemplates; + } + + public static LinkedHashSet<SectionDto> getSections(List<SectionWithTemplate> data) { + return Sets.newLinkedHashSet(Iterables.transform(data, GET_DELEGATE_FUNCTION)); + } +} diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUI.css b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUI.css index 598904c..820e445 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUI.css +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUI.css @@ -101,8 +101,6 @@ label:{t("observe.branchline.timerTimeOnBoard")}; date:{bean.getTimerTimeOnBoard()}; propertyDate: {BranchlineDto.PROPERTY_TIMER_TIME_ON_BOARD}; - propertyDayDate: {BranchlineUIModel.PROPERTY_TIMER_TIME_ON_BOARD_DATE}; - propertyTimeDate: {BranchlineUIModel.PROPERTY_TIMER_TIME_ON_BOARD_TIME}; _validatorLabel:{t("observe.branchline.timerTimeOnBoard")}; } @@ -185,7 +183,7 @@ } #hookType { - property:{Branchline.PROPERTY_HOOK_TYPE}; + property:{BranchlineDto.PROPERTY_HOOK_TYPE}; selectedItem:{bean.getHookType()}; _validatorLabel:{t("observe.branchline.hookType")}; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUI.jaxx b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUI.jaxx index 4572fa9..9d82cf9 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUI.jaxx +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUI.jaxx @@ -177,20 +177,20 @@ public void edit(BranchlineDto branchline) { getHandler().edit(branchline); } <!-- HookType --> <row> <cell anchor='west'> - <JLabel id='HookTypeLabel'/> + <JLabel id='hookTypeLabel'/> </cell> <cell anchor='east' weightx="1" fill="both" columns="2"> - <BeanComboBox id='HookType' constructorParams='this' genericType='ReferenceDto<HookTypeDto>' _entityClass='HookTypeDto.class'/> + <BeanComboBox id='hookType' constructorParams='this' genericType='ReferenceDto<HookTypeDto>' _entityClass='HookTypeDto.class'/> </cell> </row> <!-- HookSize --> <row> <cell anchor='west'> - <JLabel id='HookSizeLabel'/> + <JLabel id='hookSizeLabel'/> </cell> <cell anchor='east' weightx="1" fill="both" columns="2"> - <BeanComboBox id='HookSize' constructorParams='this' genericType='ReferenceDto<HookSizeDto>' _entityClass='HookSizeDto.class'/> + <BeanComboBox id='hookSize' constructorParams='this' genericType='ReferenceDto<HookSizeDto>' _entityClass='HookSizeDto.class'/> </cell> </row> diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java index 3bc2902..1ba8e19 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.impl.longline; import fr.ird.observe.business.db.DataContext; import fr.ird.observe.business.db.constants.DataContextType; import fr.ird.observe.db.ObserveSwingDataSource; -import fr.ird.observe.services.dto.longline.ActivityLonglineDto; import fr.ird.observe.services.dto.longline.BranchlineDto; import fr.ird.observe.services.dto.longline.BranchlineDtos; import fr.ird.observe.ui.UIHelper; @@ -41,7 +40,7 @@ import org.nuiton.decorator.Decorator; import org.nuiton.i18n.I18n; import org.nuiton.validator.NuitonValidatorScope; -import javax.swing.*; +import javax.swing.JOptionPane; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import java.util.HashSet; @@ -130,7 +129,7 @@ public class BranchlineUIHandler extends ContentUIHandler<BranchlineDto> { ContentMode contentMode; - if (dataContext.isSelectedOpen(ActivityLonglineDto.class)) { + if (getOpenDataManager().isOpenActivityLongline(dataContext.getSelectedActivityLonglineId())) { // l'activité est ouverte, mode édition contentMode = ContentMode.UPDATE; @@ -203,9 +202,8 @@ public class BranchlineUIHandler extends ContentUIHandler<BranchlineDto> { BranchlineUI.BINDING_BAIT_SETTING_STATUS_SELECTED_ITEM, BranchlineUI.BINDING_BAIT_HAULING_STATUS_SELECTED_ITEM, - //FIXME -// BranchlineUI.BINDING_HOOK_TYPE_SELECTED_ITEM, -// BranchlineUI.BINDING_HOOK_SIZE_SELECTED_ITEM, + BranchlineUI.BINDING_HOOK_TYPE_SELECTED_ITEM, + BranchlineUI.BINDING_HOOK_SIZE_SELECTED_ITEM, BranchlineUI.BINDING_HOOK_OFFSET_MODEL, BranchlineUI.BINDING_TIMER_SELECTED, diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIModel.java index 438e68f..50e857e 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIModel.java @@ -25,9 +25,7 @@ package fr.ird.observe.ui.content.impl.longline; import com.google.common.collect.ImmutableSet; import fr.ird.observe.services.dto.longline.BranchlineDto; import fr.ird.observe.ui.content.ContentUIModel; -import org.nuiton.util.DateUtil; -import java.util.Date; import java.util.Set; /** @@ -46,10 +44,6 @@ public class BranchlineUIModel extends ContentUIModel<BranchlineDto> { public static final String PROPERTY_HOOK_AND_BAIT_TAB_VALID = "hookAndBaitTabValid"; - public static final String PROPERTY_TIMER_TIME_ON_BOARD_DATE = "timerTimeOnBoardDate"; - - public static final String PROPERTY_TIMER_TIME_ON_BOARD_TIME = "timerTimeOnBoardTime"; - public static final Set<String> GENERAL_TAB_PROPERTIES = ImmutableSet.<String>builder().add(BranchlineDto.PROPERTY_TOP_TYPE, BranchlineDto.PROPERTY_TRACELINE_TYPE, @@ -113,29 +107,4 @@ public class BranchlineUIModel extends ContentUIModel<BranchlineDto> { firePropertyChange(PROPERTY_SAVED, null, true); } - public Date getTimerTimeOnBoardDate() { - Date timerTimeOnBoard = bean.getTimerTimeOnBoard(); - return timerTimeOnBoard == null ? null : DateUtil.getDay(timerTimeOnBoard); - } - - public Date getTimerTimeOnBoardTime() { - Date timerTimeOnBoard = bean.getTimerTimeOnBoard(); - return timerTimeOnBoard == null ? null : DateUtil.getTime(timerTimeOnBoard, false, false); - } - - public void setTimerTimeOnBoardDate(Date date) { - Date timerTimeOnBoard = bean.getTimerTimeOnBoard(); - if (timerTimeOnBoard != null) { - Date dateAndTime = DateUtil.getDateAndTime(date, timerTimeOnBoard, true, false); - bean.setTimerTimeOnBoard(dateAndTime); - } - } - - public void setTimerTimeOnBoardTime(Date time) { - Date timerTimeOnBoard = bean.getTimerTimeOnBoard(); - if (timerTimeOnBoard != null) { - Date dateAndTime = DateUtil.getDateAndTime(timerTimeOnBoard, time, false, false); - bean.setTimerTimeOnBoard(dateAndTime); - } - } } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineCompositionTableModelSupport.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineCompositionTableModelSupport.java index b37d4e8..c081516 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineCompositionTableModelSupport.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineCompositionTableModelSupport.java @@ -23,6 +23,7 @@ package fr.ird.observe.ui.content.impl.longline; */ import fr.ird.observe.services.dto.AbstractObserveDto; +import fr.ird.observe.services.dto.longline.LonglineCompositionDto; import fr.ird.observe.ui.util.table.EditableTableModelSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,10 +36,7 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 3.10 */ -public abstract class LonglineCompositionTableModelSupport<E extends AbstractObserveDto - //FIXME -// & LonglineCompositionEntity - > extends EditableTableModelSupport<E> { +public abstract class LonglineCompositionTableModelSupport<E extends AbstractObserveDto & LonglineCompositionDto> extends EditableTableModelSupport<E> { /** Logger. */ private static final Log log = LogFactory.getLog(LonglineCompositionTableModelSupport.class); @@ -96,8 +94,7 @@ public abstract class LonglineCompositionTableModelSupport<E extends AbstractObs if (log.isInfoEnabled()) { log.info("SettingIdentifier : " + index); } - //FIXME -// e.setSettingIdentifier(index); + e.setSettingIdentifier(index); if (generateHaulingIds) { @@ -112,8 +109,7 @@ public abstract class LonglineCompositionTableModelSupport<E extends AbstractObs if (log.isInfoEnabled()) { log.info("HaulingIdentifier : " + haulingId); } - //FIXME -// e.setHaulingIdentifier(haulingId); + e.setHaulingIdentifier(haulingId); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUI.jaxx b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUI.jaxx index 14a70be..d8b13db 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUI.jaxx +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUI.jaxx @@ -20,12 +20,12 @@ #L% --> -<fr.ird.observe.ui.content.ContentUI superGenericType='SetLonglineDto' +<fr.ird.observe.ui.content.ContentUI superGenericType='SetLonglineDetailCompositionDto' contentTitle='{n("observe.longlineDetailComposition.title")}'> <import> fr.ird.observe.ObserveSwingApplicationContext - fr.ird.observe.services.dto.longline.SetLonglineDto + fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto fr.ird.observe.ui.actions.shared.ResetEditUIAction fr.ird.observe.ui.actions.shared.SaveEditUIAction @@ -58,10 +58,10 @@ <BranchlinesTableModel id='branchlinesTableModel' initializer="getModel().getBranchlinesTableModel()"/> <!-- edit bean --> - <SetLonglineDto id='bean'/> + <SetLonglineDetailCompositionDto id='bean'/> <!-- validator --> - <BeanValidator id='validator' autoField='true' beanClass='fr.ird.observe.services.dto.longline.SetLonglineDto' + <BeanValidator id='validator' autoField='true' beanClass='fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto' errorTableModel='{getErrorTableModel()}' context='n1-update-longlineDetailComposition'> </BeanValidator> diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java index 1dd807c..04b5730 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java @@ -22,19 +22,25 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import fr.ird.observe.ObserveSwingApplicationContext; import fr.ird.observe.business.db.DataContext; import fr.ird.observe.business.db.constants.DataContextType; import fr.ird.observe.db.ObserveSwingDataSource; import fr.ird.observe.entities.longline.SectionTemplate; +import fr.ird.observe.entities.longline.SectionWithTemplate; +import fr.ird.observe.entities.longline.SectionWithTemplates; import fr.ird.observe.services.dto.FormDto; +import fr.ird.observe.services.dto.FormDtos; import fr.ird.observe.services.dto.longline.ActivityLonglineDto; import fr.ird.observe.services.dto.longline.BasketDto; import fr.ird.observe.services.dto.longline.BranchlineDto; import fr.ird.observe.services.dto.longline.SectionDto; -import fr.ird.observe.services.dto.longline.SetLonglineDto; -import fr.ird.observe.services.dto.longline.SetLonglineDtos; -import fr.ird.observe.services.service.longline.SetLonglineService; +import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; +import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDtos; +import fr.ird.observe.services.dto.result.SaveResultDto; +import fr.ird.observe.services.service.longline.SetLonglineDetailCompositionService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -47,7 +53,8 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import org.nuiton.validator.NuitonValidatorScope; -import javax.swing.*; +import javax.swing.JComboBox; +import javax.swing.JOptionPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.TableModelEvent; @@ -56,6 +63,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import static org.nuiton.i18n.I18n.t; @@ -66,7 +74,7 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 3.8 */ -public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLonglineDto> { +public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLonglineDetailCompositionDto> { static final String SECTION_TEMPLATES_EDITOR = "sectionTemplatesEditor"; @@ -93,8 +101,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong @Override public void tableChanged(TableModelEvent e) { SectionsTableModel source = (SectionsTableModel) e.getSource(); -// FIXME -// onSectionsTableModelChanged(source.getData()); + onSectionsTableModelChanged(source.getData()); } }; @@ -285,7 +292,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong ContentMode contentMode; - if (dataContext.isSelectedOpen(ActivityLonglineDto.class)) { + if (getOpenDataManager().isOpenActivityLongline(dataContext.getSelectedActivityLonglineId())) { // l'activité est ouverte, mode édition contentMode = ContentMode.UPDATE; @@ -389,9 +396,9 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong // utilisation du mode requis setContentMode(mode); - SetLonglineService setLonglineService = getSetLonglineService(); + SetLonglineDetailCompositionService setLonglineService = getSetLonglineDetailCompositionService(); - FormDto<SetLonglineDto> setLonglineDtoFormDto; + FormDto<SetLonglineDetailCompositionDto> setLonglineDtoFormDto; if (mode == ContentMode.READ) { setLonglineDtoFormDto = setLonglineService.loadToRead(setId); @@ -400,8 +407,12 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } getModel().setFormDto(setLonglineDtoFormDto); - SetLonglineDto bean = getBean(); - SetLonglineDtos.copySetLonglineDto(setLonglineDtoFormDto.getForm(), bean); + SetLonglineDetailCompositionDto bean = getBean(); + SetLonglineDetailCompositionDtos.copySetLonglineDetailCompositionDto(setLonglineDtoFormDto.getForm(), bean); + + FormDto<BranchlineDto> branchlineDtoFormDto = FormDtos.newFormDto(BranchlineDto.class, null, setLonglineDtoFormDto.getLabels()); + + getUi().getBranchlineDetailUI().getModel().setFormDto(branchlineDtoFormDto); //FIXME Validate this default date if (log.isInfoEnabled()) { @@ -410,14 +421,11 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong getBranchlinesTableModel().setDefaultDate(bean.getSettingStartTimeStamp()); getBranchlinesTableModel().setUseTimer(BooleanUtils.isTrue(bean.getMonitored())); - // by default, can generate if there is no section in database - //FIXME -// getModel().setCanGenerate(bean.isSectionEmpty()); + getModel().setCanGenerate(bean.isSectionEmpty()); // TODO Use a cache of templates on setLongline (session scope) - //FIXME -// getSectionTemplatesTableModel().setData(Collections.<SectionTemplate>emptyList()); + getSectionTemplatesTableModel().setData(Lists.<SectionTemplate>newArrayList()); BranchlineUI branchlineDetailUI = getUi().getBranchlineDetailUI(); branchlineDetailUI.edit(null); @@ -426,9 +434,8 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong try { - //FIXME -// List<SectionWithTemplate> section = SectionWithTemplates.getSectionTemplates(bean.getSection()); -// getSectionsTableModel().setData(section); + List<SectionWithTemplate> section = SectionWithTemplates.getSectionTemplates(bean.getSection()); + getSectionsTableModel().setData(section); validationHelper.setObjectValueAdjusting(true); @@ -464,7 +471,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong @Override public void startEditUI(String... binding) { - ContentUIModel<SetLonglineDto> model = getModel(); + ContentUIModel<SetLonglineDetailCompositionDto> model = getModel(); addInfoMessage(t("observe.longlineDetailComposition.message.updating")); super.startEditUI(LonglineDetailCompositionUI.BINDING_GENERATE_ALL_ENABLED, @@ -474,183 +481,39 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } - //FIXME -// @Override -// protected boolean doSave(SetLonglineDto bean, -// DataService dataService, -// DataSource dataSource, -// TopiaEntityBinder<SetLonglineDto> binder) throws Exception { -// -// BranchlineUI branchlineDetailUI = getUi().getBranchlineDetailUI(); -// -// boolean continueSave = true; -// -// if (getUi().getFishingOperationTabPane().getSelectedIndex() == 2) { -// -// BranchlineUIHandler branchlineUIHandler = branchlineDetailUI.getHandler(); -// -// continueSave = branchlineUIHandler.tryToQuit(); -// -// } -// -// if (continueSave) { -// -// SectionsTableModel sectionsTableModel = getSectionsTableModel(); -// SectionWithTemplate selectedSection = sectionsTableModel.getSelectedRow(); -// if (selectedSection != null) { -// -// // flush selected section before save -// flushSection(selectedSection); -// -// } -// -// dataService.update(dataSource, null, bean, getUpdateExecutor()); -// } -// -// return continueSave; -// } - - //FIXME -// @Override -// protected SetLonglineDto onUpdate(TopiaContext tx, Object parentBean, SetLonglineDto beanToSave) throws TopiaException { -// -// Map<String, SectionDto> existingSectionsByTopiaId = Entities.toIdMap(beanToSave.getSection()); -// -// TopiaDAO<SectionDto> sectionsDao = getDataSource().getDAO(tx, SectionDto.class); -// TopiaDAO<BasketDto> basketDao = getDataSource().getDAO(tx, BasketDto.class); -// TopiaDAO<BranchlineDto> branchlineDao = getDataSource().getDAO(tx, BranchlineDto.class); -// -// List<SectionWithTemplate> sections = getSectionsTableModel().getNotEmptyData(); -// -// beanToSave.clearSection(); -// -// for (SectionWithTemplate section : sections) { -// -// Section sectionToSave = persistSection(sectionsDao, -// basketDao, -// branchlineDao, -// existingSectionsByTopiaId, -// section); -// beanToSave.addSection(sectionToSave); -// sectionToSave.setSetLongline(beanToSave); -// -// } -// -// return beanToSave; -// -// } - - //FIXME -// protected Section persistSection(TopiaDAO<Section> sectionsDao, -// TopiaDAO<Basket> basketDao, -// TopiaDAO<Branchline> branchlineDao, -// Map<String, Section> existingSectionsByTopiaId, -// Section section) throws TopiaException { -// -// Section sectionToSave; -// -// if (section.getTopiaId() == null) { -// -// // create -// sectionToSave = sectionsDao.create( -// Section.PROPERTY_SETTING_IDENTIFIER, section.getSettingIdentifier(), -// Section.PROPERTY_HAULING_IDENTIFIER, section.getHaulingIdentifier()); -// -// } else { -// -// sectionToSave = existingSectionsByTopiaId.get(section.getTopiaId()); -// -// } -// -// TopiaEntityBinder<Section> sectionBinder = getModel().getSectionBinder(); -// sectionBinder.copyExcluding(section, sectionToSave, Section.PROPERTY_BASKET); -// -// Map<String, Basket> existingBasketsByTopiaId = Entities.toIdMap(sectionToSave.getBasket()); -// -// List<Basket> baskets = section.getBasket(); -// sectionToSave.clearBasket(); -// -// for (Basket basket : baskets) { -// -// Basket basketToSave = persistBasket(basketDao, -// branchlineDao, -// existingBasketsByTopiaId, -// basket); -// sectionToSave.addBasket(basketToSave); -// -// } -// -// return sectionToSave; -// -// } - - //FIXME -// protected Basket persistBasket(TopiaDAO<Basket> basketDao, -// TopiaDAO<Branchline> branchlineDao, -// Map<String, Basket> existingBasketsByTopiaId, -// Basket basket) throws TopiaException { -// -// Basket basketToSave; -// -// if (basket.getTopiaId() == null) { -// -// // create -// basketToSave = basketDao.create( -// Basket.PROPERTY_SETTING_IDENTIFIER, basket.getSettingIdentifier(), -// Basket.PROPERTY_HAULING_IDENTIFIER, basket.getHaulingIdentifier()); -// -// } else { -// -// basketToSave = existingBasketsByTopiaId.get(basket.getTopiaId()); -// -// } -// -// TopiaEntityBinder<Basket> basketBinder = getModel().getBasketBinder(); -// basketBinder.copyExcluding(basket, basketToSave, Basket.PROPERTY_BRANCHLINE); -// -// Map<String, Branchline> existingBranchlinesByTopiaId = Entities.toIdMap(basketToSave.getBranchline()); -// -// basketToSave.clearBranchline(); -// -// List<Branchline> branchlines = basket.getBranchline(); -// -// for (Branchline branchline : branchlines) { -// -// Branchline branchlineToSave = persistBranchline(branchlineDao, existingBranchlinesByTopiaId, branchline); -// basketToSave.addBranchline(branchlineToSave); -// -// } -// -// return basketToSave; -// -// } - - //FIXME -// protected Branchline persistBranchline(TopiaDAO<Branchline> branchlineDao, -// Map<String, Branchline> existingBranchlinesByTopiaId, -// Branchline branchline) throws TopiaException { -// -// Branchline branchlineToSave; -// -// if (branchline.getTopiaId() == null) { -// -// // create -// branchlineToSave = branchlineDao.create( -// Branchline.PROPERTY_SETTING_IDENTIFIER, branchline.getSettingIdentifier(), -// Branchline.PROPERTY_HAULING_IDENTIFIER, branchline.getHaulingIdentifier()); -// -// } else { -// -// branchlineToSave = existingBranchlinesByTopiaId.get(branchline.getTopiaId()); -// -// } -// -// TopiaEntityBinder<Branchline> branchlineBinder = getModel().getBranchlineBinder(); -// branchlineBinder.copy(branchline, branchlineToSave); -// -// return branchlineToSave; -// -// } + @Override + protected boolean doSave(SetLonglineDetailCompositionDto bean) throws Exception { + + BranchlineUI branchlineDetailUI = getUi().getBranchlineDetailUI(); + + boolean continueSave = true; + + if (getUi().getFishingOperationTabPane().getSelectedIndex() == 2) { + + BranchlineUIHandler branchlineUIHandler = branchlineDetailUI.getHandler(); + + continueSave = branchlineUIHandler.tryToQuit(); + + } + + if (continueSave) { + + SectionsTableModel sectionsTableModel = getSectionsTableModel(); + SectionWithTemplate selectedSection = sectionsTableModel.getSelectedRow(); + if (selectedSection != null) { + + // flush selected section before save + flushSection(selectedSection); + + } + + SaveResultDto saveResult = getSetLonglineDetailCompositionService().save(bean); + bean.setLastUpdate(saveResult.getLastUpdate()); + + } + + return continueSave; + } public void generateAllSections() { @@ -658,7 +521,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong log.info("Generate all sections."); } - SetLonglineDto bean = getBean(); + SetLonglineDetailCompositionDto bean = getBean(); Integer nbSections = bean.getTotalSectionsCount(); Integer basketsCount = bean.getBasketsPerSectionCount(); Integer nbBranchlines = bean.getBranchlinesPerBasketCount(); @@ -666,35 +529,34 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong SectionTemplate template = null; SectionTemplatesTableModel sectionTemplatesTableModel = getSectionTemplatesTableModel(); - //FIXME -// List<SectionTemplate> sectionTemplates = sectionTemplatesTableModel.getNotEmptyData(); -// if (sectionTemplates.size() == 1) { -// -// template = sectionTemplates.get(0); -// -// boolean compiliantWithBasketCount = template.isCompiliantWithBasketCount(basketsCount); -// if (!compiliantWithBasketCount) { -// -// if (log.isWarnEnabled()) { -// log.warn("sectionTemplate " + template + " is not compliant with basketCount: " + basketsCount); -// } -// -// UIHelper.displayWarning(t("observe.longlineDetailComposition.title.section.cant.use.firstTemplate"), t("observe.longlineDetailComposition.firstTemplate.template.notCompilant.basketCount", template.getFloatlineLengths(), basketsCount)); -// -// template = null; -// -// } -// -// } -// -// boolean usingTemplate = template != null; -// -// if (usingTemplate) { -// -// if (log.isInfoEnabled()) { -// log.info("Will use sectionTemplate: " + template); -// } -// } + List<SectionTemplate> sectionTemplates = sectionTemplatesTableModel.getNotEmptyData(); + if (sectionTemplates.size() == 1) { + + template = sectionTemplates.get(0); + + boolean compiliantWithBasketCount = template.isCompiliantWithBasketCount(basketsCount); + if (!compiliantWithBasketCount) { + + if (log.isWarnEnabled()) { + log.warn("sectionTemplate " + template + " is not compliant with basketCount: " + basketsCount); + } + + UIHelper.displayWarning(t("observe.longlineDetailComposition.title.section.cant.use.firstTemplate"), t("observe.longlineDetailComposition.firstTemplate.template.notCompilant.basketCount", template.getFloatlineLengths(), basketsCount)); + + template = null; + + } + + } + + boolean usingTemplate = template != null; + + if (usingTemplate) { + + if (log.isInfoEnabled()) { + log.info("Will use sectionTemplate: " + template); + } + } validationHelper.setObjectValueAdjusting(true); @@ -704,46 +566,44 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong BasketsTableModel basketsTableModel = getBasketsTableModel(); BranchlinesTableModel branchlinesTableModel = getBranchlinesTableModel(); - //FIXME -// List<SectionWithTemplate> sections = new ArrayList<SectionWithTemplate>(nbSections); + List<SectionWithTemplate> sections = new ArrayList<SectionWithTemplate>(nbSections); for (int sectionNumber = 0; sectionNumber < nbSections; sectionNumber++) { - //FIXME -// SectionWithTemplate section = sectionsTableModel.createNewRow(); -// sections.add(section); - -// for (int basketNumber = 0; basketNumber < basketsCount; basketNumber++) { -// -// Basket basket = basketsTableModel.createNewRow(); -// section.addBasket(basket); -// -// for (int branchlineNumber = 0; branchlineNumber < nbBranchlines; branchlineNumber++) { -// -// Branchline branchline = branchlinesTableModel.createNewRow(); -// basket.addBranchline(branchline); -// -// } -// -// branchlinesTableModel.rearrangeIds(basket.getBranchline()); -// -// } -// -// List<Basket> baskets = section.getBasket(); -// basketsTableModel.rearrangeIds(baskets); -// -// if (usingTemplate) { -// -// section.setSectionTemplate(template); -// template.applyToBaskets(baskets); -// -// } + SectionWithTemplate section = sectionsTableModel.createNewRow(); + sections.add(section); + + for (int basketNumber = 0; basketNumber < basketsCount; basketNumber++) { + + BasketDto basket = basketsTableModel.createNewRow(); + section.addBasket(basket); + + for (int branchlineNumber = 0; branchlineNumber < nbBranchlines; branchlineNumber++) { + + BranchlineDto branchline = branchlinesTableModel.createNewRow(); + basket.addBranchline(branchline); + + } + + LinkedList<BranchlineDto> branchlines = Lists.newLinkedList(basket.getBranchline()); + branchlinesTableModel.rearrangeIds(branchlines); + + } + + List<BasketDto> baskets = Lists.newLinkedList(section.getBasket()); + basketsTableModel.rearrangeIds(baskets); + + if (usingTemplate) { + + section.setSectionTemplate(template); + template.applyToBaskets(baskets); + + } } - //FIXME -// sectionsTableModel.rearrangeIds(sections); -// sectionsTableModel.setData(sections); + sectionsTableModel.rearrangeIds(sections); + sectionsTableModel.setData(sections); getModel().setModified(true); @@ -765,14 +625,13 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } boolean canDelete = true; - //FIXME -// for (SectionWithTemplate sectionWithTemplate : getSectionsTableModel().getNotEmptyData()) { -// -// if (!canDeleteSection(sectionWithTemplate.getDelegate())) { -// canDelete = false; -// break; -// } -// } + for (SectionWithTemplate sectionWithTemplate : getSectionsTableModel().getNotEmptyData()) { + + if (!canDeleteSection(sectionWithTemplate.getDelegate())) { + canDelete = false; + break; + } + } if (!canDelete) { @@ -805,8 +664,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong try { - //FIXME -// getSectionsTableModel().setData(Collections.<SectionWithTemplate>emptyList()); + getSectionsTableModel().setData(Lists.<SectionWithTemplate>newArrayList()); getModel().setModified(true); } finally { @@ -825,12 +683,11 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong if (!selectionEmpty) { - //FIXME -// SectionTemplate data = getSectionTemplatesTableModel().getSelectedRow(); -// -// if (log.isInfoEnabled()) { -// log.info("Delete: " + data); -// } + SectionTemplate data = getSectionTemplatesTableModel().getSelectedRow(); + + if (log.isInfoEnabled()) { + log.info("Delete: " + data); + } ObserveMainUI mainUI = ObserveSwingApplicationContext.get().getObserveMainUI(); int response = UIHelper.askUser(mainUI, @@ -861,36 +718,35 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong if (!selectionEmpty) { - //FIXME -// SectionWithTemplate selectedSection = tableModel.getSelectedRow(); -// -// boolean canDelete = canDeleteSection(selectedSection.getDelegate()); -// -// if (!canDelete) { -// // there is some references, can't delete -// UIHelper.displayWarning(t("observe.section.cant.delete.title"), t("observe.section.cant.delete.message")); -// return; -// } -// -// boolean accept = UIHelper.confirmForEntityDelete(ui, Section.class, selectedSection); + SectionWithTemplate selectedSection = tableModel.getSelectedRow(); + + boolean canDelete = canDeleteSection(selectedSection.getDelegate()); + + if (!canDelete) { + // there is some references, can't delete + UIHelper.displayWarning(t("observe.section.cant.delete.title"), t("observe.section.cant.delete.message")); + return; + } + + boolean accept = UIHelper.confirmForEntityDelete(ui, SectionDto.class, selectedSection); ObserveMainUI mainUI = ObserveSwingApplicationContext.get().getObserveMainUI(); mainUI.setBusy(false); - //FIXME -// if (!accept) { -// return; -// } -// -// if (log.isInfoEnabled()) { -// log.info("Delete section: " + sectionDecorator.toString(selectedSection)); -// } + if (!accept) { + return; + } + + if (log.isInfoEnabled()) { + log.info("Delete section: " + sectionDecorator.toString(selectedSection)); + } validationHelper.setObjectValueAdjusting(true); skipSavePreviousSelectedSection = true; try { + getBean().removeSection(tableModel.getSelectedRow().getDelegate()); tableModel.removeSelectedRow(); } finally { @@ -914,6 +770,13 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong SectionsTableModel tableModel = getSectionsTableModel(); tableModel.insertBeforeSelectedRow(); + SectionWithTemplate newSectionWithTemplate = tableModel.getSelectedRow(); + int selectedRowIndex = tableModel.getSelectedRowIndex(); + List<SectionDto> sections = Lists.newArrayList(getBean().getSection()); + sections.add(selectedRowIndex, newSectionWithTemplate.getDelegate()); + getBean().getSection().clear(); + getBean().addAllSection(sections); + } finally { validationHelper.setObjectValueAdjusting(false); @@ -932,6 +795,13 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong SectionsTableModel tableModel = getSectionsTableModel(); tableModel.insertAfterSelectedRow(); + SectionWithTemplate newSectionWithTemplate = tableModel.getSelectedRow(); + int selectedRowIndex = tableModel.getSelectedRowIndex(); + List<SectionDto> sections = Lists.newArrayList(getBean().getSection()); + sections.add(selectedRowIndex, newSectionWithTemplate.getDelegate()); + getBean().getSection().clear(); + getBean().addAllSection(sections); + } finally { validationHelper.setObjectValueAdjusting(false); @@ -978,8 +848,7 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong try { - //FIXME -// getSectionsTableModel().getSelectedRow().removeBasket(selectedBasket); + getSectionsTableModel().getSelectedRow().removeBasket(selectedBasket); tableModel.removeSelectedRow(); } finally { @@ -1006,12 +875,15 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong BasketDto newBasket = tableModel.getSelectedRow(); int selectedRowIndex = tableModel.getSelectedRowIndex(); - //FIXME -// SectionWithTemplate selectedSection = getSectionsTableModel().getSelectedRow(); -// if (selectedSection.isBasketEmpty()) { -// selectedSection.setBasket(new ArrayList<Basket>()); -// } -// selectedSection.getBasket().add(selectedRowIndex, newBasket); + SectionWithTemplate selectedSection = getSectionsTableModel().getSelectedRow(); + if (selectedSection.isBasketEmpty()) { + selectedSection.setBasket(Sets.<BasketDto>newLinkedHashSet()); + } + List<BasketDto> baskets = Lists.newArrayList(selectedSection.getBasket()); + baskets.add(selectedRowIndex, newBasket); + selectedSection.getBasket().clear(); + selectedSection.addAllBasket(baskets); + getBasketsTableModel().setData(baskets); } finally { @@ -1033,12 +905,15 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong BasketDto newBasket = tableModel.getSelectedRow(); int selectedRowIndex = tableModel.getSelectedRowIndex(); - //FIXME -// SectionWithTemplate selectedSection = getSectionsTableModel().getSelectedRow(); -// if (selectedSection.isBasketEmpty()) { -// selectedSection.setBasket(new ArrayList<Basket>()); -// } -// getSectionsTableModel().getSelectedRow().getBasket().add(selectedRowIndex, newBasket); + SectionWithTemplate selectedSection = getSectionsTableModel().getSelectedRow(); + if (selectedSection.isBasketEmpty()) { + selectedSection.setBasket(Sets.<BasketDto>newLinkedHashSet()); + } + List<BasketDto> baskets = Lists.newArrayList(selectedSection.getBasket()); + baskets.add(selectedRowIndex, newBasket); + selectedSection.getBasket().clear(); + selectedSection.addAllBasket(baskets); + getBasketsTableModel().setData(baskets); } finally { @@ -1113,10 +988,14 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong int selectedRowIndex = tableModel.getSelectedRowIndex(); BasketDto selectedBasket = getBasketsTableModel().getSelectedRow(); if (selectedBasket.isBranchlineEmpty()) { - selectedBasket.setBranchline(new LinkedHashSet<BranchlineDto>()); + selectedBasket.setBranchline(Sets.<BranchlineDto>newLinkedHashSet()); } - //FIXME -// selectedBasket.getBranchline().add(selectedRowIndex, newBranchline); + + List<BranchlineDto> branchlines = Lists.newArrayList(selectedBasket.getBranchline()); + branchlines.add(selectedRowIndex, newBranchline); + selectedBasket.getBranchline().clear(); + selectedBasket.addAllBranchline(branchlines); + getBranchlinesTableModel().setData(branchlines); } finally { @@ -1140,10 +1019,14 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong int selectedRowIndex = tableModel.getSelectedRowIndex(); BasketDto selectedBasket = getBasketsTableModel().getSelectedRow(); if (selectedBasket.isBranchlineEmpty()) { - selectedBasket.setBranchline(new LinkedHashSet<BranchlineDto>()); + selectedBasket.setBranchline(Sets.<BranchlineDto>newLinkedHashSet()); } - //FIXME -// selectedBasket.getBranchline().add(selectedRowIndex, newBranchline); + List<BranchlineDto> branchlines = Lists.newArrayList(selectedBasket.getBranchline()); + branchlines.add(selectedRowIndex, newBranchline); + selectedBasket.getBranchline().clear(); + selectedBasket.addAllBranchline(branchlines); + getBranchlinesTableModel().setData(branchlines); + } finally { @@ -1173,16 +1056,15 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } - //FIXME -// protected void onSectionsTableModelChanged(List<SectionWithTemplate> data) { -// -// if (log.isInfoEnabled()) { -// log.info("Sections was changed, new size: " + data.size()); -// } -// -// validationHelper.whenSectionChanged(); -// -// } + protected void onSectionsTableModelChanged(List<SectionWithTemplate> data) { + + if (log.isInfoEnabled()) { + log.info("Sections was changed, new size: " + data.size()); + } + + validationHelper.whenSectionChanged(); + + } protected void onModelCanGenerateChanged(Boolean canGenerate) { @@ -1216,12 +1098,8 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } - //FIXME -// List<BasketDto> baskets = newSection == null ? null : newSection.getBasket(); -// if (baskets == null) { -// baskets = Collections.emptyList(); -// } -// getBasketsTableModel().setData(baskets); + List<BasketDto> baskets = newSection == null ? Lists.<BasketDto>newArrayList() : Lists.newArrayList(newSection.getBasket()); + getBasketsTableModel().setData(baskets); } finally { @@ -1235,11 +1113,10 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong if (newTemplate != null) { - //FIXME -// SectionWithTemplate selectedSection = getSectionsTableModel().getSelectedRow(); -// if (log.isInfoEnabled()) { -// log.info("Will apply template: " + newTemplate + " to section: " + sectionDecorator.toString(selectedSection)); -// } + SectionWithTemplate selectedSection = getSectionsTableModel().getSelectedRow(); + if (log.isInfoEnabled()) { + log.info("Will apply template: " + newTemplate + " to section: " + sectionDecorator.toString(selectedSection)); + } validationHelper.setObjectValueAdjusting(true); @@ -1403,10 +1280,9 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong if (getModel().isCanGenerate()) { // update section templates list - //FIXME -// List<SectionTemplate> sectionTemplates = getSectionTemplatesTableModel().getNotEmptyData(); -// JComboBox comboBox = (JComboBox) getUi().getSectionsTable().getClientProperty(SECTION_TEMPLATES_EDITOR); -// LonglineDetailCompositionUIInitializer.prepareComboBoxData(comboBox, sectionTemplates); + List<SectionTemplate> sectionTemplates = getSectionTemplatesTableModel().getNotEmptyData(); + JComboBox comboBox = (JComboBox) getUi().getSectionsTable().getClientProperty(SECTION_TEMPLATES_EDITOR); + LonglineDetailCompositionUIInitializer.prepareComboBoxData(comboBox, sectionTemplates); //FIXME See why templates are not well reselect in cell editor //FIXME See cell editor does not loose focus and empty selection when losing focus @@ -1509,117 +1385,24 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong protected boolean canDeleteSection(SectionDto section) { - boolean canDelete = true; - - if (section.getId() != null) { - //FIXME -// try { -// -// EntityMap allUsages = getDataService().findAllUsages(getDataSource(), section); -// allUsages.remove(SetLongline.class); -// -// if (!allUsages.isEmpty()) { -// -// canDelete = false; -// -// } else { -// -// if (!section.isBasketEmpty()) { -// -// for (Basket basket : section.getBasket()) { -// -// if (!canDeleteBasket(basket)) { -// -// canDelete = false; -// break; -// -// } -// -// } -// } -// -// } - -// } catch (DataSourceException e) { -// throw new ObserveTechnicalException("Could not find all usage of selected section", e); -// } - } - - return canDelete; + return section.isNotPersisted() || getSetLonglineDetailCompositionService().canDeleteSection(section.getId()); } protected boolean canDeleteBasket(BasketDto basket) { - boolean canDelete = true; - - if (basket.getId() != null) { - //FIXME -// try { -// -// EntityMap allUsages = getDataService().findAllUsages(getDataSource(), basket); -// allUsages.remove(Section.class); -// -// if (!allUsages.isEmpty()) { -// -// canDelete = false; -// -// } else { -// -// if (!basket.isBranchlineEmpty()) { -// -// for (Branchline branchline : basket.getBranchline()) { -// -// if (!canDeleteBranchline(branchline)) { -// -// canDelete = false; -// break; -// -// } -// -// } -// -// } -// -// } -// -// } catch (DataSourceException e) { -// throw new ObserveTechnicalException("Could not find all usage of selected section", e); -// } - } - - return canDelete; + return basket.isNotPersisted() || getSetLonglineDetailCompositionService().canDeleteBasket(basket.getId()); } protected boolean canDeleteBranchline(BranchlineDto branchline) { - boolean canDelete = true; - - if (branchline.getId() != null) { - //FIXME -// try { -// -// EntityMap allUsages = getDataService().findAllUsages(getDataSource(), branchline); -// allUsages.remove(Basket.class); -// -// if (!allUsages.isEmpty()) { -// -// canDelete = false; -// -// } -// -// } catch (DataSourceException e) { -// throw new ObserveTechnicalException("Could not find all usage of selected branchline", e); -// } - } - - return canDelete; + return branchline.isNotPersisted() || getSetLonglineDetailCompositionService().canDeleteBranchline(branchline.getId()); } - protected SetLonglineService getSetLonglineService() { - return ObserveSwingApplicationContext.get().newService(SetLonglineService.class); + protected SetLonglineDetailCompositionService getSetLonglineDetailCompositionService() { + return ObserveSwingApplicationContext.get().newService(SetLonglineDetailCompositionService.class); } } \ No newline at end of file diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java index 37dbbcd..e1a991b 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIInitializer.java @@ -23,7 +23,7 @@ package fr.ird.observe.ui.content.impl.longline; */ import fr.ird.observe.entities.longline.SectionTemplate; -import fr.ird.observe.services.dto.longline.SetLonglineDto; +import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; import fr.ird.observe.ui.DecoratorService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentUIInitializer; @@ -32,9 +32,13 @@ import fr.ird.observe.ui.util.table.EditableTableModelSupport; import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor; import org.nuiton.decorator.Decorator; -import javax.swing.*; +import javax.swing.JComboBox; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; import javax.swing.table.TableCellRenderer; -import java.awt.*; +import java.awt.Container; import java.io.Serializable; import java.util.Collections; @@ -46,7 +50,7 @@ import static org.nuiton.i18n.I18n.n; * @author Tony Chemit - chemit@codelutin.com * @since 3.10 */ -public class LonglineDetailCompositionUIInitializer extends ContentUIInitializer<SetLonglineDto, LonglineDetailCompositionUI> { +public class LonglineDetailCompositionUIInitializer extends ContentUIInitializer<SetLonglineDetailCompositionDto, LonglineDetailCompositionUI> { public LonglineDetailCompositionUIInitializer(LonglineDetailCompositionUI ui) { super(ui); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIModel.java index 26e71d7..1570c25 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIModel.java @@ -22,7 +22,7 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.services.dto.longline.SetLonglineDto; +import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; import fr.ird.observe.ui.content.ContentUIModel; /** @@ -31,7 +31,7 @@ import fr.ird.observe.ui.content.ContentUIModel; * @author Tony Chemit - chemit@codelutin.com * @since 3.8 */ -public class LonglineDetailCompositionUIModel extends ContentUIModel<SetLonglineDto> { +public class LonglineDetailCompositionUIModel extends ContentUIModel<SetLonglineDetailCompositionDto> { public static final String PROPERTY_CAN_GENERATE = "canGenerate"; @@ -61,7 +61,7 @@ public class LonglineDetailCompositionUIModel extends ContentUIModel<SetLongline public LonglineDetailCompositionUIModel() { - super(SetLonglineDto.class); + super(SetLonglineDetailCompositionDto.class); this.sectionTemplatesTableModel = new SectionTemplatesTableModel(); this.sectionsTableModel = new SectionsTableModel(this); this.basketsTableModel = new BasketsTableModel(this); @@ -129,103 +129,4 @@ public class LonglineDetailCompositionUIModel extends ContentUIModel<SetLongline firePropertyChange(PROPERTY_GENERATE_TAB_VALID, null, generateTabValid); } - //FIXME -// public TopiaEntityBinder<BasketDto> getBasketBinder() { -// if (basketBinder == null) { -// -// String binderName = getClass().getName() + "-open"; -// -// BinderService binderService = ObserveServiceHelper.get().getBinderService(); -// basketBinder = binderService.getTopiaBinder(Basket.class, binderName); -// -// if (basketBinder == null) { -// -// BinderModelBuilder<BasketDto, BasketDto> builderBasket = binderService.newBinderBuilder( -// BasketDto.class, -// BasketDto.PROPERTY_BRANCHLINE, -// BasketDto.PROPERTY_SETTING_IDENTIFIER, -// BasketDto.PROPERTY_HAULING_IDENTIFIER, -// BasketDto.PROPERTY_FLOATLINE1_LENGTH, -// BasketDto.PROPERTY_FLOATLINE2_LENGTH); -// builderBasket.addCollectionBinder(getBranchlineBinder(), BasketDto.PROPERTY_BRANCHLINE); -// -// basketBinder = binderService.registerTopiaBinder(Basket.class, builderBasket, binderName); -// -// } -// -// } -// return basketBinder; -// } -// - //FIXME -// public TopiaEntityBinder<BranchlineDto> getBranchlineBinder() { -// if (branchlineBinder == null) { -// -// String binderName = getClass().getName() + "-open"; -// -// BinderService binderService = ObserveServiceHelper.get().getBinderService(); -// branchlineBinder = binderService.getTopiaBinder(Branchline.class, binderName); -// -// if (branchlineBinder == null) { -// -// BinderModelBuilder<Branchline, Branchline> builderBranchline = binderService.newBinderBuilder( -// Branchline.class, -// Branchline.PROPERTY_SETTING_IDENTIFIER, -// Branchline.PROPERTY_HAULING_IDENTIFIER, -// Branchline.PROPERTY_TRACELINE_LENGTH, -// Branchline.PROPERTY_BRANCHLINE_LENGTH, -// Branchline.PROPERTY_COMMENT, -// Branchline.PROPERTY_TOP_TYPE, -// Branchline.PROPERTY_TRACELINE_TYPE, -// Branchline.PROPERTY_DEPTH_RECORDER, -// Branchline.PROPERTY_HOOK_LOST, -// Branchline.PROPERTY_TRACE_CUT_OFF, -// Branchline.PROPERTY_WEIGHTED_SWIVEL, -// Branchline.PROPERTY_SWIVEL_WEIGHT, -// Branchline.PROPERTY_WEIGHTED_SNAP, -// Branchline.PROPERTY_SNAP_WEIGHT, -// Branchline.PROPERTY_BAIT_TYPE, -// Branchline.PROPERTY_BAIT_SETTING_STATUS, -// Branchline.PROPERTY_BAIT_HAULING_STATUS, -// Branchline.PROPERTY_HOOK_TYPE, -// Branchline.PROPERTY_HOOK_SIZE, -// Branchline.PROPERTY_HOOK_OFFSET, -// Branchline.PROPERTY_TIMER, -// Branchline.PROPERTY_TIME_SINCE_CONTACT, -// Branchline.PROPERTY_TIMER_TIME_ON_BOARD); -// -// branchlineBinder = binderService.registerTopiaBinder(Branchline.class, builderBranchline, binderName); -// } -// -// } -// return branchlineBinder; -// } - - //FIXME -// public TopiaEntityBinder<Section> getSectionBinder() { -// if (sectionBinder == null) { -// -// String binderName = getClass().getName() + "-open"; -// -// BinderService binderService = ObserveServiceHelper.get().getBinderService(); -// sectionBinder = binderService.getTopiaBinder(Section.class, binderName); -// -// if (sectionBinder == null) { -// -// BinderModelBuilder<Section, Section> builderSection = binderService.newBinderBuilder( -// Section.class, -// Section.PROPERTY_SET_LONGLINE, -// Section.PROPERTY_BASKET, -// Section.PROPERTY_SETTING_IDENTIFIER, -// Section.PROPERTY_HAULING_IDENTIFIER); -// builderSection.addCollectionBinder(getBasketBinder(), Section.PROPERTY_BASKET); -// -// sectionBinder = binderService.registerTopiaBinder(Section.class, builderSection, binderName); -// -// } -// -// } -// return sectionBinder; -// } - } \ No newline at end of file diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIValidationHelper.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIValidationHelper.java index f5f9c86..d998ac9 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIValidationHelper.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIValidationHelper.java @@ -25,10 +25,11 @@ package fr.ird.observe.ui.content.impl.longline; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import fr.ird.observe.ui.DecoratorService; +import fr.ird.observe.entities.longline.SectionWithTemplate; import fr.ird.observe.services.dto.longline.BasketDto; import fr.ird.observe.services.dto.longline.BranchlineDto; import fr.ird.observe.services.dto.longline.SectionDto; +import fr.ird.observe.ui.DecoratorService; import fr.ird.observe.ui.util.ObserveSwingValidatorMessageTableModel; import jaxx.runtime.validator.swing.SwingValidator; import jaxx.runtime.validator.swing.SwingValidatorMessage; @@ -102,15 +103,15 @@ public class LonglineDetailCompositionUIValidationHelper { if (log.isInfoEnabled()) { log.info("Rebuild messages, section model changes."); } -//FIXME -// List<SectionWithTemplate> notEmptyData = model.getSectionsTableModel().getNotEmptyData(); -// List<SwingValidatorMessage> messages = validatorService.validateSections(notEmptyData); -// -// removeOldMessages(); -// -// errorTableModel.addMessages(messages); -// -// model.setCompositionTabValid(messages.isEmpty()); + + List<SectionWithTemplate> notEmptyData = model.getSectionsTableModel().getNotEmptyData(); + List<SwingValidatorMessage> messages = validatorService.validateSections(notEmptyData); + + removeOldMessages(); + + errorTableModel.addMessages(messages); + + model.setCompositionTabValid(messages.isEmpty()); } } @@ -122,18 +123,14 @@ public class LonglineDetailCompositionUIValidationHelper { if (log.isInfoEnabled()) { log.info("Rebuild messages, basket model changes."); } - - //FIXME -// List<SectionWithTemplate> notEmptyData = model.getSectionsTableModel().getNotEmptyData(); -// List<SwingValidatorMessage> messages = validatorService.validateSections(notEmptyData); + List<SectionWithTemplate> notEmptyData = model.getSectionsTableModel().getNotEmptyData(); + List<SwingValidatorMessage> messages = validatorService.validateSections(notEmptyData); removeOldMessages(); - //FIXME -// errorTableModel.addMessages(messages); + errorTableModel.addMessages(messages); - //FIXME -// model.setCompositionTabValid(messages.isEmpty()); + model.setCompositionTabValid(messages.isEmpty()); } @@ -147,17 +144,14 @@ public class LonglineDetailCompositionUIValidationHelper { log.info("Rebuild messages, branchline model changes."); } - //FIXME -// List<SectionWithTemplate> notEmptyData = model.getSectionsTableModel().getNotEmptyData(); -// List<SwingValidatorMessage> messages = validatorService.validateSections(notEmptyData); + List<SectionWithTemplate> notEmptyData = model.getSectionsTableModel().getNotEmptyData(); + List<SwingValidatorMessage> messages = validatorService.validateSections(notEmptyData); removeOldMessages(); - //FIXME -// errorTableModel.addMessages(messages); + errorTableModel.addMessages(messages); - //FIXME -// model.setCompositionTabValid(messages.isEmpty()); + model.setCompositionTabValid(messages.isEmpty()); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SectionTemplatesTableModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SectionTemplatesTableModel.java index 6a91680..ebf526a 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SectionTemplatesTableModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SectionTemplatesTableModel.java @@ -22,8 +22,9 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.services.dto.IdDto; +import fr.ird.observe.entities.longline.SectionTemplate; import fr.ird.observe.ui.util.table.EditableTableModelSupport; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,8 +37,7 @@ import java.util.Set; * @author Tony Chemit - chemit@codelutin.com * @since 3.10 */ -//FIXME -public class SectionTemplatesTableModel extends EditableTableModelSupport<IdDto> {//FIXME <SectionTemplate> { +public class SectionTemplatesTableModel extends EditableTableModelSupport<SectionTemplate> { private static final long serialVersionUID = 1L; @@ -49,24 +49,20 @@ public class SectionTemplatesTableModel extends EditableTableModelSupport<IdDto> } @Override - public boolean isRowNotEmpty(IdDto row) { - //FIXME -// return !(StringUtils.isBlank(row.getId()) && StringUtils.isBlank(row.getFloatlineLengths())); - return false; + public boolean isRowNotEmpty(SectionTemplate row) { + return !(StringUtils.isBlank(row.getId()) && StringUtils.isBlank(row.getFloatlineLengths())); } @Override - public boolean isRowValid(IdDto row) { - //FIXME -// return StringUtils.isNotBlank(row.getId()) && -// StringUtils.isNotBlank(row.getFloatlineLengths()) && -// row.isFloatlineLengthsValid(); - return false; + public boolean isRowValid(SectionTemplate row) { + return StringUtils.isNotBlank(row.getId()) && + StringUtils.isNotBlank(row.getFloatlineLengths()) && + row.isFloatlineLengthsValid(); } @Override - protected IdDto createNewRow() { - return null; + protected SectionTemplate createNewRow() { + return new SectionTemplate(); } @Override @@ -76,52 +72,46 @@ public class SectionTemplatesTableModel extends EditableTableModelSupport<IdDto> @Override public Object getValueAt(int rowIndex, int columnIndex) { + SectionTemplate measure = data.get(rowIndex); + Object result; - //FIXME -// SectionTemplate measure = data.get(rowIndex); -// Object result; -// -// switch (columnIndex) { -// case 0: -// -// result = measure.getId(); -// break; -// -// case 1: -// -// result = measure.getFloatlineLengths(); -// break; -// -// default: -// throw new IllegalStateException("Can't come here"); -// } -// -// return result; - - return null; + switch (columnIndex) { + case 0: + + result = measure.getId(); + break; + + case 1: + + result = measure.getFloatlineLengths(); + break; + + default: + throw new IllegalStateException("Can't come here"); + } + + return result; } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + SectionTemplate measure = data.get(rowIndex); + + switch (columnIndex) { + case 0: + + measure.setId((String) aValue); + break; + + case 1: + + measure.setFloatlineLengths((String) aValue); + break; + + default: + throw new IllegalStateException("Can't come here"); + } - //FIXME -// SectionTemplate measure = data.get(rowIndex); -// -// switch (columnIndex) { -// case 0: -// -// measure.setId((String) aValue); -// break; -// -// case 1: -// -// measure.setFloatlineLengths((String) aValue); -// break; -// -// default: -// throw new IllegalStateException("Can't come here"); -// } -// setModified(true); } @@ -134,20 +124,19 @@ public class SectionTemplatesTableModel extends EditableTableModelSupport<IdDto> // check that we are using unique ids Set<String> ids = new HashSet<String>(); - //FIXME -// for (SectionTemplate sectionTemplate : data) { -// -// boolean add = ids.add(sectionTemplate.getId()); -// if (!add) { -// -// if (log.isWarnEnabled()) { -// log.warn("Template identifiants (" + sectionTemplate.getId() + ") are not unique."); -// } -// newValidState = false; -// break; -// } -// -// } + for (SectionTemplate sectionTemplate : data) { + + boolean add = ids.add(sectionTemplate.getId()); + if (!add) { + + if (log.isWarnEnabled()) { + log.warn("Template identifiants (" + sectionTemplate.getId() + ") are not unique."); + } + newValidState = false; + break; + } + + } } return newValidState; diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SectionsTableModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SectionsTableModel.java index f9c9600..5c191bf 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SectionsTableModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SectionsTableModel.java @@ -22,7 +22,8 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.services.dto.IdDto; +import fr.ird.observe.entities.longline.SectionTemplate; +import fr.ird.observe.entities.longline.SectionWithTemplate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -32,8 +33,7 @@ import org.apache.commons.logging.LogFactory; * @author Tony Chemit - chemit@codelutin.com * @since 3.10 */ -//FIXME -public class SectionsTableModel extends LonglineCompositionTableModelSupport<IdDto> {//FIXME <SectionWithTemplate> { +public class SectionsTableModel extends LonglineCompositionTableModelSupport<SectionWithTemplate> { public static final String TEMPLATE_PROPERTY = "template"; @@ -47,12 +47,8 @@ public class SectionsTableModel extends LonglineCompositionTableModelSupport<IdD } @Override - //FIXME -// protected SectionWithTemplate createNewRow() { -// return new SectionWithTemplateImpl(); -// } - protected IdDto createNewRow() { - return null; + protected SectionWithTemplate createNewRow() { + return new SectionWithTemplate(); } @Override @@ -96,92 +92,88 @@ public class SectionsTableModel extends LonglineCompositionTableModelSupport<IdD @Override public Object getValueAt(int rowIndex, int columnIndex) { + SectionWithTemplate row = data.get(rowIndex); + Object result; - //FIXME -// SectionWithTemplate row = data.get(rowIndex); -// Object result; -// -// switch (columnIndex) { -// case 0: -// -// result = row.getSettingIdentifier(); -// break; -// -// case 1: -// -// result = row.getHaulingIdentifier(); -// break; -// -// case 2: -// -// result = row.getSectionTemplate(); -// break; -// -// default: -// throw new IllegalStateException("Can't come here"); -// } -// -// return result; -return null; + switch (columnIndex) { + case 0: + + result = row.getSettingIdentifier(); + break; + + case 1: + + result = row.getHaulingIdentifier(); + break; + + case 2: + + result = row.getSectionTemplate(); + break; + + default: + throw new IllegalStateException("Can't come here"); + } + + return result; } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { -//FIXME -// SectionWithTemplate row = data.get(rowIndex); -// -// switch (columnIndex) { -// case 0: -// -// row.setSettingIdentifier((Integer) aValue); -// setModified(true); -// break; -// -// case 1: -// -// row.setHaulingIdentifier((Integer) aValue); -// setModified(true); -// break; -// -// case 2: -// -// SectionTemplate sectionTemplate = (SectionTemplate) aValue; -// -// boolean changeTemplate = true; -// -// if (sectionTemplate != null) { -// -// // check if can use this template -// int basketsCount = row.sizeBasket(); -// boolean compiliantWithBasketCount = sectionTemplate.isCompiliantWithBasketCount(basketsCount); -// -// if (!compiliantWithBasketCount) { -// -// // We can't use this value -// if (log.isWarnEnabled()) { -// log.warn("sectionTemplate " + sectionTemplate + " is not compliant with basketCount: " + basketsCount); -// } -// //TODO Send user a message -// -// changeTemplate = false; -// -// } -// -// } -// -// if (changeTemplate) { -// -// SectionTemplate previousSectionTemplate = row.getSectionTemplate(); -// row.setSectionTemplate(sectionTemplate); -// firePropertyChange(TEMPLATE_PROPERTY, previousSectionTemplate, sectionTemplate); -// -// } -// -// break; -// -// default: -// throw new IllegalStateException("Can't come here"); -// } + SectionWithTemplate row = data.get(rowIndex); + + switch (columnIndex) { + case 0: + + row.setSettingIdentifier((Integer) aValue); + setModified(true); + break; + + case 1: + + row.setHaulingIdentifier((Integer) aValue); + setModified(true); + break; + + case 2: + + SectionTemplate sectionTemplate = (SectionTemplate) aValue; + + boolean changeTemplate = true; + + if (sectionTemplate != null) { + + // check if can use this template + int basketsCount = row.sizeBasket(); + boolean compiliantWithBasketCount = sectionTemplate.isCompiliantWithBasketCount(basketsCount); + + if (!compiliantWithBasketCount) { + + // We can't use this value + if (log.isWarnEnabled()) { + log.warn("sectionTemplate " + sectionTemplate + " is not compliant with basketCount: " + basketsCount); + } + //TODO Send user a message + + changeTemplate = false; + + } + + } + + if (changeTemplate) { + + SectionTemplate previousSectionTemplate = row.getSectionTemplate(); + row.setSectionTemplate(sectionTemplate); + firePropertyChange(TEMPLATE_PROPERTY, previousSectionTemplate, sectionTemplate); + + } + + break; + + default: + throw new IllegalStateException("Can't come here"); + } } diff --git a/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BasketDto-n1-update-table-error-validation.xml b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BasketDto-n1-update-table-error-validation.xml new file mode 100644 index 0000000..ff3dcf5 --- /dev/null +++ b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BasketDto-n1-update-table-error-validation.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + ObServe :: Validation + %% + Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + %% + 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% + --> + +<!DOCTYPE validators PUBLIC + "-//Apache Struts//XWork Validator 1.0.3//EN" + "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> +<validators> + + <field name="settingIdentifier"> + + <!-- settingIdentifier obligatoire --> + <field-validator type="required" short-circuit="true"> + <message>validator.basket.required.settingIdentifier</message> + </field-validator> + + </field> + + <field name="floatline1Length"> + + <!-- floatline1Length non saisi || 0.0 <= floatline1Length <= 150.0 --> + <field-validator type="fieldexpressionwithparams" short-circuit="true"> + <param name="doubleParams">min:0.0|max:150.0</param> + <param name="expression"> + <![CDATA[ floatline1Length == null || (doubles.min <= floatline1Length && floatline1Length <= doubles.max)]]> + </param> + <message> + validator.basket.bound.floatline1Length##${doubles.min}##${doubles.max} + </message> + </field-validator> + + </field> + + <field name="floatline2Length"> + + <!-- floatline2Length non saisi || 0.0 <= floatline2Length <= 150.0 --> + <field-validator type="fieldexpressionwithparams" short-circuit="true"> + <param name="doubleParams">min:0.0|max:150.0</param> + <param name="expression"> + <![CDATA[ floatline2Length == null || (doubles.min <= floatline2Length && floatline2Length <= doubles.max)]]> + </param> + <message> + validator.basket.bound.floatline2Length##${doubles.min}##${doubles.max} + </message> + </field-validator> + + </field> + +</validators> diff --git a/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-error-validation.xml b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-error-validation.xml new file mode 100644 index 0000000..0008125 --- /dev/null +++ b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-error-validation.xml @@ -0,0 +1,113 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + ObServe :: Validation + %% + Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + %% + 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% + --> + +<!DOCTYPE validators PUBLIC + "-//Apache Struts//XWork Validator 1.0.3//EN" + "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> +<validators> + + <field name="topType"> + + <!-- topType desactive --> + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ topType == null || topType.enabled ]]> + </param> + <message>validator.branchline.desactivated.topType</message> + </field-validator> + + </field> + + <field name="tracelineType"> + + <!-- tracelineType desactive --> + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ tracelineType == null || tracelineType.enabled ]]> + </param> + <message>validator.branchline.desactivated.tracelineType</message> + </field-validator> + + </field> + + <field name="baitType"> + + <!-- baitType desactive --> + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ baitType == null || baitType.enabled ]]> + </param> + <message>validator.branchline.desactivated.baitType</message> + </field-validator> + + </field> + + <field name="baitSettingStatus"> + + <!-- baitSettingStatus desactive --> + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ baitSettingStatus == null || baitSettingStatus.enabled ]]> + </param> + <message>validator.branchline.desactivated.baitSettingStatus</message> + </field-validator> + + </field> + + <field name="baitHaulingStatus"> + + <!-- baitHaulingStatus desactive --> + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ baitHaulingStatus == null || baitHaulingStatus.enabled ]]> + </param> + <message>validator.branchline.desactivated.baitHaulingStatus</message> + </field-validator> + + </field> + + <field name="hookSize"> + + <!-- hookSize desactive --> + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ hookSize == null || hookSize.enabled ]]> + </param> + <message>validator.branchline.desactivated.hookSize</message> + </field-validator> + + </field> + + <field name="hookType"> + + <!-- hookType desactive --> + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ hookType == null || hookType.enabled ]]> + </param> + <message>validator.branchline.desactivated.hookType</message> + </field-validator> + + </field> + +</validators> diff --git a/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-table-error-validation.xml b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-table-error-validation.xml new file mode 100644 index 0000000..11feb46 --- /dev/null +++ b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-table-error-validation.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + ObServe :: Validation + %% + Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + %% + 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% + --> + +<!DOCTYPE validators PUBLIC + "-//Apache Struts//XWork Validator 1.0.3//EN" + "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> +<validators> + + <field name="settingIdentifier"> + + <!-- settingIdentifier obligatoire --> + <field-validator type="required" short-circuit="true"> + <message>validator.branchline.required.settingIdentifier</message> + </field-validator> + + </field> + + <field name="branchlineLength"> + + <!-- branchlineLength non saisi || 0.0 <= branchlineLength <= 50.0 --> + <field-validator type="fieldexpressionwithparams" short-circuit="true"> + <param name="doubleParams">min:0.0|max:50.0</param> + <param name="expression"> + <![CDATA[ branchlineLength == null || (doubles.min <= branchlineLength && branchlineLength <= doubles.max)]]> + </param> + <message> + validator.branchline.bound.branchlineLength##${doubles.min}##${doubles.max} + </message> + </field-validator> + + </field> + + <field name="tracelineLength"> + + <!-- tracelineLength non saisi || 0.0 <= tracelineLength <= 50.0 --> + <field-validator type="fieldexpressionwithparams" short-circuit="true"> + <param name="doubleParams">min:0.0|max:50.0</param> + <param name="expression"> + <![CDATA[ tracelineLength == null || (doubles.min <= tracelineLength && tracelineLength <= doubles.max)]]> + </param> + <message> + validator.branchline.bound.tracelineLength##${doubles.min}##${doubles.max} + </message> + </field-validator> + + </field> + +</validators> diff --git a/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-warning-validation.xml b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-warning-validation.xml new file mode 100644 index 0000000..4213606 --- /dev/null +++ b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/BranchlineDto-n1-update-warning-validation.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + ObServe :: Validation + %% + Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + %% + 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% + --> + +<!DOCTYPE validators PUBLIC + "-//Apache Struts//XWork Validator 1.0.3//EN" + "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> +<validators> + + <field name="topType"> + + <!-- pas de topType selectionnee --> + <field-validator type="required" short-circuit="true"> + <message>validator.branchline.required.topType</message> + </field-validator> + + </field> + + <field name="tracelineType"> + + <!-- pas de tracelineType selectionnee --> + <field-validator type="required" short-circuit="true"> + <message>validator.branchline.required.tracelineType</message> + </field-validator> + + </field> + +</validators> diff --git a/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/SectionDto-n1-update-table-error-validation.xml b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/SectionDto-n1-update-table-error-validation.xml new file mode 100644 index 0000000..6b7a6a4 --- /dev/null +++ b/observe-application-swing/src/main/resources/fr/ird/observe/services/dto/longline/SectionDto-n1-update-table-error-validation.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + ObServe :: Validation + %% + Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + %% + 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% + --> + +<!DOCTYPE validators PUBLIC + "-//Apache Struts//XWork Validator 1.0.3//EN" + "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> +<validators> + + <field name="settingIdentifier"> + + <!-- settingIdentifier obligatoire --> + <field-validator type="required" short-circuit="true"> + <message>validator.section.required.settingIdentifier</message> + </field-validator> + + </field> + +</validators> diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/longline/SetLonglineDetailCompositionServiceController.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/longline/SetLonglineDetailCompositionServiceController.java index 4bda7c3..a34ad18 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/longline/SetLonglineDetailCompositionServiceController.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/longline/SetLonglineDetailCompositionServiceController.java @@ -25,6 +25,7 @@ package fr.ird.observe.application.web.controller.v1.longline; import fr.ird.observe.application.web.controller.v1.ObserveAuthenticatedServiceControllerSupport; import fr.ird.observe.services.dto.FormDto; import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; +import fr.ird.observe.services.dto.result.SaveResultDto; import fr.ird.observe.services.service.longline.SetLonglineDetailCompositionService; /** @@ -47,7 +48,22 @@ public class SetLonglineDetailCompositionServiceController extends ObserveAuthen } @Override - public String save(FormDto<SetLonglineDetailCompositionDto> form) { - return service.save(form); + public boolean canDeleteSection(String sectionId) { + return service.canDeleteSection(sectionId); + } + + @Override + public boolean canDeleteBasket(String basketId) { + return service.canDeleteBasket(basketId); + } + + @Override + public boolean canDeleteBranchline(String branchlineId) { + return service.canDeleteBranchline(branchlineId); + } + + @Override + public SaveResultDto save(SetLonglineDetailCompositionDto dto) { + return service.save(dto); } } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/longline/BasketTopiaDao.java b/observe-entities/src/main/java/fr/ird/observe/entities/longline/BasketTopiaDao.java new file mode 100644 index 0000000..4ce4bf4 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/longline/BasketTopiaDao.java @@ -0,0 +1,26 @@ +package fr.ird.observe.entities.longline; + +public class BasketTopiaDao extends AbstractBasketTopiaDao<Basket> { + + public boolean isUsed(Basket entity) { + + boolean used; + + TdrTopiaDao tdrDao = topiaDaoSupplier.getDao(Tdr.class, TdrTopiaDao.class); + used = tdrDao.forBasketEquals(entity).exists(); + + if (! used) { + + CatchLonglineTopiaDao catchLonglineDao = topiaDaoSupplier.getDao(CatchLongline.class, CatchLonglineTopiaDao.class); + used = catchLonglineDao.forBasketEquals(entity).exists(); + + } + + return used; + + + + + } + +} \ No newline at end of file diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/longline/BranchlineTopiaDao.java b/observe-entities/src/main/java/fr/ird/observe/entities/longline/BranchlineTopiaDao.java new file mode 100644 index 0000000..a685b1a --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/longline/BranchlineTopiaDao.java @@ -0,0 +1,24 @@ +package fr.ird.observe.entities.longline; + +public class BranchlineTopiaDao extends AbstractBranchlineTopiaDao<Branchline> { + + public boolean isUsed(Branchline entity) { + + boolean used; + + TdrTopiaDao tdrDao = topiaDaoSupplier.getDao(Tdr.class, TdrTopiaDao.class); + used = tdrDao.forBranchlineEquals(entity).exists(); + + if (! used) { + + CatchLonglineTopiaDao catchLonglineDao = topiaDaoSupplier.getDao(CatchLongline.class, CatchLonglineTopiaDao.class); + used = catchLonglineDao.forBranchlineEquals(entity).exists(); + + } + + return used; + + } + + +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/longline/SectionTopiaDao.java b/observe-entities/src/main/java/fr/ird/observe/entities/longline/SectionTopiaDao.java new file mode 100644 index 0000000..4a5363a --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/longline/SectionTopiaDao.java @@ -0,0 +1,23 @@ +package fr.ird.observe.entities.longline; + +public class SectionTopiaDao extends AbstractSectionTopiaDao<Section> { + + public boolean isUsed(Section entity) { + + boolean used; + + TdrTopiaDao tdrDao = topiaDaoSupplier.getDao(Tdr.class, TdrTopiaDao.class); + used = tdrDao.forSectionEquals(entity).exists(); + + if (! used) { + + CatchLonglineTopiaDao catchLonglineDao = topiaDaoSupplier.getDao(CatchLongline.class, CatchLonglineTopiaDao.class); + used = catchLonglineDao.forSectionEquals(entity).exists(); + + } + + return used; + + } + +} \ No newline at end of file diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/service/longline/SetLonglineDetailCompositionService.java b/observe-services-api/src/main/java/fr/ird/observe/services/service/longline/SetLonglineDetailCompositionService.java index f9b726b..07b3cb2 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/service/longline/SetLonglineDetailCompositionService.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/service/longline/SetLonglineDetailCompositionService.java @@ -25,6 +25,7 @@ package fr.ird.observe.services.service.longline; import fr.ird.observe.services.ObserveService; import fr.ird.observe.services.dto.FormDto; import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; +import fr.ird.observe.services.dto.result.SaveResultDto; import fr.ird.observe.services.spi.PostRequest; import fr.ird.observe.services.spi.ReadDataPermission; import fr.ird.observe.services.spi.Write; @@ -41,9 +42,18 @@ public interface SetLonglineDetailCompositionService extends ObserveService { @WriteDataPermission FormDto<SetLonglineDetailCompositionDto> loadToEdit(String setLonglineId); + @WriteDataPermission + boolean canDeleteSection(String sectionId); + + @WriteDataPermission + boolean canDeleteBasket(String basketId); + + @WriteDataPermission + boolean canDeleteBranchline(String branchlineId); + @Write @WriteDataPermission @PostRequest - String save(FormDto<SetLonglineDetailCompositionDto> form); + SaveResultDto save(SetLonglineDetailCompositionDto dto); } diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/longline/LonglineCompositionDto.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/longline/LonglineCompositionDto.java new file mode 100644 index 0000000..2f99ec2 --- /dev/null +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/longline/LonglineCompositionDto.java @@ -0,0 +1,43 @@ +package fr.ird.observe.services.dto.longline; + +/* + * #%L + * ObServe :: Entities + * %% + * Copyright (C) 2008 - 2014 IRD, Codelutin, Tony Chemit + * %% + * 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% + */ + +import java.io.Serializable; + +/** + * Created on 12/13/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.10 + */ +public interface LonglineCompositionDto extends Serializable { + + void setSettingIdentifier(Integer settingIdentifier); + + Integer getSettingIdentifier(); + + void setHaulingIdentifier(Integer haulingIdentifier); + + Integer getHaulingIdentifier(); + +} diff --git a/observe-services-model/src/main/xmi/observe-services-dto-longline.zargo b/observe-services-model/src/main/xmi/observe-services-dto-longline.zargo index 89aef58..8512fdf 100644 Binary files a/observe-services-model/src/main/xmi/observe-services-dto-longline.zargo and b/observe-services-model/src/main/xmi/observe-services-dto-longline.zargo differ diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/dto/ObserveDtosInitializer.java b/observe-services-topia/src/main/java/fr/ird/observe/services/dto/ObserveDtosInitializer.java index 5f2d2e9..3fb28de 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/dto/ObserveDtosInitializer.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/dto/ObserveDtosInitializer.java @@ -640,6 +640,13 @@ public class ObserveDtosInitializer implements ObserveModelInitializer { public void initSetLonglineDetailCompositionDto() { registerDto(SetLonglineDetailCompositionDto.class, SetLongline.class, SetLonglineDetailCompositionDto.PROPERTY_SECTION, + SetLonglineDetailCompositionDto.PROPERTY_SETTING_START_TIME_STAMP, + SetLonglineDetailCompositionDto.PROPERTY_MONITORED, + SetLonglineDetailCompositionDto.PROPERTY_TOTAL_SECTIONS_COUNT, + SetLonglineDetailCompositionDto.PROPERTY_BASKETS_PER_SECTION_COUNT, + SetLonglineDetailCompositionDto.PROPERTY_BRANCHLINES_PER_BASKET_COUNT, + SetLonglineDetailCompositionDto.PROPERTY_HAULING_DIRECTION_SAME_AS_SETTING, + SetLonglineDetailCompositionDto.PROPERTY_HAULING_BREAKS, SetLonglineDetailCompositionDto.PROPERTY_LAST_UPDATE ); } diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/service/longline/SetLonglineDetailCompositionServiceTopia.java b/observe-services-topia/src/main/java/fr/ird/observe/services/service/longline/SetLonglineDetailCompositionServiceTopia.java index 96cea89..2ed5426 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/service/longline/SetLonglineDetailCompositionServiceTopia.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/service/longline/SetLonglineDetailCompositionServiceTopia.java @@ -22,11 +22,16 @@ package fr.ird.observe.services.service.longline; * #L% */ +import fr.ird.observe.entities.longline.Basket; +import fr.ird.observe.entities.longline.Branchline; +import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.services.ObserveServiceTopia; import fr.ird.observe.services.dto.FormDto; import fr.ird.observe.services.dto.ReferenceTypeName; +import fr.ird.observe.services.dto.longline.BasketDto; import fr.ird.observe.services.dto.longline.BranchlineDto; +import fr.ird.observe.services.dto.longline.SectionDto; import fr.ird.observe.services.dto.longline.SetLonglineDetailCompositionDto; import fr.ird.observe.services.dto.referential.longline.BaitHaulingStatusDto; import fr.ird.observe.services.dto.referential.longline.BaitSettingStatusDto; @@ -34,6 +39,8 @@ import fr.ird.observe.services.dto.referential.longline.BaitTypeDto; import fr.ird.observe.services.dto.referential.longline.HookSizeDto; import fr.ird.observe.services.dto.referential.longline.HookTypeDto; import fr.ird.observe.services.dto.referential.longline.LineTypeDto; +import fr.ird.observe.services.dto.result.SaveResultDto; +import fr.ird.observe.services.dto.result.SaveResultDtos; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com @@ -74,15 +81,55 @@ public class SetLonglineDetailCompositionServiceTopia extends ObserveServiceTopi } @Override - public String save(FormDto<SetLonglineDetailCompositionDto> form) { + public boolean canDeleteSection(String sectionId) { - SetLonglineDetailCompositionDto setLonglineDetailCompositionDto = form.getForm(); + Section section = loadEntity(SectionDto.class, Section.class, sectionId); - SetLongline setLongline = dtoToEntity(SetLonglineDetailCompositionDto.class, SetLongline.class, setLonglineDetailCompositionDto); + boolean sectionUsed = getTopiaPersistenceContext().getSectionDao().isUsed(section); + + // il ne doit pas être nécessaire de parcourir les paniers de las section + // car si un des paniers de la section est utilisé alors la section est aussi utilisé. + + return ! sectionUsed; + } + + @Override + public boolean canDeleteBasket(String basketId) { + + Basket basket = loadEntity(BasketDto.class, Basket.class, basketId); + + boolean basketUsed = getTopiaPersistenceContext().getBasketDao().isUsed(basket); + + // il ne doit pas être nécessaire de parcourir les avançons du panier + // car si un des avançons du panier est utilisé alors le panier est aussi utilisé. + + return ! basketUsed; + + + } + + @Override + public boolean canDeleteBranchline(String branchlineId) { + + Branchline branchline = loadEntity(BranchlineDto.class, Branchline.class, branchlineId); + + boolean branchlineUsed = getTopiaPersistenceContext().getBranchlineDao().isUsed(branchline); + + return ! branchlineUsed; + } + + @Override + public SaveResultDto save(SetLonglineDetailCompositionDto dto) { + + SetLongline setLongline = dtoToEntity(SetLonglineDetailCompositionDto.class, SetLongline.class, dto); setLongline = saveEntity(SetLongline.class, setLongline); - return setLongline.getTopiaId(); + for (Section section : setLongline.getSection()) { + section.setSetLongline(setLongline); + } + + return SaveResultDtos.newSaveResult(setLongline.getTopiaId(), setLongline.getLastUpdate()); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.