Search in sources :

Example 6 with PCRException

use of com.wso2telco.core.pcrservice.exception.PCRException in project core-util by WSO2Telco.

the class OAuthApplicationData method getApplicationData.

public OAuthConsumerAppDTO getApplicationData(String appId) throws PCRException {
    OAuthConsumerAppDTO apps = null;
    OAuthAdminServiceStub oAuthAdminServiceStub;
    try {
        if (DEBUG)
            log.debug("initializing the o Auth Admin Service stub");
        Object stub = this.stubs.borrowObject();
        if (stub != null) {
            oAuthAdminServiceStub = (OAuthAdminServiceStub) stub;
            if (cookie != null) {
                oAuthAdminServiceStub._getServiceClient().getOptions().setProperty(HTTPConstants.COOKIE_STRING, cookie);
            }
            apps = oAuthAdminServiceStub.getOAuthApplicationData(appId);
            // apps = oAuthAdminServiceStub.getAllOAuthApplicationData();
            ServiceContext serviceContext = oAuthAdminServiceStub._getServiceClient().getLastOperationContext().getServiceContext();
            cookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);
        } else {
            log.warn("Stub initialization failed.");
        }
    } catch (Exception e) {
        log.error("error initializing the stub", e);
        throw new PCRException("error initializing the stub");
    }
    return apps;
}
Also used : OAuthAdminServiceStub(org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub) ServiceContext(org.apache.axis2.context.ServiceContext) PCRException(com.wso2telco.core.pcrservice.exception.PCRException) OAuthConsumerAppDTO(org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO) PCRException(com.wso2telco.core.pcrservice.exception.PCRException)

Example 7 with PCRException

use of com.wso2telco.core.pcrservice.exception.PCRException in project core-util by WSO2Telco.

the class UUIDPCRService method getPcr.

public String getPcr(RequestDTO requestDTO) throws PCRException {
    KeyValueBasedPcrDAOImpl keyValueBasedPcrDAO = new KeyValueBasedPcrDAOImpl();
    if (DEBUG) {
        log.debug("PCR service : userID : {}", requestDTO.getUserId());
        log.debug("PCR service : appID : {}", requestDTO.getAppId());
        log.debug("PCR service : sectorID : {}", requestDTO.getSectorId());
    }
    if (validateParameters(requestDTO)) {
        log.error("Mandatory parameters are empty");
        throw new PCRException("Mandatory parameters are empty");
    }
    // check whether there is an existing pcr for the given UserId,
    // SectorId, AppId combination (RequestDTO)
    String pcr = keyValueBasedPcrDAO.getExistingPCR(requestDTO);
    // if there is an existing pcr for the given RequestDTO
    if (pcr != null) {
        if (DEBUG)
            log.debug("PCR service : Existing PCR found");
        uuid = pcr;
    } else {
        if (DEBUG) {
            log.debug("PCR service : There is no Exisiting PCR, Creating New PCR");
            log.debug("PCR service : check whether there is an existing application, for the given UserId, SectorId");
        }
        // Otherwise check whether there is an existing application/s for
        // the given userId, SectorId combination
        List<String> applicationIdList = keyValueBasedPcrDAO.getAppIdListForUserSectorCombination(requestDTO.getUserId(), requestDTO.getSectorId());
        // combination, create and persist new pcr
        if (applicationIdList.isEmpty()) {
            log.debug("PCR service : No Existing app for the given UserID, SectorID");
            updateServiceProviderMap(requestDTO.getAppId());
            uuid = createAndPersistNewPcr(requestDTO);
            updatePcrMsisdnMap(requestDTO, uuid);
        } else {
            // provider map
            if (DEBUG) {
                log.debug("PCR service : Existing application found");
                log.debug("PCR service : Check application exists in the SP map");
            }
            if (!keyValueBasedPcrDAO.checkApplicationExists(requestDTO.getSectorId(), requestDTO.getAppId())) {
                updateServiceProviderMap(requestDTO.getAppId());
            }
            if (DEBUG) {
                log.debug("PCR service : Aplication found in the SP map");
                log.debug("PCR service : Check whether the app is related");
            }
            // map check whether the app is related
            if (keyValueBasedPcrDAO.checkIsRelated(requestDTO.getSectorId(), requestDTO.getAppId())) {
                boolean relatedAppExists = false;
                String applicationId = null;
                for (String appId : applicationIdList) {
                    relatedAppExists = keyValueBasedPcrDAO.checkIsRelated(requestDTO.getSectorId(), appId);
                    if (relatedAppExists) {
                        applicationId = appId;
                        break;
                    }
                }
                if (relatedAppExists) {
                    RequestDTO newRequestDTO = new RequestDTO(requestDTO.getUserId(), applicationId, requestDTO.getSectorId());
                    uuid = keyValueBasedPcrDAO.getExistingPCR(newRequestDTO);
                    createAndPersistNewPcr(requestDTO, uuid);
                } else {
                    uuid = createAndPersistNewPcr(requestDTO);
                    updatePcrMsisdnMap(requestDTO, uuid);
                }
            } else {
                // if the app is not related return a new pcr and
                // persist
                uuid = createAndPersistNewPcr(requestDTO);
                updatePcrMsisdnMap(requestDTO, uuid);
            }
        }
    }
    return uuid;
}
Also used : PCRException(com.wso2telco.core.pcrservice.exception.PCRException) RequestDTO(com.wso2telco.core.pcrservice.model.RequestDTO) KeyValueBasedPcrDAOImpl(com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl)

Aggregations

PCRException (com.wso2telco.core.pcrservice.exception.PCRException)7 Returnable (com.wso2telco.core.pcrservice.Returnable)3 KeyValueBasedPcrDAOImpl (com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl)2 OAuthAdminServiceStub (org.wso2.carbon.identity.oauth.stub.OAuthAdminServiceStub)2 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)2 RequestDTO (com.wso2telco.core.pcrservice.model.RequestDTO)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 AxisFault (org.apache.axis2.AxisFault)1 Options (org.apache.axis2.client.Options)1 ServiceClient (org.apache.axis2.client.ServiceClient)1 ServiceContext (org.apache.axis2.context.ServiceContext)1 HttpTransportProperties (org.apache.axis2.transport.http.HttpTransportProperties)1