Skip to content
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package fr.insee.genesis.controller.rest.exception;

import com.mongodb.DuplicateKeyException;
import fr.insee.genesis.exceptions.GenesisException;
import fr.insee.genesis.exceptions.InvalidDateIntervalException;
import fr.insee.genesis.exceptions.NoDataException;
import fr.insee.genesis.exceptions.QuestionnaireNotFoundException;
import fr.insee.genesis.exceptions.ReviewDisabledException;
import fr.insee.genesis.exceptions.SpecificationNotFoundException;
import fr.insee.genesis.exceptions.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ProblemDetail;
Expand All @@ -29,20 +24,10 @@ public ProblemDetail handleGenesis(GenesisException genesisException) {
genesisException);

return ProblemDetail.forStatusAndDetail(
resolveHttpCode(genesisException.getStatus().value()),
genesisException.getStatus(),
genesisException.getMessage());
}

/** Returns the corresponding http status, or 500 if the given code does not match an http status. */
private static HttpStatus resolveHttpCode(int statusCode) {
HttpStatus httpStatus = HttpStatus.resolve(statusCode);
if (httpStatus == null) {
log.warn("Unknown http status code '{}', 500 will be sent.", statusCode);
return HttpStatus.INTERNAL_SERVER_ERROR;
}
return httpStatus;
}

