diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/README.txt b/modules/distribution/resources/migration-1.8.0_to_1.9.0/README.txt new file mode 100644 index 0000000000..e680d1c65e --- /dev/null +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/README.txt @@ -0,0 +1,51 @@ +Data Migration 1.7.0 to 1.8.0 +============================= + +1. Shutdown AM 1.7.0 if it is running. + +2. Backup your API Manager Databases of your AM 1.7.0 instance. + +3. Execute relevant sql script in in here against your API Manager Database. + +4. Now point same WSO2 Carbon Database(User Store and Registry) and API Manager Databases of your AM 1.7.0 instance to AM 1.8.0. +(Configure AM_1.8.0/repository/datasource/master-datasources.xml to point same databases configured in AM 1.7.0) + +5. Move your synapse configurations to APIM_1.8.0. For that, copy and replace APIM_1.7.0/repository/deployment/server/synapse-configs/default directory to APIM_1.8.0/repository/deployment/server/synapse-configs/default. Do not replace _TokenAPI_.xml, _RevokeAPI_.xml and _AuthorizeAPI_.xml files in the default/api subdirectory + +6. Start AM 1.8.0 and Login. + +7. Copy the /dbscripts/migration-1.7.0_to_1.8.0/swagger-doc-migration directory to (The new directory path will now be /swagger-doc-migration). + +8. Configure swagger-doc-migration/build.xml with the information for the below properties. + + registry.home= Path to AM pack location + username= Username for the AM server + password= Password for the AM server + host= IP of running AM server [In a distributed setup, give the host of the Publisher node] + port= Port of running AM server [In a distributed setup, give the port of the Publisher node] + version= Version of AM server + +9. Go inside swagger-doc-migration/ and execute "ant run". You should get a "BUILD SUCCESSFUL" message if it ran correctly. + +10. To re-index log in to carbon console (ex: http://localhost:9443/carbon) and delete 'lastaccesstime' resource in '/_system/local/repository/components/org.wso2.carbon.registry/indexing' location. For that go to Home-> Resources->Browse and navigate to the above given location. You can delete the 'lastaccesstime' resource by selecting Actions-> Delete + +11. shutdown AM 1.8.0 and delete /repository/conf/solr directory and restart the server. + + +Tenant Migration (Only needs to be done if you are migrating a multi-tenanted setup) +==================================================================================== + +1. Move your tenant synapse configurations to APIM_1.8.0. For that, copy and replace specific folders for tenants(shown as 1,2,...) from APIM_1.7.0/repository/tenants/ to APIM_1.8.0/repository/tenants. Do not replace _TokenAPI_.xml, _RevokeAPI_.xml and _AuthorizeAPI_.xml files in the default/api subdirectory. + +2. Start AM 1.8.0. + +3. Configure swagger-doc-migration/build.xml with the information for the below properties. (swagger-doc-migration folder should be already copied to ) + + registry.home= Path to AM pack location + username= Username for the AM server - respective tenant space + password= Password for the AM server - respective tenant space + host= IP of running AM server [In a distributed setup, give the host of the Publisher node] + port= Port of running AM server [In a distributed setup, give the port of the Publisher node] + version= Version of AM server + +4. Go inside swagger-doc-migration/ and execute "ant run". You should get a "BUILD SUCCESSFUL" message if it ran correctly. diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/h2.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/h2.sql new file mode 100644 index 0000000000..5b59b9119c --- /dev/null +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/h2.sql @@ -0,0 +1 @@ +ALTER TABLE AM_SUBSCRIPTION ADD SUBS_CREATE_STATE VARCHAR(50) DEFAULT 'SUBSCRIBE'; \ No newline at end of file diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/mssql.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/mssql.sql new file mode 100644 index 0000000000..5b59b9119c --- /dev/null +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/mssql.sql @@ -0,0 +1 @@ +ALTER TABLE AM_SUBSCRIPTION ADD SUBS_CREATE_STATE VARCHAR(50) DEFAULT 'SUBSCRIBE'; \ No newline at end of file diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/mysql.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/mysql.sql new file mode 100644 index 0000000000..45e75b01b0 --- /dev/null +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/mysql.sql @@ -0,0 +1 @@ +ALTER TABLE AM_SUBSCRIPTION ADD COLUMN SUBS_CREATE_STATE VARCHAR(50) DEFAULT 'SUBSCRIBE'; \ No newline at end of file diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/oracle.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/oracle.sql new file mode 100644 index 0000000000..638438bf42 --- /dev/null +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/oracle.sql @@ -0,0 +1 @@ +ALTER TABLE AM_APPLICATION GROUP_ID VARCHAR(100); diff --git a/modules/distribution/resources/migration-1.8.0_to_1.9.0/postgresql.sql b/modules/distribution/resources/migration-1.8.0_to_1.9.0/postgresql.sql new file mode 100644 index 0000000000..45e75b01b0 --- /dev/null +++ b/modules/distribution/resources/migration-1.8.0_to_1.9.0/postgresql.sql @@ -0,0 +1 @@ +ALTER TABLE AM_SUBSCRIPTION ADD COLUMN SUBS_CREATE_STATE VARCHAR(50) DEFAULT 'SUBSCRIBE'; \ No newline at end of file diff --git a/modules/distribution/resources/sql/h2.sql b/modules/distribution/resources/sql/h2.sql index b31574261d..b1008f781e 100644 --- a/modules/distribution/resources/sql/h2.sql +++ b/modules/distribution/resources/sql/h2.sql @@ -435,7 +435,8 @@ CREATE TABLE IF NOT EXISTS AM_APPLICATION ( APPLICATION_TIER VARCHAR(50) DEFAULT 'Unlimited', CALLBACK_URL VARCHAR(512), DESCRIPTION VARCHAR(512), - APPLICATION_STATUS VARCHAR(50) DEFAULT 'APPROVED', + APPLICATION_STATUS VARCHAR(50) DEFAULT 'APPROVED', + GROUP_ID VARCHAR(100), FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON UPDATE CASCADE ON DELETE RESTRICT, PRIMARY KEY(APPLICATION_ID), UNIQUE (NAME,SUBSCRIBER_ID) diff --git a/modules/distribution/resources/sql/mssql.sql b/modules/distribution/resources/sql/mssql.sql index 14f30eddbd..e14e94c0aa 100644 --- a/modules/distribution/resources/sql/mssql.sql +++ b/modules/distribution/resources/sql/mssql.sql @@ -477,6 +477,7 @@ CREATE TABLE AM_APPLICATION ( APPLICATION_TIER VARCHAR(50) DEFAULT 'Unlimited', CALLBACK_URL VARCHAR(512), DESCRIPTION VARCHAR(512), + GROUP_ID VARCHAR(100), APPLICATION_STATUS VARCHAR(50) DEFAULT 'APPROVED', FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON UPDATE CASCADE, PRIMARY KEY(APPLICATION_ID), diff --git a/modules/distribution/resources/sql/mysql.sql b/modules/distribution/resources/sql/mysql.sql index de6129fc50..4d27afb981 100644 --- a/modules/distribution/resources/sql/mysql.sql +++ b/modules/distribution/resources/sql/mysql.sql @@ -453,7 +453,8 @@ CREATE TABLE IF NOT EXISTS AM_APPLICATION ( APPLICATION_TIER VARCHAR(50) DEFAULT 'Unlimited', CALLBACK_URL VARCHAR(512), DESCRIPTION VARCHAR(512), - APPLICATION_STATUS VARCHAR(50) DEFAULT 'APPROVED', + APPLICATION_STATUS VARCHAR(50) DEFAULT 'APPROVED', + GROUP_ID VARCHAR(100), FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON UPDATE CASCADE ON DELETE RESTRICT, PRIMARY KEY(APPLICATION_ID), UNIQUE (NAME,SUBSCRIBER_ID) diff --git a/modules/distribution/resources/sql/oracle.sql b/modules/distribution/resources/sql/oracle.sql index dc2885cb41..7b3109b012 100644 --- a/modules/distribution/resources/sql/oracle.sql +++ b/modules/distribution/resources/sql/oracle.sql @@ -687,7 +687,8 @@ CREATE TABLE AM_APPLICATION ( APPLICATION_TIER VARCHAR2(50) DEFAULT 'Unlimited', CALLBACK_URL VARCHAR2(512), DESCRIPTION VARCHAR2(512), - APPLICATION_STATUS VARCHAR2(50) DEFAULT 'APPROVED', + APPLICATION_STATUS VARCHAR2(50) DEFAULT 'APPROVED', + GROUP_ID VARCHAR(100), FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON DELETE CASCADE, PRIMARY KEY(APPLICATION_ID), UNIQUE (NAME,SUBSCRIBER_ID) diff --git a/modules/distribution/resources/sql/oracle_rac.sql b/modules/distribution/resources/sql/oracle_rac.sql index 3201cb6659..85cf03a85a 100644 --- a/modules/distribution/resources/sql/oracle_rac.sql +++ b/modules/distribution/resources/sql/oracle_rac.sql @@ -686,7 +686,8 @@ CREATE TABLE AM_APPLICATION ( APPLICATION_TIER VARCHAR2(50) DEFAULT 'Unlimited', CALLBACK_URL VARCHAR2(512), DESCRIPTION VARCHAR2(512), - APPLICATION_STATUS VARCHAR2(50) DEFAULT 'APPROVED', + APPLICATION_STATUS VARCHAR2(50) DEFAULT 'APPROVED', + GROUP_ID VARCHAR(100), FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON DELETE CASCADE, PRIMARY KEY(APPLICATION_ID), UNIQUE (NAME,SUBSCRIBER_ID) diff --git a/modules/distribution/resources/sql/postgresql.sql b/modules/distribution/resources/sql/postgresql.sql index 075cb7324d..6c35df7477 100644 --- a/modules/distribution/resources/sql/postgresql.sql +++ b/modules/distribution/resources/sql/postgresql.sql @@ -520,6 +520,7 @@ CREATE TABLE AM_APPLICATION ( CALLBACK_URL VARCHAR(512), DESCRIPTION VARCHAR(512), APPLICATION_STATUS VARCHAR(50) DEFAULT 'APPROVED', + GROUP_ID VARCHAR(100), FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON UPDATE CASCADE ON DELETE RESTRICT, PRIMARY KEY(APPLICATION_ID), UNIQUE (NAME,SUBSCRIBER_ID) diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/GenerateAppKeyRequest.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/GenerateAppKeyRequest.java index e0f0d2d6d8..ea0f7d0f8e 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/GenerateAppKeyRequest.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/GenerateAppKeyRequest.java @@ -28,6 +28,10 @@ public class GenerateAppKeyRequest extends AbstractRequest { private String callbackUrl = "some-url"; private String authorizedDomains = "ALL"; private int validityTime = 360000; + private String appId ="1"; + + + public GenerateAppKeyRequest(String application) { this.application = application; @@ -45,6 +49,7 @@ public void init() { addParameter("callbackUrl", callbackUrl); addParameter("authorizedDomains", authorizedDomains); addParameter("validityTime", String.valueOf(validityTime)); + addParameter("selectedAppID", appId); } public String getApplication(){ return application; } @@ -80,4 +85,13 @@ public int getValidityTime() { public void setValidityTime(int validityTime) { this.validityTime = validityTime; } + + public String getAppId() { + return appId; + } + + + public void setAppId(String appId) { + this.appId = appId; + } } diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIStoreRestClient.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIStoreRestClient.java index 86a453977f..b0597b9148 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIStoreRestClient.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIStoreRestClient.java @@ -19,6 +19,9 @@ package org.wso2.am.integration.test.utils.clients; import org.apache.commons.codec.binary.Base64; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import org.wso2.am.integration.test.utils.bean.GenerateAppKeyRequest; import org.wso2.am.integration.test.utils.bean.SubscriptionRequest; import org.wso2.am.integration.test.utils.validation.VerificationUtil; @@ -101,6 +104,9 @@ public HttpResponse subscribe(SubscriptionRequest subscriptionRequest) public HttpResponse generateApplicationKey(GenerateAppKeyRequest generateAppKeyRequest) throws Exception { checkAuthentication(); + HttpResponse responseApp = getAllApplications(); + String appId = getApplicationId(responseApp.getData(), generateAppKeyRequest.getApplication()); + generateAppKeyRequest.setAppId(appId); HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag") , generateAppKeyRequest.generateRequestParameters() @@ -654,7 +660,26 @@ public HttpResponse getRecentlyAddedAPIs(String tenant, String limit) throws Exc } } - + + private String getApplicationId(String jsonStringOfApplications, String applicationName) throws Exception{ + String applicationId=null; + JSONObject obj; + try { + obj = new JSONObject(jsonStringOfApplications); + JSONArray arr = obj.getJSONArray("applications"); + for (int i = 0; i < arr.length(); i++) + { + String appName = arr.getJSONObject(i).getString("name"); + if(applicationName.equals(appName)){ + applicationId = arr.getJSONObject(i).getString("id"); + } + } + } catch (JSONException e) { + throw new Exception("getting application Id failed "); + } + return applicationId; + + } /** * Get the web page with filtered API when click the API Tag link * diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/store/utils/APIStoreRestClient.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/store/utils/APIStoreRestClient.java index 74515c4f4d..68361b4555 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/store/utils/APIStoreRestClient.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/store/utils/APIStoreRestClient.java @@ -19,6 +19,9 @@ package org.wso2.am.integration.test.utils.store.utils; import org.apache.commons.codec.binary.Base64; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import org.wso2.am.integration.test.utils.VerificationUtil; import org.wso2.am.integration.test.utils.bean.GenerateAppKeyRequest; import org.wso2.am.integration.test.utils.bean.SubscriptionRequest; @@ -76,9 +79,11 @@ public HttpResponse subscribe(SubscriptionRequest subscriptionRequest) public HttpResponse generateApplicationKey(GenerateAppKeyRequest generateAppKeyRequest) throws Exception { checkAuthentication(); + HttpResponse response1=getAllApplications(); + String appId = getApplicationId(response1.getData(), generateAppKeyRequest.getApplication()); HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag?"+ "action=generateApplicationKey&application="+ generateAppKeyRequest.getApplication() + - "&keytype=" + generateAppKeyRequest.getKeyType() + "&callbackUrl=&authorizedDomains=ALL&validityTime=360000"), + "&keytype=" + generateAppKeyRequest.getKeyType() + "&callbackUrl=&authorizedDomains=ALL&validityTime=360000&selectedAppID=" +appId), "", requestHeaders); if (response.getResponseCode() == 200) { @@ -445,4 +450,24 @@ public HttpResponse removeAPISubscription(String API, String version, String pro } } + + private String getApplicationId(String jsonStringOfApplications, String applicationName) throws Exception{ + String applicationId=null; + JSONObject obj; + try { + obj = new JSONObject(jsonStringOfApplications); + JSONArray arr = obj.getJSONArray("applications"); + for (int i = 0; i < arr.length(); i++) + { + String appName = arr.getJSONObject(i).getString("name"); + if(applicationName.equals(appName)){ + applicationId = arr.getJSONObject(i).getString("id"); + } + } + } catch (JSONException e) { + throw new Exception("getting application Id failed "); + } + return applicationId; + + } } diff --git a/modules/integration/tests/src/test/java/org/wso2/carbon/am/tests/util/APIStoreRestClient.java b/modules/integration/tests/src/test/java/org/wso2/carbon/am/tests/util/APIStoreRestClient.java new file mode 100644 index 0000000000..fa3b88da4b --- /dev/null +++ b/modules/integration/tests/src/test/java/org/wso2/carbon/am/tests/util/APIStoreRestClient.java @@ -0,0 +1,430 @@ +/* +*Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +*WSO2 Inc. licenses this file to you under the Apache License, +*Version 2.0 (the "License"); you may not use this file except +*in compliance with the License. +*You may obtain a copy of the License at +* +*http://www.apache.org/licenses/LICENSE-2.0 +* +*Unless required by applicable law or agreed to in writing, +*software distributed under the License is distributed on an +*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +*KIND, either express or implied. See the License for the +*specific language governing permissions and limitations +*under the License. +*/ + +package org.wso2.carbon.am.tests.util; + +import org.wso2.carbon.am.tests.util.bean.SubscriptionRequest; +import org.wso2.carbon.am.tests.util.bean.GenerateAppKeyRequest; +import org.wso2.carbon.automation.core.utils.HttpRequestUtil; +import org.wso2.carbon.automation.core.utils.HttpResponse; +import org.apache.commons.codec.binary.Base64; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class APIStoreRestClient { + private String backEndUrl; + private Map requestHeaders = new HashMap(); + + public APIStoreRestClient(String backEndUrl) { + this.backEndUrl = backEndUrl; + if (requestHeaders.get("Content-Type") == null) { + this.requestHeaders.put("Content-Type", "application/x-www-form-urlencoded"); + } + } + + public HttpResponse login(String userName, String password) + throws Exception { + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/user/login/ajax/login.jag") + , "action=login&username=" + userName + "&password=" + password + "", requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + String session = getSession(response.getHeaders()); + if (session == null) { + throw new Exception("No session cookie found with response"); + } + setSession(session); + return response; + } else { + throw new Exception("login() failed: " + response.getData()); + } + + } + + public HttpResponse subscribe(SubscriptionRequest subscriptionRequest) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag") + , subscriptionRequest.generateRequestParameters() + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("subscribe() failed> " + response.getData()); + } + + } + + public HttpResponse generateApplicationKey(GenerateAppKeyRequest generateAppKeyRequest) + throws Exception { + checkAuthentication(); + HttpResponse response1=HttpRequestUtil.getAllApplications(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag?"+ + "action=generateApplicationKey&application="+ generateAppKeyRequest.getApplication() + + "&keytype=" + generateAppKeyRequest.getKeyType() + "&callbackUrl=&authorizedDomains=ALL&validityTime=360000&selectedAppID=1"), + "", requestHeaders); + + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("generateApplicationKey() failed: " + response.getData()); + } + + } + + public HttpResponse getAPI(String apiName) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/api/listing/ajax/list.jag?action=getAllPublishedAPIs") + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("getAPI() failed: " + response.getData()); + } + + } + + + public void setHttpHeader(String headerName, String value) { + this.requestHeaders.put(headerName, value); + } + + public String getHttpHeader(String headerName) { + return this.requestHeaders.get(headerName); + } + + public void removeHttpHeader(String headerName) { + this.requestHeaders.remove(headerName); + } + + private String getSession(Map responseHeaders) { + return responseHeaders.get("Set-Cookie"); + } + + private String setSession(String session) { + return requestHeaders.put("Cookie", session); + } + + private boolean checkAuthentication() throws Exception { + if (requestHeaders.get("Cookie") == null) { + throw new Exception("No Session Cookie found. Please login first"); + } + return true; + } + + + public HttpResponse generateUserAccessKey(String consumeKey, String consumerSecret, String body, URL tokenEndpointURL) + throws Exception { + checkAuthentication(); + Map authenticationRequestHeaders = new HashMap(); + String basicAuthHeader = consumeKey + ":" +consumerSecret; + byte[] encodedBytes = Base64.encodeBase64(basicAuthHeader.getBytes()); + authenticationRequestHeaders.put("Content-Type", "application/x-www-form-urlencoded"); + authenticationRequestHeaders.put("Authorization", "Basic " + new String(encodedBytes)); + HttpResponse response = HttpRequestUtil.doPost(tokenEndpointURL + , body + , authenticationRequestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("generateUserAccessKey() failed: " + response.getData()); + } + } + + + public HttpResponse getAllPublishedAPIs() + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl+"/store/site/blocks/api/listing/ajax/list.jag?action=getAllPublishedAPIs" + , requestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("getAllPublishedAPIs() failed: " + response.getData()); + } + } + + + public HttpResponse getAllApplications() + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl+"/store/site/blocks/application/application-list/ajax/application-list.jag?action=getApplications" + , requestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("getAllApplications() failed: " + response.getData()); + } + } + + public HttpResponse getPublishedAPIsByApplication(String applicationName) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl+"/store/site/blocks/subscription/subscription-list/ajax/subscription-list.jag?action=getSubscriptionByApplication&app="+applicationName + , requestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("getPublishedAPIsByApplication() failed: " + response.getData()); + } + } + + + public HttpResponse addRatingToAPI(String apiName, String version, String provider, String rating) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl+"/store/site/blocks/api/api-info/ajax/api-info.jag?" + + "action=addRating&name=" + apiName + "&version=" + version + "&provider=" + provider + "&rating=" + rating + , requestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("addRatingToAPI failed: " + response.getData()); + } + } + + public HttpResponse removeRatingFromAPI(String apiName, String version, String provider) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl+"/store/site/blocks/api/api-info/ajax/api-info.jag?" + + "action=removeRating&name=" + apiName + "&version=" + version + "&provider=" + provider + , requestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("removeRatingFromAPI() failed: " + response.getData()); + } + } + + + public HttpResponse isRatingActivated() + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl+"/store/site/blocks/api/api-info/ajax/api-info.jag?" + + "action=isRatingActivated" + , requestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("isRatingActivated() failed: " + response.getData()); + } + } + /* + apiData.name = request.getParameter("name"); + apiData.version = request.getParameter("version"); + apiData.provider = request.getParameter("provider") + */ + public HttpResponse getAllDocumentationOfApi(String apiName, String version, String provider) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl+"/store/site/blocks/api/listing/ajax/list.jag?" + + "action=getAllDocumentationOfApi&name=" + apiName + "&version=" + version + "&provider=" + provider + , requestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("getAllDocumentationOfApi() failed: " + response.getData()); + } + } + /* + tenant = request.getParameter("tenant"); + var start=request.getParameter("start"); + var end=request.getParameter("end"); + */ + public HttpResponse getAllPaginatedPublishedAPIs(String tenant, String start, String end) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl+"/store/site/blocks/api/listing/ajax/list.jag?" + + "action=getAllPaginatedPublishedAPIs&tenant=" + tenant + "&start=" + start + "&end=" + end + , requestHeaders); + if (response.getResponseCode() == 200) { + return response; + } else { + throw new Exception("getAllPaginatedPublishedAPIs() failed: " + response.getData()); + } + } + + public HttpResponse getAllPublishedAPIs(String tenant) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/api/listing/ajax/list.jag?action=getAllPublishedAPIs&tenant=" + tenant) + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("getAllPublishedAPIs() failed: " + response.getData()); + } + + } + + public HttpResponse addApplication(String application, String tier, String callbackUrl, String description) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/application/application-add/ajax/application-add.jag?action=addApplication&tier=" + tier + "&callbackUrl="+callbackUrl+"&description="+description+"&application="+application) + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("addApplication() failed: " + response.getData()); + } + + } + + public HttpResponse getApplications() + throws Exception { + checkAuthentication(); + + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/application/application-list/ajax/application-list.jag?action=getApplications") + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("getApplications() failed: " + response.getData()); + } + + } + + public HttpResponse removeApplication(String application) + throws Exception { + checkAuthentication(); + + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/application/application-remove/ajax/application-remove.jag?action=removeApplication&application=" + application) + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("removeApplication() failed: " + response.getData()); + } + + } + + public HttpResponse updateApplication(String applicationOld, String applicationNew, String callbackUrlNew, String descriptionNew, String tier) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/application/application-update/ajax/application-update.jag?" + + "action=updateApplication&applicationOld=" + applicationOld + "&applicationNew="+applicationNew+"&callbackUrlNew="+callbackUrlNew+ + "&descriptionNew="+descriptionNew+"&tier="+tier) + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("updateApplication() failed: " + response.getData()); + } + + } + public HttpResponse getAllSubscriptions() + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/subscription/subscription-list/ajax/subscription-list.jag?" + + "action=getAllSubscriptions") + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("getAllSubscriptions() failed: " + response.getData()); + } + + } + + public HttpResponse getAllTags() + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/tag/tag-cloud/ajax/list.jag?action=getAllTags") + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("getAllTags() failed : " + response.getData()); + } + + } + /* + name = request.getParameter("name"); + version = request.getParameter("version"); + provider = request.getParameter("provider"); + comment = request.getParameter("comment"); + /home/sanjeewa/carbon/turing/components/apimgt/api-store-web/1.2.0/src/site/blocks/comment/comment-add/ajax/comment-add.jag + */ + public HttpResponse addComment(String name, String version, String provider, String comment) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/comment/comment-add/ajax/comment-add.jag?" + + "action=addComment&name="+name + "&version="+version+"&provider="+provider+"&comment="+comment) + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("addComment() failed: " + response.getData()); + } + + } + + public HttpResponse isCommentActivated() + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doGet(backEndUrl + "/store/site/blocks/comment/comment-add/ajax/comment-add.jag?" + + "action=isCommentActivated" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("isCommentActivated() failed: " + response.getData()); + } + + } + + public HttpResponse getRecentlyAddedAPIs(String tenant, String limit) + throws Exception { + ///home/sanjeewa/carbon/turing/components/apimgt/api-store-web/1.2.0/src/site/blocks/api/recently-added/ajax/list.jag + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/api/recently-added/ajax/list.jag?action=getRecentlyAddedAPIs"+ + "&tenant="+tenant+"&limit="+limit) + , "" + , requestHeaders); + if (response.getResponseCode() == 200) { + VerificationUtil.checkErrors(response); + return response; + } else { + throw new Exception("getRecentlyAddedAPIs() failed: " + response.getData()); + } + + } +}