public ApiResource getResource(String namespace, String resourceName) throws ApsSystemException { try { if (null == this.getMasterResources()) { this.loadResources(); } String resourceCode = this.getResourceCode(namespace, resourceName); ApiResource apiResource = this.getMasterResources().get(resourceCode); if (null != apiResource) { return apiResource.clone(); } } catch (Throwable t) { ApsSystemUtils.logThrowable( t, this, "getApiResource", "Error extracting resource by name '" + resourceName + "'"); throw new ApsSystemException("Error extracting resource", t); } return null; }
public Map<String, ApiResource> getResources() throws ApsSystemException { Map<String, ApiResource> clonedApiResources = new HashMap<String, ApiResource>(); try { if (null == this.getMasterResources()) { this.loadResources(); } Iterator<String> iterator = this.getMasterResources().keySet().iterator(); while (iterator.hasNext()) { String resourceFullCode = iterator.next(); ApiResource resource = this.getMasterResources().get(resourceFullCode); clonedApiResources.put(resourceFullCode, resource.clone()); } } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "getApiResources", "Error extracting resources"); throw new ApsSystemException("Error extracting resources", t); } return clonedApiResources; }
protected ApiMethod getMasterMethod( ApiMethod.HttpMethod httpMethod, String namespace, String resourceName) throws ApsSystemException { try { if (null == this.getMasterResources()) { this.loadResources(); } String resourceCode = this.getResourceCode(namespace, resourceName); ApiResource resource = this.getMasterResources().get(resourceCode); if (null != resource) { return resource.getMethod(httpMethod); } } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "getMasterMethod", "Error extracting methods"); throw new ApsSystemException("Error extracting methods", t); } return null; }
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); // resource, httpmethod, isactive, authenticationrequired, authorizationrequired // "SELECT method, isactive FROM apicatalog_status"; res = stat.executeQuery(); while (res.next()) { String resourceName = res.getString("resource"); String httpMethodString = res.getString("httpmethod"); ApiMethod.HttpMethod httpMethod = Enum.valueOf(ApiMethod.HttpMethod.class, httpMethodString.toUpperCase()); ApiMethod method = null; ApiResource resource = resources.get(resourceName); if (null != resource) { method = resource.getMethod(httpMethod); } if (null == method) { this.resetApiStatus(resourceName, 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); } } conn.commit(); } catch (Throwable t) { this.executeRollback(conn); processDaoException(t, "Error while loading api status ", "loadApiStatus"); } finally { closeDaoResources(res, stat, conn); } }
protected void loadServices() throws ApsSystemException { try { if (null == this.getMasterResources()) { this.loadResources(); } List<ApiMethod> apiGETMethods = new ArrayList<ApiMethod>(); List<ApiResource> resourceList = new ArrayList<ApiResource>(this.getMasterResources().values()); for (int i = 0; i < resourceList.size(); i++) { ApiResource apiResource = resourceList.get(i); if (null != apiResource.getGetMethod()) { apiGETMethods.add(apiResource.getGetMethod()); } } this.setMasterServices(this.getApiCatalogDAO().loadServices(apiGETMethods)); } catch (Throwable t) { this.setMasterServices(new HashMap<String, ApiService>()); ApsSystemUtils.logThrowable(t, this, "loadServices", "Error loading Services definitions"); throw new ApsSystemException("Error loading Services definitions", t); } }
protected List<ApiMethod> getMasterMethods(ApiMethod.HttpMethod httpMethod) throws ApsSystemException { List<ApiMethod> apiMethods = new ArrayList<ApiMethod>(); try { if (null == this.getMasterResources()) { this.loadResources(); } List<ApiResource> resourceList = new ArrayList<ApiResource>(this.getMasterResources().values()); for (int i = 0; i < resourceList.size(); i++) { ApiResource apiResource = resourceList.get(i); if (null != apiResource.getMethod(httpMethod)) { apiMethods.add(apiResource.getMethod(httpMethod)); } } } catch (Throwable t) { ApsSystemUtils.logThrowable( t, this, "getMasterMethods", "Error loading Master Methods definitions"); throw new ApsSystemException("Error loading Master Methods definitions", t); } return apiMethods; }
private String getResourceCode(String namespace, String resourceName) { return ApiResource.getCode(namespace, resourceName); }