use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method updateAPISubscriptionStatus.
@Override
public void updateAPISubscriptionStatus(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
SubscriptionEvent subscriptionBlockEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_STATUS_CHANGE);
subscriptionBlockEvent.setSubscriptionsList(subscriptionValidationDataList);
publishToStoreTopic(subscriptionBlockEvent);
if (log.isDebugEnabled()) {
log.debug("Subscription updated event has been successfully published to broker");
}
}
use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method deleteAPISubscription.
/**
* {@inheritDoc}
*/
@Override
public void deleteAPISubscription(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
SubscriptionEvent subscriptionDeleteEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_DELETE);
subscriptionDeleteEvent.setSubscriptionsList(subscriptionValidationDataList);
publishToStoreTopic(subscriptionDeleteEvent);
if (log.isDebugEnabled()) {
log.debug("Subscription deleted event has been successfully published to broker");
}
}
use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class APIStateChangeWorkflow method updateAPIStatusForWorkflowComplete.
private void updateAPIStatusForWorkflowComplete(String apiId, String status, String updatedBy, LocalDateTime time) throws APIManagementException {
boolean requireReSubscriptions = false;
boolean deprecateOlderVersion = false;
try {
API api = apiDAO.getAPI(apiId);
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.lastUpdatedTime(time);
apiBuilder.updatedBy(updatedBy);
LifecycleState currentState = apiLifecycleManager.getLifecycleDataForState(apiBuilder.getLifecycleInstanceId(), apiBuilder.getLifeCycleStatus());
apiBuilder.lifecycleState(currentState);
if (APIMgtConstants.APILCWorkflowStatus.PENDING.toString().equals(api.getWorkflowStatus())) {
apiBuilder.workflowStatus(APIMgtConstants.APILCWorkflowStatus.APPROVED.toString());
apiDAO.updateAPIWorkflowStatus(apiId, APIMgtConstants.APILCWorkflowStatus.APPROVED);
}
List<CheckItemBean> list = currentState.getCheckItemBeanList();
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
CheckItemBean checkItemBean = (CheckItemBean) iterator.next();
if (APIMgtConstants.DEPRECATE_PREVIOUS_VERSIONS.equals(checkItemBean.getName())) {
deprecateOlderVersion = checkItemBean.isValue();
} else if (APIMgtConstants.REQUIRE_RE_SUBSCRIPTIONS.equals(checkItemBean.getName())) {
requireReSubscriptions = checkItemBean.isValue();
}
}
API originalAPI = apiBuilder.build();
apiLifecycleManager.executeLifecycleEvent(api.getLifeCycleStatus(), status, apiBuilder.getLifecycleInstanceId(), updatedBy, originalAPI);
if (deprecateOlderVersion) {
if (StringUtils.isNotEmpty(api.getCopiedFromApiId())) {
API oldAPI = apiDAO.getAPI(api.getCopiedFromApiId());
if (oldAPI != null) {
API.APIBuilder previousAPI = new API.APIBuilder(oldAPI);
previousAPI.setLifecycleStateInfo(apiLifecycleManager.getLifecycleDataForState(previousAPI.getLifecycleInstanceId(), previousAPI.getLifeCycleStatus()));
if (APIUtils.validateTargetState(previousAPI.getLifecycleState(), APIStatus.DEPRECATED.getStatus())) {
apiLifecycleManager.executeLifecycleEvent(previousAPI.getLifeCycleStatus(), APIStatus.DEPRECATED.getStatus(), previousAPI.getLifecycleInstanceId(), updatedBy, previousAPI.build());
}
}
}
}
if (!requireReSubscriptions) {
if (StringUtils.isNotEmpty(api.getCopiedFromApiId())) {
List<Subscription> subscriptions = apiSubscriptionDAO.getAPISubscriptionsByAPI(api.getCopiedFromApiId());
List<Subscription> subscriptionList = new ArrayList<>();
for (Subscription subscription : subscriptions) {
if (api.getPolicies().contains(subscription.getPolicy())) {
if (!APIMgtConstants.SubscriptionStatus.ON_HOLD.equals(subscription.getStatus())) {
subscriptionList.add(new Subscription(UUID.randomUUID().toString(), subscription.getApplication(), subscription.getApi(), subscription.getPolicy()));
}
}
apiSubscriptionDAO.copySubscriptions(subscriptionList);
}
}
}
// publish API state change to gateway
apiGateway.changeAPIState(originalAPI, status);
} catch (APIMgtDAOException e) {
String errorMsg = "Couldn't change the status of api ID " + apiId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
} catch (LifecycleException e) {
String errorMsg = "Couldn't change the status of api ID " + apiId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, ExceptionCodes.APIMGT_LIFECYCLE_EXCEPTION);
} catch (GatewayException e) {
String message = "Error occurred while changing the state of api ID: " + apiId + " to " + status + "in gateway";
log.error(message, e);
throw new APIManagementException(message, ExceptionCodes.GATEWAY_EXCEPTION);
}
}
use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class SubscriptionDeletionWorkflow method completeWorkflow.
public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
if (subscription == null) {
// this is when complete method is executed through workflow rest api
this.subscription = apiSubscriptionDAO.getAPISubscription(getWorkflowReference());
}
WorkflowResponse response = workflowExecutor.complete(this);
setStatus(response.getWorkflowStatus());
List<SubscriptionValidationData> subscriptionValidationDataList = null;
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Subscription deletion workflow complete: Approved");
}
if (subscription.getApi() != null && subscription.getApplication() != null) {
subscriptionValidationDataList = apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(subscription.getApi().getContext(), subscription.getApi().getVersion(), subscription.getApplication().getId());
}
apiSubscriptionDAO.deleteAPISubscription(getWorkflowReference());
} else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Subscription deletion workflow complete: Rejected");
}
}
updateWorkflowEntries(this);
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (subscriptionValidationDataList != null && !subscriptionValidationDataList.isEmpty()) {
apiGateway.deleteAPISubscription(subscriptionValidationDataList);
if (log.isDebugEnabled()) {
log.debug("Subscription for API : " + subscription.getApi().getName() + " with " + "application : " + subscription.getApplication().getName() + " has been successfully " + "removed from gateway");
}
}
}
return response;
}
use of org.wso2.carbon.apimgt.core.models.Subscription in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateSubscriptionPolicy.
@Test(description = "Update subscription policy")
public void testUpdateSubscriptionPolicy() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiSubscriptionDAO);
apiPublisher.updateSubscriptionPolicy(SUB_ID, "test policy");
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionPolicy(SUB_ID, "test policy");
}
Aggregations