use of org.apache.cloudstack.api.response.ApiDiscoveryResponse in project cloudstack by apache.
the class ApiDiscoveryServiceImpl method getCmdRequestMap.
private ApiDiscoveryResponse getCmdRequestMap(Class<?> cmdClass, APICommand apiCmdAnnotation) {
String apiName = apiCmdAnnotation.name();
ApiDiscoveryResponse response = new ApiDiscoveryResponse();
response.setName(apiName);
response.setDescription(apiCmdAnnotation.description());
if (!apiCmdAnnotation.since().isEmpty()) {
response.setSince(apiCmdAnnotation.since());
}
Set<Field> fields = ReflectUtil.getAllFieldsForClass(cmdClass, new Class<?>[] { BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class });
boolean isAsync = ReflectUtil.isCmdClassAsync(cmdClass, new Class<?>[] { BaseAsyncCmd.class, BaseAsyncCreateCmd.class });
response.setAsync(isAsync);
for (Field field : fields) {
Parameter parameterAnnotation = field.getAnnotation(Parameter.class);
if (parameterAnnotation != null && parameterAnnotation.expose() && parameterAnnotation.includeInApiDoc()) {
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;
}
use of org.apache.cloudstack.api.response.ApiDiscoveryResponse in project cloudstack by apache.
the class ApiDiscoveryServiceImpl method listApis.
@Override
public ListResponse<? extends BaseResponse> listApis(User user, String name) {
ListResponse<ApiDiscoveryResponse> response = new ListResponse<ApiDiscoveryResponse>();
List<ApiDiscoveryResponse> responseList = new ArrayList<ApiDiscoveryResponse>();
if (user == null)
return null;
if (name != null) {
if (!s_apiNameDiscoveryResponseMap.containsKey(name))
return null;
for (APIChecker apiChecker : _apiAccessCheckers) {
try {
apiChecker.checkAccess(user, name);
} catch (Exception ex) {
s_logger.debug("API discovery access check failed for " + name + " with " + ex.getMessage());
return null;
}
}
responseList.add(s_apiNameDiscoveryResponseMap.get(name));
} else {
for (String apiName : s_apiNameDiscoveryResponseMap.keySet()) {
boolean isAllowed = true;
for (APIChecker apiChecker : _apiAccessCheckers) {
try {
apiChecker.checkAccess(user, apiName);
} catch (Exception ex) {
isAllowed = false;
}
}
if (isAllowed)
responseList.add(s_apiNameDiscoveryResponseMap.get(apiName));
}
}
response.setResponses(responseList);
return response;
}
Aggregations