use of com.cloud.api.response.ApiParameterResponse in project cosmic by MissionCriticalCloud.
the class ApiDiscoveryServiceImpl method cacheResponseMap.
protected Map<String, List<String>> cacheResponseMap(final Set<Class<?>> cmdClasses) {
final Map<String, List<String>> responseApiNameListMap = new HashMap<>();
for (final 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;
}
final String apiName = apiCmdAnnotation.name();
if (s_logger.isTraceEnabled()) {
s_logger.trace("Found api: " + apiName);
}
final ApiDiscoveryResponse response = getCmdRequestMap(cmdClass, apiCmdAnnotation);
final String responseName = apiCmdAnnotation.responseObject().getName();
if (!responseName.contains("SuccessResponse")) {
if (!responseApiNameListMap.containsKey(responseName)) {
responseApiNameListMap.put(responseName, new ArrayList<>());
}
responseApiNameListMap.get(responseName).add(apiName);
}
response.setRelated(responseName);
final Field[] responseFields = apiCmdAnnotation.responseObject().getDeclaredFields();
for (final Field responseField : responseFields) {
final ApiResponseResponse responseResponse = getFieldResponseMap(responseField);
response.addApiResponse(responseResponse);
}
response.setObjectName("api");
s_apiNameDiscoveryResponseMap.put(apiName, response);
}
for (final String apiName : s_apiNameDiscoveryResponseMap.keySet()) {
final ApiDiscoveryResponse response = s_apiNameDiscoveryResponseMap.get(apiName);
final Set<ApiParameterResponse> processedParams = new HashSet<>();
for (final ApiParameterResponse param : response.getParams()) {
if (responseApiNameListMap.containsKey(param.getRelated())) {
final 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())) {
final 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;
}
use of com.cloud.api.response.ApiParameterResponse in project cosmic by MissionCriticalCloud.
the class ApiDiscoveryServiceImpl method getCmdRequestMap.
private ApiDiscoveryResponse getCmdRequestMap(final Class<?> cmdClass, final APICommand apiCmdAnnotation) {
final String apiName = apiCmdAnnotation.name();
final ApiDiscoveryResponse response = new ApiDiscoveryResponse();
response.setName(apiName);
response.setGroupName(apiCmdAnnotation.group().name());
response.setGroupDescription(apiCmdAnnotation.group().toString());
response.setDescription(apiCmdAnnotation.description());
if (!apiCmdAnnotation.since().isEmpty()) {
response.setSince(apiCmdAnnotation.since());
}
final Set<Field> fields = ReflectUtil.getAllFieldsForClass(cmdClass, new Class<?>[] { BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class });
final boolean isAsync = ReflectUtil.isCmdClassAsync(cmdClass, new Class<?>[] { BaseAsyncCmd.class, BaseAsyncCreateCmd.class });
response.setAsync(isAsync);
for (final Field field : fields) {
final Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
if (parameterAnnotation != null && parameterAnnotation.expose() && parameterAnnotation.includeInApiDoc()) {
final ApiParameterResponse paramResponse = new ApiParameterResponse();
paramResponse.setName(parameterAnnotation.name());
paramResponse.setDescription(parameterAnnotation.description());
paramResponse.setType(parameterAnnotation.type().toString().toLowerCase());
paramResponse.setLength(parameterAnnotation.length());
paramResponse.setRequired(parameterAnnotation.required());
if (!parameterAnnotation.since().isEmpty()) {
paramResponse.setSince(parameterAnnotation.since());
}
paramResponse.setRelated(parameterAnnotation.entityType()[0].getName());
response.addParam(paramResponse);
}
}
return response;
}
Aggregations