Skip to content

Commit 5a14ecc

Browse files
authored
Add subcription approval capability to publisher portal (wso2#12472)
Add subscription approval workflow API.
1 parent c56ebbc commit 5a14ecc

File tree

19 files changed

+1886
-404
lines changed

19 files changed

+1886
-404
lines changed

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java

Lines changed: 194 additions & 185 deletions
Large diffs are not rendered by default.

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/ExceptionCodes.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,15 @@ public enum ExceptionCodes implements ErrorHandler {
630630
"Operation type/http method is not specified for the operation/resource", 400,
631631
"Operation type/http method is not specified for the operation/resource: %s", false),
632632

633+
FAILED_TO_RETRIEVE_WORKFLOW_BY_EXTERNAL_REFERENCE_ID(902033, "Failed to rettrieve workflow request by the " +
634+
"external workflow reference", 500,
635+
"Failed to retrieve workflow request by the external workflow reference"),
636+
FAILED_TO_RETRIEVE_WORKFLOWS(902034, "Error while retrieving workflow requests.", 500,
637+
"Error while retrieving workflow requests."),
638+
WORKFLOW_PAYLOAD_MISSING(902035, "Payload is missing", 400,
639+
"Payload is missing in the workflow request"),
640+
WORKFLOW_STATUS_NOT_DEFINED(902036, "Workflow status not defined", 400,
641+
"Workflow status is not defined"),
633642
RESOURCE_URI_TEMPLATE_NOT_DEFINED(902032, "Resource URI template value not defined", 400,
634643
"Resource URI template value (target) not defined", false);
635644
private final long errorCode;

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/WorkflowDTO.java

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
/*
2-
* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3-
*
4-
* WSO2 Inc. licenses this file to you under the Apache License,
5-
* Version 2.0 (the "License"); you may not use this file except
6-
* in compliance with the License.
7-
* You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing,
12-
* software distributed under the License is distributed on an
13-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
* KIND, either express or implied. See the License for the
15-
* specific language governing permissions and limitations
16-
* under the License.
17-
*/
2+
* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 Inc. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
1818

1919
package org.wso2.carbon.apimgt.api.dto;
2020

21-
import org.wso2.carbon.apimgt.api.WorkflowStatus;
21+
import org.json.simple.JSONObject;
22+
import org.wso2.carbon.apimgt.api.model.WorkflowStatus;
2223

2324
import java.io.Serializable;
25+
import java.util.HashMap;
26+
import java.util.Map;
2427

2528
/**
2629
* This is the DTO that will be used for storing workflow related contextual information.
@@ -33,9 +36,6 @@ public class WorkflowDTO implements Serializable {
3336

3437
private String workflowType;
3538

36-
//Used to hold the status of the workflow. When a workflow is initially executed, it will be in the CREATED state.
37-
//It will then move to the APPROVED or REJECTED states depending on the output of the workflow execution.
38-
private WorkflowStatus status;
3939

4040
private long createdTime;
4141

@@ -55,28 +55,37 @@ public class WorkflowDTO implements Serializable {
5555

5656
private String callbackUrl;
5757

58-
public String getCallbackUrl() {
59-
return callbackUrl;
58+
private JSONObject metadata;
59+
60+
private JSONObject properties;
61+
62+
public WorkflowDTO() {
63+
metadata = new JSONObject();
64+
properties = new JSONObject();
6065
}
6166

62-
public void setCallbackUrl(String callbackUrl) {
63-
this.callbackUrl = callbackUrl;
67+
public String getProperties(String key) {
68+
return properties.get(key).toString();
6469
}
6570

66-
/**
67-
* Returns the status of the Workflow.
68-
* @return - Enum, the workflow status (Ex: CREATED, APPROVED, REJECTED)
69-
*/
70-
public WorkflowStatus getStatus() {
71-
return status;
71+
public void setProperties(String key, String value) {
72+
properties.put(key, value);
7273
}
7374

74-
public void setStatus(WorkflowStatus status) {
75-
this.status = status;
75+
//to pass any additional parameters. This can be used to pass parameters to the executor's complete() method
76+
private Map<String, String> attributes = new HashMap<String, String>();
77+
78+
public String getCallbackUrl() {
79+
return callbackUrl;
80+
}
81+
82+
public void setCallbackUrl(String callbackUrl) {
83+
this.callbackUrl = callbackUrl;
7684
}
7785

7886
/**
7987
* Returns the reference id of the workflow.
88+
*
8089
* @return - The workflow reference id.
8190
*/
8291
public String getExternalWorkflowReference() {
@@ -89,6 +98,7 @@ public void setExternalWorkflowReference(String externalWorkflowReference) {
8998

9099
/**
91100
* Returns the workflow description.
101+
*
92102
* @return - The workflow description.
93103
*/
94104
public String getWorkflowDescription() {
@@ -146,4 +156,54 @@ public String getTenantDomain() {
146156
public void setTenantDomain(String tenantDomain) {
147157
this.tenantDomain = tenantDomain;
148158
}
159+
160+
public Map<String, String> getAttributes() {
161+
return attributes;
162+
}
163+
164+
public void setAttributes(Map<String, String> attributes) {
165+
this.attributes = attributes;
166+
}
167+
168+
public String getMetadata(String key) {
169+
return metadata.get(key).toString();
170+
}
171+
172+
public void setMetadata(String key, String value) {
173+
metadata.put(key, value);
174+
}
175+
176+
public JSONObject getMetadata() {
177+
return metadata;
178+
}
179+
180+
public void setMetadata(JSONObject metadata) {
181+
this.metadata = metadata;
182+
}
183+
184+
public JSONObject getProperties() {
185+
return properties;
186+
}
187+
188+
public void setProperties(JSONObject properties) {
189+
this.properties = properties;
190+
}
191+
192+
@Override
193+
public String toString() {
194+
return "WorkflowDTO{" +
195+
"workflowReference='" + workflowReference + '\'' +
196+
", workflowType='" + workflowType + '\'' +
197+
", createdTime=" + createdTime +
198+
", updatedTime=" + updatedTime +
199+
", workflowDescription='" + workflowDescription + '\'' +
200+
", tenantId=" + tenantId +
201+
", tenantDomain='" + tenantDomain + '\'' +
202+
", externalWorkflowReference='" + externalWorkflowReference + '\'' +
203+
", callbackUrl='" + callbackUrl + '\'' +
204+
", metadata=" + metadata +
205+
", properties=" + properties +
206+
", attributes=" + attributes +
207+
'}';
208+
}
149209
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 Inc. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.apimgt.api.model;
20+
21+
public enum WorkflowStatus {
22+
CREATED, APPROVED, REJECTED, REGISTERED
23+
}

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7518,4 +7518,16 @@ public void updateSoapToRestSequences(String organization, String apiId, List<SO
75187518
throw new APIManagementException("Error while sequences to the api " + apiId, e);
75197519
}
75207520
}
7521+
7522+
@Override
7523+
public org.wso2.carbon.apimgt.api.dto.WorkflowDTO retrieveWorkflow(
7524+
String workflowReferenceID) throws APIManagementException {
7525+
try {
7526+
org.wso2.carbon.apimgt.api.dto.WorkflowDTO workflowDTO = apiMgtDAO.retrieveWorkflow(workflowReferenceID);
7527+
return workflowDTO;
7528+
} catch (APIManagementException e) {
7529+
throw new APIManagementException("Error while resuming workflow " + workflowReferenceID, e);
7530+
}
7531+
}
7532+
75217533
}

components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/config/APIMConfigServiceImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
public class APIMConfigServiceImpl implements APIMConfigService {
5757

5858
private static final Log log = LogFactory.getLog(APIMConfigServiceImpl.class);
59+
private static final String SUBSCRIPTION_APPROVAL_VIEW_SCOPE = "apim:subscription_approval_view";
60+
private static final String SUBSCRIPTION_APPROVAL_MANAGE_SCOPE = "apim:subscription_approval_manage";
5961
protected SystemConfigurationsDAO systemConfigurationsDAO;
6062

6163
public APIMConfigServiceImpl() {
@@ -195,7 +197,9 @@ private String addMissingScopes(String systemConfig) {
195197
"apim:admin_tier_view",
196198
"apim:admin_tier_manage",
197199
"apim:keymanagers_manage",
198-
"apim:api_category"
200+
"apim:api_category",
201+
SUBSCRIPTION_APPROVAL_VIEW_SCOPE,
202+
SUBSCRIPTION_APPROVAL_MANAGE_SCOPE
199203
};
200204

201205
ArrayList<String> missingScopesList = new ArrayList<>(Arrays.asList(scopesToCheck));
@@ -227,7 +231,12 @@ private String addMissingScopes(String systemConfig) {
227231
for (String missingScope : missingScopesList) {
228232
JsonObject newScope = new JsonObject();
229233
newScope.addProperty("Name", missingScope);
230-
newScope.addProperty("Roles", "admin");
234+
if (missingScope.equals(SUBSCRIPTION_APPROVAL_VIEW_SCOPE) ||
235+
missingScope.equals(SUBSCRIPTION_APPROVAL_MANAGE_SCOPE)) {
236+
newScope.addProperty("Roles", "admin,Internal/publisher");
237+
} else {
238+
newScope.addProperty("Roles", "admin");
239+
}
231240
scopeArray.add(newScope);
232241
}
233242

0 commit comments

Comments
 (0)