774b760ffdc4f5d96fa5c46a7cd9494bb35ef2fa
[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("#").append(OxmFileProcessor.LINE_SEPARATOR).append(
315             "# ============LICENSE_START=======================================================")
316             .append(OxmFileProcessor.LINE_SEPARATOR).append("# org.onap.aai")
317             .append(OxmFileProcessor.LINE_SEPARATOR)
318             .append(
319                 "# ================================================================================")
320             .append(OxmFileProcessor.LINE_SEPARATOR)
321             .append("# Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.")
322             .append(OxmFileProcessor.LINE_SEPARATOR)
323             .append(
324                 "# ================================================================================")
325             .append(OxmFileProcessor.LINE_SEPARATOR)
326             .append(
327                 "# Licensed under the Creative Commons License, Attribution 4.0 Intl. (the \"License\");")
328             .append(OxmFileProcessor.LINE_SEPARATOR)
329             .append("# you may not use this file except in compliance with the License.")
330             .append(OxmFileProcessor.LINE_SEPARATOR)
331             .append("# You may obtain a copy of the License at")
332             .append(OxmFileProcessor.LINE_SEPARATOR).append("# <p>")
333             .append(OxmFileProcessor.LINE_SEPARATOR)
334             .append("# https://creativecommons.org/licenses/by/4.0/")
335             .append(OxmFileProcessor.LINE_SEPARATOR).append("# <p>")
336             .append(OxmFileProcessor.LINE_SEPARATOR)
337             .append("# Unless required by applicable law or agreed to in writing, software")
338             .append(OxmFileProcessor.LINE_SEPARATOR)
339             .append("# distributed under the License is distributed on an \"AS IS\" BASIS,")
340             .append(OxmFileProcessor.LINE_SEPARATOR)
341             .append("# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.")
342             .append(OxmFileProcessor.LINE_SEPARATOR)
343             .append("# See the License for the specific language governing permissions and")
344             .append(OxmFileProcessor.LINE_SEPARATOR).append("# limitations under the License.")
345             .append(OxmFileProcessor.LINE_SEPARATOR)
346             .append(
347                 "# ============LICENSE_END=========================================================")
348             .append(OxmFileProcessor.LINE_SEPARATOR).append("#")
349             .append(OxmFileProcessor.LINE_SEPARATOR).append(OxmFileProcessor.LINE_SEPARATOR);
350         sb.append("swagger: \"2.0\"\n");
351         sb.append("info:" + OxmFileProcessor.LINE_SEPARATOR);
352         sb.append("  description: |\n");
353         sb.append(
354             "    [Differences versus the previous schema version](apidocs/aai/aai_swagger_v11.diff)"
355                 + OxmFileProcessor.DOUBLE_LINE_SEPARATOR);
356         sb.append(
357             "    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."
358                 + OxmFileProcessor.LINE_SEPARATOR);
359         sb.append("  version: \"v11\"" + OxmFileProcessor.LINE_SEPARATOR);
360         sb.append(
361             "  title: Active and Available Inventory REST API" + OxmFileProcessor.LINE_SEPARATOR);
362         sb.append("  license:" + OxmFileProcessor.LINE_SEPARATOR);
363         sb.append("    name: Apache 2.0\n");
364         sb.append("    url: http://www.apache.org/licenses/LICENSE-2.0.html"
365             + OxmFileProcessor.LINE_SEPARATOR);
366         sb.append("host: localhost" + OxmFileProcessor.LINE_SEPARATOR);
367         sb.append("basePath: /aai/v11" + OxmFileProcessor.LINE_SEPARATOR);
368         sb.append("schemes:" + OxmFileProcessor.LINE_SEPARATOR);
369         sb.append("  - https\n");
370         sb.append("paths:" + OxmFileProcessor.LINE_SEPARATOR);
371         return sb.toString();
372     }
373
374     public String YAMLops() {
375         StringBuilder sb = new StringBuilder(16384);
376         sb.append(
377             "  /business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}:\n");
378         sb.append("    get:\n");
379         sb.append("      tags:\n");
380         sb.append("        - Business\n");
381         sb.append("      summary: returns service-subscription\n");
382         sb.append("      description: returns service-subscription\n");
383         sb.append(
384             "      operationId: getBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
385         sb.append("      produces:\n");
386         sb.append("        - application/json\n");
387         sb.append("        - application/xml\n");
388         sb.append("      responses:\n");
389         sb.append("        \"200\":\n");
390         sb.append("          description: successful operation\n");
391         sb.append("          schema:\n");
392         sb.append("              $ref: \"#/definitions/service-subscription\"\n");
393         sb.append("        \"default\":\n");
394         sb.append("          null      parameters:\n");
395         sb.append("        - name: global-customer-id\n");
396         sb.append("          in: path\n");
397         sb.append(
398             "          description: Global customer id used across to uniquely identify customer.\n");
399         sb.append("          required: true\n");
400         sb.append("          type: string\n");
401         sb.append("        - name: service-type\n");
402         sb.append("          in: path\n");
403         sb.append(
404             "          description: Value defined by orchestration to identify this service.\n");
405         sb.append("          required: true\n");
406         sb.append("          type: string\n");
407         sb.append("    put:\n");
408         sb.append("      tags:\n");
409         sb.append("        - Business\n");
410         sb.append("      summary: create or update an existing service-subscription\n");
411         sb.append("      description: |\n");
412         sb.append("        Create or update an existing service-subscription.\n");
413         sb.append("        #\n");
414         sb.append(
415             "        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");
416         sb.append(
417             "      operationId: createOrUpdateBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
418         sb.append("      consumes:\n");
419         sb.append("        - application/json\n");
420         sb.append("        - application/xml\n");
421         sb.append("      produces:\n");
422         sb.append("        - application/json\n");
423         sb.append("        - application/xml\n");
424         sb.append("      responses:\n");
425         sb.append("        \"default\":\n");
426         sb.append("          null      parameters:\n");
427         sb.append("        - name: global-customer-id\n");
428         sb.append("          in: path\n");
429         sb.append(
430             "          description: Global customer id used across to uniquely identify customer.\n");
431         sb.append("          required: true\n");
432         sb.append("          type: string\n");
433         sb.append("        - name: service-type\n");
434         sb.append("          in: path\n");
435         sb.append(
436             "          description: Value defined by orchestration to identify this service.\n");
437         sb.append("          required: true\n");
438         sb.append("          type: string\n");
439         sb.append("        - name: body\n");
440         sb.append("          in: body\n");
441         sb.append(
442             "          description: service-subscription object that needs to be created or updated. [Valid relationship examples shown here](apidocs/aai/relations/v11/BusinessCustomersCustomerServiceSubscriptionsServiceSubscription.json)\n");
443         sb.append("          required: true\n");
444         sb.append("          schema:\n");
445         sb.append("            $ref: \"#/definitions/service-subscription\"\n");
446         sb.append("    patch:\n");
447         sb.append("      tags:\n");
448         sb.append("        - Business\n");
449         sb.append("      summary: update an existing service-subscription\n");
450         sb.append("      description: |\n");
451         sb.append("        Update an existing service-subscription\n");
452         sb.append("        #\n");
453         sb.append(
454             "        Note:  Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
455         sb.append("        The PUT operation will entirely replace an existing object.\n");
456         sb.append(
457             "        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");
458         sb.append("        #\n");
459         sb.append("        Other differences between PUT and PATCH are:\n");
460         sb.append("        #\n");
461         sb.append(
462             "        - For PATCH, you can send any of the values shown in sample REQUEST body.  There are no required values.\n");
463         sb.append(
464             "        - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
465         sb.append(
466             "        - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
467         sb.append(
468             "      operationId: UpdateBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
469         sb.append("      consumes:\n");
470         sb.append("        - application/json\n");
471         sb.append("      produces:\n");
472         sb.append("        - application/json\n");
473         sb.append("      responses:\n");
474         sb.append("        \"default\":\n");
475         sb.append("          null      parameters:\n");
476         sb.append("        - name: global-customer-id\n");
477         sb.append("          in: path\n");
478         sb.append(
479             "          description: Global customer id used across to uniquely identify customer.\n");
480         sb.append("          required: true\n");
481         sb.append("          type: string\n");
482         sb.append("        - name: service-type\n");
483         sb.append("          in: path\n");
484         sb.append(
485             "          description: Value defined by orchestration to identify this service.\n");
486         sb.append("          required: true\n");
487         sb.append("          type: string\n");
488         sb.append("        - name: body\n");
489         sb.append("          in: body\n");
490         sb.append("          description: service-subscription object that needs to be updated.");
491         sb.append(
492             "[See Examples](apidocs/aai/relations/v11/BusinessCustomersCustomerServiceSubscriptionsServiceSubscription.json)\n");
493         sb.append("          required: true\n");
494         sb.append("          schema:\n");
495         sb.append("            $ref: \"#/definitions/zzzz-patch-service-subscription\"\n");
496         sb.append("    delete:\n");
497         sb.append("      tags:\n");
498         sb.append("        - Business\n");
499         sb.append("      summary: delete an existing service-subscription\n");
500         sb.append("      description: delete an existing service-subscription\n");
501         sb.append(
502             "      operationId: deleteBusinessCustomersCustomerServiceSubscriptionsServiceSubscription\n");
503         sb.append("      consumes:\n");
504         sb.append("        - application/json\n");
505         sb.append("        - application/xml\n");
506         sb.append("      produces:\n");
507         sb.append("        - application/json\n");
508         sb.append("        - application/xml\n");
509         sb.append("      responses:\n");
510         sb.append("        \"default\":\n");
511         sb.append("          null      parameters:\n");
512         sb.append("        - name: global-customer-id\n");
513         sb.append("          in: path\n");
514         sb.append(
515             "          description: Global customer id used across to uniquely identify customer.\n");
516         sb.append("          required: true\n");
517         sb.append("          type: string\n");
518         sb.append("        - name: service-type\n");
519         sb.append("          in: path\n");
520         sb.append(
521             "          description: Value defined by orchestration to identify this service.\n");
522         sb.append("          required: true\n");
523         sb.append("          type: string\n");
524         sb.append("        - name: resource-version\n");
525         sb.append("          in: query\n");
526         sb.append("          description: resource-version for concurrency\n");
527         sb.append("          required: true\n");
528         sb.append("          type: string\n");
529         sb.append("  /business/customers/customer/{global-customer-id}/service-subscriptions:\n");
530         sb.append("    get:\n");
531         sb.append("      tags:\n");
532         sb.append("        - Business\n");
533         sb.append("      summary: returns service-subscriptions\n");
534         sb.append("      description: returns service-subscriptions\n");
535         sb.append("      operationId: getBusinessCustomersCustomerServiceSubscriptions\n");
536         sb.append("      produces:\n");
537         sb.append("        - application/json\n");
538         sb.append("        - application/xml\n");
539         sb.append("      responses:\n");
540         sb.append("        \"200\":\n");
541         sb.append("          description: successful operation\n");
542         sb.append("          schema:\n");
543         sb.append("              $ref: \"#/definitions/service-subscriptions\"\n");
544         sb.append("        \"default\":\n");
545         sb.append("          null      parameters:\n");
546         sb.append("        - name: global-customer-id\n");
547         sb.append("          in: path\n");
548         sb.append(
549             "          description: Global customer id used across to uniquely identify customer.\n");
550         sb.append("          required: true\n");
551         sb.append("          type: string\n");
552         sb.append("        - name: service-type\n");
553         sb.append("          in: query\n");
554         sb.append("          required: false\n");
555         sb.append("          type: string\n");
556         sb.append("  /business/customers/customer/{global-customer-id}:\n");
557         sb.append("    get:\n");
558         sb.append("      tags:\n");
559         sb.append("        - Business\n");
560         sb.append("      summary: returns customer\n");
561         sb.append("      description: returns customer\n");
562         sb.append("      operationId: getBusinessCustomersCustomer\n");
563         sb.append("      produces:\n");
564         sb.append("        - application/json\n");
565         sb.append("        - application/xml\n");
566         sb.append("      responses:\n");
567         sb.append("        \"200\":\n");
568         sb.append("          description: successful operation\n");
569         sb.append("          schema:\n");
570         sb.append("              $ref: \"#/definitions/customer\"\n");
571         sb.append("        \"default\":\n");
572         sb.append("          null      parameters:\n");
573         sb.append("        - name: global-customer-id\n");
574         sb.append("          in: path\n");
575         sb.append(
576             "          description: Global customer id used across to uniquely identify customer.\n");
577         sb.append("          required: true\n");
578         sb.append("          type: string\n");
579         sb.append("    put:\n");
580         sb.append("      tags:\n");
581         sb.append("        - Business\n");
582         sb.append("      summary: create or update an existing customer\n");
583         sb.append("      description: |\n");
584         sb.append("        Create or update an existing customer.\n");
585         sb.append("        #\n");
586         sb.append(
587             "        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");
588         sb.append("      operationId: createOrUpdateBusinessCustomersCustomer\n");
589         sb.append("      consumes:\n");
590         sb.append("        - application/json\n");
591         sb.append("        - application/xml\n");
592         sb.append("      produces:\n");
593         sb.append("        - application/json\n");
594         sb.append("        - application/xml\n");
595         sb.append("      responses:\n");
596         sb.append("        \"default\":\n");
597         sb.append("          null      parameters:\n");
598         sb.append("        - name: global-customer-id\n");
599         sb.append("          in: path\n");
600         sb.append(
601             "          description: Global customer id used across to uniquely identify customer.\n");
602         sb.append("          required: true\n");
603         sb.append("          type: string\n");
604         sb.append("        - name: body\n");
605         sb.append("          in: body\n");
606         sb.append(
607             "          description: customer object that needs to be created or updated. [Valid relationship examples shown here](apidocs/aai/relations/v11/BusinessCustomersCustomer.json)\n");
608         sb.append("          required: true\n");
609         sb.append("          schema:\n");
610         sb.append("            $ref: \"#/definitions/customer\"\n");
611         sb.append("    patch:\n");
612         sb.append("      tags:\n");
613         sb.append("        - Business\n");
614         sb.append("      summary: update an existing customer\n");
615         sb.append("      description: |\n");
616         sb.append("        Update an existing customer\n");
617         sb.append("        #\n");
618         sb.append(
619             "        Note:  Endpoints that are not devoted to object relationships support both PUT and PATCH operations.\n");
620         sb.append("        The PUT operation will entirely replace an existing object.\n");
621         sb.append(
622             "        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");
623         sb.append("        #\n");
624         sb.append("        Other differences between PUT and PATCH are:\n");
625         sb.append("        #\n");
626         sb.append(
627             "        - For PATCH, you can send any of the values shown in sample REQUEST body.  There are no required values.\n");
628         sb.append(
629             "        - For PATCH, resource-id which is a required REQUEST body element for PUT, must not be sent.\n");
630         sb.append(
631             "        - PATCH cannot be used to update relationship elements; there are dedicated PUT operations for this.\n");
632         sb.append("      operationId: UpdateBusinessCustomersCustomer\n");
633         sb.append("      consumes:\n");
634         sb.append("        - application/json\n");
635         sb.append("      produces:\n");
636         sb.append("        - application/json\n");
637         sb.append("      responses:\n");
638         sb.append("        \"default\":\n");
639         sb.append("          null      parameters:\n");
640         sb.append("        - name: global-customer-id\n");
641         sb.append("          in: path\n");
642         sb.append(
643             "          description: Global customer id used across to uniquely identify customer.\n");
644         sb.append("          required: true\n");
645         sb.append("          type: string\n");
646         sb.append("        - name: body\n");
647         sb.append("          in: body\n");
648         sb.append("          description: customer object that needs to be updated.");
649         sb.append("[See Examples](apidocs/aai/relations/v11/BusinessCustomersCustomer.json)\n");
650         sb.append("          required: true\n");
651         sb.append("          schema:\n");
652         sb.append("            $ref: \"#/definitions/zzzz-patch-customer\"\n");
653         sb.append("    delete:\n");
654         sb.append("      tags:\n");
655         sb.append("        - Business\n");
656         sb.append("      summary: delete an existing customer\n");
657         sb.append("      description: delete an existing customer\n");
658         sb.append("      operationId: deleteBusinessCustomersCustomer\n");
659         sb.append("      consumes:\n");
660         sb.append("        - application/json\n");
661         sb.append("        - application/xml\n");
662         sb.append("      produces:\n");
663         sb.append("        - application/json\n");
664         sb.append("        - application/xml\n");
665         sb.append("      responses:\n");
666         sb.append("        \"default\":\n");
667         sb.append("          null      parameters:\n");
668         sb.append("        - name: global-customer-id\n");
669         sb.append("          in: path\n");
670         sb.append(
671             "          description: Global customer id used across to uniquely identify customer.\n");
672         sb.append("          required: true\n");
673         sb.append("          type: string\n");
674         sb.append("        - name: resource-version\n");
675         sb.append("          in: query\n");
676         sb.append("          description: resource-version for concurrency\n");
677         sb.append("          required: true\n");
678         sb.append("          type: string\n");
679         sb.append("  /business/customers:\n");
680         sb.append("    get:\n");
681         sb.append("      tags:\n");
682         sb.append("        - Business\n");
683         sb.append("      summary: returns customers\n");
684         sb.append("      description: returns customers\n");
685         sb.append("      operationId: getBusinessCustomers\n");
686         sb.append("      produces:\n");
687         sb.append("        - application/json\n");
688         sb.append("        - application/xml\n");
689         sb.append("      responses:\n");
690         sb.append("        \"200\":\n");
691         sb.append("          description: successful operation\n");
692         sb.append("          schema:\n");
693         sb.append("              $ref: \"#/definitions/customers\"\n");
694         sb.append("        \"default\":\n");
695         sb.append("          null      parameters:\n");
696         sb.append("        - name: global-customer-id\n");
697         sb.append("          in: query\n");
698         sb.append("          required: false\n");
699         sb.append("          type: string\n");
700         sb.append("        - name: subscriber-name\n");
701         sb.append("          in: query\n");
702         sb.append("          required: false\n");
703         sb.append("          type: string\n");
704         sb.append("        - name: subscriber-type\n");
705         sb.append("          in: query\n");
706         sb.append("          required: false\n");
707         sb.append("          type: string\n");
708         return sb.toString();
709     }
710
711     public String YAMLdefs() {
712         StringBuilder sb = new StringBuilder(8092);
713         sb.append("definitions:\n");
714         sb.append("  business:\n");
715         sb.append("    description: |\n");
716         sb.append("      Namespace for business related constructs\n");
717         sb.append("    properties:\n");
718         sb.append("      customers:\n");
719         sb.append("        type: array\n");
720         sb.append("        items:\n");
721         sb.append("          $ref: \"#/definitions/customer\"\n");
722         sb.append("  customer:\n");
723         sb.append("    description: |\n");
724         sb.append("      customer identifiers to provide linkage back to BSS information.\n");
725         sb.append("      ###### Related Nodes\n");
726         sb.append(
727             "      - FROM service-subscription (CHILD of customer, service-subscription BelongsTo customer, MANY2ONE)(1)\n");
728         sb.append("\n");
729         sb.append("      -(1) IF this CUSTOMER node is deleted, this FROM node is DELETED also\n");
730         sb.append("    required:\n");
731         sb.append("    - global-customer-id\n");
732         sb.append("    - subscriber-name\n");
733         sb.append("    - subscriber-type\n");
734         sb.append("    properties:\n");
735         sb.append("      global-customer-id:\n");
736         sb.append("        type: string\n");
737         sb.append(
738             "        description: Global customer id used across to uniquely identify customer.\n");
739         sb.append("      subscriber-name:\n");
740         sb.append("        type: string\n");
741         sb.append(
742             "        description: Subscriber name, an alternate way to retrieve a customer.\n");
743         sb.append("      subscriber-type:\n");
744         sb.append("        type: string\n");
745         sb.append(
746             "        description: Subscriber type, a way to provide VID with only the INFRA customers.\n");
747         sb.append("      resource-version:\n");
748         sb.append("        type: string\n");
749         sb.append(
750             "        description: Used for optimistic concurrency.  Must be empty on create, valid on update and delete.\n");
751         sb.append("      service-subscriptions:\n");
752         sb.append("        type: array\n");
753         sb.append("        items:\n");
754         sb.append("          $ref: \"#/definitions/service-subscription\"\n");
755         sb.append("  customers:\n");
756         sb.append("    description: |\n");
757         sb.append(
758             "      Collection of customer identifiers to provide linkage back to BSS information.\n");
759         sb.append("    properties:\n");
760         sb.append("      customer:\n");
761         sb.append("        type: array\n");
762         sb.append("        items:          \n");
763         sb.append("          $ref: \"#/definitions/customer\"\n");
764         sb.append("  inventory:\n");
765         sb.append("    properties:\n");
766         sb.append("      business:\n");
767         sb.append("        type: object\n");
768         sb.append("        $ref: \"#/definitions/business\"\n");
769         sb.append("  nodes:" + OxmFileProcessor.LINE_SEPARATOR);
770         sb.append("    properties:" + OxmFileProcessor.LINE_SEPARATOR);
771         sb.append("      inventory-item-data:" + OxmFileProcessor.LINE_SEPARATOR);
772         sb.append("        type: array" + OxmFileProcessor.LINE_SEPARATOR);
773         sb.append("        items:" + OxmFileProcessor.LINE_SEPARATOR);
774         sb.append("          $ref: \"#/definitions/inventory-item-data\""
775             + OxmFileProcessor.LINE_SEPARATOR);
776         sb.append("  service-subscription:\n");
777         sb.append("    description: |\n");
778         sb.append("      Object that group service instances.\n");
779         sb.append("      ###### Related Nodes\n");
780         sb.append(
781             "      - TO customer (PARENT of service-subscription, service-subscription BelongsTo customer, MANY2ONE)(4)\n");
782         sb.append("      - TO tenant( service-subscription Uses tenant, MANY2MANY)\n");
783         sb.append(
784             "      - FROM service-instance (CHILD of service-subscription, service-instance BelongsTo service-subscription, MANY2ONE)(1)\n");
785         sb.append("\n");
786         sb.append(
787             "      -(1) IF this SERVICE-SUBSCRIPTION node is deleted, this FROM node is DELETED also\n");
788         sb.append(
789             "      -(4) IF this TO node is deleted, this SERVICE-SUBSCRIPTION is DELETED also\n");
790         sb.append("    required:\n");
791         sb.append("    - service-type\n");
792         sb.append("    properties:\n");
793         sb.append("      service-type:\n");
794         sb.append("        type: string\n");
795         sb.append(
796             "        description: Value defined by orchestration to identify this service.\n");
797         sb.append("      temp-ub-sub-account-id:\n");
798         sb.append("        type: string\n");
799         sb.append(
800             "        description: This property will be deleted from A&AI in the near future. Only stop gap solution.\n");
801         sb.append("      resource-version:\n");
802         sb.append("        type: string\n");
803         sb.append(
804             "        description: Used for optimistic concurrency.  Must be empty on create, valid on update and delete.\n");
805         sb.append("  service-subscriptions:\n");
806         sb.append("    description: |\n");
807         sb.append("      Collection of objects that group service instances.\n");
808         sb.append("    properties:\n");
809         sb.append("      service-subscription:\n");
810         sb.append("        type: array\n");
811         sb.append("        items:          \n");
812         sb.append("          $ref: \"#/definitions/service-subscription\"\n");
813         return sb.toString();
814     }
815
816     public String YAMLdefsAddPatch() {
817         StringBuilder sb = new StringBuilder(8092);
818         sb.append("  zzzz-patch-customer:\n");
819         sb.append("    description: |\n");
820         sb.append("      customer identifiers to provide linkage back to BSS information.\n");
821         sb.append("      ###### Related Nodes\n");
822         sb.append(
823             "      - FROM service-subscription (CHILD of customer, service-subscription BelongsTo customer, MANY2ONE)(1)\n");
824         sb.append("\n");
825         sb.append("      -(1) IF this CUSTOMER node is deleted, this FROM node is DELETED also\n");
826         sb.append("    properties:\n");
827         sb.append("      global-customer-id:\n");
828         sb.append("        type: string\n");
829         sb.append(
830             "        description: Global customer id used across to uniquely identify customer.\n");
831         sb.append("      subscriber-name:\n");
832         sb.append("        type: string\n");
833         sb.append(
834             "        description: Subscriber name, an alternate way to retrieve a customer.\n");
835         sb.append("      subscriber-type:\n");
836         sb.append("        type: string\n");
837         sb.append(
838             "        description: Subscriber type, a way to provide VID with only the INFRA customers.\n");
839         sb.append("  zzzz-patch-service-subscription:\n");
840         sb.append("    description: |\n");
841         sb.append("      Object that group service instances.\n");
842         sb.append("      ###### Related Nodes\n");
843         sb.append(
844             "      - TO customer (PARENT of service-subscription, service-subscription BelongsTo customer, MANY2ONE)(4)\n");
845         sb.append("      - TO tenant( service-subscription Uses tenant, MANY2MANY)\n");
846         sb.append(
847             "      - FROM service-instance (CHILD of service-subscription, service-instance BelongsTo service-subscription, MANY2ONE)(1)\n");
848         sb.append("\n");
849         sb.append(
850             "      -(1) IF this SERVICE-SUBSCRIPTION node is deleted, this FROM node is DELETED also\n");
851         sb.append(
852             "      -(4) IF this TO node is deleted, this SERVICE-SUBSCRIPTION is DELETED also\n");
853         sb.append("    properties:\n");
854         sb.append("      service-type:\n");
855         sb.append("        type: string\n");
856         sb.append(
857             "        description: Value defined by orchestration to identify this service.\n");
858         sb.append("      temp-ub-sub-account-id:\n");
859         sb.append("        type: string\n");
860         sb.append(
861             "        description: This property will be deleted from A&AI in the near future. Only stop gap solution.\n");
862         return sb.toString();
863     }
864
865     public String YAMLRelationshipList() {
866         StringBuilder sb = new StringBuilder(8092);
867         sb.append("  relationship-list:\n");
868         sb.append("    properties:\n");
869         sb.append("      relationship:\n");
870         sb.append("        type: object\n");
871         sb.append("        $ref: \"#/definitions/relationship\"\n");
872         return sb.toString();
873     }
874
875     public static String EdgeDefs() {
876         StringBuilder sb = new StringBuilder(8092);
877         sb.append("{\n" + "  \"rules\": [\n");
878         sb.append("    {\n");
879         sb.append("      \"from\": \"service-subscription\",\n");
880         sb.append("      \"to\": \"customer\",\n"
881             + "      \"label\": \"org.onap.relationships.inventory.BelongsTo\",\n"
882             + "      \"direction\": \"OUT\",\n" + "      \"multiplicity\": \"MANY2ONE\",\n"
883             + "      \"contains-other-v\": \"!${direction}\",\n"
884             + "      \"delete-other-v\": \"!${direction}\",\n"
885             + "      \"prevent-delete\": \"NONE\",\n" + "      \"default\": \"true\",\n"
886             + "      \"description\":\"\"\n");
887         sb.append("    },\n");
888         sb.append("    {\n" + "      \"from\": \"service-instance\",\n"
889             + "      \"to\": \"service-subscription\",\n"
890             + "      \"label\": \"org.onap.relationships.inventory.BelongsTo\",\n"
891             + "      \"direction\": \"OUT\",\n" + "      \"multiplicity\": \"MANY2ONE\",\n"
892             + "      \"contains-other-v\": \"!${direction}\",\n"
893             + "      \"delete-other-v\": \"!${direction}\",\n"
894             + "      \"prevent-delete\": \"NONE\",\n" + "      \"default\": \"true\",\n"
895             + "      \"description\":\"\"\n" + "    },\n");
896         sb.append("    {\n" + "      \"from\": \"service-subscription\",\n"
897             + "      \"to\": \"tenant\",\n"
898             + "      \"label\": \"org.onap.relationships.inventory.Uses\",\n"
899             + "      \"direction\": \"OUT\",\n" + "      \"multiplicity\": \"MANY2MANY\",\n"
900             + "      \"contains-other-v\": \"NONE\",\n" + "      \"delete-other-v\": \"NONE\",\n"
901             + "      \"prevent-delete\": \"NONE\",\n" + "      \"default\": \"true\",\n"
902             + "      \"description\":\"\"\n" + "    }");
903         sb.append("  ]\n" + "}\n");
904         return sb.toString();
905     }
906 }