package com.lgnortel.r4.r4equipment.management.olt.facility;
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.logger.LoggerUtil;
import com.lgnortel.netconf.DOM4Confspec;
import com.lgnortel.netconf.NetconfElementModel;
import com.lgnortel.netconf.wdmpon.Jinterface;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.netconf.wdmpon.Pon;
import com.lgnortel.r4.r4equipment.common.ManagementComplexModelIF;
import com.lgnortel.r4.r4equipment.common.ParameterCheckException;
import com.lgnortel.r4.util.R4Constants;
import com.lgnortel.r4.util.R4Util;
import com.tailf.confm.confd.Exists;
import com.tailf.inm.Element;
import com.tailf.inm.ElementChildrenIterator;
import com.tailf.inm.INMException;
/**
* 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: FacilityPonController<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. 5. 18.
* @modified 2009. 5. 18
* @product EFA R4.0 EMS
* @sw_block
*/
public class FacilityPonModel implements ManagementComplexModelIF {
// Log4J
Logger logger = LoggerUtil.getInstance().getLogger(this.getClass().getName());
// table name
public static final String TABLE_NAME = "Pon";
// Syntax information
String sMaxOccurs = null;
// Column Definition
private String COLUMN_NAME_SLOT = "slot";
private String COLUMN_NAME_DISABLE = "admin-state";
/**
* Constructor
*/
public FacilityPonModel() {}
/**
* 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("FacilityPonController 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", "interface", "pon"};
org.w3c.dom.Node fNode = dom4Confspec.findNode(fFdn);
if (fNode == null) {
logger.warning("FacilityPonController getTableSchema(): wdmpon.cs parsing(pon) 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("FacilityPonController sMaxOccurs: " + sMaxOccurs);
}
// Extract leaf nodes' attribute information with 'type' attribute
columnInfo = dom4Confspec.getComponentSchema(fNode.getChildNodes());
// bool type Processing
NetconfElementModel nem = dom4Confspec.getBooleanStateNetconfElementModel(COLUMN_NAME_DISABLE);
columnInfo.addElement(nem);
// fetch attribute info under status
String[] statusFdn = {"msp", "interface", "pon", "status"};
org.w3c.dom.Node statusNode = dom4Confspec.findNode(statusFdn);
Vector<NetconfElementModel> statusColumnInfo = dom4Confspec.getComponentSchema(statusNode.getChildNodes());
for (int i=0; i<statusColumnInfo.size(); i++) {
columnInfo.addElement(statusColumnInfo.get(i));
}
// change column name and width
for (NetconfElementModel nemro : columnInfo) {
if (nemro.getElementName().equals(COLUMN_NAME_SLOT)) {
nemro.setColWidth(50);
} else if (nemro.getElementName().equals(COLUMN_NAME_DISABLE)) {
nemro.setColWidth(80);
} else if (nemro.getElementName().equals("cbls-power")) {
nemro.setElementName("cbls-*power(dBm)");
nemro.setReadOnly(true);
nemro.setColWidth(70);
} else if (nemro.getElementName().equals("lbls-power")) {
nemro.setElementName("lbls-*power(dBm)");
nemro.setReadOnly(true);
nemro.setColWidth(70);
} else if (nemro.getElementName().equals("int-temp")) {
nemro.setElementName("int-*temp(C)");
nemro.setReadOnly(true);
nemro.setColWidth(70);
} else if (nemro.getElementName().equals("ld-temp")) {
nemro.setElementName("ld-*temp(C)");
nemro.setReadOnly(true);
nemro.setColWidth(70);
} else if (nemro.getElementName().equals("ld-status")) {
nemro.setElementName("ld-*status");
nemro.setReadOnly(true);
nemro.setColWidth(70);
} else if (nemro.getElementName().equals("level")) {
nemro.setReadOnly(true);
nemro.setColWidth(70);
} else if (nemro.getElementName().equals("version")) {
nemro.setReadOnly(true);
nemro.setColWidth(70);
} else if (nemro.getElementName().equals("idn")) {
nemro.setReadOnly(true);
nemro.setColWidth(100);
}
}
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.addJinterface().addPon();
} 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("FacilityPonController makeTableInformation()..");
// Valuable for returning table information
Vector<Vector<Object>> tblInfo = new Vector<Vector<Object>>();
try {
// Get a upper mo
// NodeSet is leaf mo(attribute) list(one more) and element is mo or attribute(only one)
Msp msp = (Msp) element;
Jinterface jinterface = msp.jinterface;
if (jinterface == null) {
logger.info("No interface configuration..");
return tblInfo;
}
// Get a pon list from a upper mo
ElementChildrenIterator ponIt = jinterface.ponIterator();
while (ponIt.hasNext()) {
Pon pon = (Pon) ponIt.next();
Object slot = pon.getSlotValue();
Exists disable = pon.getDisableValue();
Object cblsPower = "", lblsPower = "", intTemp = "", ldTemp = "", ldStatus = "", level = "", version = "", idn = "";
if (pon.status != null) {
cblsPower = R4Util.validateNullValue(pon.status.getCblsPowerValue());
lblsPower = R4Util.validateNullValue(pon.status.getLblsPowerValue());
intTemp = R4Util.validateNullValue(pon.status.getIntTempValue());
ldTemp = R4Util.validateNullValue(pon.status.getLdTempValue());
ldStatus = R4Util.validateNullValue(pon.status.getLdStatusValue());
level = R4Util.validateNullValue(pon.status.getLevelValue());
version = R4Util.validateNullValue(pon.status.getVersionValue());
idn = R4Util.validateNullValue(pon.status.getIdnValue());
}
Vector<Object> tblRow = new Vector<Object>();
tblRow.addElement(slot);
if (disable != null) {
tblRow.addElement(DOM4Confspec.BOOLEAN_DISABLE);
} else {
tblRow.addElement(DOM4Confspec.BOOLEAN_ENABLE);
}
tblRow.addElement(cblsPower);
tblRow.addElement(lblsPower);
tblRow.addElement(intTemp);
tblRow.addElement(ldTemp);
tblRow.addElement(ldStatus);
tblRow.addElement(level);
tblRow.addElement(version);
tblRow.addElement(idn);
// add row
tblInfo.addElement(tblRow);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception in FacilityPonController makeTableInformation()", 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) throws ParameterCheckException{
logger.info("addTableInfoToMsp()..");
try {
Jinterface jinterface = msp.jinterface;
if (jinterface == null) {
logger.info("No interface configuration..");
jinterface = new Jinterface();
msp.addJinterface(jinterface);
}
for (int i=0; i<rows.size(); i++) {
Map<String, Object> oneRow = rows.get(i);
String slot = oneRow.get(COLUMN_NAME_SLOT).toString();
String state = oneRow.get(COLUMN_NAME_DISABLE).toString();
Pon pon = null;
try {
pon = jinterface.getPon(slot);
} catch (INMException ie) {
pon = new Pon(slot);
jinterface.addPon(pon);
}
if (state.trim().length()!=0 && !R4Util.isBooleanTrue(state)) {
pon.addDisable();
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception ", e);
throw new ParameterCheckException(ParameterCheckException.FIRST_MSG, ParameterCheckException.SECOND_MSG);
}
logger.fine("config ==> \n" + msp.toXMLString());
return msp;
}
}
|