From a8623bacd73a1b1026df8770be1c6a98bde11ba6 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 23 Jan 2013 13:50:59 -0800 Subject: [PATCH] ApiXmlDocWriter: Fix multiple field occurence in apidocs by using set Signed-off-by: Rohit Yadav --- .../com/cloud/api/doc/ApiXmlDocWriter.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java index 84851c389ad..c3c0cabdf17 100644 --- a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java +++ b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java @@ -28,6 +28,7 @@ import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import com.cloud.utils.IteratorUtil; import com.cloud.utils.ReflectUtil; import org.apache.cloudstack.api.*; import org.apache.log4j.Logger; @@ -135,7 +136,7 @@ public class ApiXmlDocWriter { String commandRoleMask = preProcessedCommand.substring(splitIndex + 1); Class cmdClass = _apiNameCmdClassMap.get(key); if (cmdClass == null) { - System.out.println("Check, Null Value for key: " + key + " preProcessedCommand=" + preProcessedCommand); + System.out.println("Check, is this api part of another build profile? Null value for key: " + key + " preProcessedCommand=" + preProcessedCommand); continue; } String commandName = cmdClass.getName(); @@ -349,7 +350,7 @@ public class ApiXmlDocWriter { apiCommand.setAsync(isAsync); - Field[] fields = ReflectUtil.getAllFieldsForClass(clas, + Set fields = ReflectUtil.getAllFieldsForClass(clas, new Class[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class}); request = setRequestFields(fields); @@ -422,10 +423,10 @@ public class ApiXmlDocWriter { out.writeObject(apiCommand); } - private static ArrayList setRequestFields(Field[] fields) { + private static ArrayList setRequestFields(Set fields) { ArrayList arguments = new ArrayList(); - ArrayList requiredArguments = new ArrayList(); - ArrayList optionalArguments = new ArrayList(); + Set requiredArguments = new HashSet(); + Set optionalArguments = new HashSet(); Argument id = null; for (Field f : fields) { Parameter parameterAnnotation = f.getAnnotation(Parameter.class); @@ -444,7 +445,7 @@ public class ApiXmlDocWriter { reqArg.setSinceVersion(parameterAnnotation.since()); } - if (reqArg.isRequired() == true) { + if (reqArg.isRequired()) { if (parameterAnnotation.name().equals("id")) { id = reqArg; } else { @@ -456,15 +457,12 @@ public class ApiXmlDocWriter { } } - Collections.sort(requiredArguments); - Collections.sort(optionalArguments); - // sort required and optional arguments here if (id != null) { arguments.add(id); } - arguments.addAll(requiredArguments); - arguments.addAll(optionalArguments); + arguments.addAll(IteratorUtil.asSortedList(requiredArguments)); + arguments.addAll(IteratorUtil.asSortedList(optionalArguments)); return arguments; }