Search in sources :

Example 41 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.

the class CommentMappingUtil method fromCommentListToDTO.

/**
 * Wraps a List of Comments to a CommentListDTO
 *
 * @param commentList list of comments
 * @param limit maximum comments to return
 * @param offset  starting position of the pagination
 * @return CommentListDTO
 */
public static CommentListDTO fromCommentListToDTO(List<Comment> commentList, int limit, int offset) {
    CommentListDTO commentListDTO = new CommentListDTO();
    List<CommentDTO> listOfCommentDTOs = new ArrayList<>();
    commentListDTO.setCount(commentList.size());
    int start = offset < commentList.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = offset + limit - 1 <= commentList.size() - 1 ? offset + limit - 1 : commentList.size() - 1;
    for (int i = start; i <= end; i++) {
        listOfCommentDTOs.add(fromCommentToDTO(commentList.get(i)));
    }
    commentListDTO.setList(listOfCommentDTOs);
    return commentListDTO;
}
Also used : ArrayList(java.util.ArrayList) CommentDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO) CommentListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CommentListDTO)

Example 42 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.

the class APIStoreImpl method searchCompositeAPIs.

@Override
public List<CompositeAPI> searchCompositeAPIs(String query, int offset, int limit) throws APIManagementException {
    List<CompositeAPI> apiResults;
    // this should be current logged in user
    String user = getUsername();
    // role list of current user
    Set<String> roles = APIUtils.getAllRolesOfUser(user);
    try {
        if (query != null && !query.isEmpty()) {
            apiResults = getApiDAO().searchCompositeAPIs(roles, user, query, offset, limit);
        } else {
            apiResults = getApiDAO().getCompositeAPIs(roles, user, offset, limit);
        }
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while updating searching APIs - " + query;
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e, e.getErrorHandler());
    }
    return apiResults;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI)

Example 43 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.

the class PolicyDAOImplIT method testGetSubscriptionPolicies.

