/** * Helper method for running yaml workflows using an instance of WorkflowRunner. * * @param yamlFile The workflow yaml file * @param workflow Workflow definition object * @param settings A map of the settings provided as input to the runner * @return json containing the id of this run */ private static ObjectNode runYamlWorkflow( String yamlFile, Workflow workflow, Map<String, Object> settings) { InputStream yamlStream = null; try { yamlStream = loadYamlStream(yamlFile); } catch (Exception e) { throw new RuntimeException("Could not load workflow from yaml file.", e); } ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ByteArrayOutputStream errStream = new ByteArrayOutputStream(); // This instance of runnable will be executed at the end of a workflow run AsyncWorkflowRunnable runnable = new AsyncWorkflowRunnable(); try { // Get jython home and path variables from application.conf and set them in workflow runner // global config String jythonPath = ConfigFactory.defaultApplication().getString("jython.packages"); String jythonHome = ConfigFactory.defaultApplication().getString("jython.home"); Map<String, Object> config = new HashMap<String, Object>(); config.put("jython_home", jythonHome); config.put("jython_path", jythonPath); // Initialize and run the yaml workflow WorkflowRunner runner = new YamlStreamWorkflowRunner().yamlStream(yamlStream).configure(config); runnable.init(workflow, runner, errStream, outStream); runner .apply(settings) .outputStream(new PrintStream(outStream)) .errorStream(new PrintStream(errStream)) .runAsync(runnable); } catch (Exception e) { e.printStackTrace(); // Log exceptions as part of the workflow error log StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); String errorText = writer.toString(); String outputText = new String(outStream.toByteArray()); runnable.error(errorText, outputText); } // The response json contains the workflow run id for later reference ObjectNode response = Json.newObject(); WorkflowRun run = runnable.getWorkflowRun(); response.put("runId", run.id); return response; }
@Transactional(rollbackFor = Exception.class) public GeneralResponse doctorSendReportMessage(Doctor doctor, ReportChatMessage msg) throws Exception { try { User user = userRepo.findOne(msg.receiver.id); ChatParticipantInfo sender = new ChatParticipantInfo(); sender.id = doctor.id; sender.role = 0; sender.name = doctor.name; sender.avatar = doctor.avatar; ChatParticipantInfo receiver = new ChatParticipantInfo(); receiver.id = user.id; receiver.role = 1; receiver.name = user.name; ReportChatMessageResponse response = new ReportChatMessageResponse(); response.category = 3; response.description = msg.description; response.suggestion = msg.suggestion; response.sender = sender; response.receiver = receiver; response.inquiryID = msg.inquiryID; IMScheduler.defaultSender.tell( new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null); InquiryReport report = new InquiryReport(); report.description = msg.description; report.suggestion = msg.suggestion; report.createTime = System.currentTimeMillis(); Inquiry inquiry = inquiryRepo.findOne(msg.inquiryID); inquiry.report = report; inquiry.finished = true; inquiryRepo.save(inquiry); ChatRecord record = new ChatRecord(); record.category = msg.category; record.senderID = doctor.id; record.receiverID = user.id; record.reportID = report.id; record.inquiryID = msg.inquiryID; record.createTime = System.currentTimeMillis(); chatRepo.save(record); return new GeneralResponse(); } catch (Exception e) { Logger.error("Send message failed", e); throw new IMServerException(e.getMessage()); } }
@Transactional(rollbackFor = Exception.class) public GeneralResponse doctorSendReceptMessage(Doctor doctor, BaseChatMessage msg) throws Exception { try { User user = userRepo.findOne(msg.receiver.id); ChatParticipantInfo sender = new ChatParticipantInfo(); sender.id = doctor.id; sender.role = 0; sender.name = doctor.name; sender.avatar = doctor.avatar; ChatParticipantInfo receiver = new ChatParticipantInfo(); receiver.id = user.id; receiver.role = 1; receiver.name = user.name; ReceptChatMessageResponse response = new ReceptChatMessageResponse(); response.sender = sender; response.receiver = receiver; response.category = 2; response.department = doctor.department.name; response.name = doctor.name; response.hospital = doctor.inHospital.name; response.title = doctor.title; response.inquiryID = msg.inquiryID; IMScheduler.defaultSender.tell( new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null); ChatRecord record = new ChatRecord(); record.category = msg.category; record.senderID = doctor.id; record.receiverID = user.id; record.doctorID = doctor.id; record.inquiryID = msg.inquiryID; record.createTime = System.currentTimeMillis(); chatRepo.save(record); return new GeneralResponse(); } catch (Exception e) { Logger.error("Send message failed", e); throw new IMServerException(e.getMessage()); } }
public static void imp(File file) { String result = ""; String profiles = ""; int imported = 0; int missed = 0; if (file != null) { Config config = Config.find("1=1").first(); FileInputStream fileInputStream = null; HSSFWorkbook workbook = null; try { fileInputStream = new FileInputStream(file); workbook = new HSSFWorkbook(fileInputStream); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Profile profile = null; User user = null; String value = ""; Material material = null; SendMessage m = new SendMessage(); for (int x = 0; x < workbook.getNumberOfSheets(); x++) { HSSFSheet worksheet = workbook.getSheetAt(x); HSSFRow row = null; HSSFCell cell = null; DecimalFormat df = new DecimalFormat("#"); df.setMaximumFractionDigits(0); for (int i = 1; i < worksheet.getLastRowNum(); i++) { String unit = "万元"; String business = "0"; try { row = worksheet.getRow(i); if (row.getLastCellNum() < 22) { continue; } cell = row.getCell(0); value = cell.getStringCellValue(); user = User.find("username=?", value).first(); if (user == null) { user = new User(value, getRandomPwd(), ApplicationRole.getByName("user")); user.save(); } profile = Profile.find("user.id=?", user.id).first(); if (profile == null) { profile = new Profile(); profile.user = user; } profile.is_audit = 1; cell = row.getCell(1); value = cell.getStringCellValue(); profile.name = value; cell = row.getCell(2); value = cell.getStringCellValue(); material = Material.find("name=?", value).first(); if (material == null) { material = new Material(); material.name = value; material.save(); } if (!profile.materials.contains(material)) profile.materials.add(material); cell = row.getCell(3); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } cell = row.getCell(4); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } cell = row.getCell(5); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.registration_number = value; cell = row.getCell(6); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { df.setMaximumFractionDigits(2); value = String.valueOf(df.format(cell.getNumericCellValue())); } else { value = cell.getStringCellValue(); } if (value.contains("美元")) { value = value.replace("(美元)", "").trim(); unit = "万美元"; } profile.registration_assets = value; profile.registration_assets_unit = unit; df.setMaximumFractionDigits(0); cell = row.getCell(7); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.registration_address = value; cell = row.getCell(8); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.bank_name = value; cell = row.getCell(9); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.account_name = value; cell = row.getCell(10); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.tfn = value; cell = row.getCell(11); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.factory_name = value; cell = row.getCell(12); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.factory_address = value; cell = row.getCell(13); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(df.format(cell.getNumericCellValue())); } else { value = cell.getStringCellValue(); } profile.first_supply = value.replaceAll("年", ""); cell = row.getCell(14); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.legal_person = value; cell = row.getCell(15); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.contact_name = value; cell = row.getCell(16); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.contact_job = value; cell = row.getCell(17); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(df.format(cell.getNumericCellValue())); } else { value = cell.getStringCellValue(); } profile.contact_phone = value; cell = row.getCell(18); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.sales_name = value; cell = row.getCell(19); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } profile.sales_job = value; cell = row.getCell(20); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(df.format(cell.getNumericCellValue())); } else { value = cell.getStringCellValue(); } profile.sales_phone = value; cell = row.getCell(21); if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } if (value.equals("自营")) { business = "1"; } else if (value.equals("经销")) { business = "2"; } else if (value.equals("挂靠")) { business = "3"; } else { business = "0"; } profile.business_model = business; profile.save(); imported += 1; if (profile.contact_phone != null) { String message = "您的信息已导入,用户名:" + user.username + ",密码:" + user.password + ",请登录比价平台上传资质文件"; if (config.msg_import != null && !"".equals(config.msg_import)) { message = config .msg_import .replace("{username}", user.username) .replace("{passowrd}", user.password); } m.sendSms(profile.contact_phone, message, "0000001"); if (profile.contact_email != null && !"".equals(profile.contact_phone)) { m.sendMail( profile.contact_email, "[" + Messages.get("application.name") + "]信息导入", message); } } } catch (Exception e) { missed += 1; if (!"".equals(profiles)) { profiles += "," + profile.name; } else { profiles += profile.name; } e.printStackTrace(); } } } result = "成功导入" + imported + "条记录,丢失" + missed + "条记录。"; if (!"".equals(profiles)) { result += "丢失导入的供应商为:" + profiles; } } redirect("/admin/profiles?result=" + URLEncoder.encode(result)); }
public static void impSpec(File file) { if (file != null) { List<Specification> specifications = new ArrayList<Specification>(); Specification spec = null; Material material = null; try { FileInputStream fileInputStream = new FileInputStream(file); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheetAt(0); HSSFRow row = null; HSSFCell cell = null; Map<Integer, String> headerMap = new HashMap<Integer, String>(); Prop prop = null; if (worksheet.getLastRowNum() > 0) { row = worksheet.getRow(0); for (int i = 0; i < row.getLastCellNum(); i++) { headerMap.put(Integer.valueOf(i), row.getCell(i).getStringCellValue()); } } for (int i = 1; i < worksheet.getLastRowNum(); i++) { row = worksheet.getRow(i); cell = row.getCell(0); String materialName = cell.getStringCellValue(); cell = row.getCell(1); String specification = cell.getStringCellValue(); cell = row.getCell(2); Double number = cell.getNumericCellValue(); cell = row.getCell(3); String unit = cell.getStringCellValue(); cell = row.getCell(4); String company = cell.getStringCellValue(); cell = row.getCell(5); Date date = cell.getDateCellValue(); cell = row.getCell(6); String description = cell.getStringCellValue(); spec = new Specification(); for (int x = 7; x < row.getLastCellNum(); x++) { cell = row.getCell(x); String value = ""; if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { value = String.valueOf(cell.getNumericCellValue()); } else { value = cell.getStringCellValue(); } prop = new Prop(); prop.name = headerMap.get(x); prop.value = value; prop.save(); spec.properties.add(prop); } spec.name = specification; spec.specification = specification; if (number != null && !"".equals(number)) spec.amount = number; spec.unit = unit; spec.company = company; if (materialName != null && !"".equals(materialName)) { material = Material.find("name=?", materialName.trim()).first(); spec.material = material; } spec.arrival_time = date; spec.description = description; spec.save(); specifications.add(spec); } renderJSON(specifications); } catch (Exception e) { e.printStackTrace(); } } }
public static void upload(String imei, File data) { try { File pbFile = new File( Play.configuration.getProperty("application.uploadDataDirectory"), imei + "_" + new Date().getTime() + ".pb"); Logger.info(pbFile.toString()); data.renameTo(pbFile); byte[] dataFrame = new byte[(int) pbFile.length()]; ; DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(pbFile))); dataInputStream.read(dataFrame); Upload upload = Upload.parseFrom(dataFrame); Phone phone = Phone.find("imei = ?", imei).first(); if (phone == null) badRequest(); for (Upload.Route r : upload.getRouteList()) { if (r.getPointList().size() <= 1) continue; Agency a = Agency.find("gtfsAgencyId = ?", "DEFAULT").first(); Route route = new Route("", r.getRouteName(), RouteType.BUS, r.getRouteDescription(), a); route.phone = phone; route.routeNotes = r.getRouteNotes(); route.vehicleCapacity = r.getVehicleCapacity(); route.vehicleType = r.getVehicleType(); route.captureTime = new Date(r.getStartTime()); route.save(); List<String> points = new ArrayList<String>(); Integer pointSequence = 1; for (Upload.Route.Point p : r.getPointList()) { points.add(new Double(p.getLon()).toString() + " " + new Double(p.getLat()).toString()); RoutePoint.addRoutePoint(p, route.id, pointSequence); pointSequence++; } String linestring = "LINESTRING(" + StringUtils.join(points, ", ") + ")"; BigInteger tripShapeId = TripShape.nativeInsert(TripShape.em(), "", linestring, 0.0); TripPattern tp = new TripPattern(); tp.route = route; tp.headsign = r.getRouteName(); tp.shape = TripShape.findById(tripShapeId.longValue()); tp.save(); Integer sequenceId = 0; for (Upload.Route.Stop s : r.getStopList()) { BigInteger stopId = Stop.nativeInsert(Stop.em(), s); TripPatternStop tps = new TripPatternStop(); tps.stop = Stop.findById(stopId.longValue()); tps.stopSequence = sequenceId; tps.defaultTravelTime = s.getArrivalTimeoffset(); tps.defaultDwellTime = s.getDepartureTimeoffset() - s.getArrivalTimeoffset(); tps.pattern = tp; tps.board = s.getBoard(); tps.alight = s.getAlight(); tps.save(); sequenceId++; } // ProcessGisExport gisExport = new ProcessGisExport(tp.id); // gisExport.doJob(); } Logger.info("Routes uploaded: " + upload.getRouteList().size()); dataInputStream.close(); ok(); } catch (Exception e) { e.printStackTrace(); badRequest(); } }
@Transactional(rollbackFor = Exception.class) public GeneralResponse doctorSendNormalChat( Doctor doctor, NormalChatMessage msg, Http.MultipartFormData body) throws Exception { User user = userRepo.findOne(msg.receiver.id); String chatFileStore = Play.application().path() + "/store/chats"; if (user != null) { try { ChatParticipantInfo sender = new ChatParticipantInfo(); sender.id = doctor.id; sender.role = 0; sender.name = doctor.name; sender.avatar = doctor.avatar; ChatParticipantInfo receiver = new ChatParticipantInfo(); receiver.id = user.id; receiver.role = 1; receiver.name = user.name; String fileDirPath = ""; String id = MD5Generator.getMd5Value( UUIDGenerator.getUUID() + "doctor" + doctor.id + "user" + user.id); fileDirPath = chatFileStore + "/" + id; File filesDir = null; switch (msg.subCategory) { case 1: if (msg.content == null || msg.content.isEmpty()) { return new GeneralResponse(53, "Can't send empty content"); } else { NormalChatMessageResponse response = new NormalChatMessageResponse(); response.category = 1; response.sender = sender; response.receiver = receiver; response.subCategory = msg.subCategory; response.content = msg.content; response.inquiryID = msg.inquiryID; IMScheduler.defaultSender.tell( new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null); ChatRecord record = new ChatRecord(); record.category = msg.category; record.content = msg.content; record.subCategory = msg.subCategory; record.senderID = doctor.id; record.receiverID = user.id; record.inquiryID = msg.inquiryID; record.createTime = System.currentTimeMillis(); chatRepo.save(record); } break; case 2: filesDir = new File(fileDirPath); if (!filesDir.exists()) { filesDir.mkdirs(); } Http.MultipartFormData.FilePart imgFlPart = body.getFile("file"); if (imgFlPart != null) { NormalChatMessageResponse response = new NormalChatMessageResponse(); response.sender = sender; response.receiver = receiver; response.category = 1; response.subCategory = msg.subCategory; response.inquiryID = msg.inquiryID; String fileName = imgFlPart.getFilename(); String newFlName; if (!fileName.contains(".")) { newFlName = MD5Generator.getMd5Value(fileName + System.currentTimeMillis()); } else { newFlName = MD5Generator.getMd5Value( fileName.substring(0, fileName.lastIndexOf(".")) + System.currentTimeMillis()) + fileName.substring(fileName.lastIndexOf(".")); } FileUtils.moveFile(imgFlPart.getFile(), new File(filesDir, newFlName)); response.content = "/chat/" + id + "/image/" + newFlName; IMScheduler.defaultSender.tell( new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null); ChatRecord record = new ChatRecord(); record.category = msg.category; record.content = response.content; record.subCategory = msg.subCategory; record.senderID = doctor.id; record.receiverID = user.id; record.inquiryID = msg.inquiryID; record.createTime = System.currentTimeMillis(); chatRepo.save(record); } else { return new GeneralResponse(56, "Not has file"); } break; case 3: filesDir = new File(fileDirPath); if (!filesDir.exists()) { filesDir.mkdirs(); } Http.MultipartFormData.FilePart sndFlPart = body.getFile("file"); if (sndFlPart != null) { NormalChatMessageResponse response = new NormalChatMessageResponse(); response.category = 1; response.sender = sender; response.receiver = receiver; response.subCategory = msg.subCategory; response.inquiryID = msg.inquiryID; String fileName = sndFlPart.getFilename(); String newFlName; if (!fileName.contains(".")) { newFlName = MD5Generator.getMd5Value(fileName + System.currentTimeMillis()); } else { newFlName = MD5Generator.getMd5Value( fileName.substring(0, fileName.lastIndexOf(".")) + System.currentTimeMillis()) + fileName.substring(fileName.lastIndexOf(".")); } FileUtils.moveFile(sndFlPart.getFile(), new File(filesDir, newFlName)); response.content = "/chat/" + id + "/audio/" + newFlName; IMScheduler.defaultSender.tell( new IMSenderMessage(user.jid, 1, user.clientID, user.deviceType, response), null); ChatRecord record = new ChatRecord(); record.category = msg.category; record.content = response.content; record.subCategory = msg.subCategory; record.senderID = doctor.id; record.receiverID = user.id; record.inquiryID = msg.inquiryID; record.createTime = System.currentTimeMillis(); chatRepo.save(record); } else { return new GeneralResponse(56, "Not has file"); } break; default: return new GeneralResponse(54, "Not indicate subcategory"); } return new GeneralResponse(); } catch (Exception e) { Logger.error("Send message failed", e); throw new IMServerException(e.getMessage()); } } else { return new GeneralResponse(11, "Please push necessary data"); } }
public static void inviteNewMember( @Required String nom, @Required String prenom, @Required String mail, @Required String langue) { try { String login = normalize(prenom) + '.' + normalize(nom); String url = ""; String signature = ""; String community = "Hypertopic"; // String mailGodfather = ""; String firstNameGodfather = ""; String lastNameGodfather = ""; int flag = -1; if (session.get("username").equals("admin")) { firstNameGodfather = "l'administrateur"; mailGodfather = "Hypertopic Team <*****@*****.**>"; } else { HashMap<String, String> infos = Ldap.getConnectedUserInfos(session.get("username")); mailGodfather = infos.get("mail"); firstNameGodfather = infos.get("firstName"); lastNameGodfather = infos.get("lastName"); firstNameGodfather = firstNameGodfather.substring(0, 1).toUpperCase() + firstNameGodfather.substring(1).toLowerCase(); lastNameGodfather = lastNameGodfather.substring(0, 1).toUpperCase() + lastNameGodfather.substring(1).toLowerCase(); } flag = Invitation.verifyMaliciousPassword(login, mail); if (flag == Invitation.ADDRESSES_MATCHE || flag == Invitation.USER_NOTEXIST) { System.out.println("invitenewmember"); try { url = "http://" + request.domain; if (request.port != 80) url += ":" + request.port; url += "/inscription?firstname=" + URLEncoder.encode(prenom, "UTF-8") + "&lastname=" + URLEncoder.encode(nom, "UTF-8") + "&email=" + URLEncoder.encode(mail, "UTF-8"); signature = Crypto.sign(prenom + nom + mail); url += "&signature=" + signature; System.out.println("url in inviteNewMember: " + url); } catch (UnsupportedEncodingException uee) { System.err.println(uee); } if (validation.hasErrors()) { render("Invitation/index.html"); } else { if (renderArgs.get("domainName") != null) { community = renderArgs.get("domainName").toString(); } System.out.println("I can arrive heeeeeeeeeeeeeeeeeeeeeeeeer"); if (langue.equals("fr")) { Mails.inviteFr( "Hypertopic Team <*****@*****.**>", mail, prenom, nom, url, community, firstNameGodfather, lastNameGodfather, mailGodfather); } else { Mails.inviteEn( "Hypertopic Team <*****@*****.**>", mail, prenom, nom, url, community, firstNameGodfather, lastNameGodfather, mailGodfather); } flash.success(Messages.get("invitation_success")); System.out.println("community: " + community); session.remove("nom"); session.remove("prenom"); session.remove("mail"); Invitation.invitation(); } } else { if (langue.equals("fr")) { flash.error(Messages.get("invitation_mailadresse_no_match")); } else { flash.error(Messages.get("invitation_mailadresse_no_match")); } Invitation.invitation(); } } catch (Exception e) { System.out.println("An exception occurred in Invitation.inviteNewMember"); e.printStackTrace(); render("Invitation/index.html"); } }