Search in sources :

Example 11 with KeyValueBasedPcrDAOImpl

use of com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl 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)

Example 12 with KeyValueBasedPcrDAOImpl

use of com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl in project core-util by WSO2Telco.

the class UUIDPCRService method updatePcrMsisdnMap.

private void updatePcrMsisdnMap(RequestDTO requestDTO, String pcrValue) throws PCRException {
    if (DEBUG)
        log.debug("Updating PCR MSISDN Map");
    String userId = requestDTO.getUserId();
    String sectorId = requestDTO.getSectorId();
    String pcr = pcrValue;
    KeyValueBasedPcrDAOImpl keyValueBasedPcrDAO = new KeyValueBasedPcrDAOImpl();
    keyValueBasedPcrDAO.createNewPCRMSISDNEntry(userId, sectorId, pcr);
}
Also used : KeyValueBasedPcrDAOImpl(com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl)

Aggregations

KeyValueBasedPcrDAOImpl (com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl)12 Test (org.junit.Test)7 RequestDTO (com.wso2telco.core.pcrservice.model.RequestDTO)3 PCRException (com.wso2telco.core.pcrservice.exception.PCRException)2 UUID (java.util.UUID)1 OAuthConsumerAppDTO (org.wso2.carbon.identity.oauth.stub.dto.OAuthConsumerAppDTO)1