public void executeNotifyFlow(Notifiable target) { if (target == null) { throw new RuntimeException("Cannot execute flow on null target"); } EngineFlow ef = workspace.getFlow(target.getNotifyFlowName()); if (ef == null) { return; } Set users = new HashSet(); for (Iterator itor = ef.execute(target).iterator(); itor.hasNext(); ) { RuleConsequence rc = (RuleConsequence) itor.next(); User notifier = rc.getUser(); if (!users.contains(notifier)) { /* * 重新load User, 个人信息可能已经修改 */ notifier = userManager.getUser(notifier.getId()); if (EnabledDisabled.ENABLED.equals(notifier.getEnabled())) { Map context = target.getNotifyEmailContext(); context.put("user", notifier); context.put("role", EmailManager.EMAIL_ROLE_NOTIFIER); emailManager.insertEmail( target.getLogSite(), notifier.getEmail(), target.getNotifyEmailTemplateName(), context); } users.add(notifier); } } }
/* * (non-Javadoc) * * @see com.aof.service.business.rule.FlowManager#getSiteEnabledFlow(java.lang.Integer, * com.aof.model.metadata.RuleType) */ public Flow getSiteEnabledFlow(Integer siteId, RuleType type) { Map conditions = new HashMap(); conditions.put(FlowQueryCondition.ENABLED_EQ, EnabledDisabled.ENABLED.getEnumCode()); conditions.put(FlowQueryCondition.SITE_ID_EQ, siteId); conditions.put(FlowQueryCondition.TYPE_EQ, type.getEnumCode()); List l = getFlowList(conditions, 0, 1, null, false); if (l.size() > 0) return (Flow) l.get(0); return null; }
/* * (non-Javadoc) * * @see com.aof.service.business.rule.FlowManager#removeFlow(java.lang.Integer) */ public void removeFlow(Integer id) { Flow f = getFlow(id, true); for (Iterator itor = f.getRules().iterator(); itor.hasNext(); ) { dao.removeFlowRule((FlowRule) itor.next()); } dao.removeFlow(id); if (EnabledDisabled.ENABLED.equals(f.getEnabled())) { Site s = f.getSite(); RuleType rt = f.getType(); workspace.removeFlow(s.getId() + rt.getPrefixUrl()); } }
public void importFromTextFile(Site site, String localFileName) throws Exception { Map customerMap = new HashMap(); for (Iterator itor = dao.getCustomerList(site).iterator(); itor.hasNext(); ) { Customer customer = (Customer) itor.next(); customerMap.put(customer.getCode(), customer); } BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(localFileName), FILE_ENCODE)); String line; try { while ((line = reader.readLine()) != null) { if (line.length() < LINE_LENGTH) continue; String code = getCode(line); boolean insert = false; Customer customer = (Customer) customerMap.remove(code); if (customer == null) { insert = true; customer = new Customer(); customer.setCode(code); } customer.setSite(site); customer.setDescription(getDesc(line)); customer.setType(getType(line)); customer.setEnabled(getEnable(line)); dao.updateCustomer(customer, insert); } for (Iterator itor = customerMap.values().iterator(); itor.hasNext(); ) { Customer customer = (Customer) itor.next(); if (EnabledDisabled.ENABLED.equals(customer.getEnabled())) { customer.setEnabled(EnabledDisabled.DISABLED); dao.updateCustomer(customer, false); } } } finally { reader.close(); } }
/* * (non-Javadoc) * * @see com.aof.service.business.rule.FlowManager#saveFlow(com.aof.model.business.rule.Flow, * java.util.Set) */ public Flow[] saveFlow(Flow f, Set flowRules) { Flow[] result = null; boolean needUpdateWorkspace = false; Flow f2 = getSiteEnabledFlow(f.getSite().getId(), f.getType()); if (f.equals(f2)) { f2.setDescription(f.getDescription()); f2.setEnabled(f.getEnabled()); f = f2; needUpdateWorkspace = true; } else { if (EnabledDisabled.ENABLED.equals(f.getEnabled())) { if (f2 != null) { result = new Flow[2]; f2.setEnabled(EnabledDisabled.DISABLED); result[1] = dao.saveFlow(f2); } needUpdateWorkspace = true; } } if (result == null) result = new Flow[1]; result[0] = dao.saveFlow(f); if (flowRules != null) { for (Iterator itor = dao.getRulesForFlow(f.getId()).iterator(); itor.hasNext(); ) { dao.removeFlowRule((FlowRule) itor.next()); } for (Iterator itor = flowRules.iterator(); itor.hasNext(); ) { dao.saveFlowRule((FlowRule) itor.next()); } } if (needUpdateWorkspace) { constructEngineFlow(f.getSite().getId(), f.getType()); } return result; }