@Test(description = "Get Subscription Policies")
public void testGetSubscriptionPolicies() throws Exception {
    SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    SubscriptionPolicy policy2 = SampleTestObjectCreator.createSubscriptionPolicyWithBandwithLimit();
    // policy 1 has following 2 true. checking for fault scenario from policy2
    policy2.setStopOnQuotaReach(false);
    policy2.setDeployed(false);
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    // add policy
    policyDAO.addSubscriptionPolicy(policy);
    policyDAO.addSubscriptionPolicy(policy2);
    List<SubscriptionPolicy> policyList = policyDAO.getSubscriptionPolicies();
    Assert.assertNotNull(policyList);
    SubscriptionPolicy retrievedPolicy = null;
    SubscriptionPolicy retrievedPolicy2 = null;
    // there are defaut policies already there
    for (Iterator iterator = policyList.iterator(); iterator.hasNext(); ) {
        SubscriptionPolicy subscriptionPolicy = (SubscriptionPolicy) iterator.next();
        if (subscriptionPolicy.getPolicyName().equals(policy.getPolicyName())) {
            retrievedPolicy = policy;
        }
        if (subscriptionPolicy.getPolicyName().equals(policy2.getPolicyName())) {
            retrievedPolicy2 = policy2;
        }
    }
    Assert.assertNotNull(retrievedPolicy, "Policy " + policy.getPolicyName() + " not in DB");
    Assert.assertNotNull(retrievedPolicy2, "Policy " + policy2.getPolicyName() + " not in DB");
    Assert.assertEquals(retrievedPolicy.getPolicyName(), policy.getPolicyName(), "Subscription policy name mismatch");
    Assert.assertEquals(retrievedPolicy.getDisplayName(), policy.getDisplayName(), "Subscription policy display name mismatch");
    Assert.assertEquals(retrievedPolicy.getDescription(), policy.getDescription(), "Subscription policy description mismatch");
    Assert.assertEquals(retrievedPolicy.isDeployed(), policy.isDeployed(), "Subscription policy isDeployed mismatch");
    Assert.assertEquals(retrievedPolicy.getRateLimitCount(), policy.getRateLimitCount(), "Subscription policy rate limit mismatch");
    Assert.assertEquals(retrievedPolicy.getRateLimitTimeUnit(), policy.getRateLimitTimeUnit(), "Subscription policy rate limit mismatch");
    Assert.assertEquals(retrievedPolicy.isStopOnQuotaReach(), policy.isStopOnQuotaReach(), "Subscription policy stop on quota reach mismatch");
    Assert.assertEquals(retrievedPolicy.getCustomAttributes(), policy.getCustomAttributes(), "Subscription policy custom attribute mismatch");
    Assert.assertEquals(retrievedPolicy.getDefaultQuotaPolicy().getType(), policy.getDefaultQuotaPolicy().getType(), "Subscription policy default quota type mismatch");
    RequestCountLimit limitRetrieved = (RequestCountLimit) retrievedPolicy.getDefaultQuotaPolicy().getLimit();
    RequestCountLimit policyLimit = (RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit();
    Assert.assertEquals(limitRetrieved.getRequestCount(), policyLimit.getRequestCount(), "Subscription policy default quota count mismatch");
    Assert.assertEquals(limitRetrieved.getTimeUnit(), policyLimit.getTimeUnit(), "Subscription policy default quota time unit mismatch");
    Assert.assertEquals(limitRetrieved.getUnitTime(), policyLimit.getUnitTime(), "Subscription policy default quota unit time mismatch");
    // check policy related properties for policy 2
    Assert.assertEquals(retrievedPolicy2.getPolicyName(), policy2.getPolicyName(), "Subscription policy name mismatch");
    Assert.assertEquals(retrievedPolicy2.getDisplayName(), policy2.getDisplayName(), "Subscription policy display name mismatch");
    Assert.assertEquals(retrievedPolicy2.getDescription(), policy2.getDescription(), "Subscription policy description mismatch");
    Assert.assertEquals(retrievedPolicy2.isDeployed(), policy2.isDeployed(), "Subscription policy isDeployed mismatch");
    Assert.assertEquals(retrievedPolicy2.getRateLimitCount(), policy2.getRateLimitCount(), "Subscription policy rate limit mismatch");
    Assert.assertEquals(retrievedPolicy2.getRateLimitTimeUnit(), policy2.getRateLimitTimeUnit(), "Subscription policy rate limit mismatch");
    Assert.assertEquals(retrievedPolicy2.isStopOnQuotaReach(), policy2.isStopOnQuotaReach(), "Subscription policy stop on quota reach mismatch");
    Assert.assertEquals(retrievedPolicy2.getCustomAttributes(), policy2.getCustomAttributes(), "Subscription policy custom attribute mismatch");
    Assert.assertEquals(retrievedPolicy2.getDefaultQuotaPolicy().getType(), policy2.getDefaultQuotaPolicy().getType(), "Subscription policy default quota type mismatch");
    BandwidthLimit limitRetrieved2 = (BandwidthLimit) retrievedPolicy2.getDefaultQuotaPolicy().getLimit();
    BandwidthLimit policyLimit2 = (BandwidthLimit) policy2.getDefaultQuotaPolicy().getLimit();
    Assert.assertEquals(limitRetrieved2.getDataAmount(), policyLimit2.getDataAmount(), "Subscription policy default quota data amount mismatch");
    Assert.assertEquals(limitRetrieved2.getDataUnit(), policyLimit2.getDataUnit(), "Subscription policy default quota data amount mismatch");
    Assert.assertEquals(limitRetrieved2.getTimeUnit(), policyLimit2.getTimeUnit(), "Subscription policy default quota time unit mismatch");
    Assert.assertEquals(limitRetrieved2.getUnitTime(), policyLimit2.getUnitTime(), "Subscription policy default quota unit time mismatch");
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Iterator(java.util.Iterator) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit) Test(org.testng.annotations.Test)

Example 44 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.

the class PolicyDAOImplIT method testGetAPIPolicyWithBandwidthLimit.

@Test(description = "Get API Policies with bandwidth limit")
public void testGetAPIPolicyWithBandwidthLimit() throws Exception {
    APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicyWithBandwidthLimit();
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    // add policy
    policyDAO.addApiPolicy(policy);
    Policy policyAdded = policyDAO.getApiPolicy(policy.getPolicyName());
    Assert.assertNotNull(policyAdded);
    Assert.assertEquals(policyAdded.getPolicyName(), policy.getPolicyName());
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 45 with Limit

use of org.wso2.carbon.apimgt.api.model.policy.Limit in project carbon-apimgt by wso2.

the class PolicyDAOImplIT method testGetSubscriptionPolicyByUUIDandName.

@Test(description = "Get Subscription Policy by Name and UUID")
public void testGetSubscriptionPolicyByUUIDandName() throws Exception {
    SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    // add policy
    policyDAO.addSubscriptionPolicy(policy);
    SubscriptionPolicy retrievedPolicy = policyDAO.getSubscriptionPolicy(policy.getPolicyName());
    Assert.assertNotNull(retrievedPolicy);
    Assert.assertEquals(retrievedPolicy.getPolicyName(), policy.getPolicyName(), "Subscription policy name mismatch");
    Assert.assertEquals(retrievedPolicy.getDisplayName(), policy.getDisplayName(), "Subscription policy display name mismatch");
    Assert.assertEquals(retrievedPolicy.getDescription(), policy.getDescription(), "Subscription policy description mismatch");
    Assert.assertEquals(retrievedPolicy.isDeployed(), policy.isDeployed(), "Subscription policy isDeployed mismatch");
    Assert.assertEquals(retrievedPolicy.getRateLimitCount(), policy.getRateLimitCount(), "Subscription policy rate limit mismatch");
    Assert.assertEquals(retrievedPolicy.getRateLimitTimeUnit(), policy.getRateLimitTimeUnit(), "Subscription policy rate limit mismatch");
    Assert.assertEquals(retrievedPolicy.isStopOnQuotaReach(), policy.isStopOnQuotaReach(), "Subscription policy stop on quota reach mismatch");
    Assert.assertEquals(retrievedPolicy.getCustomAttributes(), policy.getCustomAttributes(), "Subscription policy custom attribute mismatch");
    Assert.assertEquals(retrievedPolicy.getDefaultQuotaPolicy().getType(), policy.getDefaultQuotaPolicy().getType(), "Subscription policy default quota type mismatch");
    RequestCountLimit limitRetrieved = (RequestCountLimit) retrievedPolicy.getDefaultQuotaPolicy().getLimit();
    RequestCountLimit policyLimit = (RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit();
    Assert.assertEquals(limitRetrieved.getRequestCount(), policyLimit.getRequestCount(), "Subscription policy default quota count mismatch");
    Assert.assertEquals(limitRetrieved.getTimeUnit(), policyLimit.getTimeUnit(), "Subscription policy default quota time unit mismatch");
    Assert.assertEquals(limitRetrieved.getUnitTime(), policyLimit.getUnitTime(), "Subscription policy default quota unit time mismatch");
    // get the UUID of the created policy. since this value is generated in the code, we use previously retrieved
    // policy to get the uuid and again query the policy
    String uuid = retrievedPolicy.getUuid();
    retrievedPolicy = policyDAO.getSubscriptionPolicyByUuid(uuid);
    Assert.assertNotNull(retrievedPolicy);
    Assert.assertEquals(retrievedPolicy.getPolicyName(), policy.getPolicyName(), "Subscription policy name mismatch");
    Assert.assertEquals(retrievedPolicy.getDisplayName(), policy.getDisplayName(), "Subscription policy display name mismatch");
    Assert.assertEquals(retrievedPolicy.getDescription(), policy.getDescription(), "Subscription policy description mismatch");
    Assert.assertEquals(retrievedPolicy.isDeployed(), policy.isDeployed(), "Subscription policy isDeployed mismatch");
    Assert.assertEquals(retrievedPolicy.getRateLimitCount(), policy.getRateLimitCount(), "Subscription policy rate limit mismatch");
    Assert.assertEquals(retrievedPolicy.getRateLimitTimeUnit(), policy.getRateLimitTimeUnit(), "Subscription policy rate limit mismatch");
    Assert.assertEquals(retrievedPolicy.isStopOnQuotaReach(), policy.isStopOnQuotaReach(), "Subscription policy stop on quota reach mismatch");
    Assert.assertEquals(retrievedPolicy.getCustomAttributes(), policy.getCustomAttributes(), "Subscription policy custom attribute mismatch");
    Assert.assertEquals(retrievedPolicy.getDefaultQuotaPolicy().getType(), policy.getDefaultQuotaPolicy().getType(), "Subscription policy default quota type mismatch");
    limitRetrieved = (RequestCountLimit) retrievedPolicy.getDefaultQuotaPolicy().getLimit();
    policyLimit = (RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit();
    Assert.assertEquals(limitRetrieved.getRequestCount(), policyLimit.getRequestCount(), "Subscription policy default quota count mismatch");
    Assert.assertEquals(limitRetrieved.getTimeUnit(), policyLimit.getTimeUnit(), "Subscription policy default quota time unit mismatch");
    Assert.assertEquals(limitRetrieved.getUnitTime(), policyLimit.getUnitTime(), "Subscription policy default quota unit time mismatch");
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)49 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)41 Test (org.testng.annotations.Test)29 PreparedStatement (java.sql.PreparedStatement)22 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)21 API (org.wso2.carbon.apimgt.api.model.API)20 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)19 Map (java.util.Map)18 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 SQLException (java.sql.SQLException)16 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)16 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)15 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)15 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)15 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)14 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)13 PaginationDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.PaginationDTO)13 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)13 GovernanceArtifact (org.wso2.carbon.governance.api.common.dataobjects.GovernanceArtifact)12