Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 128cdb55 by Tony CHEMIT at 2017-08-01T13:42:33+02:00 Revoir la gestion d'erreur sur l'api Rest (Close #801) - - - - - 20 changed files: - client/src/main/java/fr/ird/observe/client/ObserveTextGenerator.java - client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIHandler.java - client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIModel.java - pom.xml - server/src/main/filtered-resources/mapping - server/src/main/java/fr/ird/observe/server/ObserveWebApplicationListener.java - server/src/main/java/fr/ird/observe/server/controller/v1/ObserveWebErrorController.java - server/src/main/java/fr/ird/observe/server/injector/ImmutableSetInjector.java - services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestClientContext.java - services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestClientSupport.java - − services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestErrorException.java - − services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestNotAvailableException.java - services-rest/src/test/java/fr/ird/observe/services/rest/service/PingServiceRestTest.java - services-topia/src/main/java/fr/ird/observe/services/topia/service/data/seine/FloatingObjectServiceTopia.java - services/src/main/java/fr/ird/observe/services/dto/AbstractObserveDto.java - services/src/main/java/fr/ird/observe/services/dto/source/DataSourceCreateConfigurationDto.java - services/src/main/java/fr/ird/observe/services/gson/ObserveDtoGsonSupplier.java - − services/src/main/java/fr/ird/observe/services/gson/ObserveHttpErrorAdapter.java - − services/src/main/java/fr/ird/observe/services/http/ObserveHttpError.java - services/src/main/java/fr/ird/observe/services/service/data/seine/FloatingObjectService.java Changes: ===================================== client/src/main/java/fr/ird/observe/client/ObserveTextGenerator.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ObserveTextGenerator.java +++ b/client/src/main/java/fr/ird/observe/client/ObserveTextGenerator.java @@ -51,29 +51,27 @@ public class ObserveTextGenerator { private static final Log log = LogFactory.getLog(ObserveTextGenerator.class); - protected static final String DATA_SOURCE_CONFIGURATION_TEMPLATE = "dataSourceConfiguration.ftl"; + private static final String DATA_SOURCE_CONFIGURATION_TEMPLATE = "dataSourceConfiguration.ftl"; - protected static final String CONNEXION_TEST_RESULT_TEMPLATE = "connexionTestResult.ftl"; + private static final String CONNEXION_TEST_RESULT_TEMPLATE = "connexionTestResult.ftl"; - protected static final String DATA_SOURCE_SELECT_MODE_RESUME_TEMPLATE = "dataSourceSelectModeResume.ftl"; + private static final String DATA_SOURCE_SELECT_MODE_RESUME_TEMPLATE = "dataSourceSelectModeResume.ftl"; - protected static final String DATA_SOURCE_CONNECTION_REPORT_TEMPLATE = "dataSourceConnectionReport.ftl"; + private static final String DATA_SOURCE_CONNECTION_REPORT_TEMPLATE = "dataSourceConnectionReport.ftl"; - protected static final String DATA_SOURCE_INFORMATION_TEMPLATE = "dataSourceInformation.ftl"; + private static final String DATA_SOURCE_INFORMATION_TEMPLATE = "dataSourceInformation.ftl"; - protected static final String DATA_SOURCE_POLICY_TEMPLATE = "dataSourcePolicy.ftl"; + private static final String DATA_SOURCE_POLICY_TEMPLATE = "dataSourcePolicy.ftl"; - protected static final String ABOUT_TEMPLATE = "about.ftl"; + private static final String ABOUT_TEMPLATE = "about.ftl"; - protected static final String TRANSLATE_TEMPLATE = "translate.ftl"; + private static final String INIT_STORAGE_TEMPLATE = "initStorage.ftl"; - protected static final String INIT_STORAGE_TEMPLATE = "initStorage.ftl"; + private final Configuration freemarkerConfiguration; - protected final Configuration freemarkerConfiguration; + private final ClientConfig observeConfiguration; - protected final ClientConfig observeConfiguration; - - public ObserveTextGenerator(ClientConfig observeConfiguration) { + ObserveTextGenerator(ClientConfig observeConfiguration) { this.observeConfiguration = observeConfiguration; freemarkerConfiguration = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); @@ -116,7 +114,7 @@ public class ObserveTextGenerator { return generateHtml(DATA_SOURCE_POLICY_TEMPLATE, model); } - public String getInitStorage(ObserveSwingApplicationDataSourcesManager.InitStorageModel model) { + String getInitStorage(ObserveSwingApplicationDataSourcesManager.InitStorageModel model) { return generateHtml(INIT_STORAGE_TEMPLATE, model); } @@ -128,15 +126,6 @@ public class ObserveTextGenerator { return generateHtml(ABOUT_TEMPLATE, model); } - public String getTranslate(File model) { - try { - URL url = model.toURI().toURL(); - return generateHtml(TRANSLATE_TEMPLATE, ImmutableMap.of("file", url)); - } catch (MalformedURLException e) { - throw new ObserveSwingTechnicalException(e); - } - } - protected String generateHtml(Locale locale, String templateName, Object model) { try { ===================================== client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIHandler.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIHandler.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIHandler.java @@ -247,8 +247,8 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto, SaveResultDto saveResult = getFloatingObjectService().save(activityId, bean); saveResult.toDto(bean); - List<FloatingObjectPartDto> parts = getModel().toParts(); - getFloatingObjectService().save(saveResult.getId(), parts); + ImmutableSet<FloatingObjectPartDto> parts = getModel().toParts(); + getFloatingObjectService().saveParts(saveResult.getId(), parts); saveResult.toDto(bean); return true; ===================================== client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIModel.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIModel.java +++ b/client/src/main/java/fr/ird/observe/client/ui/content/impl/seine/FloatingObjectUIModel.java @@ -34,7 +34,6 @@ import fr.ird.observe.services.dto.seine.FloatingObjectPartDto; import fr.ird.observe.services.dto.seine.ObjectMaterialHierarchyDto; import java.util.LinkedHashMap; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -77,9 +76,9 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { public static final String PROPERTY_GENERAL_TAB_VALID = "generalTabValid"; private static final String PROPERTY_MATERIALS_TAB_VALID = "materialsTabValid"; - public static final String PROPERTY_REFERENCE = "reference"; - public static final String PROPERTY_ARRIVING = "arriving"; - public static final String PROPERTY_LEAVING = "leaving"; + static final String PROPERTY_REFERENCE = "reference"; + private static final String PROPERTY_ARRIVING = "arriving"; + private static final String PROPERTY_LEAVING = "leaving"; public static final Set<String> GENERAL_TAB_PROPERTIES = ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_OBJECT_OPERATION, @@ -90,7 +89,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { ImmutableSet.<String>builder().add(FloatingObjectDto.PROPERTY_COMMENT).build(); protected boolean generalTabValid; - protected boolean materialsTabValid; + private boolean materialsTabValid; private final Map<ObjectMaterialDto, String> whenArriving; private final Map<ObjectMaterialDto, String> whenLeaving; @@ -116,8 +115,8 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { } - public List<FloatingObjectPartDto> toParts() { - List<FloatingObjectPartDto> result = new LinkedList<>(); + ImmutableSet<FloatingObjectPartDto> toParts() { + ImmutableSet.Builder<FloatingObjectPartDto> result = ImmutableSet.builder(); for (ObjectMaterialDto o : getAll()) { FloatingObjectPartDto partDto = new FloatingObjectPartDto(); partDto.setObjectMaterial(referenceBinderEngine.transformReferentialDtoToReference(referentialLocale, o)); @@ -129,7 +128,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { } result.add(partDto); } - return result; + return result.build(); } public void reset() { @@ -151,7 +150,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { return alls; } - public void setReferentialMap(Map<String, ObjectMaterialDto> referentialMap) { + void setReferentialMap(Map<String, ObjectMaterialDto> referentialMap) { this.referentialMap = referentialMap; } @@ -171,7 +170,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> { whenLeaving.put(dto, value); } - public DefaultMutableTreeTableNode createRoot(Decorator<ObjectMaterialDto> decoratorByType, List<ObjectMaterialHierarchyDto> referential) { + DefaultMutableTreeTableNode createRoot(Decorator<ObjectMaterialDto> decoratorByType, List<ObjectMaterialHierarchyDto> referential) { DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode(); for (ObjectMaterialHierarchyDto dto : referential) { root.add(new FloatingObjectPartsTreeNode(decoratorByType, this, dto)); ===================================== pom.xml ===================================== --- a/pom.xml +++ b/pom.xml @@ -179,7 +179,7 @@ <nuitonUtilsVersion>3.0-rc-18</nuitonUtilsVersion> <nuitonConverterVersion>1.0</nuitonConverterVersion> <nuitonVersionVersion>1.0-rc-2</nuitonVersionVersion> - <httpVersion>1.0.2-SNAPSHOT</httpVersion> + <httpVersion>1.0.2</httpVersion> <xworkVersion>2.3.33</xworkVersion> <flexmarkVersion>0.22.14</flexmarkVersion> <hibernateVersion>5.1.8.Final</hibernateVersion> ===================================== server/src/main/filtered-resources/mapping ===================================== --- a/server/src/main/filtered-resources/mapping +++ b/server/src/main/filtered-resources/mapping @@ -161,7 +161,7 @@ GET /api/v1/data/seine/FloatingObjectService/loadReferenceToRead GET /api/v1/data/seine/FloatingObjectService/preCreate v1.data.seine.FloatingObjectServiceRestApi.preCreate GET /api/v1/data/seine/FloatingObjectService/retainExistingIds v1.data.seine.FloatingObjectServiceRestApi.retainExistingIds POST /api/v1/data/seine/FloatingObjectService/save v1.data.seine.FloatingObjectServiceRestApi.save -POST /api/v1/data/seine/FloatingObjectService/save v1.data.seine.FloatingObjectServiceRestApi.save +POST /api/v1/data/seine/FloatingObjectService/saveParts v1.data.seine.FloatingObjectServiceRestApi.saveParts GET /api/v1/data/seine/NonTargetCatchReleaseService/getSampleSpecies v1.data.seine.NonTargetCatchReleaseServiceRestApi.getSampleSpecies GET /api/v1/data/seine/NonTargetCatchReleaseService/loadForm v1.data.seine.NonTargetCatchReleaseServiceRestApi.loadForm POST /api/v1/data/seine/NonTargetCatchReleaseService/save v1.data.seine.NonTargetCatchReleaseServiceRestApi.save ===================================== server/src/main/java/fr/ird/observe/server/ObserveWebApplicationListener.java ===================================== --- a/server/src/main/java/fr/ird/observe/server/ObserveWebApplicationListener.java +++ b/server/src/main/java/fr/ird/observe/server/ObserveWebApplicationListener.java @@ -77,7 +77,7 @@ public class ObserveWebApplicationListener implements WebMotionServerListener { context.addInjector(new ObserveReferenceSetRequestInjector(gson)); context.addInjector(new DateInjector(HRequestBuilder.DATE_PATTERN)); context.addInjector(new SqlScriptProducerRequestInjector(gson)); - context.addInjector(new ImmutableSetInjector()); + context.addInjector(new ImmutableSetInjector(gson)); context.addConverter(new ObserveDtoConverter(gson), ObserveDbUserDto.class); context.getServletContext().setAttribute(ObserveWebApplicationContext.APPLICATION_CONTEXT_PARAMETER, applicationContext); ===================================== server/src/main/java/fr/ird/observe/server/controller/v1/ObserveWebErrorController.java ===================================== --- a/server/src/main/java/fr/ird/observe/server/controller/v1/ObserveWebErrorController.java +++ b/server/src/main/java/fr/ird/observe/server/controller/v1/ObserveWebErrorController.java @@ -22,7 +22,7 @@ package fr.ird.observe.server.controller.v1; * #L% */ -import fr.ird.observe.services.http.ObserveHttpError; +import io.ultreia.java4all.http.HResponseError; import fr.ird.observe.services.security.ObserveWebSecurityExceptionSupport; import fr.ird.observe.services.security.UnauthorizedException; import java.lang.reflect.InvocationTargetException; @@ -42,7 +42,7 @@ import org.debux.webmotion.server.call.HttpContext; */ public class ObserveWebErrorController extends WebMotionController { - public ObserveHttpError error(HttpContext.ErrorData errorData) { + public HResponseError error(HttpContext.ErrorData errorData) { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") Throwable exception = errorData.getException(); @@ -96,10 +96,10 @@ public class ObserveWebErrorController extends WebMotionController { } - return new ObserveHttpError(statusCode, - exception == null ? null : exception.getClass(), - message, - exception); + return new HResponseError(statusCode, + exception == null ? null : exception.getClass(), + message, + exception); } ===================================== server/src/main/java/fr/ird/observe/server/injector/ImmutableSetInjector.java ===================================== --- a/server/src/main/java/fr/ird/observe/server/injector/ImmutableSetInjector.java +++ b/server/src/main/java/fr/ird/observe/server/injector/ImmutableSetInjector.java @@ -23,7 +23,9 @@ package fr.ird.observe.server.injector; */ import com.google.common.collect.ImmutableSet; +import com.google.gson.Gson; import java.lang.reflect.Type; +import java.util.Collection; import java.util.Objects; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -47,6 +49,11 @@ public class ImmutableSetInjector implements ExecutorParametersInjectorHandler.I /** Logger. */ private static final Log log = LogFactory.getLog(ImmutableSetInjector.class); + private final Gson gson; + + public ImmutableSetInjector(Gson gson) { + this.gson = gson; + } @Override public Object getValue(Mapping mapping, Call call, String name, Class<?> type, Type generic) { @@ -54,11 +61,8 @@ public class ImmutableSetInjector implements ExecutorParametersInjectorHandler.I ImmutableSet result = null; if (ImmutableSet.class.isAssignableFrom(type)) { - // Type des objets contenu dans le set - // Type[] actualTypeArguments = ((ParameterizedType) generic).getActualTypeArguments(); - // Type subType = actualTypeArguments[0]; - ImmutableSet.Builder builder = ImmutableSet.builder(); + ImmutableSet.Builder<Object> builder = ImmutableSet.builder(); if (call.getParameterTree().getObject() != null) { Call.ParameterTree parameterTree = call.getParameterTree().getObject().get(name); @@ -66,9 +70,8 @@ public class ImmutableSetInjector implements ExecutorParametersInjectorHandler.I Objects.requireNonNull(parameterTree, "Le paramètre " + name + " n'as pas été trouvé, recompiler (parameter)!"); String[] values = (String[]) parameterTree.getValue(); - for (String value : values) { - builder.add(value); - } + Collection o = gson.fromJson(values[0], generic); + builder.addAll(o); } result = builder.build(); @@ -81,4 +84,5 @@ public class ImmutableSetInjector implements ExecutorParametersInjectorHandler.I return result; } + } ===================================== services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestClientContext.java ===================================== --- a/services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestClientContext.java +++ b/services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestClientContext.java @@ -56,11 +56,11 @@ public class ObserveServiceRestClientContext { this.locateService = locateService; } - public ObserveRequestBuilderFactory getRequestBuilderFactory() { + ObserveRequestBuilderFactory getRequestBuilderFactory() { return requestBuilderFactory; } - public HResponseBuilder getResponseBuilder() { + HResponseBuilder getResponseBuilder() { return responseBuilder; } @@ -68,23 +68,19 @@ public class ObserveServiceRestClientContext { return initializer; } - public String getSpeciesListConfigurationAsString() { + String getSpeciesListConfigurationAsString() { return speciesListConfigurationAsString; } - public Optional<ObserveDataSourceConnectionRest> getDataSourceConnection() { - return (Optional) initializer.getDataSourceConnection(); - } - public Optional<ObserveDataSourceConfiguration> getDataSourceConfiguration() { return initializer.getDataSourceConfiguration(); } - public boolean withApplicationLocale() { + boolean withApplicationLocale() { return getApplicationLocale() != null; } - public Locale getApplicationLocale() { + Locale getApplicationLocale() { return initializer.getApplicationLocale(); } @@ -92,7 +88,7 @@ public class ObserveServiceRestClientContext { return initializer.getReferentialLocale(); } - public boolean withReferentialLocale() { + boolean withReferentialLocale() { return getReferentialLocale() != null; } @@ -101,7 +97,7 @@ public class ObserveServiceRestClientContext { return getServiceUrl() + suffix; } - String getServiceUrl() { + private String getServiceUrl() { String serviceUrl; if (initializer.withDataSourceConnection()) { ===================================== services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestClientSupport.java ===================================== --- a/services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestClientSupport.java +++ b/services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestClientSupport.java @@ -25,7 +25,6 @@ package fr.ird.observe.services.rest; import com.google.gson.Gson; import fr.ird.observe.services.service.ObserveService; import io.ultreia.java4all.http.HRequest; -import io.ultreia.java4all.http.HRequestBuilder; import io.ultreia.java4all.http.HResponse; import io.ultreia.java4all.http.HRestClientService; import org.nuiton.util.TimeLog; @@ -52,7 +51,7 @@ public class ObserveServiceRestClientSupport implements HRestClientService, Obse } @Override - public HRequestBuilder create(String baseUrl) { + public ObserveRequestBuilder create(String baseUrl) { return getRequestBuilderFactory().create(serviceContext, baseUrl); } @@ -61,6 +60,8 @@ public class ObserveServiceRestClientSupport implements HRestClientService, Obse long t0 = TimeLog.getTime(); try { return serviceContext.getResponseBuilder().executeRequest(request, expectedStatusCode); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { throw new IllegalStateException("Can't execute request " + request, e); } finally { @@ -73,6 +74,8 @@ public class ObserveServiceRestClientSupport implements HRestClientService, Obse long t0 = TimeLog.getTime(); try { return serviceContext.getResponseBuilder().executeRequest(request); + } catch (RuntimeException e) { + throw e; } catch (Exception e) { throw new IllegalStateException("Can't execute request " + request, e); } finally { ===================================== services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestErrorException.java deleted ===================================== --- a/services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestErrorException.java +++ /dev/null @@ -1,38 +0,0 @@ -package fr.ird.observe.services.rest; - -/*- - * #%L - * ObServe :: Services REST Implementation - * %% - * Copyright (C) 2008 - 2017 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 Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class ObserveServiceRestErrorException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public ObserveServiceRestErrorException() { - } - - public ObserveServiceRestErrorException(String message) { - super(message); - } -} ===================================== services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestNotAvailableException.java deleted ===================================== --- a/services-rest/src/main/java/fr/ird/observe/services/rest/ObserveServiceRestNotAvailableException.java +++ /dev/null @@ -1,49 +0,0 @@ -package fr.ird.observe.services.rest; - -/* - * #%L - * ObServe :: Services REST Implementation - * %% - * Copyright (C) 2008 - 2017 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.net.URL; - -/** - * Exception à retourner quand le service n'est pas accessible. - * <p> - * Created on 06/09/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class ObserveServiceRestNotAvailableException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - private final URL serverUrl; - - public ObserveServiceRestNotAvailableException(URL serverUrl) { - super("Server " + serverUrl + " not available"); - this.serverUrl = serverUrl; - } - - public URL getServerUrl() { - return serverUrl; - } - -} ===================================== services-rest/src/test/java/fr/ird/observe/services/rest/service/PingServiceRestTest.java ===================================== --- a/services-rest/src/test/java/fr/ird/observe/services/rest/service/PingServiceRestTest.java +++ b/services-rest/src/test/java/fr/ird/observe/services/rest/service/PingServiceRestTest.java @@ -22,13 +22,12 @@ package fr.ird.observe.services.rest.service; * #L% */ -import fr.ird.observe.services.rest.ObserveServiceRestNotAvailableException; import fr.ird.observe.services.configuration.rest.ObserveDataSourceConfigurationRest; import fr.ird.observe.services.service.PingService; -import org.junit.Test; - +import io.ultreia.java4all.http.HResponseNotAvailableException; import java.net.MalformedURLException; import java.net.URL; +import org.junit.Test; /** * Created on 07/09/15. @@ -37,7 +36,7 @@ import java.net.URL; */ public class PingServiceRestTest extends AbstractServiceRestTest { - @Test(expected = ObserveServiceRestNotAvailableException.class) + @Test(expected = HResponseNotAvailableException.class) public void testPingWithBadServerUrl() throws MalformedURLException, CloneNotSupportedException { ObserveDataSourceConfigurationRest dataSourceConfiguration = restTestMethodResource.getDataSourceConfiguration().clone(); ===================================== services-topia/src/main/java/fr/ird/observe/services/topia/service/data/seine/FloatingObjectServiceTopia.java ===================================== --- a/services-topia/src/main/java/fr/ird/observe/services/topia/service/data/seine/FloatingObjectServiceTopia.java +++ b/services-topia/src/main/java/fr/ird/observe/services/topia/service/data/seine/FloatingObjectServiceTopia.java @@ -184,7 +184,7 @@ public class FloatingObjectServiceTopia extends ObserveServiceTopia implements F } @Override - public SaveResultDto save(String floatingObjectId, List<FloatingObjectPartDto> dtos) { + public SaveResultDto saveParts(String floatingObjectId, ImmutableSet<FloatingObjectPartDto> floatingObjectParts) { FloatingObject floatingObject = loadEntity(FloatingObjectDto.class, floatingObjectId); ImmutableMap<String, ObjectMaterial> objectMaterialsMap = Maps.uniqueIndex(getTopiaPersistenceContext().getObjectMaterialDao().findAll(), ObjectMaterial::getTopiaId); @@ -192,7 +192,7 @@ public class FloatingObjectServiceTopia extends ObserveServiceTopia implements F FloatingObjectPartTopiaDao dao = getTopiaPersistenceContext().getFloatingObjectPartDao(); Set<String> remainingIds = new LinkedHashSet<>(); List<FloatingObjectPart> toSave = new LinkedList<>(); - for (FloatingObjectPartDto dto : dtos) { + for (FloatingObjectPartDto dto : floatingObjectParts) { FloatingObjectPart floatingObjectPart = existingMap.get(dto.getObjectMaterial().getCode()); if (floatingObjectPart != null) { String topiaId = floatingObjectPart.getTopiaId(); ===================================== services/src/main/java/fr/ird/observe/services/dto/AbstractObserveDto.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/dto/AbstractObserveDto.java +++ b/services/src/main/java/fr/ird/observe/services/dto/AbstractObserveDto.java @@ -32,7 +32,7 @@ import org.nuiton.util.CollectionUtil; * @author Tony Chemit - dev@tchemit.fr * @since 7.0 */ -public abstract class AbstractObserveDto extends AbstractSerializableBean { +public abstract class AbstractObserveDto extends AbstractSerializableBean implements ObserveDto{ private static final long serialVersionUID = 1L; ===================================== services/src/main/java/fr/ird/observe/services/dto/source/DataSourceCreateConfigurationDto.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/dto/source/DataSourceCreateConfigurationDto.java +++ b/services/src/main/java/fr/ird/observe/services/dto/source/DataSourceCreateConfigurationDto.java @@ -39,31 +39,31 @@ public class DataSourceCreateConfigurationDto extends AbstractObserveDto { /** * Le contenu de la base à importer (Optionel). */ - protected byte[] optionalImportDatabase; + private byte[] optionalImportDatabase; /** * Une configuration de la dataSource à utiliser pour importer le référentiel (Optionel). */ - protected ObserveDataSourceConfiguration optionalImportReferentialDataSourceConfiguration; + private ObserveDataSourceConfiguration optionalImportReferentialDataSourceConfiguration; /** * Une configuration de la dataSource à utiliser pour importer des données (Optionel). */ - protected ObserveDataSourceConfiguration optionalImportDataDataSourceConfiguration; + private ObserveDataSourceConfiguration optionalImportDataDataSourceConfiguration; /** * Les données à importer (ids des marées) (Optionel). */ - protected ImmutableSet<String> optionalImportDataIds; + private ImmutableSet<String> optionalImportDataIds; /** * Pour autoriser la création d'une base vide (utilisé pour les bases temporaires) */ - protected boolean canCreateEmptyDatabase; + private boolean canCreateEmptyDatabase; private boolean leaveOpenSource; - public boolean isCanCreateEmptyDatabase() { + private boolean isCanCreateEmptyDatabase() { return canCreateEmptyDatabase; } ===================================== services/src/main/java/fr/ird/observe/services/gson/ObserveDtoGsonSupplier.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/gson/ObserveDtoGsonSupplier.java +++ b/services/src/main/java/fr/ird/observe/services/gson/ObserveDtoGsonSupplier.java @@ -47,8 +47,9 @@ import fr.ird.observe.services.gson.reference.DataReferenceSetAdapter; import fr.ird.observe.services.gson.reference.ReferentialReferenceAdapter; import fr.ird.observe.services.gson.reference.ReferentialReferenceSetAdapter; import fr.ird.observe.services.gson.reference.UnknownReferenceAdapter; -import fr.ird.observe.services.http.ObserveHttpError; +import io.ultreia.java4all.http.HResponseError; import fr.ird.observe.services.service.actions.report.ReportVariable; +import io.ultreia.java4all.http.HResponseErrorAdapter; import java.sql.Blob; import java.util.Collection; import java.util.Date; @@ -144,7 +145,7 @@ public class ObserveDtoGsonSupplier implements Supplier<Gson> { gsonBuilder.registerTypeAdapter(Form.class, new FormAdapter()); gsonBuilder.registerTypeAdapter(ReportVariable.class, new ReportVariableAdapter()); gsonBuilder.registerTypeAdapter(Version.class, new VersionAdapter()); - gsonBuilder.registerTypeAdapter(ObserveHttpError.class, new ObserveHttpErrorAdapter()); + gsonBuilder.registerTypeAdapter(HResponseError.class, new HResponseErrorAdapter()); gsonBuilder.enableComplexMapKeySerialization(); } ===================================== services/src/main/java/fr/ird/observe/services/gson/ObserveHttpErrorAdapter.java deleted ===================================== --- a/services/src/main/java/fr/ird/observe/services/gson/ObserveHttpErrorAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -package fr.ird.observe.services.gson; - -/*- - * #%L - * ObServe :: Services - * %% - * Copyright (C) 2008 - 2017 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 com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import fr.ird.observe.services.http.ObserveHttpError; -import java.lang.reflect.Type; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class ObserveHttpErrorAdapter implements JsonDeserializer<ObserveHttpError> { - @Override - public ObserveHttpError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - - JsonObject jsonObject = json.getAsJsonObject(); - - Integer httpCode = context.deserialize(jsonObject.get(ObserveHttpError.PROPERTY_HTTP_CODE), Integer.class); - - String message = context.deserialize(jsonObject.get(ObserveHttpError.PROPERTY_MESSAGE), String.class); - - Class exceptionType = context.deserialize(jsonObject.get(ObserveHttpError.PROPERTY_EXECPTION_TYPE), Class.class); - - Throwable exception = null; - - if (exceptionType != null) { - - exception = context.deserialize(jsonObject.get(ObserveHttpError.PROPERTY_EXCEPTION), exceptionType); - - } - - return new ObserveHttpError(httpCode, exceptionType, message, exception); - } -} ===================================== services/src/main/java/fr/ird/observe/services/http/ObserveHttpError.java deleted ===================================== --- a/services/src/main/java/fr/ird/observe/services/http/ObserveHttpError.java +++ /dev/null @@ -1,68 +0,0 @@ -package fr.ird.observe.services.http; - -/*- - * #%L - * ObServe :: Services - * %% - * Copyright (C) 2008 - 2017 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 Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class ObserveHttpError { - - public static final String PROPERTY_HTTP_CODE = "httpCode"; - - public static final String PROPERTY_EXECPTION_TYPE = "exceptionType"; - - public static final String PROPERTY_MESSAGE = "message"; - - public static final String PROPERTY_EXCEPTION = "exception"; - - protected final Integer httpCode; - - protected final Class<?> exceptionType; - - protected final String message; - - protected final Throwable exception; - - public ObserveHttpError(Integer httpCode, Class<?> exceptionType, String message, Throwable exception) { - this.httpCode = httpCode; - this.exceptionType = exceptionType; - this.message = message; - this.exception = exception; - } - - public Integer getHttpCode() { - return httpCode; - } - - public Class<?> getExceptionType() { - return exceptionType; - } - - public String getMessage() { - return message; - } - - public Throwable getException() { - return exception; - } -} ===================================== services/src/main/java/fr/ird/observe/services/service/data/seine/FloatingObjectService.java ===================================== --- a/services/src/main/java/fr/ird/observe/services/service/data/seine/FloatingObjectService.java +++ b/services/src/main/java/fr/ird/observe/services/service/data/seine/FloatingObjectService.java @@ -89,7 +89,7 @@ public interface FloatingObjectService extends ObserveService { @Write @WriteDataPermission @Post - SaveResultDto save(String floatingObjectId, List<FloatingObjectPartDto> dtos); + SaveResultDto saveParts(String floatingObjectId, ImmutableSet<FloatingObjectPartDto> floatingObjectParts); @Write @WriteDataPermission View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/128cdb55e5c3d45be71a81a9145c... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/128cdb55e5c3d45be71a81a9145c... You're receiving this email because of your account on gitlab.com.