2323import io .kusanagi .katana .sdk .Callable ;
2424import io .kusanagi .katana .sdk .ServiceSchema ;
2525
26+ import java .util .ArrayList ;
2627import java .util .HashMap ;
28+ import java .util .List ;
2729import java .util .Map ;
2830
2931/**
3032 * Created by juan on 28/08/16.
3133 */
32- public class Api {
34+ public abstract class Api {
3335
3436 protected Component component ;
3537
@@ -76,81 +78,31 @@ public Api(Component component, String path, String name, String version, String
7678 this .isDebug = isDebug ;
7779 }
7880
79- public Api (Api other ) {
80- this .path = other .path ;
81- this .name = other .name ;
82- this .version = other .version ;
83- this .platformVersion = other .platformVersion ;
84- this .variables = other .variables ;
85- this .isDebug = other .isDebug ;
86- }
87-
88- /**
89- * Path setter
90- *
91- * @param path Path of the call
92- */
93- public void setPath (String path ) {
81+ public Api (Component component , String path , String name , String version , String platformVersion ,
82+ Map <String , String > variables , boolean isDebug , Mapping mapping ) {
83+ this .component = component ;
9484 this .path = path ;
95- }
96-
97- /**
98- * Name setter
99- *
100- * @param name Name of the Service
101- */
102- public void setName (String name ) {
10385 this .name = name ;
104- }
105-
106- /**
107- * Version setter
108- *
109- * @param version Version of the service
110- */
111- public void setProtocolVersion (String version ) {
11286 this .version = version ;
113- }
114-
115- /**
116- * Platform version setter
117- *
118- * @param platformVersion Version of the platform
119- */
120- public void setPlatformVersion (String platformVersion ) {
12187 this .platformVersion = platformVersion ;
122- }
123-
124- /**
125- * Variables setter
126- *
127- * @param variables Sdk variables
128- */
129- public void setVariables (Map <String , String > variables ) {
13088 this .variables = variables ;
89+ this .isDebug = isDebug ;
90+ this .mapping = mapping ;
13191 }
13292
133- /**
134- * Debug state setter
135- *
136- * @param debug Debug state
137- */
138- public void setDebug ( boolean debug ) {
139- isDebug = debug ;
93+ public Api ( Api other ) {
94+ this . path = other . path ;
95+ this . name = other . name ;
96+ this . version = other . version ;
97+ this . platformVersion = other . platformVersion ;
98+ this . variables = other . variables ;
99+ this . isDebug = other . isDebug ;
140100 }
141101
142102 public Mapping getMapping () {
143103 return mapping ;
144104 }
145105
146- public void setMapping (Mapping mapping ) {
147- this .mapping = mapping ;
148- }
149-
150- public void setComponent (Component component ) {
151- this .component = component ;
152- }
153-
154106 // SDK Method
155107
156108 /**
@@ -165,7 +117,7 @@ public boolean isDebug() {
165117 * @return Return the version of the platform
166118 */
167119 @ JsonIgnore
168- public String getPlatformVersion () {
120+ public String getFrameworkVersion () {
169121 return platformVersion ;
170122 }
171123
@@ -201,6 +153,15 @@ public Map<String, String> getVariables() {
201153 return variables ;
202154 }
203155
156+ /**
157+ *
158+ * @param name case-sensitive name argument.
159+ * @return determine if a variable has been defined with the REQUIRED case-sensitive name argument.
160+ */
161+ public boolean hasVariable (String name ) {
162+ return this .variables .containsKey (name );
163+ }
164+
204165 /**
205166 * Get the variable with the REQUIRED case-sensitive name argument, and which MUST be returned as a string.
206167 *
@@ -228,6 +189,27 @@ public Callable getResource(String name) {
228189 return this .component .getResource (name );
229190 }
230191
192+ /**
193+ *
194+ * @return return an array with the Service versions in the stored schema mapping, in which each item MUST be an
195+ * object with the key name that MUST have the name of the Service and the key version that MUST have the version of the Service.
196+ */
197+ public List <Map <String , String >> getServices (){
198+ List <Map <String , String >> services = new ArrayList <>();
199+
200+ for (Map .Entry service : mapping .getServiceSchema ().entrySet ()) {
201+ Map <String , ServiceSchema > versions = mapping .getServiceSchema ().get ((String ) service .getKey ());
202+ for (Map .Entry version : versions .entrySet ()) {
203+ Map <String , String > serviceMap = new HashMap <>();
204+ serviceMap .put ("service" , (String ) service .getKey ());
205+ serviceMap .put ("version" , (String ) version .getKey ());
206+ services .add (serviceMap );
207+ }
208+ }
209+
210+ return services ;
211+ }
212+
231213 /**
232214 * Return an instance of the Mapping class for the Service defined by the REQUIRED case sensitive name and
233215 * version arguments, using the stored mapping of schemas.
@@ -259,6 +241,15 @@ public boolean log(String value) {
259241 return true ;
260242 }
261243
244+ /**
245+ *
246+ * @return This function is only for use in an asynchronous implementation of the SDK, for any other implementation
247+ * it MUST return false.
248+ */
249+ public boolean done (){
250+ return false ;
251+ }
252+
262253 @ Override
263254 public boolean equals (Object o ) {
264255 if (this == o ) {
@@ -320,4 +311,92 @@ public String toString() {
320311 ", mapping=" + mapping +
321312 '}' ;
322313 }
314+
315+ public abstract static class Builder <T > {
316+ private Component component ;
317+ private String path ;
318+ private String name ;
319+ private String version ;
320+ private String platformVersion ;
321+ private Map <String , String > variables ;
322+ private boolean isDebug ;
323+ private Mapping mapping ;
324+
325+ public Builder () {
326+ }
327+
328+ public Builder <T > setComponent (Component component ) {
329+ this .component = component ;
330+ return this ;
331+ }
332+
333+ public Builder <T > setPath (String path ) {
334+ this .path = path ;
335+ return this ;
336+ }
337+
338+ public Builder <T > setName (String name ) {
339+ this .name = name ;
340+ return this ;
341+ }
342+
343+ public Builder <T > setVersion (String version ) {
344+ this .version = version ;
345+ return this ;
346+ }
347+
348+ public Builder <T > setPlatformVersion (String platformVersion ) {
349+ this .platformVersion = platformVersion ;
350+ return this ;
351+ }
352+
353+ public Builder <T > setVariables (Map <String , String > variables ) {
354+ this .variables = variables ;
355+ return this ;
356+ }
357+
358+ public Builder <T > setDebug (boolean debug ) {
359+ isDebug = debug ;
360+ return this ;
361+ }
362+
363+ public Builder <T > setMapping (Mapping mapping ) {
364+ this .mapping = mapping ;
365+ return this ;
366+ }
367+
368+ public Component getComponent () {
369+ return component ;
370+ }
371+
372+ public String getPath () {
373+ return path ;
374+ }
375+
376+ public String getName () {
377+ return name ;
378+ }
379+
380+ public String getVersion () {
381+ return version ;
382+ }
383+
384+ public String getPlatformVersion () {
385+ return platformVersion ;
386+ }
387+
388+ public Map <String , String > getVariables () {
389+ return variables ;
390+ }
391+
392+ public boolean isDebug () {
393+ return isDebug ;
394+ }
395+
396+ public Mapping getMapping () {
397+ return mapping ;
398+ }
399+
400+ public abstract T build ();
401+ }
323402}
0 commit comments