39 Restricting Bundle Validity Based on Roles

Learn how to you can restrict the validity or end date set by CSRs while purchasing additional products or services.

Topics in this document:

About Restricting Bundle Validity

Typically, CSRs set the validity or end date of a product or service in a bundle (/deal object) during purchase. For additional purchases, you can customize Billing Care to restrict the validity or end date set by the CSR based on the CSR's role by using the OPSS policies and the Billing Care SDK.

For example, for an additional discount purchased from a bundle, you can allow a CSR with the super user role to set an end date up to a maximum of 12 months, and allow a CSR with a basic role to set an end date only up to a maximum of 6 months.

Restricting Bundle Validity

You can customize the Purchase Catalogue screen using OPSS policies to restrict the end date set by CSRs for additional purchases.

To restrict bundle validity:

  1. Define a new ResourceType and Resource in the OPSS Server for restricting bundle validity, such as DealResourceType and DealResource.
  2. Define purchase as the corresponding action for the ResourceType in the OPSS Server.
  3. Associate the new resource that you created to a CSR who has permission to purchase products or services.
  4. Add the new ResourceType to the CustomConfigurations.xml file. For example:
    <keyvals> 
       <key>authorizationResourceTypes</key> 
       <value>DealResourceType</value> 
       <desc>Add comma separated OPSS Resource Types(values) for authorization. 
             Also these resource types should be defined in OPSS. 
             Please note that the key should not be changed here. 
       </desc> 
    </keyvals>
  5. To set the validity allowed for a CSR, add an obligation with a string (for example, maximum validity end month) for a policy using OPSS and set a numeric value to the string (for example, 6).
  6. Create a custom REST resource for validating the end date entered in the Purchase Catalogue screen. See "Creating CustomAccountResource.java Class" for more information.
  7. Create a custom view model to override the default additional purchase logic with your customization. See "Creating a Custom Purchase View Model" for more information.
  8. Create a customRegistry.js file to configure Billing Care to use the custom view model that you created. See "Configuring the Custom Purchase View Model in the Registry" for more information.
  9. Deploy your customizations using one of the methods described in "Using an Exploded Archive during Customization" or "Packaging and Deploying Customizations".

  10. Verify your changes in Billing Care by doing the following:

    1. Log in to Billing Care as a CSR who has the permission to purchase products or services and obligation to validate end date during purchase.
    2. Purchase an additional charge or discount offer. For more information, see the Billing Care Online Help.
    3. In the Configure screen, enter an end date for the purchased offer.

    If the end date exceeds the end date specified in the obligation associated with the CSR, an error is displayed. If it matches or less than the end date in the obligation, CSR is allowed to configure the offer.

Creating CustomAccountResource.java Class

Create a custom resource Java class to get the list of all customized charge offers and discount offers in Billing Care and validate their end dates.

To create the customAccountResource.java class:

  1. Create the CustomAccountResource.java file in myproject/projectname//src/java/com/oracle/communications/brm/cc/ws/account, where myproject is your NetBeans IDE Billing Care customizations project and projectname is the name of your custom project.

  2. Add the following code in the CustomAccountResource.java file using a text editor:

    //This custom REST validates the deal end month with the obligation and then 
    calls the OOTB REST resource. 
    
    @Path("customaccounts") 
    public class CustomAccountResource { 
       
        @Context 
        HttpServletRequest servletRequest; 
           
        @Path("{id}/custombundle") 
        @POST 
        @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) 
        public void purchaseCustomizedBundle(@PathParam("id") String id, 
    CustomizedBundleForPurchase custbundle) throws JSONException, IOException { 
      
             
    /* 
    *  Get the list of all CustomizedChargeOffers using 
    getCustomizedChargeOffers() method of CustomizedBundleForPurchase class. 
    */ 
    List <CustomizedChargeOffers> custoffer = 
    custbundle.getCustomizedChargeOffers(); 
                List <CustomizedDiscountOffers> custDistOffer = 
    custbundle.getCustomizedDiscountOffers(); 
    
    /* 
    *  Iterate through each charge offer and get the purchaseEnd months and 
    validate the same against OPSS obligation 
    */ 
    for (CustomizedChargeOffers i : custoffer) 
    { 
    purchaseEnd=i.getPurchaseEnd(); 
    months=purchaseEnd.getUnitSettings().getOffset(); 
           
    
    UIRequestValue maxValidityEndMonthLimit = new UIRequestValue("Maximum 
    validity end month", 
      new BigDecimal(months), ConstraintOperator.GREATER_THAN, 
    new EnforcementError(40002,"Maximum validity end month exceeded"));     
      
    //Checks if user is not super csr and UI value is greater than OPSS 
    obligation value and throws error "Maximum validity end month exceeded" 
    if (!EnforcementUtil.isResourceGranted(servletRequest, subject, 
    "BillingCare", EnforcementConstants.SUPERUSER_RESOURCE)) { 
       EnforcementUtil.checkAccess(subject, "BillingCare", "Purchase", 
    "DealResourceType","DealResource", 
    error, maxValidityEndMonthLimit); 
    }           
    } 
    
    Repeat the above validations for all the discount offers as well by 
    iterating through custDistOffer. 
    
    
    /* 
    *After validating maximum validity end month criteria invoke out of the 
    box code to perform purchase.In below steps 
    *we have used jersey clients to achieve the same. 
    */ 
    
    1. Create a new Jersey Client   
    2. Create a webresource passing the baseURI ( 
    host:port/bc/webresources/v1.0/accounts/id/bundle ). 
    3. Convert custbundle java object to json object. 
    
    String scheme = servletRequest.getScheme();             // http or https
    String serverName = servletRequest.getServerName();     // hostname.com
    int serverPort = servletRequest.getServerPort();        // port
    String BASE_URI = scheme + " + serverName + ":" + serverPort + "/bc/webresources/v1.0/accounts/";                        
    Client client = Client.create();                            
    ObjectMapper mapper = new ObjectMapper();  
    String jsonInString = mapper.writeValueAsString(custbundle);
    JSONObject object = new JSONObject(jsonInString);    
           
    javax.servlet.http.Cookie[] cookies=servletRequest.getCookies();            
    WebResource webResource2 = client.resource(BASE_URI).path(id).path("bundle");           
    WebResource.Builder webresourceBuilder = webResource2.accept(MediaType.APPLICATION_JSON);
    Cookie cookieObject =null;
           
    for(javax.servlet.http.Cookie cookie: cookies)
            {
                if(cookie.getName().contains("JSESSIONID"))
                {     
                    cookieObject = new Cookie(cookie.getName(),cookie.getValue());              
                    webresourceBuilder.cookie(cookieObject);
                }           
            }   
    webresourceBuilder.post(ClientResponse.class, object);
    
    }
    }
  3. Save the file in your NetBeans IDE project.

