AlarmHistoryModel.java :  » App » learnandroid » com » lgnortel » r4 » r4equipment » management » olt » alarm » oper » Android Open Source

Android Open Source » App » learnandroid 
learnandroid » com » lgnortel » r4 » r4equipment » management » olt » alarm » oper » AlarmHistoryModel.java
package com.lgnortel.r4.r4equipment.management.olt.alarm.oper;

import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.w3c.dom.NamedNodeMap;

import com.lgnortel.lib.help.HelpTargetConst;
import com.lgnortel.lib.logger.LoggerUtil;
import com.lgnortel.netconf.DOM4Confspec;
import com.lgnortel.netconf.NetconfElementModel;
import com.lgnortel.netconf.wdmpon.AlarmHistory;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.netconf.wdmpon.Oper;
import com.lgnortel.r4.r4equipment.common.ManagementComplexModelIF;
import com.lgnortel.r4.r4equipment.common.ManagementHelpIF;
import com.lgnortel.r4.util.R4Constants;
import com.lgnortel.r4.util.R4Util;
import com.tailf.inm.Element;
import com.tailf.inm.ElementChildrenIterator;

/**
 * Copyright (c) 2009 LG-Nortel, Inc. All Rights Reserved.
 * 
 * CONFIDENTIALITY AND LIMITED USE: This software, including any software of <br>
 * third parties embodied herein, contains code, information, data and concepts <br>
 * which are confidential and/or proprietary to LG-Nortel and such third <br>
 * parties. This software is licensed for use solely in accordance with the <br>
 * terms and conditions of the applicable license agreement with LG-Nortel or <br>
 * its authorized distributor, and not for any other use or purpose. No <br>
 * redistribution of this software by any party is permitted. <br>
 * 
 * Title: AlarmHistoryModel<br>
 * Description: This is a class that GUI uses. And this is a class to set information of ONT port using Netconf interface and get it. <br>
 * Copyright: Copyright(c) 2009 LG-NORTEL ALL Rights Reserved<br>
 * Company: LG-Nortel<br>
 * 
 * @author Moongye, Oh
 * @version 0.1
 * @created 2009. 7. 1.
 * @modified 2009. 7. 1.
 * @product EFA R4.0 EMS
 * @sw_block
 */
public class AlarmHistoryModel implements ManagementComplexModelIF,ManagementHelpIF {
  
  // Log4J
  Logger logger = LoggerUtil.getInstance().getLogger(this.getClass().getName());

  // table name
  public static final String TABLE_NAME = "Alarm History";

  // Syntax information
  String sMaxOccurs = null;

  /**
   * Constructor
   */
  public AlarmHistoryModel() {}

  /**
   * Reference : <elem[DOM tree node name] K[DOM tree attribute name]="K1"[DOM tree attribute value]...> 
   * 
   * @return table schema information
   */
  public List<NetconfElementModel> getTableSchema() {
    
    logger.info("AlarmInterfaceAttrModel getTableSchema()..");
    
    Vector<NetconfElementModel> columnInfo = new Vector<NetconfElementModel>();

    DOM4Confspec dom4Confspec = DOM4Confspec.getInstance();
        
    // Locate a Node using fdn in the DOM tree of wdmpon.cs
    String[] fFdn = {"msp", "oper", "alarm-history"};
    org.w3c.dom.Node fNode = dom4Confspec.findNode(fFdn);  
    if (fNode == null) {
      logger.warning("wdmpon.cs parsing error!");
      return null;
    }

    // Extract and save 'maxOccurs' value for getMaxOccurs() for GUI table
    // A NamedNodeMap containing the attributes(DOM tree attribute name and DOM tree attribute value) of this DOM tree node    
    NamedNodeMap nnm = fNode.getAttributes(); 
    org.w3c.dom.Node fmNode = nnm.getNamedItem("maxOccurs");
    if (fmNode != null) {
      sMaxOccurs = fmNode.getNodeValue();
      logger.info("sMaxOccurs: " + sMaxOccurs);
    }

    // A target is only confspec attributes to be clung to confspec mo
    // Save DOM tree attributes of confspec attributes in a valuable of Vector<NetconfElementModel> type  
    // NetconfElementModel is composed of the valuables for name, type, minOccurs, maxOccurs, default, use, key
    // First  argument: org.w3c.dom.NodeList
    // Second argument: data to change names of columns
    // Third  argument: data to change sequence of columns
    columnInfo = dom4Confspec.getComponentSchema(fNode.getChildNodes(), null, null);

    // change column name and width
    for (NetconfElementModel oneNem : columnInfo) {
      if (oneNem.getElementName().equals("component")) {
        oneNem.setColWidth(100);
        
      } else if (oneNem.getElementName().equals("severity")) {
        oneNem.setColWidth(50);
        
      } else if (oneNem.getElementName().equals("reason")) {
        oneNem.setColWidth(250);
        
      } else if (oneNem.getElementName().equals("unit")) {
        oneNem.setColWidth(30);
        
      } else if (oneNem.getElementName().equals("address")) {
        oneNem.setColWidth(50);
        
      } else if (oneNem.getElementName().equals("invoke-time")) {
        oneNem.setColWidth(110);
        
      } else if (oneNem.getElementName().equals("release-time")) {
        oneNem.setColWidth(110);
        
      } else if (oneNem.getElementName().equals("recovery")) {
        oneNem.setColWidth(70);
        
      }
    }
    
    return columnInfo;
  }

