public void process(Action action, Payload payload, Model model) { switch (action) { case TOPOLOGY_GRAPH_NODE_CONFIG_LIST: model.setGraphConfig(m_topologyConfigManager.getConfig()); break; case TOPOLOGY_GRAPH_NODE_CONFIG_ADD_OR_UPDATE: graphNodeConfigAddOrUpdate(payload, model); model.setProjects(m_globalConfigManager.queryAllProjects()); break; case TOPOLOGY_GRAPH_NODE_CONFIG_ADD_OR_UPDATE_SUBMIT: model.setOpState(graphNodeConfigAddOrUpdateSubmit(payload, model)); model.setGraphConfig(m_topologyConfigManager.getConfig()); break; case TOPOLOGY_GRAPH_NODE_CONFIG_DELETE: model.setOpState(graphNodeConfigDelete(payload)); model.setConfig(m_topologyConfigManager.getConfig()); break; case TOPOLOGY_GRAPH_EDGE_CONFIG_LIST: model.setGraphConfig(m_topologyConfigManager.getConfig()); model.buildEdgeInfo(); break; case TOPOLOGY_GRAPH_EDGE_CONFIG_ADD_OR_UPDATE: graphEdgeConfigAdd(payload, model); model.setProjects(m_globalConfigManager.queryAllProjects()); break; case TOPOLOGY_GRAPH_EDGE_CONFIG_ADD_OR_UPDATE_SUBMIT: model.setOpState(graphEdgeConfigAddOrUpdateSubmit(payload, model)); model.setGraphConfig(m_topologyConfigManager.getConfig()); model.buildEdgeInfo(); break; case TOPOLOGY_GRAPH_EDGE_CONFIG_DELETE: model.setGraphConfig(m_topologyConfigManager.getConfig()); model.setOpState(graphEdgeConfigDelete(payload)); model.buildEdgeInfo(); break; case TOPOLOGY_GRAPH_PRODUCT_LINE: model.setProductLines(m_productLineConfigManger.queryAllProductLines()); model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines()); break; case TOPOLOGY_GRAPH_PRODUCT_LINE_ADD_OR_UPDATE: graphPruductLineAddOrUpdate(payload, model); model.setProjects(m_globalConfigManager.queryAllProjects()); break; case TOPOLOGY_GRAPH_PRODUCT_LINE_DELETE: model.setOpState( m_productLineConfigManger.deleteProductLine( payload.getProductLineName(), payload.getType())); model.setProductLines(m_productLineConfigManger.queryAllProductLines()); model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines()); break; case TOPOLOGY_GRAPH_PRODUCT_LINE_ADD_OR_UPDATE_SUBMIT: Pair<Boolean, String> addProductlineResult = graphProductLineConfigAddOrUpdateSubmit(payload, model); String duplicateDomains = addProductlineResult.getValue(); model.setOpState(addProductlineResult.getKey()); if (!StringUtils.isEmpty(duplicateDomains)) { model.setDuplicateDomains(addProductlineResult.getValue()); } model.setProductLines(m_productLineConfigManger.queryAllProductLines()); model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines()); break; case TOPO_GRAPH_FORMAT_CONFIG_UPDATE: String topoGraphFormat = payload.getContent(); if (!StringUtils.isEmpty(topoGraphFormat)) { model.setOpState(m_formatConfigManager.insert(topoGraphFormat)); } model.setContent(m_formatConfigManager.getConfig().toString()); break; default: throw new RuntimeException("Error action name " + action.getName()); } }
public void process(Action action, Payload payload, Model model) { int id; switch (action) { case APP_NAME_CHECK: if (m_appConfigManager.isNameDuplicate(payload.getName())) { model.setNameUniqueResult("{\"isNameUnique\" : false}"); } else { model.setNameUniqueResult("{\"isNameUnique\" : true}"); } break; case APP_LIST: buildListInfo(model, payload); break; case APP_COMMMAND_UPDATE: id = payload.getId(); if (m_appConfigManager.containCommand(id)) { Command command = m_appConfigManager.getConfig().findCommand(id); if (command == null) { command = new Command(); } model.setUpdateCommand(command); } break; case APP_COMMAND_SUBMIT: id = payload.getId(); String domain = payload.getDomain(); String name = payload.getName(); String title = payload.getTitle(); boolean all = payload.isAll(); int timeThreshold = payload.getThreshold(); if (m_appConfigManager.containCommand(id)) { Command command = new Command(); command .setDomain(domain) .setName(name) .setTitle(title) .setAll(all) .setThreshold(timeThreshold); if (m_appConfigManager.updateCommand(id, command)) { model.setOpState(true); } else { model.setOpState(false); } } else { try { Command command = new Command() .setDomain(domain) .setTitle(title) .setName(name) .setAll(all) .setThreshold(timeThreshold); if (m_appConfigManager.addCommand(command).getKey()) { model.setOpState(true); } else { model.setOpState(false); } } catch (Exception e) { model.setOpState(false); } } buildListInfo(model, payload); break; case APP_COMMAND_DELETE: id = payload.getId(); if (m_appConfigManager.deleteCommand(id)) { model.setOpState(true); } else { model.setOpState(false); } buildListInfo(model, payload); break; case APP_CODE_UPDATE: id = payload.getId(); int codeId = payload.getCode(); if (payload.isConstant()) { Code code = m_appConfigManager.getConfig().getCodes().get(codeId); model.setCode(code); } else { Command cmd = m_appConfigManager.getRawCommands().get(id); if (cmd != null) { Code code = cmd.getCodes().get(codeId); model.setCode(code); model.setUpdateCommand(cmd); } } break; case APP_CODE_SUBMIT: try { id = payload.getId(); String codeStr = payload.getContent(); List<String> strs = Splitters.by(":").split(codeStr); codeId = Integer.parseInt(strs.get(0)); name = strs.get(1); int status = Integer.parseInt(strs.get(2)); Code code = new Code(codeId); code.setName(name).setStatus(status); if (payload.isConstant()) { m_appConfigManager.updateCode(code); } else { m_appConfigManager.updateCode(id, code); } buildListInfo(model, payload); } catch (Exception e) { Cat.logError(e); } break; case APP_CODE_ADD: id = payload.getId(); model.setId(String.valueOf(id)); break; case APP_CODE_DELETE: try { id = payload.getId(); codeId = payload.getCode(); if (payload.isConstant()) { m_appConfigManager.getCodes().remove(codeId); } else { m_appConfigManager.deleteCode(id, codeId); } buildListInfo(model, payload); } catch (Exception e) { Cat.logError(e); } break; case APP_SPEED_UPDATE: case APP_SPEED_ADD: id = payload.getId(); Speed speed = m_appSpeedConfigManager.getConfig().getSpeeds().get(id); if (speed != null) { model.setSpeed(speed); } break; case APP_SPEED_DELETE: try { id = payload.getId(); m_appSpeedConfigManager.deleteSpeed(id); buildListInfo(model, payload); } catch (Exception e) { Cat.logError(e); } break; case APP_SPEED_SUBMIT: try { id = payload.getId(); String speedStr = payload.getContent(); List<String> strs = Splitters.by(":").split(speedStr); String page = strs.get(0).trim(); int step = Integer.parseInt(strs.get(1).trim()); title = strs.get(2).trim(); int threshold = Integer.parseInt(strs.get(3).trim()); int speedId = id > 0 ? id : m_appSpeedConfigManager.generateId(); speed = new Speed(speedId); speed.setPage(page).setStep(step).setTitle(title).setThreshold(threshold); m_appSpeedConfigManager.updateConfig(speed); buildListInfo(model, payload); } catch (Exception e) { Cat.logError(e); } break; case APP_CONFIG_UPDATE: String appConfig = payload.getContent(); if (!StringUtils.isEmpty(appConfig)) { model.setOpState(m_appConfigManager.insert(appConfig)); } model.setContent(m_appConfigManager.getConfig().toString()); break; case APP_RULE: buildAppConfigInfo(m_appConfigManager, model); model.setRules(m_appRuleConfigManager.getMonitorRules().getRules().values()); break; case APP_RULE_ADD_OR_UPDATE: buildAppConfigInfo(m_appConfigManager, model); generateRuleConfigContent(payload.getRuleId(), m_appRuleConfigManager, model); break; case APP_RULE_ADD_OR_UPDATE_SUBMIT: buildAppConfigInfo(m_appConfigManager, model); model.setOpState( addSubmitRule(m_appRuleConfigManager, payload.getRuleId(), "", payload.getConfigs())); model.setRules(m_appRuleConfigManager.getMonitorRules().getRules().values()); break; case APP_RULE_DELETE: buildAppConfigInfo(m_appConfigManager, model); model.setOpState(deleteRule(m_appRuleConfigManager, payload.getRuleId())); model.setRules(m_appRuleConfigManager.getMonitorRules().getRules().values()); break; case APP_COMPARISON_CONFIG_UPDATE: String appComparisonConfig = payload.getContent(); if (!StringUtils.isEmpty(appComparisonConfig)) { model.setOpState(m_appComparisonConfigManager.insert(appComparisonConfig)); } model.setContent(m_appComparisonConfigManager.getConfig().toString()); break; case APP_RULE_BATCH_UPDATE: appRuleBatchUpdate(payload, model); buildListInfo(model, payload); break; case APP_CONSTANT_ADD: break; case APP_CONSTANT_UPDATE: Item item = m_appConfigManager.queryItem(payload.getType(), payload.getId()); model.setAppItem(item); break; case APP_CONSTATN_SUBMIT: try { id = payload.getId(); String content = payload.getContent(); String[] strs = content.split(":"); String type = strs[0]; int constantId = Integer.valueOf(strs[1]); String value = strs[2]; model.setOpState(m_appConfigManager.addConstant(type, constantId, value)); buildListInfo(model, payload); } catch (Exception e) { Cat.logError(e); } break; case APP_COMMAND_FORMAT_CONFIG: String content = payload.getContent(); if (StringUtils.isNotEmpty(content)) { m_urlConfigManager.insert(content); } model.setContent(m_urlConfigManager.getUrlFormat().toString()); break; default: throw new RuntimeException("Error action name " + action.getName()); } }