Skip to content

Commit

Permalink
Smell fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Grasso2000 committed Aug 25, 2023
1 parent 663c771 commit 252b92a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/main/java/it/gov/pagopa/taxonomy/TaxonomyGetFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public HttpResponseMessage getTaxonomy(
map);

} catch (AppException e) {
logger.log(Level.SEVERE, MessageFormat.format("[ALERT][Get] AppException at {0}\n {1}", Instant.now(),ExceptionUtils.getMessage(e)));
logger.log(Level.SEVERE, MessageFormat.format("[ALERT][Get] AppException at {0}\n {1}", Instant.now(), ExceptionUtils.getMessage(e)));

String payload = AppUtil.getPayload(getObjectMapper(), ErrorMessage.builder()
.message(AppMessageUtil.getMessage(GENERIC_RETRIEVAL_ERROR))
Expand All @@ -121,21 +121,22 @@ public HttpResponseMessage getTaxonomy(
payload);
} catch (BlobStorageException e) {
if(e.getErrorCode().equals(BlobErrorCode.BLOB_NOT_FOUND)) {
logger.log(Level.SEVERE, "[ALERT][Get] BlobStorageException at " + Instant.now() + "\n" + ExceptionUtils.getStackTrace(e), e);
logger.log(Level.SEVERE, MessageFormat.format("[ALERT][Get] BlobStorageException at {0}\n {1}",Instant.now(), ExceptionUtils.getStackTrace(e)));

AppException appException = new AppException(e, AppErrorCodeMessageEnum.BLOB_NOT_FOUND_JSON_ERROR);
String payload = AppUtil.getPayload(getObjectMapper(), ErrorMessage.builder()
.message("Taxonomy retrieval failed")
.message(GENERIC_RETRIEVAL_ERROR)
.error(appException.getCodeMessage().message(appException.getArgs()))
.build());
return AppUtil.writeResponse(request,
HttpStatus.valueOf(appException.getCodeMessage().httpStatus().name()),
payload
);
} else {
logger.log(Level.SEVERE, "[ALERT][Get] BlobStorageException at " + Instant.now() + "\n" + ExceptionUtils.getStackTrace(e), e);
logger.log(Level.SEVERE, MessageFormat.format("[ALERT][Get] BlobStorageException at {0}\n {1}", Instant.now(), ExceptionUtils.getStackTrace(e)));
AppException appException = new AppException(e, AppErrorCodeMessageEnum.ERROR);
String payload = AppUtil.getPayload(getObjectMapper(), ErrorMessage.builder()
.message("Taxonomy retrieval failed")
.message(GENERIC_RETRIEVAL_ERROR)
.error(appException.getCodeMessage().message(appException.getArgs()))
.build());
return AppUtil.writeResponse(request,
Expand All @@ -160,7 +161,7 @@ public HttpResponseMessage getTaxonomy(
private static TaxonomyJson getTaxonomy(Logger logger) {
try {
Instant now = Instant.now();
logger.info(MessageFormat.format("Retrieving the json file from the blob storage at: [{0}]",now));
logger.info(MessageFormat.format("Retrieving the json file from the blob storage at: [{0}]", now));
String content = getBlobContainerClientOutput()
.getBlobClient(JSON_NAME)
.downloadContent()
Expand All @@ -175,17 +176,16 @@ private static TaxonomyJson getTaxonomy(Logger logger) {
private static String generatePayload(Logger logger, String version, TaxonomyJson taxonomyJson) {
String payload = null;
if (version.equalsIgnoreCase(VersionEnum.STANDARD.toString())) {
logger.info(MessageFormat.format("Versioning json id = [{0}] to the standard version",taxonomyJson.getUuid()));
logger.info(MessageFormat.format("Versioning json id = [{0}] to the {1} version", taxonomyJson.getUuid(), VersionEnum.STANDARD));
List<TaxonomyStandard> taxonomyList = getObjectMapper().convertValue(taxonomyJson.getTaxonomyList(), new TypeReference<>() {});
payload = AppUtil.getPayload(getObjectMapper(), taxonomyList);
logger.info("Standard taxonomy retrieved successfully");
logger.info(MessageFormat.format("{0} taxonomy retrieved successfully", VersionEnum.STANDARD));
} else if (version.equalsIgnoreCase(VersionEnum.TOPIC_FLAG.toString())) {
logger.info("Versioning json id = [" + taxonomyJson.getUuid() + "] to the topic-flag version");
logger.info(MessageFormat.format("Versioning json id = [{0}] to the topic-flag version",taxonomyJson.getUuid()));
logger.info(MessageFormat.format("Versioning json id = [{0}] to the {1} version", taxonomyJson.getUuid(), VersionEnum.TOPIC_FLAG));

List<TaxonomyTopicFlag> taxonomyList = getObjectMapper().convertValue(taxonomyJson.getTaxonomyList(), new TypeReference<>() {});
payload = AppUtil.getPayload(getObjectMapper(), taxonomyList);
logger.info("Topic-flag taxonomy retrieved successfully");
logger.info(MessageFormat.format("{0} taxonomy retrieved successfully", VersionEnum.TOPIC_FLAG));
}
return payload;
}
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/it/gov/pagopa/taxonomy/TaxonomyUpdateFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import it.gov.pagopa.taxonomy.model.function.Message;
import it.gov.pagopa.taxonomy.model.json.TaxonomyTopicFlag;
import it.gov.pagopa.taxonomy.model.json.TaxonomyJson;
import it.gov.pagopa.taxonomy.util.AppMessageUtil;
import it.gov.pagopa.taxonomy.util.AppUtil;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.modelmapper.ModelMapper;
Expand All @@ -37,6 +38,7 @@

public class TaxonomyUpdateFunction {

private static final String UPDATE_FAILED = AppMessageUtil.getMessage("update.failed");
private static final String STORAGE_ACCOUNT_CONN_STRING = System.getenv("STORAGE_ACCOUNT_CONN_STRING");
private static final String BLOB_CONTAINER_NAME_INPUT = System.getenv("BLOB_CONTAINER_NAME_INPUT");
private static final String BLOB_CONTAINER_NAME_OUTPUT = System.getenv("BLOB_CONTAINER_NAME_OUTPUT");
Expand Down Expand Up @@ -105,9 +107,9 @@ public HttpResponseMessage updateTaxonomy(
);

} catch (AppException e) {
logger.log(Level.SEVERE, MessageFormat.format("[ALERT][Get][Triggered] AppException at {0}\n {1}",Instant.now(), ExceptionUtils.getStackTrace(e)));
logger.log(Level.SEVERE, MessageFormat.format("[ALERT][Get][Triggered] AppException at {0}\n {1}", Instant.now(), ExceptionUtils.getStackTrace(e)));
String payload = AppUtil.getPayload(getObjectMapper(), ErrorMessage.builder()
.message("Taxonomy update failed")
.message(UPDATE_FAILED)
.error(e.getCodeMessage().message(e.getArgs()))
.build());
return AppUtil.writeResponse(request,
Expand All @@ -117,21 +119,22 @@ public HttpResponseMessage updateTaxonomy(

} catch (BlobStorageException e) {
if(e.getErrorCode().equals(BlobErrorCode.BLOB_NOT_FOUND)) {
logger.log(Level.SEVERE, "[ALERT][Update] BlobStorageException at " + Instant.now() + "\n" + ExceptionUtils.getStackTrace(e), e);
logger.log(Level.SEVERE, MessageFormat.format("[ALERT][Update] BlobStorageException at {0} \n {1}" , Instant.now(), ExceptionUtils.getStackTrace(e)));

AppException appException = new AppException(e, AppErrorCodeMessageEnum.BLOB_NOT_FOUND_CSV_ERROR);
String payload = AppUtil.getPayload(getObjectMapper(), ErrorMessage.builder()
.message("Taxonomy update failed")
.message(UPDATE_FAILED)
.error(appException.getCodeMessage().message(appException.getArgs()))
.build());
return AppUtil.writeResponse(request,
HttpStatus.valueOf(appException.getCodeMessage().httpStatus().name()),
payload
);
} else {
logger.log(Level.SEVERE, "[ALERT][Update] BlobStorageException at " + Instant.now() + "\n" + ExceptionUtils.getStackTrace(e), e);
logger.log(Level.SEVERE,MessageFormat.format( "[ALERT][Update] BlobStorageException at {0}\n {1}", Instant.now(), ExceptionUtils.getStackTrace(e)));
AppException appException = new AppException(e, AppErrorCodeMessageEnum.ERROR);
String payload = AppUtil.getPayload(getObjectMapper(), ErrorMessage.builder()
.message("Taxonomy update failed")
.message(UPDATE_FAILED)
.error(appException.getCodeMessage().message(appException.getArgs()))
.build());
return AppUtil.writeResponse(request,
Expand All @@ -142,10 +145,9 @@ public HttpResponseMessage updateTaxonomy(
} catch (Exception e) {
logger.log(Level.SEVERE,MessageFormat.format("[ALERT][Get][Triggered] Generic error at {0}\n {1}",Instant.now(), ExceptionUtils.getStackTrace(e)));

logger.log(Level.SEVERE, "[ALERT][Update] GenericError at " + Instant.now() + "\n" + ExceptionUtils.getStackTrace(e), e);
AppException appException = new AppException(e, AppErrorCodeMessageEnum.ERROR);
String payload = AppUtil.getPayload(getObjectMapper(), ErrorMessage.builder()
.message("Taxonomy update failed")
.message(UPDATE_FAILED)
.error(appException.getCodeMessage().message(appException.getArgs()))
.build());
return AppUtil.writeResponse(request,
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ json.parsing.error=Error when parsing the JSON file.
blob.not.found.csv.error=Cannot find CSV file.
blob.not.found.json.error=Cannot find JSON file.
generic.retrieval.error=Taxonomy retrieval failed.
version.not.exists.error=Unknown version has been specified.
version.not.exists.error=Unknown version has been specified.
update.failed=Taxonomy update failed

0 comments on commit 252b92a

Please sign in to comment.