diff options
author | James Forsyth <jf2512@att.com> | 2018-09-06 15:21:26 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-09-06 15:21:26 +0000 |
commit | bd45f44915e013fcb3cd330530247b07cb79d5c4 (patch) | |
tree | 44bb07fe1f23b39b792095420ba2e7ed6c57041e | |
parent | 865f2afae1223fd75daec75389ad849fd2af8cf0 (diff) | |
parent | 0d472eeb08a6e8705ee1e08bc6db8fb760604e85 (diff) |
Merge "renaming/constant instead of literal/unused items"
5 files changed, 274 insertions, 259 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/auth/AAIUser.java b/aai-core/src/main/java/org/onap/aai/auth/AAIUser.java index d0f7456e..499c6858 100644 --- a/aai-core/src/main/java/org/onap/aai/auth/AAIUser.java +++ b/aai-core/src/main/java/org/onap/aai/auth/AAIUser.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,56 +25,56 @@ import java.util.*; public class AAIUser { - private String username; + private String username; - private boolean isWildcard = false; - private Set<String> roles; - private Map<String, Set<String>> aaiFunctionToHttpMethod; + private boolean isWildcard = false; + private Set<String> roles; + private Map<String, Set<String>> aaiFunctionToHttpMethod; - public AAIUser(String username) { - this(username, false); - } + public AAIUser(String username) { + this(username, false); + } - public AAIUser(String username, boolean isWildcard) { - this.username = username; - this.roles = new HashSet<>(); - this.aaiFunctionToHttpMethod = new HashMap<>(); - this.isWildcard = isWildcard; - } + public AAIUser(String username, boolean isWildcard) { + this.username = username; + this.roles = new HashSet<>(); + this.aaiFunctionToHttpMethod = new HashMap<>(); + this.isWildcard = isWildcard; + } - public boolean isWildcard() { - return isWildcard; - } + public boolean isWildcard() { + return isWildcard; + } - public String getUsername() { - return username; - } + public String getUsername() { + return username; + } - public void addRole(String role) { - this.roles.add(role); - } + public void addRole(String role) { + this.roles.add(role); + } - public boolean hasRole(String role) { - return this.roles.contains(role); - } + public boolean hasRole(String role) { + return this.roles.contains(role); + } - public void setUserAccess(String aaiMethod, String... httpMethods) { - for (String httpMethod : httpMethods) { - this.addUserAccess(aaiMethod, httpMethod); - } - } + public void setUserAccess(String aaiMethod, String... httpMethods) { + for (String httpMethod : httpMethods) { + this.addUserAccess(aaiMethod, httpMethod); + } + } - private void addUserAccess(String aaiMethod, String httpMethod) { - Set<String> httpMethods = new HashSet<>(); - if (this.aaiFunctionToHttpMethod.containsKey(aaiMethod)) { - httpMethods = this.aaiFunctionToHttpMethod.get(aaiMethod); - } - httpMethods.add(httpMethod); - this.aaiFunctionToHttpMethod.put(aaiMethod, httpMethods); - } + private void addUserAccess(String aaiMethod, String httpMethod) { + Set<String> httpMethods = new HashSet<>(); + if (this.aaiFunctionToHttpMethod.containsKey(aaiMethod)) { + httpMethods = this.aaiFunctionToHttpMethod.get(aaiMethod); + } + httpMethods.add(httpMethod); + this.aaiFunctionToHttpMethod.put(aaiMethod, httpMethods); + } - public boolean hasAccess(String aaiMethod, String httpMethod) { - return this.aaiFunctionToHttpMethod.getOrDefault(aaiMethod, Collections.EMPTY_SET).contains(httpMethod); - } + public boolean hasAccess(String aaiMethod, String httpMethod) { + return this.aaiFunctionToHttpMethod.getOrDefault(aaiMethod, Collections.emptySet()).contains(httpMethod); + } } diff --git a/aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java b/aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java index c77fbfe9..01be1c27 100644 --- a/aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java +++ b/aai-core/src/main/java/org/onap/aai/auth/exceptions/AAIUnrecognizedFunctionException.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,19 +25,20 @@ import org.onap.aai.exceptions.AAIException; public class AAIUnrecognizedFunctionException extends AAIException { - private static final long serialVersionUID = 3297064867724071290L; + private static final String AAI_3012 = "AAI_3012"; + private static final long serialVersionUID = 3297064867724071290L; - public AAIUnrecognizedFunctionException() {} + public AAIUnrecognizedFunctionException() {} - public AAIUnrecognizedFunctionException(String message) { - super("AAI_3012", message); - } + public AAIUnrecognizedFunctionException(String message) { + super(AAI_3012, message); + } - public AAIUnrecognizedFunctionException(Throwable cause) { - super("AAI_3012",cause); - } + public AAIUnrecognizedFunctionException(Throwable cause) { + super(AAI_3012,cause); + } - public AAIUnrecognizedFunctionException(String message, Throwable cause) { - super("AAI_3012", cause, message); - } + public AAIUnrecognizedFunctionException(String message, Throwable cause) { + super(AAI_3012, cause, message); + } } diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java index 49cc0e90..2803f69b 100644 --- a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java +++ b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -41,85 +43,87 @@ import org.springframework.web.client.RestTemplate; public class AAIDmaapEventJMSConsumer implements MessageListener { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIDmaapEventJMSConsumer.class); - - private RestTemplate restTemplate; - - private HttpHeaders httpHeaders; - - private Environment environment; - - public AAIDmaapEventJMSConsumer(Environment environment, RestTemplate restTemplate, HttpHeaders httpHeaders) { - Objects.nonNull(environment); - Objects.nonNull(restTemplate); - Objects.nonNull(httpHeaders); - this.environment = environment; - this.restTemplate = restTemplate; - this.httpHeaders = httpHeaders; - } - - @Override - public void onMessage(Message message) { - - if(restTemplate == null){ - return; - } - - String jsmMessageTxt = ""; - String aaiEvent = ""; - String eventName = ""; - - if (message instanceof TextMessage) { - try { - jsmMessageTxt = ((TextMessage) message).getText(); - JSONObject jo = new JSONObject(jsmMessageTxt); - - if (jo.has("aaiEventPayload")) { - aaiEvent = jo.getJSONObject("aaiEventPayload").toString(); - } else { - return; - } - if (jo.getString("transId") != null) { - MDC.put("requestId", jo.getString("transId")); - } - if (jo.getString("fromAppId") != null) { - MDC.put("partnerName", jo.getString("fromAppId")); - } - if (jo.getString("event-topic") != null) { - eventName = jo.getString("event-topic"); - } - - MDC.put ("targetEntity", "DMAAP"); - if (jo.getString("event-topic") != null) { - eventName = jo.getString("event-topic"); - MDC.put ("targetServiceName", eventName); - } - MDC.put ("serviceName", "AAI"); - MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.COMPLETE.toString()); - MDC.put(LoggingField.RESPONSE_CODE.toString(), "0"); - LOGGER.info(eventName + "|" + aaiEvent); - HttpEntity httpEntity = new HttpEntity(aaiEvent, httpHeaders); - - String transportType = environment.getProperty("dmaap.ribbon.transportType", "http"); - String baseUrl = transportType + "://" + environment.getProperty("dmaap.ribbon.listOfServers"); - String endpoint = "/events/" + eventName; - - if ("AAI-EVENT".equals(eventName)) { + private static final String EVENT_TOPIC = "event-topic"; + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIDmaapEventJMSConsumer.class); + + private RestTemplate restTemplate; + + private HttpHeaders httpHeaders; + + private Environment environment; + + public AAIDmaapEventJMSConsumer(Environment environment, RestTemplate restTemplate, HttpHeaders httpHeaders) { + Objects.nonNull(environment); + Objects.nonNull(restTemplate); + Objects.nonNull(httpHeaders); + this.environment = environment; + this.restTemplate = restTemplate; + this.httpHeaders = httpHeaders; + } + + @Override + public void onMessage(Message message) { + + if(restTemplate == null){ + return; + } + + String jsmMessageTxt = ""; + String aaiEvent = ""; + String eventName = ""; + + if (message instanceof TextMessage) { + try { + jsmMessageTxt = ((TextMessage) message).getText(); + JSONObject jo = new JSONObject(jsmMessageTxt); + + if (jo.has("aaiEventPayload")) { + aaiEvent = jo.getJSONObject("aaiEventPayload").toString(); + } else { + return; + } + if (jo.getString("transId") != null) { + MDC.put("requestId", jo.getString("transId")); + } + if (jo.getString("fromAppId") != null) { + MDC.put("partnerName", jo.getString("fromAppId")); + } + if (jo.getString(EVENT_TOPIC) != null) { + eventName = jo.getString(EVENT_TOPIC); + } + + MDC.put ("targetEntity", "DMAAP"); + if (jo.getString(EVENT_TOPIC) != null) { + eventName = jo.getString(EVENT_TOPIC); + MDC.put ("targetServiceName", eventName); + } + MDC.put ("serviceName", "AAI"); + MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.COMPLETE.toString()); + MDC.put(LoggingField.RESPONSE_CODE.toString(), "0"); + LOGGER.info(eventName + "|" + aaiEvent); + HttpEntity httpEntity = new HttpEntity(aaiEvent, httpHeaders); + + String transportType = environment.getProperty("dmaap.ribbon.transportType", "http"); + String baseUrl = transportType + "://" + environment.getProperty("dmaap.ribbon.listOfServers"); + String endpoint = "/events/" + eventName; + + if ("AAI-EVENT".equals(eventName)) { restTemplate.exchange(baseUrl + endpoint, HttpMethod.POST, httpEntity, String.class); - } else { - LoggingContext.statusCode(StatusCode.ERROR); - LOGGER.error(eventName + "|Event Topic invalid."); - } - } catch (JMSException | JSONException e) { - MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString()); - MDC.put(LoggingField.RESPONSE_CODE.toString(), "200"); - LOGGER.error("AAI_7350 Error parsing aaievent jsm message for sending to dmaap. {} {}", jsmMessageTxt, LogFormatTools.getStackTop(e)); - } catch (Exception e) { - MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString()); - MDC.put(LoggingField.RESPONSE_CODE.toString(), "200"); - LOGGER.error("AAI_7350 Error sending message to dmaap. {} {}" , jsmMessageTxt, LogFormatTools.getStackTop(e)); - } - } - - } + } else { + LoggingContext.statusCode(StatusCode.ERROR); + LOGGER.error(eventName + "|Event Topic invalid."); + } + } catch (JMSException | JSONException e) { + MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString()); + MDC.put(LoggingField.RESPONSE_CODE.toString(), "200"); + LOGGER.error("AAI_7350 Error parsing aaievent jsm message for sending to dmaap. {} {}", jsmMessageTxt, LogFormatTools.getStackTop(e)); + } catch (Exception e) { + MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString()); + MDC.put(LoggingField.RESPONSE_CODE.toString(), "200"); + LOGGER.error("AAI_7350 Error sending message to dmaap. {} {}" , jsmMessageTxt, LogFormatTools.getStackTop(e)); + } + } + + } } diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java index 851a22fe..35e1a4a5 100644 --- a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java +++ b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -28,22 +30,22 @@ import org.springframework.jms.core.JmsTemplate; public class AAIDmaapEventJMSProducer implements MessageProducer { - private JmsTemplate jmsTemplate; + private JmsTemplate jmsTemplate; - public AAIDmaapEventJMSProducer() { - if(AAIConfig.get("aai.jms.enable", "true").equals("true")){ + public AAIDmaapEventJMSProducer() { + if("true".equals(AAIConfig.get("aai.jms.enable", "true"))){ this.jmsTemplate = new JmsTemplate(); String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61547"); this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl))); this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE")); - } - } + } + } - public void sendMessageToDefaultDestination(JSONObject finalJson) { - if(jmsTemplate != null){ - jmsTemplate.convertAndSend(finalJson.toString()); - CachingConnectionFactory ccf = (CachingConnectionFactory) this.jmsTemplate.getConnectionFactory(); - ccf.destroy(); - } - } + public void sendMessageToDefaultDestination(JSONObject finalJson) { + if(jmsTemplate != null){ + jmsTemplate.convertAndSend(finalJson.toString()); + CachingConnectionFactory ccf = (CachingConnectionFactory) this.jmsTemplate.getConnectionFactory(); + ccf.destroy(); + } + } } diff --git a/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java b/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java index f2253a30..0851e719 100644 --- a/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java +++ b/aai-core/src/main/java/org/onap/aai/exceptions/AAIException.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -28,119 +30,121 @@ import org.onap.aai.logging.ErrorObjectNotFoundException; public class AAIException extends Exception { - public static final String DEFAULT_EXCEPTION_CODE = "AAI_4000"; - private static final long serialVersionUID = 1L; - - private final String code; - private final ErrorObject errorObject; - private final Collection<String> templateVars; - - /** - * Instantiates a new AAI exception. - */ - public AAIException() { - super(); - this.code = DEFAULT_EXCEPTION_CODE; - this.templateVars = new LinkedList<String> (); - - try { - this.errorObject = ErrorLogHelper.getErrorObject(getCode()); - } catch (ErrorObjectNotFoundException e) { - throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode() - + " - update error.properties before using this exception code"); - } - } - - /** - * Instantiates a new AAI exception. - * - * @param code the code - */ - public AAIException(String code) { - super(); - - this.code = code; - this.templateVars = new LinkedList<String> (); - - try { - this.errorObject = ErrorLogHelper.getErrorObject(getCode()); - } catch (ErrorObjectNotFoundException e) { - throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode() - + " - update error.properties before using this exception code"); - } - } - - /** - * Instantiates a new AAI exception. - * - * @param code the code - * @param details the details - */ - public AAIException(String code, String details) { - super(details); - - this.code = code; - this.templateVars = new LinkedList<String> (); - - try { - this.errorObject = ErrorLogHelper.getErrorObject(getCode()); - errorObject.setDetails(details); - } catch (ErrorObjectNotFoundException e) { - throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode() - + " - update error.properties before using this exception code"); - } - } - - /** - * Instantiates a new AAI exception. - * - * @param code the code - * @param cause the cause - */ - public AAIException(String code, Throwable cause) { - super(cause); - - this.code = code; - this.templateVars = new LinkedList<String> (); - - try { - this.errorObject = ErrorLogHelper.getErrorObject(getCode()); - } catch (ErrorObjectNotFoundException e) { - throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode() - + " - update error.properties before using this exception code"); - } - } - - /** - * Instantiates a new AAI exception. - * - * @param code the code - * @param cause the cause - * @param details the details - */ - public AAIException(String code, Throwable cause, String details) { - super(details, cause); - - this.code = code; - this.templateVars = new LinkedList<String> (); - - try { - this.errorObject = ErrorLogHelper.getErrorObject(getCode()); - } catch (ErrorObjectNotFoundException e) { - throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode() - + " - update error.properties before using this exception code"); - } - } - - public String getCode() { - return code; - } - - public ErrorObject getErrorObject() { - return errorObject; - } - - public Collection<String> getTemplateVars() { - return templateVars; - } + private static final String UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE = " - update error.properties before using this exception code"; + private static final String FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE = "Failed to instantiate AAIException with code="; + public static final String DEFAULT_EXCEPTION_CODE = "AAI_4000"; + private static final long serialVersionUID = 1L; + + private final String code; + private final ErrorObject errorObject; + private final Collection<String> templateVars; + + /** + * Instantiates a new AAI exception. + */ + public AAIException() { + super(); + this.code = DEFAULT_EXCEPTION_CODE; + this.templateVars = new LinkedList<String> (); + + try { + this.errorObject = ErrorLogHelper.getErrorObject(getCode()); + } catch (ErrorObjectNotFoundException e) { + throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode() + + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE); + } + } + + /** + * Instantiates a new AAI exception. + * + * @param code the code + */ + public AAIException(String code) { + super(); + + this.code = code; + this.templateVars = new LinkedList<String> (); + + try { + this.errorObject = ErrorLogHelper.getErrorObject(getCode()); + } catch (ErrorObjectNotFoundException e) { + throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode() + + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE); + } + } + + /** + * Instantiates a new AAI exception. + * + * @param code the code + * @param details the details + */ + public AAIException(String code, String details) { + super(details); + + this.code = code; + this.templateVars = new LinkedList<String> (); + + try { + this.errorObject = ErrorLogHelper.getErrorObject(getCode()); + errorObject.setDetails(details); + } catch (ErrorObjectNotFoundException e) { + throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode() + + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE); + } + } + + /** + * Instantiates a new AAI exception. + * + * @param code the code + * @param cause the cause + */ + public AAIException(String code, Throwable cause) { + super(cause); + + this.code = code; + this.templateVars = new LinkedList<String> (); + + try { + this.errorObject = ErrorLogHelper.getErrorObject(getCode()); + } catch (ErrorObjectNotFoundException e) { + throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode() + + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE); + } + } + + /** + * Instantiates a new AAI exception. + * + * @param code the code + * @param cause the cause + * @param details the details + */ + public AAIException(String code, Throwable cause, String details) { + super(details, cause); + + this.code = code; + this.templateVars = new LinkedList<String> (); + + try { + this.errorObject = ErrorLogHelper.getErrorObject(getCode()); + } catch (ErrorObjectNotFoundException e) { + throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode() + + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE); + } + } + + public String getCode() { + return code; + } + + public ErrorObject getErrorObject() { + return errorObject; + } + + public Collection<String> getTemplateVars() { + return templateVars; + } } |