The contracting company and the major telecom.



  • My father has seen a course of WTFs in his life. Being a software engineer, what more is there to expect? However there has been one master WTF he has seen and is stuck maintaining, he was suspicious of from its preconception to its maturity. He works for a billion-dollar global telecommunications company that has a huge network of fiber directly to the home, which is called FTTP internally (fiber-to-the-premises). As with any telecommunications company technicians are needed to keep the network in order. At the heart of the technical department is a testing interface which lets them retrieve diagnostics on individual circuits, and helps them troubleshoot a customer as they are able to pull up information on every circuit that goes from their computers through the wires and tubes all the way to the customer's house. If a special router is hooked up, all computers on the network can be seen, and commands can be run remotely to the device. This is why we have always bought our own router. ;-)

    The architecture is multi-tiered, and has several back ends, front ends and everything in between. The front end used most often was a standard desktop application, currently maintained by a contracting company whose name will not be disclosed. The desktop application was designed from the ground-up with maintenance in mind, and always worked nicely for the technicians. They proposed the idea of a web application to the telecom where people would do their work from their browser. The telecom liked the idea so the contracting company hired a Russian programmer and gave him a hefty sum. After the course of about four years the application was complete having over two thousand classes and half a million lines of code almost all undocumented apart from Eclipse’s template header since the programmer spoke very little English. My father was working for this contracting company at the time, working on one of the archaic back ends using an obscure programming language originally for AI programming called ART Enterprise.

    The middle end would pull gather information from the several back ends, all for testing different circuit types, and report it to the front end using a proprietary format known as ASSOC messaging, which was almost entirely, but not quite like JSON. The information would be forced into JSP, thrown through Java, be exported to XML, be formatted by XSL on the server which HTML for that section. This was by design, and was working perfectly until logging improved to log every XSL transformation, in which there were about 60 per page load, with many redundant duplicates. Which should be multiplied by 9 for each of the application’s 9 frames, many of which are "updaters" which constantly poll the servers for new data and use JavaScript to inject the resulting HTML. The resulting HTML would be thrown out to IE (the company standard) to make a somewhat pleasant experience. The programmer clearly didn't have a clear understanding of HTML or CSS. I was asked by my father to help with some coding inserting an inline image into a small tab. Simple, right? Err… no. Everything was aligned to the pixel: to get a border on a tab working correctly, the programmer used a div with the border color as background, all elements in the tab "covered" the background color, including the tab label, an “a” element with a font-size of 13.24916px.

    When the telecom wanted to put more people on the team, it all fell apart. The boss of the contracting company was stuck, the Russian programmer couldn’t do training, and there was no documentation for anyone else. The programmer's brain was the most important asset to the web application. The telecom didn't like to hear that they couldn't put more people on the project, and they shoved the contracting company off the cliff. The telecom is now stuck with a half a million lines of code, and pays my father to maintain it. Word is a new application is in development, which is supposed to supercede it, but I’ve heard no frameworks are being used. I can only hope to see no more /** Performs some action. */ after this.

    And for your pleasure, I have a code snippet from a file named TestResultsParser.java and keep in mind that most comments were added by my father:


    /*
    * Created on Apr 18, 2003
    *
    * To change this generated comment go to Window>Preferences>Java>Code
    * Generation>Code and Comments
    */
    package GUILTY;

    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.Serializable;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;

    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.ParserConfigurationException;

    import org.w3c.dom.Document;
    import org.xml.sax.SAXException;

    /**
    * @author GUILTY
    * To change this generated comment go to Window>Preferences>Java>Code
    * Generation>Code and Comments
    */
    public class TestResultsParser implements TestResultsConstants {

    private static Map<String, Serializable> resultsMap = new HashMap<String, Serializable>();

    public static String resultSD = "";

    public static TestResultsUpdateEvent parseTestResults(Date time,
    String testId, String testPrintName, String diagnosis,
    String resultType, List results, List rawReadings, String displayClass) {

    List<TestSummary> lstResults = new LinkedList<TestSummary>();
    String reultStr = "";
    if(resultSD != null && resultSD.trim().length() > 0) {
    Document doc = TestResultsParser.getDocumentNode(resultSD);
    resultSD = "";
    Map resMap = Config.generateMapFromDOM(doc);
    String explanation = getSpecificDetailRemark(diagnosis, "EXPLANATION=");
    String action = getSpecificDetailRemark(diagnosis, "ACTION=");

    if(resMap != null && resMap.size() > 0)
    reultStr = getSimplifiedResultsTable(resMap, explanation, action);
    }

    if (results != null) {
    resultsMap.clear();
    Iterator it = results.iterator();
    if (testPrintName.indexOf(HOME_VIDEO_DIAGNOSTICS_TEST_NAME) != -1) {
    TestResultResponse.Result currentItem = (TestResultResponse.Result) it.next();
    String modifiedResultText = currentItem.text.substring(currentItem.text.indexOf(_SUMMARY_RESULT_TAG_));
    modifiedResultText = getVideoDiagResultsTable(modifiedResultText);
    currentItem = new TestResultResponse.Result(currentItem.id,
    currentItem.printName, modifiedResultText,
    currentItem.type, currentItem.pathList);
    TestSummary testSummary = new TestSummary(currentItem);
    if (!"IGNORE".equalsIgnoreCase(testSummary.getType()))
    lstResults.add(testSummary);
    }
    else {
    while (it.hasNext()) {
    TestResultResponse.Result currentItem = (TestResultResponse.Result) it.next();
    String afStatus = "";
    // if test is 'Perform Home Diagnostics' then get a formatted result
    if (testPrintName.indexOf(HOME_DIAGNOSTICS_TEST_NAME) != -1) {
    // ignore the initial part of the results until the <RESULT> tag
    String modifiedResultText = currentItem.text.substring(currentItem.text.indexOf(_RESULT_TAG_));
    // get formatted result in HTML format
    modifiedResultText = getResultsTable(modifiedResultText, false);
    // pick up the Autofix Status - required for ordering the results
    afStatus = modifiedResultText.substring(0, modifiedResultText.indexOf(AF_STATUS_TAG));
    // clip off the Autofix Status part and just get the actual results string - delimiter is AF_STATUS_TAG
    modifiedResultText = modifiedResultText.substring(modifiedResultText.indexOf(AF_STATUS_TAG) + AF_STATUS_TAG.length());
    currentItem = new TestResultResponse.Result(currentItem.id,
    currentItem.printName, modifiedResultText,
    currentItem.type, currentItem.pathList);
    }
    // if test is 'PolicyManager Compare MPE Subscriber data / Get OM Statistics' then get a formatted result
    if (testPrintName.equalsIgnoreCase(POLICY_MANAGER_COMP_MPE_TEST_NAME)||
    testPrintName.equalsIgnoreCase(POLICY_MANAGER_OM_STATS_TEST_NAME)){
    String modifiedResultText = "";
    // get formatted result in HTML format
    modifiedResultText = getPolicyManagerResultsTable(currentItem.text, testPrintName);
    currentItem = new TestResultResponse.Result(currentItem.id,
    currentItem.printName, modifiedResultText,
    currentItem.type, currentItem.pathList);
    }
    TestSummary testSummary = new TestSummary(currentItem);
    if (!"IGNORE".equalsIgnoreCase(testSummary.getType()))
    lstResults.add(testSummary);

    // populate the results map - used for ordering the results
    // format: Map<auto_fix_status_string, List<test_summary_objects>>
    LinkedList<TestSummary> lst = new LinkedList<TestSummary>();
    if (resultsMap.containsKey(afStatus)) {
    lst = (LinkedList<TestSummary>)resultsMap.get(afStatus);
    }
    lst.add(testSummary);
    resultsMap.put(afStatus, lst);
    }

    // get the results in a specific order (AF_FAIL, AF_NEED_PERM, AF_SUCCESSFUL, AF_OTHER)
    // for Home diagnostics results
    if (testPrintName.indexOf(HOME_DIAGNOSTICS_TEST_NAME) != -1 && lstResults.size() > 1) {
    lstResults = getOrderedResults();
    }
    }
    }

    List<RawReading> lstRawReadings = new RawReadingList();

    if (rawReadings != null) {
    String singleMultilineRawReading = parseSingleMultilineRawReading(rawReadings);
    if (StringHelper.isEmpty(singleMultilineRawReading)) {
    Iterator it = rawReadings.iterator();
    for (int i = 0; it.hasNext(); i++) {
    TestResultResponse.RawReading currentItem = (TestResultResponse.RawReading) it
    .next();

    RawReading rawReading = new RawReading(i, currentItem);
    if (rawReading.getKey().endsWith("-default") || !rawReading.isNil())
    lstRawReadings.add(rawReading);
    }
    } else
    diagnosis = singleMultilineRawReading;
    }

    if(reultStr != null && reultStr.trim().length() > 0) {
    return new TestResultsUpdateEvent(new TestResultsUpdate(time, testId,
    testPrintName == null ? testId : testPrintName, resultType,
    diagnosis, lstResults, lstRawReadings, displayClass, reultStr));
    }

    return new TestResultsUpdateEvent(new TestResultsUpdate(time, testId,
    testPrintName == null ? testId : testPrintName, resultType,
    diagnosis, lstResults, lstRawReadings, displayClass));
    }

    /**
    * Transforms the result string from XML to HTML format (in a table);
    * Read this method along with hd-result-spec.xml from DtiNotes
    *
    * @param result - will be a map if this function is called from getVideoDiagResultsTable();
    * otherwise it will be a String (when called from getResultsTable() - Data Home Diagnostics.
    * @return
    */
    private static String getResultsTable (Object result, boolean isMap) {
    StringBuffer returnStr = new StringBuffer();
    try {
    if (result != null) {
    Map resMap = new HashMap();
    if (!isMap) {
    Document doc = getDocumentNode((String)result);
    resMap = Config.generateMapFromDOM(doc);
    returnStr.append(HOME_DIAGNOSTICS_TEST_NAME);
    }
    else {
    resMap = (Map) result;
    }
    returnStr.append(HTML_1);
    String afStatus = "";
    if (resMap != null) {
    TestResultHelper.loadAfStatusCodes();
    TestResultHelper.loadColorCodesForHnmResults();
    afStatus = ((Map)resMap.get(RESULT_TAG)).get(AF_STATUS_TAG).toString().trim();
    // any junk/unknown AF_STATUS value? replace it with AF_UNKNOWN
    if (afStatus == null || afStatus.length() < 1 || !TestResultHelper.AF_STATUS_LIST.contains(afStatus)) {
    afStatus = AF_UNKNOWN;
    }
    returnStr.replace(0, 0, afStatus + AF_STATUS_TAG);
    // background color of result heading depends on what the AUTO FIX STATUS is.
    String bkgrndClr = TestResultHelper.getColorCode(afStatus);
    String resultHeading = ((Map)resMap.get(RESULT_TAG)).get(NAME_TAG).toString().trim();
    Map tableMap = (Map)((Map)resMap.get(RESULT_TAG)).get(TABLE_TAG);
    Map headerMap = (Map)tableMap.get(HEADER_TAG);
    returnStr.append(HTML_2 + headerMap.size() + HTML_3 + bkgrndClr + HTML_4);
    if (afStatus.equalsIgnoreCase(AF_FAILED)) {
    returnStr.append(HTML_4_1 + resultHeading + HTML_4_2);
    }
    else {
    returnStr.append(resultHeading);
    }
    returnStr.append(HTML_5);
    Object rows = tableMap.get(ROW_TAG);
    Iterator hIter = headerMap.keySet().iterator();
    returnStr.append(HTML_6);
    boolean isFirstItem = true;
    while (hIter.hasNext()) {
    if (isFirstItem) {
    returnStr.append(HTML_7 + HTML_8 + headerMap.get(hIter.next()).toString().trim() + HTML_9);
    isFirstItem = false;
    }
    else {
    returnStr.append(HTML_7 + HTML_10 + headerMap.get(hIter.next()).toString().trim() + HTML_9);
    }
    }
    isFirstItem = true;
    returnStr.append(HTML_11);
    if (rows instanceof List) {
    Iterator lstIter = ((List) rows).listIterator();
    while (lstIter.hasNext()) {
    returnStr.append(HTML_6);
    Map rowData = (Map) lstIter.next();
    Iterator rdIter = rowData.keySet().iterator();
    while (rdIter.hasNext()) {
    String data = rowData.get(rdIter.next()).toString().trim();
    if (data.length() == 0) {
    data = HTML_12;
    }
    if (isFirstItem) {
    returnStr.append(HTML_13 + data + HTML_14);
    isFirstItem = false;
    }
    else {
    returnStr.append(HTML_15 + data + HTML_14);
    }
    }
    }
    }
    else if (rows instanceof Map) {
    Iterator rdIter = ((Map) rows).keySet().iterator();
    returnStr.append(HTML_6);
    while (rdIter.hasNext()) {
    String data = ((Map)rows).get(rdIter.next()).toString().trim();
    if (data.length() == 0) {
    data = HTML_12;
    }
    if (isFirstItem) {
    returnStr.append(HTML_13 + data + HTML_14);
    isFirstItem = false;
    }
    else {
    returnStr.append(HTML_15 + data + HTML_14);
    }
    }
    }
    returnStr.append(HTML_11);
    }
    returnStr.append(HTML_16);
    }
    }
    catch (NullPointerException e) {
    e.printStackTrace();
    }

    return returnStr.toString();
    }

    private static String getVideoDiagResultsTable (String result) {
    StringBuffer returnStr = new StringBuffer();
    Map resMap = new HashMap();
    try {
    if (result != null) {
    Document doc = getDocumentNode(result);
    resMap = (Map)Config.generateMapFromDOM(doc).get(TestResultsConstants.SUMMARY_RESULT);
    returnStr.append(HOME_DIAGNOSTICS_TEST_NAME);
    String summary = resMap.get(SUMMARY).toString().trim();
    String trouble = resMap.get(TROUBLE).toString().trim();
    returnStr.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" style=\"background-color: white\" width=\"100%\"><tr><td><table width=\"100%\" cellspacing=\"10\" style=\"background-color:white\" >");
    returnStr.append("<tr><td width=\"25%\" style=\"font-weight: bold; text-align:left;\">TROUBLE REPORTED</td><td style=\"font-weight: normal; text-align:left;\">" + trouble + "</td></tr>");
    returnStr.append("<tr><td width=\"25%\" style=\"font-weight: bold; text-align:left;\">SUMMARY RESULT</td><td style=\"font-weight: normal; text-align:left;\">" + summary + "</td></tr>");
    returnStr.append("</table>");
    String resStringInHtml = "";

    // for SUMMARY RESULTs, we do not get any RESULT tags...
    if ((result).indexOf(_RESULT_TAG_) != -1) {
    String resultTags = result.substring(result.indexOf(_RESULT_TAG_), result.lastIndexOf(_RESULT_END_TAG_)+_RESULT_END_TAG_.length());
    while (resultTags.length() > 0 && resultTags.indexOf(_RESULT_TAG_) != -1) {
    String oneResult = resultTags.substring(resultTags.indexOf(_RESULT_TAG_), resultTags.indexOf(_RESULT_END_TAG_)+_RESULT_END_TAG_.length());
    resultTags = resultTags.substring(oneResult.length()).trim();

    Document docInner = getDocumentNode(oneResult);
    resMap = Config.generateMapFromDOM(docInner);
    String afStatus = "";
    // get formatted result in HTML format
    resStringInHtml = getResultsTable(resMap, true);
    // pick up the Autofix Status - required for ordering the results
    afStatus = resStringInHtml.substring(0, resStringInHtml.indexOf(AF_STATUS_TAG));
    // clip off the Autofix Status part and just get the actual results string - delimiter is AF_STATUS_TAG
    resStringInHtml = resStringInHtml.substring(resStringInHtml.indexOf(AF_STATUS_TAG) + AF_STATUS_TAG.length());
    resultsMap.put(afStatus, resStringInHtml);
    }
    LinkedList<String> orderedList = new LinkedList<String>();
    orderedList = getOrderedVideoResults();
    Iterator<String> ordResIter = orderedList.iterator();
    while (ordResIter.hasNext()) {
    returnStr.append(ordResIter.next());
    }
    }
    }
    }
    catch (NullPointerException e) {
    e.printStackTrace();
    }

    return returnStr.toString();
    }

    private static String getPMResultsTable (Object result, boolean isMap) {
    StringBuffer returnStr = new StringBuffer();
    String retStr="";
    try {
    if (result != null) {
    Map resMap = new HashMap();
    if (isMap) {
    resMap = (Map) result;
    }

    if (resMap != null) {
    Object rowList = ((Map)resMap.get(RESULT_TAG)).get(ROW_TAG);
    Map rowData0 = new HashMap();
    if (rowList instanceof List){
    Iterator lstIter0 = ((List) rowList).listIterator();
    while (lstIter0.hasNext()) {
    rowData0.putAll((Map) lstIter0.next());
    }
    }
    String resEquipment = "";
    String resCapacity = "";
    String resMpe = "";
    String resDate = "";
    String resTimeInt = "";
    try{
    resEquipment = rowData0.get(EQUIPMENT_TAG).toString().trim();
    }
    catch (NullPointerException e){}
    try{
    resCapacity = rowData0.get(CAPACITY_TAG).toString().trim();
    }
    catch (NullPointerException e){}
    try{
    resMpe = rowData0.get(MPE_TAG).toString().trim();
    }
    catch (NullPointerException e){}
    try{
    resDate = rowData0.get(DATE_TAG).toString().trim();
    }
    catch (NullPointerException e){}
    try{
    resTimeInt = rowData0.get(TIME_INTERVAL_TAG).toString().trim();
    }
    catch (NullPointerException e){}

    if ((resMpe != null)&&(resDate != null)&&(resTimeInt != null)&&(resMpe != "")&&(resDate != "")&&(resTimeInt != ""))
    {returnStr.append("<br/><b>"+resMpe+" "+resDate+" "+resTimeInt+"</b><br/><br/>");}

    if ((resEquipment != null) && (resEquipment != "")) {returnStr.append("<b>Equipment: </b>"+resEquipment+"<br/>");}
    if ((resCapacity != null) && (resCapacity != "")) {returnStr.append("<b>Capacity: </b>"+resCapacity+"<br/>");}


    returnStr.append(""+HTML_1_PM);
    //String resultHeading = ((Map)resMap.get(RESULT_TAG)).get(NAME_TAG).toString().trim();
    Map tableMap = (Map)((Map)resMap.get(RESULT_TAG)).get(TABLE_TAG);
    Map headerMap = (Map)tableMap.get(HEADER_TAG);
    //returnStr.append(HTML_2 + headerMap.size() + HTML_3 + "#ffffff" + HTML_4);
    //returnStr.append(resultHeading);
    //returnStr.append(HTML_5);
    Object rows = tableMap.get(ROW_TAG);
    Iterator hIter = headerMap.keySet().iterator();
    returnStr.append(HTML_6);
    boolean isFirstItem = true;
    while (hIter.hasNext()) {
    if (isFirstItem) {
    returnStr.append(HTML_7_PM +" "+ HTML_10 + headerMap.get(hIter.next()).toString().trim() + HTML_9);
    isFirstItem = false;
    }
    else {
    returnStr.append(HTML_7_PM +" "+ HTML_10 + headerMap.get(hIter.next()).toString().trim() + HTML_9);
    }
    }
    isFirstItem = true;
    returnStr.append(HTML_11);
    if (rows instanceof List) {
    Iterator lstIter = ((List) rows).listIterator();
    while (lstIter.hasNext()) {
    returnStr.append(HTML_6);
    Map rowData = (Map) lstIter.next();
    Iterator rdIter = rowData.keySet().iterator();
    while (rdIter.hasNext()) {
    String data = rowData.get(rdIter.next()).toString().trim();
    if (data.length() == 0) {
    data = HTML_12;
    }
    if (isFirstItem) {
    returnStr.append(HTML_15 + data + HTML_14);
    isFirstItem = false;
    }
    else {
    Pattern p=Pattern.compile("([\\d\\.]+)%");
    Matcher m = p.matcher(data);
    if (m.find()){
    String str1 = m.group(1);
    Double d = Double.parseDouble(m.group(1));
    if (d > 75){
    returnStr.append(HTML_15 + "<font color='red'>"+data+"</font>" + HTML_14);
    }
    else{
    returnStr.append(HTML_15 + data + HTML_14);
    }
    }
    else{
    returnStr.append(HTML_15 + data + HTML_14);
    }
    }
    }
    returnStr.append(HTML_11);
    }
    }
    else if (rows instanceof Map) {
    Iterator rdIter = ((Map) rows).keySet().iterator();
    returnStr.append(HTML_6);
    while (rdIter.hasNext()) {
    String data = ((Map)rows).get(rdIter.next()).toString().trim();
    if (data.length() == 0) {
    data = HTML_12;
    }
    if (isFirstItem) {
    returnStr.append(HTML_13 + data + HTML_14);
    isFirstItem = false;
    }
    else {
    returnStr.append(HTML_15 + data + HTML_14);
    }
    }
    returnStr.append(HTML_11);
    }
    returnStr.append(HTML_16_PM+"<br/>");
    }

    }
    retStr = returnStr.toString();
    retStr=retStr.replaceAll("SUCCESS","<img src='images/good.gif' >");
    retStr=retStr.replaceAll("FAIL","<img src='images/bad.gif' >");
    retStr=retStr.replaceAll("FAULT","<img src='images/bad.gif' >");
    retStr=retStr.replaceAll("UNKNOWN","<img src='images/incomplete.gif' >");
    }
    catch (NullPointerException e) {
    e.printStackTrace();
    }

    return retStr;
    }

    private static String getPolicyManagerResultsTable (String result, String testname) {
    StringBuffer returnStr = new StringBuffer();
    Map resMap = new HashMap();
    try {
    if (result != null) {
    Document doc = getDocumentNode(result);
    resMap = (Map)Config.generateMapFromDOM(doc).get(TestResultsConstants.SUMMARY_RESULT);
    returnStr.append(HOME_DIAGNOSTICS_TEST_NAME); //Hack . Should work with POLICY_MANAGER_COMP_MPE_TEST_NAME
    //String testname = resMap.get(NAME_TAG).toString().trim();
    String summary = resMap.get(SUMMARY).toString().trim();
    //String trouble = resMap.get(TROUBLE).toString().trim();
    returnStr.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"background-color: white\" width=\"100%\"><tr><td>");
    returnStr.append("<table width=\"100%\" cellspacing=\"0\" style=\"background-color:white\" >");
    returnStr.append("<tr><td style=\"text-align:left;\"><b>" + testname + "</b></td></tr>");
    returnStr.append("<tr><td style=\"text-align:left;\"><b>Summary Result: </b>" + summary + "</td></tr>");
    returnStr.append("</table>");
    StringBuffer resStringInHtml = new StringBuffer();

    // for SUMMARY RESULTs, we do not get any RESULT tags...
    if ((result).indexOf(_RESULT_TAG_) != -1) {
    String resultTags = result.substring(result.indexOf(_RESULT_TAG_), result.lastIndexOf(_RESULT_END_TAG_)+_RESULT_END_TAG_.length());
    while (resultTags.length() > 0 && resultTags.indexOf(_RESULT_TAG_) != -1) {
    String oneResult = resultTags.substring(resultTags.indexOf(_RESULT_TAG_), resultTags.indexOf(_RESULT_END_TAG_)+_RESULT_END_TAG_.length());
    resultTags = resultTags.substring(oneResult.length()).trim();

    Document docInner = getDocumentNode(oneResult);
    resMap = Config.generateMapFromDOM(docInner);
    // get formatted result in HTML format
    resStringInHtml.append(getPMResultsTable(resMap, true));
    }
    returnStr.append(resStringInHtml);
    }
    returnStr.append("</td></tr></table>");
    }
    }
    catch (NullPointerException e) {
    e.printStackTrace();
    }

    return returnStr.toString();
    }

    private static LinkedList<String> getOrderedVideoResults () {
    LinkedList<String> ordList = new LinkedList<String>();
    Iterator statusIter = TestResultHelper.AF_STATUS_LIST.listIterator();
    String resString = "";
    while (statusIter.hasNext()) {
    String status = statusIter.next().toString();
    if ((resString = (String)resultsMap.get(status)) != null) {
    ordList.add(resString);
    }
    resultsMap.remove(status);
    }
    // Check if there are any more results left - ones that sneaked in without an AF_STATUS
    // or with an AF_STATUS thats not in our list. If we find any, just insert them at the end
    // our results list
    if (resultsMap.size() > 0) {
    Iterator<String> leftOverResIter = resultsMap.keySet().iterator();
    while (leftOverResIter.hasNext()) {
    if ((resString = (String)resultsMap.get(leftOverResIter.next())) != null) {
    ordList.add(resString);
    }
    }
    }
    return ordList;
    }

    private static String getSpecificDetailRemark(String diagnosis, String detailRemark) {
    String returnStr = "";

    if(diagnosis.indexOf(detailRemark) != -1) {
    returnStr = diagnosis.substring(diagnosis.indexOf(detailRemark)).trim();
    if(returnStr.indexOf("\n") != -1)
    returnStr = returnStr.substring(detailRemark.length(), returnStr.indexOf("\n")).trim();
    else
    returnStr = returnStr.substring(detailRemark.length()).trim();
    }

    return returnStr;
    }

    public static String getSimplifiedResultsTable (Map resMap, String explanation, String action) {
    StringBuffer returnStr = new StringBuffer();
    try {

    returnStr.append(SIMPLIFIED_DETAIL);
    String explanationActionStr = getExplanationActionStr(explanation, action);
    if(explanationActionStr == null || explanationActionStr.trim().length() == 0)
    returnStr.append(HTML_SD_10 + HTML_SD_3 + HTML_SD_4);
    else
    returnStr.append(explanationActionStr);

    Map outputMap = (Map)resMap.get("output");
    String outputType = outputMap.get("type").toString().trim();
    String informationValue = "";
    int informationCount = 0;
    Object informations = outputMap.get("information");
    if (informations instanceof List) {
    Iterator lstIter = ((List) informations).listIterator();
    while (lstIter.hasNext()) {
    Map informationMap = (Map) lstIter.next();
    informationValue = getInformationStr(informationMap, informationCount, informationValue);
    informationCount++;
    }
    }
    else if (informations instanceof Map) {
    Map informationMap = (Map) informations;
    informationValue = getInformationStr(informationMap, informationCount, informationValue);
    informationCount++;
    }

    returnStr.append(HTML_SD_11 + HTML_SD_13 +informationValue+ HTML_SD_14 + HTML_SD_12);
    returnStr.append(HTML_SD_15 + HTML_SD_2 + HTML_SD_4 + HTML_15 + HTML_SD_1 + HTML_SD_5);
    Map dataheadingMap = (Map)outputMap.get("dataheading");
    String dataheadingName = dataheadingMap.get("name").toString().trim();
    returnStr.append(HTML_SD_27 + HTML_SD_13 +dataheadingName+ HTML_SD_14 + HTML_SD_17);
    String dataheadingValue = dataheadingMap.get("value").toString().trim();
    returnStr.append(HTML_SD_16 + HTML_SD_13 +dataheadingValue+ HTML_SD_14 + HTML_SD_17 + HTML_11);

    Object datas = outputMap.get("data");
    if (datas instanceof List) {
    Iterator lstIter = ((List) datas).listIterator();
    int dataCount = 0;
    while (lstIter.hasNext()) {
    Map dataMap = (Map) lstIter.next();
    appendDataStr(dataMap, returnStr, dataCount);
    dataCount++;
    }
    }
    else if (datas instanceof Map) {
    Map dataMap = (Map) datas;
    appendDataStr(dataMap, returnStr, 0);
    }

    returnStr.append(HTML_SD_18 + HTML_SD_22);

    }
    catch (NullPointerException e) {
    e.printStackTrace();
    }
    return returnStr.toString();

    }

    private static String getExplanationActionStr(String explanation, String action) {

    StringBuffer explanationActionStr = new StringBuffer();

    if((explanation == null || explanation.trim().length() == 0) &&
    (action == null || action.trim().length() == 0))
    return "";

    explanationActionStr.append(HTML_SD_10 + HTML_SD_3);

    if(explanation != null && explanation.trim().length() > 0) {
    explanationActionStr.append(HTML_SD_4 + HTML_SD_25 +HTML_SD_13 + "Explanation: " + HTML_SD_14 + HTML_SD_12);
    explanationActionStr.append(HTML_SD_11 + explanation + HTML_SD_12 + HTML_11);
    }

    if(action != null && action.trim().length() > 0) {
    explanationActionStr.append(HTML_SD_4 + HTML_SD_25 +HTML_SD_13 + "Action: " + HTML_SD_14 + HTML_SD_12);
    explanationActionStr.append(HTML_SD_11 + action + HTML_SD_12 + HTML_11);
    }
    explanationActionStr.append(HTML_SD_26 + HTML_SD_24);

    explanationActionStr.append(HTML_SD_23 + HTML_SD_3 + HTML_SD_4);

    return explanationActionStr.toString();

    }

    private static String getInformationStr(Map informationMap, int informationCount, String informationValue) {
    String infoStr = informationValue;
    if(informationCount > 0)
    infoStr = infoStr + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + informationMap.get("value");
    else if(informationCount == 0)
    infoStr = infoStr + informationMap.get("value");

    return infoStr;
    }

    private static void appendDataStr(Map dataMap, StringBuffer returnStr, int dataCount){

    if(dataCount > 0) {
    returnStr.append(HTML_SD_6 + HTML_SD_7 + HTML_11);
    }
    //dataCount++;
    returnStr.append(HTML_SD_6 + HTML_SD_19 + HTML_SD_13 +dataMap.get("name")+ HTML_SD_14 + HTML_SD_12);

    Object valuess = dataMap.get("values");
    if(valuess instanceof List) {
    Iterator lstIter = ((List) valuess).listIterator();
    while (lstIter.hasNext()) {
    Map valuessMap = (Map) lstIter.next();
    appendValuessStr(valuessMap, returnStr);
    }
    } else if(valuess instanceof Map) {
    Map valuessMap = (Map)valuess;
    appendValuessStr(valuessMap, returnStr);
    }
    returnStr.append(HTML_11);
    }

    private static void appendValuessStr(Map valuessMap, StringBuffer returnStr) {
    Object values = valuessMap.get("value");
    if(values instanceof List) {
    Iterator valueLstIter = ((List) values).listIterator();
    returnStr.append(HTML_15 + HTML_SD_1);
    while (valueLstIter.hasNext()) {
    Map valueMap = (Map) valueLstIter.next();
    appendValueStr(valueMap, returnStr);

    }
    returnStr.append(HTML_SD_20);
    } else if(values instanceof Map) {
    returnStr.append(HTML_15 + HTML_SD_1);
    Map valueMap = (Map) values;
    appendValueStr(valueMap, returnStr);
    returnStr.append(HTML_SD_20);
    }
    }

    private static void appendValueStr(Map valueMap, StringBuffer returnStr){
    String result = (String)valueMap.get("result");
    String imageType = "grey_block.gif";
    if("SUCCESS".equalsIgnoreCase(result))
    imageType = "green_block.gif";
    else if("INCOMPLETE".equalsIgnoreCase(result))
    imageType = "yellow_block.gif";
    else if("FAIL".equalsIgnoreCase(result))
    imageType = "red_block.gif";
    returnStr.append(HTML_SD_6 + HTML_SD_28 + "&nbsp;<img src=\"images\\"+imageType+"\" />&nbsp;&nbsp;"+ HTML_14 + HTML_15 + HTML_SD_21 +valueMap.get("text")+HTML_SD_12 + HTML_11);
    }

    /**
    * Helper method to return the document node for the XML
    *
    * @param sString
    * @return
    */
    private static Document getDocumentNode (String sString) {
    Document doc = null;
    File f = new File(TEMP_FILE);
    try {
    DocumentBuilder docBuilder = DOMHelper.getDocBuilder();
    BufferedWriter bw = new BufferedWriter(new FileWriter(f));
    bw.write(sString);
    bw.close();
    doc = docBuilder.parse (f);

    } catch (ParserConfigurationException e) {
    e.printStackTrace();
    } catch (SAXException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    f.deleteOnExit();
    }

    return doc;
    }

    /**
    * Return results in a specific order for Home Diagnostics results depending
    * on the problem severity (AF_FAIL, AF_NEED_PERM, AF_SUCCESSFUL, AF_OTHER)
    *
    * @param lstResults
    * @return
    */
    private static LinkedList<TestSummary> getOrderedResults () {
    LinkedList<TestSummary> ordResults = new LinkedList<TestSummary>();
    LinkedList<TestSummary> lst = new LinkedList<TestSummary>();
    Iterator statusIter = TestResultHelper.AF_STATUS_LIST.listIterator();
    while (statusIter.hasNext()) {
    String status = statusIter.next().toString();
    if ((lst = (LinkedList<TestSummary>)resultsMap.get(status)) != null) {
    Iterator<TestSummary> iter = lst.iterator();
    while (iter.hasNext()) {
    ordResults.add(iter.next());
    }
    resultsMap.remove(status);
    }
    }
    // Check if there are any more results left - ones that sneaked in without an AF_STATUS
    // or with an AF_STATUS thats not in our list. If we find any, just insert them at the end
    // our results list
    if (resultsMap.size() > 0) {
    Iterator<String> leftOverResIter = resultsMap.keySet().iterator();
    while (leftOverResIter.hasNext()) {
    if ((lst = (LinkedList<TestSummary>)resultsMap.get(leftOverResIter.next())) != null) {
    Iterator<TestSummary> iter = lst.iterator();
    while (iter.hasNext()) {
    ordResults.add(iter.next());
    }
    }
    }
    }
    return ordResults;
    }

    /**
    * Checks to see for all the following conditions to be true:
    * <ul>
    * <li>There's a single raw reading in the list,
    * <li>This sole raw reading contains multiline text, and
    * <li>it only has TEXT key, and no TYPE.
    * </ul>
    * Assumes non-null #rawReadingsAssoc.
    *
    * @param rawReadingsAssoc
    * @return multi line TEXT from the sole raw reading or <b>null</b>.
    */

    private static String parseSingleMultilineRawReading(List rawReadings) {
    String multiLine = null;
    Iterator i = rawReadings.iterator();
    if (i.hasNext()) {
    TestResultResponse.RawReading firstReading = (TestResultResponse.RawReading) i
    .next();
    if (firstReading != null && !i.hasNext() &&
    !"text/xml".equalsIgnoreCase(firstReading.mimeType)) {
    String singleLine = firstReading.value;
    multiLine = (!StringHelper.isEmpty(singleLine) && singleLine
    .indexOf(lineSeparator) < 0) ? null : singleLine;
    }
    }
    return multiLine;
    }

    static private String lineSeparator = "\n";
    }



  • First result from a Google for "snipet":

    "A segment of a document. Typically, a snippet is a set of contiguous text about the size of a paragraph and is about a single topic."



  •  @halcyon1234 said:

    First result from a Google for "snipet":

    "A segment of a document. Typically, a snippet is a set of contiguous text about the size of a paragraph and is about a single topic."

    Maybe the author was measuring code size by its usefulness, I dunno :)  Perhaps a listing of WTFs would be in order?

    The main problem I see (other than the lack of comments) is that the code isn't well-structured.  People who manage to succeed in writing enormous programs tend to have code like this based on the little I've seen before (I'm just a lad ;) ).  A rewrite of all this would result in a much nicer, faster, and easier to maintain module, but is it worth the time?



  • I barely read the code, but I see a class with only static methods, no constructor, and yet it implements an interface.

    I also see:

    catch (NullPointerException e) {
    e.printStackTrace();
    }
    EDIT: I also see @param's that don't match the actual methods.But who's fault is that?



  • @Zecc said:

    I barely read the code, but I see a class with only static methods, no constructor, and yet it implements an interface.

    That (creating an interface that only defines non-public static final variables and no methods) used to be a common idiom in Java before there were static imports. In Java's own API, in fact, one can find many instances of this. For example, javax.swing.ScrollPaneConstants contains many static final (note: not public) constants. This means that you cannot do javax.swing.ScrollPaneConstants.VIEWPORT, but the containing class MUST (you have no choice whatsoever) implement javax.swing.ScrollPaneConstants. Had Sun made these public, you could now put

    import static javax.swing.ScrollPaneConstants.*;

    at the beginning of your file and be done with it.



  • It's surprising but every once in a while I run across a programmer who just never 'got' what it means to have a class member vs an instance member. Somehow I imagine abominations like the above as a reaction to compilation failure ... like making the class properly, calling the methods as Class.methodCall(), then making everything static until it compiles.  I used to think that some language standardization might help, but we basically have that now.  One wonders if there's a better way to single these guys out and at least stretch their brain muscles a bit.



  • @Zecc said:

    I also see:

    catch (NullPointerException e) {
    e.printStackTrace();
    }

     

    That is not always a WTF.  Sometimes you just want to alert to the fact that such an exception was found, and in case you are using Jakarta Phoenix by printing the error out it is going to a file called phoenix.console, which acts as a log file for the operations.  While I agree that it is far better to have more specific logging of errors, this one is far to small to even mention in my opinion.  Hell, at least he's printing it out instead of {}.



  • the goggles, they make my eyes bleed worse.



  • Ha! I used to work for the company that created the "obscure programming language" and I speak Russian. Wish I knew about this problem before... Could have come in as a high-priced consultant to interpret the code and the coder :)

     



  • @amischiefr said:

    @Zecc said:

    I also see:

    catch (NullPointerException e) {
    e.printStackTrace();
    }

     

    That is not always a WTF.  Sometimes you just want to alert to the fact that such an exception was found, and in case you are using Jakarta Phoenix by printing the error out it is going to a file called phoenix.console, which acts as a log file for the operations.  While I agree that it is far better to have more specific logging of errors, this one is far to small to even mention in my opinion.  Hell, at least he's printing it out instead of {}.

    Oh, like this?

     

    try{
    resEquipment = rowData0.get(EQUIPMENT_TAG).toString().trim();
    }
    catch (NullPointerException e){}

    Looks like this guy would rather catch and swallow the NullPointerExceptions than actually test if the object's null.

    Oh, and abusing System.out is usually bad; I'm dealing with an app where 45% of the codebase was made by someone who throws everything as an Exception, and sends all "logging" output to System.out, thus depriving me of doing simple searches on the appserver's log.

    However, even a tail -f nohup.out shows that he wasn't the only one sending crap to stdout...


Log in to reply