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