Commit 3d914c7f authored by descamps's avatar descamps
Browse files

02/12/2021 - KDE - Modification Dto camelCase PA/PUA + Modification réponse modification PA

parent 36fc71d8
......@@ -21,10 +21,10 @@ public class ArchivalProfileUnitDto extends IdDto implements Serializable {
private String name;
private String description;
private ArchiveUnitProfileStatus status;
private String creationdate;
private String lastupdate;
private String activationdate;
private String deactivationdate;
private String creationDate;
private String lastUpdate;
private String activationDate;
private String deactivationDate;
private String controlSchema;
private List<String> fields;
}
......@@ -57,8 +57,8 @@ public class ProfileDto extends IdDto {
private ProfileStatus status;
private ProfileFormat format;
private String path;
private String creationdate;
private String lastupdate;
private String activationdate;
private String deactivationdate;
private String creationDate;
private String lastUpdate;
private String activationDate;
private String deactivationDate;
}
/**
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2020)
* and the signatories of the "VITAM - Accord du Contributeur" agreement.
*
* <p>
* contact@programmevitam.fr
*
* <p>
* This software is a computer program whose purpose is to implement
* implement a digital archiving front-office system for the secure and
* efficient high volumetry VITAM solution.
*
* <p>
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* <p>
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* <p>
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
......@@ -30,7 +30,7 @@
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* <p>
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
......@@ -39,10 +39,12 @@ package fr.gouv.vitamui.referential.external.client;
import com.fasterxml.jackson.databind.JsonNode;
import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto;
import fr.gouv.vitamui.commons.api.utils.ApiUtils;
import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient;
import fr.gouv.vitamui.commons.rest.client.ExternalHttpContext;
import fr.gouv.vitamui.referential.common.dto.ProfileDto;
import fr.gouv.vitamui.referential.common.rest.RestApi;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
......@@ -50,6 +52,7 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
......@@ -65,8 +68,10 @@ public class ProfileExternalRestClient extends BasePaginatingAndSortingRestClien
super(restTemplate, baseUrl);
}
@Override protected ParameterizedTypeReference<PaginatedValuesDto<ProfileDto>> getDtoPaginatedClass() {
return new ParameterizedTypeReference<PaginatedValuesDto<ProfileDto>>() { };
@Override
protected ParameterizedTypeReference<PaginatedValuesDto<ProfileDto>> getDtoPaginatedClass() {
return new ParameterizedTypeReference<PaginatedValuesDto<ProfileDto>>() {
};
}
@Override
......@@ -74,7 +79,8 @@ public class ProfileExternalRestClient extends BasePaginatingAndSortingRestClien
return RestApi.PROFILES_URL;
}
@Override protected Class<ProfileDto> getDtoClass() {
@Override
protected Class<ProfileDto> getDtoClass() {
return ProfileDto.class;
}
......@@ -110,17 +116,38 @@ public class ProfileExternalRestClient extends BasePaginatingAndSortingRestClien
JsonNode.class);
}
public ResponseEntity<JsonNode> updateProfile(ExternalHttpContext c, ProfileDto dto) {
beforeUpdate(dto);
ApiUtils.checkValidity(dto);
final String dtoId = dto.getId();
final HttpEntity<ProfileDto> request = new HttpEntity<>(dto, buildHeaders(c));
final ResponseEntity<JsonNode> response = restTemplate.exchange(getUrl() + CommonConstants.PATH_ID, HttpMethod.PUT,
request, JsonNode.class, dtoId);
checkResponse(response);
return response;
}
protected void beforeUpdate(final ProfileDto dto) {
Assert.isTrue(StringUtils.isNotBlank(dto.getId()), "The DTO identifier must be not null for update.");
ApiUtils.checkValidity(dto);
}
public static class FileSystemResource extends ByteArrayResource {
private String fileName;
public FileSystemResource(byte[] byteArray , String filename) {
public FileSystemResource(byte[] byteArray, String filename) {
super(byteArray);
this.fileName = filename;
}
public String getFilename() { return fileName; }
public void setFilename(String fileName) { this.fileName= fileName; }
public String getFilename() {
return fileName;
}
public void setFilename(String fileName) {
this.fileName = fileName;
}
}
......
......@@ -139,11 +139,11 @@ public class ProfileExternalController {
*/
//@Secured(ServicesData.ROLE_UPDATE_ARCHIVE_PROFILES)
@PutMapping(CommonConstants.PATH_ID)
public ProfileDto update(final @PathVariable("id") String id, final @Valid @RequestBody ProfileDto dto) {
public ResponseEntity<JsonNode> update(final @PathVariable("id") String id, final @Valid @RequestBody ProfileDto dto) {
LOGGER.debug("Update {} with {}", id, dto);
SanityChecker.check(id);
Assert.isTrue(StringUtils.equals(id, dto.getId()), "Unable to update profile : the DTO id must match the path id");
return profileExternalService.update(dto);
return profileExternalService.updateProfile(dto);
}
/**
......
......@@ -120,8 +120,8 @@ public class ProfileExternalService extends AbstractResourceClientService<Profil
return super.checkExists(criteria);
}
public ProfileDto update(final ProfileDto dto) {
return profileInternalRestClient.update(getInternalHttpContext(), dto);
public ResponseEntity<JsonNode> updateProfile(final ProfileDto dto) {
return profileInternalRestClient.updateProfile(getInternalHttpContext(), dto);
}
@Override
......
......@@ -41,10 +41,12 @@ import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.api.utils.ApiUtils;
import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient;
import fr.gouv.vitamui.commons.rest.client.InternalHttpContext;
import fr.gouv.vitamui.referential.common.dto.ProfileDto;
import fr.gouv.vitamui.referential.common.rest.RestApi;
import io.swagger.v3.core.util.Json;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
......@@ -100,7 +102,16 @@ public class ProfileInternalRestClient extends BasePaginatingAndSortingRestClien
return restTemplate.exchange(uriBuilder.build(id), HttpMethod.GET, request, Resource.class);
}
public ResponseEntity<JsonNode> updateProfile(InternalHttpContext context, final ProfileDto dto) {
LOGGER.debug("Update {}", dto);
ApiUtils.checkValidity(dto);
final String dtoId = dto.getId();
final HttpEntity<ProfileDto> request = new HttpEntity<>(dto, buildHeaders(context));
final ResponseEntity<JsonNode> response = restTemplate.exchange(getUrl() + CommonConstants.PATH_ID, HttpMethod.PUT,
request, JsonNode.class, dtoId);
checkResponse(response);
return response;
}
public ResponseEntity<JsonNode> updateProfileFile(InternalHttpContext context, String id, MultipartFile profileFile) throws IOException {
final UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(getUrl() + RestApi.UPDATE_PROFILE_FILE + CommonConstants.PATH_ID);
......
......@@ -14,17 +14,21 @@ public class ArchivalProfileUnitConverter {
return VitamUIUtils.copyProperties(dto, new ArchiveUnitProfileModel());
}
public ArchivalProfileUnitDto convertVitamToDto(final ArchiveUnitProfileModel archivalProfile) {
return VitamUIUtils.copyProperties(archivalProfile, new ArchivalProfileUnitDto());
public ArchivalProfileUnitDto convertVitamToDto(final ArchiveUnitProfileModel archivalUnitProfile) {
ArchivalProfileUnitDto archivalProfileUnitDto = VitamUIUtils.copyProperties(archivalUnitProfile, new ArchivalProfileUnitDto());
archivalProfileUnitDto.setActivationDate(archivalUnitProfile.getActivationdate());
archivalProfileUnitDto.setCreationDate(archivalUnitProfile.getCreationdate());
archivalProfileUnitDto.setDeactivationDate(archivalUnitProfile.getDeactivationdate());
archivalProfileUnitDto.setLastUpdate(archivalUnitProfile.getLastupdate());
return archivalProfileUnitDto;
}
public List<ArchiveUnitProfileModel> convertDtosToVitams(final List<ArchivalProfileUnitDto> dtos) {
return dtos.stream().map(this::convertDtoToVitam).collect(Collectors.toList());
}
public List<ArchivalProfileUnitDto> convertVitamsToDtos(final List<ArchiveUnitProfileModel> agencies) {
return agencies.stream().map(this::convertVitamToDto).collect(Collectors.toList());
public List<ArchivalProfileUnitDto> convertVitamsToDtos(final List<ArchiveUnitProfileModel> archiveUnitProfileModels) {
return archiveUnitProfileModels.stream().map(this::convertVitamToDto).collect(Collectors.toList());
}
}
......@@ -195,20 +195,20 @@ public class ArchivalProfileUnitInternalService {
if (dto.getStatus() != null) {
propertiesToUpdate.put("Status", dto.getStatus().toString());
}
if (dto.getCreationdate() != null) {
propertiesToUpdate.put("CreationDate", dto.getCreationdate());
if (dto.getCreationDate() != null) {
propertiesToUpdate.put("CreationDate", dto.getCreationDate());
}
if (dto.getLastupdate() != null) {
propertiesToUpdate.put("LastUpdate", dto.getLastupdate());
if (dto.getLastUpdate() != null) {
propertiesToUpdate.put("LastUpdate", dto.getLastUpdate());
}
if (dto.getActivationdate() != null) {
propertiesToUpdate.put("ActivationDate", dto.getActivationdate());
if (dto.getActivationDate() != null) {
propertiesToUpdate.put("ActivationDate", dto.getActivationDate());
}
if (dto.getDeactivationdate() != null) {
propertiesToUpdate.put("DeactivationDate", dto.getDeactivationdate());
if (dto.getDeactivationDate() != null) {
propertiesToUpdate.put("DeactivationDate", dto.getDeactivationDate());
}
if (dto.getControlSchema() != null) {
......
......@@ -45,8 +45,6 @@ import java.util.stream.Collectors;
public class ProfileConverter {
// TODO : Make a model DTO able to be converted as XML Droid format ?
public ProfileModel convertDtoToVitam(final ProfileDto dto) {
final ProfileModel Profile = VitamUIUtils.copyProperties(dto, new ProfileModel());
......@@ -55,7 +53,10 @@ public class ProfileConverter {
public ProfileDto convertVitamToDto(final ProfileModel profile) {
final ProfileDto dto = VitamUIUtils.copyProperties(profile, new ProfileDto());
dto.setActivationDate(profile.getActivationdate());
dto.setCreationDate(profile.getCreationdate());
dto.setDeactivationDate(profile.getDeactivationdate());
dto.setLastUpdate(profile.getLastupdate());
return dto;
}
......
......@@ -52,6 +52,7 @@ import fr.gouv.vitam.common.exception.InvalidParseOperationException;
import fr.gouv.vitam.common.exception.VitamClientException;
import fr.gouv.vitam.common.json.JsonHandler;
import fr.gouv.vitam.common.model.RequestResponse;
import fr.gouv.vitam.common.model.RequestResponseOK;
import fr.gouv.vitam.common.model.administration.ProfileModel;
import fr.gouv.vitamui.commons.api.domain.DirectionDto;
import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto;
......@@ -102,10 +103,10 @@ public class ProfileInternalService {
try {
LOGGER.info("All Profiles EvIdAppSession : {} ", vitamContext.getApplicationSessionId());
requestResponse = vitamProfileService.findArchivalProfiles(vitamContext, new Select().getFinalSelect());
final ProfileResponseDto managementContractResponseDto = objectMapper
final ProfileResponseDto profileResponseDto = objectMapper
.treeToValue(requestResponse.toJsonNode(), ProfileResponseDto.class);
return converter.convertVitamsToDtos(managementContractResponseDto.getResults());
return converter.convertVitamsToDtos(profileResponseDto.getResults());
} catch (VitamClientException | JsonProcessingException e) {
throw new InternalServerException("Unable to find Profiles", e);
}
......@@ -176,7 +177,7 @@ public class ProfileInternalService {
}
}
public ProfileDto updateProfile(ProfileDto dto, VitamContext vitamContext) {
public JsonNode updateProfile(ProfileDto dto, VitamContext vitamContext) {
String id = dto.getIdentifier();
if (id == null) {
throw new BadRequestException("id must be one the update criteria");
......@@ -191,10 +192,9 @@ public class ProfileInternalService {
query.set("$action", actions);
try {
RequestResponse<?> requestResponse = vitamProfileService.updateProfile(vitamContext, id, query);
final ProfileModel archivalUnitProfileVitamDto = objectMapper
.treeToValue(requestResponse.toJsonNode(), ProfileModel.class);
return converter.convertVitamToDto(archivalUnitProfileVitamDto);
} catch (JsonProcessingException | AccessExternalClientException e) {
return ((JsonNode) (((RequestResponseOK) requestResponse).getResults().get(0))).get("diffs");
} catch (AccessExternalClientException e) {
throw new InternalServerException("Can't update Archival Profile", e);
}
}
......@@ -218,17 +218,17 @@ public class ProfileInternalService {
if (dto.getPath() != null) {
propertiesToUpdate.put("Path", dto.getPath());
}
if (dto.getCreationdate() != null) {
propertiesToUpdate.put("CreationDate", dto.getCreationdate());
if (dto.getCreationDate() != null) {
propertiesToUpdate.put("CreationDate", dto.getCreationDate());
}
if (dto.getLastupdate() != null) {
propertiesToUpdate.put("LastUpdate", dto.getLastupdate());
if (dto.getLastUpdate() != null) {
propertiesToUpdate.put("LastUpdate", dto.getLastUpdate());
}
if (dto.getActivationdate() != null) {
propertiesToUpdate.put("ActivationDate", dto.getActivationdate());
if (dto.getActivationDate() != null) {
propertiesToUpdate.put("ActivationDate", dto.getActivationDate());
}
if (dto.getDeactivationdate() != null) {
propertiesToUpdate.put("DeactivationDate", dto.getDeactivationdate());
if (dto.getDeactivationDate() != null) {
propertiesToUpdate.put("DeactivationDate", dto.getDeactivationDate());
}
return propertiesToUpdate;
}
......
......@@ -146,7 +146,7 @@ public class ProfileInternalController {
@PutMapping(CommonConstants.PATH_ID)
public ProfileDto updateProfile(final @PathVariable("id") String id, final @RequestBody ProfileDto dto) throws AccessExternalClientException, InvalidParseOperationException {
public JsonNode updateProfile(final @PathVariable("id") String id, final @RequestBody ProfileDto dto) throws AccessExternalClientException, InvalidParseOperationException {
LOGGER.debug("Update {} with {}", id, dto);
ParameterChecker.checkParameter("Identifier is mandatory : ", id);
Assert.isTrue(StringUtils.equals(id, dto.getId()), "The DTO identifier must match the path identifier for update.");
......
......@@ -176,9 +176,9 @@ public class ProfileController extends AbstractUiRestController {
@ApiOperation(value = "Update entity")
@PutMapping(CommonConstants.PATH_ID)
@ResponseStatus(HttpStatus.OK)
public ProfileDto update(@RequestBody final ProfileDto profileDto) {
public ResponseEntity<JsonNode> updateProfile(@RequestBody final ProfileDto profileDto) {
LOGGER.debug("update profile {}", profileDto.getId());
return service.update(buildUiHttpContext(), profileDto);
return service.updateProfile(buildUiHttpContext(), profileDto);
}
......
......@@ -101,11 +101,11 @@ public class ProfileService extends AbstractPaginateService<ProfileDto> {
return client.check(context, ProfileDto);
}
public ProfileDto update(final ExternalHttpContext c, final ProfileDto dto) {
public ResponseEntity<JsonNode> updateProfile(final ExternalHttpContext c, final ProfileDto dto) {
if (StringUtils.isBlank(dto.getIdentifier())) {
throw new IllegalArgumentException("Profile is mandatory.");
}
return super.update(c, dto);
return client.updateProfile(c,dto);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment