use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtil method fromApplicationThrottlePolicyToDTO.
/**
* Converts a single Application Policy model into REST API DTO
*
* @param appPolicy An Application Policy model object
* @return Converted Application policy REST API DTO object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static ApplicationThrottlePolicyDTO fromApplicationThrottlePolicyToDTO(Policy appPolicy) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ApplicationThrottlePolicyDTO policyDTO = new ApplicationThrottlePolicyDTO();
policyDTO = CommonThrottleMappingUtil.updateFieldsFromToPolicyToDTO(appPolicy, policyDTO);
if (appPolicy.getDefaultQuotaPolicy() != null) {
policyDTO.setDefaultLimit(CommonThrottleMappingUtil.fromQuotaPolicyToDTO(appPolicy.getDefaultQuotaPolicy()));
}
return policyDTO;
}
use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtil method fromApplicationPolicyArrayToListDTO.
/**
* Converts an array of Application Policy objects into a List DTO
*
* @param appPolicies Array of Application Policies
* @return A List DTO of converted Application Policies
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(List<ApplicationPolicy> appPolicies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
if (appPolicies != null) {
for (Policy policy : appPolicies) {
ApplicationThrottlePolicyDTO dto = fromApplicationThrottlePolicyToDTO(policy);
appPolicyDTOList.add(dto);
}
}
listDTO.setCount(appPolicyDTOList.size());
listDTO.setList(appPolicyDTOList);
return listDTO;
}
use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.
the class LabelsApiServiceImplTest method testLabelsPost.
@Test
public void testLabelsPost() throws Exception {
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
Mockito.when(labelService.labelsPost(LabelMappingUtil.fromLabelToDTO(label1), "application/json", getRequest())).thenReturn(Response.status(Response.Status.CREATED).entity(LabelMappingUtil.fromLabelToDTO(label1)).build());
Response response = labelService.labelsPost(LabelMappingUtil.fromLabelToDTO(label1), "application/json", getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.CREATED);
}
use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.
the class LabelsApiServiceImplTest method testLabelsLabelIdPut.
@Test
public void testLabelsLabelIdPut() throws Exception {
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
List<Label> labels = new ArrayList<>();
Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
Label label2 = new Label.Builder().id("2").name("label2").type("STORE").build();
labels.add(label1);
labels.add(label2);
LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
Mockito.when(labelService.labelsLabelIdPut("1", LabelMappingUtil.fromLabelToDTO(label1), "application/Json", getRequest())).thenReturn(Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelArrayToListDTO(labels)).build());
Response response = labelService.labelsLabelIdPut("1", LabelMappingUtil.fromLabelToDTO(label1), "application/Json", getRequest());
Assert.assertEquals(response.getEntity(), LabelMappingUtil.fromLabelArrayToListDTO(labels));
}
use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdKeysKeyTypePut.
/**
* Update grant types/callback URL
*
* @param applicationId Application Id
* @param keyType Key Type (Production | Sandbox)
* @param body Grant type and callback URL information
* @param request msf4j request object
* @return Updated Key Information
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationsApplicationIdKeysKeyTypePut(String applicationId, String keyType, ApplicationKeysDTO body, Request request) throws NotFoundException {
try {
String username = RestApiUtil.getLoggedInUsername(request);
APIStore apiConsumer = RestApiUtil.getConsumer(username);
OAuthApplicationInfo oAuthApp = apiConsumer.updateGrantTypesAndCallbackURL(applicationId, keyType, body.getSupportedGrantTypes(), body.getCallbackUrl());
ApplicationKeysDTO appKeys = ApplicationKeyMappingUtil.fromApplicationKeysToDTO(oAuthApp);
return Response.ok().entity(appKeys).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while updating '" + keyType + "'-type grant types/callback url of " + "application: " + applicationId;
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
paramList.put(APIMgtConstants.ExceptionsConstants.KEY_TYPE, keyType);
paramList.put(APIMgtConstants.ExceptionsConstants.CALLBACK_URL, body.getCallbackUrl());
String grantTypes = null;
if (body.getSupportedGrantTypes() != null) {
grantTypes = String.join(",", body.getSupportedGrantTypes());
}
paramList.put(APIMgtConstants.ExceptionsConstants.GRANT_TYPES, grantTypes);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations