Java tutorial
/** * * This is a common class for all the report exports for which there is no built in service container associated with the DB. * These service containers are created on the go, i.e. it will be created only when there is a request. * * These service containers are created for the export feature to be supported. * * NOTE : Please change the functionality of creating the service containers. * Override the method getTableDataForRequest of DefaultRequestHandlerImpl and start creating the TableData directly. * * @author surajsha * */ package com.pari.reports.request.handlers; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import com.pari.api.device.groups.DeviceGroupMembership; import com.pari.base.so.GoldenConfigInfo; import com.pari.base.so.NetworkNode; import com.pari.base.so.OSTypeDetails; import com.pari.config.templates.IConfigset; import com.pari.health.NCCMHealthStatus; import com.pari.health.NCCMHealthStatusManagerIf; import com.pari.health.NCCMHealthType; import com.pari.mw.api.ServerIfProvider; import com.pari.nm.faults.Fault; import com.pari.nm.groups.GroupType; import com.pari.nm.groups.GroupingService; import com.pari.nm.groups.LWObjectGroup; import com.pari.nm.gui.guiservices.PariException; import com.pari.nm.modules.approvals.ApprovalDefinition; import com.pari.nm.modules.approvals.ApprovalGroupDefinition; import com.pari.nm.modules.approvals.ApprovalLevelDefination; import com.pari.nm.modules.cspc.ImageCollectionFreezePreferences; import com.pari.nm.modules.customers.Customer; import com.pari.nm.modules.dsp.management.DeviceScriptInfo; import com.pari.nm.modules.externalscript.ExternalScripts; import com.pari.nm.modules.imgmgmt.LWSoftwareImage; import com.pari.nm.modules.inventory.Dataset; import com.pari.nm.modules.jobs.TriggerConfigJobDetails; import com.pari.nm.modules.jobs.metadata.JobMetadataDetails; import com.pari.nm.modules.jobs.metadata.JobMetadataException; import com.pari.nm.modules.session.UserDetails; import com.pari.nm.modules.session.UserGroupType; import com.pari.nm.modules.session.UserRole; import com.pari.nm.modules.session.UserSession; import com.pari.nm.modules.session.UserSessionManager; import com.pari.nm.modules.session.UsersFactory; import com.pari.nm.utils.DateUtils; import com.pari.nm.utils.db.DeviceScriptDBHelper; import com.pari.policies.custom.LWCustomPolicy; import com.pari.policies.policygroups.LWPolicyGroup; import com.pari.policies.policygroups.PolicyGroupManager; import com.pari.policies.profiles.LWPolicyProfile; import com.pari.reports.request.constants.ExportInfoConstants; import com.pari.reports.request.constants.RequestAttributes; import com.pari.reports.request.core.ReportRequestDetails; import com.pari.reports.request.export.core.ExportDBHelper; import com.pari.reports.request.export.core.ExportInfo; import com.pari.reports.request.export.core.ExportRequestHandler; import com.pari.reports.request.export.formathandlers.ExportFormatHandler; import com.pari.reports.request.intf.ReportExporterIntf; import com.pari.reports.template.management.ReportTemplateMetaInfo; import com.pari.reports.udreports.UserDefinedReport; import com.pari.server.LicenseValidator; import com.pari.server.weightage.LicenseReportInstance; import com.pari.services.ServiceContainer; import com.pari.services.ServiceContainerImpl; import com.pari.services.ServiceImpl; import com.pari.services.def.version.DefaultVersionInfo; import com.pari.services.def.version.IOSVersionInfoImpl; import com.pari.services.def.version.ValueMatcher; import com.pari.services.def.version.VersionOperatorType; import com.pari.services.def.version.VersionedEntity; import com.pari.services.def.version.custom.CustomPlatformIf; import com.pari.services.def.version.custom.CustomPlatformManagerIf; import com.pari.swim.ScriptInfo; import com.pari.swim.ScriptInfo.ScriptType; import com.pari.web.api.table.ColumnDefinition; import com.pari.web.api.table.RendererType; import com.pari.web.api.table.TableDefinition; import com.pari.web.api.table.TableProperties; public class ManageExportHandlerImpl extends DefaultRequestHandlerImpl { private static Logger logger = Logger.getLogger(ManageExportHandlerImpl.class); private static final String TYPE_SYSTEM = "System"; private static final String TYPE_USER_DEFINED = "User Defined"; private static final String DATE_FORMAT = "EEE, MMM dd, yyyy HH:mm:ss Z"; public ManageExportHandlerImpl(ReportRequestDetails reqDetails) { super(reqDetails); } @Override public ServiceContainer getServiceContainer() throws Exception { ServiceContainer serviceContainer = null; TableDefinition tableDef = getRequestDetails().getTableDef(); if (getRequestDetails().getReportId().equals("manage_report_template")) { serviceContainer = getReportTemplates(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_reports")) { serviceContainer = getCustomReports(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_gold_configs")) { serviceContainer = getGoldConfigTemplateDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_mix_and_match")) { serviceContainer = getMixAndMatchReportDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_software_repository")) { serviceContainer = getSoftwareImageDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("user_role")) { serviceContainer = getUserRoles(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("nccm_health_summary_report")) { serviceContainer = getNCCMMHealthStatusTable(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("fault_history")) { serviceContainer = getFaultHistory(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("image_freeze_preference")) { serviceContainer = getImageFreezePreferences(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("my_waiting_triggerconfig")) { serviceContainer = getMyTriggerConfigJobDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_scripts")) { serviceContainer = getManageScriptRepositoryDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("licenseweightage")) { serviceContainer = getLicenseWeightageDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("customers_export")) { serviceContainer = getManageCustomerDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_users_export")) { serviceContainer = getCiscoNccmUserDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("setup_approvals")) { TableDefinition[] childTableDefs = tableDef.getChildTables(); TableDefinition childTableDef = null; if (childTableDefs != null && childTableDefs.length > 0) { childTableDef = childTableDefs[0]; } serviceContainer = getSetUpWorkflowApprovalDetails(tableDef.getColumnDefs(), childTableDef, getRequestDetails().getParameterFilterMap()); } else if (getRequestDetails().getReportId().equals("user_defined_platforms")) { serviceContainer = getUserDefinedPlatformDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("user_defined_dataset")) { serviceContainer = getUserDefinedDatasetDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_device_groups") || getRequestDetails().getReportId().equals("manage_interface_groups")) { serviceContainer = getManageGroupDetails(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_config_templates")) { serviceContainer = getManageConfigTemplateDetail(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("profile_mgmt")) { serviceContainer = getManagePolicyProfileDetail(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("policy_group_mgmt")) { serviceContainer = getPolicyGroupsDetailsReport(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_custom_policies")) { serviceContainer = getPolicyProfileDetail(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_os_type")) { serviceContainer = getManageOSType(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_device_support_package")) { serviceContainer = getManageDSP(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_custom_chart_script")) { serviceContainer = getManageCustomChart(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_external_scripts")) { serviceContainer = getExternalScripts(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("manage_job_metadata")) { serviceContainer = getManageJobMetadataReport(tableDef.getColumnDefs()); } else if (getRequestDetails().getReportId().equals("approval_user_groups")) { TableDefinition[] childTableDefs = tableDef.getChildTables(); TableDefinition childTableDef = null; if (childTableDefs != null && childTableDefs.length > 0) { childTableDef = childTableDefs[0]; } serviceContainer = getApprovalUserGroupDetails(tableDef.getColumnDefs(), childTableDef != null ? childTableDef.getColumnDefs() : null, getRequestDetails().getParameterFilterMap()); } return serviceContainer; } private ServiceContainer getExternalScripts(ColumnDefinition[] columnDefs) throws JobMetadataException { ServiceImpl service = null; ServiceContainerImpl serviceContainer = new ServiceContainerImpl(); ServerIfProvider serverIf = getRequestDetails().getServerIf(); String customer = getRequestDetails().getCustomer(); int customerId = -1; if (customer != null && customer.trim().length() > 0) { try { customerId = getRequestDetails().getServerIf().getCustomerIf().getCustomerIdByName(customer); } catch (Exception e) { logger.error("Exception while Exporting Manage External Scripts", e); } } try { List<ExternalScripts> scriptList = new ArrayList<ExternalScripts>(); if (customerId == -1) { scriptList = serverIf.getNmIf().getExternalScriptList(-1); } else { scriptList = serverIf.getNmIf().getExternalScriptList(customerId); } if (scriptList != null && scriptList.size() > 0) { for (ExternalScripts script : scriptList) { if (script.getType() == ScriptType.Lib.toString()) { continue; } service = new ServiceImpl(); String customerName = serverIf.getCustomerIf().getCustomerNameById(script.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(columnDefs[0].getId(), customerName); service.put(columnDefs[1].getId(), script.getTitle()); service.put(columnDefs[2].getId(), script.getFilename()); service.put(columnDefs[3].getId(), script.getDescription()); service.put(columnDefs[4].getId(), script.getType()); service.put(columnDefs[5].getId(), script.isArgument() == true ? "Yes" : "No"); serviceContainer.addManageServices(service); } } } catch (Exception ex) { throw new JobMetadataException("Exception while exporting the Manage External Scripts", ex); } return serviceContainer; } private ServiceContainer getManageCustomChart(ColumnDefinition[] columnDefs) throws JobMetadataException { ServiceImpl service = null; ServiceContainerImpl serviceContainer = new ServiceContainerImpl(); ServerIfProvider serverIf = getRequestDetails().getServerIf(); String customer = getRequestDetails().getCustomer(); int customerId = -1; if (customer != null && customer.trim().length() > 0) { try { customerId = getRequestDetails().getServerIf().getCustomerIf().getCustomerIdByName(customer); } catch (Exception e) { logger.error("Exception while Exporting Manage custom chart", e); } } try { List<ScriptInfo> scriptInfoArr = new ArrayList<ScriptInfo>(); if (customerId == -1) { scriptInfoArr = serverIf.getCustomChartManager().getAllScriptInfos(); } else { Map<String, ScriptInfo> scriptInfoMap = serverIf.getCustomChartManager().getScriptInfo(customerId); if (scriptInfoMap.size() > 0) { for (ScriptInfo scriptInfo : scriptInfoMap.values()) { scriptInfoArr.add(scriptInfo); } } } if (scriptInfoArr != null) { for (ScriptInfo scriptInfo : scriptInfoArr) { if (scriptInfo.getScriptType() == ScriptType.Lib) { continue; } service = new ServiceImpl(); String customerName = serverIf.getCustomerIf().getCustomerNameById(scriptInfo.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(columnDefs[0].getId(), customerName); service.put(columnDefs[1].getId(), scriptInfo.getScriptTitle()); service.put(columnDefs[2].getId(), scriptInfo.getDefinition().toString()); service.put(columnDefs[3].getId(), scriptInfo.getCreatorName()); service.put(columnDefs[4].getId(), scriptInfo.getCreatedOn()); service.put(columnDefs[5].getId(), scriptInfo.getModifierName()); service.put(columnDefs[6].getId(), scriptInfo.getModifiedOn()); service.put(columnDefs[7].getId(), scriptInfo.getScriptType().name()); serviceContainer.addManageServices(service); } } } catch (Exception ex) { throw new JobMetadataException("Exception while creating the listOfScriptInfo on the system", ex); } return serviceContainer; } private ServiceContainer getManageJobMetadataReport(ColumnDefinition[] columnDefs) throws JobMetadataException { ServiceImpl service = null; ServiceContainerImpl serviceContainer = new ServiceContainerImpl(); ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { List<JobMetadataDetails> metadataDetailsList = serverIf.getJobMetadataManager() .getAllMetadataDetails(false); for (JobMetadataDetails metadataDetails : metadataDetailsList) { service = new ServiceImpl(); service.put(columnDefs[1].getId(), metadataDetails.getName()); service.put(columnDefs[2].getId(), metadataDetails.getType()); List<String> values = metadataDetails.getValues(); service.put(columnDefs[3].getId(), StringUtils.join(values, ',')); service.put(columnDefs[4].getId(), metadataDetails.getDefaultValue()); service.put(columnDefs[5].getId(), metadataDetails.isShowChart() ? "Yes" : "No"); service.put(columnDefs[6].getId(), metadataDetails.isShowParamAsColumn() ? "Yes" : "No"); service.put(columnDefs[7].getId(), metadataDetails.getCreatorName()); service.put(columnDefs[8].getId(), metadataDetails.getCreatedOn()); service.put(columnDefs[9].getId(), metadataDetails.getModifierName()); service.put(columnDefs[10].getId(), metadataDetails.getModifiedOn()); serviceContainer.addManageServices(service); } } catch (Exception ex) { throw new JobMetadataException("Exception while creating the list of job metadata parameters", ex); } return serviceContainer; } private ServiceContainer getManageDSP(ColumnDefinition[] columnDefs) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = new ServiceContainerImpl(); ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { List<DeviceScriptInfo> deviceScripts = DeviceScriptDBHelper.loadScriptsFromDB(-1, 0, null); for (DeviceScriptInfo deviceScript : deviceScripts) { service = new ServiceImpl(); String customerName = serverIf.getCustomerIf().getCustomerNameById(deviceScript.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(columnDefs[0].getId(), customerName); service.put(columnDefs[1].getId(), deviceScript.getScriptTitle()); service.put(columnDefs[3].getId(), deviceScript.getDefinition().toString()); service.put(columnDefs[4].getId(), deviceScript.getCreatorName()); service.put(columnDefs[5].getId(), deviceScript.getCreatedOn()); service.put(columnDefs[6].getId(), deviceScript.getModifierName()); service.put(columnDefs[7].getId(), deviceScript.getModifiedOn()); service.put(columnDefs[8].getId(), deviceScript.getScriptType().name()); service.put(columnDefs[9].getId(), deviceScript.getPackageType().name()); List<String> applicableVersionList = deviceScript.getApplicableVersions(); if ((applicableVersionList != null) && (applicableVersionList.size() > 0)) { StringBuffer sb = new StringBuffer(); int size = applicableVersionList.size(); int i = 0; for (String applicableVersion : applicableVersionList) { sb.append(applicableVersion); i++; if (i < size) { sb.append(","); } } service.put(columnDefs[10].getId(), sb.toString()); } service.put(columnDefs[11].getId(), deviceScript.getSize()); serviceContainer.addManageServices(service); } } catch (Exception ex) { throw new Exception("Exception while creating the listOfScriptInfo on the system", ex); } return serviceContainer; } private ServiceContainer getManageOSType(ColumnDefinition[] columnDefs) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = new ServiceContainerImpl(); ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { List<OSTypeDetails> osTypeDetailList = serverIf.getOSTypeManager().getOSTypeDetailsList(); for (OSTypeDetails osTypeDetail : osTypeDetailList) { service = new ServiceImpl(); service.put(columnDefs[0].getId(), osTypeDetail.getOsName()); service.put(columnDefs[1].getId(), osTypeDetail.getShortDesc()); service.put(columnDefs[2].getId(), osTypeDetail.getDesc()); service.put(columnDefs[3].getId(), osTypeDetail.getCategory()); serviceContainer.addManageServices(service); } } catch (Exception ex) { throw new Exception("Exception while creating the listOfScriptInfo on the system", ex); } return serviceContainer; } @Override public void exportData() throws Exception { ExportInfo exportInfo = ExportRequestHandler.getInstance().createExportInfo(getRequestDetails()); ReportExporterIntf exportReport = ExportFormatHandler.getInstance().getFormater(getRequestDetails()); if (exportReport == null) { exportInfo.setError("No exporter associated with this report"); exportInfo.setState(ExportInfoConstants.STATE_FAILED); exportInfo.setStatus(ExportInfoConstants.STATUS_FAILED); ExportDBHelper.updateExportInfo(exportInfo); throw new Exception("Exporter for the reportID " + getRequestDetails().getReportId() + " is not defined in handlers"); } exportReport.setExportInfo(exportInfo); exportReport.setReportRequestDetails(getRequestDetails()); exportReport.setTableData(getTableDataForRequest()); ExportRequestHandler.getInstance().executeTheRequest(exportReport); writeExportResponse(exportInfo); } private ServiceContainer getCustomReports(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = new ServiceContainerImpl(); ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { List<ScriptInfo> scriptInfos = serverIf.getReportDefManagerIf().getAllScriptInfo(true); for (ScriptInfo scriptInfo : scriptInfos) { if (scriptInfo.getIdentifier().startsWith("_")) { service = new ServiceImpl(); service.put(colDef[0].getId(), scriptInfo.getScriptTitle()); service.put(colDef[1].getId(), "User"); service.put(colDef[2].getId(), scriptInfo.getCreatorName()); service.put(colDef[3].getId(), scriptInfo.getCreatedOn()); service.put(colDef[4].getId(), scriptInfo.getModifierName()); service.put(colDef[5].getId(), scriptInfo.getModifiedOn()); service.put(colDef[6].getId(), scriptInfo.getScriptType().toString()); service.put(colDef[7].getId(), scriptInfo.getSize()); service.put(colDef[8].getId(), scriptInfo.getChecksum()); String customerName = getRequestDetails().getServerIf().getCustomerIf() .getCustomerNameById(scriptInfo.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(colDef[9].getId(), customerName); service.put(colDef[10].getId(), scriptInfo.getSourceType() == null ? null : scriptInfo.getSourceType().toString()); serviceContainer.addManageServices(service); } } } catch (Exception ex) { throw new Exception("Exception while creating the listOfScriptInfo on the system", ex); } return serviceContainer; } private ServiceContainer getPolicyProfileDetail(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); LWCustomPolicy[] allPolicies = serverIf.getCustomPolicyIf().getAllLWCustomPolicies(); if (null == allPolicies) { return null; } Arrays.sort(allPolicies, new PolicySorter()); serviceContainer = new ServiceContainerImpl(); for (LWCustomPolicy customPolicy : allPolicies) { if (customPolicy != null) { service = new ServiceImpl(); String customerName = serverIf.getCustomerIf().getCustomerNameById(customPolicy.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(colDef[0].getId(), customerName); service.put(colDef[1].getId(), customPolicy.getTitle()); service.put(colDef[2].getId(), customPolicy.getPolicyType().toString()); service.put(colDef[3].getId(), customPolicy.getCreatedUser()); service.put(colDef[4].getId(), customPolicy.getRuleCount()); service.put(colDef[5].getId(), customPolicy.getDescription()); service.put(colDef[6].getId(), customPolicy.getSourceType()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getPolicyGroupsDetailsReport(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; LWPolicyGroup[] allPolicyGroup = PolicyGroupManager.getInstance().getAllLWPolicyGroups(false, false); if (null == allPolicyGroup) { return null; } Arrays.sort(allPolicyGroup, new PolicySorter()); serviceContainer = new ServiceContainerImpl(); for (LWPolicyGroup policyGroup : allPolicyGroup) { if (policyGroup != null) { service = new ServiceImpl(); String name = (null == policyGroup.getTitle() || 0 == policyGroup.getTitle().length()) ? policyGroup.getName() : policyGroup.getTitle(); String category = (true == policyGroup.isFixedGroup() ? TYPE_SYSTEM : TYPE_USER_DEFINED); String customerName = getRequestDetails().getServerIf().getCustomerIf() .getCustomerNameById(policyGroup.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(colDef[0].getId(), customerName); service.put(colDef[1].getId(), name); service.put(colDef[2].getId(), category); service.put(colDef[3].getId(), policyGroup.getCreatedUser()); service.put(colDef[4].getId(), policyGroup.getMemberPolicyCount()); service.put(colDef[5].getId(), policyGroup.getDescription()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getManagePolicyProfileDetail(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; LWPolicyProfile[] allPolicies = getRequestDetails().getServerIf().getPolicyProfileManagerIf() .getAllLWPolicyProfiles(); if (null == allPolicies) { return null; } Arrays.sort(allPolicies, new PolicySorter()); serviceContainer = new ServiceContainerImpl(); for (LWPolicyProfile policyProfile : allPolicies) { if (policyProfile != null) { service = new ServiceImpl(); service.put(colDef[0].getId(), policyProfile.getName()); if (policyProfile.isSystemProfile()) { service.put(colDef[1].getId(), TYPE_SYSTEM); } else { service.put(colDef[1].getId(), TYPE_USER_DEFINED); } service.put(colDef[2].getId(), policyProfile.getCreatedUser()); service.put(colDef[3].getId(), policyProfile.getMemberCount()); service.put(colDef[4].getId(), policyProfile.getDescription()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getManageConfigTemplateDetail(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; List<IConfigset> allConfigSet = getRequestDetails().getServerIf().getCvsManagerIf().getAllConfigsets(); if (null == allConfigSet) { return null; } Collections.sort(allConfigSet, new PolicySorter()); serviceContainer = new ServiceContainerImpl(); for (IConfigset configSet : allConfigSet) { if (configSet != null) { service = new ServiceImpl(); String customerName = (configSet.getCustomer() == -1 ? "All Customers" : getRequestDetails().getServerIf().getCustomerIf() .getCustomerNameById(configSet.getCustomer())); service.put(colDef[0].getId(), customerName); service.put(colDef[1].getId(), configSet.getTitle()); service.put(colDef[2].getId(), configSet.getType().toString()); service.put(colDef[3].getId(), configSet.getCreatedBy()); service.put(colDef[4].getId(), configSet.getCreatedOn()); service.put(colDef[5].getId(), configSet.getSourceType() == null ? null : configSet.getSourceType().toString()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getManageGroupDetails(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; String reportId = getRequestDetails().getReportId(); ServerIfProvider serverIf = getRequestDetails().getServerIf(); LWObjectGroup[] allGroups = null; String category = null; if (reportId.equals("manage_device_groups")) { allGroups = serverIf.getGroupingServiceIf().getAllLWUserDefinedGroups(GroupType.NETWORK_NODE, -1); category = "Device Group"; } else if (reportId.equals("manage_interface_groups")) { allGroups = serverIf.getGroupingServiceIf().getAllLWUserDefinedGroups(GroupType.INTERFACE, -1); category = "Interface Group"; } if (null == allGroups) { return null; } List<LWObjectGroup> allGroupsList = Arrays.asList(allGroups); Collections.sort(allGroupsList, new PolicySorter()); serviceContainer = new ServiceContainerImpl(); for (LWObjectGroup group : allGroupsList) { if (group.getParentId() > 2) { continue; } processGroups(colDef, serviceContainer, category, group, 0); } return serviceContainer; } private void processGroups(ColumnDefinition[] colDef, ServiceContainerImpl serviceContainer, String category, LWObjectGroup group, int level) { ServiceImpl service; if (group != null) { service = new ServiceImpl(); String name = group.getGroupName(); for (int i = 0; i < level; i++) { if (i == 0) { name = " " + name; } name = "----" + name; } service.put(colDef[0].getId(), name); service.put(colDef[1].getId(), category); String customerName = getRequestDetails().getServerIf().getCustomerIf() .getCustomerNameById(group.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(colDef[2].getId(), customerName); String type = null; if (group.isSystemGroup()) { type = "System"; } else if (group.isCustomerGroup()) { type = "Customer"; } else { type = "User Defined"; } service.put(colDef[3].getId(), type); if (group.isDynamicGroup()) { service.put(colDef[4].getId(), StringUtils.capitalize(DeviceGroupMembership.DYNAMIC.name().toLowerCase())); } else { service.put(colDef[4].getId(), StringUtils.capitalize(DeviceGroupMembership.STATIC.name().toLowerCase())); } service.put(colDef[5].getId(), getMembers(group).size()); service.put(colDef[6].getId(), group.getCreatedBy()); service.put(colDef[7].getId(), group.getGroupDescription()); serviceContainer.addManageServices(service); if (group.getChildren() != null) { for (LWObjectGroup child : group.getChildren()) { processGroups(colDef, serviceContainer, category, child, level + 1); } } } } private HashSet<Object> getMembers(LWObjectGroup group) { HashSet<Object> deviceIds = new HashSet<Object>(); if (group.getMemberIds() != null && group.getMemberIds().length > 0) { deviceIds.addAll(Arrays.asList(group.getMemberIds())); } if (group.getChildren() != null) { for (LWObjectGroup child : group.getChildren()) { deviceIds.addAll(getMembers(child)); } } if (getRequestDetails().getReportId().equals("manage_interface_groups")) { return deviceIds; } return getGroupMembers(deviceIds.toArray()); } private HashSet<Object> getGroupMembers(Object[] memberIds) { HashSet<Object> deviceIds = new HashSet<Object>(); int[] membersIntIds = new int[memberIds.length]; int i = 0; for (int j = 0; j < memberIds.length; j++) { membersIntIds[i] = Integer.valueOf(String.valueOf(memberIds[i])); i++; } ServerIfProvider serverIfProvider = getRequestDetails().getServerIf(); NetworkNode[] nodes = serverIfProvider.getCacheIf().getUserNodeByIDList(membersIntIds); for (NetworkNode node : nodes) { if (node.isModuleDevice()) { continue; } deviceIds.add(node.getNodeId()); } return deviceIds; } private ServiceContainer getUserDefinedDatasetDetails(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; Dataset[] allDatasets = getRequestDetails().getServerIf().getInventoryIf().getAllUserDefinedDatasets(); if (null == allDatasets) { return null; } serviceContainer = new ServiceContainerImpl(); for (Dataset dataSet : allDatasets) { if (null != dataSet) { service = new ServiceImpl(); service.put(colDef[0].getId(), dataSet.getDisplayName()); service.put(colDef[1].getId(), dataSet.getApplicablePlatformsAsString()); service.put(colDef[2].getId(), String.valueOf(dataSet.getCollectonType())); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getUserDefinedPlatformDetails(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; CustomPlatformManagerIf customPlatformManagerIf = getRequestDetails().getServerIf() .getCustomPlatformManagerIf(); String[] allPlatformIds = customPlatformManagerIf.getAllPlatformIds(); if (null == allPlatformIds) { return null; } serviceContainer = new ServiceContainerImpl(); for (String platformId : allPlatformIds) { CustomPlatformIf platform = customPlatformManagerIf.getPlatform(platformId); if (null != platform) { String title = platform.getTitle(); String createdUser = platform.getCreatedUser(); String productModel = ""; String deviceFamily = ""; String productFamily = ""; String osName = ""; String osVersion = ""; int modifiedBy = platform.getModifierId(); List<VersionedEntity> hwReferences = platform.getHwReferences(); if ((hwReferences != null) && (hwReferences.size() > 0)) { deviceFamily = hwReferences.get(0).getFamily(); ValueMatcher productModelMatcher = hwReferences.get(0).getProductModel(); if (productModelMatcher != null) { productModel = productModelMatcher.getDisplayString(); } ValueMatcher productFamilyMatcher = hwReferences.get(0).getProductFamily(); if (productFamilyMatcher != null) { productFamily = productFamilyMatcher.getDisplayString(); } } List<VersionedEntity> osReferences = platform.getOsReferences(); if ((osReferences != null) && (osReferences.size() > 0)) { String osNameStr = osReferences.get(0).getFamily(); if (osNameStr != null) { osName = osNameStr; OSTypeDetails osType = getRequestDetails().getServerIf().getOSTypeManager() .getOSTypeDetails(osName); if (osType != null) { osName = osType.getDesc(); } } DefaultVersionInfo osVersionInfo = osReferences.get(0).getVersionInfo(); if (osVersionInfo instanceof IOSVersionInfoImpl) { VersionOperatorType operType = ((IOSVersionInfoImpl) osVersionInfo).getOperator(); String version = ((IOSVersionInfoImpl) osVersionInfo).getVersionStr(); if ((operType != null) && (version != null)) { osVersion = operType.toString() + " " + version.toString(); } } } service = new ServiceImpl(); String customerName = getRequestDetails().getServerIf().getCustomerIf() .getCustomerNameById(platform.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(colDef[0].getId(), customerName); service.put(colDef[1].getId(), title); service.put(colDef[2].getId(), createdUser); service.put(colDef[3].getId(), getUserName(modifiedBy)); service.put(colDef[4].getId(), productModel); service.put(colDef[5].getId(), deviceFamily); service.put(colDef[6].getId(), productFamily); service.put(colDef[7].getId(), osName); service.put(colDef[8].getId(), osVersion); service.put(colDef[9].getId(), platform.getSourceType() == null ? null : platform.getSourceType().toString()); serviceContainer.addManageServices(service); } } return serviceContainer; } @SuppressWarnings("unchecked") private ServiceContainer getSetUpWorkflowApprovalDetails(ColumnDefinition[] colDef, TableDefinition childTableDef, HashMap<String, Object> paramFilters) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; String customerName = getRequestDetails().getCustomer(); int customerId = -1; if (customerName != null && customerName.trim().length() > 0) { try { customerId = getRequestDetails().getServerIf().getCustomerIf().getCustomerIdByName(customerName); } catch (Exception e) { logger.error("Exception while Exporting Setup Workflow", e); } } Map<Integer, ApprovalDefinition> approvalDefMap = null; try { if (paramFilters != null && paramFilters.size() > 0) { approvalDefMap = new HashMap<Integer, ApprovalDefinition>(); ArrayList<String> grpNames = new ArrayList<String>(); Object grpIdObj = paramFilters.get("DeviceGroup"); if (grpIdObj instanceof String) { grpNames.add((String) grpIdObj); } else if (grpIdObj instanceof ArrayList) { grpNames = (ArrayList<String>) grpIdObj; } for (String grpName : grpNames) { int grpId = GroupingService.getInstance().getGroupIdFromName(grpName); ApprovalDefinition approvalDef = getRequestDetails().getServerIf().getApprovalIf() .getWorkflowApprovalDefsWithLevels(grpId, customerId); approvalDefMap.put(grpId, approvalDef); } } else { approvalDefMap = getRequestDetails().getServerIf().getApprovalIf() .getAllWorkflowApprovalDefsWithLevels(customerId); } } catch (PariException e) { e.printStackTrace(); } if (null == approvalDefMap) { return null; } SimpleDateFormat formatter = new SimpleDateFormat("EEE, MMM dd, yyyy HH:mm:ss Z"); serviceContainer = new ServiceContainerImpl(); for (Map.Entry<Integer, ApprovalDefinition> map : approvalDefMap.entrySet()) { service = new ServiceImpl(); ApprovalDefinition approvalDefinition = map.getValue(); String creationTime = (0 == approvalDefinition.getCreationTime()) ? "" : getTimeBasedOnZone(approvalDefinition.getCreationTime()); String modifierTime = (0 == approvalDefinition.getModifierTime()) ? "" : formatter.format(new Date(approvalDefinition.getModifierTime())); service.put(colDef[0].getId(), approvalDefinition.getGroupName()); service.put(colDef[1].getId(), approvalDefinition.getWorkFlowName()); service.put(colDef[2].getId(), approvalDefinition.getCreatorLogin()); service.put(colDef[3].getId(), creationTime); service.put(colDef[4].getId(), approvalDefinition.getModifierLogin()); service.put(colDef[5].getId(), modifierTime); if (childTableDef != null) { ColumnDefinition[] chidlColDef = childTableDef.getColumnDefs(); Map<Integer, ApprovalLevelDefination> approvalLevels = approvalDefinition.getApprovalLevels(); if (approvalLevels != null && approvalLevels.size() > 0) { ServiceContainerImpl approvalLevelSrvCont = new ServiceContainerImpl(); for (Integer level : approvalLevels.keySet()) { ApprovalLevelDefination approvalLevel = approvalLevels.get(level); Map<Integer, String> approverLogins = approvalLevel.getApproverLogins(); if (approverLogins != null && approverLogins.size() > 0) { for (Integer id : approverLogins.keySet()) { ServiceImpl srvImpl = new ServiceImpl(); srvImpl.put(chidlColDef[0].getId(), approvalDefinition.getGroupName()); srvImpl.put(chidlColDef[1].getId(), level); srvImpl.put(chidlColDef[2].getId(), approverLogins.get(id)); srvImpl.put(chidlColDef[3].getId(), approvalLevel.getApprovalComplType().getActionString()); approvalLevelSrvCont.addManageServices(srvImpl); } } HashMap<Integer, ApprovalGroupDefinition> approvalUsrGrps = approvalLevel .getApprovalUserGrps(); if (approvalUsrGrps != null && approvalUsrGrps.size() > 0) { for (ApprovalGroupDefinition approvalUsrGrp : approvalUsrGrps.values()) { approverLogins = approvalUsrGrp.getApproverLogins(); if (approverLogins != null && approverLogins.size() > 0) { for (Integer id : approverLogins.keySet()) { ServiceImpl srvImpl = new ServiceImpl(); srvImpl.put(chidlColDef[0].getId(), approvalDefinition.getGroupName()); srvImpl.put(chidlColDef[1].getId(), level); srvImpl.put(chidlColDef[2].getId(), approverLogins.get(id)); srvImpl.put(chidlColDef[3].getId(), approvalLevel.getApprovalComplType().getActionString()); approvalLevelSrvCont.addManageServices(srvImpl); } } } } } service.put("ApprovalLevelDefs", approvalLevelSrvCont); } } serviceContainer.addManageServices(service); } return serviceContainer; } private ServiceContainer getCiscoNccmUserDetails(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); UserDetails[] allUserDetails = serverIf.getNmIf().getAllUsers(); if (null == allUserDetails) { return null; } String roleName = null; serviceContainer = new ServiceContainerImpl(); for (UserDetails userDetails : allUserDetails) { if (null != userDetails) { service = new ServiceImpl(); service.put(colDef[0].getId(), userDetails.getLogin()); service.put(colDef[1].getId(), userDetails.getName()); service.put(colDef[2].getId(), userDetails.getAuthTypeStr()); UserGroupType groupType = UserGroupType.getFromGroupId(userDetails.getGroup_id()); service.put(colDef[3].getId(), (null == groupType) ? "Unknown Group" : String.valueOf(groupType)); try { roleName = serverIf.getNmIf().getUserRoleName(userDetails.getUserId()); } catch (Exception e) { logger.error("Exception while getting RoleName from UserIdentifier", e); } if (roleName != null && roleName.trim().length() > 0) { service.put(colDef[4].getId(), roleName); } else { service.put(colDef[4].getId(), " "); } service.put(colDef[5].getId(), (true == userDetails.isHasUnlimitedAccess()) ? "Unlimited Access" : getCustomerNamesFromUserDetails(userDetails)); serviceContainer.addManageServices(service); } } return serviceContainer; } private String getCustomerNamesFromUserDetails(UserDetails userDetails) { Integer[] customerArray = userDetails.getCustomerList(); if (null == customerArray || 0 == customerArray.length) { return "Selected Customers"; } boolean append = false; StringBuffer buffer = new StringBuffer(); for (Integer customerId : customerArray) { if (true == append) { buffer.append(", "); } ServerIfProvider serverIf = getRequestDetails().getServerIf(); String customer = null; try { customer = serverIf.getCustomerIf().getCustomerNameById(customerId); } catch (Exception e) { logger.error("Exception while getting CustomerName from CustomerId"); } if (null != customer) { buffer.append(customer); append = true; } else { append = false; } } return buffer.toString(); } private ServiceContainer getManageCustomerDetails(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); Customer[] allCustomers = null; boolean isSuperAdmin = false; HashMap<String, Object> filterMap = getRequestDetails().getParameterFilterMap(); if ((!(filterMap.isEmpty())) && filterMap.containsKey(RequestAttributes.SuperAdmin.name())) { isSuperAdmin = filterMap.get(RequestAttributes.SuperAdmin.name()).toString().equalsIgnoreCase("true") ? true : false; } if (isSuperAdmin || getUserAccess()) { allCustomers = serverIf.getCustomerIf().getAllCustomers(); } else { allCustomers = serverIf.getCustomerIf().getAllUserCustomers(); } if (null == allCustomers) { return null; } List<Customer> allCustomerList = Arrays.asList(allCustomers); Collections.sort(allCustomerList, new PolicySorter()); serviceContainer = new ServiceContainerImpl(); for (Customer customer : allCustomerList) { if (customer != null) { service = new ServiceImpl(); service.put(colDef[0].getId(), customer.getCustomerName()); service.put(colDef[1].getId(), customer.getCreaterName()); service.put(colDef[2].getId(), customer.getContactName()); service.put(colDef[3].getId(), customer.getContactEmailAddress()); service.put(colDef[4].getId(), customer.getContactPhoneNumber()); service.put(colDef[5].getId(), customer.getNoOfDevices()); service.put(colDef[6].getId(), (customer.getAvailedLicenses() == -1) ? 0 : customer.getAvailedLicenses()); service.put(colDef[7].getId(), (customer.getNoOfLicenses() == -1) ? "" : customer.getNoOfLicenses()); serviceContainer.addManageServices(service); } } return serviceContainer; } private boolean getUserAccess() { ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { UserDetails currentUserDetails = serverIf.getNmIf().getCurrentUser(); if (currentUserDetails != null && currentUserDetails.isHasUnlimitedAccess()) { return true; } } catch (Exception e) { logger.error("failed to get current logged in user details", e); } return false; } private ServiceContainer getLicenseWeightageDetails(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; boolean includeBlankRows = false; ServerIfProvider serverIf = getRequestDetails().getServerIf(); LicenseReportInstance[] allLicenseInstances = serverIf.getNmIf().getAllLicenseInstances(includeBlankRows); if (null == allLicenseInstances) { return null; } serviceContainer = new ServiceContainerImpl(); int totalLicense = 0; for (LicenseReportInstance licenseReport : allLicenseInstances) { if (null != licenseReport) { service = new ServiceImpl(); service.put(colDef[0].getId(), licenseReport.getRule()); service.put(colDef[1].getId(), licenseReport.getNo_of_devices()); service.put(colDef[2].getId(), licenseReport.getWeightage_per_device()); service.put(colDef[3].getId(), licenseReport.getTotal_weightage_availed()); serviceContainer.addManageServices(service); totalLicense = totalLicense + licenseReport.getTotal_weightage_availed(); } } service = new ServiceImpl(); service.put(colDef[0].getId(), "Total License"); service.put(colDef[1].getId(), "0"); service.put(colDef[2].getId(), "0"); service.put(colDef[3].getId(), totalLicense); serviceContainer.addManageServices(service); service = new ServiceImpl(); service.put(colDef[0].getId(), "System Allowed License"); service.put(colDef[1].getId(), "0"); service.put(colDef[2].getId(), "0"); service.put(colDef[3].getId(), LicenseValidator.getInstance().getNoOfDevices()); serviceContainer.addManageServices(service); return serviceContainer; } private ServiceContainer getManageScriptRepositoryDetails(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); ScriptInfo[] allScriptInfos = serverIf.getSwimScriptManagerIf().getAllScriptInfos(); if (null == allScriptInfos) { return null; } serviceContainer = new ServiceContainerImpl(); for (ScriptInfo scriptInfo : allScriptInfos) { if (scriptInfo != null) { service = new ServiceImpl(); String customerName = serverIf.getCustomerIf().getCustomerNameById(scriptInfo.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(colDef[0].getId(), customerName); service.put(colDef[1].getId(), scriptInfo.getScriptTitle()); service.put(colDef[2].getId(), (null == scriptInfo.getDefinition()) ? "" : scriptInfo.getDefinition().name()); service.put(colDef[3].getId(), scriptInfo.getCreatorName()); service.put(colDef[4].getId(), new Date(scriptInfo.getCreatedOn())); service.put(colDef[5].getId(), scriptInfo.getModifierName()); service.put(colDef[6].getId(), (0 < scriptInfo.getModifiedOn()) ? new Date(scriptInfo.getModifiedOn()) : ""); service.put(colDef[7].getId(), scriptInfo.getScriptType()); service.put(colDef[8].getId(), scriptInfo.getSize()); service.put(colDef[9].getId(), scriptInfo.getChecksum()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getMyTriggerConfigJobDetails(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); String login = serverIf.getUserDetails().getLogin(); List<TriggerConfigJobDetails> reportList = serverIf.getNmIf().getWaitingTriggerConfigDetails(login); if (null == reportList) { reportList = new ArrayList<TriggerConfigJobDetails>(); } serviceContainer = new ServiceContainerImpl(); for (TriggerConfigJobDetails report : reportList) { if (report != null) { service = new ServiceImpl(); service.put(colDef[0].getId(), report.getJobId()); service.put(colDef[1].getId(), report.getJobName()); service.put(colDef[2].getId(), report.getJobDescription()); service.put(colDef[3].getId(), report.getSubmitter()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getImageFreezePreferences(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; List<ImageCollectionFreezePreferences> allFreezeWindows = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { allFreezeWindows = serverIf.getNmIf().viewImageCollectionFreezePreferences(); } catch (Exception e) { logger.error("Exception while Export operation", e); } if (null == allFreezeWindows) { allFreezeWindows = new ArrayList<ImageCollectionFreezePreferences>(); } serviceContainer = new ServiceContainerImpl(); for (ImageCollectionFreezePreferences report : allFreezeWindows) { if (report != null) { service = new ServiceImpl(); service.put(colDef[0].getId(), report.getFreezeTitle()); service.put(colDef[1].getId(), report.getStartDate()); service.put(colDef[2].getId(), (0 < report.getRepeatInterval()) ? report.getRepeatInterval() : ""); service.put(colDef[3].getId(), (0 < report.getEndDate()) ? report.getEndDate() : ""); service.put(colDef[4].getId(), (0 < report.getDuration()) ? report.getDuration() : ""); service.put(colDef[5].getId(), report.getElementIdsList().size()); service.put(colDef[6].getId(), report.getCreateUser()); service.put(colDef[7].getId(), report.getCreateTime()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getFaultHistory(ColumnDefinition[] colDef) throws Exception { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; int faultId = -1; Fault[] fault = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); HashMap<String, Object> filterMap = getRequestDetails().getParameterFilterMap(); if (filterMap.isEmpty()) { throw new Exception("Parameter tag is required."); } faultId = filterMap.get(RequestAttributes.FaultId.name()) == null ? -1 : Integer.valueOf(filterMap.get(RequestAttributes.FaultId.name()).toString()); if (faultId <= 0) { throw new Exception("Please provide faultId"); } serviceContainer = new ServiceContainerImpl(); try { fault = serverIf.getFaultManagerIf().getFaultHistory(faultId); } catch (Exception e) { logger.error("Exception while Export Fault History operation", e); } if (fault != null && fault.length > 0) { for (Fault faultObj : fault) { if (faultObj != null) { service = new ServiceImpl(); colDef[0].setRenderer(RendererType.STRING); NetworkNode node = serverIf.getCacheIf().getNodeByID(faultObj.getDevId()); if (node != null) { service.put(colDef[0].getId(), node.getNodeId()); } else { service.put(colDef[0].getId(), "Deleted Device"); } service.put(colDef[1].getId(), faultObj.getCondition()); service.put(colDef[2].getId(), faultObj.getSubModule()); service.put(colDef[3].getId(), faultObj.getSeverity()); service.put(colDef[4].getId(), faultObj.getMessage()); service.put(colDef[5].getId(), faultObj.getInvocationCount()); if (faultObj.isActive()) { service.put(colDef[6].getId(), "Yes"); } else { service.put(colDef[6].getId(), "No"); } if (faultObj.isAcked()) { service.put(colDef[7].getId(), "Yes"); } else { service.put(colDef[7].getId(), "No"); } service.put(colDef[8].getId(), (0 < faultObj.getFirstReportedTimeStamp()) ? faultObj.getFirstReportedTimeStamp() : ""); service.put(colDef[9].getId(), (0 < faultObj.getLastUpdatedTimeStamp()) ? faultObj.getLastUpdatedTimeStamp() : ""); serviceContainer.addManageServices(service); } } } return serviceContainer; } @SuppressWarnings("rawtypes") private ServiceContainer getNCCMMHealthStatusTable(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; serviceContainer = new ServiceContainerImpl(); NCCMHealthStatus status = null; List<NCCMHealthStatus> statusList = null; try { statusList = getNCCMHealthStatus(NCCMHealthType.CPUStatus, 1); if (statusList != null) { service = new ServiceImpl(); colDef[0].setRenderer(RendererType.STRING); service.put(colDef[0].getId(), "Processor Occupancy (%)"); status = statusList.get(0); if (status != null) { Double[] cpuLoad = (Double[]) status.getMeasure(); if (cpuLoad != null && cpuLoad.length > 0) { service.put(colDef[1].getId(), cpuLoad[0]); } else { service.put(colDef[1].getId(), -1); } if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } } statusList = getNCCMHealthStatus(NCCMHealthType.MemoryStatus, 1); if (statusList != null) { status = statusList.get(0); if (status != null) { Long[] memory = (Long[]) status.getMeasure(); if (memory != null && memory.length > 2) { if (memory[0] != null) { service = new ServiceImpl(); service.put(colDef[0].getId(), "Memory Used (%)"); double usedPercent = -1; if (memory[0] != null && memory[2] != null) { usedPercent = ((double) memory[0] / (double) memory[2]) * 100.0; } service.put(colDef[1].getId(), Math.round(usedPercent)); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } else { service = new ServiceImpl(); service.put(colDef[0].getId(), "Memory Used (%)"); service.put(colDef[1].getId(), -1); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } if (memory[0] != null) { service = new ServiceImpl(); service.put(colDef[0].getId(), "Used Memory (MB)"); double usedMemory = (double) memory[0] / (1024 * 1024); service.put(colDef[1].getId(), Math.round(usedMemory * 100) / 100D); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } else { service = new ServiceImpl(); service.put(colDef[0].getId(), "Used Memory (MB)"); service.put(colDef[1].getId(), -1); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } if (memory[2] != null) { service = new ServiceImpl(); service.put(colDef[0].getId(), "Total Memory (MB)"); double totalMemory = (double) memory[2] / (1024 * 1024); service.put(colDef[1].getId(), Math.round(totalMemory * 100) / 100D); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } else { service = new ServiceImpl(); service.put(colDef[0].getId(), "Total Memory (MB)"); service.put(colDef[1].getId(), -1); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } } } } statusList = getNCCMHealthStatus(NCCMHealthType.JobStatus, -1); if (statusList != null) { status = statusList.get(0); if (status != null) { Integer[] jobCnt = (Integer[]) status.getMeasure(); if (jobCnt != null && jobCnt.length > 0) { service = new ServiceImpl(); service.put(colDef[0].getId(), "Number of Jobs Running"); service.put(colDef[1].getId(), jobCnt[0]); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } else { service = new ServiceImpl(); service.put(colDef[0].getId(), "Number of Jobs Running"); service.put(colDef[1].getId(), -1); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } } } statusList = getNCCMHealthStatus(NCCMHealthType.UserSessionStatus, 1); if (statusList != null) { status = statusList.get(0); if (status != null) { Integer[] userCnt = (Integer[]) status.getMeasure(); if (userCnt != null && userCnt.length > 0) { service = new ServiceImpl(); service.put(colDef[0].getId(), "Number of Active User Sessions"); service.put(colDef[1].getId(), userCnt[0]); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } else { service = new ServiceImpl(); service.put(colDef[0].getId(), "Number of Active User Sessions"); service.put(colDef[1].getId(), -1); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } } } statusList = getNCCMHealthStatus(NCCMHealthType.LicensesUsedStatus, 1); if (statusList != null) { status = statusList.get(0); if (status != null) { Integer[] licCnt = (Integer[]) status.getMeasure(); if (licCnt != null && licCnt.length > 0) { service = new ServiceImpl(); service.put(colDef[0].getId(), "Number of Licenses Used"); service.put(colDef[1].getId(), licCnt[0]); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } else { service = new ServiceImpl(); service.put(colDef[0].getId(), "Number of Licenses Used"); service.put(colDef[1].getId(), -1); if (status.getMeasureTime() != -1) { service.put(colDef[2].getId(), status.getMeasureTime()); } else { service.put(colDef[2].getId(), -1); } serviceContainer.addManageServices(service); } } } } catch (Exception e) { logger.error("Exception while Export operation", e); } return serviceContainer; } @SuppressWarnings("rawtypes") private List<NCCMHealthStatus> getNCCMHealthStatus(NCCMHealthType type, int numInstances) { NCCMHealthStatusManagerIf manager = getRequestDetails().getServerIf().getNCCMHealthManagerIf(); if (numInstances != -1) { return manager.retrieveStatus(type, numInstances); } return manager.retrieveStatus(type, 1000); } private ServiceContainer getUserRoles(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; List<UserRole> userRoleList = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { userRoleList = serverIf.getNmIf().loadUserRoles(); } catch (Exception ex) { logger.error("Exception occur:", ex); } if (null == userRoleList) { logger.error("Exception while fetching the userRole"); return null; } serviceContainer = new ServiceContainerImpl(); for (UserRole userRole : userRoleList) { if (null != userRole) { service = new ServiceImpl(); service.put(colDef[0].getId(), userRole.getRoleName()); service.put(colDef[1].getId(), userRole.getCreatedBy()); service.put(colDef[2].getId(), (userRole.getCreatedDate() > 0) ? userRole.getCreatedDate() : " "); service.put(colDef[3].getId(), userRole.getModifiedBy()); service.put(colDef[4].getId(), (userRole.getModifiedDate() > 0) ? userRole.getModifiedDate() : " "); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getSoftwareImageDetails(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; LWSoftwareImage[] lwSWImagesArr = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { lwSWImagesArr = serverIf.getImageIf().getLWSoftwareImages(null); } catch (Exception e) { logger.error("Exception while Export operation", e); } serviceContainer = new ServiceContainerImpl(); TableProperties tProper = getRequestDetails().getTableDef().getProps(); String title = tProper.getTitle(); tProper.setTitle(title); getRequestDetails().getTableDef().setProps(tProper); if (lwSWImagesArr != null && lwSWImagesArr.length > 0) { for (LWSoftwareImage lwSoftwareImage : lwSWImagesArr) { service = new ServiceImpl(); service.put(colDef[0].getId(), lwSoftwareImage.getName()); service.put(colDef[1].getId(), lwSoftwareImage.getCreatorName()); service.put(colDef[2].getId(), lwSoftwareImage.getOsName()); service.put(colDef[3].getId(), lwSoftwareImage.getOsVersion()); service.put(colDef[4].getId(), lwSoftwareImage.getNoOfDeviceRunning()); service.put(colDef[5].getId(), (0 < lwSoftwareImage.getLastSeenOnNetwork()) ? lwSoftwareImage.getLastSeenOnNetwork() : ""); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getMixAndMatchReportDetails(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; UserDefinedReport[] userDefinedReports = null; ServerIfProvider serverIf = getRequestDetails().getServerIf(); try { userDefinedReports = serverIf.getReportIf().getAllUserDefinedReports(); } catch (Exception e) { logger.error("Exception while Export operation", e); } serviceContainer = new ServiceContainerImpl(); if (userDefinedReports != null && userDefinedReports.length > 0) { for (UserDefinedReport userDefinedReport : userDefinedReports) { service = new ServiceImpl(); service.put(colDef[0].getId(), userDefinedReport.getTitle()); service.put(colDef[1].getId(), userDefinedReport.getReportDef().getColumnCount()); service.put(colDef[2].getId(), userDefinedReport.getCreatedUser()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getGoldConfigTemplateDetails(ColumnDefinition[] colDef) { ServerIfProvider serverIf = getRequestDetails().getServerIf(); ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; List<GoldenConfigInfo> goldConfigTemplatesList = null; try { goldConfigTemplatesList = serverIf.getCvsManagerIf().getGoldenConfigs(); } catch (Exception e) { logger.error("Exception while Export operation", e); } serviceContainer = new ServiceContainerImpl(); if (goldConfigTemplatesList != null && !goldConfigTemplatesList.isEmpty()) { for (GoldenConfigInfo goldenConfigInfo : goldConfigTemplatesList) { service = new ServiceImpl(); service.put(colDef[0].getId(), goldenConfigInfo.getTitle()); service.put(colDef[1].getId(), goldenConfigInfo.getDescription()); service.put(colDef[2].getId(), goldenConfigInfo.getCreatedBy()); service.put(colDef[3].getId(), goldenConfigInfo.getCreatedAt()); serviceContainer.addManageServices(service); } } return serviceContainer; } private ServiceContainer getReportTemplates(ColumnDefinition[] colDef) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; List<ReportTemplateMetaInfo> templateDefs = new ArrayList<ReportTemplateMetaInfo>(); try { templateDefs = getRequestDetails().getServerIf().getReportTemplateManagerIf() .getAllTemplateMetaInfo(true); } catch (Exception e) { logger.error("Exception while Export Report Templates", e); } serviceContainer = new ServiceContainerImpl(); if (templateDefs.size() > 0) { for (ReportTemplateMetaInfo templateDef : templateDefs) { service = new ServiceImpl(); service.put(colDef[0].getId(), templateDef.getTemplateTitle()); service.put(colDef[1].getId(), templateDef.getDefinition().name()); service.put(colDef[2].getId(), templateDef.getCreatorName()); service.put(colDef[3].getId(), templateDef.getCreated_on()); service.put(colDef[4].getId(), templateDef.getSize()); String customerName = getRequestDetails().getServerIf().getCustomerIf() .getCustomerNameById(templateDef.getCustomerId()); customerName = (null == customerName) ? "All Customers" : customerName; service.put(colDef[5].getId(), customerName); service.put(colDef[6].getId(), templateDef.getSourceType() == null ? null : templateDef.getSourceType().toString()); serviceContainer.addManageServices(service); } } return serviceContainer; } @SuppressWarnings("unchecked") private ServiceContainer getApprovalUserGroupDetails(ColumnDefinition[] colDef, ColumnDefinition[] chidlColDef, HashMap<String, Object> paramFilters) { ServiceImpl service = null; ServiceContainerImpl serviceContainer = null; String customerName = getRequestDetails().getCustomer(); int customerId = -1; if (customerName != null && customerName.trim().length() > 0) { try { customerId = getRequestDetails().getServerIf().getCustomerIf().getCustomerIdByName(customerName); } catch (Exception e) { logger.error("Exception while Exporting Approval User Group", e); } } Map<Integer, ApprovalGroupDefinition> approvalUserGrps = new HashMap<Integer, ApprovalGroupDefinition>(); try { if (paramFilters != null && paramFilters.size() > 0) { ArrayList<String> approvalUsrGrpIds = new ArrayList<String>(); Object approvalGrpIdObj = paramFilters.get("GroupId"); if (approvalGrpIdObj instanceof String) { approvalUsrGrpIds.add((String) approvalGrpIdObj); } else if (approvalGrpIdObj instanceof ArrayList) { approvalUsrGrpIds = (ArrayList<String>) approvalGrpIdObj; } for (String approvalUsrGrpId : approvalUsrGrpIds) { ApprovalGroupDefinition approvalUsrGrpDef = getRequestDetails().getServerIf().getApprovalIf() .getApprovalUserGroup(Integer.parseInt(approvalUsrGrpId), -1); approvalUserGrps.put(Integer.parseInt(approvalUsrGrpId), approvalUsrGrpDef); } } else { approvalUserGrps = getRequestDetails().getServerIf().getApprovalIf() .getAllApprovalUserGroup(customerId); } } catch (Exception e) { logger.error("Exception while Export Approval User Groups", e); } serviceContainer = new ServiceContainerImpl(); if (approvalUserGrps.size() > 0) { for (Integer identifier : approvalUserGrps.keySet()) { ApprovalGroupDefinition approvalDefinition = approvalUserGrps.get(identifier); service = new ServiceImpl(); service.put(colDef[0].getId(), approvalDefinition.getGrpName()); service.put(colDef[1].getId(), approvalDefinition.getCreatorLogin()); service.put(colDef[2].getId(), approvalDefinition.getCreatedOn()); service.put(colDef[3].getId(), approvalDefinition.getModifierLogin()); service.put(colDef[4].getId(), approvalDefinition.getModifiedOn()); if (chidlColDef != null) { ArrayList<Integer> approversIds = approvalDefinition.getApproverIds(); if (approversIds != null && approversIds.size() > 0) { service.put(colDef[5].getId(), approversIds.size()); ServiceContainerImpl serviceContainer1 = new ServiceContainerImpl(); for (Integer approverId : approversIds) { UserDetails userDetails = getRequestDetails().getServerIf().getNmIf() .getUserById(approverId); if (userDetails == null) { continue; } ServiceImpl service1 = new ServiceImpl(); service1.put(chidlColDef[0].getId(), approvalDefinition.getGrpName()); service1.put(chidlColDef[1].getId(), userDetails.getLogin()); String email = userDetails.getEmail(); email = email == null ? "" : email; service1.put(chidlColDef[2].getId(), email); String phone = userDetails.getPhone(); phone = phone == null ? "" : phone; service1.put(chidlColDef[3].getId(), phone); String pager = userDetails.getPager(); phone = pager == null ? "" : pager; service1.put(chidlColDef[4].getId(), pager); serviceContainer1.addManageServices(service1); } service.put("UserDetails", serviceContainer1); } else { service.put(colDef[5].getId(), 0); } } serviceContainer.addManageServices(service); } } return serviceContainer; } private static String getUserName(int creatorId) { UserDetails userDetails = UsersFactory.getUser(creatorId); if (userDetails != null) { return userDetails.getLogin(); } return null; } /** * policy object sorter class */ private class PolicySorter implements Comparator<Object> { @Override public int compare(Object o1, Object o2) { if (null == o1 || null == o2) { return -1; } String str1 = "", str2 = ""; if (o1 instanceof LWPolicyGroup && o2 instanceof LWPolicyGroup) { str1 = ((LWPolicyGroup) o1).getDisplayName(); str2 = ((LWPolicyGroup) o2).getDisplayName(); } else if (o1 instanceof LWCustomPolicy && o2 instanceof LWCustomPolicy) { str1 = ((LWCustomPolicy) o1).getTitle(); str2 = ((LWCustomPolicy) o2).getTitle(); } else if (o1 instanceof IConfigset && o2 instanceof IConfigset) { str1 = ((IConfigset) o1).getTitle(); str2 = ((IConfigset) o2).getTitle(); } else if (o1 instanceof LWPolicyProfile && o2 instanceof LWPolicyProfile) { str1 = ((LWPolicyProfile) o1).getName(); str2 = ((LWPolicyProfile) o2).getName(); } else if (o1 instanceof LWObjectGroup && o2 instanceof LWObjectGroup) { str1 = ((LWObjectGroup) o1).getGroupName(); str2 = ((LWObjectGroup) o2).getGroupName(); } else if (o1 instanceof Customer && o2 instanceof Customer) { str1 = ((Customer) o1).getCustomerName(); str2 = ((Customer) o2).getCustomerName(); } else { return -1; } return str1.compareTo(str2); } }// end of PolicySorter class // Generic method to get time for different time zone. Parameter need to pass as millisecond public String getTimeBasedOnZone(Long value) { UserSession session = UserSessionManager.getInstance().getCurrentUserSession(); SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); return DateUtils.convertDateFormatByRawOffset(formatter, Integer.valueOf(session.getLoginTimeZoneMin()), value); } }