use of org.wso2.carbon.apimgt.api.model.webhooks.Subscription in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionListToDTO.
/**
* Converts a List object of SubscribedAPIs into a DTO
*
* @param subscriptions a list of SubscribedAPI objects
* @param limit max number of objects returned
* @param offset starting index
* @return SubscriptionListDTO object containing SubscriptionDTOs
*/
public static SubscriptionListDTO fromSubscriptionListToDTO(List<Subscription> subscriptions, Integer limit, Integer offset) {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
List<SubscriptionDTO> subscriptionDTOs = subscriptionListDTO.getList();
if (subscriptionDTOs == null) {
subscriptionDTOs = new ArrayList<>();
subscriptionListDTO.setList(subscriptionDTOs);
}
// identifying the proper start and end indexes
int size = subscriptions.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
Subscription subscription = subscriptions.get(i);
subscriptionDTOs.add(fromSubscriptionToDTO(subscription));
}
subscriptionListDTO.setCount(subscriptionDTOs.size());
return subscriptionListDTO;
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Subscription in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionToDTO.
/**
* Converts a SubscribedAPI object into SubscriptionDTO
*
* @param subscription SubscribedAPI object
* @return SubscriptionDTO corresponds to SubscribedAPI object
*/
public static SubscriptionDTO fromSubscriptionToDTO(Subscription subscription) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionId(subscription.getId());
if (subscription.getApi() != null) {
subscriptionDTO.setApiIdentifier(subscription.getApi().getId());
subscriptionDTO.setApiName(subscription.getApi().getName());
subscriptionDTO.setApiVersion(subscription.getApi().getVersion());
}
if (subscription.getApplication() != null) {
subscriptionDTO.setApplicationId(subscription.getApplication().getId());
}
subscriptionDTO.setPolicy(subscription.getPolicy().getPolicyName());
subscriptionDTO.setLifeCycleStatus(SubscriptionDTO.LifeCycleStatusEnum.valueOf(subscription.getStatus().toString()));
return subscriptionDTO;
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Subscription in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createSubscription.
public static Subscription createSubscription(String uuid) {
if (StringUtils.isEmpty(uuid)) {
uuid = UUID.randomUUID().toString();
}
Subscription subscription = new Subscription(uuid, createDefaultApplication(), createDefaultAPI().build(), goldApiPolicy);
subscription.setStatus(APIMgtConstants.SubscriptionStatus.ACTIVE);
return subscription;
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Subscription in project carbon-apimgt by wso2.
the class APISubscriptionDAOImpl method deleteAPISubscription.
/**
* Remove an existing API Subscription
*
* @param subscriptionId The UUID of the API Subscription that needs to be deleted
* @throws APIMgtDAOException If failed to delete subscription.
*/
@Override
public void deleteAPISubscription(String subscriptionId) throws APIMgtDAOException {
final String deleteSubscriptionSql = "DELETE FROM AM_SUBSCRIPTION WHERE UUID = ? ";
try (Connection conn = DAOUtil.getConnection()) {
boolean originalAutoCommitState = conn.getAutoCommit();
conn.setAutoCommit(false);
try (PreparedStatement ps = conn.prepareStatement(deleteSubscriptionSql)) {
ps.setString(1, subscriptionId);
ps.execute();
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting api subscription(subscriptionId: " + subscriptionId + ")", ex);
} finally {
conn.setAutoCommit(originalAutoCommitState);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting api subscription(subscriptionId: " + subscriptionId + ")", e);
}
}
use of org.wso2.carbon.apimgt.api.model.webhooks.Subscription in project carbon-apimgt by wso2.
the class APISubscriptionDAOImpl method updateSubscriptionStatus.
/**
* Update Subscription Status
*
* @param subId ID of the Subscription
* @param subStatus New Subscription Status
* @throws APIMgtDAOException If failed to update subscriptions.
*/
@Override
public void updateSubscriptionStatus(String subId, APIMgtConstants.SubscriptionStatus subStatus) throws APIMgtDAOException {
final String updateSubscriptionSql = "UPDATE AM_SUBSCRIPTION SET SUB_STATUS = ?, LAST_UPDATED_TIME = ? " + "WHERE UUID = ?";
try (Connection conn = DAOUtil.getConnection()) {
conn.setAutoCommit(false);
try (PreparedStatement preparedStatement = conn.prepareStatement(updateSubscriptionSql)) {
preparedStatement.setString(1, subStatus.toString());
preparedStatement.setTimestamp(2, Timestamp.valueOf(LocalDateTime.now()));
preparedStatement.setString(3, subId);
preparedStatement.execute();
conn.commit();
} catch (SQLException ex) {
conn.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating subscription status(subscriptionId: " + subId + ", status: " + subStatus + ")", ex);
} finally {
conn.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating subscription status(subscriptionId: " + subId + ", status: " + subStatus + ")", e);
}
}
Aggregations