/**
*
*/
package com.lgnortel.profile.olt.manager.view.ces;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.Level;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.xml.sax.InputSource;
import com.lgnortel.lib.help.HelpTargetConst;
import com.lgnortel.lib.table.SortFilterModel;
import com.lgnortel.netconf.wdmpon.Ces;
import com.lgnortel.netconf.wdmpon.Msp;
import com.lgnortel.netconf.wdmpon.Profile;
import com.lgnortel.network.networkview.ErrorInspect;
import com.lgnortel.network.networkview.MainMenuBar;
import com.lgnortel.network.networkview.User;
import com.lgnortel.platform.db.DBDataDesc;
import com.lgnortel.platform.db.DBManager;
import com.lgnortel.profile.common.ProfileComplexIF;
import com.lgnortel.profile.common.ProfileUpdateIF;
import com.lgnortel.profile.olt.assign.CmdTotalOLTAssignmentView;
import com.lgnortel.r4.r4equipment.common.DefaultManagementView;
import com.lgnortel.r4.r4equipment.common.DuplicateKeyException;
import com.lgnortel.r4.r4equipment.common.ManagementHelpIF;
import com.lgnortel.r4.r4equipment.common.R4CommonUtil;
import com.lgnortel.r4.r4equipment.common.R4TableModel;
import com.lgnortel.r4.r4equipment.common.WrongParameterException;
import com.lgnortel.r4.r4equipment.management.olt.ces.CesProfileModel;
import com.lgnortel.r4.util.R4Constants;
import com.lgnortel.r4.util.R4Util;
import com.lgnortel.rmi.common.ClientManager;
import com.lgnortel.rmi.common.EmsCode;
import com.tailf.confm.XMLParser;
import com.tailf.inm.Element;
/**
* Copyright (c) 2008 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: QoSClassifierComplexView.java<br>
* Description: This class display QoS Classifier View.<br>
* Copyright: Copyright(c) 2009 LG-NORTEL ALL Rights Reserved<br>
* Company: LG-Nortel<br>
*
* @author Jonghwa, Lee
* @version 0.1
* @created 2009. 4. 3.
* @modified 2009. 4. 3.
* @product EFA R4.0 EMS
* @sw_block Client Block
*/
public class CesProfileManagerComplexView extends DefaultManagementView implements ProfileUpdateIF, ProfileComplexIF, ManagementHelpIF {
/**
*
*/
private static final long serialVersionUID = -2840032401804139119L;
private CesProfileModel cesProfileModel;
private CesProfileView pnlClass;
private int viewId;
private int neId = 0;
private String profileName;
private Msp updateMsp;
private ClientManager clientManager = ClientManager.getInstance();
private User user = User.getInstance();
public CesProfileManagerComplexView(String profile, int viewId) {
super();
this.viewId = viewId;
profileName = profile;
this.sTitle = profile;
initialize();
}
@Override
protected JPanel createMainPanel() {
cesProfileModel = new CesProfileModel();
pnlClass = new CesProfileView("CES Profile", cesProfileModel);
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
panel.add(pnlClass, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0));
return panel;
}
/*
* Request 'NETCONF-GETFILTER' command
*/
public void get() {
Msp filter = getFilter();
Element element = null;
DBManager dbMgr = DBManager.getInstance();
File file = dbMgr.getProfileFile(DBDataDesc.OLT_CES_PROFILE, profileName);
logger.info("file Name = " + file.getName());
FileInputStream is = null;
try {
if (file.length() > 0) {
is = new FileInputStream(file);
element = new XMLParser().parse(new InputSource(is));
}
} catch (Exception e) {
logger.log(Level.SEVERE, "error in get profile", e);
pnlResult.updateMessage(ErrorInspect.PROFILE_FILE_OPEN_ERROR);
element = null;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
logger.log(Level.SEVERE, "error in get profile", e);
}
}
file.delete();
}
Object[] resData = new Object[2];
resData[0] = (Object) filter;
resData[1] = (Object) element;
String errMessage = "";
if (element == null) {
errMessage = "No data";
cmdResponse(viewId, user.getUserId(), neId, EmsCode.NETCONF_GETFILTER_CONFIG, resData, ErrorInspect.NO_DATA, errMessage);
} else {
errMessage = R4Constants.CMD_SUCCESS;
cmdResponse(viewId, user.getUserId(), neId, EmsCode.NETCONF_GETFILTER_CONFIG, resData, ErrorInspect.SUCCESS, errMessage);
}
}
@Override
protected void set() {
if (R4CommonUtil.displayQuestionDialog(this, profileName, "Do you want to execute?")) {
if(!isCreateMsp()){
return;
}
R4TableModel model = (R4TableModel) pnlClass.getModel();
String profileName = model.getValueAt(0, 0).toString();
MainMenuBar mainMenuBar = MainMenuBar.getInstance();
CmdTotalOLTAssignmentView view = CmdTotalOLTAssignmentView.getInstance();
view.setViewId(MainMenuBar.R4_OLT_ASSIGN);
mainMenuBar.removeCommand(MainMenuBar.R4_OLT_ASSIGN);
mainMenuBar.putCommand(MainMenuBar.R4_OLT_ASSIGN, (Object) view);
view.changeAssignView(this, profileName, true, DBDataDesc.CES_PROFILE_MO);
SortFilterModel setModel = view.getCesSetModel();
view.setSelectionTab(1, 0, DBDataDesc.CES_PROFILE_MO);
if (R4Util.isExistProfile(setModel)) {
view.setCesMsp(updateMsp);
view.setVisible(true);
if (view.isVisible()) {
view.setState(JFrame.NORMAL);
}
view.repaint();
} else {
update();
if (!view.isVisible()) {
view.setVisible(false);
}
}
}
}
public void set(Msp msp) {
logger.info("set command profileName = " + profileName);
Object[] data = new Object[3];
data[0] = profileName;
data[1] = DBDataDesc.OLT_CES_PROFILE;
data[2] = msp;
String cmdStr = new String("");
cmdStr = "UPDATE-OLT-CES-PROFILE : Profile-Name =" + profileName;
clientManager.cmdRequest(viewId, user.getUserId(), neId, 0, EmsCode.NETCONF_PROFILE_UPDATE, data, cmdStr);
}
public void add(String iProfileName) {
Msp msp = new Msp();
Ces ces = new Ces();
Profile profile = new Profile();
try {
msp.addCes(ces).addProfile(profile);
profile.setCesProfileNameValue(profileName);
} catch (Exception e) {
logger.fine("Exception is occurred !!");
}
Object[] data = new Object[3];
data[0] = iProfileName;
data[1] = DBDataDesc.OLT_CES_PROFILE;
data[2] = msp;
String cmdStr = new String("");
cmdStr = "INSERT-OLT-CES-PROFILE : Profile-Name =" + iProfileName;
clientManager.cmdRequest(viewId, user.getUserId(), neId, 0, EmsCode.NETCONF_PROFILE_INSERT, data,cmdStr);
}
public void delete(String iProfileName) {
logger.fine("delete command iProfileName = " + iProfileName);
Object[] data = new Object[2];
data[0] = iProfileName;
data[1] = DBDataDesc.OLT_CES_PROFILE;
String cmdStr = new String("");
cmdStr = "DELETE-OLT-CES-PROFILE : Profile-Name =" + iProfileName;
clientManager.cmdRequest(viewId, user.getUserId(), neId, 0, EmsCode.NETCONF_PROFILE_DELETE, data, cmdStr);
}
public void changeName(String previousProfileName, String changedProfileName) {
logger.info("change command previousProfileName = " + previousProfileName + ", changedProfileName = " + changedProfileName);
Object[] data = new Object[3];
data[0] = previousProfileName;
data[1] = changedProfileName;
data[2] = DBDataDesc.OLT_CES_PROFILE;
String cmdStr = new String("");
cmdStr = "CHANGE-NAME-OLT-CES-PROFILE : Profile-Name =" + changedProfileName;
clientManager.cmdRequest(viewId, user.getUserId(), neId, 0, EmsCode.NETCONF_PROFILE_NAME_CHANGE, data,cmdStr);
}
public int isProfileChanged(String profileName) {
int result = DBDataDesc.NO;
DBManager dbMgr = DBManager.getInstance();
result = dbMgr.isProfileChanged(DBDataDesc.OLT_CES_PROFILE, profileName);
if (DBDataDesc.YES == result) {
btnSet.setEnabled(false);
}
return result;
}
@Override
public boolean cmdResponse(int viewId, int userId, int nodeId, int cmdCode, Object[] data, int result, String errMessage) {
if(!(EmsCode.NETCONF_PROFILE_UPDATE ==cmdCode||EmsCode.NETCONF_PROFILE_DELETE ==cmdCode||EmsCode.NETCONF_PROFILE_INSERT==cmdCode)){
pnlResult.updateMessage(errMessage);
}
// Will modify : If return more result code.
if (EmsCode.NETCONF_GET_CONFIG == cmdCode || EmsCode.NETCONF_GETFILTER_CONFIG == cmdCode) {
pnlClass.cmdResponse(viewId, userId, nodeId, cmdCode, data, result, errMessage);
} else if ((EmsCode.NETCONF_DELETE == cmdCode || EmsCode.NETCONF_EDIT == cmdCode) || EmsCode.NETCONF_AUDIT == cmdCode || EmsCode.NETCONF_PROFILE_INSERT == cmdCode) {
if (ErrorInspect.SUCCESS == result) {
get();
}
}
if (EmsCode.NETCONF_PROFILE_UPDATE == cmdCode && ErrorInspect.SUCCESS == result) {
get();
} else if (EmsCode.NETCONF_PROFILE_DELETE == cmdCode && ErrorInspect.SUCCESS == result) {
get();
}
return true;
}
public Msp getFilter() {
// construct filter to retrieve msp/qos/access-list MOs only
Msp filter = new Msp();
try {
filter.addCes().addProfile();
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception", e);
}
return filter;
}
public Msp getFilter(String name) {
Msp filter = new Msp();
try {
filter.addCes().addProfile(name);
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception", e);
}
return filter;
}
public String getHelpFilePath() {
return HelpTargetConst.NV_R4_OLT_CES_PROFILE_MANAGER;
}
public void setViewId(int viewId) {
this.viewId = viewId;
}
@Override
public void changeButtonState(int isButtonChange) {
if (isButtonChange == DBDataDesc.YES) {
btnSet.setEnabled(false);
} else if (isButtonChange == DBDataDesc.NO) {
btnSet.setEnabled(true);
}
}
@Override
public void update() {
set(updateMsp);
}
private boolean isCreateMsp() {
boolean isCreate = true;
updateMsp = new Msp();
try {
pnlClass.checkTableValues();
updateMsp = cesProfileModel.addTableInfoToMsp(updateMsp, pnlClass.getExecuteTableRows(), null);
} catch (WrongParameterException ie) {
R4CommonUtil.displayConfirmDialog(this, sTitle, ie.getDisplayMessage());
logger.info("Parameter value is wrong !! " + ie.getMessage());
isCreate = false;
} catch (DuplicateKeyException dc) {
R4CommonUtil.displayConfirmDialog(this, sTitle, dc.getDisplayMessage());
logger.info("Duplicated key exists !! : " + dc.getMessage());
isCreate = false;
} catch (Exception e) {
R4CommonUtil.displayConfirmDialog(this, sTitle, "Internal Error!");
logger.log(Level.SEVERE, "Execute failed!", e);
isCreate = false;
}
return isCreate;
}
}
|