Search in sources :

Example 16 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ResponseBuilder method extractApiMethod.

@Override
public ApiMethod extractApiMethod(ApiMethod.HttpMethod httpMethod, String namespace, String resourceName) throws ApiException {
    ApiMethod api = null;
    String signature = this.buildApiSignature(httpMethod, namespace, resourceName);
    try {
        api = this.getApiCatalogManager().getMethod(httpMethod, namespace, resourceName);
        if (null == api) {
            ApiError error = new ApiError(IApiErrorCodes.API_INVALID, signature + " does not exists", Response.Status.NOT_FOUND);
            throw new ApiException(error);
        }
        if (!api.isActive()) {
            ApiError error = new ApiError(IApiErrorCodes.API_INVALID, signature + " does not exists", Response.Status.NOT_FOUND);
            throw new ApiException(error);
        }
    } catch (ApiException ae) {
        _logger.error("Error extracting api method {}", this.buildApiSignature(httpMethod, namespace, resourceName), ae);
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting api method {}", this.buildApiSignature(httpMethod, namespace, resourceName), t);
        throw new ApiException(IApiErrorCodes.SERVER_ERROR, signature + " is not supported", Response.Status.INTERNAL_SERVER_ERROR);
    }
    return api;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 17 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ResponseBuilder method invokePutPostMethod.

private Object invokePutPostMethod(ApiMethod api, Object bean, Properties parameters, Object bodyObject) throws NoSuchMethodException, InvocationTargetException, Throwable {
    Object result = null;
    Class beanClass = bean.getClass();
    String methodName = api.getSpringBeanMethod();
    try {
        Class[] parameterTypes = new Class[] { bodyObject.getClass(), Properties.class };
        Method method = beanClass.getDeclaredMethod(methodName, parameterTypes);
        result = method.invoke(bean, bodyObject, parameters);
    } catch (NoSuchMethodException e) {
        // the first exception of type "NoSuchMethodException" will not catched... the second yes
        Class[] parameterTypes = new Class[] { bodyObject.getClass() };
        Method method = beanClass.getDeclaredMethod(methodName, parameterTypes);
        result = method.invoke(bean, bodyObject);
    } catch (InvocationTargetException e) {
        throw e;
    } catch (Throwable t) {
        throw t;
    }
    return result;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Method(java.lang.reflect.Method) Properties(java.util.Properties) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ApiCatalogManager method getMethods.

@Deprecated
@Override
public Map<String, ApiMethod> getMethods() throws ApsSystemException {
    Map<String, ApiMethod> map = new HashMap<>();
    List<ApiMethod> list = this.getMethods(ApiMethod.HttpMethod.GET);
    for (int i = 0; i < list.size(); i++) {
        ApiMethod apiMethod = list.get(i);
        map.put(apiMethod.getResourceName(), apiMethod);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Example 19 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ApiCatalogManager method saveService.

@Override
public void saveService(ApiService service) throws ApsSystemException {
    try {
        if (null == service) {
            throw new ApsSystemException("Null api service to save");
        }
        ApiMethod master = service.getMaster();
        if (null == master || null == this.getMethod(master.getHttpMethod(), master.getNamespace(), master.getResourceName())) {
            throw new ApsSystemException("null or invalid master method of service to save");
        }
        if (null != this.getServiceCacheWrapper().getMasterServices().get(service.getKey())) {
            this.getApiCatalogDAO().updateService(service);
        } else {
            this.getApiCatalogDAO().addService(service);
        }
        this.getServiceCacheWrapper().addService(service);
    } catch (Throwable t) {
        logger.error("Error saving service", t);
        throw new ApsSystemException("Error saving service", t);
    }
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 20 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.

the class ApiResourcesDefDOM method getResources.

public Map<String, ApiResource> getResources() {
    Map<String, ApiResource> apiResources = new HashMap<String, ApiResource>();
    try {
        List<Element> methodElements = this._doc.getRootElement().getChildren(METHOD_ELEMENT_NAME);
        if (null != methodElements) {
            for (int i = 0; i < methodElements.size(); i++) {
                Element methodElement = methodElements.get(i);
                ApiMethod apiMethod = new ApiMethod(methodElement);
                ApiResource resource = new ApiResource();
                resource.setResourceName(apiMethod.getResourceName());
                resource.setNamespace(apiMethod.getNamespace());
                resource.setDescription(apiMethod.getDescription());
                resource.setPluginCode(apiMethod.getPluginCode());
                resource.setSource(apiMethod.getSource());
                resource.setMethod(apiMethod);
                this.checkResource(resource, apiResources);
            }
        }
        List<Element> resourceElements = this._doc.getRootElement().getChildren(RESOURCE_ELEMENT_NAME);
        if (null != resourceElements) {
            for (int j = 0; j < resourceElements.size(); j++) {
                Element resourceElement = resourceElements.get(j);
                String resourceName = resourceElement.getAttributeValue(RESOURCE_ATTRIBUTE_NAME);
                String namespace = resourceElement.getAttributeValue(RESOURCE_ATTRIBUTE_NAMESPACE);
                Element descriptionElement = resourceElement.getChild(RESOURCE_DESCRIPTION_ELEMENT_NAME);
                String resourceDescription = (null != descriptionElement) ? descriptionElement.getText() : null;
                Element sourceElement = resourceElement.getChild(ApiResourcesDefDOM.SOURCE_ELEMENT_NAME);
                String source = null;
                String pluginCode = null;
                if (null != sourceElement) {
                    source = sourceElement.getText();
                    pluginCode = sourceElement.getAttributeValue(PLUGIN_CODE_ATTRIBUTE_NAME);
                }
                ApiResource resource = new ApiResource();
                resource.setResourceName(resourceName);
                resource.setNamespace(namespace);
                resource.setDescription(resourceDescription);
                resource.setPluginCode(pluginCode);
                resource.setSource(source);
                List<Element> resourceMethodElements = resourceElement.getChildren(METHOD_ELEMENT_NAME);
                for (int k = 0; k < resourceMethodElements.size(); k++) {
                    Element methodElement = resourceMethodElements.get(k);
                    ApiMethod apiMethod = new ApiMethod(resourceName, namespace, source, pluginCode, methodElement);
                    this.checkMethod(apiMethod, resource);
                }
                this.checkResource(resource, apiResources);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error building api resources", t);
    }
    return apiResources;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) HashMap(java.util.HashMap) Element(org.jdom.Element) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Aggregations

ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)40 Properties (java.util.Properties)11 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 ApsProperties (com.agiletec.aps.util.ApsProperties)6 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)6 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)5 ApiService (org.entando.entando.aps.system.services.api.model.ApiService)5 Method (java.lang.reflect.Method)4 HashMap (java.util.HashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 ApiMethodRelatedWidget (org.entando.entando.aps.system.services.api.model.ApiMethodRelatedWidget)3 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2