Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: 41aadc59 by tchemit at 2019-01-14T16:19:06Z Revert referential write service + improve some code - - - - - 5 changed files: - + dto/src/main/java/fr/ird/observe/dto/referential/SpeciesGroupHelper.java - server-core/src/main/filtered-resources/mapping - services-local/src/main/java/fr/ird/observe/services/local/service/data/seine/NonTargetCatchReleaseServiceLocal.java - services-local/src/main/java/fr/ird/observe/services/local/service/referential/ReferentialServiceLocal.java - services/src/main/java/fr/ird/observe/services/service/referential/ReferentialService.java Changes: ===================================== dto/src/main/java/fr/ird/observe/dto/referential/SpeciesGroupHelper.java ===================================== @@ -0,0 +1,36 @@ +package fr.ird.observe.dto.referential; + +/*- + * #%L + * ObServe :: Dto + * %% + * Copyright (C) 2008 - 2019 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 java.util.Arrays; +import java.util.List; + +public class SpeciesGroupHelper extends GeneratedSpeciesGroupHelper { + //FIXME PROTECTED-ID + public static final List<String> SPECIES_GROUP_IDS = Arrays.asList( + "fr.ird.referential.common.SpeciesGroup#1445863056144#0.9820877553253712", + "fr.ird.referential.common.SpeciesGroup#1239832683690#0.24333033683679461", + "fr.ird.referential.common.SpeciesGroup#1446014286433#0.6480183366605247", + "fr.ird.referential.common.SpeciesGroup#1239832683689#0.7120116158620075" + ); +} ===================================== server-core/src/main/filtered-resources/mapping ===================================== @@ -228,6 +228,7 @@ GET /api/v1/referential/ReferentialService/getReferenceSet POST /api/v1/referential/ReferentialService/getReferentialIds v1.referential.ReferentialServiceRestApi.getReferentialIds GET /api/v1/referential/ReferentialService/getReferentialReferenceSets v1.referential.ReferentialServiceRestApi.getReferentialReferenceSets POST /api/v1/referential/ReferentialService/insertMissingReferential v1.referential.ReferentialServiceRestApi.insertMissingReferential +GET /api/v1/referential/ReferentialService/loadDto v1.referential.ReferentialServiceRestApi.loadDto GET /api/v1/referential/ReferentialService/loadForm v1.referential.ReferentialServiceRestApi.loadForm GET /api/v1/referential/ReferentialService/loadObservedSystems v1.referential.ReferentialServiceRestApi.loadObservedSystems GET /api/v1/referential/ReferentialService/loadReference v1.referential.ReferentialServiceRestApi.loadReference ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/data/seine/NonTargetCatchReleaseServiceLocal.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service.data.seine; * 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>. @@ -26,15 +26,16 @@ import fr.ird.observe.dto.data.seine.SetSeineNonTargetCatchReleaseDto; import fr.ird.observe.dto.form.Form; import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet; import fr.ird.observe.dto.referential.SpeciesReference; +import fr.ird.observe.dto.referential.SpeciesGroupHelper; import fr.ird.observe.dto.result.SaveResultDto; import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.local.service.ObserveServiceLocal; -import fr.ird.observe.services.local.service.referential.ReferentialServiceLocal; import fr.ird.observe.services.service.data.seine.NonTargetCatchReleaseService; -import java.util.stream.Collectors; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.stream.Collectors; /** * @author Tony Chemit - dev@tchemit.fr @@ -54,7 +55,7 @@ public class NonTargetCatchReleaseServiceLocal extends ObserveServiceLocal imple return SPECIES_SPI.toReferentialReferenceSet(setSeine.getNonTargetCatch().stream() .map(NonTargetCatch::getSpecies) .distinct() - .filter(s -> ReferentialServiceLocal.SPECIES_GROUP_IDS.contains(s.getSpeciesGroup().getTopiaId())) + .filter(s -> SpeciesGroupHelper.SPECIES_GROUP_IDS.contains(s.getSpeciesGroup().getTopiaId())) .collect(Collectors.toList()), getReferentialLocale(), null); } @@ -64,7 +65,7 @@ public class NonTargetCatchReleaseServiceLocal extends ObserveServiceLocal imple log.trace("loadForm(" + setSeineId + ")"); } - SetSeine setSeine = SET_SEINE_NON_TARGET_RELEASE_SPI.loadEntity(getTopiaPersistenceContext(),setSeineId); + SetSeine setSeine = SET_SEINE_NON_TARGET_RELEASE_SPI.loadEntity(getTopiaPersistenceContext(), setSeineId); return SET_SEINE_NON_TARGET_RELEASE_SPI.dataEntityToForm(setSeine, getReferentialLocale()); } ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/referential/ReferentialServiceLocal.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service.referential; * 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>. @@ -41,6 +41,7 @@ import fr.ird.observe.dto.referential.ReferenceStatus; import fr.ird.observe.dto.referential.ReferentialDto; import fr.ird.observe.dto.referential.SpeciesDto; import fr.ird.observe.dto.referential.SpeciesGroupDto; +import fr.ird.observe.dto.referential.SpeciesGroupHelper; import fr.ird.observe.dto.referential.seine.ObservedSystemReference; import fr.ird.observe.dto.result.SaveResultDto; import fr.ird.observe.entities.ObserveDataEntity; @@ -82,7 +83,6 @@ import org.nuiton.topia.persistence.script.TopiaSqlScript; import org.nuiton.version.Version; import org.nuiton.version.Versions; -import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.LinkedHashSet; @@ -99,12 +99,6 @@ import java.util.Set; */ public class ReferentialServiceLocal extends ObserveServiceLocal implements ReferentialService { - public static final List<String> SPECIES_GROUP_IDS = Arrays.asList( - "fr.ird.observe.entities.referentiel.SpeciesGroup#1445863056144#0.9820877553253712", - "fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683690#0.24333033683679461", - "fr.ird.observe.entities.referentiel.SpeciesGroup#1446014286433#0.6480183366605247", - "fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683689#0.7120116158620075" - ); private static final Logger log = LogManager.getLogger(ReferentialServiceLocal.class); @Override @@ -151,12 +145,24 @@ public class ReferentialServiceLocal extends ObserveServiceLocal implements Refe @Override public ImmutableSet<SpeciesGroupDto> loadSensibleSpeciesGroup() { ImmutableSet.Builder<SpeciesGroupDto> result = ImmutableSet.builder(); - for (String speciesGroupId : SPECIES_GROUP_IDS) { + for (String speciesGroupId : SpeciesGroupHelper.SPECIES_GROUP_IDS) { result.add(loadSpeciesGroup(speciesGroupId)); } return result.build(); } + @Override + public <D extends ReferentialDto> D loadDto(Class<D> type, String id) { + ReferentialDtoEntityContext<D, ?, ?> spi = DbModelHelper.fromReferentialDto(type); + ObserveReferentialEntity entity = loadEntity(type, id); + D dto = spi.toDto(serviceContext.getReferentialLocale(), entity); + dto.setVersion(entity.getTopiaVersion()); + dto.setCreateDate(entity.getTopiaCreateDate()); + dto.setLastUpdateDate(entity.getLastUpdateDate()); + dto.setStatus(ReferenceStatus.valueOf(entity.getStatus().name())); + return dto; + } + @Override public <D extends ReferentialDto> Form<D> loadForm(Class<D> type, String id) { ReferentialDtoEntityContext<D, ?, ?> spi = DbModelHelper.fromReferentialDto(type); ===================================== services/src/main/java/fr/ird/observe/services/service/referential/ReferentialService.java ===================================== @@ -10,12 +10,12 @@ package fr.ird.observe.services.service.referential; * 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>. @@ -87,7 +87,11 @@ public interface ReferentialService extends ObserveService { @ReadReferentialPermission @Get - <R extends ReferentialDto> Form<R> loadForm(Class<R> type, String id); + <D extends ReferentialDto> D loadDto(Class<D> type, String id); + + @ReadReferentialPermission + @Get + <D extends ReferentialDto> Form<D> loadForm(Class<D> type, String id); @Get @ReadReferentialPermission @@ -95,22 +99,24 @@ public interface ReferentialService extends ObserveService { @Get @WriteReferentialPermission - <R extends ReferentialDto> Form<R> preCreate(Class<R> type); + <D extends ReferentialDto> Form<D> preCreate(Class<D> type); @WriteReferentialPermission @Write @Post - <R extends ReferentialDto> SaveResultDto save(R bean); + <D extends ReferentialDto> SaveResultDto save(D bean); @WriteReferentialPermission + @WriteDataPermission @Write @Delete - <R extends ReferentialDto> void delete(Class<R> type, String id); + <D extends ReferentialDto> void delete(Class<D> type, String id); @Post @WriteReferentialPermission + @WriteDataPermission @Write - <E extends ReferentialDto> void replaceReference(Class<E> beanType, String idToReplace, String replaceId); + <D extends ReferentialDto> void replaceReference(Class<D> beanType, String idToReplace, String replaceId); @Post(useMultiPartForm = true) @ReadReferentialPermission @@ -118,13 +124,12 @@ public interface ReferentialService extends ObserveService { @Get @ReadReferentialPermission - <R extends ReferentialDto> boolean exists(Class<R> type, String id); + <D extends ReferentialDto> boolean exists(Class<D> type, String id); @ReadReferentialPermission @Post ImmutableSetStringMap getReferentialIds(); - @ReadReferentialPermission @ReadDataPermission @Post(useMultiPartForm = true) View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/41aadc596cd44e2163941e683972... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/41aadc596cd44e2163941e683972... You're receiving this email because of your account on gitlab.com.