aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolasLaplaud <nicolas.laplaud@orange.com>2018-07-10 11:40:24 +0200
committerNicolasLaplaud <nicolas.laplaud@orange.com>2018-07-10 11:45:08 +0200
commiteab71985d99a7eaf2003ac97245fef2c9bc1ad87 (patch)
tree7a087444f275ddb2cfdf789fdd59b25e51d4c2c2
parent7f3ac1ec967c0768c3807c1d980e4b6b658d7ec0 (diff)
HUB Resource
- adding AOP pointcut to intercept event around ServiceOrderService Change-Id: I4c4036ad6f2020c6015a7b2005fe92c745e592e5 Issue-ID: EXTAPI-96 Signed-off-by: NicolasLaplaud <nicolas.laplaud@orange.com>
-rw-r--r--pom.xml5
-rw-r--r--src/main/java/org/onap/nbi/apis/hub/MyAspect.java59
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java20
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java20
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java2
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java9
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java25
7 files changed, 91 insertions, 49 deletions
diff --git a/pom.xml b/pom.xml
index d7b2401..ac83f88 100644
--- a/pom.xml
+++ b/pom.xml
@@ -123,6 +123,11 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-aop</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
diff --git a/src/main/java/org/onap/nbi/apis/hub/MyAspect.java b/src/main/java/org/onap/nbi/apis/hub/MyAspect.java
new file mode 100644
index 0000000..3f0f99b
--- /dev/null
+++ b/src/main/java/org/onap/nbi/apis/hub/MyAspect.java
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2018 Orange
+ *
+ * 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.
+ */
+package org.onap.nbi.apis.hub;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.AfterReturning;
+import org.aspectj.lang.annotation.Aspect;
+import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
+import org.onap.nbi.apis.serviceorder.model.StateType;
+import org.springframework.beans.factory.annotation.Configurable;
+import org.springframework.stereotype.Component;
+
+@Aspect
+@Component
+@Configurable
+public class MyAspect {
+
+ @AfterReturning(value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService" +
+ ".createServiceOrder(..))", returning = "serviceOrderCreated")
+ public void whenCreateServiceOrder(ServiceOrder serviceOrderCreated) {
+ if(StateType.ACKNOWLEDGED.equals(serviceOrderCreated.getState())) {
+ // Notif createServiceOrder
+ }
+ }
+
+ @AfterReturning(value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService" +
+ ".updateOrderState(..))", returning = "serviceOrderUpdated")
+ public void whenUpdateServiceOrderState(ServiceOrder serviceOrderUpdated) {
+ if(StateType.COMPLETED.equals(serviceOrderUpdated.getState())||
+ StateType.FAILED.equals(serviceOrderUpdated.getState())) {
+ // Notif updateServiceOrder
+ }
+ }
+
+ @AfterReturning(value = "execution(* org.onap.nbi.apis.serviceorder.service.ServiceOrderService" +
+ ".updateOrderItemState(..))")
+ public void whenUpdateServiceOrderItemState(JoinPoint joinPoint) {
+ Object[] signatureArgs = joinPoint.getArgs();
+
+ if(signatureArgs != null && signatureArgs.length == 3) {
+ StateType serviceOrderItemState = (StateType) signatureArgs[2];
+ // Notif updateServiceOrderItem
+
+ }
+ }
+}
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java
index ca01af9..d439306 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java
@@ -15,8 +15,6 @@
*/
package org.onap.nbi.apis.serviceorder;
-import java.util.List;
-import javax.validation.Valid;
import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
import org.onap.nbi.apis.serviceorder.model.StateType;
import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
@@ -38,14 +36,10 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.Errors;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.List;
@RestController
@RequestMapping("/serviceOrder")
@@ -122,7 +116,7 @@ public class ServiceOrderResource extends ResourceManagement {
throw new ValidationException(errors.getAllErrors());
}
- ServiceOrder serviceOrderSaved =serviceOrderService.updateOrderAndItemStateToAcknowledged(serviceOrder);
+ ServiceOrder serviceOrderSaved =serviceOrderService.createServiceOrder(serviceOrder);
serviceOrderService.updateOrderHref(serviceOrderSaved);
JsonRepresentation filter = new JsonRepresentation(params);
return this.createResponse(serviceOrderSaved, filter);
@@ -135,9 +129,9 @@ public class ServiceOrderResource extends ResourceManagement {
for (ServiceOrder serviceOrder : acknowledgedOrders) {
ServiceOrderInfo serviceOrderInfo = checkOrderConsistenceManager.checkServiceOrder(serviceOrder);
if (serviceOrderInfo.isServiceOrderRejected()) {
- serviceOrderService.updateOrderFinalState(serviceOrder, StateType.REJECTED);
+ serviceOrderService.updateOrderState(serviceOrder, StateType.REJECTED);
} else if (serviceOrderInfo.isAllItemsCompleted()) {
- serviceOrderService.updateOrderFinalState(serviceOrder, StateType.COMPLETED);
+ serviceOrderService.updateOrderState(serviceOrder, StateType.COMPLETED);
} else {
createAAICustomer.createAAICustomer(serviceOrder,serviceOrderInfo);
if(StateType.ACKNOWLEDGED==serviceOrder.getState()) {
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java
index 8f9cff1..14b864a 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java
@@ -15,8 +15,6 @@
*/
package org.onap.nbi.apis.serviceorder.service;
-import java.util.Date;
-import java.util.List;
import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
import org.onap.nbi.apis.serviceorder.model.StateType;
@@ -24,6 +22,9 @@ import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.util.Date;
+import java.util.List;
+
@Service
public class ServiceOrderService {
@@ -38,15 +39,12 @@ public class ServiceOrderService {
return serviceOrderRepository.findByState(state);
}
- public void updateOrderState(ServiceOrder serviceOrder,StateType state){
- serviceOrder.setState(state);
- serviceOrderRepository.save(serviceOrder);
- }
-
- public void updateOrderFinalState(ServiceOrder serviceOrder,StateType state){
+ public ServiceOrder updateOrderState(ServiceOrder serviceOrder,StateType state){
+ if(StateType.COMPLETED.equals(state) || StateType.REJECTED.equals(state)) {
+ serviceOrder.setCompletionDateTime(new Date());
+ }
serviceOrder.setState(state);
- serviceOrder.setCompletionDateTime(new Date());
- serviceOrderRepository.save(serviceOrder);
+ return serviceOrderRepository.save(serviceOrder);
}
public void updateOrderItemState(ServiceOrder serviceOrder,ServiceOrderItem serviceOrderItem, StateType state){
@@ -54,7 +52,7 @@ public class ServiceOrderService {
serviceOrderRepository.save(serviceOrder);
}
- public ServiceOrder updateOrderAndItemStateToAcknowledged(ServiceOrder serviceOrder){
+ public ServiceOrder createServiceOrder(ServiceOrder serviceOrder){
serviceOrder.setState(StateType.ACKNOWLEDGED);
serviceOrder.setOrderDate(new Date());
for (ServiceOrderItem serviceOrderItem : serviceOrder.getOrderItem()) {
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java
index 69bbd83..aacf48c 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java
@@ -45,7 +45,7 @@ public class CreateAAICustomerManager {
boolean customerCreated = serviceOrderConsumerService.putCustomer(serviceOrderInfo.getSubscriberInfo());
if (!customerCreated) {
- serviceOrderService.updateOrderFinalState(serviceOrder,StateType.REJECTED);
+ serviceOrderService.updateOrderState(serviceOrder,StateType.REJECTED);
LOGGER.warn("serviceOrder {} rejected : cannot create customer", serviceOrder.getId());
}
}
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java
index 7f150fe..0da0355 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java
@@ -12,9 +12,6 @@
*/
package org.onap.nbi.apis.serviceorder.workflow;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
import org.onap.nbi.apis.serviceorder.MultiClient;
import org.onap.nbi.apis.serviceorder.model.ActionType;
import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
@@ -28,6 +25,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
@Service
public class CreateAAIServiceTypeManager {
@@ -53,7 +54,7 @@ public class CreateAAIServiceTypeManager {
boolean serviceCreated = serviceOrderConsumerService.putServiceType(
serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), sdcServiceName);
if (!serviceCreated) {
- serviceOrderService.updateOrderFinalState(serviceOrder,StateType.REJECTED);
+ serviceOrderService.updateOrderState(serviceOrder,StateType.REJECTED);
LOGGER.warn("serviceOrder {} rejected : cannot create service type {} for customer {}",
serviceOrder.getId(), sdcServiceName,
serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId());
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
index def4fe0..1957e5b 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
@@ -12,30 +12,12 @@
*/
package org.onap.nbi.apis.serviceorder.workflow;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
import org.onap.nbi.apis.serviceorder.SoClient;
import org.onap.nbi.apis.serviceorder.model.ServiceCharacteristic;
import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
import org.onap.nbi.apis.serviceorder.model.StateType;
-import org.onap.nbi.apis.serviceorder.model.consumer.CloudConfiguration;
-import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse;
-import org.onap.nbi.apis.serviceorder.model.consumer.GetRequestStatusResponse;
-import org.onap.nbi.apis.serviceorder.model.consumer.MSOPayload;
-import org.onap.nbi.apis.serviceorder.model.consumer.ModelInfo;
-import org.onap.nbi.apis.serviceorder.model.consumer.OwningEntity;
-import org.onap.nbi.apis.serviceorder.model.consumer.Project;
-import org.onap.nbi.apis.serviceorder.model.consumer.RequestDetails;
-import org.onap.nbi.apis.serviceorder.model.consumer.RequestInfo;
-import org.onap.nbi.apis.serviceorder.model.consumer.RequestParameters;
-import org.onap.nbi.apis.serviceorder.model.consumer.RequestState;
-import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo;
-import org.onap.nbi.apis.serviceorder.model.consumer.UserParams;
+import org.onap.nbi.apis.serviceorder.model.consumer.*;
import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
import org.onap.nbi.apis.serviceorder.repositories.ExecutionTaskRepository;
@@ -50,6 +32,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
+import java.io.IOException;
+import java.util.*;
+
@Service
public class SOTaskProcessor {
@@ -216,7 +201,7 @@ public class SOTaskProcessor {
} else {
finalState=StateType.COMPLETED;
}
- serviceOrderService.updateOrderFinalState(serviceOrder,finalState);
+ serviceOrderService.updateOrderState(serviceOrder,finalState);
}
}