use of org.apache.cloudstack.api.response.ApiResponseResponse in project cloudstack by apache.
the class ApiDiscoveryServiceImpl method getFieldResponseMap.
private ApiResponseResponse getFieldResponseMap(Field responseField) {
ApiResponseResponse responseResponse = new ApiResponseResponse();
SerializedName serializedName = responseField.getAnnotation(SerializedName.class);
Param param = responseField.getAnnotation(Param.class);
if (serializedName != null && param != null) {
responseResponse.setName(serializedName.value());
responseResponse.setDescription(param.description());
responseResponse.setType(responseField.getType().getSimpleName().toLowerCase());
//If response is not of primitive type - we have a nested entity
Class fieldClass = param.responseObject();
if (fieldClass != null) {
Class<?> superClass = fieldClass.getSuperclass();
if (superClass != null) {
String superName = superClass.getName();
if (superName.equals(BaseResponse.class.getName())) {
Field[] fields = fieldClass.getDeclaredFields();
for (Field field : fields) {
ApiResponseResponse innerResponse = getFieldResponseMap(field);
if (innerResponse != null) {
responseResponse.addApiResponse(innerResponse);
}
}
}
}
}
}
return responseResponse;
}
use of org.apache.cloudstack.api.response.ApiResponseResponse in project cloudstack by apache.
the class ApiDiscoveryServiceImpl method cacheResponseMap.
protected Map<String, List<String>> cacheResponseMap(Set<Class<?>> cmdClasses) {
Map<String, List<String>> responseApiNameListMap = new HashMap<String, List<String>>();
for (Class<?> cmdClass : cmdClasses) {
APICommand apiCmdAnnotation = cmdClass.getAnnotation(APICommand.class);
if (apiCmdAnnotation == null) {
apiCmdAnnotation = cmdClass.getSuperclass().getAnnotation(APICommand.class);
}
if (apiCmdAnnotation == null || !apiCmdAnnotation.includeInApiDoc() || apiCmdAnnotation.name().isEmpty()) {
continue;
}
String apiName = apiCmdAnnotation.name();
if (s_logger.isTraceEnabled()) {
s_logger.trace("Found api: " + apiName);
}
ApiDiscoveryResponse response = getCmdRequestMap(cmdClass, apiCmdAnnotation);
String responseName = apiCmdAnnotation.responseObject().getName();
if (!responseName.contains("SuccessResponse")) {
if (!responseApiNameListMap.containsKey(responseName)) {
responseApiNameListMap.put(responseName, new ArrayList<String>());
}
responseApiNameListMap.get(responseName).add(apiName);
}
response.setRelated(responseName);
Field[] responseFields = apiCmdAnnotation.responseObject().getDeclaredFields();
for (Field responseField : responseFields) {
ApiResponseResponse responseResponse = getFieldResponseMap(responseField);
response.addApiResponse(responseResponse);
}
response.setObjectName("api");
s_apiNameDiscoveryResponseMap.put(apiName, response);
}
for (String apiName : s_apiNameDiscoveryResponseMap.keySet()) {
ApiDiscoveryResponse response = s_apiNameDiscoveryResponseMap.get(apiName);
Set<ApiParameterResponse> processedParams = new HashSet<ApiParameterResponse>();
for (ApiParameterResponse param : response.getParams()) {
if (responseApiNameListMap.containsKey(param.getRelated())) {
List<String> relatedApis = responseApiNameListMap.get(param.getRelated());
param.setRelated(StringUtils.join(relatedApis, ","));
} else {
param.setRelated(null);
}
processedParams.add(param);
}
response.setParams(processedParams);
if (responseApiNameListMap.containsKey(response.getRelated())) {
List<String> relatedApis = responseApiNameListMap.get(response.getRelated());
relatedApis.remove(apiName);
response.setRelated(StringUtils.join(relatedApis, ","));
} else {
response.setRelated(null);
}
s_apiNameDiscoveryResponseMap.put(apiName, response);
}
return responseApiNameListMap;
}
Aggregations