diff --git a/.gitignore b/.gitignore index b6f70359..67b3e655 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ build.xml /.classpath /.project /.gradle +.nb-gradle # macbook .DS_Store diff --git a/README.md b/README.md index 4b93e317..e21aeb2f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ + +THIS IS THE NEW CODEGEN2 BRANCH +============================== + +A code generator rewrite is under way.... + ari4java ======== diff --git a/build.gradle b/build.gradle index 76a5e3d0..171e5270 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ def env = System.getenv() project.ext { webapp_name = 'ari4java' - app_version = '0.3.2' + app_version = 'c2.0.0' build_number = env["BUILD_NUMBER"] version_class = 'ch/loway/oss/ari4java/BUILD.java' build_time = "" + new Date() @@ -105,6 +105,7 @@ dependencies { compile 'com.fasterxml.jackson.core:jackson-databind:2.2.2' compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.2' compile 'io.netty:netty-all:4.0.25.Final' + compile 'org.freemarker:freemarker:2.3.23' testCompile 'junit:junit:4.10' diff --git a/classes/ch/loway/oss/ari4java/ggen/ari_1_8_0/model/FormatLangPairXxx.java b/classes/ch/loway/oss/ari4java/ggen/ari_1_8_0/model/FormatLangPairXxx.java new file mode 100644 index 00000000..92d0de60 --- /dev/null +++ b/classes/ch/loway/oss/ari4java/ggen/ari_1_8_0/model/FormatLangPairXxx.java @@ -0,0 +1 @@ +ch.loway.oss.ari4java.codegen2.writeClass.JClass@4732a704 diff --git a/codegen-data/ari_0_0_1/channels.json b/codegen-data/ari_0_0_1/channels.json index 97e6b103..b720d62a 100644 --- a/codegen-data/ari_0_0_1/channels.json +++ b/codegen-data/ari_0_0_1/channels.json @@ -146,7 +146,7 @@ "required": false, "allowMultiple": false, "dataType": "string", - "defalutValue": "normal", + "defaultValue": "normal", "allowableValues": { "valueType": "LIST", "values": [ diff --git a/codegen-data/ari_0_0_1/sounds.json b/codegen-data/ari_0_0_1/sounds.json index 1a92ee02..1ea48d2b 100644 --- a/codegen-data/ari_0_0_1/sounds.json +++ b/codegen-data/ari_0_0_1/sounds.json @@ -30,7 +30,7 @@ "paramType": "query", "dataType": "string", "required": false, - "__note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." + "note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." } ] } diff --git a/codegen-data/ari_1_0_0/channels.json b/codegen-data/ari_1_0_0/channels.json index 6122f6d9..b337d4b7 100644 --- a/codegen-data/ari_1_0_0/channels.json +++ b/codegen-data/ari_1_0_0/channels.json @@ -146,7 +146,7 @@ "required": false, "allowMultiple": false, "dataType": "string", - "defalutValue": "normal", + "defaultValue": "normal", "allowableValues": { "valueType": "LIST", "values": [ diff --git a/codegen-data/ari_1_0_0/sounds.json b/codegen-data/ari_1_0_0/sounds.json index 0825909d..dc79e79d 100644 --- a/codegen-data/ari_1_0_0/sounds.json +++ b/codegen-data/ari_1_0_0/sounds.json @@ -30,7 +30,7 @@ "paramType": "query", "dataType": "string", "required": false, - "__note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." + "note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." } ] } diff --git a/codegen-data/ari_1_5_0/channels.json b/codegen-data/ari_1_5_0/channels.json index 1cc28e79..5bea0470 100644 --- a/codegen-data/ari_1_5_0/channels.json +++ b/codegen-data/ari_1_5_0/channels.json @@ -275,7 +275,7 @@ "required": false, "allowMultiple": false, "dataType": "string", - "defalutValue": "normal", + "defaultValue": "normal", "allowableValues": { "valueType": "LIST", "values": [ diff --git a/codegen-data/ari_1_5_0/endpoints.json b/codegen-data/ari_1_5_0/endpoints.json index 8c59db0b..e439377a 100644 --- a/codegen-data/ari_1_5_0/endpoints.json +++ b/codegen-data/ari_1_5_0/endpoints.json @@ -55,7 +55,7 @@ }, { "name": "variables", - "descriptioni": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", + "description": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", "paramType": "body", "required": false, "dataType": "containers", @@ -173,7 +173,7 @@ }, { "name": "variables", - "descriptioni": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", + "description": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", "paramType": "body", "required": false, "dataType": "containers", diff --git a/codegen-data/ari_1_5_0/sounds.json b/codegen-data/ari_1_5_0/sounds.json index c46340c0..f2e0ef65 100644 --- a/codegen-data/ari_1_5_0/sounds.json +++ b/codegen-data/ari_1_5_0/sounds.json @@ -30,7 +30,7 @@ "paramType": "query", "dataType": "string", "required": false, - "__note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." + "note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." } ] } diff --git a/codegen-data/ari_1_6_0/channels.json b/codegen-data/ari_1_6_0/channels.json index ac497e9e..a969acc5 100644 --- a/codegen-data/ari_1_6_0/channels.json +++ b/codegen-data/ari_1_6_0/channels.json @@ -275,7 +275,7 @@ "required": false, "allowMultiple": false, "dataType": "string", - "defalutValue": "normal", + "defaultValue": "normal", "allowableValues": { "valueType": "LIST", "values": [ diff --git a/codegen-data/ari_1_6_0/endpoints.json b/codegen-data/ari_1_6_0/endpoints.json index 8440d8b0..33bb1c2e 100644 --- a/codegen-data/ari_1_6_0/endpoints.json +++ b/codegen-data/ari_1_6_0/endpoints.json @@ -55,7 +55,7 @@ }, { "name": "variables", - "descriptioni": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", + "description": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", "paramType": "body", "required": false, "dataType": "containers", @@ -173,7 +173,7 @@ }, { "name": "variables", - "descriptioni": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", + "description": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", "paramType": "body", "required": false, "dataType": "containers", diff --git a/codegen-data/ari_1_6_0/sounds.json b/codegen-data/ari_1_6_0/sounds.json index 5ed6de7a..e4a6b4da 100644 --- a/codegen-data/ari_1_6_0/sounds.json +++ b/codegen-data/ari_1_6_0/sounds.json @@ -30,7 +30,7 @@ "paramType": "query", "dataType": "string", "required": false, - "__note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." + "note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." } ] } diff --git a/codegen-data/ari_1_7_0/channels.json b/codegen-data/ari_1_7_0/channels.json index dd81a23e..fa957904 100644 --- a/codegen-data/ari_1_7_0/channels.json +++ b/codegen-data/ari_1_7_0/channels.json @@ -307,7 +307,7 @@ "required": false, "allowMultiple": false, "dataType": "string", - "defalutValue": "normal", + "defaultValue": "normal", "allowableValues": { "valueType": "LIST", "values": [ diff --git a/codegen-data/ari_1_7_0/endpoints.json b/codegen-data/ari_1_7_0/endpoints.json index 8440d8b0..33bb1c2e 100644 --- a/codegen-data/ari_1_7_0/endpoints.json +++ b/codegen-data/ari_1_7_0/endpoints.json @@ -55,7 +55,7 @@ }, { "name": "variables", - "descriptioni": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", + "description": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", "paramType": "body", "required": false, "dataType": "containers", @@ -173,7 +173,7 @@ }, { "name": "variables", - "descriptioni": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", + "description": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", "paramType": "body", "required": false, "dataType": "containers", diff --git a/codegen-data/ari_1_7_0/sounds.json b/codegen-data/ari_1_7_0/sounds.json index 5ed6de7a..b684e430 100644 --- a/codegen-data/ari_1_7_0/sounds.json +++ b/codegen-data/ari_1_7_0/sounds.json @@ -29,9 +29,7 @@ "description": "Lookup sound in a specific format.", "paramType": "query", "dataType": "string", - "required": false, - "__note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." - } + "required": false } ] } ] diff --git a/codegen-data/ari_1_8_0/channels.json b/codegen-data/ari_1_8_0/channels.json index 1b7faf75..b4866f9c 100644 --- a/codegen-data/ari_1_8_0/channels.json +++ b/codegen-data/ari_1_8_0/channels.json @@ -307,7 +307,7 @@ "required": false, "allowMultiple": false, "dataType": "string", - "defalutValue": "normal", + "defaultValue": "normal", "allowableValues": { "valueType": "LIST", "values": [ diff --git a/codegen-data/ari_1_8_0/endpoints.json b/codegen-data/ari_1_8_0/endpoints.json index 73467731..02dd406f 100644 --- a/codegen-data/ari_1_8_0/endpoints.json +++ b/codegen-data/ari_1_8_0/endpoints.json @@ -55,7 +55,7 @@ }, { "name": "variables", - "descriptioni": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", + "description": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", "paramType": "body", "required": false, "dataType": "containers", @@ -177,7 +177,7 @@ }, { "name": "variables", - "descriptioni": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", + "description": "The \"variables\" key in the body object holds technology specific key/value pairs to append to the message. These can be interpreted and used by the various resource types; for example, pjsip and sip resource types will add the key/value pairs as SIP headers,", "paramType": "body", "required": false, "dataType": "containers", diff --git a/codegen-data/ari_1_8_0/sounds.json b/codegen-data/ari_1_8_0/sounds.json index 4cfa7ed4..ad668ee1 100644 --- a/codegen-data/ari_1_8_0/sounds.json +++ b/codegen-data/ari_1_8_0/sounds.json @@ -29,8 +29,7 @@ "description": "Lookup sound in a specific format.", "paramType": "query", "dataType": "string", - "required": false, - "__note": "core show translation can show translation paths between formats, along with relative costs. so this could be just installed format, or we could follow that for transcoded formats." + "required": false } ] } diff --git a/codegen/ch/loway/oss/ari4java/codegen2/AriActions.java b/codegen/ch/loway/oss/ari4java/codegen2/AriActions.java new file mode 100644 index 00000000..20cba20b --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/AriActions.java @@ -0,0 +1,13 @@ + +package ch.loway.oss.ari4java.codegen2; + +/** + * + * @author lenz + */ +public class AriActions { + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/AriEntity.java b/codegen/ch/loway/oss/ari4java/codegen2/AriEntity.java new file mode 100644 index 00000000..d9fa3139 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/AriEntity.java @@ -0,0 +1,24 @@ +package ch.loway.oss.ari4java.codegen2; + +import ch.loway.oss.ari4java.codegen2.writeClass.JClass; +import ch.loway.oss.ari4java.codegen2.writeClass.JMethod; +import java.util.ArrayList; +import java.util.List; + +/** + * This is a bsic ARI entity: + * - ActionXXX + * - A model + * - An event + * + * @author lenz + */ +public class AriEntity { + + public String ariVersion = ""; + public JClass javaClass = new JClass(); + + public List methods = new ArrayList(); + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/AriModels.java b/codegen/ch/loway/oss/ari4java/codegen2/AriModels.java new file mode 100644 index 00000000..39379665 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/AriModels.java @@ -0,0 +1,11 @@ + +package ch.loway.oss.ari4java.codegen2; + +/** + * + * @author lenz + */ +public class AriModels { + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/ImplClasses.java b/codegen/ch/loway/oss/ari4java/codegen2/ImplClasses.java new file mode 100644 index 00000000..642a3f63 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/ImplClasses.java @@ -0,0 +1,40 @@ + +package ch.loway.oss.ari4java.codegen2; + +import ch.loway.oss.ari4java.codegen2.models.Api; +import ch.loway.oss.ari4java.codegen2.models.SwaggerFile; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author lenz + */ +public class ImplClasses { + + Map hmClassi = new HashMap(); + + public void process( String ariVersion, SwaggerFile sf ) { + + for ( Api a: sf.apis ) { + + + + + } + + + } + + public void addClass( AriEntity e ) { + String className = e.javaClass.getFullName(); + + assert( !hmClassi.containsKey( className ) ); + + hmClassi.put(className, e); + + } + + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/Rebuild.java b/codegen/ch/loway/oss/ari4java/codegen2/Rebuild.java new file mode 100644 index 00000000..5772b171 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/Rebuild.java @@ -0,0 +1,202 @@ +package ch.loway.oss.ari4java.codegen2; + +import ch.loway.oss.ari4java.codegen2.models.Api; +import ch.loway.oss.ari4java.codegen2.models.ApiOperation; +import ch.loway.oss.ari4java.codegen2.models.Model; +import ch.loway.oss.ari4java.codegen2.models.ModelProperty; +import ch.loway.oss.ari4java.codegen2.models.SwaggerFile; +import ch.loway.oss.ari4java.codegen2.writeClass.InterfaceWriter; +import ch.loway.oss.ari4java.codegen2.writeClass.JClass; +import ch.loway.oss.ari4java.codegen2.writeClass.JavaImplBuilder; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * + * @author lenz + */ +public class Rebuild { + + public static String DIR = "/Users/lenz/dev/github/ari4java/codegen-data"; + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws Exception { + + List versions = Arrays.asList( new String[] { + "ari_1_8_0", "ari_1_7_0" + , "ari_1_6_0", "ari_1_5_0" + // field "extends" needed but not valid Java name + // , + // "ari_1_0_0", "ari_0_0_1" + }); + + List files = Arrays.asList(new String[]{ +// "applications", "asterisk", "bridges", +// "channels", "deviceStates", "endpoints", +// "mailboxes", "playbacks", "recordings", +// "sounds", "events" + + "sounds" + }); + + // Loads all files into an in-memory representation. + Map> sources = new HashMap(); + SharedInterfaces sharedInterfaces = new SharedInterfaces(); + SharedEnums sharedEnums = new SharedEnums(); + + for (String version : versions) { + for (String file : files) { + loadSwaggerData(sources, version, file); + } + } + + + + + // Common interface + // Build interface + // Build enums + + + + for ( String file: files) { + for ( String ver: versions ) { + SwaggerFile sf = sources.get(ver).get(file); + sharedInterfaces.merge(sf); + } + } + + System.out.println( sharedInterfaces.toString() ); + + for ( String file: files) { + for ( String ver: versions ) { + SwaggerFile sf = sources.get(ver).get(file); + for ( Api api: sf.apis) { + for ( ApiOperation ao: api.operations) { + sharedEnums.loadEnums( ao ); + } + } + + for ( Model m: sf.models.values() ) { + for ( String prop: m.properties.keySet() ) { + ModelProperty mp = m.properties.get(prop); + + sharedEnums.loadEnums( StringTools.enumClassName(m.id,prop), mp); + } + } + + } + } + + + System.out.println( sharedEnums.toString() ); + + System.out.println( "-------"); + + // Write interfaces + for ( String version: versions ) { + + for (String file: files ) { + SwaggerFile swagFile = sources.get(version).get(file); + for ( Entry e: swagFile.models.entrySet() ) { + String modelName = e.getKey(); + Model model = e.getValue(); + SharedInterface ifc = sharedInterfaces.getInterface(modelName); + + JClass myClass = JavaImplBuilder.makeModelImpl(version, model, ifc); + StringTools.writeClass(myClass); + } + } + + + // build models + // build actions + // build events (?) + // merge models + // merge actions + // merge events + + + + // Process models + // Process events + // Process Actions + } + + + // For each version + String PATH = "~/varie"; + + InterfaceWriter iw = new InterfaceWriter(); + iw.process( PATH, sharedInterfaces ); + + + } + + /** + * Adds a Swagger file to the sources map. + * + * map[version][filename] = swaggerFile + * + * If no file found / load error, nothing is added. + * + * @param sources + * @param version + * @param filename + */ + + private static void loadSwaggerData(Map> sources, String version, String filename) { + + SwaggerFile sf = loadSwagger( version, filename + ".json" ); + + if ( sf != null ) { + + sf.a4j_filename = filename; + + if ( !sources.containsKey(version) ) { + sources.put( version, new HashMap()); + } + + Map m = sources.get( version ); + m.put( filename, sf ); + } + + } + + /** + * Deserializes a swagger file. + * + * @param version + * @param name + * @return the object, or null if no file was loaded. + */ + + + private static SwaggerFile loadSwagger( String version, String name ) { + + SwaggerFile sf = null; + + try { + + ObjectMapper mapper = new ObjectMapper(); + sf = mapper.readValue(new File( DIR + "/" + version + "/" + name ), SwaggerFile.class); + + } catch (IOException e ) { + e.printStackTrace(); + } + + return sf; + } + + + + +} diff --git a/codegen/ch/loway/oss/ari4java/codegen2/Settings.java b/codegen/ch/loway/oss/ari4java/codegen2/Settings.java new file mode 100644 index 00000000..d6c85ee3 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/Settings.java @@ -0,0 +1,17 @@ + +package ch.loway.oss.ari4java.codegen2; + +import java.io.File; + +/** + * General system settings. + * + * @author lenz + */ +public class Settings { + + public static final String pkgGen = "ch.loway.oss.ari4java.ggen"; + public static final File basePkgs = new File( "/Users/lenz/dev/github/ari4java/classes" ); + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/SharedEnums.java b/codegen/ch/loway/oss/ari4java/codegen2/SharedEnums.java new file mode 100644 index 00000000..4f1a8170 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/SharedEnums.java @@ -0,0 +1,70 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package ch.loway.oss.ari4java.codegen2; + +import ch.loway.oss.ari4java.codegen2.models.ApiOperation; +import ch.loway.oss.ari4java.codegen2.models.ApiParameter; +import ch.loway.oss.ari4java.codegen2.models.ModelProperty; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +/** + * + * @author lenz + * @version $Id$ + */ +public class SharedEnums { + + Map> enums = new HashMap(); + + public void addEnumValue( String enumName, String value ) { + + enumName = StringTools.prefixCapitalize("E", enumName); + + if ( !enums.containsKey(enumName) ) { + enums.put( enumName, new TreeSet() ); + } + + Set vals = enums.get(enumName); + vals.add(value); + } + + + public void loadEnums( ApiOperation op ) { + for ( ApiParameter p: op.parameters) { + if (p.translatesToEnum() ) { + for ( String evs: p.allowableValues.values ) { + addEnumValue( p.name, evs); + } + } + } + } + + + + public void loadEnums( String name, ModelProperty mp ) { + if (mp.translatesToEnum() ) { + for ( String evs: mp.allowableValues.values ) { + addEnumValue( name, evs); + } + } + } + + + @Override + public String toString() { + return "ENUMS:\n" + enums.toString(); + } + + + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/SharedInterface.java b/codegen/ch/loway/oss/ari4java/codegen2/SharedInterface.java new file mode 100644 index 00000000..8433ee9e --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/SharedInterface.java @@ -0,0 +1,78 @@ + +package ch.loway.oss.ari4java.codegen2; + +import ch.loway.oss.ari4java.codegen2.writeClass.JMethod; +import ch.loway.oss.ari4java.codegen2.models.ApiOperation; +import ch.loway.oss.ari4java.codegen2.models.ApiParameter; +import ch.loway.oss.ari4java.codegen2.models.DataType; +import ch.loway.oss.ari4java.codegen2.models.ModelProperty; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * + * @author lenz + * @version $Id$ + */ +public class SharedInterface { + + public String name = ""; + public String fromFile = ""; + + public Map methods = new HashMap(); + + /** + * Merges a SwaggerFile into this interface. + * + * @param si + */ + + public void add( String apiVersion, ApiOperation op ) { + + JMethod m = JMethod.build(op); + setUnlessDupe(m, apiVersion); + + } + + + + + + public void addGetterSetter( String apiVersion, String propertyName, ModelProperty mp ) { + + setUnlessDupe(JMethod.buildGetter(propertyName, mp), apiVersion); + setUnlessDupe(JMethod.buildSetter(propertyName, mp), apiVersion); + + } + + + private JMethod setUnlessDupe( JMethod m, String apiVersion ) { + String sig = m.getJavaSignature(); + + if ( methods.containsKey(sig) ) { + m = methods.get(sig); + } else { + methods.put(sig, m); + } + + m.addVersionAvailable( apiVersion ); + return m; + } + + public List getMethods() { + List lM = new ArrayList(); + for ( String mn: StringTools.sortedKeySet(methods) ) { + lM.add( methods.get(mn) ); + } + return lM; + } + + + + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/SharedInterfaces.java b/codegen/ch/loway/oss/ari4java/codegen2/SharedInterfaces.java new file mode 100644 index 00000000..8410a756 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/SharedInterfaces.java @@ -0,0 +1,106 @@ + +package ch.loway.oss.ari4java.codegen2; + +import ch.loway.oss.ari4java.codegen2.writeClass.JMethod; +import ch.loway.oss.ari4java.codegen2.models.Api; +import ch.loway.oss.ari4java.codegen2.models.ApiOperation; +import ch.loway.oss.ari4java.codegen2.models.Model; +import ch.loway.oss.ari4java.codegen2.models.SwaggerFile; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Holds a set of shared iterfaces. + * + * @author lenz + * @version $Id$ + */ +public class SharedInterfaces { + + Map ints = new HashMap(); + + public void merge( SwaggerFile sf ) { + String version = sf.apiVersion; + + // sounds.json -> ActionSounds + String actionName = sf.getActionName(); + SharedInterface sia = fetchOrCreate(actionName); + + for ( Api api: sf.apis ) { + for (ApiOperation op: api.operations ) { + sia.add(version, op); + } + } + + // Objects + for ( Model m: sf.models.values() ){ + String name = m.id; + SharedInterface smi = fetchOrCreate(name); + + for (String names: m.properties.keySet() ) { + smi.addGetterSetter( version, names, m.properties.get(names) ); + } + } + } + + /** + * Gets a Shared Interface, or creates it if it does not exist. + * + * @param interfaceName + * @return + */ + + private SharedInterface fetchOrCreate( String interfaceName ) { + if ( !ints.containsKey( interfaceName) ) { + SharedInterface si = new SharedInterface(); + si.name = interfaceName; + ints.put(interfaceName, si); + } + return ints.get(interfaceName); + } + + + /** + * Dumps the shared interface. + * + * @return + */ + + + @Override + public String toString() { + + String s = "SharedInterface:\n"; + for ( String k: StringTools.sortedKeySet( ints ) ) { + s += "- Inteface " + k + ":\n"; + SharedInterface si = ints.get(k); + for ( String mn: StringTools.sortedKeySet( si.methods) ) { + JMethod m = si.methods.get(mn); + s += " " + mn + " " + m.availableIn + "\n"; + } + } + return s; + } + + public Map getIntefaces() { + return ints; + } + + /** + * Loads the current shared interface. + * + * @param file + * @return + */ + + public SharedInterface getInterface( String file ) { + return ints.get(file); + } + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/StringTools.java b/codegen/ch/loway/oss/ari4java/codegen2/StringTools.java new file mode 100644 index 00000000..df199dbb --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/StringTools.java @@ -0,0 +1,127 @@ + +package ch.loway.oss.ari4java.codegen2; + +import ch.loway.oss.ari4java.codegen2.writeClass.JClass; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * + * @author lenz + * @version $Id$ + */ +public class StringTools { + + public static String capitalize( String in ) { + if ( in.length() < 2 ) { + return in.toUpperCase(); + } else { + return in.substring(0,1).toUpperCase() + in.substring(1); + } + } + + public static String prefixCapitalize( String prefix, String name ) { + return prefix + capitalize(name); + } + + public static String mkGetter( String name ) { + return prefixCapitalize("get", name); + } + + public static String mkSetter( String name ) { + return prefixCapitalize("set", name); + } + + public static String mkActionClass( String name ) { + return prefixCapitalize( "Action", name); + } + + /** + * Traverses map.keySet orderly. + * + * @param m + * @return + */ + + public static List sortedKeySet( Map m) { + List ks = new ArrayList( m.keySet() ); + Collections.sort(ks); + return ks; + } + + /** + * Joins a list of objects with a separator. + * + * @param vals + * @param sep + * @return + */ + + public static String join( List vals, String sep ) { + StringBuilder sb = new StringBuilder(); + for (int i =0; i < vals.size(); i++) { + if (i>0) { + sb.append( sep ); + } + sb.append( vals.get(i).toString() ); + } + return sb.toString(); + } + + public static String enumClassName( String model, String name ) { + + if ( name.equalsIgnoreCase( "state") ) { + return prefixCapitalize(model, name); + } + + return capitalize(name); + } + + + /** + * Writes a file, creating the path if missing, and relative to the file base. + * I'm not sure about the encoding . + * + * @param jPkgName a.b.c -> /base/path/a/b/c/ + * @param name The file name + * @param contents The contents of the file. + * @throws IOException If shit happens. + */ + + public static void writeFile( String jPkgName, String name, String contents ) throws IOException { + + char pathSeparator = '/'; + File base = Settings.basePkgs.getCanonicalFile(); + + String pkgInPath = base.getAbsolutePath() + pathSeparator + jPkgName.replace('.', pathSeparator ); + + // creates the destination path (if it does not exist) + File withFolder = new File( pkgInPath ); + withFolder.mkdirs(); + + File myFile = new File( withFolder.getCanonicalFile().toString() + pathSeparator + name ); + FileWriter outFile = new FileWriter( myFile ); + PrintWriter out = new PrintWriter(outFile); + out.println( contents ); + out.close(); + } + + /** + * Scrive una classe. + * + * @param jc + * @throws IOException + */ + + public static void writeClass( JClass jc ) throws IOException { + writeFile(jc.xPackage, jc.xName + ".java", jc.toString() ); + } + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/AllowableValue.java b/codegen/ch/loway/oss/ari4java/codegen2/models/AllowableValue.java new file mode 100644 index 00000000..1bfb466f --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/AllowableValue.java @@ -0,0 +1,22 @@ + +package ch.loway.oss.ari4java.codegen2.models; + +import java.util.List; + +/** + * + * @author lenz + * @see + */ +public class AllowableValue { + + public Type valueType= null; + public int min = 0; + public List values = null; + + public static enum Type { + RANGE, + LIST + } + +} diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/Api.java b/codegen/ch/loway/oss/ari4java/codegen2/models/Api.java new file mode 100644 index 00000000..117de1ec --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/Api.java @@ -0,0 +1,25 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package ch.loway.oss.ari4java.codegen2.models; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author lenz + * @version $Id$ + */ +public class Api { + + public String path = ""; + public String description = ""; + public List operations = new ArrayList(); +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/ApiErrorResponse.java b/codegen/ch/loway/oss/ari4java/codegen2/models/ApiErrorResponse.java new file mode 100644 index 00000000..36b5a51f --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/ApiErrorResponse.java @@ -0,0 +1,15 @@ + +package ch.loway.oss.ari4java.codegen2.models; + +/** + * + * @author lenz + * @version $Id$ + */ +public class ApiErrorResponse { + public int code = 0; + public String reason = ""; +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/ApiOperation.java b/codegen/ch/loway/oss/ari4java/codegen2/models/ApiOperation.java new file mode 100644 index 00000000..6c858953 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/ApiOperation.java @@ -0,0 +1,45 @@ + +package ch.loway.oss.ari4java.codegen2.models; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author lenz + * @version $Id$ + */ +public class ApiOperation { + + public HttpMethod httpMethod = null; + public String summary = ""; + public String notes = ""; + public String nickname = ""; + public DataType responseClass = null; + public UpgradeTo upgrade = null; + public WebsocketProtocol websocketProtocol = null; + + public List parameters = new ArrayList(); + public List errorResponses = new ArrayList(); + + + public static enum HttpMethod { + GET, + POST, + DELETE, + PUT + } + + + public static enum UpgradeTo { + websocket + } + + public static enum WebsocketProtocol { + ari + } + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/ApiParameter.java b/codegen/ch/loway/oss/ari4java/codegen2/models/ApiParameter.java new file mode 100644 index 00000000..00d9af11 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/ApiParameter.java @@ -0,0 +1,42 @@ + +package ch.loway.oss.ari4java.codegen2.models; + +/** + * + * @author lenz + * @version $Id$ + */ +public class ApiParameter { + + public String name= ""; + public String description = ""; + public ParamType paramType = null; + public boolean required = false; + public boolean allowMultiple = false; + public DataType dataType = null; + public String defaultValue = null; + public AllowableValue allowableValues = null; + public String note = ""; + + public static enum ParamType { + query, + path, + body; + } + + + public boolean translatesToEnum() { + if (allowableValues != null ) { + if ( allowableValues.valueType == AllowableValue.Type.LIST) { + assert( dataType.javaType.equalsIgnoreCase("String") ); + return true; + } + } + return false; + } + + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/DataType.java b/codegen/ch/loway/oss/ari4java/codegen2/models/DataType.java new file mode 100644 index 00000000..456db824 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/DataType.java @@ -0,0 +1,60 @@ +package ch.loway.oss.ari4java.codegen2.models; + +import java.util.HashMap; +import java.util.Map; + +public class DataType { + + private static Map REMAP_TYPES; + static { + REMAP_TYPES = new HashMap(); + REMAP_TYPES.put( "string", "String"); + REMAP_TYPES.put( "int", "int"); + REMAP_TYPES.put( "boolean", "boolean"); + REMAP_TYPES.put( "long", "long"); + REMAP_TYPES.put( "containers", "containers"); + REMAP_TYPES.put( "void", "void" ); + REMAP_TYPES.put( "Date", "Date"); + REMAP_TYPES.put( "double", "double"); + } + + + public String swagType = ""; + public String javaType = ""; + + + public DataType( String fromSwaggerType ) { + swagType = fromSwaggerType; + javaType = mkJavaType( swagType ); + + } + + + public String asJavaType() { + return javaType; + } + + /** + * Translates a Swagger type to Java. + * + * @param type + * @return + */ + + private String mkJavaType( String type ) { + + if ( type.startsWith("List[") && type.endsWith("]")) { + String inner = type.substring( "List[".length(), type.length() - "]".length() ); + return "List<" + mkJavaType(inner) + ">"; + } + + if ( REMAP_TYPES.containsKey(type) ) { + return REMAP_TYPES.get(type); + } else { + return type; + } + + } + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/Model.java b/codegen/ch/loway/oss/ari4java/codegen2/models/Model.java new file mode 100644 index 00000000..9cc86e42 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/Model.java @@ -0,0 +1,35 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package ch.loway.oss.ari4java.codegen2.models; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * + * @author lenz + * @version $Id$ + */ +public class Model { + public String id = ""; + public String description = ""; + public Discriminator discriminator = null; + public List subTypes = new ArrayList(); + // public String extends = ""; + public Map properties = new HashMap(); + + + public static enum Discriminator { + type + } + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/ModelProperty.java b/codegen/ch/loway/oss/ari4java/codegen2/models/ModelProperty.java new file mode 100644 index 00000000..776c38eb --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/ModelProperty.java @@ -0,0 +1,41 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package ch.loway.oss.ari4java.codegen2.models; + +/** + * + * @author lenz + * @version $Id$ + */ +public class ModelProperty { + + public DataType type = null; + public String description = ""; + public boolean required; + public AllowableValue allowableValues = null; + + + /** + * Questo e' un valore semplice o un enum? + * + * @return + */ + + public boolean translatesToEnum() { + if (allowableValues != null ) { + if ( allowableValues.valueType == AllowableValue.Type.LIST) { + assert( type.javaType.equalsIgnoreCase("String") ); + return true; + } + } + return false; + } + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/models/SwaggerFile.java b/codegen/ch/loway/oss/ari4java/codegen2/models/SwaggerFile.java new file mode 100644 index 00000000..cb1e6396 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/models/SwaggerFile.java @@ -0,0 +1,50 @@ +package ch.loway.oss.ari4java.codegen2.models; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * + * @author lenz + */ +public class SwaggerFile { + + // Loaded by JAckson + + public String _copyright = ""; + public String _author = ""; + public String _svn_revision = ""; + public String swaggerVersion = ""; + public String basePath = ""; + public String apiVersion = ""; + public String resourcePath = ""; + + public List apis = new ArrayList(); + public Map models = new HashMap(); + + + // Other + public String a4j_filename = ""; + + /** + * File: sounds -> ActionSounds. + * + * @return + */ + public String getActionName() { + return "Action" + + a4j_filename.substring(0, 1).toUpperCase() + + a4j_filename.substring(1); + } + + + + + + + + + +} diff --git a/codegen/ch/loway/oss/ari4java/codegen2/writeClass/BasicFtl.java b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/BasicFtl.java new file mode 100644 index 00000000..a0086c61 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/BasicFtl.java @@ -0,0 +1,52 @@ + +package ch.loway.oss.ari4java.codegen2.writeClass; + +import ch.loway.oss.ari4java.codegen2.learn.LearnFreemarker; +import freemarker.cache.ClassTemplateLoader; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateExceptionHandler; +import java.io.OutputStreamWriter; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author lenz + */ +public class BasicFtl { + + Configuration cfg = null; + + + public Configuration getCfg() throws Exception { + + if ( cfg == null ) { + + cfg = new Configuration(Configuration.VERSION_2_3_22); + cfg.setDefaultEncoding("UTF-8"); + cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); + cfg.setTemplateLoader( new ClassTemplateLoader( BasicFtl.class, "") ); + } + + return cfg; + } + + + public String processTemplate( String template, Map root ) throws Exception { + + getCfg(); + + Template temp = cfg.getTemplate( template ); + Writer out = new StringWriter(); + + temp.process(root, out); + return out.toString(); + } + + +} + + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/writeClass/InterfaceWriter.java b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/InterfaceWriter.java new file mode 100644 index 00000000..aa87359c --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/InterfaceWriter.java @@ -0,0 +1,36 @@ + +package ch.loway.oss.ari4java.codegen2.writeClass; + +import ch.loway.oss.ari4java.codegen2.SharedInterfaces; +import ch.loway.oss.ari4java.codegen2.StringTools; +import java.util.HashMap; +import java.util.Map; + +/** + * Writes interfaces. + * + * @author lenz + */ +public class InterfaceWriter extends BasicFtl { + + public void process(String PATH, SharedInterfaces sharedInterfaces) throws Exception { + + for ( String intf: StringTools.sortedKeySet( sharedInterfaces.getIntefaces()) ) { + + + Map root = new HashMap(); + root.put( "interfaceName" , intf ); + root.put( "methods", sharedInterfaces.getIntefaces().get(intf).getMethods() ); + + System.out.println( processTemplate( "ftl/interface.ftl", root)); + + } + + + } + + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JClass.java b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JClass.java new file mode 100644 index 00000000..7b7b021e --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JClass.java @@ -0,0 +1,40 @@ + +package ch.loway.oss.ari4java.codegen2.writeClass; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author lenz + */ +public class JClass { + + public String xPackage = ""; + public String xName = ""; + public Type type = null; + public JClass xtends = null; + public List xImpls = new ArrayList(); + + public List xMethods = new ArrayList(); + public List xVars = new ArrayList(); + + public static enum Type { + CLASS, + INTERFACE, + ENUM + } + + + public String getFullName() { + return xPackage + "." + xName; + } + + + // public String // + + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JMethod.java b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JMethod.java new file mode 100644 index 00000000..4c915f78 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JMethod.java @@ -0,0 +1,102 @@ + +package ch.loway.oss.ari4java.codegen2.writeClass; + +import ch.loway.oss.ari4java.codegen2.StringTools; +import ch.loway.oss.ari4java.codegen2.models.ApiOperation; +import ch.loway.oss.ari4java.codegen2.models.ApiParameter; +import ch.loway.oss.ari4java.codegen2.models.DataType; +import ch.loway.oss.ari4java.codegen2.models.ModelProperty; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author lenz + * @version $Id$ + */ +public class JMethod { + public String returnType = ""; + public String name = ""; + public String description = ""; + public List parameters = new ArrayList(); + public List availableIn = new ArrayList(); + public List throwsEx = new ArrayList(); + public String body = ""; + + public void addParameter(DataType d, String name, String comment) { + parameters.add( JParm.build(d.asJavaType(), name, comment)); + } + + /** + * + * @param version xxx + */ + + public void addVersionAvailable(String version) { + availableIn.add(version); + } + + public static JMethod build(ApiOperation o) { + JMethod m = new JMethod(); + m.name = o.nickname; + m.returnType = o.responseClass.asJavaType(); + for (ApiParameter ap : o.parameters) { + m.addParameter(ap.dataType, ap.name, ap.description + " " + ap.note ); + } + return m; + } + + public static JMethod buildGetter(String name, ModelProperty mp) { + JMethod m = new JMethod(); + m.name = StringTools.mkGetter(name); + m.returnType = mp.type.asJavaType(); + return m; + } + + public static JMethod buildSetter(String name, ModelProperty mp) { + JMethod m = new JMethod(); + m.name = StringTools.mkSetter(name); + m.returnType = "void"; + m.addParameter(mp.type, "v", mp.description); + return m; + } + + public String getJavaSignature() { + return returnType + " " + name + "(" + StringTools.join(parameters, ", ") + ")"; + } + + public String getCode() { + String c = "public " + returnType + " " + + name + "(" + StringTools.join(parameters, ", ") + ")"; + + if ( !throwsEx.isEmpty() ) { + c += " throws " + StringTools.join( throwsEx, ", "); + } + return c; + } + + public String getAvailableVers() { + return StringTools.join(availableIn, ", "); + } + + public String getParamDescriptions() { + + String s = ""; + for ( JParm p: parameters) { + s += " * @param " + p.name + " " + p.comment + "\n"; + } + return s; + } + + public String getDescription() { + return description; + } + + + + + +} + +// $Log$ +// diff --git a/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JParm.java b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JParm.java new file mode 100644 index 00000000..8c886a0c --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JParm.java @@ -0,0 +1,28 @@ + +package ch.loway.oss.ari4java.codegen2.writeClass; + +/** + * A Java call parameter. + * + * @author lenz + */ +public class JParm { + public String type = ""; + public String name = ""; + public String comment = ""; + + public static JParm build(String t, String v, String c) { + JParm jp = new JParm(); + jp.type = t; + jp.name = v; + jp.comment = c; + return jp; + } + + @Override + public String toString() { + return type + " " + name; + } + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JavaImplBuilder.java b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JavaImplBuilder.java new file mode 100644 index 00000000..1ec7ba4d --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/JavaImplBuilder.java @@ -0,0 +1,53 @@ + +package ch.loway.oss.ari4java.codegen2.writeClass; + +import ch.loway.oss.ari4java.codegen2.Settings; +import ch.loway.oss.ari4java.codegen2.SharedInterface; +import ch.loway.oss.ari4java.codegen2.models.Model; +import ch.loway.oss.ari4java.codegen2.models.ModelProperty; +import java.util.Map.Entry; + +/** + * + * @author lenz + * @version $Id$ + */ +public class JavaImplBuilder { + + public static JClass makeModelImpl( String version, Model m, SharedInterface i ) { + + JClass jc = new JClass(); + jc.xName = m.id + "_impl_" + version; + jc.xPackage = Settings.pkgGen + "." + version + ".models"; + + for ( Entry mp: m.properties.entrySet() ) { + String propName = mp.getKey(); + ModelProperty pr = mp.getValue(); + + JMethod getter = JMethod.buildGetter(propName, pr); + JMethod setter = JMethod.buildSetter(propName, pr); + + getter.body = ""; + setter.body = ""; + + jc.xMethods.add(setter); + jc.xMethods.add(getter); + + } + + + + + // controlla i metodi esisteti + for (Entry em: i.methods.entrySet() ) { + + } + + return jc; + + + } + + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/writeClass/ftl/interface.ftl b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/ftl/interface.ftl new file mode 100644 index 00000000..b89fc0ec --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/ftl/interface.ftl @@ -0,0 +1,37 @@ +package ch.loway.oss.ari4java.generated; + +// ---------------------------------------------------- +// THIS CLASS WAS GENERATED AUTOMATICALLY +// PLEASE DO NOT EDIT +// Generated on: -------------------------------- +// ---------------------------------------------------- + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.ArrayList; +import ch.loway.oss.ari4java.tools.RestException; +import ch.loway.oss.ari4java.tools.AriCallback; +import ch.loway.oss.ari4java.tools.tags.*; + +/********************************************************** + * Template: Interface.ftl + *********************************************************/ + + +public interface ${interfaceName} { + +<#list methods as met> + /** + * ${met.description} + * + ${met.paramDescriptions} + * Available in: ${met.availableVers} + */ + ${met.code}; + + + + +} + diff --git a/codegen/ch/loway/oss/ari4java/codegen2/writeClass/ftl/klazz.ftl b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/ftl/klazz.ftl new file mode 100644 index 00000000..26431bb1 --- /dev/null +++ b/codegen/ch/loway/oss/ari4java/codegen2/writeClass/ftl/klazz.ftl @@ -0,0 +1,41 @@ +package ch.loway.oss.ari4java.generated; + +// ---------------------------------------------------- +// THIS CLASS WAS GENERATED AUTOMATICALLY +// PLEASE DO NOT EDIT +// Generated on: -------------------------------- +// ---------------------------------------------------- + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.ArrayList; +import ch.loway.oss.ari4java.tools.RestException; +import ch.loway.oss.ari4java.tools.AriCallback; +import ch.loway.oss.ari4java.tools.tags.*; + +/********************************************************** + * Template: klazz.ftl + *********************************************************/ + + +public class ${interfaceName} ${extendsImplements} { + + + + + +<#list methods as met> + /** + * ${met.description} + * + ${met.paramDescriptions} + * Available in: ${met.availableVers} + */ + ${met.code}; + + + + +} + diff --git a/docs/swagger_anomalies.txt b/docs/swagger_anomalies.txt new file mode 100644 index 00000000..812ccb0c --- /dev/null +++ b/docs/swagger_anomalies.txt @@ -0,0 +1,41 @@ +This file is used to keep track of a number of anomalies in Swagger files. + + +Unrecognized field "defalutValue" (class ch.loway.oss.ari4java.codegen2.models.ApiParameter) + at [Source: ./codegen-data/ari_1_8_0/channels.json; line: 310, column: 25] + +Unrecognized field "descriptioni" (class ch.loway.oss.ari4java.codegen2.models.ApiParameter) + at [Source: ./codegen-data/ari_1_8_0/endpoints.json; line: 58, column: 25] + + Unrecognized field "descriptioni" (class ch.loway.oss.ari4java.codegen2.models.ApiParameter) + at [Source: ./codegen-data/ari_1_8_0/endpoints.json; line: 180, column: 25] + + Unrecognized field "__note" + at [Source: ./codegen-data/ari_1_8_0/sounds.json + + + +Enums are a mix of different cases (lowercase, uppercase, CamelCase) + +EBridge_type=[holding, mixing], +ELiveRecordingState=[canceled, done, failed, paused, queued, recording], +EIfExists=[append, fail, overwrite], +EEndpointState=[offline, online, unknown], +EDirection=[both, in, out], +ESpy=[both, in, none, out], +EReason=[busy, congestion, no_answer, normal], +EWhisper=[both, in, none, out], +EPlaybackState=[complete, playing, queued], +EOnly=[build, config, status, system], + +EDeviceState=[BUSY, INUSE, INVALID, NOT_INUSE, ONHOLD, RINGING, RINGINUSE, UNAVAILABLE], +EDeviceStateState=[BUSY, INUSE, INVALID, NOT_INUSE, ONHOLD, RINGING, RINGINUSE, UNAVAILABLE, UNKNOWN], + +- DeviceStates appear twice, with a different set of entries! + +EOperation=[forward, pause, restart, reverse, unpause], +ETerminateOn=[#, *, any, none], + +EChannelState=[Busy, Dialing, Dialing Offhook, Down, OffHook, Pre-ring, Ring, Ringing, Rsrved, Unknown, Up]} + +- Rserverd? \ No newline at end of file