sanity fix after merge of BE code
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / api / ComponentBaseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.api;
22
23 import com.aventstack.extentreports.ExtentTest;
24 import com.aventstack.extentreports.Status;
25 import com.thinkaurelius.titan.core.TitanFactory;
26 import com.thinkaurelius.titan.core.TitanGraph;
27 import com.thinkaurelius.titan.core.TitanVertex;
28 import org.apache.commons.collections.CollectionUtils;
29 import org.apache.commons.io.FileUtils;
30 import org.apache.commons.lang3.tuple.ImmutablePair;
31 import org.apache.commons.lang3.tuple.ImmutableTriple;
32 import org.apache.tinkerpop.gremlin.structure.Direction;
33 import org.apache.tinkerpop.gremlin.structure.Vertex;
34 import org.junit.rules.TestName;
35 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
36 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
37 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
38 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
39 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
40 import org.openecomp.sdc.be.model.*;
41 import org.openecomp.sdc.ci.tests.config.Config;
42 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
43 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
44 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
45 import org.openecomp.sdc.ci.tests.utils.Utils;
46 import org.openecomp.sdc.ci.tests.utils.cassandra.CassandraUtils;
47 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
48 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
49 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
50 import org.openecomp.sdc.ci.tests.utils.rest.*;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53 import org.testng.ITestContext;
54 import org.testng.ITestResult;
55 import org.testng.annotations.*;
56
57 import java.io.File;
58 import java.io.FileNotFoundException;
59 import java.io.IOException;
60 import java.util.*;
61 import java.util.function.Consumer;
62 import java.util.stream.Collectors;
63
64 import static org.testng.AssertJUnit.assertEquals;
65 import static org.testng.AssertJUnit.assertNotNull;
66
67
68
69
70 public abstract class ComponentBaseTest {
71
72 //      private static Logger logger = LoggerFactory.getLogger(ComponentBaseTest.class.getName());
73         protected static Logger logger= LoggerFactory.getLogger(ComponentBaseTest.class);
74         
75
76 //       public ComponentBaseTest(TestName testName, String className) {
77 //       super(testName, className);
78 //       }
79
80         protected static final String REPORT_FOLDER = "." + File.separator + "ExtentReport" + File.separator;
81         private static final String VERSIONS_INFO_FILE_NAME = "versions.info";
82         private static final String REPORT_FILE_NAME = "SDC_CI_Extent_Report.html";
83         protected static TitanGraph titanGraph;
84         public static Config config;
85         protected static ITestContext myContext;
86         
87         
88         
89         /**************** METHODS ****************/
90         public static ExtentTest getExtendTest() {
91                 return ExtentTestManager.getTest();
92         }
93
94         public static enum ComponentOperationEnum {
95                 CREATE_COMPONENT, UPDATE_COMPONENT, GET_COMPONENT, DELETE_COMPONENT, CHANGE_STATE_CHECKIN, CHANGE_STATE_CHECKOUT, CHANGE_STATE_UNDO_CHECKOUT
96         };
97
98         public ComponentBaseTest(TestName name, String name2) {
99                 // TODO Auto-generated constructor stub
100 //              LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
101 //              lc.getLogger("com.thinkaurelius").setLevel(Level.INFO);
102 //              lc.getLogger("com.datastax").setLevel(Level.INFO);
103 //              lc.getLogger("io.netty").setLevel(Level.INFO);
104 //              lc.getLogger("c.d").setLevel(Level.INFO);
105 //              lc.getLogger("o.a.h").setLevel(Level.INFO);
106 //              lc.getLogger("o.o.s.c.t.d.h").setLevel(Level.INFO);
107
108 }
109         
110         public static String getReportFolder() {
111                 return REPORT_FOLDER;
112         }
113
114         @BeforeSuite(alwaysRun = true)
115         public void setupBeforeSuite(ITestContext context) throws Exception {
116                 config = Utils.getConfig();
117                 myContext=context;
118                 ExtentManager.initReporter(getReportFolder(), REPORT_FILE_NAME, context);       
119                 AtomicOperationUtils.createDefaultConsumer(true);
120                 openTitanLogic();
121                 performClean();
122                 
123                 String basePath = FileHandling.getBasePath();
124                 String csarDir = FileHandling.getCreateDirByName("outputCsar");
125                 FileUtils.cleanDirectory(new File(csarDir));
126         }
127         
128         @BeforeMethod(alwaysRun = true)
129         public void setBrowserBeforeTest(java.lang.reflect.Method method, ITestContext context) throws Exception {
130
131
132 //                  String suiteName = ExtentManager.getSuiteName(context);
133 //                      ExtentTestManager.startTest(method.getName());
134 //                      ExtentTestManager.assignCategory(this.getClass());
135
136                 boolean emptyDataProvider = method.getAnnotation(Test.class).dataProvider().isEmpty();
137                 String className = method.getDeclaringClass().getName();
138                 System.out.println(" method.getName() " + method.getName());
139                 if (!method.getName().equals("onboardVNFShotFlow"))  {
140                         System.out.println("ExtentReport instance started from BeforeMethod...");
141                         ExtentTestManager.startTest(method.getName());
142                         ExtentTestManager.assignCategory(this.getClass());
143
144                 } else {
145                         System.out.println("ExtentReport instance started from Test...");
146                 }
147       
148
149         }
150         
151         @AfterMethod(alwaysRun = true)
152         public void quitAfterTest(ITestResult result, ITestContext context) throws Exception {
153
154                 String testName = result.getName();
155                 Throwable throwable = result.getThrowable();
156                 int status = result.getStatus();
157                 
158                 switch(status){
159                 case ITestResult.SUCCESS:                               
160                         getExtendTest().log(Status.PASS, "Test Result : <span class='label success'>Success</span>");
161                         break;
162                                 
163                 case ITestResult.FAILURE:
164                         getExtendTest().log(Status.ERROR, "ERROR - The following exepction occured");
165                         getExtendTest().log(Status.ERROR, result.getThrowable());
166                         getExtendTest().log(Status.FAIL, "<span class='label failure'>Failure</span>");
167                         break;
168                         
169                 case ITestResult.SKIP:
170                         getExtendTest().log(Status.SKIP, "SKIP - The following exepction occured");
171                         break;
172                 default:
173                         break;
174                 }
175
176
177                 ExtentTestManager.endTest();
178         
179                 
180         }
181
182         @AfterClass(alwaysRun = true)
183         public synchronized static void cleanAfterClass() throws Exception{
184
185                 System.out.println("delete components AfterClass");
186                 deleteCreatedComponents(getCatalogAsMap());
187
188         }
189         
190         @AfterSuite(alwaysRun = true)
191         public static void shutdownTitan() throws Exception {
192                 
193                 performClean();
194                 shutdownTitanLogic();
195         }
196
197         protected static void openTitanLogic() throws Exception {
198         
199                 logger.trace(config.toString());
200                 String titanConfigFilePath = config.getTitanPropertiesFile();
201                 titanGraph = TitanFactory.open(titanConfigFilePath);
202                 assertNotNull(titanGraph);
203                 
204         }
205
206
207         protected static void shutdownTitanLogic() {
208                 if (titanGraph.isOpen()) {
209                         titanGraph.close();
210                 }
211                 CassandraUtils.close();
212         }
213
214         
215
216         public void setLog(String fromDataProvider) {
217
218                 String suiteName = ExtentManager.getSuiteName(myContext);
219                 ExtentTestManager.startTest(Thread.currentThread().getStackTrace()[2].getMethodName() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + fromDataProvider);
220                 ExtentTestManager.assignCategory(this.getClass());
221
222         }
223
224         protected static void performClean() throws Exception, FileNotFoundException {
225 //              cleanComponents();
226                 deleteCreatedComponents(getCatalogAsMap());
227                 CassandraUtils.truncateAllKeyspaces();
228         }
229
230         public void verifyErrorCode(RestResponse response, String action, int expectedCode) {
231                 assertNotNull("check response object is not null after " + action, response);
232                 assertNotNull("check error code exists in response after " + action, response.getErrorCode());
233                 assertEquals("Check response code after  + action" + action, expectedCode, response.getErrorCode().intValue());
234         }
235
236         private static void cleanComponents() throws Exception {
237
238                 // Components to delete
239                 List<String> vfResourcesToDelete = new ArrayList<String>();
240                 List<String> nonVfResourcesToDelete = new ArrayList<String>();
241                 List<String> servicesToDelete = new ArrayList<String>();
242                 List<String> productsToDelete = new ArrayList<String>();
243
244                 // Categories to delete
245                 List<ImmutableTriple<String, String, String>> productGroupingsToDelete = new ArrayList<>();
246                 List<ImmutablePair<String, String>> productSubsToDelete = new ArrayList<>();
247                 List<ImmutablePair<String, String>> resourceSubsToDelete = new ArrayList<>();
248                 List<String> productCategoriesToDelete = new ArrayList<>();
249                 List<String> resourceCategoriesToDelete = new ArrayList<String>();
250                 List<String> serviceCategoriesToDelete = new ArrayList<String>();
251
252                 List<String> resourcesNotToDelete = config.getResourcesNotToDelete();
253                 List<String> resourceCategoriesNotToDelete = config.getResourceCategoriesNotToDelete();
254                 List<String> serviceCategoriesNotToDelete = config.getServiceCategoriesNotToDelete();
255
256                 Iterable<TitanVertex> vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName()).vertices();
257                 if (vertices != null) {
258                         Iterator<TitanVertex> iter = vertices.iterator();
259                         while (iter.hasNext()) {
260                                 Vertex vertex = iter.next();
261                                 Boolean isAbstract = vertex.value(GraphPropertiesDictionary.IS_ABSTRACT.getProperty());
262                                 // if (!isAbstract) {
263                                 String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
264                                 String version = vertex.value(GraphPropertiesDictionary.VERSION.getProperty());
265
266                                 if ((resourcesNotToDelete != null && !resourcesNotToDelete.contains(name)) || (version != null && !version.equals("1.0"))) {
267                                         String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
268                                         String resourceType = vertex.value(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty());
269                                         if (name.startsWith("ci")) {
270                                                 if (resourceType.equals(ResourceTypeEnum.VF.name())) {
271                                                         vfResourcesToDelete.add(id);
272                                                 } else {
273                                                         nonVfResourcesToDelete.add(id);
274                                                 }
275                                         }
276                                 } else if ((resourcesNotToDelete != null && !resourcesNotToDelete.contains(name)) || (version != null && version.equals("1.0"))) {
277                                         if ((boolean) vertex.value(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()) == false) {
278                                                 vertex.property(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
279                                         }
280                                 }
281                                 // }
282                         }
283                 }
284                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Service.getName()).vertices();
285                 if (vertices != null) {
286                         Iterator<TitanVertex> iter = vertices.iterator();
287                         while (iter.hasNext()) {
288                                 Vertex vertex = iter.next();
289                                 String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
290                                 String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
291                                 if (name.startsWith("ci")) {
292                                         servicesToDelete.add(id);
293                                 }
294                         }
295                 }
296
297                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices();
298                 if (vertices != null) {
299                         Iterator<TitanVertex> iter = vertices.iterator();
300                         while (iter.hasNext()) {
301                                 Vertex vertex = iter.next();
302                                 String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
303                                 String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
304                                 if (name.startsWith("Ci")) {
305                                         productsToDelete.add(id);
306                                 }
307                         }
308                 }
309
310                 // Getting categories
311
312                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ResourceNewCategory.getName()).vertices();
313                 if (vertices != null) {
314                         Iterator<TitanVertex> iter = vertices.iterator();
315                         while (iter.hasNext()) {
316                                 Vertex category = iter.next();
317                                 String name = category.value(GraphPropertiesDictionary.NAME.getProperty());
318                                 if (!resourceCategoriesNotToDelete.contains(name)) {
319                                         String catId = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
320                                         resourceCategoriesToDelete.add(catId);
321                                         Iterator<Vertex> subs = category.vertices(Direction.OUT, GraphEdgeLabels.SUB_CATEGORY.getProperty());
322                                         while (subs.hasNext()) {
323                                                 Vertex sub = subs.next();
324                                                 String subCatId = sub.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
325                                                 resourceSubsToDelete.add(new ImmutablePair<String, String>(catId, subCatId));
326                                         }
327                                 }
328                         }
329                 }
330
331                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ServiceNewCategory.getName()).vertices();
332                 if (vertices != null) {
333                         Iterator<TitanVertex> iter = vertices.iterator();
334                         while (iter.hasNext()) {
335                                 Vertex category = iter.next();
336                                 String name = category.value(GraphPropertiesDictionary.NAME.getProperty());
337                                 if (!serviceCategoriesNotToDelete.contains(name)) {
338                                         String id = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
339                                         serviceCategoriesToDelete.add(id);
340                                 }
341                         }
342                 }
343
344                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ProductCategory.getName()).vertices();
345                 if (vertices != null) {
346                         Iterator<TitanVertex> iter = vertices.iterator();
347                         while (iter.hasNext()) {
348                                 Vertex category = iter.next();
349                                 String catId = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
350                                 productCategoriesToDelete.add(catId);
351                                 Iterator<Vertex> subs = category.vertices(Direction.OUT, GraphEdgeLabels.SUB_CATEGORY.getProperty());
352                                 while (subs.hasNext()) {
353                                         Vertex sub = subs.next();
354                                         String subCatId = sub.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
355                                         productSubsToDelete.add(new ImmutablePair<String, String>(catId, subCatId));
356                                         Iterator<Vertex> groupings = sub.vertices(Direction.OUT, GraphEdgeLabels.GROUPING.getProperty());
357                                         while (groupings.hasNext()) {
358                                                 Vertex grouping = groupings.next();
359                                                 String groupId = grouping.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
360                                                 productGroupingsToDelete.add(new ImmutableTriple<String, String, String>(catId, subCatId, groupId));
361                                         }
362                                 }
363
364                         }
365                 }
366
367                 titanGraph.tx().commit();
368
369                 String adminId = UserRoleEnum.ADMIN.getUserId();
370                 String productStrategistId = UserRoleEnum.PRODUCT_STRATEGIST1.getUserId();
371
372                 // Component delete
373                 for (String id : productsToDelete) {
374                         RestResponse deleteProduct = ProductRestUtils.deleteProduct(id, productStrategistId);
375
376                 }
377                 for (String id : servicesToDelete) {
378                         RestResponse deleteServiceById = ServiceRestUtils.deleteServiceById(id, adminId);
379
380                 }
381                 for (String id : vfResourcesToDelete) {
382                         RestResponse deleteResource = ResourceRestUtils.deleteResource(id, adminId);
383
384                 }
385
386                 for (String id : nonVfResourcesToDelete) {
387                         RestResponse deleteResource = ResourceRestUtils.deleteResource(id, adminId);
388
389                 }
390
391                 // Categories delete - product
392                 String componentType = BaseRestUtils.PRODUCT_COMPONENT_TYPE;
393                 for (ImmutableTriple<String, String, String> triple : productGroupingsToDelete) {
394                         CategoryRestUtils.deleteGrouping(triple.getRight(), triple.getMiddle(), triple.getLeft(), productStrategistId, componentType);
395                 }
396                 for (ImmutablePair<String, String> pair : productSubsToDelete) {
397                         CategoryRestUtils.deleteSubCategory(pair.getRight(), pair.getLeft(), productStrategistId, componentType);
398                 }
399                 for (String id : productCategoriesToDelete) {
400                         CategoryRestUtils.deleteCategory(id, productStrategistId, componentType);
401                 }
402
403                 // Categories delete - resource
404                 componentType = BaseRestUtils.RESOURCE_COMPONENT_TYPE;
405                 for (ImmutablePair<String, String> pair : resourceSubsToDelete) {
406                         CategoryRestUtils.deleteSubCategory(pair.getRight(), pair.getLeft(), adminId, componentType);
407                 }
408                 for (String id : resourceCategoriesToDelete) {
409                         CategoryRestUtils.deleteCategory(id, adminId, componentType);
410                 }
411                 // Categories delete - resource
412                 componentType = BaseRestUtils.SERVICE_COMPONENT_TYPE;
413                 for (String id : serviceCategoriesToDelete) {
414                         CategoryRestUtils.deleteCategory(id, adminId, componentType);
415                 }
416
417         }
418
419         private static void deleteCreatedComponents(Map<String, List<Component>> convertCatalogResponseToJavaObject) throws IOException {
420                 final String userId = UserRoleEnum.DESIGNER.getUserId();
421                 
422                 List<Component> resourcesArrayList = convertCatalogResponseToJavaObject.get(ComponentTypeEnum.PRODUCT_PARAM_NAME);
423                 if (resourcesArrayList.size() > 0) {
424                         List<String> collect = buildCollectionUniqueId(resourcesArrayList);
425                         for (String uId : collect) {
426                                 ProductRestUtils.deleteProduct(uId, userId);
427                         }
428                 }
429                 
430                 
431                 resourcesArrayList = convertCatalogResponseToJavaObject.get(ComponentTypeEnum.SERVICE_PARAM_NAME);
432                 if (resourcesArrayList.size() > 0) {
433                         List<String> collect = buildCollectionUniqueId(resourcesArrayList);
434                         for (String uId : collect) {
435                                 ServiceRestUtils.markServiceToDelete(uId, userId);
436                         }
437                         ServiceRestUtils.deleteMarkedServices(userId);
438                 }
439
440                 
441                 resourcesArrayList = convertCatalogResponseToJavaObject.get(ComponentTypeEnum.RESOURCE_PARAM_NAME);
442
443                 // List<String> collect = resourcesArrayList.stream().filter(s ->
444                 // s.getName().startsWith("ci")).map(e ->
445                 // e.getUniqueId()).collect(Collectors.toList());
446
447                 // List<Map<String, String>> collect =
448                 // resourcesArrayList.stream().filter(s ->
449                 // s.getName().startsWith("ci")).map(e ->
450                 // e.getAllVersions()).collect(Collectors.toList());
451                 /*
452                  * List<String> collect = resourcesArrayList.stream().filter(s -> s.getName().startsWith("ci")) .flatMap(e -> e.getAllVersions().values().stream()).collect(Collectors.toList());
453                  */
454
455                 if (!CollectionUtils.isEmpty(resourcesArrayList)) {
456                         List<String> collect = buildCollectionUniqueId(resourcesArrayList);
457                         for (String uId : collect) {
458                                 ResourceRestUtils.markResourceToDelete(uId, userId);
459                         }
460                         ResourceRestUtils.deleteMarkedResources(userId);
461                 }
462
463         
464
465         }
466
467         private void deleteCollection(List<Component> componentArrayList, Consumer<String> deleteHandler) {
468
469                 if (componentArrayList.size() > 0) {
470                         List<String> collect = buildCollectionUniqueId(componentArrayList);
471                         for (String uId : collect) {
472                                 deleteHandler.accept(uId);
473                                 // ProductRestUtils.deleteProduct(uId, userId);
474                         }
475                 }
476         }
477
478         protected static List<String> buildCollectionUniqueId(List<Component> resourcesArrayList) {
479
480                 // Stream<String> flatMap = resourcesArrayList.stream().filter(s ->
481                 // s.getName().startsWith("ci")).map(e -> e.getAllVersions()).map( e ->
482                 // e.values()).flatMap( e -> e.stream());
483
484                 // List<String> collect = resourcesArrayList.stream()
485                 // //
486                 // .filter(s -> s.getName().startsWith("ci") )
487                 // //
488                 // .map(e -> e.getUniqueId())
489
490                 // .map( e -> e.values())
491                 // .filter(out -> out!=null )
492                 // .flatMap( e -> e.stream())
493                 // .collect(Collectors.toList());
494
495                 // List<String> collect = resourcesArrayList.stream().filter(s ->
496                 // s.getName().startsWith("ci"))
497                 // .flatMap(e ->
498                 // e.getAllVersions().values().stream()).collect(Collectors.toList());
499                 ComponentTypeEnum componentTypeEnum = resourcesArrayList.get(0).getComponentType();
500  
501                 List<String> genericCollection = new ArrayList<String>();
502                 
503                 resourcesArrayList.stream().filter(s -> s.getName().toLowerCase().startsWith("ci") && !s.getName().toLowerCase().equals("cindervolume")).map(e -> e.getUniqueId()).collect(Collectors.toList()).forEach((i) -> {
504                         buildCollectionBaseOnComponentType(componentTypeEnum, genericCollection, i);
505                 });
506                 
507         
508                 //
509
510                 // List<String> collect =
511                 // genericCollection.stream().collect(Collectors.toList());
512
513                 return genericCollection;
514         }
515
516         public static void buildCollectionBaseOnComponentType(ComponentTypeEnum componentTypeEnum,
517                         List<String> genericCollection, String i) {
518                 try {
519                         switch (componentTypeEnum) {
520                         case RESOURCE:
521                                 RestResponse resource = ResourceRestUtils.getResource(i);
522                                 Resource convertResourceResponseToJavaObject = ResponseParser.convertResourceResponseToJavaObject(resource.getResponse());
523                                 Map<String, String> allVersions = convertResourceResponseToJavaObject.getAllVersions();
524                                 Collection<String> values = allVersions.values();
525                                 genericCollection.addAll(values);
526                                         
527                                 break;
528                         case SERVICE:
529                                 RestResponse service = ServiceRestUtils.getService(i);
530                                 Service convertServiceResponseToJavaObject = ResponseParser.convertServiceResponseToJavaObject(service.getResponse());
531                                 allVersions = convertServiceResponseToJavaObject.getAllVersions();
532                                 values = allVersions.values();
533                                 genericCollection.addAll(values);
534
535                                 break;
536                                         
537
538                         case PRODUCT:
539                                 RestResponse product = ProductRestUtils.getProduct(i);
540                                 Product convertProductResponseToJavaObject = ResponseParser.convertProductResponseToJavaObject(product.getResponse());
541                                 allVersions = convertProductResponseToJavaObject.getAllVersions();
542                                 values = allVersions.values();
543                                 genericCollection.addAll(values);
544
545                                 break;
546
547                         // default:
548                         // break;
549                         }
550                 } catch (Exception e1) {
551                         // TODO Auto-generated catch block
552                         e1.printStackTrace();
553                 }
554         }
555
556         protected static Map<String, List<Component>> getCatalogAsMap() throws Exception {
557                 RestResponse catalog = CatalogRestUtils.getCatalog(UserRoleEnum.DESIGNER.getUserId());
558                 Map<String, List<Component>> convertCatalogResponseToJavaObject = ResponseParser.convertCatalogResponseToJavaObject(catalog.getResponse());
559                 return convertCatalogResponseToJavaObject;
560         }
561         protected Resource createVfFromCSAR(User sdncModifierDetails, String csarId) throws Exception {
562                 // create new resource from Csar
563                 ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
564
565                 resourceDetails.setCsarUUID(csarId);
566                 resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
567                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
568                 BaseRestUtils.checkCreateResponse(createResource);
569                 Resource createdResource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
570                 return createdResource;
571         }
572         
573
574
575 }