Fix getApplication method with Rest api calls

master
Pasindu Rupasinghe 1 year ago
parent bfaeb1778f
commit da1485d04f

@ -18,9 +18,10 @@
package io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer;
import org.json.JSONObject;
import org.wso2.carbon.apimgt.api.model.APIKey;
import java.util.List;
import java.util.Map;
/**
* This class represents the Consumer Application Information.
@ -36,7 +37,7 @@ public class Application {
private List<String> groups;
private int subscriptionCount;
private List<String> keys;
private JSONObject attributes;
private Map<String, String> attributes;
private List<Scopes> subscriptionScopes;
private String owner;
private boolean hashEnabled;
@ -113,11 +114,11 @@ public class Application {
this.keys = keys;
}
public JSONObject getAttributes() {
public Map<String, String> getAttributes() {
return attributes;
}
public void setAttributes(JSONObject attributes) {
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}

@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.wso2.carbon.apimgt.api.APIConsumer;
import org.wso2.carbon.apimgt.api.APIManagementException;
import org.wso2.carbon.apimgt.api.model.APIKey;
import org.wso2.carbon.apimgt.api.model.Application;
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
@ -429,30 +430,40 @@ public class KeyMgtServiceImpl implements KeyMgtService {
* @throws KeyMgtException if any error occurs while retrieving the application
*/
private Application getApplication(String applicationName, String accessToken) throws KeyMgtException {
try {
APIManagerFactory apiManagerFactory = APIManagerFactory.getInstance();
// APIConsumer apiConsumer = apiManagerFactory.getAPIConsumer(owner);
try {
ConsumerRESTAPIServices consumerRESTAPIServices =
KeyMgtDataHolder.getInstance().getConsumerRESTAPIServices();
io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application[] applications =
consumerRESTAPIServices.getAllApplications(null, accessToken, applicationName);
//todo map Application and return
//todo modify the method signature and use access token and call REST API to get application data
return null; // todo:apim - apiConsumer.getApplicationsByName(owner, applicationName, "");
// // curl -k -H "Authorization: Bearer ae4eae22-3f65-387b-a171-d37eaa366fa8" "https://localhost:9443/api/am/devportal/v3/applications?query=CalculatorApp"
io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application applicationFromRestCall;
if (applications.length == 1) {
applicationFromRestCall = applications[0];
} else {
String msg =
"Found invalid number of applications. No of applications found from the APIM: " + applications.length;
throw new KeyMgtException(msg);
}
// catch (APIManagementException e) {
// msg = "Error while trying to retrieve the application";
// log.error(msg);
// throw new KeyMgtException(msg);
// }
Application application = null;
application.setUUID(applicationFromRestCall.getApplicationId());
application.setName(applicationFromRestCall.getName());
application.setDescription(applicationFromRestCall.getDescription());
application.setApplicationAttributes(applicationFromRestCall.getAttributes());
application.setTokenType(applicationFromRestCall.getTokenType());
application.setStatus(applicationFromRestCall.getStatus());
application.setSubscriptionCount(applicationFromRestCall.getSubscriptionCount());
application.setOwner(applicationFromRestCall.getOwner());
application.setIsBlackListed(applicationFromRestCall.isHashEnabled());
return application;
}
catch (io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException e) {
e.printStackTrace();
throw new KeyMgtException("");
msg = "Error while trying to retrieve the application";
log.error(msg);
throw new KeyMgtException(msg);
} catch (UnexpectedResponseException e) {
throw new KeyMgtException("");
} catch (APIServicesException e) {

Loading…
Cancel
Save