Skip to content

Commit

Permalink
Merge pull request #640 from SwethaKrish4/mydevelop
Browse files Browse the repository at this point in the history
MOSIP-28187: Sonar duplication fix
  • Loading branch information
mayuradesh committed Jul 12, 2023
2 parents 960a82a + 28f1b2d commit 9b28967
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.mosip.compliance.toolkit.controllers;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import javax.validation.Valid;

import io.mosip.compliance.toolkit.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
Expand Down Expand Up @@ -33,7 +33,6 @@
import io.mosip.compliance.toolkit.service.TestCasesService;
import io.mosip.compliance.toolkit.util.DataValidationUtil;
import io.mosip.compliance.toolkit.util.RequestValidator;
import io.mosip.kernel.core.exception.ServiceError;
import io.mosip.kernel.core.http.RequestWrapper;
import io.mosip.kernel.core.http.ResponseWrapper;

Expand Down Expand Up @@ -113,13 +112,9 @@ private ResponseWrapper<List<TestCaseDto>> handleFailureForGetTestcases(Exceptio
ResponseWrapper<List<TestCaseDto>> responseWrapper = new ResponseWrapper<>();
responseWrapper.setId(getTestCasesId);
responseWrapper.setResponse(null);
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.GET_TEST_CASE_ERROR.getErrorCode());
serviceError.setMessage(
ToolkitErrorCodes.GET_TEST_CASE_ERROR.getErrorMessage() + " " + ex.getLocalizedMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.GET_TEST_CASE_ERROR.getErrorCode();
String errorMessage = ToolkitErrorCodes.GET_TEST_CASE_ERROR.getErrorMessage() + " " + ex.getLocalizedMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
responseWrapper.setVersion(AppConstants.VERSION);
responseWrapper.setResponsetime(LocalDateTime.now());
return responseWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import javax.transaction.Transactional;

import io.mosip.compliance.toolkit.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down Expand Up @@ -183,13 +182,9 @@ public ResponseWrapper<DataShareResponseWrapperDto> createDataShareUrl(DataShare
log.debug("sessionId", "idType", "id", ex.getStackTrace());
log.error("sessionId", "idType", "id",
"In getDataShareUrl method of ABISQueueService Service - " + ex.getMessage());
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.ABIS_DATA_SHARE_URL_EXCEPTION.getErrorCode());
serviceError.setMessage(
ToolkitErrorCodes.ABIS_DATA_SHARE_URL_EXCEPTION.getErrorMessage() + " " + ex.getMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.ABIS_DATA_SHARE_URL_EXCEPTION.getErrorCode();
String errorMessage = ToolkitErrorCodes.ABIS_DATA_SHARE_URL_EXCEPTION.getErrorMessage() + " " + ex.getMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
responseWrapper.setId(getDataShareUrlId);
responseWrapper.setVersion(AppConstants.VERSION);
Expand Down Expand Up @@ -248,13 +243,9 @@ public ResponseWrapper<Boolean> expireDataShareUrl(DataShareExpireRequest reques
log.debug("sessionId", "idType", "id", ex.getStackTrace());
log.error("sessionId", "idType", "id",
"In getDataShareUrl method of ABISQueueService Service - " + ex.getMessage());
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.ABIS_EXPIRE_DATA_SHARE_URL_EXCEPTION.getErrorCode());
serviceError.setMessage(
ToolkitErrorCodes.ABIS_EXPIRE_DATA_SHARE_URL_EXCEPTION.getErrorMessage() + " " + ex.getMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.ABIS_EXPIRE_DATA_SHARE_URL_EXCEPTION.getErrorCode();
String errorMessage = ToolkitErrorCodes.ABIS_EXPIRE_DATA_SHARE_URL_EXCEPTION.getErrorMessage() + " " + ex.getMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
responseWrapper.setId(getDataShareUrlId);
responseWrapper.setVersion(AppConstants.VERSION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.mosip.compliance.toolkit.service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -11,6 +9,7 @@
import io.mosip.compliance.toolkit.entity.BiometricTestDataEntity;
import io.mosip.compliance.toolkit.exceptions.ToolkitException;
import io.mosip.compliance.toolkit.repository.BiometricTestDataRepository;
import io.mosip.compliance.toolkit.util.CommonUtil;
import io.mosip.compliance.toolkit.util.ObjectMapperConfig;
import io.mosip.compliance.toolkit.util.RandomIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -32,7 +31,6 @@
import io.mosip.compliance.toolkit.entity.AbisProjectEntity;
import io.mosip.compliance.toolkit.repository.AbisProjectRepository;
import io.mosip.kernel.core.authmanager.authadapter.model.AuthUserDetails;
import io.mosip.kernel.core.exception.ServiceError;
import io.mosip.kernel.core.http.ResponseWrapper;
import io.mosip.kernel.core.logger.spi.Logger;

Expand Down Expand Up @@ -92,24 +90,17 @@ public ResponseWrapper<AbisProjectDto> getAbisProject(String id) {
abisProjectDto = objectMapper.convertValue(abisProjectEntity, AbisProjectDto.class);

} else {
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorCode());
serviceError.setMessage(ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorCode();
String errorMessage = ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
} catch (Exception ex) {
log.debug("sessionId", "idType", "id", ex.getStackTrace());
log.error("sessionId", "idType", "id",
"In getAbisProject method of AbisProjectService Service - " + ex.getMessage());
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorCode());
serviceError
.setMessage(ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorMessage() + " " + ex.getMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorCode();
String errorMessage = ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorMessage() + " " + ex.getMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
responseWrapper.setId(getAbisProjectId);
responseWrapper.setResponse(abisProjectDto);
Expand Down Expand Up @@ -165,47 +156,34 @@ public ResponseWrapper<AbisProjectDto> addAbisProject(AbisProjectDto abisProject
abisProjectDto.setCrBy(entity.getCrBy());
abisProjectDto.setCrDate(entity.getCrDate());
} else {
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.OBJECT_STORE_FILE_NOT_AVAILABLE.getErrorCode());
serviceError.setMessage(ToolkitErrorCodes.OBJECT_STORE_FILE_NOT_AVAILABLE.getErrorMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.OBJECT_STORE_FILE_NOT_AVAILABLE.getErrorCode();
String errorMessage = ToolkitErrorCodes.OBJECT_STORE_FILE_NOT_AVAILABLE.getErrorMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
}
} catch (ToolkitException ex) {
abisProjectDto = null;
log.debug("sessionId", "idType", "id", ex.getStackTrace());
log.error("sessionId", "idType", "id",
"In addAbisProject method of AbisProjectService Service - " + ex.getMessage());
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ex.getErrorCode());
serviceError.setMessage(ex.getMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ex.getErrorCode();
String errorMessage = ex.getMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
} catch (DataIntegrityViolationException ex) {
log.debug("sessionId", "idType", "id", ex.getStackTrace());
log.error("sessionId", "idType", "id",
"In addSAbisProject method of AbisProjectService Service - " + ex.getMessage());
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.PROJECT_NAME_EXISTS.getErrorCode());
serviceError.setMessage(ToolkitErrorCodes.PROJECT_NAME_EXISTS.getErrorMessage() + " " + abisProjectDto.getName());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.PROJECT_NAME_EXISTS.getErrorCode();
String errorMessage = ToolkitErrorCodes.PROJECT_NAME_EXISTS.getErrorMessage() + " " + abisProjectDto.getName();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
} catch (Exception ex) {
abisProjectDto = null;
log.debug("sessionId", "idType", "id", ex.getStackTrace());
log.error("sessionId", "idType", "id",
"In addAbisProject method of AbisProjectService Service - " + ex.getMessage());
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.ABIS_PROJECT_UNABLE_TO_ADD.getErrorCode());
serviceError
.setMessage(ToolkitErrorCodes.ABIS_PROJECT_UNABLE_TO_ADD.getErrorMessage() + " " + ex.getMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.ABIS_PROJECT_UNABLE_TO_ADD.getErrorCode();
String errorMessage = ToolkitErrorCodes.ABIS_PROJECT_UNABLE_TO_ADD.getErrorMessage() + " " + ex.getMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
responseWrapper.setId(getAbisProjectPostId);
responseWrapper.setResponse(abisProjectDto);
Expand Down Expand Up @@ -258,14 +236,9 @@ public ResponseWrapper<AbisProjectDto> updateAbisProject(AbisProjectDto abisProj
if (objectStore.exists(objectStoreAccountName, container, null, null, fileName)) {
entity.setBioTestDataFileName(bioTestDataName);
} else {
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(
ToolkitErrorCodes.OBJECT_STORE_FILE_NOT_AVAILABLE.getErrorCode());
serviceError.setMessage(
ToolkitErrorCodes.OBJECT_STORE_FILE_NOT_AVAILABLE.getErrorMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.OBJECT_STORE_FILE_NOT_AVAILABLE.getErrorCode();
String errorMessage = ToolkitErrorCodes.OBJECT_STORE_FILE_NOT_AVAILABLE.getErrorMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
}
}
Expand All @@ -275,37 +248,27 @@ public ResponseWrapper<AbisProjectDto> updateAbisProject(AbisProjectDto abisProj
abisProjectDto = objectMapperConfig.objectMapper().convertValue(outputEntity,
AbisProjectDto.class);
} else {
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorCode());
serviceError.setMessage(ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorCode();
String errorMessage = ToolkitErrorCodes.ABIS_PROJECT_NOT_AVAILABLE.getErrorMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
}
} catch (ToolkitException ex) {
abisProjectDto = null;
log.debug("sessionId", "idType", "id", ex.getStackTrace());
log.error("sessionId", "idType", "id",
"In updateAbisProject method of AbisProjectService Service - " + ex.getMessage());
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ex.getErrorCode());
serviceError.setMessage(ex.getMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ex.getErrorCode();
String errorMessage = ex.getMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
} catch (Exception ex) {
abisProjectDto = null;
log.debug("sessionId", "idType", "id", ex.getStackTrace());
log.error("sessionId", "idType", "id",
"In updateAbisProject method of AbisProjectService Service - " + ex.getMessage());
List<ServiceError> serviceErrorsList = new ArrayList<>();
ServiceError serviceError = new ServiceError();
serviceError.setErrorCode(ToolkitErrorCodes.ABIS_PROJECT_UNABLE_TO_ADD.getErrorCode());
serviceError
.setMessage(ToolkitErrorCodes.ABIS_PROJECT_UNABLE_TO_ADD.getErrorMessage() + " " + ex.getMessage());
serviceErrorsList.add(serviceError);
responseWrapper.setErrors(serviceErrorsList);
String errorCode = ToolkitErrorCodes.ABIS_PROJECT_UNABLE_TO_ADD.getErrorCode();
String errorMessage = ToolkitErrorCodes.ABIS_PROJECT_UNABLE_TO_ADD.getErrorMessage() + " " + ex.getMessage();
responseWrapper.setErrors(CommonUtil.getServiceErr(errorCode,errorMessage));
}
responseWrapper.setId(putAbisProjectId);
responseWrapper.setResponse(abisProjectDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public ValidationResultDto validateResponse(ValidationInputDto inputDto) {
validationResultDto = validateDeviceSignature(inputDto);
break;
case CAPTURE:
validationResultDto = validateCaptureSignature(inputDto);
validationResultDto = validateSignature(inputDto);
break;
case RCAPTURE:
validationResultDto = validateRCaptureSignature(inputDto);
validationResultDto = validateSignature(inputDto);
break;
default:
validationResultDto.setStatus(AppConstants.FAILURE);
Expand Down Expand Up @@ -193,46 +193,7 @@ protected ValidationResultDto validateSignedDeviceInfo(ObjectNode objectNode) {
return validationResultDto;
}

protected ValidationResultDto validateCaptureSignature(ValidationInputDto inputDto) {
ValidationResultDto validationResultDto = new ValidationResultDto();
try {
ObjectNode captureInfoResponse = (ObjectNode) objectMapperConfig.objectMapper()
.readValue(inputDto.getMethodResponse(), ObjectNode.class);

final JsonNode arrBiometricNodes = captureInfoResponse.get(BIOMETRICS);
if (arrBiometricNodes.isArray()) {
for (final JsonNode biometricNode : arrBiometricNodes) {
String dataInfo = biometricNode.get(DATA).asText();
validationResultDto = checkIfJWTSignatureIsValid(dataInfo);
if (validationResultDto.getStatus().equals(AppConstants.SUCCESS)) {
validationResultDto = trustRootValidation(getCertificate(dataInfo),
PartnerTypes.DEVICE.toString(), TRUST_FOR_BIOMETRIC_INFO);

if (validationResultDto.getStatus().equals(AppConstants.SUCCESS)) {
String biometricData = getPayload(dataInfo);
ObjectNode biometricDataNode = (ObjectNode) objectMapperConfig.objectMapper()
.readValue(biometricData, ObjectNode.class);

ObjectNode extraInfo = (ObjectNode) objectMapperConfig.objectMapper()
.readValue(inputDto.getExtraInfoJson(), ObjectNode.class);
String certificationType = extraInfo.get(CERTIFICATION_TYPE).asText();
validationResultDto = validateSignedDigitalId(biometricDataNode.get(DIGITAL_ID).asText(),
certificationType, TRUST_FOR_DIGITAL_ID);
}
}
if (validationResultDto.getStatus().equals(AppConstants.FAILURE))
break;
}
}
} catch (Exception e) {
validationResultDto.setStatus(AppConstants.FAILURE);
validationResultDto
.setDescription("SignatureValidator failure - " + "with Message - " + e.getLocalizedMessage());
}
return validationResultDto;
}

protected ValidationResultDto validateRCaptureSignature(ValidationInputDto inputDto) {
protected ValidationResultDto validateSignature(ValidationInputDto inputDto) {
ValidationResultDto validationResultDto = new ValidationResultDto();
try {
ObjectNode captureInfoResponse = (ObjectNode) objectMapperConfig.objectMapper()
Expand Down

0 comments on commit 9b28967

Please sign in to comment.