use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ApiServiceAction method save.
/**
* Save an api service.
*
* @return The result code.
*/
public String save() {
try {
String key = this.getServiceKey().trim();
ApiMethod masterMethod = this.getMethod(this.getNamespace(), this.getResourceName());
String[] freeParams = null;
if (null != this.getFreeParameters()) {
freeParams = new String[this.getFreeParameters().size()];
for (int i = 0; i < this.getFreeParameters().size(); i++) {
freeParams[i] = this.getFreeParameters().get(i);
}
}
ApiService service = new ApiService(key, this.getDescriptions(), masterMethod, this.getApiParameterValues(), freeParams, this.getTag(), !this.isHiddenService(), this.isActiveService());
service.setRequiredAuth(this.getRequiredAuth());
if (null != this.getRequiredGroup() && this.getRequiredGroup().trim().length() > 0) {
service.setRequiredGroup(this.getRequiredGroup());
}
if (null != this.getRequiredPermission() && this.getRequiredPermission().trim().length() > 0) {
service.setRequiredPermission(this.getRequiredPermission());
}
this.getApiCatalogManager().saveService(service);
} catch (Throwable t) {
_logger.error("error in save", t);
return FAILURE;
}
return SUCCESS;
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class SchemaGeneratorActionHelper method extractReturnType.
protected Class extractReturnType(ApiMethod method, HttpServletRequest request) throws ApsSystemException {
Class returnType = null;
try {
Object bean = ApsWebApplicationUtils.getBean(method.getSpringBean(), request);
if (null == bean) {
throw new ApsSystemException("Null bean '" + method.getSpringBean() + "' from method " + method.getHttpMethod() + " of resource " + method.getResourceName());
}
Class beanClass = bean.getClass();
String methodName = method.getSpringBeanMethod();
Method beanMethod = null;
if (method.getHttpMethod().equals(ApiMethod.HttpMethod.GET) || method.getHttpMethod().equals(ApiMethod.HttpMethod.DELETE)) {
Class[] parameterTypes = new Class[] { Properties.class };
beanMethod = beanClass.getDeclaredMethod(methodName, parameterTypes);
} else {
Class expectedType = method.getExpectedType();
if (null == expectedType) {
throw new ApsSystemException("Null expectedType for Method " + method.getHttpMethod() + " for resource " + method.getResourceName());
}
try {
// special case - put or post method with properties
Class[] parameterTypes = new Class[] { expectedType, Properties.class };
beanMethod = beanClass.getDeclaredMethod(methodName, parameterTypes);
} catch (Exception e) {
// nothing to catch
}
if (null == beanMethod) {
Class[] parameterTypes2 = new Class[] { expectedType };
beanMethod = beanClass.getDeclaredMethod(methodName, parameterTypes2);
}
}
if (null != beanMethod) {
returnType = beanMethod.getReturnType();
}
if (null != returnType && returnType.getName().equals("void")) {
return null;
}
} catch (Throwable t) {
_logger.error("Error extracting return type", t);
// ApsSystemUtils.logThrowable(t, this, "extractReturnType", "Error extracting return type ");
return null;
}
return returnType;
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ApiServiceFinderAction method buildServiceGroups.
private void buildServiceGroups(Map<String, List<ApiSelectItem>> groups) throws Throwable {
try {
Map<String, ApiService> serviceMap = this.getApiCatalogManager().getServices();
if (null == serviceMap || serviceMap.isEmpty())
return;
Iterator<ApiService> services = serviceMap.values().iterator();
while (services.hasNext()) {
ApiService apiService = services.next();
if (this.includeServiceIntoMapping(apiService)) {
ApiMethod masterMethod = apiService.getMaster();
String pluginCode = masterMethod.getPluginCode();
if (null != pluginCode && pluginCode.trim().length() > 0) {
this.addService(pluginCode, apiService, groups);
} else if (masterMethod.getSource().equals("core")) {
this.addService(masterMethod.getSource(), apiService, groups);
} else {
this.addService("custom", apiService, groups);
}
}
}
} catch (Throwable t) {
_logger.error("error in buildServiceGroups", t);
// ApsSystemUtils.logThrowable(t, this, "buildServiceGroups");
throw t;
}
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ResponseBuilder method invokeDeleteMethod.
private Object invokeDeleteMethod(ApiMethod api, Object bean, Properties parameters) throws NoSuchMethodException, InvocationTargetException, Throwable {
Class[] parameterTypes = new Class[] { Properties.class };
Class beanClass = bean.getClass();
String methodName = api.getSpringBeanMethod();
Method method = beanClass.getDeclaredMethod(methodName, parameterTypes);
return method.invoke(bean, parameters);
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class ResponseBuilder method invokeGetMethod.
protected Object invokeGetMethod(ApiMethod apiMethod, Object bean, String methodSuffix, Properties parameters, boolean throwException) throws ApiException, Throwable {
String methodName = null;
Object result = null;
try {
Class[] parameterTypes = new Class[] { Properties.class };
Class beanClass = bean.getClass();
methodName = (null != methodSuffix) ? apiMethod.getSpringBeanMethod() + methodSuffix.trim() : apiMethod.getSpringBeanMethod();
Method method = beanClass.getDeclaredMethod(methodName, parameterTypes);
result = method.invoke(bean, parameters);
} catch (NoSuchMethodException e) {
if (throwException) {
_logger.error("No such method '{}' of class '{}'", methodName, bean.getClass(), e);
throw new ApiException(IApiErrorCodes.API_METHOD_ERROR, "Method not supported - " + this.buildApiSignature(apiMethod), Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof ApiException) {
throw (ApiException) e.getTargetException();
} else if (throwException) {
_logger.error("Error invoking method '{}' of class '{}'", methodName, bean.getClass());
throw new ApiException(IApiErrorCodes.API_METHOD_ERROR, "Error invoking Method - " + this.buildApiSignature(apiMethod), Response.Status.INTERNAL_SERVER_ERROR);
}
} catch (Throwable t) {
if (throwException) {
_logger.error("Error invoking method - {} {} of class '{}'", this.buildApiSignature(apiMethod), methodName, bean.getClass(), t);
throw t;
}
}
return result;
}
Aggregations