diff options
author | lapentafd <francesco.lapenta@est.tech> | 2022-12-19 09:04:59 +0000 |
---|---|---|
committer | Francesco Davide Lapenta <francesco.lapenta@est.tech> | 2022-12-19 11:39:47 +0000 |
commit | 9c259d345eb394e53f7c5cc239c4dd91c6ac8de6 (patch) | |
tree | 620f68eebbfff87b4fa4eae3f3f60bb6ab77bc42 /runtime-acm/src/main/java | |
parent | 0b5e99601abc5290d241f2082f12758ea46231ef (diff) |
Remove unused code in acm stubs
Issue-ID: POLICY-4143
Change-Id: Iaaa16a3a3273659506bc63169b5e87ae5ed288c1
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'runtime-acm/src/main/java')
3 files changed, 14 insertions, 21 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java index f03cc4ecd..1854fc24d 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/CommissioningControllerStub.java @@ -47,11 +47,10 @@ public class CommissioningControllerStub extends AbstractRestController private static final Logger log = LoggerFactory.getLogger(CommissioningControllerStub.class); - @Autowired - private HttpServletRequest request; + private StubUtils stubUtils = new StubUtils(); @Autowired - private StubUtils stubUtils; + private HttpServletRequest request; @Value("${stub.deleteCompositionDefinitionResponse}") private String pathToResponseFile; diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java index 40152683d..cdd3ad80f 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/InstantiationControllerStub.java @@ -47,8 +47,7 @@ public class InstantiationControllerStub extends AbstractRestController implemen private static final Logger log = LoggerFactory.getLogger(InstantiationControllerStub.class); - @Autowired - private StubUtils stubUtils; + private StubUtils stubUtils = new StubUtils(); @Autowired private HttpServletRequest request; diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java index 285365d9b..650426681 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/StubUtils.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import javax.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardYamlCoder; import org.slf4j.Logger; @@ -34,6 +35,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +@RequiredArgsConstructor @Service @Profile("stub") public class StubUtils { @@ -46,26 +48,19 @@ public class StubUtils { <T> ResponseEntity<T> getResponse(String path, Class<T> clazz, HttpServletRequest request, Logger log) { String accept = request.getHeader(ACCEPT); - if (accept.contains(YAML)) { - path = path.replace("json", "yaml"); - final ClassPathResource resourceY = new ClassPathResource(path); - try (InputStream inputStreamY = resourceY.getInputStream()) { - var targetObj = YAML_TRANSLATOR.decode(inputStreamY, clazz); - return new ResponseEntity<>(targetObj, HttpStatus.OK); - } catch (IOException | CoderException e) { - log.error("Error reading the file.", e); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - } else { - final ClassPathResource resource = new ClassPathResource(path); - try (InputStream inputStream = resource.getInputStream()) { + final ClassPathResource resource = new ClassPathResource(path); + try (InputStream inputStream = resource.getInputStream()) { + if (accept.contains(YAML)) { + var targetObject = YAML_TRANSLATOR.decode(inputStream, clazz); + return new ResponseEntity<>(targetObject, HttpStatus.OK); + } else { final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); var targetObject = JSON_TRANSLATOR.fromJson(string, clazz); return new ResponseEntity<>(targetObject, HttpStatus.OK); - } catch (final IOException exception) { - log.error("Error reading the file.", exception); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } + } catch (IOException | CoderException exception) { + log.error("Error reading the file.", exception); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } } |