Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
*/
package fr.gouv.vitamui.collect.common.dto;

import fr.gouv.vitam.collect.common.dto.BatchDto;
import fr.gouv.vitamui.commons.api.domain.IdDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
Expand All @@ -58,4 +61,5 @@ public class CollectTransactionDto extends IdDto {
private String lastUpdate;
private String status;
private String projectId;
private List<BatchDto> batches;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package fr.gouv.vitamui.collect.server.rest;

import fr.gouv.vitam.collect.common.enums.TransactionValidationMode;
import fr.gouv.vitam.common.exception.VitamClientException;
import fr.gouv.vitamui.archives.search.common.dto.ReclassificationCriteriaDto;
import fr.gouv.vitamui.collect.common.dto.CollectTransactionDto;
Expand Down Expand Up @@ -55,6 +56,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -119,12 +121,18 @@ public void abortTransaction(final @PathVariable("id") String id)

@Secured(ServicesData.ROLE_CLOSE_TRANSACTIONS)
@PutMapping(CommonConstants.PATH_ID + VALIDATE_PATH)
public void validateTransaction(final @PathVariable("id") String id)
throws PreconditionFailedException, VitamClientException {
public void validateTransaction(
final @PathVariable("id") String id,
@RequestParam("validationMode") final TransactionValidationMode validationMode
) throws PreconditionFailedException, VitamClientException {
ParameterChecker.checkParameter(MANDATORY_IDENTIFIER, id);
SanityChecker.checkSecureParameter(id);
LOGGER.debug(TRANSACTION_ID, id);
transactionService.validateTransaction(id, externalParametersService.buildVitamContextFromExternalParam());
transactionService.validateTransaction(
id,
externalParametersService.buildVitamContextFromExternalParam(),
validationMode
);
}

@Operation(summary = "Get transaction by id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import fr.gouv.vitam.collect.common.dto.TransactionDto;
import fr.gouv.vitam.collect.common.enums.TransactionValidationMode;
import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitam.common.exception.InvalidParseOperationException;
import fr.gouv.vitam.common.exception.VitamClientException;
Expand Down Expand Up @@ -90,9 +91,17 @@ public class TransactionService {

private static final ObjectMapper mapper = new ObjectMapper();

public void validateTransaction(String idTransaction, VitamContext vitamContext) throws VitamClientException {
public void validateTransaction(
String idTransaction,
VitamContext vitamContext,
TransactionValidationMode validationMode
) throws VitamClientException {
try {
RequestResponse requestResponse = collectService.validateTransaction(vitamContext, idTransaction);
RequestResponse requestResponse = collectService.validateTransaction(
vitamContext,
idTransaction,
validationMode
);
if (requestResponse.getStatus() != Response.Status.OK.getStatusCode()) {
throw new VitamClientException("Error occurs when validating transaction!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static CollectTransactionDto toVitamUiDto(TransactionDto transactionDto)
collectTransactionDto.setLastUpdate(transactionDto.getLastUpdate());
collectTransactionDto.setProjectId(transactionDto.getProjectId());
collectTransactionDto.setName(transactionDto.getName());
collectTransactionDto.setBatches(transactionDto.getBatches());
return collectTransactionDto;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.gouv.vitam.collect.common.dto.TransactionDto;
import fr.gouv.vitam.collect.common.enums.TransactionValidationMode;
import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitam.common.error.VitamError;
import fr.gouv.vitam.common.error.VitamErrorDetails;
Expand Down Expand Up @@ -85,21 +86,27 @@ class TransactionServiceTest {
@Test
void shouldValidateTransactionWithSuccess() throws VitamClientException {
// GIVEN
when(collectService.validateTransaction(vitamContext, TRANSACTION_ID)).thenReturn(
new RequestResponseOK().setHttpCode(200)
);
when(
collectService.validateTransaction(vitamContext, TRANSACTION_ID, TransactionValidationMode.VALIDATE)
).thenReturn(new RequestResponseOK().setHttpCode(200));
// THEN
assertDoesNotThrow(() -> transactionService.validateTransaction(TRANSACTION_ID, vitamContext));
assertDoesNotThrow(
() ->
transactionService.validateTransaction(TRANSACTION_ID, vitamContext, TransactionValidationMode.VALIDATE)
);
}

@Test
void shouldThrowExceptionWhenValidateTransaction() throws VitamClientException {
// GIVEN
when(collectService.validateTransaction(vitamContext, TRANSACTION_ID)).thenThrow(VitamClientException.class);
when(
collectService.validateTransaction(vitamContext, TRANSACTION_ID, TransactionValidationMode.VALIDATE)
).thenThrow(VitamClientException.class);
// THEN
assertThrows(
VitamClientException.class,
() -> transactionService.validateTransaction(TRANSACTION_ID, vitamContext)
() ->
transactionService.validateTransaction(TRANSACTION_ID, vitamContext, TransactionValidationMode.VALIDATE)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import fr.gouv.vitam.collect.common.dto.ProjectDto;
import fr.gouv.vitam.collect.common.dto.TransactionDto;
import fr.gouv.vitam.collect.common.dto.UploadSipResult;
import fr.gouv.vitam.collect.common.enums.TransactionValidationMode;
import fr.gouv.vitam.collect.external.client.CollectExternalClient;
import fr.gouv.vitam.collect.external.exception.CollectExternalClientException;
import fr.gouv.vitam.common.CharsetUtils;
Expand Down Expand Up @@ -345,10 +346,17 @@ public RequestResponse<JsonNode> deleteProjectById(final VitamContext vitamConte
return result;
}

public RequestResponse validateTransaction(final VitamContext vitamContext, final String idTransaction)
throws VitamClientException {
public RequestResponse validateTransaction(
final VitamContext vitamContext,
final String idTransaction,
final TransactionValidationMode validationMode
) throws VitamClientException {
LOGGER.debug(TRANSACTION_ID, idTransaction);
final RequestResponse response = collectExternalClient.closeTransaction(vitamContext, idTransaction);
final RequestResponse response = collectExternalClient.closeTransaction(
vitamContext,
idTransaction,
validationMode
);
VitamRestUtils.checkResponse(response);
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import { AfterViewInit, Component, OnDestroy, OnInit, TemplateRef, ViewChild } f
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, finalize, merge, Observable, Subject, Subscription, zip } from 'rxjs';
import { debounceTime, filter, map, mergeMap, share, take, tap } from 'rxjs/operators';
import { BehaviorSubject, finalize, merge, Observable, of, Subject, Subscription, zip } from 'rxjs';
import { debounceTime, filter, map, mergeMap, share, switchMap, take, tap } from 'rxjs/operators';
import { isEmpty } from 'underscore';
import {
AccessContract,
Expand Down Expand Up @@ -93,6 +93,7 @@ import {
NODES,
toManagementRuleType,
MANAGEMENT_RULE_SHARED_DATA_SERVICE,
ConfirmDialogComponent,
} from 'vitamui-library';
import { ArchiveCollectService } from './archive-collect.service';
import { SearchCriteriaSaverComponent } from './archive-search-criteria/components/search-criteria-saver/search-criteria-saver.component';
Expand All @@ -103,6 +104,7 @@ import { UpdateUnitsMetadataComponent } from './update-units-metadata/update-uni
import { AddUnitsComponent } from './add-units/add-units.component';
import { TransactionsService } from '../transactions/transactions.service';
import { MatCheckboxChange } from '@angular/material/checkbox';
import { TransactionValidationMode } from '../models/transaction-validation-mode.enum';

const PAGE_SIZE = 10;
const ELIMINATION_TECHNICAL_ID = 'ELIMINATION_TECHNICAL_ID';
Expand Down Expand Up @@ -1284,14 +1286,34 @@ export class ArchiveSearchCollectComponent extends SidenavPage<any> implements O
}

validateTransaction() {
this.transactionService
.validate(this.transaction, { isAutomaticIngest: this.isAutomaticIngest })
const hasBatchError = this.hasBatchInError(this.transaction);
const validationMode = hasBatchError ? TransactionValidationMode.VALIDATE_IGNORE : TransactionValidationMode.VALIDATE;
const confirmation$ = hasBatchError
? this.dialog
.open(ConfirmDialogComponent, {
disableClose: false,
data: {
title: 'COLLECT.OTHER_ACTIONS.DIALOG_MESSAGE.CONFIRM_FORCE_TRANSACTION_VALIDATION_MESSAGE',
subTitle: 'COLLECT.OTHER_ACTIONS.DIALOG_MESSAGE.CONFIRM_TRANSACTION_VALIDATION',
confirmLabel: 'COLLECT.OTHER_ACTIONS.DIALOG_MESSAGE.CONFIRM_TRANSACTION_VALIDATION',
cancelLabel: 'COLLECT.OTHER_ACTIONS.DIALOG_MESSAGE.CANCEL',
Comment on lines +1296 to +1299
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utiliser des constantes ?

},
})
.afterClosed()
.pipe(filter((confirmed) => !!confirmed))
: of(true);

confirmation$
.pipe(
finalize(() => {
this.snackBarService.open({
message: 'COLLECT.VALIDATE_TRANSACTION_VALIDATED',
duration: 10_000,
});
switchMap(() => {
return this.transactionService.validate(this.transaction, validationMode, { isAutomaticIngest: this.isAutomaticIngest }).pipe(
finalize(() => {
this.snackBarService.open({
message: 'COLLECT.VALIDATE_TRANSACTION_VALIDATED',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En constante ?

duration: 10_000,
});
}),
);
}),
)
.subscribe((transaction: Transaction) => {
Expand Down Expand Up @@ -1434,5 +1456,9 @@ export class ArchiveSearchCollectComponent extends SidenavPage<any> implements O
});
}

private hasBatchInError(transaction: Transaction): boolean {
return transaction.batches?.some((b) => b.BatchStatus === 'KO') ?? false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utiliser un enum BatchStatus pour la comparaison ?

}

protected readonly TransactionStatus = TransactionStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* knowledge of the CeCILL-C license and that you accept its terms.
*/

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import {
Expand All @@ -49,6 +49,7 @@ import {
Unit,
VitamError,
} from 'vitamui-library';
import { TransactionValidationMode } from '../../models/transaction-validation-mode.enum';

@Injectable({
providedIn: 'root',
Expand All @@ -71,8 +72,9 @@ export class TransactionApiService extends PaginatedHttpClient<Transaction> {
return this.http.get<Transaction>(this.apiUrl + '/' + transactionId);
}

validateTransaction(id: string) {
return this.http.put<Transaction>(this.apiUrl + '/' + id + '/validate', {});
validateTransaction(id: string, validationMode: TransactionValidationMode) {
const params = new HttpParams().set('validationMode', validationMode);
return this.http.put<Transaction>(this.apiUrl + '/' + id + '/validate', {}, { params });
}

sendTransaction(id: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2022)
* and the signatories of the "VITAM - Accord du Contributeur" agreement.
*
* contact@programmevitam.fr
*
* 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.
*
* 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".
*
* 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.
*
* 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,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* 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.
*
* 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.
*/
export enum TransactionValidationMode {
VALIDATE = 'VALIDATE',
VALIDATE_IGNORE = 'VALIDATE_IGNORE',
VALIDATE_FORCE = 'VALIDATE_FORCE',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VALIDATE_FORCE n'est pas utilisé actuellement. Tu prévois de l'utiliser ?

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
justify-content: flex-end; /* ✅ pousse les boutons à droite */
}

.batch-ko-error {
color: var(--vitamui-red);
}


Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ <h5>{{ 'COLLECT.INGEST_LIST_TITLE' | translate }}</h5>
</td>
<td>{{ transaction.messageIdentifier }}</td>
<td>{{ transaction.id }}</td>
<td>{{ 'COLLECT.PROJECT_TRANSACTION_PREVIEW.STATUS.' + transaction.status | translate }}</td>
<td>
<div>{{ 'COLLECT.PROJECT_TRANSACTION_PREVIEW.STATUS.' + transaction.status | translate }}</div>
@if (shouldShowBatchError(transaction)) {
<div class="batch-ko-error">{{ 'COLLECT.BATCH_ERROR_RECORDED' | translate }}</div>
}
</td>
<td>
<div class="hgap-2 justify-content-end">
@if (transactionIsDownloadable(transaction)) {
Expand Down
Loading
Loading