Fix getApplication method with Rest api calls

remotes/1728937285237262521/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; 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.List;
import java.util.Map;
/** /**
* This class represents the Consumer Application Information. * This class represents the Consumer Application Information.
@ -36,7 +37,7 @@ public class Application {
private List<String> groups; private List<String> groups;
private int subscriptionCount; private int subscriptionCount;
private List<String> keys; private List<String> keys;
private JSONObject attributes; private Map<String, String> attributes;
private List<Scopes> subscriptionScopes; private List<Scopes> subscriptionScopes;
private String owner; private String owner;
private boolean hashEnabled; private boolean hashEnabled;
@ -113,11 +114,11 @@ public class Application {
this.keys = keys; this.keys = keys;
} }
public JSONObject getAttributes() { public Map<String, String> getAttributes() {
return attributes; return attributes;
} }
public void setAttributes(JSONObject attributes) { public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes; this.attributes = attributes;
} }

@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.carbon.apimgt.api.APIConsumer; import org.wso2.carbon.apimgt.api.APIConsumer;
import org.wso2.carbon.apimgt.api.APIManagementException; 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.api.model.Application;
import org.wso2.carbon.apimgt.impl.APIManagerFactory; import org.wso2.carbon.apimgt.impl.APIManagerFactory;
import org.wso2.carbon.apimgt.impl.utils.APIUtil; 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 * @throws KeyMgtException if any error occurs while retrieving the application
*/ */
private Application getApplication(String applicationName, String accessToken) throws KeyMgtException { private Application getApplication(String applicationName, String accessToken) throws KeyMgtException {
try {
APIManagerFactory apiManagerFactory = APIManagerFactory.getInstance();
// APIConsumer apiConsumer = apiManagerFactory.getAPIConsumer(owner);
try {
ConsumerRESTAPIServices consumerRESTAPIServices = ConsumerRESTAPIServices consumerRESTAPIServices =
KeyMgtDataHolder.getInstance().getConsumerRESTAPIServices(); KeyMgtDataHolder.getInstance().getConsumerRESTAPIServices();
io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application[] applications = io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application[] applications =
consumerRESTAPIServices.getAllApplications(null, accessToken, applicationName); 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) { Application application = null;
// msg = "Error while trying to retrieve the application"; application.setUUID(applicationFromRestCall.getApplicationId());
// log.error(msg); application.setName(applicationFromRestCall.getName());
// throw new KeyMgtException(msg); 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) { catch (io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException e) {
e.printStackTrace(); e.printStackTrace();
throw new KeyMgtException(""); msg = "Error while trying to retrieve the application";
log.error(msg);
throw new KeyMgtException(msg);
} catch (UnexpectedResponseException e) { } catch (UnexpectedResponseException e) {
throw new KeyMgtException(""); throw new KeyMgtException("");
} catch (APIServicesException e) { } catch (APIServicesException e) {

Loading…
Cancel
Save