au.com.optus.pei.express.coef2.template.businessreq.BusinessRequestTemplate.java Source code

Java tutorial

Introduction

Here is the source code for au.com.optus.pei.express.coef2.template.businessreq.BusinessRequestTemplate.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package au.com.optus.pei.express.coef2.template.businessreq;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.springframework.stereotype.Component;

/**
 *
 * @author muralir
 */

@Component
public class BusinessRequestTemplate {

    public String brTemplate(String s) {
        StringBuilder sb = new StringBuilder();
        JSONParser parser = new JSONParser();
        try {
            Object obj = parser.parse(s);
            JSONArray array = (JSONArray) obj;

            Map<String, String> map = new HashMap<String, String>();
            Iterator<JSONObject> iterator = array.iterator();

            while (iterator.hasNext()) {
                JSONObject factObj = (JSONObject) iterator.next();
                map.put((String) factObj.get("name"), (String) factObj.get("value"));
            }

            sb.append("Dear EIES Engagement,");
            sb.append(
                    "\nA new engagement request has been submitted via the online COEF Business Engagement Form. Details are as follows:");
            sb.append("\n\nRequest ID: 107");
            sb.append("\nName: ");
            sb.append(map.get("firstName"));
            sb.append("\nEmail:");
            sb.append(map.get("email"));
            sb.append("\nPhone: ");
            sb.append(map.get("phone"));
            sb.append("\nMobile:");
            sb.append(map.get("od[employeeMobile]"));
            sb.append("\nEmployee ID: ");
            sb.append(map.get("employeeID"));
            sb.append("\nWhat are you trying to achieve? ");
            sb.append(map.get("requestDescription"));
            if (map.containsKey("proposedStartDate")) {
                sb.append("\nWhen are you ready to start? ");
                sb.append(map.get("proposedStartDate"));
            }
            if (map.containsKey("proposedAvailableDate")) {
                sb.append("\nWhen would you like this change to be available? ");
                sb.append(map.get("proposedAvailableDate"));
            }

            sb.append("\nType of work requested: ");
            sb.append(map.get("requestType"));
            sb.append("\nCFU or Business Unit: ");
            sb.append(map.get("cfu"));
            sb.append("\nHas funding been identified for your request? ");
            sb.append(map.get("fundIdentified"));

            if (map.get("fundIdentified").equals("Yes")) {
                sb.append("\nWho will fund this? ");
                sb.append(map.get("sponsername"));
            } else {
                sb.append("\nDo you have a sponsor for this request? ");
                sb.append(map.get("haveSponser"));
            }
        } catch (ParseException pe) {
            // throws ;
        }

        return sb.toString();
    }
}