|
|
|
@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationInfo;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
|
|
|
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
|
|
|
@ -99,7 +100,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key)
|
|
|
|
|
public boolean isSharedScopeNameExists(APIApplicationInfo applicationInfo, String key)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace(Constants.QUERY_KEY_VALUE_SEPARATOR,
|
|
|
|
@ -109,7 +110,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(getScopeUrl)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.head()
|
|
|
|
|
.build();
|
|
|
|
|
try {
|
|
|
|
@ -118,11 +119,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return isSharedScopeNameExists(apiApplicationKey, refreshedAccessToken, key);
|
|
|
|
|
return isSharedScopeNameExists(applicationInfo,key);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -143,7 +143,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addNewSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
|
|
|
|
|
public boolean addNewSharedScope(APIApplicationInfo applicationInfo, Scope scope)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
|
|
|
@ -159,7 +159,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(addNewSharedScopeEndPoint)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.post(requestBody)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -169,11 +169,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApiApplicationInfo = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return addNewSharedScope(apiApplicationKey, refreshedAccessToken, scope);
|
|
|
|
|
return addNewSharedScope(refreshedApiApplicationInfo, scope);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid scope object";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -237,14 +236,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIIdentifier apiIdentifier)
|
|
|
|
|
public JSONObject getApi(APIApplicationInfo applicationInfo, APIIdentifier apiIdentifier)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String getAllApi = endPointPrefix + Constants.API_ENDPOINT + apiIdentifier.getUUID();
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(getAllApi)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.get()
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -255,11 +254,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return jsonObject;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return getApi(apiApplicationKey, refreshedAccessToken, apiIdentifier);
|
|
|
|
|
return getApi(refreshedApplicationInfo, apiIdentifier);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -276,14 +274,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
|
|
|
|
public JSONObject getApis(APIApplicationInfo applicationInfo)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String getAllApis = endPointPrefix + Constants.GET_ALL_APIS;
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(getAllApis)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.get()
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -294,11 +292,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return jsonObject;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApiApplicationInfo = apiApplicationServices
|
|
|
|
|
.generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return getApis(apiApplicationKey, refreshedAccessToken);
|
|
|
|
|
return getApis(refreshedApiApplicationInfo);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -315,7 +312,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
|
|
|
|
public JSONObject addAPI(APIApplicationInfo applicationInfo, APIInfo api)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT;
|
|
|
|
@ -370,7 +367,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(addAPIEndPoint)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.post(requestBody)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -381,11 +378,9 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return jsonObject;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApplicationToken = apiApplicationServices.generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return addAPI(apiApplicationKey, refreshedAccessToken, api);
|
|
|
|
|
return addAPI(refreshedApplicationToken, api);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid API request body";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -402,7 +397,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
|
|
|
|
public boolean updateApi(APIApplicationInfo applicationInfo, APIInfo api)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId();
|
|
|
|
@ -457,7 +452,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(updateAPIEndPoint)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.put(requestBody)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -468,11 +463,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return updateApi(apiApplicationKey, refreshedAccessToken, api);
|
|
|
|
|
return updateApi(refreshedApplicationInfo, api);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid API request body";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -489,8 +483,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean saveAsyncApiDefinition(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
|
String uuid, String asyncApiDefinition)
|
|
|
|
|
public boolean saveAsyncApiDefinition(APIApplicationInfo applicationInfo, String uuid, String asyncApiDefinition)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid;
|
|
|
|
@ -499,7 +492,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(addNewScope)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.put(requestBody)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -509,11 +502,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApplicationToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return saveAsyncApiDefinition(apiApplicationKey, refreshedAccessToken, uuid, asyncApiDefinition);
|
|
|
|
|
return saveAsyncApiDefinition(refreshedApplicationToken, uuid, asyncApiDefinition);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid API definition request body";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -571,8 +563,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
|
String uuid, Mediation mediation)
|
|
|
|
|
public boolean addApiSpecificMediationPolicy(APIApplicationInfo applicationInfo, String uuid, Mediation mediation)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String addAPIMediation = endPointPrefix + Constants.API_ENDPOINT + uuid + "/mediation-policies/" + mediation.getUuid()
|
|
|
|
@ -582,7 +573,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(addAPIMediation)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.post(requestBody)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -592,11 +583,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApplicationToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return addApiSpecificMediationPolicy(apiApplicationKey, refreshedAccessToken, uuid, mediation);
|
|
|
|
|
return addApiSpecificMediationPolicy(refreshedApplicationToken, uuid, mediation);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -658,7 +648,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean changeLifeCycleStatus(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
|
|
|
|
public boolean changeLifeCycleStatus(APIApplicationInfo applicationInfo,
|
|
|
|
|
String uuid, String action)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
@ -669,7 +659,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(changeAPIStatusEndPoint)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.post(requestBody)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -679,11 +669,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return changeLifeCycleStatus(apiApplicationKey, refreshedAccessToken, uuid, action);
|
|
|
|
|
return changeLifeCycleStatus(refreshedApplicationInfo, uuid, action);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid request";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -742,7 +731,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision)
|
|
|
|
|
public JSONObject addAPIRevision(APIApplicationInfo applicationInfo, APIRevision apiRevision)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions";
|
|
|
|
@ -755,7 +744,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(addNewScope)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.post(requestBody)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -766,11 +755,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return jsonObject;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return addAPIRevision(apiApplicationKey, refreshedAccessToken, apiRevision);
|
|
|
|
|
return addAPIRevision(refreshedApplicationInfo, apiRevision);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid API revision request body";
|
|
|
|
|
log.error(msg);
|
|
|
|
@ -787,7 +775,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean deployAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
|
|
|
|
|
public boolean deployAPIRevision(APIApplicationInfo applicationInfo, String uuid,
|
|
|
|
|
String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeploymentList)
|
|
|
|
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
|
|
|
|
|
|
|
|
@ -806,7 +794,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
|
.url(deployAPIRevisionEndPoint)
|
|
|
|
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
|
|
|
|
+ accessTokenInfo.getAccess_token())
|
|
|
|
|
+ applicationInfo.getAccess_token())
|
|
|
|
|
.post(requestBody)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
@ -816,11 +804,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
|
|
|
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
|
|
|
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
|
|
|
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
|
|
|
|
APIApplicationInfo refreshedApplicationInfo = apiApplicationServices.
|
|
|
|
|
generateAccessTokenFromRefreshToken(applicationInfo);
|
|
|
|
|
//TODO: max attempt count
|
|
|
|
|
return deployAPIRevision(apiApplicationKey, refreshedAccessToken, uuid, apiRevisionId,
|
|
|
|
|
return deployAPIRevision(refreshedApplicationInfo, uuid, apiRevisionId,
|
|
|
|
|
apiRevisionDeploymentList);
|
|
|
|
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
|
|
|
|
String msg = "Bad Request, Invalid API revision request body";
|
|
|
|
|