import org.json.JSONObject; import org.json.JSONArray; import java.lang.Integer; import java.lang.Boolean; String customerType = otmRequest.payload.getAvailableProducts.customerType; String customerCat = otmRequest.payload.getAvailableProducts.customerCat; String customerSpecificNpaNxx = otmRequest.payload.getAvailableProducts.customerSpecificNpaNxx; // Map npas homing data to addr based response or phone# based response JSONObject responsePayload = new JSONObject(); JSONObject eo = new JSONObject(); JSONArray switches = new JSONArray(); JSONObject locateAllReturn = new JSONObject(); locateAllReturn = locateAllResponse.Envelope.Body.locateAllResponse.locateAllReturn; // ONLY IF IT IS ADDRESS BASED // convert npasClient's Lec switch data to noes homing info // fill lec switch data eo.put("city", locateAllReturn.lecSwitch.city); eo.put("clli", locateAllReturn.lecSwitch.clli); eo.put("majorH", "" + locateAllReturn.lecSwitch.majorH); eo.put("majorV", "" + locateAllReturn.lecSwitch.majorV); eo.put("ocn", locateAllReturn.lecSwitch.ocn); eo.put("ocName", locateAllReturn.lecSwitch.ocnName); eo.put("state", locateAllReturn.lecSwitch.state); eo.put("street", locateAllReturn.lecSwitch.street); eo.put("zipCode", locateAllReturn.lecSwitch.zip); JSONArray npasMwcSwitches = new JSONArray(); if(locateAllReturn.mwcSwitches instanceof JSONObject){ npasMwcSwitches.put(locateAllReturn.mwcSwitches); } else{ npasMwcSwitches = locateAllReturn.getJSONArray("mwcSwitches"); } for(int i=0; i < npasMwcSwitches.length(); i++){ //******NxxInfo start JSONArray swNxxs = new JSONArray(); if(npasMwcSwitches.getJSONObject(i).has("nxxs")){ JSONArray npasMwcSwitchNxxs = new JSONArray(); if(npasMwcSwitches.getJSONObject(i).nxxs instanceof JSONObject){ JSONObject npasMwcSwitchNxx = new JSONObject(); npasMwcSwitchNxx = npasMwcSwitches.getJSONObject(i).nxxs; npasMwcSwitchNxxs.put(npasMwcSwitchNxx); } else{ npasMwcSwitchNxxs = npasMwcSwitches.getJSONObject(i).nxxs; } for(int j=0; j < npasMwcSwitchNxxs.length(); j++){ //Filter nxx based on NRM or BLM flag if( !("EDN".equalsIgnoreCase(customerCat)) && npasMwcSwitchNxxs.getJSONObject(j).optBoolean("nrmExcluded", false) || (npasMwcSwitchNxxs.getJSONObject(j).optBoolean("bmlExcluded", false) && !( "EXISTING".equals(customerType) || "ISP".equals(customerCat) || "Y".equals(customerSpecificNpaNxx)) ) ){ continue; } JSONObject swNxx = new JSONObject(); swNxx.put("npanxx", npasMwcSwitchNxxs.getJSONObject(j).npa + npasMwcSwitchNxxs.getJSONObject(j).nxx); swNxx.put("fromLine", npasMwcSwitchNxxs.getJSONObject(j).fromLine); swNxx.put("toLine", npasMwcSwitchNxxs.getJSONObject(j).toLine); swNxx.put("locality", npasMwcSwitchNxxs.getJSONObject(j).locality); swNxx.put("rateCenter", npasMwcSwitchNxxs.getJSONObject(j).rateCenter); swNxx.put("rateCenterState", npasMwcSwitchNxxs.getJSONObject(j).rateCenterState); if(npasMwcSwitchNxxs.getJSONObject(j).optBoolean("lineExhausted", false) ){ swNxx.put("lineExhaust", 'Y'); } else{ swNxx.put("lineExhaust", 'N'); } swNxx.put("bmlExclude", 'N'); swNxx.put("nrmExclude", 'N'); if(npasMwcSwitchNxxs.getJSONObject(j).optBoolean("portable", false) ){ swNxx.put("portable", 'Y'); } else{ swNxx.put("portable", 'N'); } swNxx.put("ocName", npasMwcSwitchNxxs.getJSONObject(j).toLine); swNxxs.put(swNxx); } //All Switches Filtered by NRM / BML Exclude flag if(swNxxs.length() == 0) { continue; } } //******swServices start JSONArray swServices = new JSONArray(); if(npasMwcSwitches.getJSONObject(i).has("services")){ JSONArray npasMwcSwitchCapacityServices = new JSONArray(); if(npasMwcSwitches.getJSONObject(i).services instanceof JSONObject){ npasMwcSwitchCapacityServices.put(npasMwcSwitches.getJSONObject(i).services); } else{ npasMwcSwitchCapacityServices = npasMwcSwitches.getJSONObject(i).services; } for(int j=0; j < npasMwcSwitchCapacityServices.length(); j++){ JSONObject swService = new JSONObject(); swService.put("capability", npasMwcSwitchCapacityServices.getJSONObject(j).capability); swService.put("availability", npasMwcSwitchCapacityServices.getJSONObject(j).availability); swService.put("capacity", npasMwcSwitchCapacityServices.getJSONObject(j).capacity); swService.put("speed", npasMwcSwitchCapacityServices.getJSONObject(j).speed); swServices.put(swService); } } //******Collos start JSONArray collos = new JSONArray(); if(npasMwcSwitches.getJSONObject(i).has("collos")){ JSONArray npasMwcSwitchCollos = new JSONArray(); if(npasMwcSwitches.getJSONObject(i).collos instanceof JSONObject){ JSONObject npasMwcSwitchCollo = new JSONObject(); npasMwcSwitchCollo = npasMwcSwitches.getJSONObject(i).collos; npasMwcSwitchCollos.put(npasMwcSwitchCollo); } else{ npasMwcSwitchCollos = npasMwcSwitches.getJSONObject(i).collos; } for(int j=0; j < npasMwcSwitchCollos.length(); j++){ JSONObject collo = new JSONObject(); JSONArray colloServices = new JSONArray(); if(npasMwcSwitchCollos.getJSONObject(j).has("services")){ JSONArray npasMwcSwitchColloCapacityServices = new JSONArray(); if(npasMwcSwitchCollos.getJSONObject(j).services instanceof JSONObject){ JSONObject npasMwcSwitchColloCapacityService = new JSONObject(); npasMwcSwitchColloCapacityService = npasMwcSwitchCollos.getJSONObject(j).services; npasMwcSwitchColloCapacityServices.put(npasMwcSwitchColloCapacityService); } else{ npasMwcSwitchColloCapacityServices = npasMwcSwitchCollos.getJSONObject(j).services; } for(int k=0; k < npasMwcSwitchColloCapacityServices.length(); k++){ JSONObject colloService = new JSONObject(); colloService.put("capability", npasMwcSwitchColloCapacityServices.getJSONObject(k).capability); colloService.put("availability", npasMwcSwitchColloCapacityServices.getJSONObject(k).availability); colloService.put("capacity", npasMwcSwitchColloCapacityServices.getJSONObject(k).capacity); colloService.put("speed", npasMwcSwitchColloCapacityServices.getJSONObject(k).speed); colloServices.put(colloService); } } JSONObject colloSwInfo = new JSONObject(); colloSwInfo.put("clli", npasMwcSwitchCollos.getJSONObject(j).clli); colloSwInfo.put("street", npasMwcSwitchCollos.getJSONObject(j).street); colloSwInfo.put("city", npasMwcSwitchCollos.getJSONObject(j).city); colloSwInfo.put("state", npasMwcSwitchCollos.getJSONObject(j).state); colloSwInfo.put("zipCode", npasMwcSwitchCollos.getJSONObject(j).zip); colloSwInfo.put("majorV", "" + npasMwcSwitchCollos.getJSONObject(j).majorV); colloSwInfo.put("majorH", "" + npasMwcSwitchCollos.getJSONObject(j).majorH); colloSwInfo.put("ocn", npasMwcSwitchCollos.getJSONObject(j).ocn); colloSwInfo.put("ocName", npasMwcSwitchCollos.getJSONObject(j).ocnName); collo.put("colloSwInfo", colloSwInfo); collo.put("services", colloServices); collo.put("bldCode", npasMwcSwitchCollos.getJSONObject(j).optJSONObject("bldCode")); collo.put("latitude", npasMwcSwitchCollos.getJSONObject(j).latitude); collo.put("longitude", npasMwcSwitchCollos.getJSONObject(j).longitude); collo.put("colloType", npasMwcSwitchCollos.getJSONObject(j).colloType.substring(0,1)); collo.put("distance", npasMwcSwitchCollos.getJSONObject(j).distance); collos.put(collo); } } //******npasMwcSwitchPlanInfos start JSONArray homingPlans = new JSONArray(); if(npasMwcSwitches.getJSONObject(i).has("homingPlans")){ JSONArray npasMwcSwitchPlanInfos = new JSONArray(); if(npasMwcSwitches.getJSONObject(i).homingPlans instanceof JSONObject){ npasMwcSwitchPlanInfos.put(npasMwcSwitches.getJSONObject(i).homingPlans); } else{ npasMwcSwitchPlanInfos = npasMwcSwitches.getJSONObject(i).homingPlans; } for(int j=0; j < npasMwcSwitchPlanInfos.length(); j++){ JSONObject homingPlan = new JSONObject(); homingPlan.put("customerType", npasMwcSwitchPlanInfos.getJSONObject(j).customerType); homingPlan.put("product", npasMwcSwitchPlanInfos.getJSONObject(j).product); homingPlan.put("transport", npasMwcSwitchPlanInfos.getJSONObject(j).transport); homingPlan.put("service", npasMwcSwitchPlanInfos.getJSONObject(j).service); homingPlan.put("billOption", npasMwcSwitchPlanInfos.getJSONObject(j).billOption); homingPlan.put("custCategory", npasMwcSwitchPlanInfos.getJSONObject(j).custCategory); homingPlan.put("priority", npasMwcSwitchPlanInfos.getJSONObject(j).priority); homingPlan.put("holdInd", npasMwcSwitchPlanInfos.getJSONObject(j).holdInd.substring(0, 1)); homingPlan.put("liftDate", npasMwcSwitchPlanInfos.getJSONObject(j).liftDate); homingPlan.put("holdComments", npasMwcSwitchPlanInfos.getJSONObject(j).holdComments); homingPlans.put(homingPlan); } } JSONObject mwcSwInfo = new JSONObject(); mwcSwInfo.put("clli", npasMwcSwitches.getJSONObject(i).clli); mwcSwInfo.put("street", npasMwcSwitches.getJSONObject(i).street); mwcSwInfo.put("city", npasMwcSwitches.getJSONObject(i).city); mwcSwInfo.put("state", npasMwcSwitches.getJSONObject(i).state); mwcSwInfo.put("zipCode", npasMwcSwitches.getJSONObject(i).zip); mwcSwInfo.put("majorV", "" + npasMwcSwitches.getJSONObject(i).majorV); mwcSwInfo.put("majorH", "" + npasMwcSwitches.getJSONObject(i).majorH); mwcSwInfo.put("ocn", npasMwcSwitches.getJSONObject(i).ocn); mwcSwInfo.put("ocName", npasMwcSwitches.getJSONObject(i).ocnName); JSONObject switchObj = new JSONObject(); switchObj.put("company", npasMwcSwitches.getJSONObject(i).company.substring(0,1) ); switchObj.put("switchName", npasMwcSwitches.getJSONObject(i).switchName); switchObj.put("switchId", npasMwcSwitches.getJSONObject(i).switchId); switchObj.put("switchType", npasMwcSwitches.getJSONObject(i).switchType); if(npasMwcSwitches.getJSONObject(i).optBoolean("converted", false) ){ switchObj.put("convertedInd", 'Y'); } else{ switchObj.put("convertedInd", 'N'); } switchObj.put("poiInd", npasMwcSwitches.getJSONObject(i).optJSONObject("poiInd") ); switchObj.put("switchInfo", mwcSwInfo); switchObj.put("switchServices", swServices); switchObj.put("mciSwCollos", collos); switchObj.put("mciSwNxxs", swNxxs); switchObj.put("mciSwPlans", homingPlans); switches.put(switchObj); } //end of for loop using index i responsePayload.put("lecSw", eo); responsePayload.put("mciSws", switches); return responsePayload;
Write, Run & Share Groovy code online using OneCompiler's Groovy online compiler for free. It's one of the robust, feature-rich online compilers for Groovy language, running the latest Groovy version 2.6. Getting started with the OneCompiler's Groovy editor is easy and fast. The editor shows sample boilerplate code when you choose language as Groovy and start coding.
OneCompiler's Groovy online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Groovy program which takes name as input and prints hello message with your name.
def name = System.in.newReader().readLine()
println "Hello " + name
Groovy is an object-oriented programming language based on java. Apache Groovy is a dynamic and agile language which is similar to Python, Ruby, Smalltalk etc.
Data type | Description | Range |
---|---|---|
String | To represent text literals | NA |
char | To represent single character literal | NA |
int | To represent whole numbers | -2,147,483,648 to 2,147,483,647 |
short | To represent short numbers | -32,768 to 32,767 |
long | To represent long numbers | -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 |
double | To represent 64 bit floating point numbers | 4.94065645841246544e-324d to 1.79769313486231570e+308d |
float | To represent 32 bit floating point numbers | 1.40129846432481707e-45 to 3.40282346638528860e+38 |
byte | To represent byte value | -128 to 127 |
boolean | To represent boolean values either true or false | True or False |
You can define variables in two ways
data-type variable-name;
[or]
def variable-name;
0.upto(n) {println "$it"}
or
n.times{println "$it"}
where n is the number of loops and 0 specifies the starting index
When ever you want to perform a set of operations based on a condition or set of conditions, then If / Nested-If / If-Else is used.
if(conditional-expression) {
// code
} else {
// code
}
Switch is an alternative to If-Else-If ladder and to select one among many blocks of code.
switch(conditional-expression) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
//code to be executed when all the above cases are not matched;
}
List allows you to store ordered collection of data values.
def mylist = [1,2,3,4,5];
List Methods | Description |
---|---|
size() | To find size of elements |
sort() | To sort the elements |
add() | To append new value at the end |
contains() | Returns true if this List contains requested value. |
get() | Returns the element of the list at the definite position |
pop() | To remove the last item from the List |
isEmpty() | Returns true if List contains no elements |
minus() | This allows you to exclude few specified elements from the elements of the original |
plus() | This allows you to add few specified elements to the elements of the original |
remove() | To remove the element present at the specific position |
reverse() | To reverse the elements of the original List and creates new list |