Update aai-schema-ingest dependency in the schema-service
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / genxsd / YAMLfromOXMTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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.onap.aai.schemagen.genxsd;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertThat;
26 import static org.junit.Assert.assertTrue;
27
28 import com.google.common.collect.Multimap;
29
30 import java.io.BufferedWriter;
31 import java.io.File;
32 import java.io.FileWriter;
33 import java.io.IOException;
34 import java.nio.charset.Charset;
35 import java.nio.file.Files;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.util.SortedSet;
39 import java.util.TreeSet;
40
41 import org.junit.Before;
42 import org.junit.BeforeClass;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.onap.aai.edges.EdgeIngestor;
46 import org.onap.aai.edges.EdgeRule;
47 import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
48 import org.onap.aai.nodes.NodeIngestor;
49 import org.onap.aai.schemagen.SwaggerGenerationConfiguration;
50 import org.onap.aai.schemagen.testutils.TestUtilConfigTranslatorforBusiness;
51 import org.onap.aai.setup.SchemaConfigVersions;
52 import org.onap.aai.setup.SchemaLocationsBean;
53 import org.onap.aai.setup.SchemaVersion;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.springframework.beans.factory.annotation.Autowired;
57 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
58 import org.springframework.test.context.ContextConfiguration;
59 import org.springframework.test.context.TestPropertySource;
60 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
61 import org.w3c.dom.Document;
62 import org.w3c.dom.Element;
63
64 @RunWith(SpringJUnit4ClassRunner.class)
65 @ContextConfiguration(
66     classes = {SchemaConfigVersions.class, SchemaLocationsBean.class,
67         TestUtilConfigTranslatorforBusiness.class, EdgeIngestor.class, NodeIngestor.class,
68         SwaggerGenerationConfiguration.class
69
70     })
71 @TestPropertySource(properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000"})
72 public class YAMLfromOXMTest {
73     @Autowired
74     EdgeIngestor edgeIngestor;
75
76     @Autowired
77     NodeIngestor nodeIngestor;
78     private static final Logger logger = LoggerFactory.getLogger("YAMLfromOXMTest.class");
79     private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml";
80     private static final String EDGEFILENAME =
81         "src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json";
82     public static AnnotationConfigApplicationContext ctx = null;
83     private static String testXML;
84     protected static final String SERVICE_NAME = "JUNIT";
85     boolean first = true;
86
87     @Autowired
88     YAMLfromOXM yamlFromOxm;
89
90     @Autowired
91     SchemaConfigVersions schemaConfigVersions;
92
93     @BeforeClass
94     public static void setUpBeforeClass() throws Exception {
95         System.setProperty("AJSC_HOME", ".");
96         System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
97         System.setProperty("aai.service.name", SERVICE_NAME);
98     }
99
100     @Before
101     public void setUp() throws Exception {
102         XSDElementTest x = new XSDElementTest();
103         x.setUp();
104         testXML = x.testXML;
105         logger.debug(testXML);
106         BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
107         bw.write(testXML);
108         bw.close();
109         BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
110         bw1.write(EdgeDefs());
111         bw1.close();
112     }
113
114     public void setupRelationship() throws Exception {
115         XSDElementTest x = new XSDElementTest();
116
117         x.setUpRelationship();
118
119         testXML = x.testXML;
120         logger.debug(testXML);
121         BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
122
123         bw.write(testXML);
124
125         bw.close();
126         BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
127         bw1.write(EdgeDefs());
128         bw1.close();
129     }
130
131     @Test
132     public void AtestIngestors() throws EdgeRuleNotFoundException {
133         Multimap<String, EdgeRule> results =
134             edgeIngestor.getAllRules(schemaConfigVersions.getDefaultVersion());
135         SortedSet<String> ss = new TreeSet<String>(results.keySet());
136         for (String key : ss) {
137             results.get(key).stream().filter((i) -> ((!i.isPrivateEdge()))).forEach((i) -> {
138                 EdgeDescription ed = new EdgeDescription(i);
139                 System.out.println(ed.getRuleKey());
140             });
141         }
142         Document doc = nodeIngestor.getSchema(schemaConfigVersions.getDefaultVersion());
143         assertNotNull(doc);
144     }
145
146     @Test
147     public void testGetDocumentHeader() {
148         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
149         String apiVersion = v.toString();
150         String header = null;
151         try {
152             yamlFromOxm.setXmlVersion(testXML, v);
153             yamlFromOxm.process();
154             header = yamlFromOxm.getDocumentHeader();
155         } catch (Exception e) {
156             e.printStackTrace();
157         }
158         assertThat("Header:\n" + header, header, is(YAMLheader()));
159     }
160
161     @Test
162     public void testProcess() {
163         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
164         String apiVersion = v.toString();
165         String fileContent = null;
166         try {
167             yamlFromOxm.setXmlVersion(testXML, v);
168             fileContent = yamlFromOxm.process();
169         } catch (Exception e) {
170             e.printStackTrace();
171         }
172         assertThat("FileContent-TestProcess:\n" + fileContent, fileContent, is(YAMLresult()));
173     }
174
175     @Test
176     public void testYAMLfromOXMFileVersionFile() throws IOException {
177         String outfileName = "testXML.xml";
178         File XMLfile = new File(outfileName);
179         XMLfile.createNewFile();
180         BufferedWriter bw = null;
181         Charset charset = Charset.forName("UTF-8");
182         Path path = Paths.get(outfileName);
183         bw = Files.newBufferedWriter(path, charset);
184         bw.write(testXML);
185         bw.close();
186         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
187         String apiVersion = v.toString();
188         String fileContent = null;
189         try {
190             yamlFromOxm.setXmlVersion(testXML, v);
191             fileContent = yamlFromOxm.process();
192         } catch (Exception e) {
193             e.printStackTrace();
194         }
195         XMLfile.delete();
196         assertThat("FileContent-OXMFileVersionFile:\n" + fileContent, fileContent,
197             is(YAMLresult()));
198     }
199
200     @Test
201     public void testYAMLfromOXMStringVersionFile() {
202         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
203         String apiVersion = v.toString();
204         String fileContent = null;
205         try {
206             yamlFromOxm.setXmlVersion(testXML, v);
207             fileContent = yamlFromOxm.process();
208         } catch (Exception e) {
209             e.printStackTrace();
210         }
211         assertThat("FileContent-OXMStringVersionFile:\n" + fileContent, fileContent,
212             is(YAMLresult()));
213     }
214
215     @Test
216     public void testRelationshipListYAMLfromOXMStringVersionFile() {
217         try {
218             setupRelationship();
219         } catch (Exception e1) {
220             // TODO Auto-generated catch block
221             e1.printStackTrace();
222         }
223         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
224         String apiVersion = v.toString();
225         String fileContent = null;
226         try {
227             yamlFromOxm.setXmlVersion(testXML, v);
228             fileContent = yamlFromOxm.process();
229         } catch (Exception e) {
230             e.printStackTrace();
231         }
232         boolean matchFound = fileContent.contains((YAMLRelationshipList()));
233         assertTrue("RelationshipListFormat:\n", matchFound);
234     }
235
236     @Test
237     public void testAppendDefinitions() {
238         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
239         String apiVersion = v.toString();
240         String definitions = null;
241         try {
242             yamlFromOxm.setXmlVersion(testXML, v);
243             yamlFromOxm.process();
244             definitions = yamlFromOxm.appendDefinitions();
245         } catch (Exception e) {
246             e.printStackTrace();
247         }
248         assertThat("Definitions:\n" + definitions, definitions,
249             is(YAMLdefs() + YAMLdefsAddPatch()));
250     }
251
252     @Test
253     public void testGetXMLRootElementName() {
254         String target = "RootElement=customer";
255         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
256         String apiVersion = v.toString();
257         Element customer = null;
258         String root = null;
259         try {
260             yamlFromOxm.setXmlVersion(testXML, v);
261             yamlFromOxm.process();
262             customer = yamlFromOxm.getJavaTypeElementSwagger("Customer");
263             root = yamlFromOxm.getXMLRootElementName(customer);
264         } catch (Exception e) {
265             e.printStackTrace();
266         }
267         assertThat("RootElement=" + root, is(target));
268     }
269
270     @Test
271     public void testGetXmlRootElementName() {
272         String target = "RootElement=customer";
273         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
274         String apiVersion = v.toString();
275         String root = null;
276         try {
277             yamlFromOxm.setXmlVersion(testXML, v);
278             yamlFromOxm.process();
279             root = yamlFromOxm.getXmlRootElementName("Customer");
280         } catch (Exception e) {
281             e.printStackTrace();
282         }
283         assertThat("RootElement=" + root, is(target));
284     }
285
286     @Test
287     public void testGetJavaTypeElementSwagger() {
288         String target = "Element=java-type/Customer";
289         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
290         String apiVersion = v.toString();
291         Element customer = null;
292         try {
293             yamlFromOxm.setXmlVersion(testXML, v);
294             yamlFromOxm.process();
295             customer = yamlFromOxm.getJavaTypeElementSwagger("Customer");
296         } catch (Exception e) {
297             e.printStackTrace();
298         }
299         assertThat("Element=" + customer.getNodeName() + "/" + customer.getAttribute("name"),
300             is(target));
301     }
302
303     public String YAMLresult() {
304         StringBuilder sb = new StringBuilder(32368);
305         sb.append(YAMLheader());
306         sb.append(YAMLops());
307         sb.append(YAMLdefs());
308         sb.append(YAMLdefsAddPatch());
309         return sb.toString();
310     }
311
312     public String YAMLheader() {
313         StringBuilder sb = new StringBuilder(1500);
314         sb.append("swagger: \"2.0\"\n");
315         sb.append("info:" + OxmFileProcessor.LINE_SEPARATOR);
316         sb.append("  description: |\n");
317         sb.append("\n");
318         sb.append(
319             "    [Differences versus the previous schema version](apidocs/aai/aai_swagger_v11.diff)"
320                 + OxmFileProcessor.DOUBLE_LINE_SEPARATOR);
321         sb.append(
322             "    Copyright &copy; 2017-18 AT&amp;T Intellectual Property. All rights reserved."
323                 + OxmFileProcessor.DOUBLE_LINE_SEPARATOR);
324         sb.append(
325             "    Licensed under the Creative Commons License, Attribution 4.0 Intl. (the &quot;License&quot;); you may not use this documentation except in compliance with the License."
326                 + OxmFileProcessor.DOUBLE_LINE_SEPARATOR);
327         sb.append("    You may obtain a copy of the License at\n");
328         sb.append("\n");
329         sb.append("    (https://creativecommons.org/licenses/by/4.0/)"
330             + OxmFileProcessor.DOUBLE_LINE_SEPARATOR);
331         sb.append(
332             "    Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
333                 + OxmFileProcessor.DOUBLE_LINE_SEPARATOR);
334         sb.append(
335             "    This document is best viewed with Firefox or Chrome. Nodes can be found by opening the models link below and finding the node-type. Edge definitions can be found with the node definitions."
336                 + OxmFileProcessor.LINE_SEPARATOR);
337         sb.append("  version: \"v11\"" + OxmFileProcessor.LINE_SEPARATOR);
338         sb.append(
339             "  title: Active and Available Inventory REST API" + OxmFileProcessor.LINE_SEPARATOR);
340         sb.append("  license:" + OxmFileProcessor.LINE_SEPARATOR);
341         sb.append("    name: Apache 2.0\n");
342         sb.append("    url: http://www.apache.org/licenses/LICENSE-2.0.html"
343             + OxmFileProcessor.LINE_SEPARATOR);
344         sb.append("  contact:" + OxmFileProcessor.LINE_SEPARATOR);
345         sb.append("    name: n/a" + OxmFileProcessor.LINE_SEPARATOR);
346         sb.append("    url: n/a" + OxmFileProcessor.LINE_SEPARATOR);
347         sb.append("    email: n/a" + OxmFileProcessor.LINE_SEPARATOR);
348         sb.append("host: n/a" + OxmFileProcessor.LINE_SEPARATOR);
349         sb.append("basePath: /aai/v11" + OxmFileProcessor.LINE_SEPARATOR);
350         sb.append("schemes:" + OxmFileProcessor.LINE_SEPARATOR);
351         sb.append("  - https\n");
352         sb.append("paths:" + OxmFileProcessor.LINE_SEPARATOR);
353         return sb.toString();
354     }
355
356     public String YAMLops() {
357         StringBuilder sb = new StringBuilder(16384);
358         sb.append(
359             "  /business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}:\n");
360         sb.append("    get:\n");
361         sb.append("      tags:\n");
362         sb.append("        - Business\n");
363         sb.append("      summary: returns service-subscription\n");
364         sb.append("      description: returns service-subscription\n");
365         sb.append(
366             "      operationId: getBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
367         sb.append("      produces:\n");
368         sb.append("        - application/json\n");
369         sb.append("        - application/xml\n");
370         sb.append("      responses:\n");
371         sb.append("        \"200\":\n");
372         sb.append("          description: successful operation\n");
373         sb.append("          schema:\n");
374         sb.append("              $ref: \"#/definitions/service-subscription\"\n");
375         sb.append("        \"default\":\n");
376         sb.append("          null      parameters:\n");
377         sb.append("        - name: global-customer-id\n");
378         sb.append("          in: path\n");
379         sb.append(
380             "          description: Global customer id used across to uniquely identify customer.\n");
381         sb.append("          required: true\n");
382         sb.append("          type: string\n");
383         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
384         sb.append("        - name: service-type\n");
385         sb.append("          in: path\n");
386         sb.append(
387             "          description: Value defined by orchestration to identify this service.\n");
388         sb.append("          required: true\n");
389         sb.append("          type: string\n");
390         sb.append("          example: __SERVICE-TYPE__\n");
391         sb.append("    put:\n");
392         sb.append("      tags:\n");
393         sb.append("        - Business\n");
394         sb.append("      summary: create or update an existing service-subscription\n");
395         sb.append("      description: |\n");
396         sb.append("        Create or update an existing service-subscription.\n");
397         sb.append("        #\n");
398         sb.append(
399             "        Note! This PUT method has a corresponding PATCH method that can be used to update just a few of the fields of an existing object, rather than a full object replacement.  An example can be found in the [PATCH section] below\n");
400         sb.append(
401             "      operationId: createOrUpdateBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
402         sb.append("      consumes:\n");
403         sb.append("        - application/json\n");
404         sb.append("        - application/xml\n");
405         sb.append("      produces:\n");
406         sb.append("        - application/json\n");
407         sb.append("        - application/xml\n");
408         sb.append("      responses:\n");
409         sb.append("        \"default\":\n");
410         sb.append("          null      parameters:\n");
411         sb.append("        - name: global-customer-id\n");
412         sb.append("          in: path\n");
413         sb.append(
414             "          description: Global customer id used across to uniquely identify customer.\n");
415         sb.append("          required: true\n");
416         sb.append("          type: string\n");
417         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
418         sb.append("        - name: service-type\n");
419         sb.append("          in: path\n");
420         sb.append(
421             "          description: Value defined by orchestration to identify this service.\n");
422         sb.append("          required: true\n");
423         sb.append("          type: string\n");
424         sb.append("          example: __SERVICE-TYPE__\n");
425         sb.append("        - name: body\n");
426         sb.append("          in: body\n");
427         sb.append(
428             "          description: service-subscription object that needs to be created or updated. [Valid relationship examples shown here](apidocs/aai/relations/v11/BusinessCustomersCustomerServiceSubscriptionsServiceSubscription.json)\n");
429         sb.append("          required: true\n");
430         sb.append("          schema:\n");
431         sb.append("            $ref: \"#/definitions/service-subscription\"\n");
432         sb.append("    patch:\n");
433         sb.append("      tags:\n");
434         sb.append("        - Business\n");
435         sb.append("      summary: update an existing service-subscription\n");
436         sb.append("      description: |\n");
437         sb.append("        Update an existing service-subscription\n");
438         sb.append("        #\n");
439         sb.append(
440             "        Note:  Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
441         sb.append("        The PUT operation will entirely replace an existing object.\n");
442         sb.append(
443             "        The PATCH operation sends a \"description of changes\" for an existing object.  The entire set of changes must be applied.  An error result means no change occurs.\n");
444         sb.append("        #\n");
445         sb.append("        Other differences between PUT and PATCH are:\n");
446         sb.append("        #\n");
447         sb.append(
448             "        - For PATCH, you can send any of the values shown in sample REQUEST body.  There are no required values.\n");
449         sb.append(
450             "        - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
451         sb.append(
452             "        - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
453         sb.append(
454             "      operationId: UpdateBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
455         sb.append("      consumes:\n");
456         sb.append("        - application/json\n");
457         sb.append("      produces:\n");
458         sb.append("        - application/json\n");
459         sb.append("      responses:\n");
460         sb.append("        \"default\":\n");
461         sb.append("          null      parameters:\n");
462         sb.append("        - name: global-customer-id\n");
463         sb.append("          in: path\n");
464         sb.append(
465             "          description: Global customer id used across to uniquely identify customer.\n");
466         sb.append("          required: true\n");
467         sb.append("          type: string\n");
468         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
469         sb.append("        - name: service-type\n");
470         sb.append("          in: path\n");
471         sb.append(
472             "          description: Value defined by orchestration to identify this service.\n");
473         sb.append("          required: true\n");
474         sb.append("          type: string\n");
475         sb.append("          example: __SERVICE-TYPE__\n");
476         sb.append("        - name: body\n");
477         sb.append("          in: body\n");
478         sb.append("          description: service-subscription object that needs to be updated.");
479         sb.append(
480             "[See Examples](apidocs/aai/relations/v11/BusinessCustomersCustomerServiceSubscriptionsServiceSubscription.json)\n");
481         sb.append("          required: true\n");
482         sb.append("          schema:\n");
483         sb.append("            $ref: \"#/definitions/zzzz-patch-service-subscription\"\n");
484         sb.append("    delete:\n");
485         sb.append("      tags:\n");
486         sb.append("        - Business\n");
487         sb.append("      summary: delete an existing service-subscription\n");
488         sb.append("      description: delete an existing service-subscription\n");
489         sb.append(
490             "      operationId: deleteBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
491         sb.append("      consumes:\n");
492         sb.append("        - application/json\n");
493         sb.append("        - application/xml\n");
494         sb.append("      produces:\n");
495         sb.append("        - application/json\n");
496         sb.append("        - application/xml\n");
497         sb.append("      responses:\n");
498         sb.append("        \"default\":\n");
499         sb.append("          null      parameters:\n");
500         sb.append("        - name: global-customer-id\n");
501         sb.append("          in: path\n");
502         sb.append(
503             "          description: Global customer id used across to uniquely identify customer.\n");
504         sb.append("          required: true\n");
505         sb.append("          type: string\n");
506         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
507         sb.append("        - name: service-type\n");
508         sb.append("          in: path\n");
509         sb.append(
510             "          description: Value defined by orchestration to identify this service.\n");
511         sb.append("          required: true\n");
512         sb.append("          type: string\n");
513         sb.append("          example: __SERVICE-TYPE__\n");
514         sb.append("        - name: resource-version\n");
515         sb.append("          in: query\n");
516         sb.append("          description: resource-version for concurrency\n");
517         sb.append("          required: true\n");
518         sb.append("          type: string\n");
519         sb.append("  /business/customers/customer/{global-customer-id}/service-subscriptions:\n");
520         sb.append("    get:\n");
521         sb.append("      tags:\n");
522         sb.append("        - Business\n");
523         sb.append("      summary: returns service-subscriptions\n");
524         sb.append("      description: returns service-subscriptions\n");
525         sb.append("      operationId: getBusinessCustomersCustomerServiceSubscriptions\n");
526         sb.append("      produces:\n");
527         sb.append("        - application/json\n");
528         sb.append("        - application/xml\n");
529         sb.append("      responses:\n");
530         sb.append("        \"200\":\n");
531         sb.append("          description: successful operation\n");
532         sb.append("          schema:\n");
533         sb.append("              $ref: \"#/definitions/service-subscriptions\"\n");
534         sb.append("        \"default\":\n");
535         sb.append("          null      parameters:\n");
536         sb.append("        - name: global-customer-id\n");
537         sb.append("          in: path\n");
538         sb.append(
539             "          description: Global customer id used across to uniquely identify customer.\n");
540         sb.append("          required: true\n");
541         sb.append("          type: string\n");
542         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
543         sb.append("        - name: service-type\n");
544         sb.append("          in: query\n");
545         sb.append("          description: n/a\n");
546         sb.append("          required: false\n");
547         sb.append("          type: string\n");
548         sb.append("  /business/customers/customer/{global-customer-id}:\n");
549         sb.append("    get:\n");
550         sb.append("      tags:\n");
551         sb.append("        - Business\n");
552         sb.append("      summary: returns customer\n");
553         sb.append("      description: returns customer\n");
554         sb.append("      operationId: getBusinessCustomersCustomer\n");
555         sb.append("      produces:\n");
556         sb.append("        - application/json\n");
557         sb.append("        - application/xml\n");
558         sb.append("      responses:\n");
559         sb.append("        \"200\":\n");
560         sb.append("          description: successful operation\n");
561         sb.append("          schema:\n");
562         sb.append("              $ref: \"#/definitions/customer\"\n");
563         sb.append("        \"default\":\n");
564         sb.append("          null      parameters:\n");
565         sb.append("        - name: global-customer-id\n");
566         sb.append("          in: path\n");
567         sb.append(
568             "          description: Global customer id used across to uniquely identify customer.\n");
569         sb.append("          required: true\n");
570         sb.append("          type: string\n");
571         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
572         sb.append("    put:\n");
573         sb.append("      tags:\n");
574         sb.append("        - Business\n");
575         sb.append("      summary: create or update an existing customer\n");
576         sb.append("      description: |\n");
577         sb.append("        Create or update an existing customer.\n");
578         sb.append("        #\n");
579         sb.append(
580             "        Note! This PUT method has a corresponding PATCH method that can be used to update just a few of the fields of an existing object, rather than a full object replacement.  An example can be found in the [PATCH section] below\n");
581         sb.append("      operationId: createOrUpdateBusinessCustomersCustomer\n");
582         sb.append("      consumes:\n");
583         sb.append("        - application/json\n");
584         sb.append("        - application/xml\n");
585         sb.append("      produces:\n");
586         sb.append("        - application/json\n");
587         sb.append("        - application/xml\n");
588         sb.append("      responses:\n");
589         sb.append("        \"default\":\n");
590         sb.append("          null      parameters:\n");
591         sb.append("        - name: global-customer-id\n");
592         sb.append("          in: path\n");
593         sb.append(
594             "          description: Global customer id used across to uniquely identify customer.\n");
595         sb.append("          required: true\n");
596         sb.append("          type: string\n");
597         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
598         sb.append("        - name: body\n");
599         sb.append("          in: body\n");
600         sb.append(
601             "          description: customer object that needs to be created or updated. [Valid relationship examples shown here](apidocs/aai/relations/v11/BusinessCustomersCustomer.json)\n");
602         sb.append("          required: true\n");
603         sb.append("          schema:\n");
604         sb.append("            $ref: \"#/definitions/customer\"\n");
605         sb.append("    patch:\n");
606         sb.append("      tags:\n");
607         sb.append("        - Business\n");
608         sb.append("      summary: update an existing customer\n");
609         sb.append("      description: |\n");
610         sb.append("        Update an existing customer\n");
611         sb.append("        #\n");
612         sb.append(
613             "        Note:  Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
614         sb.append("        The PUT operation will entirely replace an existing object.\n");
615         sb.append(
616             "        The PATCH operation sends a \"description of changes\" for an existing object.  The entire set of changes must be applied.  An error result means no change occurs.\n");
617         sb.append("        #\n");
618         sb.append("        Other differences between PUT and PATCH are:\n");
619         sb.append("        #\n");
620         sb.append(
621             "        - For PATCH, you can send any of the values shown in sample REQUEST body.  There are no required values.\n");
622         sb.append(
623             "        - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
624         sb.append(
625             "        - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
626         sb.append("      operationId: UpdateBusinessCustomersCustomer\n");
627         sb.append("      consumes:\n");
628         sb.append("        - application/json\n");
629         sb.append("      produces:\n");
630         sb.append("        - application/json\n");
631         sb.append("      responses:\n");
632         sb.append("        \"default\":\n");
633         sb.append("          null      parameters:\n");
634         sb.append("        - name: global-customer-id\n");
635         sb.append("          in: path\n");
636         sb.append(
637             "          description: Global customer id used across to uniquely identify customer.\n");
638         sb.append("          required: true\n");
639         sb.append("          type: string\n");
640         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
641         sb.append("        - name: body\n");
642         sb.append("          in: body\n");
643         sb.append("          description: customer object that needs to be updated.");
644         sb.append("[See Examples](apidocs/aai/relations/v11/BusinessCustomersCustomer.json)\n");
645         sb.append("          required: true\n");
646         sb.append("          schema:\n");
647         sb.append("            $ref: \"#/definitions/zzzz-patch-customer\"\n");
648         sb.append("    delete:\n");
649         sb.append("      tags:\n");
650         sb.append("        - Business\n");
651         sb.append("      summary: delete an existing customer\n");
652         sb.append("      description: delete an existing customer\n");
653         sb.append("      operationId: deleteBusinessCustomersCustomer\n");
654         sb.append("      consumes:\n");
655         sb.append("        - application/json\n");
656         sb.append("        - application/xml\n");
657         sb.append("      produces:\n");
658         sb.append("        - application/json\n");
659         sb.append("        - application/xml\n");
660         sb.append("      responses:\n");
661         sb.append("        \"default\":\n");
662         sb.append("          null      parameters:\n");
663         sb.append("        - name: global-customer-id\n");
664         sb.append("          in: path\n");
665         sb.append(
666             "          description: Global customer id used across to uniquely identify customer.\n");
667         sb.append("          required: true\n");
668         sb.append("          type: string\n");
669         sb.append("          example: __GLOBAL-CUSTOMER-ID__\n");
670         sb.append("        - name: resource-version\n");
671         sb.append("          in: query\n");
672         sb.append("          description: resource-version for concurrency\n");
673         sb.append("          required: true\n");
674         sb.append("          type: string\n");
675         sb.append("  /business/customers:\n");
676         sb.append("    get:\n");
677         sb.append("      tags:\n");
678         sb.append("        - Business\n");
679         sb.append("      summary: returns customers\n");
680         sb.append("      description: returns customers\n");
681         sb.append("      operationId: getBusinessCustomers\n");
682         sb.append("      produces:\n");
683         sb.append("        - application/json\n");
684         sb.append("        - application/xml\n");
685         sb.append("      responses:\n");
686         sb.append("        \"200\":\n");
687         sb.append("          description: successful operation\n");
688         sb.append("          schema:\n");
689         sb.append("              $ref: \"#/definitions/customers\"\n");
690         sb.append("        \"default\":\n");
691         sb.append("          null      parameters:\n");
692         sb.append("        - name: global-customer-id\n");
693         sb.append("          in: query\n");
694         sb.append("          description: n/a\n");
695         sb.append("          required: false\n");
696         sb.append("          type: string\n");
697         sb.append("        - name: subscriber-name\n");
698         sb.append("          in: query\n");
699         sb.append("          description: n/a\n");
700         sb.append("          required: false\n");
701         sb.append("          type: string\n");
702         sb.append("        - name: subscriber-type\n");
703         sb.append("          in: query\n");
704         sb.append("          description: n/a\n");
705         sb.append("          required: false\n");
706         sb.append("          type: string\n");
707         return sb.toString();
708     }
709
710     public String YAMLdefs() {
711         StringBuilder sb = new StringBuilder(8092);
712         sb.append("definitions:\n");
713         sb.append("  business:\n");
714         sb.append("    description: |\n");
715         sb.append("      Namespace for business related constructs\n");
716         sb.append("    properties:\n");
717         sb.append("      customers:\n");
718         sb.append("        type: array\n");
719         sb.append("        items:\n");
720         sb.append("          $ref: \"#/definitions/customer\"\n");
721         sb.append("  customer:\n");
722         sb.append("    description: |\n");
723         sb.append("      customer identifiers to provide linkage back to BSS information.\n");
724         sb.append("      ###### Related Nodes\n");
725         sb.append(
726             "      - FROM service-subscription (CHILD of customer, service-subscription BelongsTo customer, MANY2ONE)(1)\n");
727         sb.append("\n");
728         sb.append("      -(1) IF this CUSTOMER node is deleted, this FROM node is DELETED also\n");
729         sb.append("    required:\n");
730         sb.append("    - global-customer-id\n");
731         sb.append("    - subscriber-name\n");
732         sb.append("    - subscriber-type\n");
733         sb.append("    properties:\n");
734         sb.append("      global-customer-id:\n");
735         sb.append("        type: string\n");
736         sb.append(
737             "        description: Global customer id used across to uniquely identify customer.\n");
738         sb.append("      subscriber-name:\n");
739         sb.append("        type: string\n");
740         sb.append(
741             "        description: Subscriber name, an alternate way to retrieve a customer.\n");
742         sb.append("      subscriber-type:\n");
743         sb.append("        type: string\n");
744         sb.append(
745             "        description: Subscriber type, a way to provide VID with only the INFRA customers.\n");
746         sb.append("      resource-version:\n");
747         sb.append("        type: string\n");
748         sb.append(
749             "        description: Used for optimistic concurrency.  Must be empty on create, valid on update and delete.\n");
750         sb.append("      service-subscriptions:\n");
751         sb.append("        type: array\n");
752         sb.append("        items:\n");
753         sb.append("          $ref: \"#/definitions/service-subscription\"\n");
754         sb.append("  customers:\n");
755         sb.append("    description: |\n");
756         sb.append(
757             "      Collection of customer identifiers to provide linkage back to BSS information.\n");
758         sb.append("    properties:\n");
759         sb.append("      customer:\n");
760         sb.append("        type: array\n");
761         sb.append("        items:          \n");
762         sb.append("          $ref: \"#/definitions/customer\"\n");
763         sb.append("  inventory:\n");
764         sb.append("    properties:\n");
765         sb.append("      business:\n");
766         sb.append("        type: object\n");
767         sb.append("        $ref: \"#/definitions/business\"\n");
768         sb.append("  nodes:" + OxmFileProcessor.LINE_SEPARATOR);
769         sb.append("    properties:" + OxmFileProcessor.LINE_SEPARATOR);
770         sb.append("      inventory-item-data:" + OxmFileProcessor.LINE_SEPARATOR);
771         sb.append("        type: array" + OxmFileProcessor.LINE_SEPARATOR);
772         sb.append("        items:" + OxmFileProcessor.LINE_SEPARATOR);
773         sb.append("          $ref: \"#/definitions/inventory-item-data\""
774             + OxmFileProcessor.LINE_SEPARATOR);
775         sb.append("  service-subscription:\n");
776         sb.append("    description: |\n");
777         sb.append("      Object that group service instances.\n");
778         sb.append("      ###### Related Nodes\n");
779         sb.append(
780             "      - TO customer (PARENT of service-subscription, service-subscription BelongsTo customer, MANY2ONE)(4)\n");
781         sb.append("      - TO tenant( service-subscription Uses tenant, MANY2MANY)\n");
782         sb.append(
783             "      - FROM service-instance (CHILD of service-subscription, service-instance BelongsTo service-subscription, MANY2ONE)(1)\n");
784         sb.append("\n");
785         sb.append(
786             "      -(1) IF this SERVICE-SUBSCRIPTION node is deleted, this FROM node is DELETED also\n");
787         sb.append(
788             "      -(4) IF this TO node is deleted, this SERVICE-SUBSCRIPTION is DELETED also\n");
789         sb.append("    required:\n");
790         sb.append("    - service-type\n");
791         sb.append("    properties:\n");
792         sb.append("      service-type:\n");
793         sb.append("        type: string\n");
794         sb.append(
795             "        description: Value defined by orchestration to identify this service.\n");
796         sb.append("      temp-ub-sub-account-id:\n");
797         sb.append("        type: string\n");
798         sb.append(
799             "        description: This property will be deleted from A&AI in the near future. Only stop gap solution.\n");
800         sb.append("      resource-version:\n");
801         sb.append("        type: string\n");
802         sb.append(
803             "        description: Used for optimistic concurrency.  Must be empty on create, valid on update and delete.\n");
804         sb.append("  service-subscriptions:\n");
805         sb.append("    description: |\n");
806         sb.append("      Collection of objects that group service instances.\n");
807         sb.append("    properties:\n");
808         sb.append("      service-subscription:\n");
809         sb.append("        type: array\n");
810         sb.append("        items:          \n");
811         sb.append("          $ref: \"#/definitions/service-subscription\"\n");
812         return sb.toString();
813     }
814
815     public String YAMLdefsAddPatch() {
816         StringBuilder sb = new StringBuilder(8092);
817         sb.append("  zzzz-patch-customer:\n");
818         sb.append("    description: |\n");
819         sb.append("      customer identifiers to provide linkage back to BSS information.\n");
820         sb.append("      ###### Related Nodes\n");
821         sb.append(
822             "      - FROM service-subscription (CHILD of customer, service-subscription BelongsTo customer, MANY2ONE)(1)\n");
823         sb.append("\n");
824         sb.append("      -(1) IF this CUSTOMER node is deleted, this FROM node is DELETED also\n");
825         sb.append("    properties:\n");
826         sb.append("      global-customer-id:\n");
827         sb.append("        type: string\n");
828         sb.append(
829             "        description: Global customer id used across to uniquely identify customer.\n");
830         sb.append("      subscriber-name:\n");
831         sb.append("        type: string\n");
832         sb.append(
833             "        description: Subscriber name, an alternate way to retrieve a customer.\n");
834         sb.append("      subscriber-type:\n");
835         sb.append("        type: string\n");
836         sb.append(
837             "        description: Subscriber type, a way to provide VID with only the INFRA customers.\n");
838         sb.append("  zzzz-patch-service-subscription:\n");
839         sb.append("    description: |\n");
840         sb.append("      Object that group service instances.\n");
841         sb.append("      ###### Related Nodes\n");
842         sb.append(
843             "      - TO customer (PARENT of service-subscription, service-subscription BelongsTo customer, MANY2ONE)(4)\n");
844         sb.append("      - TO tenant( service-subscription Uses tenant, MANY2MANY)\n");
845         sb.append(
846             "      - FROM service-instance (CHILD of service-subscription, service-instance BelongsTo service-subscription, MANY2ONE)(1)\n");
847         sb.append("\n");
848         sb.append(
849             "      -(1) IF this SERVICE-SUBSCRIPTION node is deleted, this FROM node is DELETED also\n");
850         sb.append(
851             "      -(4) IF this TO node is deleted, this SERVICE-SUBSCRIPTION is DELETED also\n");
852         sb.append("    properties:\n");
853         sb.append("      service-type:\n");
854         sb.append("        type: string\n");
855         sb.append(
856             "        description: Value defined by orchestration to identify this service.\n");
857         sb.append("      temp-ub-sub-account-id:\n");
858         sb.append("        type: string\n");
859         sb.append(
860             "        description: This property will be deleted from A&AI in the near future. Only stop gap solution.\n");
861         return sb.toString();
862     }
863
864     public String YAMLRelationshipList() {
865         StringBuilder sb = new StringBuilder(8092);
866         sb.append("  relationship-list:\n");
867         sb.append("    properties:\n");
868         sb.append("      relationship:\n");
869         sb.append("        type: object\n");
870         sb.append("        $ref: \"#/definitions/relationship\"\n");
871         return sb.toString();
872     }
873
874     public static String EdgeDefs() {
875         StringBuilder sb = new StringBuilder(8092);
876         sb.append("{\n" + "  \"rules\": [\n");
877         sb.append("    {\n");
878         sb.append("      \"from\": \"service-subscription\",\n");
879         sb.append("      \"to\": \"customer\",\n"
880             + "      \"label\": \"org.onap.relationships.inventory.BelongsTo\",\n"
881             + "      \"direction\": \"OUT\",\n" + "      \"multiplicity\": \"MANY2ONE\",\n"
882             + "      \"contains-other-v\": \"!${direction}\",\n"
883             + "      \"delete-other-v\": \"!${direction}\",\n"
884             + "      \"prevent-delete\": \"NONE\",\n" + "      \"default\": \"true\",\n"
885             + "      \"description\":\"\"\n");
886         sb.append("    },\n");
887         sb.append("    {\n" + "      \"from\": \"service-instance\",\n"
888             + "      \"to\": \"service-subscription\",\n"
889             + "      \"label\": \"org.onap.relationships.inventory.BelongsTo\",\n"
890             + "      \"direction\": \"OUT\",\n" + "      \"multiplicity\": \"MANY2ONE\",\n"
891             + "      \"contains-other-v\": \"!${direction}\",\n"
892             + "      \"delete-other-v\": \"!${direction}\",\n"
893             + "      \"prevent-delete\": \"NONE\",\n" + "      \"default\": \"true\",\n"
894             + "      \"description\":\"\"\n" + "    },\n");
895         sb.append("    {\n" + "      \"from\": \"service-subscription\",\n"
896             + "      \"to\": \"tenant\",\n"
897             + "      \"label\": \"org.onap.relationships.inventory.Uses\",\n"
898             + "      \"direction\": \"OUT\",\n" + "      \"multiplicity\": \"MANY2MANY\",\n"
899             + "      \"contains-other-v\": \"NONE\",\n" + "      \"delete-other-v\": \"NONE\",\n"
900             + "      \"prevent-delete\": \"NONE\",\n" + "      \"default\": \"true\",\n"
901             + "      \"description\":\"\"\n" + "    }");
902         sb.append("  ]\n" + "}\n");
903         return sb.toString();
904     }
905 }