Skip to content

Commit

Permalink
Story #14127: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Benaissa BENARBIA committed Feb 4, 2025
1 parent fb82612 commit 32203a5
Show file tree
Hide file tree
Showing 21 changed files with 303 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.domain.ExternalParametersDto;
import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto;
import fr.gouv.vitamui.commons.rest.client.AbstractHttpContext;
import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient;
import fr.gouv.vitamui.commons.rest.client.InternalHttpContext;
import fr.gouv.vitamui.iam.common.rest.RestApi;
Expand All @@ -55,8 +56,6 @@

/**
* A REST client to check existence, read, create, update and delete the external parameters.
*
*
*/
public class ExternalParametersInternalRestClient
extends BasePaginatingAndSortingRestClient<ExternalParametersDto, InternalHttpContext> {
Expand All @@ -69,10 +68,11 @@ public ExternalParametersInternalRestClient(final RestTemplate restTemplate, fin

/**
* Retrieve the external parameters associated to the authenticated user.
*
* @param context
* @return the external parameters
*/
public ExternalParametersDto getMyExternalParameters(final InternalHttpContext context) {
public ExternalParametersDto getMyExternalParameters(final AbstractHttpContext context) {
LOGGER.debug("getMyExternalParameters");
final HttpEntity<?> request = new HttpEntity<>(buildHeaders(context));

Expand Down Expand Up @@ -100,11 +100,13 @@ protected Class<ExternalParametersDto> getDtoClass() {

@Override
protected ParameterizedTypeReference<List<ExternalParametersDto>> getDtoListClass() {
return new ParameterizedTypeReference<List<ExternalParametersDto>>() {};
return new ParameterizedTypeReference<List<ExternalParametersDto>>() {
};
}

@Override
protected ParameterizedTypeReference<PaginatedValuesDto<ExternalParametersDto>> getDtoPaginatedClass() {
return new ParameterizedTypeReference<PaginatedValuesDto<ExternalParametersDto>>() {};
return new ParameterizedTypeReference<PaginatedValuesDto<ExternalParametersDto>>() {
};
}
}
36 changes: 11 additions & 25 deletions api/api-ingest/ingest-external/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
<artifactId>iam-security</artifactId>
</dependency>

<!-- APACHE ODFtoolKit-->
<dependency>
<groupId>org.odftoolkit</groupId>
<artifactId>odfdom-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.odftoolkit</groupId>
<artifactId>simple-odf</artifactId>
</dependency>
<!-- APACHE ODFtoolKit-->

<!-- SPRING BOOT -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -94,33 +105,12 @@
<artifactId>spring-boot-devtools</artifactId>
</dependency>

<!-- APACHE ODFtoolKit-->
<dependency>
<groupId>org.odftoolkit</groupId>
<artifactId>odfdom-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.odftoolkit</groupId>
<artifactId>simple-odf</artifactId>
</dependency>
<!-- APACHE ODFtoolKit-->
<!-- Metrics -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

<dependency>
<groupId>fr.gouv.vitamui.commons</groupId>
<artifactId>commons-vitam</artifactId>
</dependency>


<dependency>
<groupId>fr.gouv.vitamui</groupId>
<artifactId>ingest-commons</artifactId>
</dependency>

<!-- UTIL -->
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -205,10 +195,6 @@
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>fr.gouv.vitamui.commons</groupId>
<artifactId>commons-mongo</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ public class ApiIngestExternalApplicationProperties {

private RestClientConfiguration securityClient;

private RestClientConfiguration ingestInternalClient;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import fr.gouv.vitam.ingest.external.client.IngestExternalClient;
import fr.gouv.vitamui.commons.api.application.AbstractContextConfiguration;
import fr.gouv.vitamui.commons.rest.RestExceptionHandler;
import fr.gouv.vitamui.commons.rest.client.configuration.RestClientConfiguration;
import fr.gouv.vitamui.commons.rest.configuration.SwaggerConfiguration;
import fr.gouv.vitamui.commons.vitam.api.access.LogbookService;
import fr.gouv.vitamui.commons.vitam.api.config.VitamAccessConfig;
Expand All @@ -58,14 +57,13 @@
import fr.gouv.vitamui.iam.security.service.InternalAuthentificationService;
import fr.gouv.vitamui.iam.security.service.InternalSecurityService;
import fr.gouv.vitamui.ingest.external.server.security.WebSecurityConfig;
import fr.gouv.vitamui.ingest.external.server.service.AccessContractInternalService;
import fr.gouv.vitamui.ingest.external.server.service.IngestExternalParametersService;
import fr.gouv.vitamui.ingest.external.server.service.IngestGeneratorODTFile;
import fr.gouv.vitamui.ingest.external.server.service.IngestInternalService;
import fr.gouv.vitamui.ingest.external.server.service.internal.AccessContractInternalService;
import fr.gouv.vitamui.ingest.external.server.service.internal.IngestExternalParametersService;
import fr.gouv.vitamui.ingest.external.server.service.internal.IngestGeneratorODTFile;
import fr.gouv.vitamui.ingest.external.server.service.internal.IngestInternalService;
import fr.gouv.vitamui.security.client.ContextRestClient;
import fr.gouv.vitamui.security.client.SecurityRestClientFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -76,9 +74,14 @@
import java.util.Arrays;

@Configuration
@Import({RestExceptionHandler.class, VitamAdministrationConfig.class, VitamAccessConfig.class,
WebSecurityConfig.class, VitamIngestConfig.class,
SwaggerConfiguration.class, HttpMessageConvertersAutoConfiguration.class})
@Import({RestExceptionHandler.class,
SwaggerConfiguration.class,
//MongoConfig.class, not sure to need it
WebSecurityConfig.class,
VitamAccessConfig.class,
VitamIngestConfig.class,
VitamAdministrationConfig.class,
HttpMessageConvertersAutoConfiguration.class})
public class ApiIngestServerConfig extends AbstractContextConfiguration {

@Bean
Expand All @@ -97,6 +100,19 @@ public ContextRestClient contextCrudRestClient(final SecurityRestClientFactory s
return securityRestClientFactory.getContextRestClient();
}

@Bean
public MappingJackson2HttpMessageConverter customizedJacksonMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(
Arrays.asList(
MediaType.APPLICATION_JSON,
new MediaType("application", "*+json"),
MediaType.APPLICATION_OCTET_STREAM
)
);
return converter;
}

@Bean
public ExternalApiAuthenticationProvider apiAuthenticationProvider(
final ExternalAuthentificationService externalAuthentificationService
Expand Down Expand Up @@ -129,72 +145,54 @@ public IamInternalRestClientFactory iamInternalRestClientFactory(
}

@Bean
public InternalSecurityService securityService() {
return new InternalSecurityService();
}

@Bean
public CustomerInternalRestClient customerInternalRestClient(
public UserInternalRestClient userInternalRestClient(
final IamInternalRestClientFactory iamInternalRestClientFactory
) {
return iamInternalRestClientFactory.getCustomerInternalRestClient();
}

@Bean
public IngestGeneratorODTFile ingestGeneratorODTFile() {
return new IngestGeneratorODTFile();
return iamInternalRestClientFactory.getUserInternalRestClient();
}

@Bean
public ExternalParametersInternalRestClient externalParametersInternalRestClient(
final IamInternalRestClientFactory iamInternalRestClientFactory
public InternalApiAuthenticationProvider internalApiAuthenticationProvider(
final InternalAuthentificationService internalAuthentificationService
) {
return iamInternalRestClientFactory.getExternalParametersInternalRestClient();
return new InternalApiAuthenticationProvider(internalAuthentificationService);
}



@Bean
@ConfigurationProperties(prefix = "clients.iam-internal")
public RestClientConfiguration IamInternalRestClientConfiguration() {
return new RestClientConfiguration();
public InternalAuthentificationService internalAuthentificationService(
final UserInternalRestClient userInternalRestClient
) {
return new InternalAuthentificationService(userInternalRestClient);
}

@Bean
public MappingJackson2HttpMessageConverter customizedJacksonMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(
Arrays.asList(
MediaType.APPLICATION_JSON,
new MediaType("application", "*+json"),
MediaType.APPLICATION_OCTET_STREAM
)
);
return converter;
public InternalSecurityService securityService() {
return new InternalSecurityService();
}

@Bean
public InternalApiAuthenticationProvider internalApiAuthenticationProvider(
final InternalAuthentificationService internalAuthentificationService
public CustomerInternalRestClient customerInternalRestClient(
final IamInternalRestClientFactory iamInternalRestClientFactory
) {
return new InternalApiAuthenticationProvider(internalAuthentificationService);
return iamInternalRestClientFactory.getCustomerInternalRestClient();
}

@Bean
public UserInternalRestClient userInternalRestClient(
final IamInternalRestClientFactory iamInternalRestClientFactory
) {
return iamInternalRestClientFactory.getUserInternalRestClient();
public IngestGeneratorODTFile ingestGeneratorODTFile() {
return new IngestGeneratorODTFile();
}

@Bean
public InternalAuthentificationService internalAuthentificationService(
final UserInternalRestClient userInternalRestClient
public ExternalParametersInternalRestClient externalParametersInternalRestClient(
final IamInternalRestClientFactory iamInternalRestClientFactory
) {
return new InternalAuthentificationService(userInternalRestClient);
return iamInternalRestClientFactory.getExternalParametersInternalRestClient();
}

@Bean
public IngestInternalService ingestInternalService(
final ExternalSecurityService externalSecurityService,
final InternalSecurityService internalSecurityService,
final LogbookService logbookService,
final ObjectMapper objectMapper,
Expand All @@ -203,10 +201,10 @@ public IngestInternalService ingestInternalService(
final CustomerInternalRestClient customerInternalRestClient,
final IngestGeneratorODTFile ingestGeneratorODTFile,
final IngestExternalParametersService ingestExternalParametersService,
final AccessContractInternalService accessContractInternalService
final AccessContractInternalService accessContractInternalService,
final ExternalSecurityService externalSecurityService
) {
return new IngestInternalService(
externalSecurityService,
internalSecurityService,
logbookService,
objectMapper,
Expand All @@ -215,6 +213,7 @@ public IngestInternalService ingestInternalService(
customerInternalRestClient,
ingestGeneratorODTFile,
ingestExternalParametersService,
externalSecurityService,
accessContractInternalService
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import fr.gouv.vitamui.commons.utils.VitamUIUtils;
import fr.gouv.vitamui.commons.vitam.api.dto.LogbookOperationDto;
import fr.gouv.vitamui.ingest.common.rest.RestApi;
import fr.gouv.vitamui.ingest.external.server.service.IngestInternalService;
import fr.gouv.vitamui.ingest.external.server.service.internal.IngestInternalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
Expand All @@ -69,7 +69,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Optional;

/**
Expand All @@ -83,7 +82,6 @@ public class IngestExternalController {

private static final Logger LOGGER = LoggerFactory.getLogger(IngestExternalController.class);

//private final IngestExternalService ingestExternalService;
private final IngestInternalService ingestInternalService;

@Autowired
Expand All @@ -99,7 +97,7 @@ public PaginatedValuesDto<LogbookOperationDto> getAllPaginated(
@RequestParam(required = false) final Optional<String> criteria,
@RequestParam(required = false) final Optional<String> orderBy,
@RequestParam(required = false) final Optional<DirectionDto> direction
) throws PreconditionFailedException, InvalidParseOperationException, IOException {
) throws PreconditionFailedException, IOException {
direction.ifPresent(SanityChecker::sanitizeCriteria);
orderBy.ifPresent(SanityChecker::checkSecureParameter);
SanityChecker.sanitizeCriteria(criteria);
Expand All @@ -124,14 +122,13 @@ public LogbookOperationDto getOne(@PathVariable("id") final String id)
ParameterChecker.checkParameter("The Identifier is a mandatory parameter: ", id);
SanityChecker.checkSecureParameter(id);
LOGGER.debug("get One Ingest id={}", id);

return ingestInternalService.getOne(id);
}

@Secured(ServicesData.ROLE_LOGBOOKS)
@GetMapping(RestApi.INGEST_REPORT_ODT + CommonConstants.PATH_ID)
public byte[] generateODTReport(final @PathVariable("id") String id)
throws PreconditionFailedException, InvalidParseOperationException, IOException, URISyntaxException {
throws PreconditionFailedException, InvalidParseOperationException {
ParameterChecker.checkParameter("The Identifier is a mandatory parameter :", id);
SanityChecker.checkSecureParameter(id);
LOGGER.debug("export ODT report for ingest with id :{}", id);
Expand All @@ -146,7 +143,7 @@ public ResponseEntity<Void> streamingUpload(
@RequestHeader(value = CommonConstants.X_ACTION) final String action,
@RequestHeader(value = CommonConstants.X_CONTEXT_ID) final String contextId,
@RequestHeader(value = CommonConstants.X_ORIGINAL_FILENAME_HEADER) final String originalFileName
) throws InvalidParseOperationException, PreconditionFailedException, IngestExternalException {
) throws PreconditionFailedException, IngestExternalException {
ParameterChecker.checkParameter(
"The action and the context ID are mandatory parameters: ",
action,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* The fact that you are presently reading this means that you have had knowledge of the CeCILL 2.1 license and that you
* accept its terms.
*/
package fr.gouv.vitamui.ingest.external.server.service;
package fr.gouv.vitamui.ingest.external.server.service.internal;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* 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.
*/
package fr.gouv.vitamui.ingest.external.server.service;
package fr.gouv.vitamui.ingest.external.server.service.internal;

import fr.gouv.vitamui.commons.vitam.api.dto.LogbookOperationDto;

Expand Down
Loading

0 comments on commit 32203a5

Please sign in to comment.