You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/02/20 16:53:17 UTC
[airavata-django-portal] branch master updated: AIRAVATA-2982
Switched DataProduct REST API to use query paramAlso reworked the
ServiceFactory configuration to make it easier to addnon-ViewSet methods
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
The following commit(s) were added to refs/heads/master by this push:
new 9d0deb6 AIRAVATA-2982 Switched DataProduct REST API to use query paramAlso reworked the ServiceFactory configuration to make it easier to addnon-ViewSet methods
9d0deb6 is described below
commit 9d0deb61be08be40f6eca75df595fd0429bba070
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Feb 20 11:22:51 2019 -0500
AIRAVATA-2982 Switched DataProduct REST API to use query paramAlso reworked the ServiceFactory configuration to make it easier to addnon-ViewSet methods
---
django_airavata/apps/api/serializers.py | 4 -
.../django_airavata_api/js/service_config.js | 224 ++++------
.../js/services/ServiceFactory.js | 456 ++++++++++++---------
django_airavata/apps/api/urls.py | 5 +-
django_airavata/apps/api/views.py | 16 +-
5 files changed, 339 insertions(+), 366 deletions(-)
diff --git a/django_airavata/apps/api/serializers.py b/django_airavata/apps/api/serializers.py
index 72678ed..a3c5a9c 100644
--- a/django_airavata/apps/api/serializers.py
+++ b/django_airavata/apps/api/serializers.py
@@ -450,10 +450,6 @@ class DataProductSerializer(
lastModifiedTime = UTCPosixTimestampDateTimeField()
replicaLocations = DataReplicaLocationSerializer(many=True)
downloadURL = serializers.SerializerMethodField()
- url = FullyEncodedHyperlinkedIdentityField(
- view_name='django_airavata_api:data-product-detail',
- lookup_field='productUri',
- lookup_url_kwarg='product_uri')
def get_downloadURL(self, data_product):
"""Getter for downloadURL field."""
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/service_config.js b/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
index 2eecb10..16e449d 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
@@ -21,55 +21,45 @@ examples:
Generating Services based on the API view set
{
-serviceName:{
-url:'/example/api',
-viewSet:true,
-pagination: true/false,
-modelClass: ModelClass,
-}
+ serviceName:{
+ url:'/example/api',
+ viewSet:true, // or array of supported view set method names
+ pagination: true/false,
+ modelClass: ModelClass,
+ }
}
Normal service configuration:
{
-serviceName:{
-serviceAction1:{
-url:'/example/api/<look_up>', # the <look_up> implies a path parameter lok_up
-requestType:'post',
-bodyParams:[...] # body parameter names for json parameter if body params id=s a list of array else an object with the param name for the body object
-queryParams:[] # list query param names/ query param name to param name mapping
-pagination:true # whether to treat the response as a paginated response
-
-
-}
-}
+ serviceName:{
+ methods: {
+ serviceAction1:{
+ url:'/example/api/<look_up>', # the <look_up> implies a path parameter lok_up, defaults to service's url
+ requestType:'post', # defaults to "get"
+ bodyParams:[...] # body parameter names for json parameter if body
+ params id=s a list of array else an object with the param name for the
+ body object
+ queryParams:[], # list query param names/ query param name to param
+ name mapping, defaults to service's queryParams
+ pagination:true, # whether to treat the response as a paginated
+ response, defaults to service's pagination
+ modelClass: ModelClass
+ }
+ }
+ }
}
*/
export default {
ApplicationDeployments: {
url: "/api/application-deployments",
- viewSet: [
- {
- name: "list"
- },
- {
- name: "create"
- },
- {
- name: "retrieve"
- },
- {
- name: "update"
- },
- {
- name: "delete"
- },
- {
- name: "getQueues",
+ viewSet: true,
+ methods: {
+ getQueues: {
url: "/api/application-deployments/<lookup>/queues/",
requestType: "get",
modelClass: BatchQueue
}
- ],
+ },
queryParams: ["appModuleId", "groupResourceProfileId"],
modelClass: ApplicationDeploymentDescription
},
@@ -80,88 +70,56 @@ export default {
},
ApplicationModules: {
url: "/api/applications",
- viewSet: [
- {
- name: "list"
- },
- {
- name: "create"
- },
- {
- name: "retrieve"
- },
- {
- name: "update"
- },
- {
- name: "delete"
- },
- {
- name: "getApplicationInterface",
+ viewSet: true,
+ methods: {
+ getApplicationInterface: {
url: "/api/applications/<lookup>/application_interface/",
requestType: "get",
modelClass: ApplicationInterfaceDefinition
},
- {
- name: "getApplicationDeployments",
+ getApplicationDeployments: {
url: "/api/applications/<lookup>/application_deployments/",
requestType: "get",
modelClass: ApplicationDeploymentDescription
},
- {
- name: "listAll",
+ listAll: {
url: "/api/applications/list_all/",
requestType: "get",
modelClass: ApplicationModule
}
- ],
+ },
modelClass: ApplicationModule
},
ComputeResources: {
url: "/api/compute-resources",
- viewSet: [
- {
- name: "retrieve"
- },
- {
- name: "names",
+ viewSet: ["retrieve"],
+ methods: {
+ names: {
url: "/api/compute-resources/all_names/",
requestType: "get"
},
- {
- name: "namesList",
+ namesList: {
url: "/api/compute-resources/all_names_list/",
requestType: "get"
}
- ],
+ },
modelClass: ComputeResourceDescription
},
CredentialSummaries: {
url: "/api/credential-summaries/",
- viewSet: [
- {
- name: "list"
- },
- {
- name: "retrieve"
- },
- {
- name: "delete"
- },
- {
- name: "allSSHCredentials",
+ viewSet: ["list", "retrieve", "delete"],
+ methods: {
+ allSSHCredentials: {
url: "/api/credential-summaries/ssh/",
requestType: "get",
modelClass: CredentialSummary
},
- {
- name: "allPasswordCredentials",
+ allPasswordCredentials: {
url: "/api/credential-summaries/password/",
requestType: "get",
modelClass: CredentialSummary
},
- {
- name: "createSSH",
+ createSSH: {
url: "/api/credential-summaries/create_ssh/",
requestType: "post",
bodyParams: {
@@ -169,8 +127,7 @@ export default {
},
modelClass: CredentialSummary
},
- {
- name: "createPassword",
+ createPassword: {
url: "/api/credential-summaries/create_password/",
requestType: "post",
bodyParams: {
@@ -178,49 +135,36 @@ export default {
},
modelClass: CredentialSummary
}
- ],
+ },
modelClass: CredentialSummary
},
DataProducts: {
url: "/api/data-products/",
- viewSet: [
- {
- name: "retrieve"
+ methods: {
+ retrieve: {
+ requestType: "get",
+ queryParams: {
+ "lookup": "product-uri"
+ },
+ modelClass: DataProduct
}
- ],
- modelClass: DataProduct
+ }
},
Experiments: {
url: "/api/experiments/",
- viewSet: [
- {
- name: "list"
- },
- {
- name: "create"
- },
- {
- name: "retrieve"
- },
- {
- name: "update"
- },
- {
- name: "delete"
- },
- {
- name: "launch",
+ viewSet: true,
+ methods: {
+ launch: {
url: "/api/experiments/<lookup>/launch/",
requestType: "post",
modelClass: Experiment
},
- {
- name: "clone",
+ clone: {
url: "/api/experiments/<lookup>/clone/",
requestType: "post",
modelClass: Experiment
}
- ],
+ },
modelClass: Experiment
},
ExperimentSearch: {
@@ -237,29 +181,14 @@ export default {
},
GatewayResourceProfiles: {
url: "/api/gateway-resource-profiles/",
- viewSet: [
- {
- name: "list"
- },
- {
- name: "create"
- },
- {
- name: "retrieve"
- },
- {
- name: "update"
- },
- {
- name: "delete"
- },
- {
- name: "current",
+ viewSet: true,
+ methods: {
+ current: {
url: "/api/gateway-resource-profile/",
requestType: "get",
modelClass: GatewayResourceProfile
}
- ],
+ },
modelClass: GatewayResourceProfile
},
GroupResourceProfiles: {
@@ -282,15 +211,9 @@ export default {
},
SharedEntities: {
url: "/api/shared-entities",
- viewSet: [
- {
- name: "retrieve"
- },
- {
- name: "update"
- },
- {
- name: "merge",
+ viewSet: ["retrieve", "update"],
+ methods: {
+ merge: {
url: "/api/shared-entities/<lookup>/merge/",
bodyParams: {
name: "data"
@@ -298,7 +221,7 @@ export default {
requestType: "put",
modelClass: SharedEntity
}
- ],
+ },
modelClass: SharedEntity
},
StoragePreferences: {
@@ -308,25 +231,18 @@ export default {
},
StorageResources: {
url: "/api/storage-resources",
- viewSet: [
- {
- name: "retrieve"
- },
- {
- name: "names",
+ viewSet: ["retrieve"],
+ methods: {
+ names: {
url: "/api/storage-resources/all_names/",
requestType: "get"
}
- ],
+ },
modelClass: StorageResourceDescription
},
UserProfiles: {
url: "/api/user-profiles",
- viewSet: [
- {
- name: "list"
- }
- ],
+ viewSet: ["list"],
modelClass: UserProfile
}
};
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/services/ServiceFactory.js b/django_airavata/apps/api/static/django_airavata_api/js/services/ServiceFactory.js
index a3e24f0..702cb45 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/services/ServiceFactory.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/services/ServiceFactory.js
@@ -1,224 +1,284 @@
-import PaginationIterator from '../utils/PaginationIterator'
-import FetchUtils from '../utils/FetchUtils'
-import serviceConfiguration from '../service_config'
+import PaginationIterator from "../utils/PaginationIterator";
+import FetchUtils from "../utils/FetchUtils";
+import serviceConfiguration from "../service_config";
const postKey = "post";
const getKey = "get";
const putKey = "put";
const delKey = "delete";
-const parsePathParams = function (url) {
- var pathParamsRegEx = new RegExp('<[a-zA-Z0-9_]+(:[a-zA-Z0-9_]*)?>', 'g');
- let pathParamsMatch = url.match(pathParamsRegEx);
- let pathParams = {};
- if (!pathParamsMatch) {
- return pathParams;
- }
- for (let pathParamMatch of pathParamsMatch) {
- let pathParam = pathParamMatch.split(":");
- if (pathParam.length == 2) {
- pathParams[pathParam[1]] = pathParam[0].replace(/<|>/gi, "");
- } else {
- pathParams[pathParam[0].replace(/<|>/gi, "")] = null;
- }
- }
+const parsePathParams = function(url) {
+ var pathParamsRegEx = new RegExp("<[a-zA-Z0-9_]+(:[a-zA-Z0-9_]*)?>", "g");
+ let pathParamsMatch = url.match(pathParamsRegEx);
+ let pathParams = {};
+ if (!pathParamsMatch) {
return pathParams;
-}
+ }
+ for (let pathParamMatch of pathParamsMatch) {
+ let pathParam = pathParamMatch.split(":");
+ if (pathParam.length == 2) {
+ pathParams[pathParam[1]] = pathParam[0].replace(/<|>/gi, "");
+ } else {
+ pathParams[pathParam[0].replace(/<|>/gi, "")] = null;
+ }
+ }
+ return pathParams;
+};
-const parseServiceMapping = function (serviceConfiguration) {
- let supportedFunctions = [];
- if (serviceConfiguration.viewSet === true) {
- supportedFunctions = ['list', 'create', 'update', 'delete', 'retrieve'];
- } else if (serviceConfiguration.viewSet instanceof Array) {
- supportedFunctions = serviceConfiguration.viewSet;
+const parseServiceMapping = function(serviceConfiguration) {
+ const mappedFunctions = {};
+ let viewSetFunctions = [];
+ if (serviceConfiguration.viewSet === true) {
+ viewSetFunctions = ["list", "create", "update", "delete", "retrieve"];
+ } else if (serviceConfiguration.viewSet instanceof Array) {
+ viewSetFunctions = serviceConfiguration.viewSet;
+ }
+ let url = serviceConfiguration.url;
+ if (!url.endsWith("/")) {
+ url = url + "/";
+ }
+ let modelClass = serviceConfiguration.modelClass;
+ let queryParams = serviceConfiguration.queryParams;
+ let defaultPagination = serviceConfiguration.pagination ? true : false;
+ for (let viewSetFunction of viewSetFunctions) {
+ let viewSetFunctionName = viewSetFunction;
+ let pagination = defaultPagination;
+ if (typeof viewSetFunctionName !== "string") {
+ viewSetFunctionName = viewSetFunction.name;
+ if ("pagination" in viewSetFunction) {
+ pagination = viewSetFunction.pagination;
+ }
}
- if (supportedFunctions) {
- let url = serviceConfiguration.url;
- if (!url.endsWith("/")) {
- url = url + "/";
- }
- let modelClass = serviceConfiguration.modelClass;
- let queryParams = serviceConfiguration.queryParams;
- let defaultPagination = (serviceConfiguration.pagination) ? true : false;
- delete serviceConfiguration.viewSet;
- delete serviceConfiguration.url;
- delete serviceConfiguration.modelClass;
- delete serviceConfiguration.queryParams;
- delete serviceConfiguration.pagination;
- for (let supportedFunction of supportedFunctions) {
- let supportedFunctionName = supportedFunction
- let pagination = defaultPagination;
- if (typeof(supportedFunctionName) !== "string") {
- supportedFunctionName = supportedFunction.name
- if ('pagination' in supportedFunction) {
- pagination = supportedFunction.pagination
- }
- }
- switch (supportedFunctionName) {
- case "list":
- serviceConfiguration["list"] = {
- url: url,
- requestType: getKey,
- modelClass: modelClass,
- queryParams: queryParams,
- initialDataParam: supportedFunction.initialDataParam,
- }
- break;
- case "create":
- serviceConfiguration["create"] = {
- url: url,
- requestType: postKey,
- bodyParams: {
- name: "data"
- },
- modelClass: modelClass,
- queryParams: queryParams,
- }
- break;
- case "update":
- serviceConfiguration["update"] = {
- url: url + "<lookup>/",
- requestType: putKey,
- bodyParams: {
- name: "data"
- },
- modelClass: modelClass,
- queryParams: queryParams,
- }
- break;
- case "retrieve":
- serviceConfiguration["retrieve"] = {
- url: url + "<lookup>/",
- requestType: getKey,
- modelClass: modelClass,
- queryParams: queryParams,
- initialDataParam: supportedFunction.initialDataParam,
- }
- break;
- case "delete":
- serviceConfiguration["delete"] = {
- url: url + "<lookup>/",
- requestType: delKey,
- modelClass: modelClass,
- queryParams: queryParams,
- }
- break;
- default:
- // Assume all fields have been provided
- serviceConfiguration[supportedFunctionName] = supportedFunction;
- break;
- }
- serviceConfiguration[supportedFunctionName].pagination = pagination
- }
+ switch (viewSetFunctionName) {
+ case "list":
+ mappedFunctions["list"] = {
+ url: url,
+ requestType: getKey,
+ modelClass: modelClass,
+ queryParams: queryParams,
+ initialDataParam: viewSetFunction.initialDataParam
+ };
+ break;
+ case "create":
+ mappedFunctions["create"] = {
+ url: url,
+ requestType: postKey,
+ bodyParams: {
+ name: "data"
+ },
+ modelClass: modelClass,
+ queryParams: queryParams
+ };
+ break;
+ case "update":
+ mappedFunctions["update"] = {
+ url: url + "<lookup>/",
+ requestType: putKey,
+ bodyParams: {
+ name: "data"
+ },
+ modelClass: modelClass,
+ queryParams: queryParams
+ };
+ break;
+ case "retrieve":
+ mappedFunctions["retrieve"] = {
+ url: url + "<lookup>/",
+ requestType: getKey,
+ modelClass: modelClass,
+ queryParams: queryParams,
+ initialDataParam: viewSetFunction.initialDataParam
+ };
+ break;
+ case "delete":
+ mappedFunctions["delete"] = {
+ url: url + "<lookup>/",
+ requestType: delKey,
+ modelClass: modelClass,
+ queryParams: queryParams
+ };
+ break;
+ default:
+ // Assume all fields have been provided
+ mappedFunctions[viewSetFunctionName] = viewSetFunction;
+ break;
}
-}
-
-const parseQueryMapping = function (queryParamsMapping) {
- let newQueryParamMapping = {};
- if (!queryParamsMapping) {
- return newQueryParamMapping;
+ mappedFunctions[viewSetFunctionName].pagination = pagination;
+ }
+ if ("methods" in serviceConfiguration) {
+ for (let methodName of Object.keys(serviceConfiguration["methods"])) {
+ let methodConfig = serviceConfiguration["methods"][methodName];
+ mappedFunctions[methodName] = {
+ url: methodConfig.url || url,
+ requestType: methodConfig.requestType || getKey,
+ queryParams: methodConfig.queryParams || queryParams,
+ pagination:
+ "pagination" in methodConfig
+ ? methodConfig.pagination
+ : defaultPagination
+ };
+ if ("modelClass" in methodConfig) {
+ mappedFunctions[methodName]["modelClass"] = methodConfig.modelClass;
+ }
+ if ("bodyParams" in methodConfig) {
+ mappedFunctions[methodName]["bodyParams"] = methodConfig.bodyParams;
+ }
+ if ("pathParams" in methodConfig) {
+ mappedFunctions[methodName]["pathParams"] = methodConfig.pathParams;
+ }
}
+ }
+ return mappedFunctions;
+};
+
+const parseQueryMapping = function(queryParamsMapping) {
+ let newQueryParamMapping = {};
+ if (!queryParamsMapping) {
+ return newQueryParamMapping;
+ }
+ // names of query parameters as an array of strings
+ if (queryParamsMapping instanceof Array) {
for (let queryParam of queryParamsMapping) {
- if (typeof(queryParam) === "string") {
- newQueryParamMapping[queryParam] = null;
- } else {
- newQueryParamMapping[queryParam.value] = queryParam.name;
- }
+ if (typeof queryParam === "string") {
+ newQueryParamMapping[queryParam] = null;
+ }
}
- return newQueryParamMapping;
-}
+ }
+ // mapping of query parameters as an object of names/values
+ else {
+ for (let queryParam of Object.keys(queryParamsMapping)) {
+ newQueryParamMapping[queryParam] = queryParamsMapping[queryParam];
+ }
+ }
+ return newQueryParamMapping;
+};
class ServiceFactory {
- constructor(serviceConfigurations) {
- for (let serviceName of Object.keys(serviceConfigurations)) {
- parseServiceMapping(serviceConfigurations[serviceName]);
- }
- this.serviceConfigurations = serviceConfigurations;
+ constructor(serviceConfigurations) {
+ const parsedConfigurations = {};
+ for (let serviceName of Object.keys(serviceConfigurations)) {
+ parsedConfigurations[serviceName] = parseServiceMapping(
+ serviceConfigurations[serviceName]
+ );
}
+ this.serviceConfigurations = parsedConfigurations;
+ }
- /*
+ /*
Creates service object based serviceName in service configuration
*/
- service(serviceName) {
- if (!serviceName) {
- throw new TypeError("Invalid Service Name");
- } else if (!(serviceName in this.serviceConfigurations)) {
- throw new Error("Service :" + serviceName + " could not be found");
- }
- let serviceConfiguration = this.serviceConfigurations[serviceName];
- let serviceObj = {};
- let functionNames = Object.keys(serviceConfiguration);
- for (let functionName of functionNames) {
- let config = serviceConfiguration[functionName];
- switch (config.requestType.toLowerCase()) {
- case postKey:
- case getKey:
- case putKey:
- case delKey:
- break;
- default:
- throw new TypeError("Invalid request type: " + config.requestType + " for the function: " + functionName + " in the service: " + serviceName);
+ service(serviceName) {
+ if (!serviceName) {
+ throw new TypeError("Invalid Service Name");
+ } else if (!(serviceName in this.serviceConfigurations)) {
+ throw new Error("Service :" + serviceName + " could not be found");
+ }
+ let serviceConfiguration = this.serviceConfigurations[serviceName];
+ let serviceObj = {};
+ let functionNames = Object.keys(serviceConfiguration);
+ for (let functionName of functionNames) {
+ let config = serviceConfiguration[functionName];
+ switch (config.requestType.toLowerCase()) {
+ case postKey:
+ case getKey:
+ case putKey:
+ case delKey:
+ break;
+ default:
+ throw new TypeError(
+ "Invalid request type: " +
+ config.requestType +
+ " for the function: " +
+ functionName +
+ " in the service: " +
+ serviceName
+ );
+ }
+ let pathParamsMapping = parsePathParams(config.url);
+ let queryParamsMapping = parseQueryMapping(config.queryParams);
+ serviceObj[functionName] = function(
+ params = {},
+ { ignoreErrors } = { ignoreErrors: false }
+ ) {
+ let url = config.url;
+ let paramKeys = Object.keys(params);
+ let queryParams = {};
+ let bodyParams = {};
+ let initialData = undefined;
+ for (let paramKey of paramKeys) {
+ if (paramKey in pathParamsMapping) {
+ if (pathParamsMapping[paramKey] !== null) {
+ url = url.replace(
+ "<" + pathParamsMapping[paramKey] + ":" + paramKey + ">",
+ encodeURIComponent(params[paramKey])
+ );
+ } else {
+ url = url.replace(
+ "<" + paramKey + ">",
+ encodeURIComponent(params[paramKey])
+ );
}
- let pathParamsMapping = parsePathParams(config.url);
- let queryParamsMapping = parseQueryMapping(config.queryParams);
- serviceObj[functionName] = function (params = {}, { ignoreErrors } = { ignoreErrors: false }) {
- let url = config.url;
- let paramKeys = Object.keys(params);
- let queryParams = {};
- let bodyParams = {};
- let initialData = undefined;
- for (let paramKey of paramKeys) {
- if (paramKey in pathParamsMapping) {
- if (pathParamsMapping[paramKey] !== null) {
- url = url.replace('<' + pathParamsMapping[paramKey] + ':' + paramKey + '>', encodeURIComponent(params[paramKey]));
- } else {
- url = url.replace('<' + paramKey + '>', encodeURIComponent(params[paramKey]));
- }
- } else if (paramKey in queryParamsMapping) {
- if (queryParamsMapping[paramKey] === null) {
- queryParams[paramKey] = params[paramKey];
- } else {
- queryParams[queryParamsMapping[paramKey]] = params[paramKey];
- }
- }
- else if ((config.requestType == postKey || config.requestType == putKey) && config.bodyParams instanceof Array && paramKey in config.bodyParams) {
- bodyParams[paramKey] = params[paramKey];
- } else if ((config.requestType == postKey || config.requestType == putKey) && config.bodyParams !== null && config.bodyParams.name == paramKey) {
- bodyParams = params[paramKey];
- } else if (config.initialDataParam && paramKey === config.initialDataParam) {
- initialData = params[paramKey];
- }
- }
- let paginationHandler = (data) => {
- if (config.pagination === true && 'next' in data) {
- return new PaginationIterator(data, config.modelClass);
- } else if (data instanceof Array) {
- return data.map(item => resultHandler(item));
- } else {
- return resultHandler(data);
- }
- };
- let resultHandler = (data) => {
- return (config.modelClass) ? new config.modelClass(data) : data;
- }
- switch (config.requestType.toLowerCase()) {
- case postKey:
- return FetchUtils.post(url, bodyParams, queryParams, { ignoreErrors }).then(resultHandler);
- case getKey:
- if (initialData) {
- return Promise.resolve(paginationHandler(initialData));
- } else {
- return FetchUtils.get(url, queryParams, { ignoreErrors }).then(paginationHandler);
- }
- case putKey:
- return FetchUtils.put(url, bodyParams, { ignoreErrors }).then(resultHandler);
- case delKey:
- return FetchUtils.delete(url, { ignoreErrors });
- }
+ } else if (paramKey in queryParamsMapping) {
+ if (queryParamsMapping[paramKey] === null) {
+ queryParams[paramKey] = params[paramKey];
+ } else {
+ queryParams[queryParamsMapping[paramKey]] = params[paramKey];
+ }
+ } else if (
+ (config.requestType == postKey || config.requestType == putKey) &&
+ config.bodyParams instanceof Array &&
+ paramKey in config.bodyParams
+ ) {
+ bodyParams[paramKey] = params[paramKey];
+ } else if (
+ (config.requestType == postKey || config.requestType == putKey) &&
+ config.bodyParams !== null &&
+ config.bodyParams.name == paramKey
+ ) {
+ bodyParams = params[paramKey];
+ } else if (
+ config.initialDataParam &&
+ paramKey === config.initialDataParam
+ ) {
+ initialData = params[paramKey];
+ }
+ }
+ let paginationHandler = data => {
+ if (config.pagination === true && "next" in data) {
+ return new PaginationIterator(data, config.modelClass);
+ } else if (data instanceof Array) {
+ return data.map(item => resultHandler(item));
+ } else {
+ return resultHandler(data);
+ }
+ };
+ let resultHandler = data => {
+ return config.modelClass ? new config.modelClass(data) : data;
+ };
+ switch (config.requestType.toLowerCase()) {
+ case postKey:
+ return FetchUtils.post(url, bodyParams, queryParams, {
+ ignoreErrors
+ }).then(resultHandler);
+ case getKey:
+ if (initialData) {
+ return Promise.resolve(paginationHandler(initialData));
+ } else {
+ return FetchUtils.get(url, queryParams, { ignoreErrors }).then(
+ paginationHandler
+ );
}
+ case putKey:
+ return FetchUtils.put(url, bodyParams, { ignoreErrors }).then(
+ resultHandler
+ );
+ case delKey:
+ return FetchUtils.delete(url, { ignoreErrors });
}
- return serviceObj;
+ };
}
+ return serviceObj;
+ }
}
export default new ServiceFactory(serviceConfiguration);
diff --git a/django_airavata/apps/api/urls.py b/django_airavata/apps/api/urls.py
index 064bd1c..07364be 100644
--- a/django_airavata/apps/api/urls.py
+++ b/django_airavata/apps/api/urls.py
@@ -41,15 +41,14 @@ router.register(r'storage-preferences',
views.StoragePreferenceViewSet,
base_name='storage-preference')
router.register(r'parsers', views.ParserViewSet, base_name='parser')
-router.register(r'data-products',
- views.DataProductViewSet,
- base_name='data-product')
app_name = 'django_airavata_api'
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^upload$', views.upload_input_file, name='upload_input_file'),
url(r'^download', views.download_file, name='download_file'),
+ url(r'^data-products', views.DataProductView.as_view(),
+ name='data-products-detail'),
url(r'^job/submission/local', views.LocalJobSubmissionView.as_view(),
name="local_job_submission"),
url(r'^job/submission/cloud', views.CloudJobSubmissionView.as_view(),
diff --git a/django_airavata/apps/api/views.py b/django_airavata/apps/api/views.py
index 75df505..61f9973 100644
--- a/django_airavata/apps/api/views.py
+++ b/django_airavata/apps/api/views.py
@@ -695,15 +695,17 @@ class LocalDataMovementView(APIView):
instance=data_movement).data)
-class DataProductViewSet(mixins.RetrieveModelMixin,
- GenericAPIBackedViewSet):
+class DataProductView(APIView):
+
serializer_class = serializers.DataProductSerializer
- lookup_field = 'product_uri'
- lookup_value_regex = '.*'
- def get_instance(self, lookup_value):
- return self.request.airavata_client.getDataProduct(
- self.request.authz_token, lookup_value)
+ def get(self, request, format=None):
+ data_product_uri = request.query_params['product-uri']
+ data_product = request.airavata_client.getDataProduct(
+ request.authz_token, data_product_uri)
+ serializer = self.serializer_class(
+ data_product, context={'request': request})
+ return Response(serializer.data)
@login_required