use of org.wso2.carbon.apimgt.api.model.ApiTypeWrapper in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionToDTO.
public static SubscriptionDTO fromSubscriptionToDTO(SubscribedAPI subscription, ApiTypeWrapper apiTypeWrapper, String organization) throws APIManagementException {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionId(subscription.getUUID());
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
Map<String, Tier> tierMap = APIUtil.getTiers(organization);
if (apiTypeWrapper != null && !apiTypeWrapper.isAPIProduct()) {
API api = apiTypeWrapper.getApi();
subscriptionDTO.setApiId(api.getUUID());
APIInfoDTO apiInfo = APIMappingUtil.fromAPIToInfoDTO(api);
APIMappingUtil.setThrottlePoliciesAndMonetization(api, apiInfo, deniedTiers, tierMap);
subscriptionDTO.setApiInfo(apiInfo);
} else {
APIProduct apiProduct = apiTypeWrapper.getApiProduct();
subscriptionDTO.setApiId(apiProduct.getUuid());
APIInfoDTO apiInfo = APIMappingUtil.fromAPIToInfoDTO(apiProduct, organization);
APIMappingUtil.setThrottlePoliciesAndMonetization(apiProduct, apiInfo, deniedTiers, tierMap);
subscriptionDTO.setApiInfo(apiInfo);
}
Application application = subscription.getApplication();
subscriptionDTO.setApplicationId(subscription.getApplication().getUUID());
subscriptionDTO.setStatus(SubscriptionDTO.StatusEnum.valueOf(subscription.getSubStatus()));
subscriptionDTO.setThrottlingPolicy(subscription.getTier().getName());
subscriptionDTO.setRequestedThrottlingPolicy(subscription.getRequestedTier().getName());
ApplicationInfoDTO applicationInfoDTO = ApplicationMappingUtil.fromApplicationToInfoDTO(application);
subscriptionDTO.setApplicationInfo(applicationInfoDTO);
return subscriptionDTO;
}
use of org.wso2.carbon.apimgt.api.model.ApiTypeWrapper in project carbon-apimgt by wso2.
the class ApiMgtDAO method editComment.
/**
*********
* Edit a comment
*
* @param apiTypeWrapper API Type Wrapper
* @param commentId Comment ID
* @param comment Comment object
* @throws APIManagementException
*/
public boolean editComment(ApiTypeWrapper apiTypeWrapper, String commentId, Comment comment) throws APIManagementException {
try (Connection connection = APIMgtDBUtil.getConnection()) {
int id = -1;
String editCommentQuery = SQLConstants.EDIT_COMMENT;
Identifier identifier;
String uuid;
if (apiTypeWrapper.isAPIProduct()) {
identifier = apiTypeWrapper.getApiProduct().getId();
uuid = apiTypeWrapper.getApiProduct().getUuid();
} else {
identifier = apiTypeWrapper.getApi().getId();
uuid = apiTypeWrapper.getApi().getUuid();
}
id = getAPIID(uuid, connection);
if (id == -1) {
String msg = "Could not load API record for: " + identifier.getName();
throw new APIManagementException(msg);
}
connection.setAutoCommit(false);
try (PreparedStatement prepStmt = connection.prepareStatement(editCommentQuery)) {
prepStmt.setString(1, comment.getText());
prepStmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()), Calendar.getInstance());
prepStmt.setString(3, comment.getCategory());
prepStmt.setInt(4, id);
prepStmt.setString(5, commentId);
prepStmt.execute();
connection.commit();
return true;
}
} catch (SQLException e) {
handleException("Error while editing comment " + commentId + " from the database", e);
}
return false;
}
use of org.wso2.carbon.apimgt.api.model.ApiTypeWrapper in project carbon-apimgt by wso2.
the class APIMgtDAOTest method testAddSubscription.
@Test
public void testAddSubscription() throws Exception {
Application application = new Application(100);
APIIdentifier apiIdentifier = new APIIdentifier("SUMEDHA", "API1", "V1.0.0");
apiIdentifier.setApplicationId("APPLICATION99");
apiIdentifier.setTier("T1");
String uuid = apiMgtDAO.getUUIDFromIdentifier(apiIdentifier, "org1");
apiIdentifier.setId(apiMgtDAO.getAPIID(uuid));
API api = new API(apiIdentifier);
ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api);
apiMgtDAO.addSubscription(apiTypeWrapper, application, "UNBLOCKED", "admin");
}
use of org.wso2.carbon.apimgt.api.model.ApiTypeWrapper in project carbon-apimgt by wso2.
the class APIMgtDAOTest method testKeyForwardCompatibility.
@Test
public void testKeyForwardCompatibility() throws Exception {
List<API> oldApiVersionList = new ArrayList<>();
API apiOld = new API(new APIIdentifier("SUMEDHA", "API1", "V1.0.0"));
oldApiVersionList.add(apiOld);
API api = new API(new APIIdentifier("SUMEDHA", "API1", "V2.0.0"));
api.setContext("/context1");
api.setContextTemplate("/context1/{version}");
api.setVersionTimestamp(String.valueOf(System.currentTimeMillis()));
api.setUUID(UUID.randomUUID().toString());
api.getId().setId(apiMgtDAO.addAPI(api, -1234, "testOrg"));
ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api);
apiMgtDAO.makeKeysForwardCompatible(apiTypeWrapper, oldApiVersionList);
}
use of org.wso2.carbon.apimgt.api.model.ApiTypeWrapper in project carbon-apimgt by wso2.
the class ApiProductsApiServiceImpl method changeAPIProductLifecycle.
@Override
public Response changeAPIProductLifecycle(String action, String apiProductId, String lifecycleChecklist, String ifMatch, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
ApiTypeWrapper productWrapper = new ApiTypeWrapper(apiProvider.getAPIProductbyUUID(apiProductId, organization));
APIStateChangeResponse stateChangeResponse = PublisherCommonUtils.changeApiOrApiProductLifecycle(action, productWrapper, lifecycleChecklist, organization);
LifecycleStateDTO stateDTO = getLifecycleState(apiProductId, organization);
WorkflowResponseDTO workflowResponseDTO = APIMappingUtil.toWorkflowResponseDTO(stateDTO, stateChangeResponse);
return Response.ok().entity(workflowResponseDTO).build();
}
Aggregations