Search in sources :

Example 1 with RequestDTO

use of com.wso2telco.core.pcrservice.model.RequestDTO in project core-util by WSO2Telco.

the class KeyValueBasedPcrDAOImplTest method testCreateNewPcrEntry.

@Test
public void testCreateNewPcrEntry() throws PCRException {
    RequestDTO dto = new RequestDTO("u", "a", "s");
    RequestDTO dto1 = new RequestDTO("u1", "a1", "s1");
    RequestDTO dto2 = new RequestDTO("u1", "a2", "s1");
    RequestDTO dto3 = new RequestDTO("u3", "a3", "s3");
    RequestDTO dto4 = new RequestDTO("u4", "a4", "s4");
    RequestDTO dto5 = new RequestDTO("u5", "a5", "s5");
    RequestDTO dto6 = new RequestDTO("u6", "a6", "s6");
    RequestDTO dto7 = new RequestDTO("u7", "a7", "s7");
    RequestDTO dto8 = new RequestDTO("u8", "a8", "s8");
    RequestDTO dto9 = new RequestDTO("u9", "a9", "s9");
    RequestDTO dto0 = new RequestDTO("u0", "a0", "s0");
    KeyValueBasedPcrDAOImpl keyValueBasedPcrDAOImpl = new KeyValueBasedPcrDAOImpl();
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto, "p");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto1, "p1");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto2, "p1");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto3, "p3");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto4, "p4");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto5, "p5");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto6, "p6");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto7, "p7");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto8, "p8");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto9, "p9");
    keyValueBasedPcrDAOImpl.createNewPcrEntry(dto0, "p0");
}
Also used : RequestDTO(com.wso2telco.core.pcrservice.model.RequestDTO) KeyValueBasedPcrDAOImpl(com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl) Test(org.junit.Test)

Example 2 with RequestDTO

use of com.wso2telco.core.pcrservice.model.RequestDTO in project core-util by WSO2Telco.

the class KeyValueBasedPcrDAOImplTest method testgetExistingPCR.

@Test
public void testgetExistingPCR() throws PCRException {
    KeyValueBasedPcrDAOImpl keyValueBasedPcrDAOImpl = new KeyValueBasedPcrDAOImpl();
    RequestDTO requestDTO = new RequestDTO("u1", "a1", "s1");
    assertEquals(keyValueBasedPcrDAOImpl.getExistingPCR(requestDTO), "p1");
}
Also used : RequestDTO(com.wso2telco.core.pcrservice.model.RequestDTO) KeyValueBasedPcrDAOImpl(com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl) Test(org.junit.Test)

Example 3 with RequestDTO

use of com.wso2telco.core.pcrservice.model.RequestDTO 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 4 with RequestDTO

use of com.wso2telco.core.pcrservice.model.RequestDTO in project core-util by WSO2Telco.

the class PCRFactoryTest method testGenerateUUIDPcr.

@Test
public void testGenerateUUIDPcr() throws PCRException {
    PCRFactory pcrFactory = new PCRFactory();
    RequestDTO requestDTO = new RequestDTO("u1", "ax", "s1");
    PCRGeneratable pcrGeneratable = pcrFactory.getPCRGenarator();
    Returnable pcr = pcrGeneratable.getPCR(requestDTO);
    System.out.println(pcr.getID());
    // assertThat();
    assertEquals("p1", pcr.getID());
}
Also used : RequestDTO(com.wso2telco.core.pcrservice.model.RequestDTO) Test(org.junit.Test)

Aggregations

RequestDTO (com.wso2telco.core.pcrservice.model.RequestDTO)4 KeyValueBasedPcrDAOImpl (com.wso2telco.core.pcrservice.dao.impl.KeyValueBasedPcrDAOImpl)3 Test (org.junit.Test)3 PCRException (com.wso2telco.core.pcrservice.exception.PCRException)1