@ExceptionHandler(QuestionnaireNotFoundException.class)
public ProblemDetail handleQuestionnaireNotFound(QuestionnaireNotFoundException questionnaireNotFoundException) {
log.error("Questionnaire not found (Type: {}) : {}",
Expand Down Expand Up @@ -123,4 +108,28 @@ public ProblemDetail handleValidationExceptions(MethodArgumentNotValidException
return problemDetail;
}

@ExceptionHandler(ModesConflictException.class)
public ProblemDetail handleModesConflictException(ModesConflictException e) {
log.error("ModesConflictException: {}", e.getMessage());
return ProblemDetail.forStatusAndDetail(
HttpStatus.CONFLICT,
e.getMessage());
}

@ExceptionHandler(UndefinedMetadataException.class)
public ProblemDetail handleUndefinedMetadataException(UndefinedMetadataException e) {
log.error("UndefinedMetadataException: {}", e.getMessage());
return ProblemDetail.forStatusAndDetail(
HttpStatus.NOT_FOUND,
e.getMessage());
}

@ExceptionHandler(InvalidMetadataException.class)
public ProblemDetail handleInvalidMetadataException(InvalidMetadataException e) {
log.error("InvalidMetadataException: {}", e.getMessage());
return ProblemDetail.forStatusAndDetail(
HttpStatus.BAD_REQUEST,
e.getMessage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.web.bind.annotation.RequestParam;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package fr.insee.genesis.controller.utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import fr.insee.genesis.domain.model.surveyunit.Mode;
import fr.insee.genesis.exceptions.ModesConflictException;
import fr.insee.genesis.exceptions.SpecificationNotFoundException;
import fr.insee.genesis.infrastructure.utils.FileUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import fr.insee.genesis.domain.model.surveyunit.Mode;
import fr.insee.genesis.exceptions.GenesisException;
import fr.insee.genesis.infrastructure.utils.FileUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

// Note: this class should be moved in the domain service layer.

@Component
@Slf4j
Expand All @@ -25,26 +25,24 @@ public ControllerUtils(FileUtils fileUtils) {
this.fileUtils = fileUtils;
}


/**
* If a mode is specified, we treat only this mode.
* If no mode is specified, we treat all modes in the questionnaireId.
* If no mode is specified and no specs are found, we return an error
* @param questionnaireId questionnaireId id to get modes
* @param modeSpecified a Mode to use, null if we want all modes available
* @return a list with the mode in modeSpecified or all modes if null
* @throws GenesisException if error in specs structure
*/
public List<Mode> getModesList(String questionnaireId, Mode modeSpecified) throws GenesisException {
public List<Mode> getModesList(String questionnaireId, Mode modeSpecified) {
if (modeSpecified != null){
return Collections.singletonList(modeSpecified);
}
List<Mode> modes = new ArrayList<>();
String specFolder = fileUtils.getSpecFolder(questionnaireId);
List<String> modeSpecFolders = fileUtils.listFolders(specFolder);
if (modeSpecFolders.isEmpty()) {
throw new SpecificationNotFoundException(questionnaireId);
}
throw new SpecificationNotFoundException(questionnaireId);
}
for(String modeSpecFolder : modeSpecFolders){
if(Mode.getEnumFromModeName(modeSpecFolder) == null) {
log.warn("There is an invalid mode folder name in spec folder : {}", modeSpecFolder);
Expand All @@ -53,9 +51,18 @@ public List<Mode> getModesList(String questionnaireId, Mode modeSpecified) throw
modes.add(Mode.getEnumFromModeName(modeSpecFolder));
}
if (modes.contains(Mode.F2F) && modes.contains(Mode.TEL)) {
throw new GenesisException(HttpStatus.CONFLICT, "Cannot treat simultaneously TEL and FAF modes");
throw new ModesConflictException("Cannot process simultaneously TEL and FAF modes");
}
return modes;
}

/**
* Returns the applicable modes for the collection instrument with the given identifier.
* @param collectionInstrumentId Collection instrument identifier.
* @return A list of modes.
*/
public List<Mode> getModesList(String collectionInstrumentId) {
return getModesList(collectionInstrumentId, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,28 @@
@NoArgsConstructor
@AllArgsConstructor
public class DataProcessingContextModel {

/** (Added to the class only to remove a warning) */
@Id
private ObjectId id; // Used to remove warning
private ObjectId id;

/**
* @deprecated The 'partition' concept has shifted, this property isn't used anymore. */
@Deprecated(forRemoval = true)
private String partitionId;

Check warning on line 31 in src/main/java/fr/insee/genesis/domain/model/context/DataProcessingContextModel.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=InseeFr_genesis-api&issues=AZ38lRSLu3WewRVoH9Y0&open=AZ38lRSLu3WewRVoH9Y0&pullRequest=471

private String collectionInstrumentId; //QuestionnaireId
/** New name of legacy 'questionnaireId' property. */
private String collectionInstrumentId;

private LocalDateTime lastExecution;

private List<KraftwerkExecutionSchedule> kraftwerkExecutionScheduleList;

private List<KraftwerkExecutionScheduleV2> kraftwerkExecutionScheduleV2List;

/** Determines if some review service must be called during the process. */
private boolean withReview;

private List<KraftwerkExecutionScheduleV2> kraftwerkExecutionScheduleV2List;

public List<ScheduleResponseDto> toScheduleV1ResponseDtos() {
if (kraftwerkExecutionScheduleList == null || kraftwerkExecutionScheduleList.isEmpty()) {
return List.of();
Expand Down Expand Up @@ -98,4 +107,5 @@
)
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.insee.genesis.domain.ports.api;

import fr.insee.bpm.metadata.model.VariablesMap;
import fr.insee.genesis.domain.model.surveyunit.Mode;
import fr.insee.genesis.domain.model.surveyunit.SurveyUnitModel;
import fr.insee.genesis.domain.model.surveyunit.rawdata.DataProcessResult;
import fr.insee.genesis.domain.model.surveyunit.rawdata.RawResponseModel;
Expand All @@ -16,8 +15,6 @@

public interface RawResponseApiPort {

List<RawResponseModel> getRawResponses(String collectionInstrumentId, Mode mode, List<String> interrogationIdList);
List<RawResponseModel> getRawResponsesByInterrogationID(String interrogationId);
DataProcessResult processRawResponsesByInterrogationIds(String collectionInstrumentId, List<String> interrogationIdList, List<GenesisError> errors) throws GenesisException;
DataProcessResult processRawResponsesByInterrogationIds(String collectionInstrumentId) throws GenesisException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public interface RawResponsePersistencePort {
List<ModeDto> findModesByCollectionInstrument(String collectionInstrumentId);
Page<RawResponseModel> findByCampaignIdAndDate(String campaignId, Instant startDate, Instant endDate, Pageable pageable);
long countByCollectionInstrumentId(String collectionInstrumentId);
Set<String> findDistinctCollectionInstrumentIds();
long countDistinctInterrogationIdsByCollectionInstrumentId(String collectionInstrumentId);
Set<String> findDistinctCollectionInstrumentIds();
Page<RawResponseModel> findByCollectionInstrumentId(String collectionInstrumentId, Pageable pageable);
boolean existsByInterrogationId(String interrogationId);

Expand Down
Loading
Loading