Search in sources :

Example 31 with ApiTypeWrapper

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;
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) Tier(org.wso2.carbon.apimgt.api.model.Tier) API(org.wso2.carbon.apimgt.api.model.API) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionDTO) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 32 with ApiTypeWrapper

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;
}
Also used : APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) Identifier(org.wso2.carbon.apimgt.api.model.Identifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 33 with ApiTypeWrapper

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");
}
Also used : ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) API(org.wso2.carbon.apimgt.api.model.API) Application(org.wso2.carbon.apimgt.api.model.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 34 with ApiTypeWrapper

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);
}
Also used : ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) ArrayList(java.util.ArrayList) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with ApiTypeWrapper

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();
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.WorkflowResponseDTO) LifecycleStateDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.LifecycleStateDTO) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

ApiTypeWrapper (org.wso2.carbon.apimgt.api.model.ApiTypeWrapper)41 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)38 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)25 API (org.wso2.carbon.apimgt.api.model.API)24 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)24 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)16 URI (java.net.URI)14 URISyntaxException (java.net.URISyntaxException)14 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)14 Application (org.wso2.carbon.apimgt.api.model.Application)14 ArrayList (java.util.ArrayList)13 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)13 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)11 Tier (org.wso2.carbon.apimgt.api.model.Tier)10 Comment (org.wso2.carbon.apimgt.api.model.Comment)9 DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)9 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 SubscriptionAlreadyExistingException (org.wso2.carbon.apimgt.api.SubscriptionAlreadyExistingException)7 Identifier (org.wso2.carbon.apimgt.api.model.Identifier)7