Java tutorial
package com.castis.xylophone.adsmadapter.convert.axistree; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.transaction.annotation.Transactional; import com.castis.tambourine.bizobject.common.Period; import com.castis.tambourine.bizobject.ktadsm.ADSMJobNameType; import com.castis.tambourine.bizobject.ktadsm.ADSMSchedulerStatus; import com.castis.tambourine.bizobject.ktadsm.ClientUIData; import com.castis.tambourine.define.Constants; import com.castis.tambourine.dto.inventory.NodeDTO; import com.castis.tambourine.dto.ktadsm.ADSMSchedulerLogDTO; import com.castis.tambourine.dto.ktadsm.FeSyncNoticeboardDTO; import com.castis.tambourine.enumeration.ClientUIType; import com.castis.tambourine.enumeration.FeSyncNoticeboardStatus; import com.castis.tambourine.enumeration.Platform; import com.castis.tambourine.enumeration.SyncDataType; import com.castis.tambourine.enumeration.TreeType; import com.castis.tambourine.logger.TheLogger; import com.castis.tambourine.util.DateUtil; import com.castis.xylophone.adsmadapter.common.exception.CiRuntimeException; import com.castis.xylophone.adsmadapter.filePolling.FilePolling; public class ConvertMenuAxisTreeDTO extends ConvertTreeDTO { static final Log log = LogFactory.getLog(ConvertMenuAxisTreeDTO.class); static final String name = "ConvertMenuAxisTreeDTO"; static final String ROOT_NODE_NAME = "root_menu"; public static final String ROOT_MENU_PARENT = "*"; public static final String CATEGORY_AXIS_TREE_PARTIAL_UPDATE = "CATEGORY_AXIS_TREE_PARTIAL_UPDATE"; public ConvertMenuAxisTreeDTO() { log.info(" ### " + name + " was started."); } public void close() { log.info(" # " + name + " is shutting down."); } private NodeDTO convertClientUIData2Node(ClientUIData clientUIData, int level) { NodeDTO nodeDTO = new NodeDTO(); nodeDTO.setLevel(level); nodeDTO.setName(clientUIData.getClientUIName()); nodeDTO.setReflected(false); nodeDTO.setMappingId(clientUIData.getClientUIId()); nodeDTO.setExternalNodeId(clientUIData.getClientUIId()); nodeDTO.setUseLicensingWindow(true); return nodeDTO; } private void makeTreeNode(int treeID, Date date, String externalNodeId) throws Exception { int level = 0; // ? license tambourineConnector.invalidateAxisTreeNodeExceptRootNode(treeID, date); //node merge mergeNodePointOfEntry(treeID, externalNodeId, level, date); tambourineConnector.saveClosureNodes(treeID); } private void mergeNodePointOfEntry(int treeID, String parentId, int level, Date date) throws Exception { try { mergeNode(treeID, parentId, level, date); } finally { // leak? . tambourineConnector.mergeNodeAfterMemoryClear(); } } private void mergeNode(int treeID, String parentId, int level, Date date) throws Exception { try { List<ClientUIData> ClientUIDataList = tambourineConnector.getClientUIDataByParentId(ClientUIType.MENU, parentId); for (ClientUIData clientUIData : ClientUIDataList) { NodeDTO nodeDTO = convertClientUIData2Node(clientUIData, level); nodeDTO.setLicensingPeriod(new Period(date, DateUtil.string2Date("9999-12-31"))); tambourineConnector.mergeNodeUsingMemory(treeID, parentId, nodeDTO); mergeNode(treeID, nodeDTO.getExternalNodeId(), level + 1, date); } } catch (Exception e) { throw e; } } private NodeDTO getRootNode() { List<ClientUIData> rootClientUIDataList = tambourineConnector.getClientUIDataByType(ClientUIType.ROOT); if (rootClientUIDataList != null && rootClientUIDataList.isEmpty() == false) return convertClientUIData2Node(rootClientUIDataList.get(0), 0); return null; } @Transactional(rollbackFor = Exception.class) public int convertMenuTree(Date date, ADSMSchedulerLogDTO schedulerLog, ADSMJobNameType srcJopType, String treeName, String publisher, Platform platformType) throws Exception { if (schedulerLog == null) { throw new CiRuntimeException("ADSMSchedulerLog is null"); } if (treeName == null || treeName.isEmpty()) { throw new CiRuntimeException("Cannot find treeName in generating MenuTree"); } long start = System.currentTimeMillis(); log.info("TreeName : " + treeName + ", srcDataType : " + srcJopType + ". Start Update(" + schedulerLog.getParam() + ")"); int treeID = 0; try { //?, , , ? //tambourineConnector.initializeInventoryCube(date); NodeDTO rootNodeDTO = getRootNode(); if (rootNodeDTO == null) { throw new CiRuntimeException( "Fail to Update Menu Tree (Cannot Check root node Info. " + schedulerLog.getParam() + ")"); } treeID = tambourineConnector.getAxisTreeId(TreeType.MENU_AXIS_TREE, treeName, publisher, platformType, false); //? if (treeID <= 0) treeID = tambourineConnector.registerAxisTree(getAxisTreeDTO(Constants.tree.MENU_TREE_NAME, rootNodeDTO, false, treeID, publisher, platformType), date, TreeType.MENU_AXIS_TREE); makeTreeNode(treeID, date, rootNodeDTO.getExternalNodeId()); insertTreeLogNSyncNoticeboard(null, treeID, treeName, platformType); // ? schedulerLog.setSchedulerStatus(ADSMSchedulerStatus.SUCCESS); schedulerLog.setMessage(TREE_NAME_MESSAGE_PREFIX + treeName); } catch (Exception e) { long end = System.currentTimeMillis(); TheLogger.getWriter().error("Fail to Update Menu Tree"); log.error("Fail to update Menu Tree.(" + schedulerLog.getParam() + ") - T(" + (end - start) + ")"); schedulerLog.setMessage(e.getMessage()); schedulerLog.setSchedulerStatus(ADSMSchedulerStatus.FAIL); StackTraceElement[] stackTraces = e.getStackTrace(); if (stackTraces.length > 0) { schedulerLog.setFailProcess(stackTraces[0].getClassName() + " - " + stackTraces[0].getMethodName() + "(" + stackTraces[0].getLineNumber() + ")"); } throw e; } long end = System.currentTimeMillis(); log.info("Complete to Update Menu Tree (" + schedulerLog.getParam() + ") - T(" + (end - start) + ")"); TheLogger.getWriter().info("Complete to Update Menu Tree(" + schedulerLog.getParam() + ")"); return treeID; } public void insertTreeLogNSyncNoticeboard(String publisher, int treeID, String treeName, Platform platformType) { Date nowDate = new Date(); String param = "treeId:" + treeID + "/treeType:" + TreeType.MENU_AXIS_TREE.toString() + "/treeName:" + treeName; FeSyncNoticeboardDTO feSyncNoticeboardDTO = tambourineConnector.generateFeSyncNoticeboardData( SyncDataType.TREEDATA, nowDate, param, publisher, FeSyncNoticeboardStatus.NEWDATA, platformType, null, null); // syncNoticeboard? ? tambourineConnector.insertTreeLogNSyncNoticeboard(treeID, TreeType.MENU_AXIS_TREE, treeName, feSyncNoticeboardDTO, publisher, platformType); } public List<DatInfomation> getNewSchedulerLogParam(ADSMJobNameType srcJobType, String defaultTreeName) { Map<ADSMSchedulerLogDTO, String/*treeName*/> schedulerLogMap = tambourineConnector .getNewSchedulerLogByTreeName(srcJobType, defaultTreeName); if (schedulerLogMap == null || schedulerLogMap.isEmpty()) { return null; } List<DatInfomation> datInfomationList = new ArrayList<DatInfomation>(); for (Map.Entry<ADSMSchedulerLogDTO, String> entry : schedulerLogMap.entrySet()) { ADSMSchedulerLogDTO dataLog = entry.getKey(); String treeName = entry.getValue(); int dataLogId = dataLog.getId(); String message = dataLog.getMessage(); String datStartTime = (String) dataLog.getParamValue(FilePolling.PARAM_START_TIME_PREFIX); String publisher = (String) dataLog.getParamValue(FilePolling.PARAM_SITE_PREFIX); String platformType = (String) dataLog.getParamValue(FilePolling.PARAM_PLATFORM_PREFIX); String extendParameter = ""; if (datStartTime != null && publisher != null) extendParameter = "/" + FilePolling.PARAM_TREE_NAME + ":" + treeName + "/" + FilePolling.PARAM_START_TIME_PREFIX + ":" + datStartTime + "/" + FilePolling.PARAM_SITE_PREFIX + ":" + publisher + "/" + FilePolling.PARAM_PLATFORM_PREFIX + ":" + platformType; String schedulerLogParam = "dataLogId:" + dataLogId;// + extendParameter; ADSMSchedulerLogDTO treeLog = null; treeLog = tambourineConnector.getLatestADSMSchedulerLog(TreeType.MENU_AXIS_TREE.name(), message, schedulerLogParam); if (treeLog != null) continue; else datInfomationList.add(new DatInfomation(treeName, schedulerLogParam + extendParameter, false, publisher, platformType)); } return datInfomationList; } }