From 5e4b0564b78b8673333e5c22e8795d3ef80c4d82 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Fri, 3 Mar 2017 17:02:36 +0530 Subject: [PATCH] added permission fix for operation and synchronised application creation to avoid duplicate subscription --- .../api/ApiApplicationRegistrationServiceImpl.java | 14 ++++++++------ .../extension/api/util/RegistrationProfile.java | 10 ++++++++++ .../app/modules/business-controllers/operation.js | 10 ++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java index 65392645ea..4656653988 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java @@ -107,12 +107,14 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi validityPeriod = registrationProfile.getValidityPeriod(); } - String applicationName = "devicetype_app_" + StringUtils.join(registrationProfile.getTags(), "_"); - ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( - applicationName, registrationProfile.getTags(), - ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username, - registrationProfile.isAllowedToAllDomains(), validityPeriod); - return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build(); + String applicationName = registrationProfile.getApplicationName(); + synchronized (ApiApplicationRegistrationServiceImpl.class) { + ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( + applicationName, registrationProfile.getTags(), + ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username, + registrationProfile.isAllowedToAllDomains(), validityPeriod); + return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build(); + } } catch (APIManagerException e) { String msg = "Error occurred while registering an application with apis '" + StringUtils.join(registrationProfile.getTags(), ",") + "'"; diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java index 2111753efe..44cc5554fc 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java @@ -30,6 +30,8 @@ import javax.xml.bind.annotation.XmlRootElement; @JsonIgnoreProperties(ignoreUnknown = true) public class RegistrationProfile { + @XmlElement(required = true) + private String applicationName; @XmlElement(required = true) private String tags[]; @XmlElement(required = true) @@ -37,6 +39,14 @@ public class RegistrationProfile { @XmlElement(required = false) private String validityPeriod; + public String getApplicationName() { + return applicationName; + } + + public void setApiApplicationName(String apiApplicationName) { + this.applicationName = apiApplicationName; + } + public String[] getTags() { return tags; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index 127a0df064..e9c07ee0ba 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -51,6 +51,16 @@ var operationModule = function () { feature["contentType"] = features[i].contentType; feature["deviceType"] = deviceType; feature["params"] = []; + var featuresEntry = utility.getDeviceTypeConfig(deviceType)["deviceType"]["features"]; + if (featuresEntry) { + var featureEntry = featuresEntry[features[i].code]; + if (featureEntry) { + var permissionEntry = featureEntry["permission"]; + if (permissionEntry) { + feature["permission"] = permissionEntry + } + } + } var metaData = features[i].metadataEntries; if (metaData) { for (var j = 0; j < metaData.length; j++) {