use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionToDTO.
/**
* Converts a SubscribedAPI object into SubscriptionDTO
*
* @param subscription SubscribedAPI object
* @return SubscriptionDTO corresponds to SubscribedAPI object
*/
public static SubscriptionDTO fromSubscriptionToDTO(Subscription subscription) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionId(subscription.getId());
if (subscription.getApi() != null) {
subscriptionDTO.setApiIdentifier(subscription.getApi().getId());
subscriptionDTO.setApiName(subscription.getApi().getName());
subscriptionDTO.setApiVersion(subscription.getApi().getVersion());
}
if (subscription.getApplication() != null) {
subscriptionDTO.setApplicationId(subscription.getApplication().getId());
}
subscriptionDTO.setPolicy(subscription.getPolicy().getPolicyName());
subscriptionDTO.setLifeCycleStatus(SubscriptionDTO.LifeCycleStatusEnum.valueOf(subscription.getStatus().toString()));
return subscriptionDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsPost.
@Test
public void testSubscriptionsPost() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String apiId = UUID.randomUUID().toString();
String subsID1 = UUID.randomUUID().toString();
String subsID2 = UUID.randomUUID().toString();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Application application = SampleTestObjectCreator.createDefaultApplication();
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
Mockito.when(apiStore.getApplicationByUuid(applicationId)).thenReturn(application);
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
SubscriptionDTO subscriptionDTO = SubscriptionMappingUtil.fromSubscriptionToDTO(SampleTestObjectCreator.createSubscription(subsID1));
Response response = subscriptionsApiService.subscriptionsPost(subscriptionDTO, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class MappingUtil method convertToSubscriptionListDto.
/**
* This method converts List of SubscriptionValidationData into SubscriptionDTO list.
*
* @param subscriptionValidationData List of Subscription Validation Data
* @return SubscriptionDTO list
*/
public static List<SubscriptionDTO> convertToSubscriptionListDto(List<SubscriptionValidationData> subscriptionValidationData) {
List<SubscriptionDTO> subscriptionDTOList = new ArrayList<>();
for (SubscriptionValidationData subscriptionData : subscriptionValidationData) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setApiName(subscriptionData.getApiName());
subscriptionDTO.setApiContext(subscriptionData.getApiContext());
subscriptionDTO.setApiVersion(subscriptionData.getApiVersion());
subscriptionDTO.setApiProvider(subscriptionData.getApiProvider());
subscriptionDTO.setConsumerKey(subscriptionData.getConsumerKey());
subscriptionDTO.setSubscriptionPolicy(subscriptionData.getSubscriptionPolicy());
subscriptionDTO.setKeyEnvType(subscriptionData.getKeyEnvType());
subscriptionDTO.setApplicationId(subscriptionData.getApplicationId());
subscriptionDTO.setStatus(subscriptionData.getStatus());
subscriptionDTOList.add(subscriptionDTO);
}
return subscriptionDTOList;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method unBlockSubscription.
/**
* Unblocks a subscription
*
* @param subscriptionId subscription identifier
* @param ifMatch If-Match header value
* @return 200 response and the updated subscription if subscription block is successful
*/
public Response unBlockSubscription(String subscriptionId, String ifMatch, MessageContext messageContext) {
String username = RestApiCommonUtil.getLoggedInUsername();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getProvider(username);
// validates the subscriptionId if it exists
SubscribedAPI currentSubscription = apiProvider.getSubscriptionByUUID(subscriptionId);
if (currentSubscription == null) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_SUBSCRIPTION, subscriptionId, log);
}
SubscribedAPI subscribedAPI = new SubscribedAPI(subscriptionId);
subscribedAPI.setSubStatus(APIConstants.SubscriptionStatus.UNBLOCKED);
apiProvider.updateSubscription(subscribedAPI);
SubscribedAPI updatedSubscribedAPI = apiProvider.getSubscriptionByUUID(subscriptionId);
SubscriptionDTO subscriptionDTO = SubscriptionMappingUtil.fromSubscriptionToDTO(updatedSubscribedAPI);
return Response.ok().entity(subscriptionDTO).build();
} catch (APIManagementException e) {
String msg = "Error while unblocking the subscription " + subscriptionId;
RestApiUtil.handleInternalServerError(msg, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method fromAdditionalSubscriptionInfoToDTO.
/**
* Converts a AdditionalSubscriptionInfo object into AdditionalSubscriptionInfoDTO
*
* @param subscription SubscribedAPI object
* @param organization Identifier of the organization
* @return SubscriptionDTO corresponds to SubscribedAPI object
*/
public static AdditionalSubscriptionInfoDTO fromAdditionalSubscriptionInfoToDTO(SubscribedAPI subscription, String organization) throws APIManagementException {
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
AdditionalSubscriptionInfoDTO additionalSubscriptionInfoDTO = new AdditionalSubscriptionInfoDTO();
additionalSubscriptionInfoDTO.setSubscriptionId(subscription.getUUID());
APIIdentifier apiId = subscription.getApiId();
API api = null;
if (apiId != null) {
try {
api = apiConsumer.getLightweightAPIByUUID(apiId.getUUID(), organization);
} catch (APIManagementException e) {
String msg = "User :" + username + " does not have access to the API " + apiId;
RestApiUtil.handleInternalServerError(msg, e, log);
}
}
additionalSubscriptionInfoDTO.setApiId(api.getUuid());
// Set Application information
Application application = subscription.getApplication();
application = apiConsumer.getApplicationByUUID(application.getUUID());
additionalSubscriptionInfoDTO.setApplicationId(subscription.getApplication().getUUID());
additionalSubscriptionInfoDTO.setApplicationName(application.getName());
additionalSubscriptionInfoDTO.setIsSolaceAPI(SolaceNotifierUtils.checkWhetherAPIDeployedToSolaceUsingRevision(api));
if (additionalSubscriptionInfoDTO.isIsSolaceAPI()) {
// Set Solace organization details if API is a Solace API
additionalSubscriptionInfoDTO.setSolaceOrganization(SolaceNotifierUtils.getThirdPartySolaceBrokerOrganizationNameOfAPIDeployment(api));
Map<String, Environment> gatewayEnvironmentMap = APIUtil.getReadOnlyGatewayEnvironments();
Environment solaceEnvironment = null;
for (Map.Entry<String, Environment> entry : gatewayEnvironmentMap.entrySet()) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
solaceEnvironment = entry.getValue();
}
}
if (solaceEnvironment != null) {
List<SolaceDeployedEnvironmentDTO> solaceDeployedEnvironmentsDTOS = SolaceStoreUtils.getSolaceDeployedEnvsInfo(solaceEnvironment, additionalSubscriptionInfoDTO.getSolaceOrganization(), application.getUUID());
List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> solaceEnvironments = new ArrayList<>();
for (SolaceDeployedEnvironmentDTO solaceDeployedEnvironmentEntry : solaceDeployedEnvironmentsDTOS) {
// Set Solace environment details
AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO solaceDeployedEnvironmentsDTO = new AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO();
solaceDeployedEnvironmentsDTO.setEnvironmentName(solaceDeployedEnvironmentEntry.getEnvironmentName());
solaceDeployedEnvironmentsDTO.setEnvironmentDisplayName(solaceDeployedEnvironmentEntry.getEnvironmentDisplayName());
solaceDeployedEnvironmentsDTO.setOrganizationName(solaceDeployedEnvironmentEntry.getOrganizationName());
// Set Solace URLs
List<AdditionalSubscriptionInfoSolaceURLsDTO> endpointUrls = new ArrayList<>();
List<SolaceURLsDTO> solaceURLsDTOS = solaceDeployedEnvironmentEntry.getSolaceURLs();
for (SolaceURLsDTO entry : solaceURLsDTOS) {
AdditionalSubscriptionInfoSolaceURLsDTO solaceURLsDTO = new AdditionalSubscriptionInfoSolaceURLsDTO();
solaceURLsDTO.setProtocol(entry.getProtocol());
solaceURLsDTO.setEndpointURL(entry.getEndpointURL());
endpointUrls.add(solaceURLsDTO);
}
solaceDeployedEnvironmentsDTO.setSolaceURLs(endpointUrls);
// Set Solace Topic Objects
solaceDeployedEnvironmentsDTO.setSolaceTopicsObject(mapSolaceTopicObjects(solaceDeployedEnvironmentEntry.getSolaceTopicsObject()));
solaceEnvironments.add(solaceDeployedEnvironmentsDTO);
}
additionalSubscriptionInfoDTO.setSolaceDeployedEnvironments(solaceEnvironments);
}
}
return additionalSubscriptionInfoDTO;
}
Aggregations