use of org.entando.entando.aps.system.services.api.model.ApiMethod 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.ApiMethod in project entando-core by entando.
the class ApiCatalogDAO method loadApiStatus.
@Override
public void loadApiStatus(Map<String, ApiResource> resources) {
Connection conn = null;
PreparedStatement stat = null;
ResultSet res = null;
try {
conn = this.getConnection();
conn.setAutoCommit(false);
stat = conn.prepareStatement(LOAD_API_STATUS);
// resourcecode, httpmethod, isactive, authenticationrequired, authorizationrequired
// "SELECT method, isactive FROM apicatalog_status";
res = stat.executeQuery();
while (res.next()) {
String resourceCode = res.getString("resourcecode");
String httpMethodString = res.getString("httpmethod");
ApiMethod.HttpMethod httpMethod = Enum.valueOf(ApiMethod.HttpMethod.class, httpMethodString.toUpperCase());
ApiMethod method = null;
ApiResource resource = resources.get(resourceCode);
if (null != resource) {
method = resource.getMethod(httpMethod);
}
if (null == method) {
this.resetApiStatus(resourceCode, httpMethod, conn);
continue;
}
boolean active = (res.getInt("isactive") == 1);
method.setStatus(active);
boolean authenticationRequired = (res.getInt("authenticationrequired") == 1);
method.setRequiredAuth(authenticationRequired);
String requiredPermission = res.getString("authorizationrequired");
if (null != requiredPermission && requiredPermission.trim().length() > 0) {
method.setRequiredPermission(requiredPermission);
} else {
method.setRequiredPermission(null);
}
boolean hidden = (res.getInt("ishidden") == 1);
method.setHidden(hidden);
}
conn.commit();
} catch (Throwable t) {
this.executeRollback(conn);
_logger.error("Error while loading api status", t);
throw new RuntimeException("Error while loading api status", t);
} finally {
closeDaoResources(res, stat, conn);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod 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.ApiMethod in project entando-core by entando.
the class ApiServiceCacheWrapper method buildApiGetMethods.
protected List<ApiMethod> buildApiGetMethods(Map<String, ApiResource> resources) {
List<ApiMethod> apiGETMethods = new ArrayList<>();
List<ApiResource> resourceList = new ArrayList<>(resources.values());
for (int i = 0; i < resourceList.size(); i++) {
ApiResource apiResource = resourceList.get(i);
if (null != apiResource.getGetMethod()) {
apiGETMethods.add(apiResource.getGetMethod());
}
}
return apiGETMethods;
}
use of org.entando.entando.aps.system.services.api.model.ApiMethod in project entando-core by entando.
the class TestApiI18nLabelInterface method testGetLabel.
protected JAXBI18nLabel testGetLabel(MediaType mediaType, String username, String key) throws Throwable {
ApiResource contentResource = this.getApiCatalogManager().getResource("core", "i18nlabel");
ApiMethod getMethod = contentResource.getGetMethod();
Properties properties = super.createApiProperties(username, "en", mediaType);
properties.put("key", key);
Object result = this.getResponseBuilder().createResponse(getMethod, properties);
assertNotNull(result);
ApiI18nLabelInterface apiLabelInterface = (ApiI18nLabelInterface) this.getApplicationContext().getBean("ApiI18nLabelInterface");
Object singleResult = apiLabelInterface.getLabel(properties);
assertNotNull(singleResult);
String toString = this.marshall(singleResult, mediaType);
InputStream stream = new ByteArrayInputStream(toString.getBytes());
JAXBI18nLabel jaxbLabel = (JAXBI18nLabel) UnmarshalUtils.unmarshal(super.getApplicationContext(), JAXBI18nLabel.class, stream, mediaType);
assertNotNull(jaxbLabel);
return jaxbLabel;
}
Aggregations