public String checkExtractName() throws Exception { HttpServletRequest request = Struts2Utils.getRequest(); HttpServletResponse response = Struts2Utils.getResponse(); String taskName = getQueryParameter(request, "extractName"); String act = this.getQueryParameter(request, "act"); StringBuffer result = new StringBuffer(); if (null == taskName) { result.append("{success:false,desc:'请输入任务名称!'}"); } else { if (taskName.length() > 100) { result.append("{success:false,desc:'任务名称超过100个字符,请重新命名!'}"); } else { if (HTMLFilter.isChineseEnglishNumber(taskName)) { // 新建、拷贝情况,只要分群名字存在,需要充命名 if ("new".equalsIgnoreCase(act) || "copy".equalsIgnoreCase(act) || null == act) { if (extractTaskService.isTaskNameUnique(taskName)) { result.append("{success:true,desc:'任务名称可用!'}"); } else { result.append("{success:false,desc:'任务名称已经存在,请重新命名!'}"); } } } else { result.append("{success:false,desc:'只能输入汉字、数字、字母,字符之间不能空格,请重新输入!'}"); } } } return writerMessageToClient(response, result.toString()); }
@Override public void run(Definition definition) throws IOException { String fileSep = System.getProperty("file.separator"); String htmlIncludePath = KPaths.getKBase(false) + fileSep + "include" + fileSep + "html" + fileSep; HTMLFilter htmlFilter = new HTMLFilter(htmlIncludePath, context); definition.accept(htmlFilter); String html = htmlFilter.getHTML(); String output = KompileFrontEnd.output; if (output == null) { output = "./" + FileUtil.stripExtension(new File(definition.getMainFile()).getName()) + ".html"; } output = new File(output).getAbsolutePath(); FileUtil.saveInFile(output, html); if (GlobalSettings.verbose) { sw.printIntermediate("Generating HTML"); } }
public static void main(String[] args) throws Exception { EntityManagerFactory emf = Persistence.createEntityManagerFactory("DownloadContraArticlesJPA"); em = emf.createEntityManager(); SimpleDateFormat dtf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String outfolder = "import-stories-arch-1"; opt = new XmlOptions(); opt.setUseCDataBookmarks(); opt.setSaveCDataLengthThreshold(0); opt.setSaveCDataEntityCountThreshold(-1); int i = 0; int maxResults = 1000; competitions = em.createQuery(" SELECT c FROM Competition c ").getResultList(); sports = em.createQuery(" SELECT c FROM Sport c ").getResultList(); Query q = em.createQuery(queryString).setFirstResult(i * maxResults).setMaxResults(maxResults); List<Articles_Archives100_130000> results = q.getResultList(); while (!results.isEmpty()) { EscenicDocument escenicDocument = EscenicDocument.Factory.newInstance(opt); initializeEscenic(escenicDocument); for (Articles_Archives100_130000 article : results) { Content content = escenicDocument.getEscenic().addNewContent(); content.addNewSource().setStringValue("ContraNews"); content.addNewSourceid().setStringValue(Integer.toString(article.getArticleID())); content.addNewType().setStringValue("news"); content.setState(State.PUBLISHED); content.addNewPublishdate().setStringValue(dtf.format(article.getArticleDate())); content.addNewCreationdate().setStringValue(dtf.format(article.getArticleDate())); SectionRef sectionRef = content.addNewSectionRef(); try { if (article.getCompetition().getCompetitionID() != 0) { sectionRef .addNewUniqueName() .setStringValue(article.getCompetition().getCompetitionName_url()); } else if (article.getCompetition().getCompetitionID() == 0 && article.getPlace().getPlaceID() != 0 && article.getSport().getSportID() != 0 && existCompetition(article.getSport(), article.getPlace())) { sectionRef .addNewUniqueName() .setStringValue( article.getPlace().getPlaceName_url() + "_" + article.getSport().getSportName_url()); } else if (article.getSport().getSportID() != 0) { sectionRef.addNewUniqueName().setStringValue(article.getSport().getSportName_url()); } else { sectionRef.addNewUniqueName().setStringValue("ece_incoming"); } } catch (Exception e) { System.out.println("No section found for article" + article.getArticleID()); throw new Exception(e.getMessage()); } if (article.getSubSection().getSubSectionID() != 1) { sectionRef = content.addNewSectionRef(); sectionRef .addNewUniqueName() .setStringValue(article.getSubSection().getSubSectionName_url()); } sectionRef.setHomeSection(true); // List<Image> images = em.createQuery(" SELECT i FROM Image i WHERE i.articleId = " + // article.getId()).getResultList(); // // for (Image image : images) { // // picture relation // if(article.getArticlePhoto() !=null && !article.getArticlePhoto().trim().isEmpty()){ // String fullPath = "/home/vassilis/Pictures/contra/"+article.getArticlePhoto().trim(); // // //check if file // if(new File(fullPath).exists()){ // Relation relation = content.addNewRelation(); // relation.addNewType().setStringValue("PICTUREREL"); // relation.addNewSource().setStringValue("ContraImages"); // relation.addNewSourceid().setStringValue(article.getArticlePhoto().trim()); // } // } if (article.getLinks() != null) { for (String articleId : article.getLinks().split(",")) { articleId = articleId.trim(); if (articleId.isEmpty()) continue; if (articleId.startsWith("ph")) { // try { // em.createQuery("SELECT p.photoStoryID FROM PhotoStory p WHERE p.photoStoryID // = :thePhotoStoryID ") // .setParameter("thePhotoStoryID", // Integer.valueOf(articleId.toLowerCase().replaceAll("ph", ""))) // .getSingleResult(); // Relation relationStory = content.addNewRelation(); // relationStory.addNewType().setStringValue("PHOTOSTORYREL"); // relationStory.addNewSource().setStringValue("ContraPhotostory"); // relationStory.addNewSourceid().setStringValue(articleId.replaceAll("ph", // "")); // } catch (Exception e) { // e.printStackTrace(); // System.out.println("No PhotoStory found with id " + // articleId.replaceAll("ph", "")); // } } else if (!articleId.matches("[0-9]*")) { continue; } else { Relation relationStory = content.addNewRelation(); relationStory.addNewType().setStringValue("STORYREL"); relationStory.addNewSource().setStringValue("ContraNews"); relationStory.addNewSourceid().setStringValue(articleId); } } } if (article.getTeam1() != null && article.getTeam1().getTeamID() > 0 && article.getTeam1().getTeamName_url() != null) { Relation relationTag = content.addNewRelation(); relationTag.addNewType().setStringValue("TAGREL"); relationTag.addNewSource().setStringValue("ContraTags"); relationTag .addNewSourceid() .setStringValue(Integer.toString(article.getTeam1().getTeamID())); } if (article.getTeam2() != null && article.getTeam2().getTeamID() > 0 && article.getTeam2().getTeamName_url() != null) { Relation relationTag = content.addNewRelation(); relationTag.addNewType().setStringValue("TAGREL"); relationTag.addNewSource().setStringValue("ContraTags"); relationTag .addNewSourceid() .setStringValue(Integer.toString(article.getTeam2().getTeamID())); } // Field titlePictureField = relation.addNewField(); // titlePictureField.addNewName().setStringValue("title"); // titlePictureField.newCursor().setTextValue(image.getCaption()); // // Field captionTitlePictureField = relation.addNewField(); // captionTitlePictureField.addNewName().setStringValue("captiontitle"); // Field captionPictureField = relation.addNewField(); // captionPictureField.addNewName().setStringValue("caption"); // captionPictureField.newCursor().setTextValue(image.getCaption()); // } Priority priority = content.addNewPriority(); priority.setValue(0); Field titleField = content.addNewField(); titleField.addNewName().setStringValue("title"); titleField.newCursor().setTextValue(article.getArticleTitle()); //// Field superTitleField = content.addNewField(); //// superTitleField.addNewName().setStringValue("supertitle"); //// superTitleField.newCursor().setTextValue(article.getTitle()); // Field leadtextField = content.addNewField(); leadtextField.addNewName().setStringValue("leadtext"); leadtextField .newCursor() .setTextValue( article.getArticleSummary() == null ? "" : article.getArticleSummary().replaceAll("\\<.*?\\>", "")); // Field quoteField = content.addNewField(); // quoteField.addNewName().setStringValue("quote"); if (article.getArticleBody() != null && !article.getArticleBody().trim().isEmpty()) { Field bodyField = content.addNewField(); bodyField.addNewName().setStringValue("body"); // //body XmlCursor bodyCursor = bodyField.newCursor(); bodyCursor.xmlText(opt); String fixedBody = article.getArticleBody().trim(); fixedBody = HTMLFilter.fixHtml(fixedBody); bodyCursor.setTextValue(fixedBody); } // Field bylineField = content.addNewField(); bylineField.addNewName().setStringValue("byline"); bylineField .newCursor() .setTextValue( article.getArticleAuthor() == null ? "" : article.getArticleAuthor().trim()); String tagFieldString = ""; if (article.getTeam1() != null && article.getTeam1().getTeamID() > 0 && article.getTeam1().getTeamName_url() != null) { tagFieldString = "tagppo" + article.getTeam1().getTeamName_url().toLowerCase(); } if (article.getTeam2() != null && article.getTeam2().getTeamID() > 0 && article.getTeam2().getTeamName_url() != null) { tagFieldString = tagFieldString + " tagppo" + article.getTeam2().getTeamName_url().toLowerCase(); } if (!tagFieldString.isEmpty()) { Field tagField = content.addNewField(); tagField.addNewName().setStringValue("tag"); tagField.newCursor().setTextValue(tagFieldString); } // // // if(article.getTeam1()!=null && article.getTeam1().getTeamID()!=0){ // Tag tag = content.addNewTag(); // tag.newCursor().setTextValue(article.getTeam1().getTeamName_url()); // } // // if(article.getTeam2()!=null && article.getTeam2().getTeamID()!=0){ // Tag tag = content.addNewTag(); // tag.newCursor().setTextValue(article.getTeam2().getTeamName_url()); // } // Field bylineprefixField = content.addNewField(); // bylineprefixField.addNewName().setStringValue("bylineprefix"); // // Field notesField = content.addNewField(); // notesField.addNewName().setStringValue("notes"); // // Field geocodeField = content.addNewField(); // geocodeField.addNewName().setStringValue("com.escenic.geocode"); } String counterString = ""; ++i; if (i < 10) { counterString = "000"; } else if (i < 100) { counterString = "00"; } else if (i < 1000) { counterString = "0"; } else if (i < 10000) { counterString = ""; } counterString = counterString + i; String outFileName = outfolder + "/stories1-arch" + (counterString) + ".xml"; File f = new File(outFileName); escenicDocument.save(f); q = em.createQuery(queryString).setFirstResult(i * maxResults).setMaxResults(maxResults); results = q.getResultList(); } ReplaceCDATA.replace(outfolder); }
public String saveAndSubmit() { HttpServletRequest request = Struts2Utils.getRequest(); HttpSession session = Struts2Utils.getSession(); // 1.新建 act=new 2.修改 act=modify 3.复制 act = copy String act = this.getQueryParameter(request, "act"); // 获取groupId值 String taskId = this.getQueryParameter(request, "taskId"); String taskName = this.getQueryParameter(request, "extractName"); String taskDesc = this.getQueryParameter(request, "extractDesc"); String auditor = this.getQueryParameter(request, "auditor"); String provinceId = this.getQueryParameter(request, "indArea"); ExtractTask extractTask = null; if (StringUtils.isBlank(taskId)) { // 1.新建 act=new //容器中没有就新建 if (StringUtils.isBlank(act)) { // if("new".equalsIgnoreCase(act)){ extractTask = new ExtractTask(); // 设置分群id taskId = UIDGenerator.generate().toString().substring(0, 19) + System.currentTimeMillis(); extractTask.setId(taskId); // 设置客户分群状态 目前能用的状态共7个,分别是: 2 未提交 、4 等待执行、5 执行中、6 执行失败、7 执行完成、8 有数据、9无数据 int taskStatus = 1; // 2 未提交 extractTask.setTaskStatus(taskStatus); extractTask.setTaskName(taskName); extractTask.setTaskDesc(taskDesc); // 群创建人 String createUser = securityManager.loginUser().getLoginName(); // securityManager.getAllRole().get(1). extractTask.setCreateUser(createUser); } else { throw new RuntimeException("无效操作!"); } } System.out.println("taskId=" + taskId); // 分群条件关系 规则表达式 String ruleRelationExp = this.getQueryParameter(request, "ruleRelationExp"); String[] props = request.getParameterValues("attr"); if (StringUtils.isBlank(ruleRelationExp)) { extractTask.setRuleRelationExp(""); } else { extractTask.setRuleRelationExp(ruleRelationExp); ruleRelationExp = ruleRelationExp.replace("and", "+"); } // 提取电话号码上限 String upperLimit = this.getQueryParameter(request, "upperLimit"); // 分群规则数据 String[] ruleArrray = request.getParameterValues("rule"); // 0415-2102 if (HTMLFilter.isIntNumber(upperLimit)) { extractTask.setUpperLimit(Long.parseLong(upperLimit)); } else { extractTask.setUpperLimit(0); } this.saveTaskRuleToContext(extractTask, ruleRelationExp, upperLimit, ruleArrray); /** 是否提取客户属性值 (1:表示是,0:表示否)默认为0 IS_EXTRACT_PROPS */ // if(StringUtils.isBlank(props.toString())){ if (null == props) { /** 是否提取客户属性值 (1:表示是,0:表示否)默认为0 IS_EXTRACT_PROPS */ extractTask.setIsExtractProps("0"); // 0:表示提取客户属性值 extractTask.setExtractProps(null); // 将客户群提取的用户属性置空 } else { extractTask.setIsExtractProps("1"); // 0:表示提取客户属性值 this.saveTaskAttrToContext(extractTask, props); } if (StringUtils.isBlank(act) || "copy".equalsIgnoreCase(act)) { // 任务创建日期 String createDate = DateUtil.getDateTime(Constants.DATE_PATTERN, new Date()); extractTask.setCreateDate(createDate); // 修改日期 String modifyDate = "-"; extractTask.setModifyDate(modifyDate); extractTask.setTaskType("A"); extractTask.setAuditUser(auditor); extractTask.setTaskSql( extractTaskService.getExtractTaskQueryString(extractTask).replace("'", "\"")); extractTask.setProvinceId(provinceId); // 调用service.save方法,持久化数据 try { extractTaskService.saveExtractTask(extractTask); session.setAttribute("status", "1"); } catch (Exception e) { session.setAttribute("status", "0"); } } // 跳转到客户分群列表界面 return CrudActionSupport.RELOAD; }
private ExtractTask saveTaskRuleToContext( ExtractTask extractTask, String ruleRelationExp, String upperLimit, String[] ruleArrray) { // 根据groupId 获取客户分群对象容器类 // CustomGroup customGroup = context.get(groupId); if (StringUtils.isBlank(ruleRelationExp)) { extractTask.setRuleRelationExp(""); } else { extractTask.setRuleRelationExp(ruleRelationExp); } if (HTMLFilter.isIntNumber(upperLimit)) { extractTask.setUpperLimit(Long.parseLong(upperLimit)); } else { extractTask.setUpperLimit(0); } List<String[]> ruleList = new ArrayList<String[]>(); for (int i = 0; i < ruleArrray.length; i++) { // [ruleCoce:120] // [ruleName:PROVINCE_USERINFO_D-LOGON_SOFTCLIENT_CNT] // [operator:<] [leftOperand:sdf][rightOperand: ] String ruleStr = ruleArrray[i]; int beginIndex = ruleStr.indexOf("{"); int endIndex = ruleStr.lastIndexOf("}"); String[] jsonRuleArray = ruleStr.substring(beginIndex + 1, endIndex).split("',"); ruleList.add(jsonRuleArray); } List<TaskRule> taskRuleList = new ArrayList<TaskRule>(); // 客户群规则 TaskRule taskRule = null; for (int i = 0; i < ruleList.size(); i++) { String[] rules = ruleList.get(i); taskRule = new TaskRule(); taskRule.setId(UIDGenerator.generate().toString()); taskRule.setExtractTask(extractTask); for (int j = 0; j < rules.length; j++) { String[] rule = rules[j].split(":'"); // ruleCode:'3265 String key = rule[0].replaceAll("\"", "").replaceAll("'", ""); String value = checkValue(rule); if ("ruleCode".equals(key)) { taskRule.setRuleCode(value); } if ("ruleName".equals(key)) { taskRule.setRuleName(value); } if ("operator".equals(key)) { taskRule.setOperator(value); } if ("leftOperand".equals(key)) { taskRule.setLeftOperand(value); } if ("rightOperand".equals(key)) { taskRule.setRightOperand(value); } if ("startDate".equals(key)) { taskRule.setStartDate(value.replaceAll("-", "")); } if ("endDate".equals(key)) { taskRule.setEndDate(value.replaceAll("-", "")); } if ("tableId".equals(key)) { taskRule.setTableId(value); } if ("clusterOpt".equals(key)) { taskRule.setClusterOperator(value); } if ("customTable".equals(key)) { // 存的是table的id CustomTable obj = new CustomTable(); obj.setId(value); taskRule.setCustomTable(obj); } if ("ruleDesc".equals(key)) { taskRule.setRuleDesc(value); } // logger.info("key = " + key + " value = " + value); System.out.println("key = " + key + " value = " + value); System.out.println("raskRule = " + taskRule); } CustomTable customTable = extractTableService.queryCustomTableAndField( taskRule.getCustomTable().getId(), taskRule.getRuleName()); taskRule.setCustomTable(customTable); taskRuleList.add(taskRule); } extractTask.setTaskRules(taskRuleList); System.out.println("over json"); // context.put(customGroup);将对象放入容器中 return extractTask; }
@Override String processURL(String s) throws CommentException { return HTMLFilter.sanitizeURI(HTMLFilter.stripQuotes(s), null, null, cb, true); }
@Override void throwError(String s) throws DataFilterException { HTMLFilter.throwFilterException(s); }