diff options
Diffstat (limited to 'vid-app-common/src/main')
4 files changed, 90 insertions, 37 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/ChangeManagementController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/ChangeManagementController.java index 59fe61fd0..88875b510 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/ChangeManagementController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controllers/ChangeManagementController.java @@ -1,12 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.onap.vid.controllers; +import static org.onap.vid.utils.Logging.getMethodName; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.OK; + import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Collection; +import java.util.Collections; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.WebApplicationException; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.tuple.Pair; import org.json.simple.JSONArray; import org.onap.portalsdk.core.controller.UnRestrictedBaseController; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.changeManagement.*; +import org.onap.vid.changeManagement.ChangeManagementRequest; +import org.onap.vid.changeManagement.GetVnfWorkflowRelationRequest; +import org.onap.vid.changeManagement.GetWorkflowsResponse; +import org.onap.vid.changeManagement.VnfWorkflowRelationAllResponse; +import org.onap.vid.changeManagement.VnfWorkflowRelationRequest; +import org.onap.vid.changeManagement.VnfWorkflowRelationResponse; import org.onap.vid.exceptions.NotFoundException; import org.onap.vid.model.ExceptionResponse; import org.onap.vid.model.MsoExceptionResponse; @@ -18,17 +54,18 @@ import org.onap.vid.services.WorkflowService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.WebApplicationException; -import java.util.Collection; -import java.util.Collections; - -import static org.onap.vid.utils.Logging.getMethodName; -import static org.springframework.http.HttpStatus.*; - /** * Controller to handle ChangeManagement feature requests. */ @@ -68,8 +105,7 @@ public class ChangeManagementController extends UnRestrictedBaseController { } @RequestMapping(value = "/workflow/{vnfName}", method = RequestMethod.POST) - public ResponseEntity<String> changeManagement(@PathVariable("vnfName") String vnfName, - HttpServletRequest request, + public ResponseEntity<String> changeManagement(HttpServletRequest request, @PathVariable("vnfName") String vnfName, @RequestBody ChangeManagementRequest changeManagmentRequest) throws Exception { return this.changeManagementService.doChangeManagement(changeManagmentRequest, vnfName); diff --git a/vid-app-common/src/main/java/org/onap/vid/model/CategoryParameter.java b/vid-app-common/src/main/java/org/onap/vid/model/CategoryParameter.java index 91617ff42..85caac424 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/CategoryParameter.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/CategoryParameter.java @@ -22,6 +22,7 @@ package org.onap.vid.model; * ============LICENSE_END========================================================= */ +import java.util.Collections; import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -82,7 +83,7 @@ public class CategoryParameter extends VidBaseEntity { @OneToMany(fetch = FetchType.EAGER, mappedBy = "categoryParameter") public Set<CategoryParameterOption> getOptions() { - return options; + return Collections.unmodifiableSet(options); } public void setOptions(Set<CategoryParameterOption> options) { diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index c5bee2448..acdf0afb5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -235,8 +235,7 @@ public class AaiServiceImpl implements AaiService { resultList.add(getServicesByProjectNames(projects, roleValidator)); } if (!resultList.isEmpty()) { - Intersection<ServiceInstanceSearchResult> intersection = new Intersection<>(); - serviceInstancesSearchResults.serviceInstances = intersection.intersectMultipileArray(resultList); + serviceInstancesSearchResults.serviceInstances = Intersection.of(resultList); } return new AaiResponse<>(serviceInstancesSearchResults, null, HttpStatus.SC_OK); diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Intersection.java b/vid-app-common/src/main/java/org/onap/vid/utils/Intersection.java index 6e0d1fc25..ed1be5c76 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Intersection.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Intersection.java @@ -1,31 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. All rights reserved. + * ================================================================================ + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.onap.vid.utils; -import java.util.List; -import java.util.stream.Collectors; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; -/** - * Created by moriya1 on 10/10/2017. - */ -public class Intersection<T> { - public List<T> intersectMultipileArray(List<List<T>> lists) { - if (lists.size() == 1) { - return lists.get(0); - } else { - List<T> intersectResult = intersectTwoArrays(lists.get(0),lists.get(1)); +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; - lists.remove(0); - lists.remove(0); - lists.add(0,intersectResult); - return intersectMultipileArray(lists); - } +public class Intersection { + private Intersection() { } - public List<T> intersectTwoArrays(List<T> list1, List<T> list2) { - - List<T> intersect = list1.stream() - .filter(list2::contains) - .collect(Collectors.toList()); - return intersect; + /** + * Returns intersection of given lists. Treats those lists as sets, ignores repetitions. + */ + public static <T> List<T> of(Collection<List<T>> lists) { + return lists + .stream() + .map(elements -> (Set<T>) Sets.newHashSet(elements)) + .reduce(Sets::intersection) + .map(set -> (List<T>) Lists.newArrayList(set)) + .orElse(Collections.emptyList()); } } |