ApiXmlDocWriter: Fix multiple field occurence in apidocs by using set Signed-off-by: Rohit Yadav <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/7d119c01 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/7d119c01 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/7d119c01 Branch: refs/heads/marvin-refactor Commit: 7d119c01466be78a82a538289abd4a5e0eda4e9b Parents: c47c699 Author: Rohit Yadav <[email protected]> Authored: Wed Jan 23 13:50:59 2013 -0800 Committer: Prasanna Santhanam <[email protected]> Committed: Thu Jan 24 17:48:35 2013 +0530 ---------------------------------------------------------------------- server/src/com/cloud/api/doc/ApiXmlDocWriter.java | 20 +++++++-------- 1 files changed, 9 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7d119c01/server/src/com/cloud/api/doc/ApiXmlDocWriter.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java index 84851c3..c3c0cab 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<Field> 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<Argument> setRequestFields(Field[] fields) { + private static ArrayList<Argument> setRequestFields(Set<Field> fields) { ArrayList<Argument> arguments = new ArrayList<Argument>(); - ArrayList<Argument> requiredArguments = new ArrayList<Argument>(); - ArrayList<Argument> optionalArguments = new ArrayList<Argument>(); + Set<Argument> requiredArguments = new HashSet<Argument>(); + Set<Argument> optionalArguments = new HashSet<Argument>(); 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; }
