Search in sources :

Example 6 with ApiService

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

the class ApiServiceInterface method getService.

public Object getService(Properties properties) throws ApiException {
    Object response = null;
    String key = (String) properties.get("key");
    try {
        ApiService service = this.getApiCatalogManager().getApiService(key);
        if (null == service) {
            throw new ApiException(IApiErrorCodes.API_SERVICE_INVALID, "Service '" + key + "' does not exist");
        }
        if (!service.isActive()) {
            throw new ApiException(IApiErrorCodes.API_SERVICE_ACTIVE_FALSE, "Service '" + key + "' is not active");
        }
        this.checkServiceAuthorization(service, properties, true);
        Properties serviceParameters = new Properties();
        serviceParameters.putAll(service.getParameters());
        Iterator<Object> paramIter = properties.keySet().iterator();
        List<String> reservedParameters = Arrays.asList(SystemConstants.API_RESERVED_PARAMETERS);
        while (paramIter.hasNext()) {
            Object paramName = paramIter.next();
            String paramNameString = paramName.toString();
            if (reservedParameters.contains(paramNameString) || service.isFreeParameter(paramNameString)) {
                serviceParameters.put(paramNameString, properties.get(paramName));
            }
        }
        response = this.getResponseBuilder().createResponse(service.getMaster(), serviceParameters);
    } catch (ApiException e) {
        throw e;
    } catch (Throwable t) {
        _logger.error("Error invocating service - key '{}'", key, t);
        throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
    }
    return response;
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 7 with ApiService

use of org.entando.entando.aps.system.services.api.model.ApiService 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;
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Example 8 with ApiService

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

the class ApiServiceAction method edit.

/**
 * Edit an exist api service.
 *
 * @return The result code.
 */
public String edit() {
    try {
        String check = this.checkService();
        if (null != check) {
            return check;
        }
        ApiService apiService = this.getApiService(this.getServiceKey());
        this.setApiParameters(apiService.getMaster().getParameters());
        this.setResourceName(apiService.getMaster().getResourceName());
        this.setNamespace(apiService.getMaster().getNamespace());
        this.setApiParameterValues(apiService.getParameters());
        this.setDescriptions(apiService.getDescription());
        this.setHiddenService(apiService.isHidden());
        this.setActiveService(apiService.isActive());
        // this.setMyEntandoService(apiService.isMyEntando());
        this.setServiceKey(apiService.getKey());
        if (null != apiService.getFreeParameters()) {
            List<String> freeParams = Arrays.asList(apiService.getFreeParameters());
            this.setFreeParameters(freeParams);
        }
        this.setTag(apiService.getTag());
        this.setRequiredAuth(apiService.getRequiredAuth());
        this.setRequiredGroup(apiService.getRequiredGroup());
        this.setRequiredPermission(apiService.getRequiredPermission());
        this.setStrutsAction(ApsAdminSystemConstants.EDIT);
    } catch (Throwable t) {
        _logger.error("error in edit", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService)

Example 9 with ApiService

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

the class ApiServiceAction method generateResponseBodySchema.

public String generateResponseBodySchema() {
    try {
        String result = this.checkService();
        if (null != result) {
            return result;
        }
        ApiService apiService = this.getApiService(this.getServiceKey());
        return super.generateResponseBodySchema(apiService.getMaster());
    } catch (Throwable t) {
        _logger.error("Error extracting response body Schema", t);
        return FAILURE;
    }
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService)

Example 10 with ApiService

use of org.entando.entando.aps.system.services.api.model.ApiService 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;
    }
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Aggregations

ApiService (org.entando.entando.aps.system.services.api.model.ApiService)15 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)5 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ApsProperties (com.agiletec.aps.util.ApsProperties)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 List (java.util.List)1 Properties (java.util.Properties)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 ServiceInfo (org.entando.entando.aps.system.services.api.model.ServiceInfo)1 ApiSelectItem (org.entando.entando.apsadmin.api.model.ApiSelectItem)1 Before (org.junit.Before)1 Cache (org.springframework.cache.Cache)1 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)1