32 Restricting Bundle Validity Based on Roles

This chapter provides an overview of customizing Oracle Communications Billing Care to restrict the validity or end date set by the customer service representatives (CSRs) while purchasing additional products or services.

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 OES policies and the Billing Care SDK.

For example, for an additional discount purchased from a bundle, you can allow a CSR with super user role to set an end date up to a maximum of 12 months and a CSR with 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 OES 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 OES Server for restricting bundle validity. For example, DealResourceType, DealResource.

  2. Define purchase as the corresponding action for the ResourceType in the OES 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:

    <desc>Add comma separated OES Resource Types(values) for authorization. 
    Also these resource types should be defined in OES. 
    Please note that the key should not be changed here. 
  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 OES 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 into 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 a 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. 
    public class CustomAccountResource { 
        HttpServletRequest servletRequest; 
        @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 = 
                List <CustomizedDiscountOffers> custDistOffer = 
    *  Iterate through each charge offer and get the purchaseEnd months and 
    validate the same against OES obligation 
    for (CustomizedChargeOffers i : custoffer) 
    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 OES 
    obligation value and throws error "Maximum validity end month exceeded" 
    if (!EnforcementUtil.isResourceGranted(servletRequest, subject, 
    "BillingCare", EnforcementConstants.SUPERUSER_RESOURCE)) { 
       EnforcementUtil.checkAccess(subject, "BillingCare", "Purchase", 
    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 +
    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)
                     cookieObject = new Cookie(cookie.getName(),cookie.getValue());  
    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:

           ],         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 ||
                        var urlToFetch = baseURL + "/customaccounts/" + id + "/custombundle"; 
                        var data  = 
                        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'); 
                        ajaxDef.fail(function (errorThrown) { 
                            alert(util.getLocalizedValue(purchasePackage, "UNABLE_TO_PURCHASE_BUNDLE")); 
                            self.updateStatus(stepObj, 'error'); 
                        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 event adjustment view model entry in this file. For example:

    purchaseConfiguration: { 
           viewmodel: 'custom/viewModels/purchase/customPurchaseViewModel.js' 
  3. Save the file in your NetBeans IDE project.