  /**
   * Get maxOccurs value for GUI table
   * 
   * @return maxOccurs value
   */
  public int getMaxOccurs() {

    int maxOccurs = 1;

    if (sMaxOccurs != null) {
      if (sMaxOccurs.equals(R4Constants.MAX_OCCURS_VALUE_UNBOUNDED)) {
        maxOccurs = Integer.MAX_VALUE;
      } else {
        maxOccurs = Integer.parseInt(sMaxOccurs);
      }
    }

    return maxOccurs;
  }
  
  /**
   * Make Filter from Msp MO
   * 
   * @return filter
   */
  public Element getFilter() {

    Msp filter = new Msp();
    try {
      filter.addOper().addAlarmHistory();
    } catch (Exception e) {
      logger.log(Level.SEVERE, "Exception ", e);
    }
    
    return filter;
  }

  /**
   * Convert Element into the form that can be used in Table Model
   * 
   * @param element: data to be filtered by GET request
   * @param keys: key to get a data among element argument
   *
   * @return table information for inquery
   */
  public Vector<Vector<Object>> makeTableInformation(Element element, Map<String, Object> keys) {

    logger.info("makeTableInformation()...");
    
    // Valuable for returning table information
    Vector<Vector<Object>> tblInfo = new Vector<Vector<Object>>();
          
    try {      
                  
      // Locate msp/oper/history
      Msp msp = (Msp) element;
      logger.fine(msp.toXMLString());
      
      Oper oper = msp.oper;
      if (oper == null) {
        logger.info("No oper configuration..");
        return tblInfo;
      }
            
      ElementChildrenIterator alarmHistoryIt = oper.alarmHistoryIterator();
      while(alarmHistoryIt.hasNext()) {
        AlarmHistory alarmHistory = (AlarmHistory ) alarmHistoryIt.next();
        Object component = R4Util.validateNullValue(alarmHistory.getComponentValue());
        Object severity = R4Util.validateNullValue(alarmHistory.getSeverityValue());
        Object reason = R4Util.validateNullValue(alarmHistory.getReasonValue());
        Object unit = R4Util.validateNullValue(alarmHistory.getUnitValue());
        Object address = R4Util.validateNullValue(alarmHistory.getAddressValue());
        Object invoke_time = R4Util.validateNullValue(alarmHistory.getInvokeTimeValue());
        Object release_time = R4Util.validateNullValue(alarmHistory.getReleaseTimeValue());
        Object recovery = R4Util.validateNullValue(alarmHistory.getRecoveryValue());
        
        Vector<Object> tblRow = new Vector<Object>();
        tblRow.addElement(component);
        tblRow.addElement(severity);
        tblRow.addElement(reason);
        tblRow.addElement(unit);
        tblRow.addElement(address);
        tblRow.addElement(invoke_time);
        tblRow.addElement(release_time);
        tblRow.addElement(recovery);
        tblInfo.addElement(tblRow);
      }
                  
    } catch (Exception e) {
      logger.log(Level.SEVERE, "Exception ", e);
    }  
    
    return tblInfo;
  }

  /**
   * Construct MO tree & request 'NETCONF-AUDIT' command
   * 
   * @param msp: msp to include data of other tables 
   * @param rows: data to be existed in the table of GUI interface
   *
   * @return Msp MO tree for set command
   */
  public Msp addTableInfoToMsp(Msp msp, List<Map<String, Object>> rows, Map<String, Object> keys) {
    
    logger.info("only view..");
    
    return msp;
  }

  @Override
  public String getHelpFilePath() {
    return HelpTargetConst.R4_OLT_ALARM_HISTORY;
  }  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.