Search in sources :

Example 31 with ApiMethod

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

the class ApiServiceCacheWrapper method initCache.

@Override
public void initCache(Map<String, ApiResource> resources, IApiCatalogDAO apiCatalogDAO) throws ApsSystemException {
    try {
        Cache cache = this.getCache();
        this.releaseCachedObjects(cache);
        List<ApiMethod> apiGETMethods = buildApiGetMethods(resources);
        Map<String, ApiService> services = apiCatalogDAO.loadServices(apiGETMethods);
        this.insertObjectsOnCache(cache, services);
    } catch (Throwable t) {
        logger.error("Error bootstrapping ApiCatalog cache", t);
        throw new ApsSystemException("Error bootstrapping ApiCatalog cache", t);
    }
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Cache(org.springframework.cache.Cache)

Example 32 with ApiMethod

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

the class ApiCatalogManager method getRelatedMethod.

@Override
public ApiMethod getRelatedMethod(String showletCode) throws ApsSystemException {
    List<ApiMethod> masterMethods = this.getMasterMethods(ApiMethod.HttpMethod.GET);
    for (int i = 0; i < masterMethods.size(); i++) {
        ApiMethod apiMethod = masterMethods.get(i);
        ApiMethodRelatedWidget relatedWidget = apiMethod.getRelatedWidget();
        if (null != relatedWidget && relatedWidget.getWidgetCode().equals(showletCode)) {
            return apiMethod.clone();
        }
    }
    return null;
}
Also used : ApiMethodRelatedWidget(org.entando.entando.aps.system.services.api.model.ApiMethodRelatedWidget) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Example 33 with ApiMethod

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

the class ApiCatalogManager method getRelatedWidgetMethods.

@Override
public Map<String, ApiMethod> getRelatedWidgetMethods() throws ApsSystemException {
    Map<String, ApiMethod> mapping = new HashMap<String, ApiMethod>();
    try {
        List<ApiMethod> masterMethods = this.getMasterMethods(ApiMethod.HttpMethod.GET);
        for (int i = 0; i < masterMethods.size(); i++) {
            ApiMethod apiMethod = masterMethods.get(i);
            ApiMethodRelatedWidget relatedWidget = apiMethod.getRelatedWidget();
            if (null != relatedWidget) {
                String widgetCode = relatedWidget.getWidgetCode();
                if (mapping.containsKey(widgetCode)) {
                    ApiMethod alreadyMapped = mapping.get(widgetCode);
                    logger.error("There is more than one method related whith widget '{}' - Actual mapped '{}'; other method '{}'", widgetCode, alreadyMapped.getResourceName(), apiMethod.getResourceName());
                } else {
                    mapping.put(widgetCode, apiMethod.clone());
                }
            }
        }
    } catch (Throwable t) {
        logger.error("Error loading related widget methods", t);
        throw new ApsSystemException("Error loading related widget methods", t);
    }
    return mapping;
}
Also used : ApiMethodRelatedWidget(org.entando.entando.aps.system.services.api.model.ApiMethodRelatedWidget) HashMap(java.util.HashMap) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 34 with ApiMethod

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

the class ResponseBuilder method createResponse.

@Override
@Deprecated
public Object createResponse(String resourceName, Properties parameters) throws ApsSystemException {
    Object apiResponse = null;
    try {
        ApiMethod method = this.extractApiMethod(ApiMethod.HttpMethod.GET, null, resourceName);
        apiResponse = this.createResponse(method, parameters);
    } catch (ApiException e) {
        _logger.error("Error creating response for method GET, resource '{}'", resourceName, e);
        if (apiResponse == null) {
            apiResponse = new StringApiResponse();
        }
        ((AbstractApiResponse) apiResponse).addErrors(e.getErrors());
    }
    return apiResponse;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 35 with ApiMethod

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

the class ResponseBuilder method invoke.

@Override
@Deprecated
public Object invoke(String resourceName, Properties parameters) throws ApiException, ApsSystemException {
    Object result = null;
    try {
        ApiMethod api = this.extractApiMethod(ApiMethod.HttpMethod.GET, null, resourceName);
        this.checkParameter(api, parameters);
        Object bean = this.extractBean(api);
        result = this.invokeGetMethod(api, bean, "", parameters, true);
    } catch (ApiException ae) {
        _logger.error("Error invoking method GET for resource '{}'", resourceName, ae);
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error invoking method GET for resource '{}'", resourceName, t);
        throw new ApsSystemException("Error invoking method GET for resource '" + resourceName + "'", t);
    }
    return result;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

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