Search in sources :

Example 1 with SubscriberInfoDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriberInfoDTO in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method fromSubscriberClaimsToDTO.

/**
 * Convert Subscriber claims information into SubscriberInfoDTO
 *
 * @param subscriberClaims list of subscriber claims
 * @param subscriberName   subscriber name
 * @return SubscriberInfoDTO
 * @throws APIManagementException If an error occurs when getting display name of claim
 */
public static SubscriberInfoDTO fromSubscriberClaimsToDTO(Map<String, String> subscriberClaims, String subscriberName) throws APIManagementException {
    SubscriberInfoDTO subscriberInfoDTO = new SubscriberInfoDTO();
    subscriberInfoDTO.setName(subscriberName);
    List<ClaimDTO> claimDTOList = new ArrayList<>();
    for (String key : subscriberClaims.keySet()) {
        ClaimDTO claimDTO = new ClaimDTO();
        claimDTO.setName(APIUtil.getClaimDisplayName(key, subscriberName));
        claimDTO.setURI(key);
        claimDTO.setValue(subscriberClaims.get(key));
        claimDTOList.add(claimDTO);
    }
    subscriberInfoDTO.setClaims(claimDTOList);
    return subscriberInfoDTO;
}
Also used : ClaimDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClaimDTO) ArrayList(java.util.ArrayList) SubscriberInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriberInfoDTO)

Example 2 with SubscriberInfoDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriberInfoDTO in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImpl method getSubscriberInfoBySubscriptionId.

@Override
public Response getSubscriberInfoBySubscriptionId(String subscriptionId, MessageContext messageContext) throws APIManagementException {
    if (StringUtils.isBlank(subscriptionId)) {
        String errorMessage = "Subscription ID cannot be empty or null when getting subscriber info.";
        RestApiUtil.handleBadRequest(errorMessage, log);
    }
    String username = RestApiCommonUtil.getLoggedInUsername();
    APIProvider apiProvider = RestApiCommonUtil.getProvider(username);
    String subscriberName = apiProvider.getSubscriber(subscriptionId);
    Map subscriberClaims = apiProvider.getSubscriberClaims(subscriberName);
    SubscriberInfoDTO subscriberInfoDTO = SubscriptionMappingUtil.fromSubscriberClaimsToDTO(subscriberClaims, subscriberName);
    return Response.ok().entity(subscriberInfoDTO).build();
}
Also used : SubscriberInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriberInfoDTO) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) Map(java.util.Map)

Aggregations

SubscriberInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriberInfoDTO)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)1 ClaimDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClaimDTO)1