Unverified Commit cb8aec76 authored by EL HAJJIOUI Nabil's avatar EL HAJJIOUI Nabil Committed by GitHub
Browse files

[VAS] Item 8673 order filling holding scheme trees (#532)

parent 022b4593
......@@ -29,10 +29,6 @@ package fr.gouv.vitamui.archive.internal.server.rest;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitam.common.database.builder.query.Query;
import fr.gouv.vitam.common.database.builder.request.exception.InvalidCreateOperationException;
import fr.gouv.vitam.common.database.builder.request.multiple.SelectMultiQuery;
import fr.gouv.vitam.common.exception.InvalidParseOperationException;
import fr.gouv.vitam.common.exception.VitamClientException;
import fr.gouv.vitamui.archive.internal.server.service.ArchiveSearchInternalService;
import fr.gouv.vitamui.archives.search.common.dto.ArchiveUnitsDto;
......@@ -42,12 +38,10 @@ import fr.gouv.vitamui.archives.search.common.rest.RestApi;
import fr.gouv.vitamui.common.security.SanityChecker;
import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.ParameterChecker;
import fr.gouv.vitamui.commons.api.exception.UnexpectedDataException;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.vitam.api.dto.ResultsDto;
import fr.gouv.vitamui.commons.vitam.api.dto.VitamUISearchResponseDto;
import fr.gouv.vitamui.commons.vitam.api.model.UnitTypeEnum;
import fr.gouv.vitamui.iam.security.service.InternalSecurityService;
import io.swagger.annotations.Api;
import lombok.Getter;
......@@ -70,9 +64,6 @@ import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.in;
import static fr.gouv.vitam.common.database.builder.query.VitamFieldsHelper.unitType;
@RestController
@RequestMapping(RestApi.ARCHIVE_SEARCH_PATH)
@Getter
......@@ -83,9 +74,6 @@ public class ArchiveSearchInternalController {
private static final VitamUILogger LOGGER =
VitamUILoggerFactory.getInstance(ArchiveSearchInternalController.class);
private static final String[] FILING_PLAN_PROJECTION =
new String[] {"#id", "Title", "Title_", "DescriptionLevel", "#unitType", "#unitups", "#allunitups"};
private final ArchiveSearchInternalService archiveInternalService;
......@@ -126,27 +114,10 @@ public class ArchiveSearchInternalController {
ParameterChecker.checkParameter("The tenant Id, the accessContract Id are mandatory parameters: ", tenantId,
accessContractId);
final VitamContext vitamContext = securityService.buildVitamContext(tenantId, accessContractId);
final JsonNode holdingQuery = createQueryForHoldingUnit();
return objectMapper.treeToValue(archiveInternalService.searchArchiveUnits(holdingQuery, vitamContext),
return objectMapper.treeToValue(archiveInternalService.getFillingHoldingScheme(vitamContext),
VitamUISearchResponseDto.class);
}
private JsonNode createQueryForHoldingUnit() {
try {
final SelectMultiQuery select = new SelectMultiQuery();
final Query query =
in(unitType(), UnitTypeEnum.HOLDING_UNIT.getValue(), UnitTypeEnum.FILING_UNIT.getValue());
select.addQueries(query);
select.addUsedProjection(FILING_PLAN_PROJECTION);
LOGGER.debug("query =", select.getFinalSelect().toPrettyString());
return select.getFinalSelect();
} catch (InvalidCreateOperationException | InvalidParseOperationException e) {
throw new UnexpectedDataException(
"Unexpected error occured while building holding dsl query : " + e.getMessage());
}
}
@GetMapping(RestApi.ARCHIVE_UNIT_INFO + CommonConstants.PATH_ID)
public ResultsDto findUnitById(final @PathVariable("id") String id,
@RequestHeader(value = CommonConstants.X_ACCESS_CONTRACT_ID_HEADER) final String accessContractId)
......
......@@ -37,6 +37,7 @@ import fr.gouv.vitam.common.LocalDateUtil;
import fr.gouv.vitam.common.client.VitamContext;
import fr.gouv.vitam.common.database.builder.facet.FacetHelper;
import fr.gouv.vitam.common.database.builder.query.BooleanQuery;
import fr.gouv.vitam.common.database.builder.query.Query;
import fr.gouv.vitam.common.database.builder.request.configuration.BuilderToken;
import fr.gouv.vitam.common.database.builder.request.exception.InvalidCreateOperationException;
import fr.gouv.vitam.common.database.builder.request.multiple.SelectMultiQuery;
......@@ -46,9 +47,9 @@ 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.dip.DataObjectVersions;
import fr.gouv.vitam.common.model.elimination.EliminationRequestBody;
import fr.gouv.vitam.common.model.export.dip.DipExportType;
import fr.gouv.vitam.common.model.export.dip.DipRequest;
import fr.gouv.vitam.common.model.elimination.EliminationRequestBody;
import fr.gouv.vitamui.archives.search.common.common.ArchiveSearchConsts;
import fr.gouv.vitamui.archives.search.common.dto.ArchiveUnit;
import fr.gouv.vitamui.archives.search.common.dto.ArchiveUnitCsv;
......@@ -65,6 +66,7 @@ import fr.gouv.vitamui.commons.api.exception.BadRequestException;
import fr.gouv.vitamui.commons.api.exception.InternalServerException;
import fr.gouv.vitamui.commons.api.exception.PreconditionFailedException;
import fr.gouv.vitamui.commons.api.exception.RequestEntityTooLargeException;
import fr.gouv.vitamui.commons.api.exception.UnexpectedDataException;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.vitam.api.access.EliminationService;
......@@ -72,6 +74,7 @@ import fr.gouv.vitamui.commons.vitam.api.access.ExportDipV2Service;
import fr.gouv.vitamui.commons.vitam.api.access.UnitService;
import fr.gouv.vitamui.commons.vitam.api.dto.ResultsDto;
import fr.gouv.vitamui.commons.vitam.api.dto.VitamUISearchResponseDto;
import fr.gouv.vitamui.commons.vitam.api.model.UnitTypeEnum;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -100,6 +103,8 @@ import java.util.Set;
import java.util.stream.Collectors;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.and;
import static fr.gouv.vitam.common.database.builder.query.QueryHelper.in;
import static fr.gouv.vitam.common.database.builder.query.VitamFieldsHelper.unitType;
/**
* Archive-Search Internal service communication with VITAM.
......@@ -121,8 +126,9 @@ public class ArchiveSearchInternalService {
public static final String NEW_TAB = "\t";
public static final String NEW_LINE_1 = "\r\n";
public static final String OPERATION_IDENTIFIER = "itemId";
public static final String SPACE = " ";
private static final String[] FILING_PLAN_PROJECTION =
new String[] {"#id", "Title", "Title_", "DescriptionLevel", "#unitType", "#unitups", "#allunitups"};
private final ObjectMapper objectMapper;
private final UnitService unitService;
......@@ -247,6 +253,11 @@ public class ArchiveSearchInternalService {
return response.toJsonNode();
}
public JsonNode getFillingHoldingScheme(VitamContext vitamContext) throws VitamClientException {
final JsonNode fillingHoldingQuery = createQueryForHoldingFillingUnit();
return searchArchiveUnits(fillingHoldingQuery, vitamContext);
}
public ResultsDto findArchiveUnitById(String id, VitamContext vitamContext) throws VitamClientException {
try {
LOGGER.info("Archive Unit Id : {}", id);
......@@ -630,6 +641,26 @@ public class ArchiveSearchInternalService {
return dipRequest;
}
public JsonNode createQueryForHoldingFillingUnit() {
try {
final SelectMultiQuery select = new SelectMultiQuery();
final Query query =
in(unitType(), UnitTypeEnum.HOLDING_UNIT.getValue(), UnitTypeEnum.FILING_UNIT.getValue());
select.addQueries(query);
ObjectNode orderFilter = JsonHandler.createObjectNode();
orderFilter.put("Title", 1);
ObjectNode filter = JsonHandler.createObjectNode();
filter.set("$orderby", orderFilter);
select.setFilter(filter);
select.addUsedProjection(FILING_PLAN_PROJECTION);
LOGGER.debug("query =", select.getFinalSelect().toPrettyString());
return select.getFinalSelect();
} catch (InvalidCreateOperationException | InvalidParseOperationException e) {
throw new UnexpectedDataException(
"Unexpected error occured while building holding dsl query : " + e.getMessage());
}
}
public JsonNode exportDIP( final VitamContext vitamContext, DipRequest dipRequest)
throws VitamClientException {
RequestResponse<JsonNode> response = exportDipV2Service.exportDip( vitamContext, dipRequest);
......
......@@ -110,6 +110,7 @@ public class ArchiveSearchInternalServiceTest {
public final String ELIMINATION_ANALYSIS_QUERY = "data/elimination/query.json";
public final String ELIMINATION_ANALYSIS_FINAL_QUERY = "data/elimination/expected_query.json";
public final String ELIMINATION_ANALYSIS_FINAL_RESPONSE = "data/elimination/elimination_analysis_response.json";
public final String FILLING_HOLDING_SCHEME_EXPECTED_QUERY = "data/fillingholding/expected_query.json";
@BeforeEach
public void setUp() {
......@@ -161,4 +162,19 @@ public class ArchiveSearchInternalServiceTest {
Assertions.assertThat(eliminationRequestBody2.getDslRequest()).isEqualTo(resultExpected);
Assertions.assertThat(resultExpected.get(BuilderToken.GLOBAL.THRESOLD.exactToken()).asDouble()).isEqualTo(10000);
}
@Test
public void getFinalFillingHoldingSchemeQuery() throws Exception {
// Given
JsonNode expectedQuery = JsonHandler.getFromFile(PropertiesUtils.findFile(FILLING_HOLDING_SCHEME_EXPECTED_QUERY));
// When
JsonNode givenQuery =
archiveSearchInternalService.createQueryForHoldingFillingUnit();
// Then
Assertions.assertThat(expectedQuery.toString()).isEqualTo(String.valueOf(givenQuery));
Assertions.assertThat(givenQuery.get(BuilderToken.GLOBAL.FILTER.exactToken()).get(BuilderToken.SELECTFILTER.ORDERBY.exactToken()).has("Title")).isTrue();
}
}
{
"$roots": [],
"$query": [
{
"$in": {
"#unitType": [
"HOLDING_UNIT",
"FILING_UNIT"
]
}
}
],
"$filter": {
"$limit": 10000,
"$orderby": {
"Title": 1
}
},
"$projection": {
"$fields": {
"#id": 1,
"Title": 1,
"Title_": 1,
"DescriptionLevel": 1,
"#unitType": 1,
"#unitups": 1,
"#allunitups": 1
}
},
"$facets": []
}
Supports Markdown
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