2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.introspection.generator;
24 import org.onap.aai.exceptions.AAIException;
25 import org.onap.aai.introspection.*;
27 import java.security.SecureRandom;
28 import java.util.ArrayList;
29 import java.util.List;
31 public class CreateExample implements Wanderer {
33 private SecureRandom rand = new SecureRandom();
34 private final long range = 100000000L;
35 private Loader loader = null;
36 private Introspector result = null;
37 private String objectName = null;
38 private List<String> blacklist = null;
41 * Instantiates a new creates the example.
43 * @param loader the loader
44 * @param objectName the object name
46 public CreateExample(Loader loader, String objectName) {
49 this.objectName = objectName;
50 this.blacklist = new ArrayList<>();
55 * Gets the example object.
57 * @return the example object
58 * @throws AAIException
60 public Introspector getExampleObject() throws AAIException {
61 result = loader.introspectorFromName(objectName);
62 blacklist = new ArrayList<>();
64 blacklist.add("relationship-list");
65 if (!result.isContainer()) {
66 blacklist.add("resource-version");
68 IntrospectorWalker walker = new IntrospectorWalker(this, PropertyPredicates.includeInExamples());
70 walker.preventCycles(true);
71 walker.setBlacklist(blacklist);
73 //this.getExampleObject(result);
81 * @param property the property
82 * @param type the type
83 * @param suffix the suffix
86 private Object getValue(String property, String type, String suffix) {
87 long randLong = (long)(rand.nextDouble()*range);
88 Integer randInt = rand.nextInt(100000);
89 Integer randShrt = rand.nextInt(20000);
90 short randShort = randShrt.shortValue();
93 if (type.contains("java.lang.String")) {
94 newObj = "example-" + property + "-val-" + randInt + suffix;
95 } else if ( type.toLowerCase().equals("long") ||type.contains("java.lang.Long")) {
97 } else if(type.toLowerCase().equals("boolean") || type.contains("java.lang.Boolean")){
98 newObj = Boolean.TRUE;
99 } else if ( type.toLowerCase().equals("int") || type.contains("java.lang.Integer")){
101 } else if ( type.toLowerCase().equals("short") || type.contains("java.lang.Short")){
112 public void processPrimitive(String propName, Introspector obj) {
113 String propType = obj.getType(propName);
115 Object val = this.getValue(propName, propType, "");
116 obj.setValue(propName, val);
123 public void processPrimitiveList(String propName, Introspector obj) {
125 String propType = "";
126 List<Object> list = new ArrayList<>();
127 for (int i = 0; i < listSize; i++) {
128 propType = obj.getGenericType(propName);
129 Object val = this.getValue(propName, propType, "-" + (i + 1));
132 obj.setValue(propName, list);
139 public void processComplexObj(Introspector obj) {
147 public void modifyComplexList(List<Introspector> list, List<Object> listReference, Introspector parent, Introspector child) {
148 // TODO Auto-generated method stub
156 public boolean createComplexObjIfNull() {
164 public int createComplexListSize(Introspector parent, Introspector child) {