package com.lgnortel.r4.r4equipment.management.ont;
import java.util.Hashtable;
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.Coax;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.netconf.wdmpon.Ont;
import com.lgnortel.netconf.wdmpon.OntJinterface;
import com.lgnortel.netconf.wdmpon.PonAccess;
import com.lgnortel.platform.db.DBDataDesc;
import com.lgnortel.r4.r4equipment.common.ManagementComplexModelIF;
import com.lgnortel.r4.r4equipment.common.ManagementHelpIF;
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: PonAccessOntController<br>
* Description: <br>
* Copyright: Copyright(c) 2009 LG-NORTEL ALL Rights Reserved<br>
* Company: LG-Nortel<br>
*
* @author Sungill, Kim
* @version 0.1
* @created 2009. 4. 30.
* @modified 2009. 12. 11.
* @product EFA R4.0 EMS
* @sw_block
*/
public class PonAccessOntModel implements ManagementComplexModelIF, ManagementHelpIF {
// Log4J
Logger logger = LoggerUtil.getInstance().getLogger(this.getClass().getName());
public static final String TABLE_NAME = "pon-access ONT";
// Syntax information
String sMaxOccurs = null;
// Column Definition
private String COLUMN_NAME_NAME = "name";
private String COLUMN_NAME_PEC = "pec";
private String COLUMN_NAME_SERIAL_NUMBER = "serial-number";
private String COLUMN_NAME_MAC = "MAC-address";
private String COLUMN_NAME_PON_INTERFACE = "pon-interface";
private String COLUMN_NAME_AUTO_REGISTRATION = "auto-registration";
private String COLUMN_NAME_ADMIN_STATE = "admin-state";
private String COLUMN_NAME_COAX = "coax";
/**
* Constructor
*
* @param neId
*/
public PonAccessOntModel() {
}
/**
* Return table schema information
*/
public List<NetconfElementModel> getTableSchema() {
Vector<NetconfElementModel> columnInfo = new Vector<NetconfElementModel>();
// Locate "msp/pon-access/ONT" Node in the DOM tree of wdmpon.cs
DOM4Confspec dom4Confspec = DOM4Confspec.getInstance();
String[] fdn = { "msp", "pon-access", "ont" };
org.w3c.dom.Node node = dom4Confspec.findNode(fdn);
if (node == null) {
logger.warning("wdmpon.cs parsing error!");
return null;
}
// extract and save 'maxOccurs' value for getMaxOccurs()
NamedNodeMap nnm = node.getAttributes();
org.w3c.dom.Node itemNode = nnm.getNamedItem("maxOccurs");
if (itemNode != null) {
sMaxOccurs = itemNode.getNodeValue();
logger.info("sMaxOccurs: " + sMaxOccurs);
}
// Add attributes
columnInfo = dom4Confspec.getComponentSchema(node.getChildNodes());
// change column name and width
for (NetconfElementModel nem : columnInfo) {
if (nem.getElementName().equals(COLUMN_NAME_PEC)) {
nem.setMandatory(true);
nem.setColWidth(70);
} else if (nem.getElementName().equals("mac")) {
nem.setElementName(COLUMN_NAME_MAC);
nem.setColWidth(60);
} else if (nem.getElementName().equals(COLUMN_NAME_PON_INTERFACE)) {
nem.setColWidth(60);
nem.setMandatory(true);
}
}
// add "auto-registration", "disable" attribute
NetconfElementModel nemAutoReg = dom4Confspec.getBooleanNetconfElementModel(COLUMN_NAME_AUTO_REGISTRATION);
nemAutoReg.setColWidth(70);
columnInfo.addElement(nemAutoReg);
NetconfElementModel nemAdminState = dom4Confspec.getBooleanStateNetconfElementModel(COLUMN_NAME_ADMIN_STATE);
nemAdminState.setColWidth(40);
columnInfo.addElement(nemAdminState);
NetconfElementModel netconfelementmodel = new NetconfElementModel();
netconfelementmodel.setElementName(COLUMN_NAME_COAX);
netconfelementmodel.setTypeName("xs:boolean");
netconfelementmodel.setMinOccurs("0");
Vector<String> vector = new Vector<String>();
vector.addElement(DBDataDesc.DONTCARESTR);
vector.addElement("enable");
vector.addElement("disable");
Hashtable<String, Vector<String>> hashtable = new Hashtable<String, Vector<String>>();
hashtable.put("ENUMERATION", vector);
netconfelementmodel.setTypeValue(hashtable);
columnInfo.addElement(netconfelementmodel);
return columnInfo;
}
/**
* Return maxOccurs value of msp/pon-access/ONT Component
*/
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;
}
/**
* Request 'NETCONF-GETFILTER' command
*/
public void get() {
}
/**
* Convert Element into the form that can be used in Table Model
* ===================================================================================================================
* name pec serial-number mac pon-interface auto-registration adin-state
* xs:string pec-type xs:string MacAddressType pon-interface-type-list xs:boolean xs:boolean
* -------------------------------------------------------------------------------------------------------------------
* ont1 EARU1103 1234 11:22:33:44:55:66 1/10/1 FALSE enable
* ont2 EARU1112 1235 11:22:33:44:55:67 1/20/1 FALSE enable
* ===================================================================================================================
*/
public Vector<Vector<Object>> makeTableInformation(Element element, Map<String, Object> keys) {
logger.info("makeTableInformation()..");
// return value
Vector<Vector<Object>> tblInfo = new Vector<Vector<Object>>();
try {
// Locate msp/pon-access MO
Msp msp = (Msp) element;
PonAccess ponAccess = msp.ponAccess;
if (ponAccess == null) {
logger.info("No pon-access configuration..");
return tblInfo;
}
// Get ont MO list from pon-access MO
ElementChildrenIterator ontIt = ponAccess.ontIterator();
while (ontIt.hasNext()) {
// ont MO
Ont ont = (Ont) ontIt.next();
// Extract attribute value
Object name = ont.getNameValue();
Object pec = R4Util.validateNullValue(ont.getPecValue());
Object serialNumber = R4Util.validateNullValue(ont.getSerialNumberValue());
Object mac = R4Util.validateNullValue(ont.getMacValue());
Object ponInterface = R4Util.validateNullValue(ont.getPonInterfaceValue());
Exists autoRegistration = ont.getAutoRegistrationValue();
Exists disable = ont.getDisableValue();
Exists coax = null, coaxDisable = null;
if (ont.jinterface != null) {
OntJinterface ontIf = ont.jinterface;
if (ontIf.coax != null) {
coaxDisable = ontIf.coax.getDisableValue();
}
}
// make results
Vector<Object> tblRow = new Vector<Object>();
tblRow.addElement(name);
tblRow.addElement(pec);
tblRow.addElement(serialNumber);
tblRow.addElement(mac);
tblRow.addElement(ponInterface);
tblRow.addElement(R4Util.getBooleanValue(autoRegistration));
tblRow.addElement(R4Util.getAdminStateValue(disable));
if (!pec.toString().equals(DBDataDesc.R4_ONT_TYPE_EARU11x3RF_STR)
|| coax == null) {
tblRow.addElement(DBDataDesc.DONTCARESTR);
} else {
tblRow.addElement(R4Util.getAdminStateValue(coaxDisable));
}
// add a row into the table
tblInfo.addElement(tblRow);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception", e);
}
// return table information
return tblInfo;
}
/**
* Return Help File path
*/
public String getHelpFilePath() {
return HelpTargetConst.R4_ONT_ONT;
}
/**
* Construct MO tree
* ===================================================================================================================
* name pec serial-number mac pon-interface auto-registration adin-state
* xs:string pec-type xs:string MacAddressType pon-interface-type-list xs:boolean xs:boolean
* -------------------------------------------------------------------------------------------------------------------
* ont1 EARU1103 1234 11:22:33:44:55:66 1/10/1 FALSE enable
* ont2 EARU1112 1235 11:22:33:44:55:67 1/20/1 FALSE enable
* ===================================================================================================================
* @throws ParameterCheckException
*/
public Msp addTableInfoToMsp(Msp msp, List<Map<String, Object>> rows, Map<String, Object> key) throws ParameterCheckException {
try {
// construct MO tree
PonAccess ponAccess = msp.ponAccess;
if (ponAccess == null) {
ponAccess = new PonAccess();
msp.addPonAccess(ponAccess);
}
for (int i = 0; i < rows.size(); i++) {
Map<String, Object> oneRow = rows.get(i);
// Make ont instance using input argument(oneRow)
String name = oneRow.get(COLUMN_NAME_NAME).toString();
String pec = oneRow.get(COLUMN_NAME_PEC).toString();
String serialNumber = oneRow.get(COLUMN_NAME_SERIAL_NUMBER).toString();
String mac = oneRow.get(COLUMN_NAME_MAC).toString();
String ponInterface = oneRow.get(COLUMN_NAME_PON_INTERFACE).toString();
String autoRegistration = oneRow.get(COLUMN_NAME_AUTO_REGISTRATION).toString();
String adminState = oneRow.get(COLUMN_NAME_ADMIN_STATE).toString();
String coaxAttr = oneRow.get(COLUMN_NAME_COAX).toString();
// search ONT
Ont ont = null;
try {
ont = ponAccess.getOnt(name);
// clean up attribute value
ont.delete("pec");
ont.delete("serial-number");
ont.delete("mac");
ont.delete("pon-interface");
} catch (INMException ie) {
ont = new Ont(name);
ponAccess.addOnt(ont);
}
// set attribute
if (R4Util.isExistingField(pec)) {
ont.setPecValue(pec);
}
if (R4Util.isExistingField(serialNumber)) {
ont.setSerialNumberValue(serialNumber);
}
if (R4Util.isExistingField(mac)) {
ont.setMacValue(mac);
}
if (R4Util.isExistingField(ponInterface)) {
ont.setPonInterfaceValue(ponInterface);
}
R4Util.checkAndSetBooleanAttr(ont, autoRegistration, "auto-registration");
R4Util.checkAndSetAdminStateAttr(ont, adminState);
if (pec.equals(DBDataDesc.R4_ONT_TYPE_EARU11x3RF_STR)
&& !coaxAttr.equals(DBDataDesc.DONTCARESTR)) {
// search ont/interface/coax
OntJinterface ontIf = ont.jinterface;
if (ontIf == null) {
ontIf = new OntJinterface();
ont.addJinterface(ontIf);
}
Coax coax = ontIf.coax;
if (coax == null) {
coax = new Coax();
ontIf.addCoax(coax);
}
R4Util.checkAndSetAdminStateAttr(coax, coaxAttr);
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception in set()", e);
throw new ParameterCheckException("Parameter Check Error", "Parameter Check Error");
}
// logger.fine("config ==> \n" + msp.toXMLString());
return msp;
}
}
|