import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.commons.io.IOUtils;
import org.onap.nbi.OnapComponentsUrlPaths;
import org.onap.nbi.exceptions.BackendFunctionalException;
@Service
public class SdcClient {
- public static final String HTTP_CALL_SDC_ON = "HTTP call SDC on ";
@Autowired
private RestTemplate restTemplate;
UriComponentsBuilder callURI = UriComponentsBuilder.fromHttpUrl(sdcHost + OnapComponentsUrlPaths.SDC_ROOT_URL);
if (parametersMap != null) {
Map<String, String> stringStringMap = parametersMap.toSingleValueMap();
- for (String key : stringStringMap.keySet()) {
- if (!key.equals("fields")) {
- callURI.queryParam(key, stringStringMap.get(key));
+ for (Entry<String, String> entry : stringStringMap.entrySet()) {
+ if (!entry.getKey().equals("fields")) {
+ callURI.queryParam(entry.getKey(), entry.getValue());
}
}
}
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HEADER_ECOMP_INSTANCE_ID, ecompInstanceId);
httpHeaders.add(HEADER_AUTHORIZATION, sdcHeaderAuthorization);
- HttpEntity<String> entity = new HttpEntity<>("parameters", httpHeaders);
-
- return entity;
+ return new HttpEntity<>("parameters", httpHeaders);
}
private ResponseEntity<Object> callSdc(URI callURI) {
ResponseEntity<Object> response =
restTemplate.exchange(callURI, HttpMethod.GET, buildRequestHeader(), Object.class);
- LOGGER.debug("response body : " + response.getBody().toString());
- LOGGER.info("response status : " + response.getStatusCodeValue());
+ if(LOGGER.isDebugEnabled()) {
+ LOGGER.debug("response body : {} ",response.getBody().toString());
+ }
+ LOGGER.info("response status : {}", response.getStatusCodeValue());
loggDebugIfResponseKo(callURI.toString(), response);
return response;
}
ResponseEntity<byte[]> response =
restTemplate.exchange(callURI, HttpMethod.GET, buildRequestHeader(), byte[].class);
LOGGER.info("response status : " + response.getStatusCodeValue());
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- LOGGER.warn(HTTP_CALL_SDC_ON + callURI.toString() + " returns " + response.getStatusCodeValue() + ", ");
+ if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) {
+ LOGGER.warn("HTTP call SDC on {} returns {} ", callURI.toString() , response.getStatusCodeValue());
}
return response;
} catch (BackendFunctionalException e) {
- LOGGER.error(HTTP_CALL_SDC_ON + callURI.toString() + " error " + e);
+ LOGGER.error("HTTP call SDC on {} error : {}", callURI.toString() , e);
return null;
}
}
private void loggDebugIfResponseKo(String callURI, ResponseEntity<Object> response) {
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- LOGGER.warn(HTTP_CALL_SDC_ON + callURI + " returns " + response.getStatusCodeValue() + ", "
- + response.getBody().toString());
+ if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) {
+ LOGGER.warn("HTTP call SDC on {} returns {} , {}", callURI , response.getStatusCodeValue() , response.getBody().toString());
}
}
}
import java.util.List;
import java.util.Map;
import org.onap.nbi.commons.JsonRepresentation;
-import org.onap.nbi.commons.Resource;
import org.onap.nbi.commons.ResourceManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
@RestController
@RequestMapping("/serviceSpecification")
-public class ServiceSpecificationResource extends ResourceManagement<Resource> {
+public class ServiceSpecificationResource extends ResourceManagement {
@Autowired
}
private void buildCharacteristicValuesFormShema(String parameterType,
- List<LinkedHashMap> serviceSpecCharacteristicValues, Object aDefault, ArrayList entry_schema) {
- LinkedHashMap constraints = (LinkedHashMap) entry_schema.get(0);
+ List<LinkedHashMap> serviceSpecCharacteristicValues, Object aDefault, ArrayList entrySchema) {
+ LinkedHashMap constraints = (LinkedHashMap) entrySchema.get(0);
if (constraints != null) {
ArrayList constraintsList = (ArrayList) constraints.get("constraints");
if (CollectionUtils.isNotEmpty(constraintsList)) {
}
- private LinkedHashMap getToscaInfosFromResourceUUID(LinkedHashMap node_templates, String name) {
- if(node_templates!=null) {
- for (Object nodeTemplateObject : node_templates.values()) {
+ private LinkedHashMap getToscaInfosFromResourceUUID(LinkedHashMap nodeTemplates, String name) {
+ if(nodeTemplates!=null) {
+ for (Object nodeTemplateObject : nodeTemplates.values()) {
LinkedHashMap nodeTemplate = (LinkedHashMap) nodeTemplateObject;
LinkedHashMap metadata = (LinkedHashMap) nodeTemplate.get("metadata");
if(metadata.get("UUID")!=null && metadata.get("type")!=null) {
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
-
- fos.close();
}
ze = zis.getNextEntry();
}
-
zis.closeEntry();
- zis.close();
}
LOGGER.debug("Done");
ResponseEntity<Object> response = restTemplate.exchange(callURL, HttpMethod.GET,
new HttpEntity<>("parameters", httpHeaders), Object.class);
- LOGGER.debug("response body : " + response.getBody().toString());
- LOGGER.info("response status : " + response.getStatusCodeValue());
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- LOGGER.warn("HTTP call on " + callURL + " returns " + response.getStatusCodeValue() + ", "
- + response.getBody().toString());
+ if(LOGGER.isDebugEnabled()){
+ LOGGER.debug("response body : {}",response.getBody().toString());
+ }
+ LOGGER.info("response status : {}", response.getStatusCodeValue());
+ if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) {
+ LOGGER.warn("HTTP call on {} returns {}, {}", callURL , response.getStatusCodeValue() ,response.getBody().toString());
}
return response;
}
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.onap.nbi.OnapComponentsUrlPaths;
import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo;
import org.onap.nbi.exceptions.BackendFunctionalException;
public ResponseEntity<Object> getServiceCatalog(String id) {
StringBuilder callURL = new StringBuilder().append(serviceCatalogUrl.getServiceCatalogUrl()).append(id);
- ResponseEntity<Object> response = callApiGet(callURL.toString(), new HttpHeaders(), null);
- return response;
+ return callApiGet(callURL.toString(), new HttpHeaders(), null);
}
public boolean doesServiceExistInServiceInventory(String id, String serviceName, String globalSubscriberId) {
param.put("relatedParty.id", globalSubscriberId);
ResponseEntity<Object> response = callApiGet(callURL.toString(), new HttpHeaders(), param);
- if (response == null || !response.getStatusCode().equals(HttpStatus.OK)) {
- return false;
- }
- return true;
+ return response != null && response.getStatusCode().equals(HttpStatus.OK);
}
StringBuilder callURL = new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_CUSTOMER_PATH)
.append(customerId);
ResponseEntity<Object> response = callApiGet(callURL.toString(), buildRequestHeaderForAAI(), null);
- if (response != null && response.getStatusCode().equals(HttpStatus.OK)) {
- return true;
- }
- return false;
+ return(response != null && response.getStatusCode().equals(HttpStatus.OK));
}
aaiHost + OnapComponentsUrlPaths.AAI_GET_CUSTOMER_PATH + subscriberInfo.getGlobalSubscriberId();
ResponseEntity<Object> response = putRequest(param, callURL, buildRequestHeaderForAAI());
- if (response != null && response.getStatusCode().equals(HttpStatus.CREATED)) {
- return true;
- }
- return false;
+ return response != null && response.getStatusCode().equals(HttpStatus.CREATED);
}
String callURL = aaiHost + OnapComponentsUrlPaths.AAI_PUT_SERVICE_FOR_CUSTOMER_PATH + serviceName;
String callUrlFormated = callURL.replace("$customerId", globalSubscriberId);
ResponseEntity<Object> response = putRequest(param, callUrlFormated, buildRequestHeaderForAAI());
- if (response != null && response.getStatusCode().equals(HttpStatus.CREATED)) {
- return true;
- }
- return false;
+ return response != null && response.getStatusCode().equals(HttpStatus.CREATED);
}
ResponseEntity<Object> response =
restTemplate.exchange(callUrl, HttpMethod.PUT, new HttpEntity<>(param, httpHeaders), Object.class);
LOGGER.info("response status : " + response.getStatusCodeValue());
- if (!response.getStatusCode().equals(HttpStatus.CREATED)) {
- LOGGER.warn("HTTP call on " + callUrl + " returns " + response.getStatusCodeValue() + ", "
- + response.getBody().toString());
+ if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.CREATED)) {
+ LOGGER.warn("HTTP call on {} returns {} , {}", callUrl , response.getStatusCodeValue(), response.getBody().toString());
}
return response;
} catch (BackendFunctionalException|ResourceAccessException e) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(callURL);
if (param != null) {
- for (String paramName : param.keySet()) {
- builder.queryParam(paramName, param.get(paramName));
+ for (Entry<String, String> stringEntry : param.entrySet()) {
+ builder.queryParam(stringEntry.getKey(), stringEntry.getValue());
+
}
}
URI uri = builder.build().encode().toUri();
ResponseEntity<Object> response =
restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(httpHeaders), Object.class);
- LOGGER.debug("response body : " + response.getBody().toString());
- LOGGER.info("response status : " + response.getStatusCodeValue());
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- LOGGER.warn("HTTP call on " + callURL + " returns " + response.getStatusCodeValue() + ", "
- + response.getBody().toString());
+ if(LOGGER.isDebugEnabled()){
+ LOGGER.debug("response body : {}", response.getBody().toString());
+ }
+ LOGGER.info("response status : {}", response.getStatusCodeValue());
+ if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) {
+ LOGGER.warn("HTTP call on {} returns {} , {}", callURL , response.getStatusCodeValue(), response.getBody().toString());
+
}
return response;
@RestController
@RequestMapping("/serviceOrder")
@EnableScheduling
-public class ServiceOrderResource extends ResourceManagement<ServiceOrder> {
+public class ServiceOrderResource extends ResourceManagement {
public class SoClient {
public static final String RESPONSE_STATUS = "response status : ";
- public static final String RESPONSE_BODY = "response body : ";
public static final String RETURNS = " returns ";
public static final String ERROR_ON_CALLING = "error on calling ";
@Autowired
private void logResponsePost(String url, ResponseEntity<CreateServiceInstanceResponse> response) {
LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue());
- LOGGER.debug(RESPONSE_BODY + response.getBody().toString());
+ if(LOGGER.isDebugEnabled()){
+ LOGGER.debug("response body : {}", response.getBody().toString());
+ }
- if (!response.getStatusCode().equals(HttpStatus.CREATED)) {
- LOGGER.warn("HTTP call SO on " + url + RETURNS + response.getStatusCodeValue() + ", "
- + response.getBody().toString());
+ if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.CREATED)) {
+ LOGGER.warn("HTTP call SO on {} returns {} , {}",url ,response.getStatusCodeValue(), response.getBody().toString());
}
}
private void logResponseGet(String url, ResponseEntity<GetRequestStatusResponse> response) {
if(response!=null){
- LOGGER.debug(RESPONSE_BODY + response.getBody().toString());
- LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue());
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- LOGGER.warn("HTTP call on " + url + RETURNS + response.getStatusCodeValue() + ", "
- + response.getBody().toString());
+ if(LOGGER.isDebugEnabled()){
+ LOGGER.debug("response body : {}", response.getBody().toString());
+ }
+ LOGGER.info("response status : {}", response.getStatusCodeValue());
+ if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) {
+ LOGGER.warn("HTTP call SO on {} returns {} , {}",url ,response.getStatusCodeValue(), response.getBody().toString());
}
} else {
LOGGER.info("no response calling url {}",url);
public final class JsonEntityConverter {
+ private JsonEntityConverter() {
+ }
+
private static final ObjectMapper MAPPER = new ObjectMapper();
public static String convertServiceOrderInfoToJson(ServiceOrderInfo serviceOrderInfo) {
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.onap.nbi.apis.serviceorder.model.OrderItemRelationship;
import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
}
// then we replace all orderitem ids in reliedtasks field with internalid of the tasks
for (ExecutionTask executionTask : executionTasksSaved) {
- for (String key : internalIdOrderItemsMap.keySet()) {
- String replace = executionTask.getReliedTasks().replace(key,
- String.valueOf(internalIdOrderItemsMap.get(key)));
+ for (Entry<String, Long> entry : internalIdOrderItemsMap.entrySet()) {
+ String replace = executionTask.getReliedTasks().replace(entry.getKey(),
+ String.valueOf(entry.getValue()));
executionTask.setReliedTasks(replace);
}
- LOGGER.debug("saving task with id {} , orderItemId {} , reliedtasks ", executionTask.getInternalId(),
- executionTask.getOrderItemId(), executionTask.getReliedTasks());
+ if(LOGGER.isDebugEnabled()) {
+ LOGGER.debug("saving task with id {} , orderItemId {} , reliedtasks {}", executionTask.getInternalId(),
+ executionTask.getOrderItemId(), executionTask.getReliedTasks());
+ }
executionTaskRepository.save(executionTask);
}
}
* Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from SDC
*/
private List<UserParams> retrieveUserParamsFromServiceCharacteristics(List<ServiceCharacteristic> characteristics) {
- List<UserParams> userParams = new ArrayList<UserParams>();
+ List<UserParams> userParams = new ArrayList<>();
if (!CollectionUtils.isEmpty(characteristics)) {
for (ServiceCharacteristic characteristic : characteristics) {
@RestController
@RequestMapping("/status")
-public class StatusResource extends ResourceManagement<ApplicationStatus> {
+public class StatusResource extends ResourceManagement {
@Autowired
private StatusService statusService;
@Override
public ApplicationStatus get(final String serviceName, final String serviceVersion) {
- final boolean applicationIsUp = true;
+ return new ApplicationStatus(serviceName, (StatusType.OK), serviceVersion);
-
- final ApplicationStatus applicationStatus =
- new ApplicationStatus(serviceName, (applicationIsUp ? StatusType.OK : StatusType.KO), serviceVersion);
-
-
- return applicationStatus;
}
private static final PropertyUtilsBean PUB = new PropertyUtilsBean();
+ private BeanUtils() {
+ }
+
/**
*
* @param bean
public class JacksonFilter {
- private final static List<String> SKIPPED_FIELDS = Arrays.asList("internalId");
+ private static final List<String> SKIPPED_FIELDS = Arrays.asList("internalId");
+ private JacksonFilter() {
+ }
public static <R> List<ObjectNode> createNodes(List<R> list, JsonRepresentation jsonRepresentation) {
// split fieldNames in 2 categories :
// simpleFields for simple property names with no '.'
// nestedFields for nested property names with a '.'
- Set<String> simpleFields = new LinkedHashSet<String>();
+ Set<String> simpleFields = new LinkedHashSet<>();
MultiValueMap nestedFields = new LinkedMultiValueMap();
buildFields(names, simpleFields, nestedFields);
if (nestedBean == null) {
continue;
}
- Set<String> nestedFieldNames = new LinkedHashSet<String>(entry.getValue());
+ Set<String> nestedFieldNames = new LinkedHashSet<>(entry.getValue());
// current node is an array or a list
if ((nestedBean.getClass().isArray()) || (Collection.class.isAssignableFrom(nestedBean.getClass()))) {
handleListNode(mapper, rootNode, rootFieldName, nestedBean, nestedFieldNames);
if (array.length > 0) {
// create a node for each element in array
// and add created node in an arrayNode
- Collection<JsonNode> nodes = new LinkedList<JsonNode>();
+ Collection<JsonNode> nodes = new LinkedList<>();
for (Object object : array) {
ObjectNode nestedNode = JacksonFilter.createNode(mapper, object, nestedFieldNames);
if ((nestedNode != null) && (nestedNode.size() > 0)) {
Set<Entry<String, List<String>>> entrySet = queryParameters.entrySet();
- MultiValueMap<String, String> criterias = new LinkedMultiValueMap<String, String>();
+ MultiValueMap<String, String> criterias = new LinkedMultiValueMap<>();
entrySet.stream().forEach(entry -> {
- final List<String> tempValues = new ArrayList<String>();
+ final List<String> tempValues = new ArrayList<>();
entry.getValue().stream().forEach(value -> tempValues.addAll(Arrays.asList(value.split(","))));
criterias.put(entry.getKey(), tempValues);
});
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
-public class ResourceManagement<T extends Resource> {
+public class ResourceManagement {
/**
* Build default 201 filtered response for resource
public ResponseEntity<ApiError> backendExceptionHandler(final BackendFunctionalException exception) {
ApiError apiError =
new ApiError(String.valueOf(exception.getHttpStatus().value()), exception.getMessage(), "", "");
- return new ResponseEntity<ApiError>(apiError, exception.getHttpStatus());
+ return new ResponseEntity<>(apiError, exception.getHttpStatus());
}
@ExceptionHandler(TechnicalException.class)
public ResponseEntity<ApiError> technicalExceptionHandler(final TechnicalException exception) {
ApiError apiError =
new ApiError(String.valueOf(exception.getHttpStatus().value()), exception.getMessage(), "", "");
- return new ResponseEntity<ApiError>(apiError, exception.getHttpStatus());
+ return new ResponseEntity<>(apiError, exception.getHttpStatus());
}
@ExceptionHandler(RestClientException.class)
@ResponseBody
- public ResponseEntity<ApiError> RestClientExceptionHandler(final RestClientException exception) {
+ public ResponseEntity<ApiError> restClientExceptionHandler(final RestClientException exception) {
ApiError apiError = new ApiError("500", HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),
"Unable to " + "reach ONAP services", "");
- return new ResponseEntity<ApiError>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(ValidationException.class)
@ResponseBody
- public ResponseEntity<ApiError> ValidationExceptionHandler(final ValidationException exception) {
+ public ResponseEntity<ApiError> validationExceptionHandler(final ValidationException exception) {
ApiError apiError = new ApiError("400", HttpStatus.BAD_REQUEST.getReasonPhrase(), exception.getMessages(), "");
- return new ResponseEntity<ApiError>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
+ return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
public class BackendFunctionalException extends ApiException {
- private HttpStatus httpStatus;
+ private final HttpStatus httpStatus;
public BackendFunctionalException(HttpStatus httpStatus, String message) {
super(message);
this.httpStatus = httpStatus;
}
- public BackendFunctionalException() {
- super();
- }
-
public HttpStatus getHttpStatus() {
return httpStatus;
}
public class TechnicalException extends ApiException {
- private HttpStatus httpStatus;
+ private final HttpStatus httpStatus;
public TechnicalException(String message) {
super(message);
this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
}
- public TechnicalException() {
- super();
- }
public HttpStatus getHttpStatus() {
return httpStatus;
}
- public void setHttpStatus(HttpStatus httpStatus) {
- this.httpStatus = httpStatus;
- }
}
public class ValidationException extends ApiException {
- private String messages;
+ private final String messages;
public ValidationException(List<ObjectError> listErrors) {
super();