Merge pull request #150 from Kitzanos/feature/GEPAFINBE-138
GEPAFINBE-138 (Updated VatCheck API log)
This commit is contained in:
@@ -68,24 +68,45 @@ public class VatCheckDao {
|
|||||||
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
|
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
|
||||||
log.info("Successfully checked vat number");
|
log.info("Successfully checked vat number");
|
||||||
Map<String, Object> responseMap = response.getBody();
|
Map<String, Object> responseMap = response.getBody();
|
||||||
|
processValidResponse(responseMap, vatCheckResponseBean);
|
||||||
|
}
|
||||||
|
} catch (FeignException ex) {
|
||||||
|
if (ex.status() == 406) {
|
||||||
|
try {
|
||||||
|
Map<String, Object> errorResponse = Utils.parseErrorResponse(ex.contentUTF8());
|
||||||
|
processValidResponse(errorResponse, vatCheckResponseBean);
|
||||||
|
} catch (Exception parseEx) {
|
||||||
|
log.error("Failed to parse 406 error response: {0}", parseEx);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("Exception occurred while checking vat number: {0}", ex);
|
||||||
|
Utils.callException(ex.status(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vatCheckResponseBean;
|
||||||
|
}
|
||||||
|
public static void processValidResponse(Map<String, Object> responseMap, VatCheckResponseBean vatCheckResponseBean) {
|
||||||
if (responseMap != null && responseMap.containsKey("data")) {
|
if (responseMap != null && responseMap.containsKey("data")) {
|
||||||
responseBody = (Map<String, Object>) responseMap.get("data");
|
Map<String, Object> responseBody = (Map<String, Object>) responseMap.get("data");
|
||||||
|
|
||||||
|
if (responseBody != null) {
|
||||||
responseBody.remove("timestamp_creation");
|
responseBody.remove("timestamp_creation");
|
||||||
responseBody.remove("timestamp_last_update");
|
responseBody.remove("timestamp_last_update");
|
||||||
responseBody.remove("data_iscrizione");
|
responseBody.remove("data_iscrizione");
|
||||||
responseBody.remove("id");
|
responseBody.remove("id");
|
||||||
|
|
||||||
Map<String, Object> data = new LinkedHashMap<>();
|
Map<String, Object> data = new LinkedHashMap<>();
|
||||||
data.put("data", responseBody);
|
data.put("data", responseBody);
|
||||||
|
|
||||||
vatCheckResponseBean.setValid(true);
|
vatCheckResponseBean.setValid(true);
|
||||||
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.VALID_VATNUMBER_MSG));
|
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.VALID_VATNUMBER_MSG));
|
||||||
vatCheckResponseBean.setVatCheckResponse(data);
|
vatCheckResponseBean.setVatCheckResponse(data);
|
||||||
|
} else {
|
||||||
|
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vatCheckResponseBean.setMessage(Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||||
}
|
}
|
||||||
} catch (FeignException ex) {
|
|
||||||
log.error("Exception occurred while checking vat number: {0}", ex);
|
|
||||||
Utils.callException(ex.status(), ex);
|
|
||||||
}
|
|
||||||
return vatCheckResponseBean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public VatCheckResponseBean checkVatNumber(String vatNumber) {
|
public VatCheckResponseBean checkVatNumber(String vatNumber) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import jakarta.persistence.ManyToOne;
|
|||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import net.gepafin.tendermanagement.config.Translator;
|
||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -697,4 +698,22 @@ public class Utils {
|
|||||||
public static String createChannelForUserAndCompany(Long userId, Long companyId) {
|
public static String createChannelForUserAndCompany(Long userId, Long companyId) {
|
||||||
return GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId + GepafinConstant.COMPANY_PREFIX + companyId;
|
return GepafinConstant.COMMON_SINGLE_CHANNEL_PREFIX + userId + GepafinConstant.COMPANY_PREFIX + companyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> parseErrorResponse(String responseBody) {
|
||||||
|
if (StringUtils.isBlank(responseBody)) {
|
||||||
|
return defaultErrorResponse();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return mapper.readValue(responseBody, Map.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to parse error response: {}", e.getMessage(), e);
|
||||||
|
return defaultErrorResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, Object> defaultErrorResponse() {
|
||||||
|
return Collections.singletonMap("message", Translator.toLocale(GepafinConstant.INVALID_VATNUMBER));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user