2 * ============LICENSE_START=======================================================
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
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 package org.onap.aai.introspection.generator;
22 import org.onap.aai.exceptions.AAIException;
23 import org.onap.aai.introspection.*;
25 import java.security.SecureRandom;
26 import java.util.ArrayList;
27 import java.util.List;
29 public class CreateExample implements Wanderer {
31 private SecureRandom rand = new SecureRandom();
32 private final long range = 100000000L;
33 private Loader loader = null;
34 private Introspector result = null;
35 private String objectName = null;
36 private List<String> blacklist = null;
39 * Instantiates a new creates the example.
41 * @param loader the loader
42 * @param objectName the object name
44 public CreateExample(Loader loader, String objectName) {
47 this.objectName = objectName;
48 this.blacklist = new ArrayList<>();
53 * Gets the example object.
55 * @return the example object
56 * @throws AAIException
58 public Introspector getExampleObject() throws AAIException {
59 result = loader.introspectorFromName(objectName);
60 blacklist = new ArrayList<>();
62 blacklist.add("relationship-list");
63 if (!result.isContainer()) {
64 blacklist.add("resource-version");
66 IntrospectorWalker walker = new IntrospectorWalker(this, PropertyPredicates.includeInExamples());
68 walker.preventCycles(true);
69 walker.setBlacklist(blacklist);
71 //this.getExampleObject(result);
79 * @param property the property
80 * @param type the type
81 * @param suffix the suffix
84 private Object getValue(String property, String type, String suffix) {
85 long randLong = (long)(rand.nextDouble()*range);
86 Integer randInt = rand.nextInt(100000);
87 Integer randShrt = rand.nextInt(20000);
88 short randShort = randShrt.shortValue();
91 if (type.contains("java.lang.String")) {
92 newObj = "example-" + property + "-val-" + randInt + suffix;
93 } else if ( type.toLowerCase().equals("long") ||type.contains("java.lang.Long")) {
95 } else if(type.toLowerCase().equals("boolean") || type.contains("java.lang.Boolean")){
96 newObj = Boolean.TRUE;
97 } else if ( type.toLowerCase().equals("int") || type.contains("java.lang.Integer")){
99 } else if ( type.toLowerCase().equals("short") || type.contains("java.lang.Short")){
110 public void processPrimitive(String propName, Introspector obj) {
111 String propType = obj.getType(propName);
113 Object val = this.getValue(propName, propType, "");
114 obj.setValue(propName, val);
121 public void processPrimitiveList(String propName, Introspector obj) {
123 String propType = "";
124 List<Object> list = new ArrayList<>();
125 for (int i = 0; i < listSize; i++) {
126 propType = obj.getGenericType(propName);
127 Object val = this.getValue(propName, propType, "-" + (i + 1));
130 obj.setValue(propName, list);
137 public void processComplexObj(Introspector obj) {
145 public void modifyComplexList(List<Introspector> list, List<Object> listReference, Introspector parent, Introspector child) {
146 // TODO Auto-generated method stub
154 public boolean createComplexObjIfNull() {
162 public int createComplexListSize(Introspector parent, Introspector child) {