public Purchase updatePurchase( PurchaseResponse purchaseResponse, String numberType, String restrictions, ResourceMaster resourceMaster) { Purchase purchase = new Purchase(); try { purchase.setMonthlyRentalRate(resourceMaster.getMonthlyRentalPrice()); Provider provider = providerService.getProviderById(resourceMaster.getProviderId()); Country country = countryDao.getCountryByIso(resourceMaster.getCountryIso()); Providercountry providercountry = countryDao.getProviderCountryByCountryAndProvider(country, provider); purchase.setNumberType(numberType); purchase.setNumber(resourceMaster.getServiceCode()); purchase.setResouceManagerId(resourceMaster.getResourceId()); purchase.setEffectiveDate(ImiDataFormatUtils.getCurrentTimeStamp()); purchase.setRestrictions(restrictions); purchase.setSetUpRate(purchaseResponse.getSetUpRate()); purchase.setSmsRate(resourceMaster.getSmsInboundPrice()); purchase.setVoicePrice(resourceMaster.getVoiceInboundPrice()); purchase.setNumberProviderCountry(providercountry); purchaseDao.createNewPurchase(purchase); } catch (Exception e) { LOG.error(ImiDataFormatUtils.getStackTrace(e)); } return purchase; }
public ResourceMaster updateResource( String number, PurchaseResponse purchaseResponse, ServiceConstants serviceTypeEnum, Provider provider, Country country, Integer userid, Integer clientId, Integer groupid, Integer teamid, String clientname, String clientkey, String teamuuid, String numberType) { ResourceMaster resourceMaster = new ResourceMaster(); try { resourceMaster.setServiceCode(number); // may need to configure resourceMaster.setChannel(ImiDataFormatUtils.getChannel(serviceTypeEnum)); List<Object> creditsResultList = defaultQueryDao.getNamedQueryResults(creditsConfigQuery); BigInteger creditsMultiplier = new BigInteger("1"); if (creditsResultList.size() > 0) { creditsMultiplier = (BigInteger) creditsResultList.get(0); } // hardcoding need to configure int resourceType = 4; resourceMaster.setResourceType((byte) resourceType); resourceMaster.setCategory((byte) 2); resourceMaster.setSubCategory((byte) 0); resourceMaster.setProviderId(provider.getId()); resourceMaster.setNumberType(numberType); // hardcoding 2,5 for now need to configure String monthlyRentalRate = purchaseResponse.getMonthlyRentalRate() == null || purchaseResponse.getMonthlyRentalRate().trim().equals("") ? "0" : ImiDataFormatUtils.roundOffToN(purchaseResponse.getMonthlyRentalRate(), 2); monthlyRentalRate = ImiDataFormatUtils.multiply(monthlyRentalRate, creditsMultiplier.toString()); monthlyRentalRate = ImiDataFormatUtils.roundOffToN(monthlyRentalRate, 0); resourceMaster.setMonthlyRentalPrice(monthlyRentalRate); String voiceRate = purchaseResponse.getVoicePrice() == null || purchaseResponse.getVoicePrice().trim().equals("") ? "0" : ImiDataFormatUtils.roundOffToN(purchaseResponse.getVoicePrice(), 5); voiceRate = ImiDataFormatUtils.multiply(voiceRate, creditsMultiplier.toString()); voiceRate = ImiDataFormatUtils.roundOffToN(voiceRate, 0); resourceMaster.setVoiceInboundPrice(voiceRate); String smsRate = purchaseResponse.getSmsRate() == null || purchaseResponse.getSmsRate().trim().equals("") ? "0" : ImiDataFormatUtils.roundOffToN(purchaseResponse.getSmsRate(), 5); smsRate = ImiDataFormatUtils.multiply(smsRate, creditsMultiplier.toString()); smsRate = ImiDataFormatUtils.roundOffToN(smsRate, 0); resourceMaster.setSmsInboundPrice(smsRate); updateCreditsConfigResource(number, teamuuid, monthlyRentalRate); resourceMaster.setCountryCode(country.getCountryCode()); resourceMaster.setCountryIso(country.getCountryIso()); resourceMaster.setCreatedOn(new Date()); resourceMasterDao.createNewResource(resourceMaster); } catch (Exception e) { LOG.error(ImiDataFormatUtils.getStackTrace(e)); } return resourceMaster; }