Skip to content

Commit 7d046d9

Browse files
committed
Merge branch 'release/1.5.1'
2 parents a7e56ff + 35484a9 commit 7d046d9

File tree

73 files changed

+1047
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1047
-207
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# 1.5.1
2+
- Add custom header option to v2 client, new 'execute' method on each endpoint request.
3+
14
# 1.5.0
2-
- Added support for Algorand Smart Contract Applications.
5+
- Add new execute method to support for Algorand Smart Contract Applications.
36

47
# 1.4.2
58
- Accept URI formatting in AlgodClient and IndexerClient to specify connection scheme.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Maven:
2323
<dependency>
2424
<groupId>com.algorand</groupId>
2525
<artifactId>algosdk</artifactId>
26-
<version>1.5.0</version>
26+
<version>1.5.1</version>
2727
</dependency>
2828
```
2929

generator/pom.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@
168168
<dependency>
169169
<groupId>com.algorand</groupId>
170170
<artifactId>algosdk</artifactId>
171-
<version>1.5.0</version>
171+
<version>1.5.1</version>
172172
</dependency>
173173

174174
<!-- testing -->
175175
<dependency>
176176
<groupId>org.junit.jupiter</groupId>
177177
<artifactId>junit-jupiter</artifactId>
178-
<version>RELEASE</version>
178+
<version>5.6.2</version>
179179
<scope>test</scope>
180180
</dependency>
181181

@@ -231,11 +231,9 @@
231231
<plugin>
232232
<groupId>org.apache.maven.plugins</groupId>
233233
<artifactId>maven-compiler-plugin</artifactId>
234+
<version>3.8.1</version>
234235
<configuration>
235-
<source>${java.version}</source>
236-
<target>${java.version}</target>
237-
<testSource>${java.version}</testSource>
238-
<testTarget>${java.version}</testTarget>
236+
<release>14</release>
239237
</configuration>
240238
</plugin>
241239
<plugin>

generator/src/main/java/com/algorand/sdkutils/generators/OpenApiParser.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import com.algorand.sdkutils.listeners.Publisher;
1616
import com.algorand.sdkutils.listeners.Publisher.Events;
17+
import com.algorand.sdkutils.utils.QueryDef;
1718
import com.algorand.sdkutils.utils.StructDef;
1819
import com.algorand.sdkutils.utils.Tools;
1920
import com.algorand.sdkutils.utils.TypeDef;
@@ -412,8 +413,17 @@ void writeQueryClass(
412413
properties = getSortedParameters(paramNode);
413414
}
414415

415-
String [] strarray = {methodName, returnType, path, desc, httpMethod};
416-
this.publisher.publish(Events.NEW_QUERY, strarray);
416+
List<String> contentTypes = new ArrayList<>();
417+
if (spec.has("produces") && spec.get("produces").isArray()) {
418+
for (JsonNode value : spec.get("produces")) {
419+
if (value.isTextual()) {
420+
contentTypes.add(value.asText());
421+
} else {
422+
throw new RuntimeException("Unexpected content type: " + value.toString());
423+
}
424+
}
425+
}
426+
this.publisher.publish(Events.NEW_QUERY, new QueryDef(methodName, returnType, path, desc, httpMethod, contentTypes));
417427

418428
processQueryParams(properties);
419429

generator/src/main/java/com/algorand/sdkutils/listeners/GoGenerator.java

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
package com.algorand.sdkutils.listeners;
22

3-
import java.io.BufferedWriter;
4-
import java.io.File;
5-
import java.io.FileWriter;
6-
import java.io.IOException;
7-
import java.io.Writer;
8-
import java.util.HashMap;
9-
import java.util.HashSet;
10-
import java.util.Iterator;
11-
import java.util.Map;
12-
import java.util.Map.Entry;
13-
import java.util.Set;
14-
import java.util.StringTokenizer;
15-
import java.util.TreeMap;
16-
import java.util.TreeSet;
17-
183
import com.algorand.sdkutils.listeners.Publisher.Events;
4+
import com.algorand.sdkutils.utils.QueryDef;
195
import com.algorand.sdkutils.utils.StructDef;
206
import com.algorand.sdkutils.utils.Tools;
217
import com.algorand.sdkutils.utils.TypeDef;
228

9+
import java.io.*;
10+
import java.util.*;
11+
import java.util.Map.Entry;
12+
2313
public class GoGenerator implements Subscriber {
2414

2515
enum Annotation {
@@ -194,10 +184,10 @@ public void onEvent(Events event) {
194184
}
195185

196186
@Override
197-
public void onEvent(Events event, String [] notes) {
187+
public void onEvent(Events event, QueryDef query) {
198188
switch(event) {
199189
case NEW_QUERY:
200-
newQuery(notes[0], notes[1], notes[2], notes[3], notes[4]);
190+
newQuery(query);
201191
break;
202192
default:
203193
throw new RuntimeException("Unimplemented event for note! " + event);
@@ -298,40 +288,35 @@ private StringBuilder processPath() {
298288

299289

300290

301-
private void newQuery(
302-
String className,
303-
String returnTypeName,
304-
String path,
305-
String desc,
306-
String httpMethod) {
291+
private void newQuery(QueryDef query) {
307292

308-
this.pathDesc = path + "\n" + desc;
309-
this.path = path;
310-
this.httpMethod = httpMethod;
311-
currentQueryName = Tools.getCamelCase(className, true);
312-
currentQueryReturn = Tools.getCamelCase(returnTypeName, true);
293+
this.pathDesc = query.path + "\n" + query.description;
294+
this.path = query.path;
295+
this.httpMethod = query.method;
296+
this.currentQueryName = Tools.getCamelCase(query.name, true);
297+
this.currentQueryReturn = Tools.getCamelCase(query.returnType, true);
313298

314-
pathParameters = new TreeMap<String, String>();
315-
bodyParameter = new TreeMap<String, TypeConverter>();
316-
queryFunctions = new StringBuilder();
317-
imports = new TreeMap<String, Set<String>>();
299+
this.pathParameters = new TreeMap<String, String>();
300+
this.bodyParameter = new TreeMap<String, TypeConverter>();
301+
this.queryFunctions = new StringBuilder();
302+
this.imports = new TreeMap<String, Set<String>>();
318303

319-
setFormatToMsgpack = false;
304+
this.setFormatToMsgpack = false;
320305

321-
if (queryWriter != null) {
306+
if (this.queryWriter != null) {
322307
throw new RuntimeException("Query writer should be closed!");
323308
}
324309

325310
// Also need to create the struct for the parameters
326-
modelWriter.newModel(
311+
this.modelWriter.newModel(
327312
new StructDef(
328-
currentQueryName + "Params",
329-
"defines parameters for " + currentQueryName, null, null),
330-
modelsFilePrefix + "filtermodels", "models");
313+
this.currentQueryName + "Params",
314+
"defines parameters for " + this.currentQueryName, null, null),
315+
this.modelsFilePrefix + "filtermodels", "models");
331316

332317
// Add the entry into the applicationClient file
333-
clientFunction = new StringBuilder();
334-
clientFunction.append("func (c *Client) " + currentQueryName + "(");
318+
this.clientFunction = new StringBuilder();
319+
this.clientFunction.append("func (c *Client) " + this.currentQueryName + "(");
335320
}
336321

337322
private void addPathParameter(TypeDef type) {

generator/src/main/java/com/algorand/sdkutils/listeners/JavaGenerator.java

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import com.algorand.sdkutils.generators.Utils;
1616
import com.algorand.sdkutils.listeners.Publisher.Events;
17+
import com.algorand.sdkutils.utils.QueryDef;
1718
import com.algorand.sdkutils.utils.StructDef;
1819
import com.algorand.sdkutils.utils.Tools;
1920
import com.algorand.sdkutils.utils.TypeDef;
@@ -81,20 +82,18 @@ public JavaGenerator(
8182
public void onEvent(Events event) {
8283
switch(event) {
8384
case END_QUERY:
84-
javaQueryWriter.finalize();
85+
javaQueryWriter.finish();
8586
break;
8687
default:
8788
throw new RuntimeException("Unimplemented event! " + event);
8889
}
8990
}
9091

9192
@Override
92-
public void onEvent(Events event, String [] notes) {
93+
public void onEvent(Events event, QueryDef query) {
9394
switch(event) {
9495
case NEW_QUERY:
95-
javaQueryWriter = new JavaQueryWriter(
96-
notes[0], notes[1], notes[2],
97-
notes[3], notes[4], this);
96+
javaQueryWriter = new JavaQueryWriter(query, this);
9897
break;
9998
default:
10099
throw new RuntimeException("Unimplemented event for note! " + event);
@@ -434,47 +433,41 @@ final class JavaQueryWriter {
434433

435434
TreeMap<String, Set<String>> imports;
436435

437-
public JavaQueryWriter(
438-
String methodName,
439-
String returnType,
440-
String path,
441-
String desc,
442-
String httpMethod,
443-
JavaGenerator javaGenerator) {
444-
445-
this.className = Tools.getCamelCase(methodName, true);
446-
decls = new StringBuilder();
447-
builders = new StringBuilder();
448-
constructorHeader = new StringBuilder();
449-
constructorBody = new StringBuilder();
450-
requestMethod = new StringBuilder();
451-
constructorComments = new ArrayList<String>();
452-
453-
generatedPathsEntryBody = new StringBuilder();
454-
this.httpMethod = httpMethod;
455-
456-
requestMethod.append(getQueryResponseMethod(returnType));
457-
requestMethod.append(" protected QueryData getRequestString() {\n");
458-
pAdded = false;
459-
addFormatMsgpack = false;
460-
461-
this.path = path;
462-
discAndPath = desc + "\n" + path;
436+
public JavaQueryWriter(QueryDef query, JavaGenerator javaGenerator) {
437+
438+
this.className = Tools.getCamelCase(query.name, true);
439+
this.decls = new StringBuilder();
440+
this.builders = new StringBuilder();
441+
this.constructorHeader = new StringBuilder();
442+
this.constructorBody = new StringBuilder();
443+
this.requestMethod = new StringBuilder();
444+
this.constructorComments = new ArrayList<String>();
445+
446+
this.generatedPathsEntryBody = new StringBuilder();
447+
this.httpMethod = query.method;
448+
449+
this.requestMethod.append(getQueryResponseMethod(query.returnType));
450+
this.requestMethod.append(" protected QueryData getRequestString() {\n");
451+
this.pAdded = false;
452+
this.addFormatMsgpack = false;
453+
454+
this.path = query.path;
455+
this.discAndPath = query.description + "\n" + query.path;
463456

464457
this.javaGen = javaGenerator;
465458

466-
imports = new TreeMap<String, Set<String>>();
467-
Tools.addImport(imports, "com.algorand.algosdk.v2.client.common.Client");
468-
Tools.addImport(imports, "com.algorand.algosdk.v2.client.common.HttpMethod");
469-
Tools.addImport(imports, "com.algorand.algosdk.v2.client.common.Query");
470-
Tools.addImport(imports, "com.algorand.algosdk.v2.client.common.QueryData");
471-
Tools.addImport(imports, "com.algorand.algosdk.v2.client.common.Response");
472-
if (needsClassImport(returnType.toLowerCase())) {
473-
Tools.addImport(imports, javaGen.modelPackage + "." + returnType);
459+
this.imports = new TreeMap<String, Set<String>>();
460+
Tools.addImport(this.imports, "com.algorand.algosdk.v2.client.common.Client");
461+
Tools.addImport(this.imports, "com.algorand.algosdk.v2.client.common.HttpMethod");
462+
Tools.addImport(this.imports, "com.algorand.algosdk.v2.client.common.Query");
463+
Tools.addImport(this.imports, "com.algorand.algosdk.v2.client.common.QueryData");
464+
Tools.addImport(this.imports, "com.algorand.algosdk.v2.client.common.Response");
465+
if (needsClassImport(query.returnType.toLowerCase())) {
466+
Tools.addImport(this.imports, this.javaGen.modelPackage + "." + query.returnType);
474467
}
475468

476-
javaGen.generatedPathsEntries.append(Tools.formatComment(discAndPath, TAB, true));
477-
javaGen.generatedPathsEntries.append(" public " + className + " " + methodName + "(");
469+
this.javaGen.generatedPathsEntries.append(Tools.formatComment(this.discAndPath, this.TAB, true));
470+
this.javaGen.generatedPathsEntries.append(" public " + this.className + " " + query.name + "(");
478471
}
479472

480473
public void addQueryProperty(TypeDef propType, boolean inQuery, boolean inPath, boolean inBody) {
@@ -568,7 +561,7 @@ public void addQueryProperty(TypeDef propType, boolean inQuery, boolean inPath,
568561
}
569562
}
570563

571-
public void finalize() {
564+
public void finish() {
572565

573566
javaGen.generatedPathsImports.append("import " + javaGen.queryPackage + "." + className + ";\n");
574567

@@ -621,7 +614,7 @@ public void finalize() {
621614
sb.append(Tools.formatComment(discAndPath, "", true));
622615
sb.append("public class " + className + " extends Query {\n\n");
623616
sb.append(queryParamsCode);
624-
sb.append("\n}");
617+
sb.append("\n}\n");
625618

626619
BufferedWriter bw = JavaGenerator.newFile(className, javaGen.queryFilesDirectory);
627620
JavaGenerator.append(bw, "package " + javaGen.queryPackage + ";\n\n");
@@ -651,12 +644,31 @@ static ArrayList<String> getPathInserts(String path) {
651644

652645
static String getQueryResponseMethod(String returnType) {
653646
String ret =
647+
" /**\n" +
648+
" * Execute the query.\n" +
649+
" * @return the query response object.\n" +
650+
" * @throws Exception\n" +
651+
" */\n" +
652+
" @Override\n" +
653+
" public Response<" + returnType + "> execute() throws Exception {\n" +
654+
" Response<" + returnType + "> resp = baseExecute();\n" +
655+
" resp.setValueType(" + returnType + ".class);\n" +
656+
" return resp;\n" +
657+
" }\n\n" +
658+
" /**\n" +
659+
" * Execute the query with custom headers, there must be an equal number of keys and values\n" +
660+
" * or else an error will be generated.\n" +
661+
" * @param headers an array of header keys\n" +
662+
" * @param values an array of header values\n" +
663+
" * @return the query response object.\n" +
664+
" * @throws Exception\n" +
665+
" */\n" +
654666
" @Override\n" +
655-
" public Response<" + returnType + "> execute() throws Exception {\n" +
656-
" Response<" + returnType + "> resp = baseExecute();\n" +
657-
" resp.setValueType(" + returnType + ".class);\n" +
658-
" return resp;\n" +
659-
" }\n\n";
667+
" public Response<" + returnType + "> execute(String[] headers, String[] values) throws Exception {\n" +
668+
" Response<" + returnType + "> resp = baseExecute(headers, values);\n" +
669+
" resp.setValueType(" + returnType + ".class);\n" +
670+
" return resp;\n" +
671+
" }\n\n";
660672
return ret;
661673
}
662674

@@ -754,7 +766,7 @@ public void close () {
754766

755767
if (!modelPropertyAdded) {
756768
// No file should be generated
757-
// There are some alias types in one spec file, which
769+
// There are some alias types in one spec file, which
758770
// are in contradiction with real types in the other spec file.
759771
// We don't want the alias type file to corrupt the real type object.
760772
return;

generator/src/main/java/com/algorand/sdkutils/listeners/Publisher.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashSet;
66

77
import com.algorand.sdkutils.listeners.Publisher.Events;
8+
import com.algorand.sdkutils.utils.QueryDef;
89
import com.algorand.sdkutils.utils.StructDef;
910
import com.algorand.sdkutils.utils.TypeDef;
1011
import com.fasterxml.jackson.databind.JsonNode;
@@ -64,15 +65,15 @@ public void publish(Events event) {
6465
}
6566
}
6667
}
67-
68-
public void publish(Events event, String [] notes) {
68+
69+
public void publish(Events event, QueryDef query) {
6970
if (subscribers.get(event) != null) {
7071
for (Subscriber subscriber : subscribers.get(event)) {
71-
subscriber.onEvent(event, notes);
72+
subscriber.onEvent(event, query);
7273
}
7374
}
7475
}
75-
76+
7677
public void publish(Events event, StructDef sDef) {
7778
if (subscribers.get(event) != null) {
7879
for (Subscriber subscriber : subscribers.get(event)) {

0 commit comments

Comments
 (0)