Search in sources :

Example 11 with ApiService

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

the class ApiCatalogManager method updateService.

@Override
public void updateService(ApiService service) throws ApsSystemException {
    try {
        if (null == service) {
            throw new ApsSystemException("Null api service to update");
        }
        ApiService masterService = this.getServiceCacheWrapper().getMasterServices().get(service.getKey());
        if (null == masterService) {
            throw new ApsSystemException("Api service '" + service.getKey() + "' does not exist");
        }
        masterService.setActive(service.isActive());
        masterService.setHidden(service.isHidden());
        this.getApiCatalogDAO().updateService(masterService);
        this.getServiceCacheWrapper().updateService(service);
    } catch (Throwable t) {
        logger.error("Error updating api service with key '{}'", service.getKey(), t);
        throw new ApsSystemException("Error updating service '" + service.getKey() + "'", t);
    }
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 12 with ApiService

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

the class ApiServiceInterface method getServices.

public ArrayList<ServiceInfo> getServices(Properties properties) throws ApiException {
    ArrayList<ServiceInfo> services = new ArrayList<ServiceInfo>();
    try {
        String defaultLangCode = this.getLangManager().getDefaultLang().getCode();
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        String tagParamValue = properties.getProperty("tag");
        // String myentandoParamValue = properties.getProperty("myentando");
        // Boolean myentando = (null != myentandoParamValue && myentandoParamValue.trim().length() > 0) ? Boolean.valueOf(myentandoParamValue) : null;
        langCode = (null != langCode && null != this.getLangManager().getLang(langCode)) ? langCode : defaultLangCode;
        Map<String, ApiService> masterServices = this.getApiCatalogManager().getServices(tagParamValue);
        Iterator<ApiService> iter = masterServices.values().iterator();
        while (iter.hasNext()) {
            ApiService service = (ApiService) iter.next();
            if (service.isActive() && !service.isHidden() && this.checkServiceAuthorization(service, properties, false)) {
                ServiceInfo smallService = this.createServiceInfo(service, langCode, defaultLangCode);
                services.add(smallService);
            }
        }
        BeanComparator comparator = new BeanComparator("description");
        Collections.sort(services, comparator);
    } catch (Throwable t) {
        _logger.error("Error extracting services", t);
        throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
    }
    return services;
}
Also used : ServiceInfo(org.entando.entando.aps.system.services.api.model.ServiceInfo) ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 13 with ApiService

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

the class ApiServiceCacheWrapper method removeService.

@Override
public void removeService(String key) {
    ApiService apiService = this.get(this.getCacheKeyPrefix() + key, ApiService.class);
    this.manage(key, apiService, Action.DELETE);
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService)

Example 14 with ApiService

use of org.entando.entando.aps.system.services.api.model.ApiService 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 15 with ApiService

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

the class ApiServiceFinderAction method updateAllStatusOfGroup.

public String updateAllStatusOfGroup() {
    try {
        if (this.getServiceGroup() == null) {
            this.addActionMessage(this.getText("error.service.group.required"));
            return INPUT;
        }
        Map<String, List<ApiSelectItem>> groups = this.getServiceFlavours();
        List<ApiSelectItem> group = groups.get(this.getServiceGroup());
        if (group == null) {
            this.addActionMessage(this.getText("error.service.group.invalid"));
            return INPUT;
        }
        for (int i = 0; i < group.size(); i++) {
            ApiSelectItem serviceItem = group.get(i);
            ApiService service = this.getApiCatalogManager().getApiService(serviceItem.getKey());
            boolean activeService = (this.getRequest().getParameter(service.getKey() + "_active") != null);
            boolean publicService = (this.getRequest().getParameter(service.getKey() + "_public") != null);
            if (activeService != service.isActive() || publicService != !service.isHidden()) {
                service.setActive(activeService);
                service.setHidden(!publicService);
                this.getApiCatalogManager().updateService(service);
                this.addActionMessage(this.getText("message.service.status.updated", new String[] { serviceItem.getKey(), serviceItem.getValue() }));
                _logger.info("Updated api service status - Service Key '{}'", serviceItem.getKey());
            }
        }
    } catch (Throwable t) {
        _logger.error("error in updateAllStatusOfGroup", t);
        // ApsSystemUtils.logThrowable(t, this, "updateAllStatusOfGroup");
        return FAILURE;
    }
    return SUCCESS;
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ArrayList(java.util.ArrayList) List(java.util.List) ApiSelectItem(org.entando.entando.apsadmin.api.model.ApiSelectItem)

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