use of org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class MappingUtil method convertToApplicationDtoList.
/**
* convert {@link ApplicationDTO} to {@link Application}
*
* @param applicationList List of {@link Application}
* @return ApplicationEvent list
*/
public static List<ApplicationDTO> convertToApplicationDtoList(List<Application> applicationList) {
List<ApplicationDTO> applicationDTOList = new ArrayList<>();
for (Application application : applicationList) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setName(application.getName());
applicationDTO.setApplicationId(application.getId());
applicationDTO.setThrottlingTier(application.getPolicy().getUuid());
applicationDTO.setSubscriber(application.getCreatedUser());
applicationDTOList.add(applicationDTO);
}
return applicationDTOList;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsApplicationIdGet.
/**
* Retrives an existing application
*
* @param applicationId application Id
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Requested application detials as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response applicationsApplicationIdGet(String applicationId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
ApplicationDTO applicationDTO = null;
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiConsumer = RestApiUtil.getConsumer(username);
String existingFingerprint = applicationsApplicationIdGetFingerprint(applicationId, ifNoneMatch, ifModifiedSince, request);
if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
return Response.notModified().build();
}
Application application = apiConsumer.getApplication(applicationId, username);
if (application != null) {
applicationDTO = ApplicationMappingUtil.fromApplicationToDTO(application);
return Response.ok().entity(applicationDTO).header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").build();
} else {
String errorMessage = "Application not found: " + applicationId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.APPLICATION_NOT_FOUND);
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving application: " + applicationId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, applicationId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationToDTO.
public static ApplicationDTO fromApplicationToDTO(Application application) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(application.getId());
applicationDTO.setThrottlingTier(application.getPolicy().getPolicyName());
applicationDTO.setDescription(application.getDescription());
applicationDTO.setName(application.getName());
applicationDTO.setLifeCycleStatus(application.getStatus());
applicationDTO.setPermission(application.getPermissionString());
applicationDTO.setSubscriber(application.getCreatedUser());
List<ApplicationKeysDTO> applicationKeyDTOs = new ArrayList<>();
for (OAuthApplicationInfo applicationKeys : application.getApplicationKeys()) {
ApplicationKeysDTO applicationKeysDTO = ApplicationKeyMappingUtil.fromApplicationKeysToDTO(applicationKeys);
applicationKeyDTOs.add(applicationKeysDTO);
}
applicationDTO.setToken(ApplicationKeyMappingUtil.fromApplicationTokenToDTO(application.getApplicationToken()));
applicationDTO.setKeys(applicationKeyDTOs);
return applicationDTO;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsPostErrorCase.
@Test
public void testApplicationsPostErrorCase() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String accessToken = UUID.randomUUID().toString();
String clientID = UUID.randomUUID().toString();
String clientSecret = UUID.randomUUID().toString();
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Application application = getSampleApplication(applicationId);
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
ApplicationCreationResponse creationResponse = new ApplicationCreationResponse(UUID.randomUUID().toString(), workflowResponse);
Mockito.when(apiStore.addApplication(application)).thenReturn(creationResponse);
Mockito.when(apiStore.getApplication(creationResponse.getApplicationUUID(), USER)).thenReturn(application);
ApplicationTokenDTO applicationTokenDTO = new ApplicationTokenDTO();
applicationTokenDTO.setAccessToken(accessToken);
applicationTokenDTO.setTokenScopes("SCOPE1");
applicationTokenDTO.setValidityTime((long) 100000);
List<String> grantTypes = new ArrayList<>();
grantTypes.add("password");
grantTypes.add("jwt");
ApplicationKeysDTO applicationKeysDTO = new ApplicationKeysDTO();
applicationKeysDTO.setConsumerKey(clientID);
applicationKeysDTO.setConsumerSecret(clientSecret);
applicationKeysDTO.setKeyType(ApplicationKeysDTO.KeyTypeEnum.PRODUCTION);
applicationKeysDTO.setCallbackUrl(null);
applicationKeysDTO.setSupportedGrantTypes(grantTypes);
List<ApplicationKeysDTO> applicationKeysDTOList = new ArrayList<>();
applicationKeysDTOList.add(applicationKeysDTO);
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(applicationId);
applicationDTO.setDescription("sample application");
applicationDTO.setName("app1");
applicationDTO.setSubscriber("subscriber");
applicationDTO.setPermission("permission");
applicationDTO.setLifeCycleStatus("APPROVED");
applicationDTO.setThrottlingTier("UNLIMITED");
applicationDTO.setToken(applicationTokenDTO);
applicationDTO.setKeys(applicationKeysDTOList);
Response response = applicationsApiService.applicationsPost(applicationDTO, request);
Assert.assertEquals(201, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdPut.
@Test
public void testApplicationsApplicationIdPut() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String accessToken = UUID.randomUUID().toString();
String clientID = UUID.randomUUID().toString();
String clientSecret = UUID.randomUUID().toString();
ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
ApplicationTokenDTO applicationTokenDTO = new ApplicationTokenDTO();
applicationTokenDTO.setAccessToken(accessToken);
applicationTokenDTO.setTokenScopes("SCOPE1");
applicationTokenDTO.setValidityTime((long) 100000);
List<String> grantTypes = new ArrayList<>();
grantTypes.add("password");
grantTypes.add("jwt");
ApplicationKeysDTO applicationKeysDTO = new ApplicationKeysDTO();
applicationKeysDTO.setConsumerKey(clientID);
applicationKeysDTO.setConsumerSecret(clientSecret);
applicationKeysDTO.setKeyType(ApplicationKeysDTO.KeyTypeEnum.PRODUCTION);
applicationKeysDTO.setCallbackUrl(null);
applicationKeysDTO.setSupportedGrantTypes(grantTypes);
List<ApplicationKeysDTO> applicationKeysDTOList = new ArrayList<>();
applicationKeysDTOList.add(applicationKeysDTO);
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(applicationId);
applicationDTO.setDescription("sample application");
applicationDTO.setName("app1");
applicationDTO.setSubscriber("subscriber");
applicationDTO.setPermission("permission");
applicationDTO.setLifeCycleStatus("APPROVED");
applicationDTO.setThrottlingTier("UNLIMITED");
applicationDTO.setToken(applicationTokenDTO);
applicationDTO.setKeys(applicationKeysDTOList);
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
Mockito.when(apiStore.getApplication(applicationId, USER)).thenReturn(getSampleApplication(applicationId));
Mockito.when(apiStore.updateApplication(applicationId, getSampleApplication(applicationId))).thenReturn(workflowResponse);
Mockito.when(apiStore.getApplication(applicationId, USER)).thenReturn(getSampleApplication(applicationId));
Response response = applicationsApiService.applicationsApplicationIdPut(applicationId, applicationDTO, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
Aggregations