Search in sources :

Example 1 with ApiService

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

the class ApiServiceCacheWrapperTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    ConcurrentMapCache fakeCache = new ConcurrentMapCache(CACHE_NAME);
    fakeCache.put(IApiServiceCacheWrapper.APICATALOG_SERVICES_CACHE_NAME, new HashMap<String, ApiService>());
    when(springCacheManager.getCache(CACHE_NAME)).thenReturn(fakeCache);
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) ApiService(org.entando.entando.aps.system.services.api.model.ApiService) Before(org.junit.Before)

Example 2 with ApiService

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

the class ApiCatalogDAO method buildService.

private void buildService(Map<String, ApiMethod> methods, Map<String, ApiService> services, List<String> invalidServices, ResultSet res) {
    String key = null;
    try {
        key = res.getString(1);
        String parentCode = res.getString(2);
        ApiMethod masterMethod = methods.get(parentCode);
        if (null != masterMethod) {
            ApsProperties description = new ApsProperties();
            description.loadFromXml(res.getString(3));
            ApsProperties parameters = new ApsProperties();
            parameters.loadFromXml(res.getString(4));
            String tag = res.getString(5);
            String[] freeParameters = null;
            String freeParamString = res.getString(6);
            if (null != freeParamString && freeParamString.trim().length() > 0) {
                ServiceExtraConfigDOM dom = new ServiceExtraConfigDOM(freeParamString);
                freeParameters = dom.extractFreeParameters();
            }
            boolean isActive = (1 == res.getInt(7)) ? true : false;
            boolean isHidden = (1 == res.getInt(8)) ? true : false;
            // boolean isMyEntando = (1 == res.getInt(9)) ? true : false;
            ApiService apiService = new ApiService(key, description, masterMethod, parameters, freeParameters, tag, !isHidden, isActive);
            boolean authRequired = (1 == res.getInt(10)) ? true : false;
            apiService.setRequiredAuth(authRequired);
            String requiredPermission = res.getString(11);
            if (null != requiredPermission && requiredPermission.trim().length() > 0) {
                apiService.setRequiredPermission(requiredPermission);
            }
            String requiredGroup = res.getString(12);
            if (null != requiredGroup && requiredGroup.trim().length() > 0) {
                apiService.setRequiredGroup(requiredGroup);
            }
            services.put(key, apiService);
        } else {
            invalidServices.add(key);
        }
    } catch (Throwable t) {
        _logger.error("Error building service - key '{}'", key, t);
    }
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 3 with ApiService

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

the class ApiCatalogDAO method loadServices.

@Override
public Map<String, ApiService> loadServices(List<ApiMethod> methods) {
    Map<String, ApiMethod> methodMap = new HashMap<String, ApiMethod>();
    for (int i = 0; i < methods.size(); i++) {
        ApiMethod method = methods.get(i);
        String resourceCode = ApiResource.getCode(method.getNamespace(), method.getResourceName());
        methodMap.put(resourceCode, method);
    }
    Map<String, ApiService> services = new HashMap<String, ApiService>();
    Connection conn = null;
    Statement stat = null;
    ResultSet res = null;
    List<String> invalidServices = new ArrayList<String>();
    try {
        conn = this.getConnection();
        stat = conn.createStatement();
        res = stat.executeQuery(LOAD_SERVICES);
        while (res.next()) {
            this.buildService(methodMap, services, invalidServices, res);
        }
    } catch (Throwable t) {
        _logger.error("Error while loading services", t);
        throw new RuntimeException("Error while loading services", t);
    } finally {
        closeDaoResources(res, stat, conn);
    }
    return services;
}
Also used : HashMap(java.util.HashMap) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ResultSet(java.sql.ResultSet)

Example 4 with ApiService

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

the class ApiCatalogManager method getServices.

@Override
public Map<String, ApiService> getServices() throws ApsSystemException {
    Map<String, ApiService> clonedServices = new HashMap<>();
    try {
        if (null != this.getServiceCacheWrapper().getMasterServices()) {
            Iterator<String> servicesIter = this.getServiceCacheWrapper().getMasterServices().keySet().iterator();
            while (servicesIter.hasNext()) {
                String serviceKey = servicesIter.next();
                clonedServices.put(serviceKey, this.getServiceCacheWrapper().getMasterServices().get(serviceKey).clone());
            }
        }
    } catch (Throwable t) {
        logger.error("Error extracting services", t);
        throw new ApsSystemException("Error extracting services", t);
    }
    return clonedServices;
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) HashMap(java.util.HashMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 5 with ApiService

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

the class ApiCatalogManager method getServices.

@Override
public Map<String, ApiService> getServices(String tag) throws ApsSystemException {
    Map<String, ApiService> services = this.getServices();
    if (null == tag || tag.trim().length() == 0) {
        return services;
    }
    Map<String, ApiService> servicesToReturn = new HashMap<>();
    try {
        Iterator<ApiService> iter = services.values().iterator();
        while (iter.hasNext()) {
            ApiService apiService = iter.next();
            String serviceTag = apiService.getTag();
            boolean tagCheck = (null != serviceTag && serviceTag.toLowerCase().indexOf(tag.trim().toLowerCase()) > -1);
            if (tagCheck) {
                servicesToReturn.put(apiService.getKey(), apiService);
            }
        }
    } catch (Throwable t) {
        logger.error("Error extracting services", t);
        throw new ApsSystemException("Error extracting services", t);
    }
    return servicesToReturn;
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) HashMap(java.util.HashMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

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