Commit dd8288e1 authored by harshit aggarwal's avatar harshit aggarwal
Browse files

Increasing logging coverage

parent d0825862
Pipeline #8171 failed with stages
in 23 minutes and 54 seconds
......@@ -2,6 +2,7 @@ package org.opengroup.osdu.wks.service;
import java.util.Arrays;
import lombok.extern.java.Log;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
......@@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
@Log
@Service
public class StorageServiceImpl implements StorageService {
......@@ -55,6 +57,7 @@ public class StorageServiceImpl implements StorageService {
RestResponse response = restClient.processRequest(requestParameters);
log.info(response.getMessage());
return response.getMessage();
}
......@@ -87,11 +90,13 @@ public class StorageServiceImpl implements StorageService {
RestResponse response = restClient.processRequest(requestParameters);
verifyResponseStatus(response);
log.info(response.getMessage());
return response.getMessage();
}
private void verifyResponseStatus(RestResponse response) throws ApplicationException {
if (response.getStatus() != HttpStatus.SC_CREATED) {
log.warning(response.getException());
throw new ApplicationException(response.getException());
}
}
......
......@@ -95,6 +95,7 @@ public class WKSServiceImpl implements WKSService {
throws ApplicationException {
MappingsModel mappings = mappingsMap.get(rawRecord.getKind());
if (isEmptyMappings(mappings)) {
log.warning(String.format(Constants.NO_MAPPING_FOR_KIND, rawRecord.getKind()));
throw new ApplicationException(String.format(Constants.NO_MAPPING_FOR_KIND, rawRecord.getKind()));
}
return mappings;
......@@ -102,6 +103,7 @@ public class WKSServiceImpl implements WKSService {
private void validateTransformRecord(Tree wksRecordTree) throws ApplicationException {
if (wksRecordTree == null || wksRecordTree.isEmpty()) {
log.warning(Constants.COULD_NOT_TRANSFORM);
throw new ApplicationException(Constants.COULD_NOT_TRANSFORM);
}
}
......@@ -118,6 +120,7 @@ public class WKSServiceImpl implements WKSService {
String rawRecordJsonStr = storageService.getRecord(rawRecord.getId(), dataPartitionId, correlationId);
Tree rawRecordTree = convertJsonStringToTree(rawRecordJsonStr);
if (rawRecordTree.isEmpty()) {
log.warning(Constants.RAW_RECORD_NOT_PRESENT + Constants.DASH + rawRecord.getId());
throw new ApplicationException(Constants.RAW_RECORD_NOT_PRESENT);
}
return rawRecordTree;
......@@ -146,12 +149,15 @@ public class WKSServiceImpl implements WKSService {
|| StringUtils.isBlank(rawRecordsDetails[0].getId())
|| StringUtils.isBlank(rawRecordsDetails[0].getKind())
|| StringUtils.isBlank(rawRecordsDetails[0].getOp())) {
log.warning(Constants.MISSING_RAW_RECORD_DETAILS);
throw new BadRequestException(Constants.MISSING_RAW_RECORD_DETAILS);
}
if (StringUtils.isBlank(dataPartitionId)) {
log.warning(Constants.DATA_PARTITION_ID_NEEDED);
throw new BadRequestException(Constants.DATA_PARTITION_ID_NEEDED);
}
if (StringUtils.isBlank(correlationId)) {
log.warning(Constants.CORRELATION_ID_NEEDED);
throw new BadRequestException(Constants.CORRELATION_ID_NEEDED);
}
}
......
......@@ -2,6 +2,7 @@ package org.opengroup.osdu.wks.util;
import java.util.concurrent.TimeUnit;
import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpException;
import org.opengroup.osdu.wks.constants.Constants;
......@@ -17,6 +18,7 @@ import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
@Log
@Component
public class RestClient {
......@@ -53,6 +55,7 @@ public class RestClient {
validate(requestParameters.getUrl());
submitRequest(requestParameters.getUrl(), requestParameters.getMethod(), request, retryCounter);
} catch (Exception e) {
log.warning(e.toString());
restResponse.setException(e.toString());
}
return restResponse;
......@@ -60,6 +63,7 @@ public class RestClient {
private void validate(String url) {
if (StringUtils.isBlank(url)) {
log.warning("URL is null or empty string.");
throw new RestClientException("'URL' is null or empty string.");
}
}
......@@ -107,6 +111,7 @@ public class RestClient {
} catch (HttpServerErrorException e) {
if (retryCounter == 0) {
log.warning("Error while processing request: " + e.getMessage());
throw new HttpException("Error while processing request: " + e.getMessage());
}
......@@ -114,6 +119,7 @@ public class RestClient {
submitRequest(url, method, request, retryCounter - 1);
} catch (RestClientException e) {
log.warning("Error while processing request: " + e.getMessage());
throw new HttpException("Error while processing request: " + e.getMessage());
}
}
......
......@@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.java.Log;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.opengroup.osdu.wks.constants.Constants;
......@@ -22,6 +23,7 @@ import io.datatree.Tree;
* This class do transformation of raw record to wks record
*
*/
@Log
@Component
public class WksTransformator {
......@@ -134,16 +136,19 @@ public class WksTransformator {
private void validateMappings(MappingsModel mappings) throws ApplicationException {
if (mappings == null || ArrayUtils.isEmpty(mappings.getAttributeMappings())) {
log.warning(MAPPING_NOT_PRESENT);
throw new ApplicationException(MAPPING_NOT_PRESENT);
}
if (StringUtils.isBlank(mappings.getWksSchemaKind())) {
log.warning(WKS_SCHEMA_KIND_NOT_PRESENT);
throw new ApplicationException(WKS_SCHEMA_KIND_NOT_PRESENT);
}
}
private void validateRawRecord(Tree rawRecordTree) throws ApplicationException {
if (rawRecordTree.isEmpty()) {
log.warning(RAW_RECORD_NOT_PRESENT);
throw new ApplicationException(RAW_RECORD_NOT_PRESENT);
}
validateForMandatoryAttributes(rawRecordTree);
......@@ -154,6 +159,7 @@ public class WksTransformator {
List<String> missingAttributes = retrieveMissingMandatoryAttributes(rawRecordTree, requiredAttributes);
if (ArrayUtils.isNotEmpty(missingAttributes.toArray())) {
log.warning(REQUIRED_ATTRIBUTES_ARE_MISSING_IN_RECORD + missingAttributes);
throw new ApplicationException(REQUIRED_ATTRIBUTES_ARE_MISSING_IN_RECORD + missingAttributes);
}
}
......
Markdown is supported
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