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);
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations