feat:Add instance modification function 79/127979/1 4.0.6
author’zhaoyh6‘ <zhaoyh6@asiainfo.com>
Wed, 23 Mar 2022 01:41:45 +0000 (09:41 +0800)
committer’zhaoyh6‘ <zhaoyh6@asiainfo.com>
Wed, 23 Mar 2022 01:42:40 +0000 (09:42 +0800)
Issue-ID: REQ-1075
Signed-off-by: ’zhaoyh6‘ <zhaoyh6@asiainfo.com>
Change-Id: I60151668dd67a2325b34f0c2a57df14993be84ad

server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java
server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java
server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java
server/src/test/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImplTest.java

index f63f9d9..b8d63f4 100644 (file)
@@ -449,6 +449,29 @@ public class IntentController {
         }
     }
 
+    @IntentResponseBody
+    @ResponseBody
+    @PostMapping(value = {"/updateCCVPNInstance"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+            produces = "application/json; charset=utf-8")
+    public Object updateCCVPNInstance(@RequestBody Object body) throws IOException {
+        String intentInstanceId = MapUtils.getString((Map)body,"instanceId");
+        int accessPointOneBandWidth = MapUtils.getIntValue((Map)body,"bandwidth");
+
+        CCVPNInstance instance = new CCVPNInstance();
+        instance.setInstanceId(intentInstanceId);
+        instance.setAccessPointOneBandWidth(accessPointOneBandWidth);
+
+        int flag = intentInstanceService.updateCCVPNInstance(instance);
+
+        if(flag == 1) {
+            return "OK";
+        }
+        else {
+            throw new RuntimeException("create Instance error");
+        }
+    }
+
+
     @IntentResponseBody
     @GetMapping(value = {"/getFinishedInstanceInfo"},
             produces = "application/json")
index cb922e7..d0595ce 100644 (file)
@@ -63,4 +63,6 @@ public interface IntentInstanceService {
     Page<IntentInstance> getIntentInstanceList(int currentPage, int pageSize);
 
     ServiceResult createSlicingServiceWithIntent(Object slicingOrderBody);
+
+    int updateCCVPNInstance(CCVPNInstance instance);
 }
index c54e591..b62f3aa 100644 (file)
@@ -856,6 +856,37 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
         return serviceResult;
     }
 
+    @Override
+    public int updateCCVPNInstance(CCVPNInstance instance) {
+        Session session = getSession();
+        Transaction tx = null;
+        try{
+            if (null == instance){
+                logger.error("instance is null!");
+                return 0;
+            }
+            instance.setResourceInstanceId("cll-"+instance.getInstanceId());
+
+            CCVPNInstance ccvpnInstance = (CCVPNInstance)session.createQuery("from CCVPNInstance where instanceId = :instanceId")
+                    .setParameter("instanceId", instance.getInstanceId()).uniqueResult();
+            ccvpnInstance.setAccessPointOneBandWidth(instance.getAccessPointOneBandWidth());
+            saveIntentInstanceToAAI(IntentConstant.INTENT_INSTANCE_ID_PREFIX + "-" + ccvpnInstance.getInstanceId(), ccvpnInstance);
+
+            tx = session.beginTransaction();
+            session.update(ccvpnInstance);
+            tx.commit();
+            return 1;
+        } catch (Exception e) {
+            if (tx != null) {
+                tx.rollback();
+            }
+            logger.error("Details:" + e.getMessage());
+            return 0;
+        } finally {
+            session.close();
+        }
+    }
+
     public int getIntentInstanceAllCount() {
         Session session = getSession();
         try{
@@ -917,7 +948,7 @@ public class IntentInstanceServiceImpl implements IntentInstanceService {
         params.put("service-instance-id", serviceInstanceId);
         params.put("service-instance-name", instance.getName());
         params.put("service-type", IntentConstant.MODEL_TYPE_CCVPN);
-        params.put("environment-context", environmentContext);
+        params.put("environment-context", environmentContext.toJSONString());
         params.put("service-instance-location-id", instance.getResourceInstanceId());
         params.put("bandwidth-total", instance.getAccessPointOneBandWidth());
         params.put("data-owner", IntentConstant.INTENT_INSTANCE_DATA_OWNER);
index 90353d4..7fb9eb5 100644 (file)
@@ -987,4 +987,29 @@ public class IntentInstanceServiceImplTest {
         when(session.createQuery("select count(*) from IntentInstance")).thenThrow(new RuntimeException());
         assertEquals(intentInstanceService.getIntentInstanceAllCount(),-1);
     }
+
+    @Test
+    public void updateCCVPNInstanceTest() throws IOException {
+        CCVPNInstance instance = new CCVPNInstance();
+        instance.setInstanceId("1");
+        instance.setAccessPointOneBandWidth(1);
+
+        CCVPNInstance ccvpnInstance = new CCVPNInstance();
+        ccvpnInstance.setInstanceId(instance.getInstanceId());
+
+        Query query = mock(Query.class);
+        when(session.createQuery("from CCVPNInstance where instanceId = :instanceId")).thenReturn(query);
+        when(query.setParameter(anyString(), anyString())).thenReturn(query);
+        when(query.uniqueResult()).thenReturn(ccvpnInstance);
+
+        IntentInstanceServiceImpl spy = PowerMockito.spy(intentInstanceService);
+        doNothing().when(spy).saveIntentInstanceToAAI(anyString(),any(CCVPNInstance.class));
+
+        Transaction tx = Mockito.mock(Transaction.class);
+        Mockito.when(session.beginTransaction()).thenReturn(tx);
+        doNothing().when(session).update(ccvpnInstance);
+        Mockito.doNothing().when(tx).commit();
+
+        assertEquals(spy.updateCCVPNInstance(instance), 1);
+    }
 }
\ No newline at end of file