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