Creating a Custom Purchase View Model

Billing Care uses view model to define the display of the screens in Billing Care. You must create or update the custom view model, CustomPurcahseViewModel, and add the details containing the logic to validate the end date for offers and allow purchase.

See "About View Models" for more information about Billing Care view models.

To create a custom purchase view model:

  1. Create or update the customPurchaseViewModel.js file in myproject/web/custom/viewmodels directory.
  2. Add the following code in the customPurchaseViewModel.js file using a text editor:
     define(['knockout', 
            'jquery', 
            'underscore', 
            Registry.accountCreation.wizardBase, 
            'viewmodels/purchase/PurchaseViewModel', 
            Registry.purchase.wizardView, 
            'viewmodels/purchase/PurchaseCatalogue' 
           ], 
            function (ko, $, _, WizardBaseViewModel, PurchaseViewModel, 
    wizardTempl, PurchaseCatalogue) { 
                 
                 
                CustomPurchaseViewModel.prototype = new WizardBaseViewModel(); 
                 
                function CustomPurchaseViewModel(title, content, messages) { 
                    WizardBaseViewModel.apply(this, arguments); 
                    PurchaseViewModel.apply(this, arguments); 
    
                    var self = this; 
                    self.sharedData = {}; 
                    self.purchaseCatalogue = new PurchaseCatalogue(); 
    
                    self.purchaseBundle = function (stepObj) {         
                        var id = self.sharedData.selectedServiceId || 
    globalAppContext.currentAccountViewModel().account().id(); 
                        var urlToFetch = baseURL + "/customaccounts/" + id + 
    "/custombundle"; 
                        var data  = 
    ko.toJSON(self.purchaseCatalogue.bundlePurchaseData); 
                        util.showBusyCursor(); 
                        var ajaxDef = $.ajax({ 
                            type: "POST", 
                            url: urlToFetch, 
                            data: data, 
                            contentType: "application/json; charset=utf-8", 
                            dataType: "json", 
                            processData: false 
                        }); 
                        ajaxDef.done(function (completeResponse) { 
                            self.updateStatus(stepObj, 'confirmation'); 
                            EventNotifier.assetsUpdated.dispatch("all"); 
                            EventNotifier.billUnitsUpdated.dispatch(); 
                            self.isInProgress(false); 
                            util.resetCursor(); 
                            self.close(); 
                        }); 
                        ajaxDef.fail(function (errorThrown) { 
                            alert(util.getLocalizedValue(purchasePackage, 
    "UNABLE_TO_PURCHASE_BUNDLE")); 
                            self.updateStatus(stepObj, 'error'); 
                            self.isInProgress(false); 
                            util.resetCursor(); 
                        }); 
                        return ajaxDef; 
                    }; 
                } 
                return CustomPurchaseViewModel; 
            }); 
       
  3. Save the file in your NetBeans IDE project.

Configuring the Custom Purchase View Model in the Registry

After creating the required custom view model, create a custom purchase view model entry in the customRegistry.js file. Billing Care uses the custom purchase view model instead of the default view model during additional product purchase and renders the Purchase Add on Deal Confirmation screen containing your customization.

To create the custom purchase view model entry in the registry:

  1. Create a customRegistry.js file in myproject/web/custom/ directory.
  2. Define the custom purchase view model in this file. For example:
    purchaseConfiguration: { 
       viewModel: 'custom/viewModels/purchase/customPurchaseViewModel.js' 
    } 
  3. Save the file in your NetBeans IDE project.