Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: c2a5a240 by Tony Chemit at 2020-12-02T10:30:47+01:00 Move generateHomeId to DataSourceService, and then can now delete TripService and let toolkit generates it for us. - - - - - d6a73b1b by Tony Chemit at 2020-12-02T10:39:13+01:00 Review TargetSampleAwareService and clean dedicated services - - - - - 1923b958 by Tony Chemit at 2020-12-02T10:40:27+01:00 Review LonglineCompositionDto and remove the service methods - - - - - de883bd1 by Tony Chemit at 2020-12-02T10:40:38+01:00 Remove generated service - - - - - 1420acb5 by Tony Chemit at 2020-12-02T10:40:51+01:00 Clean some code - - - - - 30 changed files: - client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/common/actions/TripUIGenerateHomeId.java - client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/BranchlineUIHandler.java - client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/LonglinePositionHelper.java - client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/SetDetailCompositionUIHandler.java - client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/actions/SetDetailCompositionUIDeleteAll.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/DiscardedTargetSampleUINavigationContext.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/KeptTargetSampleUINavigationContext.java - client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/NonTargetSampleUINavigationContext.java - models/dto/src/main/java/fr/ird/observe/dto/data/ll/observation/LonglineCompositionDto.java - models/dto/src/main/models/Observe-30-data-ll-observation.model - models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/SetImpl.java - server/core/src/main/filtered-resources/mapping - − services/api/src/main/java/fr/ird/observe/services/service/data/ll/common/TripService.java - − services/api/src/main/java/fr/ird/observe/services/service/data/ll/observation/SetDetailCompositionService.java - − services/api/src/main/java/fr/ird/observe/services/service/data/ps/common/TripService.java - − services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/DiscardedTargetSampleService.java - services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/NonTargetSampleService.java - − services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/SetService.java - services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/TargetSampleAwareService.java - services/local-impl/src/main/java/fr/ird/observe/services/local/service/DataSourceServiceLocal.java - services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/common/TripServiceLocal.java - services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/SetDetailCompositionServiceLocal.java - services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/NonTargetSampleServiceLocal.java - services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/TargetSampleServiceLocalSupport.java - services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ps/observation/DiscardedTargetSampleServiceLocalTest.java - services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ps/observation/KeptTargetSampleServiceLocalTest.java - services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/KeptTargetSampleService.java → services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ps/observation/NonTargetSampleServiceLocalTest.java - toolkit/service/src/main/java/fr/ird/observe/services/service/DataSourceService.java - toolkit/templates/src/main/java/fr/ird/observe/toolkit/templates/service/OpenableServiceTransformer.java - toolkit/templates/src/main/java/fr/ird/observe/toolkit/templates/service/SimpleServiceTransformer.java Changes: ===================================== client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/common/actions/TripUIGenerateHomeId.java ===================================== @@ -43,7 +43,7 @@ public class TripUIGenerateHomeId extends ContentUIActionSupport<TripUI> { @Override protected void doActionPerformed(ActionEvent e, TripUI ui) { - String homeId = getDataSource().getLlCommonTripService().generateHomeId(); + String homeId = getDataSource().getDataSourceService().generateHomeId(); ui.getModel().getStates().getBean().setHomeId(homeId); } } ===================================== client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/BranchlineUIHandler.java ===================================== @@ -25,6 +25,7 @@ package fr.ird.observe.client.datasource.editor.ll.data.observation; import fr.ird.observe.client.ClientUIContext; import fr.ird.observe.client.datasource.editor.api.content.actions.ResetForm; import fr.ird.observe.client.datasource.editor.api.content.actions.reset.DefaultResetAdapter; +import fr.ird.observe.client.datasource.editor.api.content.data.simple.ContentSimpleUIModelStates; import fr.ird.observe.client.datasource.editor.api.content.ui.ObserveLayoutFocusTraversalPolicy; import fr.ird.observe.client.util.UIHelper; import fr.ird.observe.dto.data.ll.observation.BranchlineDto; @@ -67,8 +68,7 @@ public class BranchlineUIHandler extends GeneratedBranchlineUIHandler { } else { beanToSave.setTimeSinceContact(null); } - - log.info("Time since contact: " + beanToSave.getTimeSinceContact()); + log.info(String.format("Time since contact: %d", beanToSave.getTimeSinceContact())); // for external models ui.getModel().fireSaved(); @@ -83,7 +83,7 @@ public class BranchlineUIHandler extends GeneratedBranchlineUIHandler { ui.getModel().setResetEdit(true); try { BranchlineDto branchline = ui.getModel().getBranchline(); - // on arrete l'edition + // on arrête l'édition stopEditUI(); // on re-ouvre l'écran d'édition try { @@ -186,14 +186,15 @@ public class BranchlineUIHandler extends GeneratedBranchlineUIHandler { // oldBranchline.removePropertyChangeListener(BranchlineDto.PROPERTY_TIMER, timerChanged); // } model.setBranchline(branchline); + ContentSimpleUIModelStates<BranchlineDto> states = model.getStates(); if (branchline == null) { - model.getStates().getBean().clear(); + states.getBean().clear(); Date timeSinceContactDate = DateUtil.createDate(0, 0, 0, 0, 0, 0); model.setTimeSinceContact(timeSinceContactDate); // stop edit stopEditUI(); } else { - branchline.copy(model.getStates().getBean()); + branchline.copy(states.getBean()); if (Objects.equals(true, branchline.getTimer())) { Long timeSinceContact = branchline.getTimeSinceContact(); if (timeSinceContact != null) { @@ -204,7 +205,7 @@ public class BranchlineUIHandler extends GeneratedBranchlineUIHandler { Date timeSinceContactDate = DateUtil.createDate(0, 0, 0, 0, 0, 0); model.setTimeSinceContact(timeSinceContactDate); } - if (model.getStates().isEnabled() && !model.getStates().isEditing()) { + if (states.isEnabled() && !states.isEditing()) { startEditUI(); } } @@ -214,9 +215,10 @@ public class BranchlineUIHandler extends GeneratedBranchlineUIHandler { public boolean tryToQuit() { boolean canContinue; BranchlineUIModel model = getModel(); - if (model.getStates().isEditing() && model.getStates().isModified()) { + ContentSimpleUIModelStates<BranchlineDto> states = model.getStates(); + if (states.isEditing() && states.isModified()) { canContinue = false; - if (model.getStates().isValid()) { + if (states.isValid()) { // le formulaire est valide, on demande a l'utilisateur s'il // veut la sauvegarder int response = ClientUIContext.askUser( @@ -236,7 +238,7 @@ public class BranchlineUIHandler extends GeneratedBranchlineUIHandler { case 0: // will save ui // sauvegarde des modifications - doSave(ui, model.getStates().getBean()); + doSave(ui, states.getBean()); canContinue = true; break; case 1: ===================================== client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/LonglinePositionHelper.java ===================================== @@ -46,35 +46,26 @@ import java.util.stream.Collectors; public class LonglinePositionHelper<D extends LonglinePositionAwareDto> { protected final JaxxComboBox<SectionReference> uiSection; - protected final JaxxComboBox<BasketReference> uiBasket; - protected final JaxxComboBox<BranchlineReference> uiBranchline; // To avoid any propagation when doing some works on locations protected boolean locationIsAdjusting; - protected Collection<SectionReference> sectionUniverse; - protected Collection<BasketReference> basketUniverse; - protected Collection<BranchlineReference> branchlineUniverse; public LonglinePositionHelper(JaxxComboBox<SectionReference> uiSection, JaxxComboBox<BasketReference> uiBasket, JaxxComboBox<BranchlineReference> uiBranchline, D tableEditBean) { - this.uiSection = uiSection; this.uiBasket = uiBasket; this.uiBranchline = uiBranchline; - @SuppressWarnings("unchecked") PropertyChangeListener sectionChanged = evt -> onSectionChanged((SectionReference) evt.getNewValue(), (D) evt.getSource()); tableEditBean.addPropertyChangeListener(CatchDto.PROPERTY_SECTION, sectionChanged); - @SuppressWarnings("unchecked") PropertyChangeListener basketChanged = evt -> onBasketChanged((BasketReference) evt.getNewValue(), (D) evt.getSource()); tableEditBean.addPropertyChangeListener(CatchDto.PROPERTY_BASKET, basketChanged); - // tri par virage uiSection.getIndexes().setSelectedButton(1); // tri par virage @@ -88,65 +79,44 @@ public class LonglinePositionHelper<D extends LonglinePositionAwareDto> { this.sectionUniverse = positionSetDto.getSections(); this.basketUniverse = positionSetDto.getBaskets(); this.branchlineUniverse = positionSetDto.getBranchlines(); - for (D dto : dtos) { - BranchlineReference branchline = dto.getBranchline(); - if (branchline != null) { - BasketReference basket = getBasket(branchline); dto.setBasket(basket); - } - BasketReference basket = dto.getBasket(); - if (basket != null) { - SectionReference section = getSection(basket); dto.setSection(section); - } } uiSection.setData(getSections()); } public void resetPosition(D dto) { - SectionReference section = dto.getSection(); BasketReference basket = dto.getBasket(); BranchlineReference branchline = dto.getBranchline(); - uiBranchline.setSelectedItem(null); uiSection.setSelectedItem(null); uiBasket.setSelectedItem(null); - if (section != null) { - // reload section (basket and branchlines universe will then changed) uiSection.setSelectedItem(section); - } - if (basket != null) { - // reload basket (branchlines universe will then changed) uiBasket.setSelectedItem(basket); - } - if (branchline != null) { - // reload branchline uiBranchline.setSelectedItem(branchline); - } - } - public void savePosition(List<D> dtos) { - for (D dto : dtos) { + public void savePosition(List<D> dtoList) { + for (D dto : dtoList) { if (dto.getBasket() != null) { // remove section dto.setSection(null); @@ -159,107 +129,66 @@ public class LonglinePositionHelper<D extends LonglinePositionAwareDto> { } public List<SectionReference> getSections() { - List<SectionReference> sections = new ArrayList<>(); - if (sectionUniverse != null) { - sections.addAll(sectionUniverse); - } - return sections; } protected void onSectionChanged(SectionReference newValue, D dto) { - locationIsAdjusting = true; - try { - BasketReference basket = dto.getBasket(); BranchlineReference branchline = dto.getBranchline(); - - // on deselectionne le panier + // on désélectionne le panier dto.setBasket(null); - - // on deselectionne l'avançon + // on désélectionne l'avançon dto.setBranchline(null); - // on vide l'ensemble des paniers uiBasket.setData(Collections.emptyList()); - // on vide l'ensemble des avançons uiBranchline.setData(Collections.emptyList()); - if (newValue != null) { - // une section est sélectionnée - // on remplit uniquement les paniers de cette section List<BasketReference> baskets = getBaskets(newValue); uiBasket.setData(new ArrayList<>(baskets)); - if (basket != null && baskets.contains(basket)) { - // un panier est sélectionné - - // on repmlit uniquement les avançons du panier + // on remplit uniquement les avançons du panier List<BranchlineReference> branchlines = getBranchlines(basket); uiBranchline.setData(new ArrayList<>(branchlines)); dto.setBasket(basket); - if (branchline != null && branchlines.contains(branchline)) { - // un avançon est sélectionné dto.setBranchline(branchline); - } - } - } - } finally { - locationIsAdjusting = false; - } - } protected void onBasketChanged(BasketReference newValue, D dto) { - if (!locationIsAdjusting) { - BranchlineReference branchline = dto.getBranchline(); - - // on deselectionne l'avançon + // on désélectionne l'avançon dto.setBranchline(null); - // on vide l'ensemble des avançons uiBranchline.setData(Collections.emptyList()); - if (newValue != null) { - - // un panier est selectionne - + // un panier est sélectionné // on remplit uniquement les avançons des paniers List<BranchlineReference> branchlines = getBranchlines(newValue); uiBranchline.setData(branchlines); - - if (branchline != null && branchlines.contains(branchline)) { - // un avançon est sélectionné dto.setBranchline(branchline); - } - } - } - } private SectionReference getSection(BasketReference basket) { ===================================== client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/SetDetailCompositionUIHandler.java ===================================== @@ -946,19 +946,19 @@ public class SetDetailCompositionUIHandler extends GeneratedSetDetailComposition public boolean canDeleteSection(SectionDto section) { - return section.isNotPersisted() || getLlObservationSetDetailCompositionService().canDeleteSection(section.getId()); + return section.isNotPersisted() || section.isNotUsed(); } private boolean canDeleteBasket(BasketDto basket) { - return basket.isNotPersisted() || getLlObservationSetDetailCompositionService().canDeleteBasket(basket.getId()); + return basket.isNotPersisted() || basket.isNotUsed(); } private boolean canDeleteBranchline(BranchlineDto branchline) { - return branchline.isNotPersisted() || getLlObservationSetDetailCompositionService().canDeleteBranchline(branchline.getId()); + return branchline.isNotPersisted() || branchline.isNotUsed(); } ===================================== client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/actions/SetDetailCompositionUIDeleteAll.java ===================================== @@ -50,7 +50,8 @@ public class SetDetailCompositionUIDeleteAll extends ContentUIActionSupport<SetD private static final Logger log = LogManager.getLogger(SetDetailCompositionUIDeleteAll.class); public SetDetailCompositionUIDeleteAll() { - super(t("observe.data.ll.observation.SetDetailComposition.action.deleteAllSections"), t("observe.data.ll.observation.SetDetailComposition.action.deleteAllSections.tip"), "delete", ObserveLLKeyStrokes.KEY_STROKE_DELETE_DATA_GLOBAL); + super(t("observe.data.ll.observation.SetDetailComposition.action.deleteAllSections"), t("observe.data.ll.observation.SetDetailComposition.action.deleteAllSections.tip"), null, ObserveLLKeyStrokes.KEY_STROKE_DELETE_DATA_GLOBAL); + setIcon(getContentScaledImage("delete")); } @Override ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/DiscardedTargetSampleUINavigationContext.java ===================================== @@ -34,6 +34,6 @@ public class DiscardedTargetSampleUINavigationContext extends GeneratedDiscarded @Override protected boolean computeShowSata(ContentTableUINavigationInitializer initializer) { - return getService().canUseTargetSample(initializer.getSelectedId()); + return getService().canUseSample(initializer.getSelectedId()); } } ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/KeptTargetSampleUINavigationContext.java ===================================== @@ -34,6 +34,6 @@ public class KeptTargetSampleUINavigationContext extends GeneratedKeptTargetSamp @Override protected boolean computeShowSata(ContentTableUINavigationInitializer initializer) { - return getService().canUseTargetSample(initializer.getSelectedId()); + return getService().canUseSample(initializer.getSelectedId()); } } ===================================== client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/data/observation/NonTargetSampleUINavigationContext.java ===================================== @@ -34,6 +34,6 @@ public class NonTargetSampleUINavigationContext extends GeneratedNonTargetSample @Override protected boolean computeShowSata(ContentTableUINavigationInitializer initializer) { - return getService().canUseNonTargetSample(initializer.getSelectedId()); + return getService().canUseSample(initializer.getSelectedId()); } } ===================================== models/dto/src/main/java/fr/ird/observe/dto/data/ll/observation/LonglineCompositionDto.java ===================================== @@ -40,4 +40,5 @@ public interface LonglineCompositionDto extends DtoParentAware { Integer getHaulingIdentifier(); + boolean isNotUsed(); } ===================================== models/dto/src/main/models/Observe-30-data-ll-observation.model ===================================== @@ -43,6 +43,7 @@ floatline1Length + {*:1} Float | positiveNumber floatline2Length + {*:1} Float | positiveNumber branchline + {*} data.ll.observation.Branchline | ordered unique parentId + {*:1} String +notUsed + {*:1} boolean data.ll.observation.Branchline > data.Simple >> data.ll.observation.LonglineCompositionDto | references=settingIdentifier,haulingIdentifier,parentId settingIdentifier + {*:1} Integer @@ -68,6 +69,7 @@ tracelineType {*:0..1} fr.ird.observe.dto.referential.ll.common.LineTypeReferenc topType {*:0..1} fr.ird.observe.dto.referential.ll.common.LineTypeReference | mayNotNull baitType {*:0..1} fr.ird.observe.dto.referential.ll.common.BaitTypeReference parentId + {*:1} String +notUsed + {*:1} boolean data.ll.observation.BranchlinesComposition > data.Data | references=topTypeLabel,tracelineTypeLabel,length,proportion length + {*:1} Float | notNull positiveNumber @@ -125,6 +127,7 @@ settingIdentifier + {*:1} Integer | notNull positiveNumber haulingIdentifier + {*:1} Integer | positiveNumber basket + {*} data.ll.observation.Basket | ordered unique parentId + {*:1} String +notUsed + {*:1} boolean data.ll.observation.SensorUsed > data.Data >> data.WithDataFile | references=sensorTypeLabel hasData + {*:1} boolean ===================================== models/persistence/src/main/java/fr/ird/observe/entities/data/ll/observation/SetImpl.java ===================================== @@ -22,6 +22,8 @@ package fr.ird.observe.entities.data.ll.observation; * #L% */ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; import fr.ird.observe.dto.CoordinateHelper; import fr.ird.observe.dto.data.DataDto; import fr.ird.observe.dto.data.ll.observation.BasketReference; @@ -301,13 +303,26 @@ public class SetImpl extends SetAbstract { } private void loadDtoParents(SetDetailCompositionDto dto) { + //FIXME If not performant, let's used an optimized dao query + ImmutableMap<String, Section> sectionsById = Maps.uniqueIndex(getSection(), Section::getTopiaId); dto.getSection().forEach(section -> { section.setParentId(dto.getId()); String sectionId = section.getTopiaId(); + Section entitySection = sectionsById.get(sectionId); + ImmutableMap<String, Basket> basketsById = Maps.uniqueIndex(entitySection.getBasket(), Basket::getTopiaId); + section.setNotUsed(entitySection.isNotUsed()); section.getBasket().forEach(basket -> { basket.setParentId(sectionId); String basketId = basket.getTopiaId(); - basket.getBranchline().forEach(branchline -> branchline.setParentId(basketId)); + Basket entityBasket = basketsById.get(basketId); + basket.setNotUsed(entityBasket.isNotUsed()); + ImmutableMap<String, Branchline> branchlinesById = Maps.uniqueIndex(entityBasket.getBranchline(), Branchline::getTopiaId); + basket.getBranchline().forEach(branchline -> { + String branchlineId = branchline.getId(); + Branchline entityBranchline = branchlinesById.get(branchlineId); + branchline.setParentId(basketId); + branchline.setNotUsed(entityBranchline.isNotUsed()); + }); }); }); } ===================================== server/core/src/main/filtered-resources/mapping ===================================== @@ -60,6 +60,7 @@ GET /api/v1/DataSourceService/checkCanConnectOrBeEmpty GET /api/v1/DataSourceService/close v1.DataSourceServiceRestApi.close GET /api/v1/DataSourceService/create v1.DataSourceServiceRestApi.create GET /api/v1/DataSourceService/destroy v1.DataSourceServiceRestApi.destroy +GET /api/v1/DataSourceService/generateHomeId v1.DataSourceServiceRestApi.generateHomeId GET /api/v1/DataSourceService/getUsers v1.DataSourceServiceRestApi.getUsers GET /api/v1/DataSourceService/isIdValid v1.DataSourceServiceRestApi.isIdValid GET /api/v1/DataSourceService/migrateData v1.DataSourceServiceRestApi.migrateData @@ -97,7 +98,6 @@ GET /api/v1/data/ll/common/TripGearUseFeaturesService/loadForm POST /api/v1/data/ll/common/TripGearUseFeaturesService/save v1.data.ll.common.TripGearUseFeaturesServiceRestApi.save DELETE /api/v1/data/ll/common/TripService/delete v1.data.ll.common.TripServiceRestApi.delete GET /api/v1/data/ll/common/TripService/exists v1.data.ll.common.TripServiceRestApi.exists -GET /api/v1/data/ll/common/TripService/generateHomeId v1.data.ll.common.TripServiceRestApi.generateHomeId GET /api/v1/data/ll/common/TripService/getAllTrip v1.data.ll.common.TripServiceRestApi.getAllTrip GET /api/v1/data/ll/common/TripService/getBrothers v1.data.ll.common.TripServiceRestApi.getBrothers GET /api/v1/data/ll/common/TripService/getChildren v1.data.ll.common.TripServiceRestApi.getChildren @@ -183,9 +183,6 @@ GET /api/v1/data/ll/observation/BranchlineService/loadForm POST /api/v1/data/ll/observation/BranchlineService/save v1.data.ll.observation.BranchlineServiceRestApi.save GET /api/v1/data/ll/observation/SetCatchService/loadForm v1.data.ll.observation.SetCatchServiceRestApi.loadForm POST /api/v1/data/ll/observation/SetCatchService/save v1.data.ll.observation.SetCatchServiceRestApi.save -GET /api/v1/data/ll/observation/SetDetailCompositionService/canDeleteBasket v1.data.ll.observation.SetDetailCompositionServiceRestApi.canDeleteBasket -GET /api/v1/data/ll/observation/SetDetailCompositionService/canDeleteBranchline v1.data.ll.observation.SetDetailCompositionServiceRestApi.canDeleteBranchline -GET /api/v1/data/ll/observation/SetDetailCompositionService/canDeleteSection v1.data.ll.observation.SetDetailCompositionServiceRestApi.canDeleteSection GET /api/v1/data/ll/observation/SetDetailCompositionService/loadForm v1.data.ll.observation.SetDetailCompositionServiceRestApi.loadForm POST /api/v1/data/ll/observation/SetDetailCompositionService/save v1.data.ll.observation.SetDetailCompositionServiceRestApi.save GET /api/v1/data/ll/observation/SetGlobalCompositionService/loadForm v1.data.ll.observation.SetGlobalCompositionServiceRestApi.loadForm @@ -229,7 +226,7 @@ GET /api/v1/data/ps/observation/ActivityService/loadReferenceToRead POST /api/v1/data/ps/observation/ActivityService/move v1.data.ps.observation.ActivityServiceRestApi.move GET /api/v1/data/ps/observation/ActivityService/preCreate v1.data.ps.observation.ActivityServiceRestApi.preCreate POST /api/v1/data/ps/observation/ActivityService/save v1.data.ps.observation.ActivityServiceRestApi.save -GET /api/v1/data/ps/observation/DiscardedTargetSampleService/canUseTargetSample v1.data.ps.observation.DiscardedTargetSampleServiceRestApi.canUseTargetSample +GET /api/v1/data/ps/observation/DiscardedTargetSampleService/canUseSample v1.data.ps.observation.DiscardedTargetSampleServiceRestApi.canUseSample GET /api/v1/data/ps/observation/DiscardedTargetSampleService/getSampleSpecies v1.data.ps.observation.DiscardedTargetSampleServiceRestApi.getSampleSpecies GET /api/v1/data/ps/observation/DiscardedTargetSampleService/loadForm v1.data.ps.observation.DiscardedTargetSampleServiceRestApi.loadForm POST /api/v1/data/ps/observation/DiscardedTargetSampleService/save v1.data.ps.observation.DiscardedTargetSampleServiceRestApi.save @@ -247,11 +244,11 @@ GET /api/v1/data/ps/observation/FloatingObjectService/loadReferenceToRead GET /api/v1/data/ps/observation/FloatingObjectService/preCreate v1.data.ps.observation.FloatingObjectServiceRestApi.preCreate GET /api/v1/data/ps/observation/FloatingObjectService/preCreate v1.data.ps.observation.FloatingObjectServiceRestApi.preCreate POST /api/v1/data/ps/observation/FloatingObjectService/save v1.data.ps.observation.FloatingObjectServiceRestApi.save -GET /api/v1/data/ps/observation/KeptTargetSampleService/canUseTargetSample v1.data.ps.observation.KeptTargetSampleServiceRestApi.canUseTargetSample +GET /api/v1/data/ps/observation/KeptTargetSampleService/canUseSample v1.data.ps.observation.KeptTargetSampleServiceRestApi.canUseSample GET /api/v1/data/ps/observation/KeptTargetSampleService/getSampleSpecies v1.data.ps.observation.KeptTargetSampleServiceRestApi.getSampleSpecies GET /api/v1/data/ps/observation/KeptTargetSampleService/loadForm v1.data.ps.observation.KeptTargetSampleServiceRestApi.loadForm POST /api/v1/data/ps/observation/KeptTargetSampleService/save v1.data.ps.observation.KeptTargetSampleServiceRestApi.save -GET /api/v1/data/ps/observation/NonTargetSampleService/canUseNonTargetSample v1.data.ps.observation.NonTargetSampleServiceRestApi.canUseNonTargetSample +GET /api/v1/data/ps/observation/NonTargetSampleService/canUseSample v1.data.ps.observation.NonTargetSampleServiceRestApi.canUseSample GET /api/v1/data/ps/observation/NonTargetSampleService/getSampleSpecies v1.data.ps.observation.NonTargetSampleServiceRestApi.getSampleSpecies GET /api/v1/data/ps/observation/NonTargetSampleService/getSampleSpeciesFate v1.data.ps.observation.NonTargetSampleServiceRestApi.getSampleSpeciesFate GET /api/v1/data/ps/observation/NonTargetSampleService/loadForm v1.data.ps.observation.NonTargetSampleServiceRestApi.loadForm ===================================== services/api/src/main/java/fr/ird/observe/services/service/data/ll/common/TripService.java deleted ===================================== @@ -1,37 +0,0 @@ -package fr.ird.observe.services.service.data.ll.common; - -/* - * #%L - * ObServe Services :: API - * %% - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io - * %% - * 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.dto.data.ll.common.TripReference; -import fr.ird.observe.services.service.data.TripAwareService; -import io.ultreia.java4all.http.spi.Get; - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public interface TripService extends GeneratedTripService, TripAwareService<TripReference> { - - @Get - String generateHomeId(); - -} ===================================== services/api/src/main/java/fr/ird/observe/services/service/data/ll/observation/SetDetailCompositionService.java deleted ===================================== @@ -1,49 +0,0 @@ -package fr.ird.observe.services.service.data.ll.observation; - -/* - * #%L - * ObServe Services :: API - * %% - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io - * %% - * 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.security.Permission; -import fr.ird.observe.services.spi.MethodCredential; -import io.ultreia.java4all.http.spi.Get; - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public interface SetDetailCompositionService extends GeneratedSetDetailCompositionService { - - //FIXME Remove this, add a field in dto containing all elements used, ca after no need to call service - @Get - @MethodCredential(Permission.WRITE_DATA) - boolean canDeleteSection(String sectionId); - - //FIXME Remove this, add a field in dto containing all elements used, ca after no need to call service - @Get - @MethodCredential(Permission.WRITE_DATA) - boolean canDeleteBasket(String basketId); - - //FIXME Remove this, add a field in dto containing all elements used, ca after no need to call service - @Get - @MethodCredential(Permission.WRITE_DATA) - boolean canDeleteBranchline(String branchlineId); - -} ===================================== services/api/src/main/java/fr/ird/observe/services/service/data/ps/common/TripService.java deleted ===================================== @@ -1,33 +0,0 @@ -package fr.ird.observe.services.service.data.ps.common; - -/* - * #%L - * ObServe Services :: API - * %% - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io - * %% - * 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.dto.data.ps.common.TripReference; -import fr.ird.observe.services.service.data.TripAwareService; - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public interface TripService extends GeneratedTripService, TripAwareService<TripReference> { - -} ===================================== services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/DiscardedTargetSampleService.java deleted ===================================== @@ -1,33 +0,0 @@ -package fr.ird.observe.services.service.data.ps.observation; - -/*- - * #%L - * ObServe Services :: API - * %% - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -/** - * Created on 16/10/2020. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 8.0.1 - */ -public interface DiscardedTargetSampleService extends GeneratedDiscardedTargetSampleService, TargetSampleAwareService { - -} ===================================== services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/NonTargetSampleService.java ===================================== @@ -23,7 +23,6 @@ package fr.ird.observe.services.service.data.ps.observation; */ import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet; -import fr.ird.observe.dto.referential.common.SpeciesReference; import fr.ird.observe.dto.referential.ps.common.SpeciesFateReference; import fr.ird.observe.security.Permission; import fr.ird.observe.services.spi.MethodCredential; @@ -34,14 +33,6 @@ import io.ultreia.java4all.http.spi.Get; */ public interface NonTargetSampleService extends GeneratedNonTargetSampleService { - @Get - @MethodCredential(Permission.READ_DATA) - boolean canUseNonTargetSample(String setId); - - @Get - @MethodCredential(Permission.READ_DATA) - ReferentialDtoReferenceSet<SpeciesReference> getSampleSpecies(String setId); - @Get @MethodCredential(Permission.READ_DATA) ReferentialDtoReferenceSet<SpeciesFateReference> getSampleSpeciesFate(String setId); ===================================== services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/SetService.java deleted ===================================== @@ -1,30 +0,0 @@ -package fr.ird.observe.services.service.data.ps.observation; - -/* - * #%L - * ObServe Services :: API - * %% - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ - -/** - * @author Tony Chemit - dev@tchemit.fr - */ -public interface SetService extends GeneratedSetService { - -} ===================================== services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/TargetSampleAwareService.java ===================================== @@ -41,7 +41,7 @@ public interface TargetSampleAwareService extends ObserveService { @Get @MethodCredential(Permission.READ_DATA) - boolean canUseTargetSample(String setId); + boolean canUseSample(String setId); @Get @MethodCredential(Permission.READ_DATA) ===================================== services/local-impl/src/main/java/fr/ird/observe/services/local/service/DataSourceServiceLocal.java ===================================== @@ -54,6 +54,7 @@ import fr.ird.observe.spi.ObservePersistenceBusinessProject; import fr.ird.observe.spi.context.DtoEntityContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.hashids.Hashids; import org.nuiton.topia.persistence.jdbc.JdbcHelper; import org.nuiton.topia.persistence.jdbc.JdbcPostgresHelper; import org.nuiton.topia.persistence.script.TopiaSqlScript; @@ -84,6 +85,7 @@ import static io.ultreia.java4all.i18n.I18n.l; public class DataSourceServiceLocal extends ObserveServiceLocal implements DataSourceService { private static final Logger log = LogManager.getLogger(DataSourceServiceLocal.class); + private static final Hashids ID_GENERATOR = new Hashids("ObServeHasSomeSalt", 8, "0123456789#abcdefghijklmnopqrestuvwxyz"); private static boolean canWrite(Set<?> privileges) { return privileges != null && @@ -173,7 +175,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS return dataSourceInformation; } - @Override public ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException { @@ -540,6 +541,11 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS return id != null && serviceContext.getTopiaPersistenceContext().isTopiaId(spi.toEntityType(), id); } + @Override + public String generateHomeId() { + return ID_GENERATOR.encode(now().getTime()); + } + private ObserveDataSourceConnectionTopia createDataSourceConnection(ObserveDataSourceInformation dataSourceInformation, String authenticationToken) { return new ObserveDataSourceConnectionTopia( authenticationToken, ===================================== services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/common/TripServiceLocal.java ===================================== @@ -31,7 +31,6 @@ import fr.ird.observe.services.local.service.data.TripServiceLocalSupport; import fr.ird.observe.services.service.data.ll.common.TripService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.hashids.Hashids; /** * @author Tony Chemit - dev@tchemit.fr @@ -39,11 +38,6 @@ import org.hashids.Hashids; public class TripServiceLocal extends TripServiceLocalSupport<TripDto, TripReference, Trip, TripTopiaDao> implements TripService { private static final Logger log = LogManager.getLogger(TripServiceLocal.class); - private static final Hashids ID_GENERATOR = new Hashids("ObServeHasSomeSalt", 8, "0123456789#abcdefghijklmnopqrestuvwxyz"); - - public TripServiceLocal() { - super(Program.SPI, Trip.SPI, Trip.PROPERTY_PROGRAM); - } public static boolean copyTripLogbookMetaData(Trip oldTrip, Trip newTrip) { if (!newTrip.isLogbookAvailability()) { @@ -73,9 +67,8 @@ public class TripServiceLocal extends TripServiceLocalSupport<TripDto, TripRefer return false; } - @Override - public String generateHomeId() { - return ID_GENERATOR.encode(now().getTime()); + public TripServiceLocal() { + super(Program.SPI, Trip.SPI, Trip.PROPERTY_PROGRAM); } } ===================================== services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/SetDetailCompositionServiceLocal.java ===================================== @@ -23,9 +23,6 @@ package fr.ird.observe.services.local.service.data.ll.observation; */ import fr.ird.observe.dto.data.ll.observation.SetDetailCompositionDto; -import fr.ird.observe.entities.data.ll.observation.Basket; -import fr.ird.observe.entities.data.ll.observation.Branchline; -import fr.ird.observe.entities.data.ll.observation.Section; import fr.ird.observe.entities.data.ll.observation.Set; import fr.ird.observe.services.local.service.data.Simple2DataServiceLocalSupport; import fr.ird.observe.services.service.data.ll.observation.SetDetailCompositionService; @@ -40,22 +37,4 @@ public class SetDetailCompositionServiceLocal extends Simple2DataServiceLocalSup super(Set.SPI, Set.SET_DETAIL_COMPOSITION_SPI, null); } - @Override - public boolean canDeleteSection(String sectionId) { - Section entity = Section.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), sectionId); - return entity.isNotUsed(); - } - - @Override - public boolean canDeleteBasket(String basketId) { - Basket entity = Basket.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), basketId); - return entity.isNotUsed(); - } - - @Override - public boolean canDeleteBranchline(String branchlineId) { - Branchline entity = Branchline.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), branchlineId); - return entity.isNotUsed(); - } - } ===================================== services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/NonTargetSampleServiceLocal.java ===================================== @@ -45,7 +45,7 @@ public class NonTargetSampleServiceLocal extends Simple3DataServiceLocalSupport< } @Override - public boolean canUseNonTargetSample(String setId) { + public boolean canUseSample(String setId) { Set parent = loadParentEntity(setId); return parent.canUseNonTargetSample(); } ===================================== services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/TargetSampleServiceLocalSupport.java ===================================== @@ -50,7 +50,7 @@ public abstract class TargetSampleServiceLocalSupport<D extends DataDto & Target this.discarded = discarded; } - public boolean canUseTargetSample(String setId) { + public boolean canUseSample(String setId) { Set parent = loadParentEntity(setId); return parent.canUseTargetSample(discarded); } ===================================== services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ps/observation/DiscardedTargetSampleServiceLocalTest.java ===================================== @@ -31,7 +31,6 @@ import fr.ird.observe.test.ObserveFixtures; import fr.ird.observe.test.spi.DatabaseNameConfiguration; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; /** @@ -49,13 +48,11 @@ public class DiscardedTargetSampleServiceLocalTest extends ServiceLocalTestSuppo @Test public void canUseTargetSampleTest() { - Assert.assertFalse(service.canUseTargetSample(ObserveFixtures.SET_SEINE_ID)); + Assert.assertFalse(service.canUseSample(ObserveFixtures.SET_SEINE_ID)); } - @Ignore @Test public void loadForEditTest() { - //FIXME Get a discarded target sample in test database Form<DiscardedTargetSampleDto> form = service.loadForm(ObserveFixtures.SET_SEINE_ID); Assert.assertNotNull(form); ===================================== services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ps/observation/KeptTargetSampleServiceLocalTest.java ===================================== @@ -48,7 +48,7 @@ public class KeptTargetSampleServiceLocalTest extends ServiceLocalTestSupport { @Test public void canUseTargetSampleTest() { - Assert.assertTrue(service.canUseTargetSample(ObserveFixtures.SET_SEINE_ID)); + Assert.assertTrue(service.canUseSample(ObserveFixtures.SET_SEINE_ID)); } @Test ===================================== services/api/src/main/java/fr/ird/observe/services/service/data/ps/observation/KeptTargetSampleService.java → services/local-impl/src/test/java/fr/ird/observe/services/local/service/data/ps/observation/NonTargetSampleServiceLocalTest.java ===================================== @@ -1,8 +1,8 @@ -package fr.ird.observe.services.service.data.ps.observation; +package fr.ird.observe.services.local.service.data.ps.observation; /*- * #%L - * ObServe Services :: API + * ObServe Services :: Local implementation * %% * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io * %% @@ -22,12 +22,46 @@ package fr.ird.observe.services.service.data.ps.observation; * #L% */ +import fr.ird.observe.dto.data.ps.observation.NonTargetSampleDto; +import fr.ird.observe.dto.form.Form; +import fr.ird.observe.services.local.service.ServiceLocalTestSupport; +import fr.ird.observe.services.service.data.ps.observation.NonTargetSampleService; +import fr.ird.observe.test.DatabaseName; +import fr.ird.observe.test.ObserveFixtures; +import fr.ird.observe.test.spi.DatabaseNameConfiguration; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + /** - * Created on 16/10/2020. + * Created on 02/12/2020. * * @author Tony Chemit - dev@tchemit.fr * @since 8.0.1 */ -public interface KeptTargetSampleService extends GeneratedKeptTargetSampleService, TargetSampleAwareService { -} +@DatabaseNameConfiguration(DatabaseName.dataForTestSeine) +public class NonTargetSampleServiceLocalTest extends ServiceLocalTestSupport { + + protected NonTargetSampleService service; + + @Before + public void setUp() throws Exception { + service = localTestMethodResource.newService(NonTargetSampleService.class); + } + @Test + public void canUseTargetSampleTest() { + Assert.assertFalse(service.canUseSample(ObserveFixtures.SET_SEINE_ID)); + } + + @Test + public void loadForEditTest() { + //FIXME Get a Non target sample in test database + Form<NonTargetSampleDto> form = service.loadForm(ObserveFixtures.SET_SEINE_ID); + Assert.assertNotNull(form); + NonTargetSampleDto dto = form.getObject(); + Assert.assertNotNull(dto); + Assert.assertTrue(dto.isNonTargetLengthEmpty()); + } + +} ===================================== toolkit/service/src/main/java/fr/ird/observe/services/service/DataSourceService.java ===================================== @@ -80,4 +80,7 @@ public interface DataSourceService extends ObserveService, Closeable { @Get <D extends IdDto> boolean isIdValid(Class<D> type, String id); + @Get + String generateHomeId(); + } ===================================== toolkit/templates/src/main/java/fr/ird/observe/toolkit/templates/service/OpenableServiceTransformer.java ===================================== @@ -197,7 +197,10 @@ public class OpenableServiceTransformer extends ObjectModelTransformerToJava imp addInterface(output, String.format("%s<%s, %s>", OpenableDataService.class.getName(), dtoName, referenceName)); addAnnotation(output, output, Internal.class); - + if (referenceName.endsWith("TripReference")) { + // Add TripAwareService contract + addInterface(output, String.format("fr.ird.observe.services.service.data.TripAwareService<%s>", referenceName)); + } String spiClass = OpenableDtoServiceContext.class.getSimpleName(); addImport(output, OpenableDtoServiceContext.class); addImport(output, packageName + "." + dtoName); ===================================== toolkit/templates/src/main/java/fr/ird/observe/toolkit/templates/service/SimpleServiceTransformer.java ===================================== @@ -202,7 +202,10 @@ public class SimpleServiceTransformer extends ObjectModelTransformerToJava imple addInterface(output, String.format("%s<%s>", SimpleDataService.class.getName(), dtoName)); addAnnotation(output, output, Internal.class); - + if (dtoName.contains(".ps.observation.") || dtoName.endsWith("SampleDto")) { + // Add TripAwareService contract + addInterface(output, "fr.ird.observe.services.service.data.ps.observation.TargetSampleAwareService"); + } String spiClass = SimpleDtoServiceContext.class.getSimpleName(); addImport(output, SimpleDtoServiceContext.class); addImport(output, packageName + "." + dtoName); View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/3f3e0589002588d57981306a6... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/3f3e0589002588d57981306a6... You're receiving this email because of your account on gitlab.com.