/** * 生成模板文件 * * @param vm * @param list * @param map */ public String generate(String vm, Map<String, Object> map) throws Exception { StringWriter writer = new StringWriter(); for (Entry<String, Object> e : map.entrySet()) { context.put(e.getKey(), e.getValue()); } context.put("generatetime", new Timestamp(System.currentTimeMillis())); context.put("modeldesc", Config.getInstance().getModeldesc()); Velocity.mergeTemplate(vm, "UTF-8", context, writer); return writer.toString(); }
@Command( value = "create-from", help = "Create a new entity service class with CRUD methods for an existing entity bean.") public void createFrom( @Option(name = "entity", required = true, type = PromptType.JAVA_CLASS) JavaResource entity, final PipeOut out) throws FileNotFoundException { JavaSourceFacet java = project.getFacet(JavaSourceFacet.class); JavaSource<?> entitySource = entity.getJavaSource(); VelocityContext context = new VelocityContext(); context.put("package", java.getBasePackage() + ".service"); context.put("entityImport", entitySource.getQualifiedName()); context.put("entityName", entitySource.getName()); context.put("cdiName", entitySource.getName().toLowerCase()); // Service class StringWriter writer = new StringWriter(); Velocity.mergeTemplate("TemplateService.vtl", "UTF-8", context, writer); JavaClass serviceClass = JavaParser.parse(JavaClass.class, writer.toString()); java.saveJavaSource(serviceClass); pickup.fire(new PickupResource(java.getJavaResource(serviceClass))); // ServiceTest class StringWriter writerTest = new StringWriter(); Velocity.mergeTemplate("TemplateServiceTest.vtl", "UTF-8", context, writerTest); JavaClass serviceTestClass = JavaParser.parse(JavaClass.class, writerTest.toString()); java.saveTestJavaSource(serviceTestClass); pickup.fire(new PickupResource(java.getTestJavaResource(serviceTestClass))); }
/** * @param context * @param templateName * @param file */ public void generate(VelocityContext context, String templateName, File file) { try { Writer writer = null; try { file.getParentFile().mkdirs(); writer = new FileWriter(file); Velocity.mergeTemplate(templateName, "UTF-8", context, writer); writer.flush(); logger.info("Generate successful! filename : " + file.getName()); } finally { if (writer != null) { writer.close(); } } } catch (Exception e) { logger.error("Generate error! filename : " + file.getName(), e); } }
private static String renderTemplate(Instance instance) { VelocityContext ctx = new VelocityContext(); WebServer ws = Jazmin.getServer(WebServer.class); if (ws != null) { ctx.put("deployServerPort", ws.getPort()); } ctx.put("env", Jazmin.environment.envs()); ctx.put("instances", getInstances()); ctx.put("instanceMap", instanceMap); ctx.put("machines", getMachines()); ctx.put("machineMap", machineMap); ctx.put("applications", getApplications()); ctx.put("applicationMap", applicationMap); ctx.put("instance", instance); // Map<String, String> properties = new HashMap<String, String>(); properties.putAll(instance.properties); properties.putAll(instance.application.properties); properties.putAll(instance.machine.properties); // ctx.put("properties", properties); StringWriter sw = new StringWriter(); String templateDir = workSpaceDir; templateDir += "template"; File file = new File(templateDir + "/" + instance.appId + ".vm"); if (!file.exists()) { logger.info("can not find {} use Default.vm to render", file); file = new File(templateDir + "/Default.vm"); } if (!file.exists()) { logger.warn("can not find template {}", file); return null; } Velocity.mergeTemplate(file.getPath(), "UTF-8", ctx, sw); return sw.toString(); }
/** * CLAIM送信を行う。 * * @param sendModel 送信するDocuentModel * @throws Exception */ public void send(DiagnosisSendWrapper wrapper) throws Exception { // s.oh^ 2013/12/10 傷病名のCLAIM送信する/しない Properties config = new Properties(); StringBuilder sbPath = new StringBuilder(); sbPath.append(System.getProperty("jboss.home.dir")); sbPath.append(File.separator); sbPath.append("custom.properties"); File f = new File(sbPath.toString()); FileInputStream fin = new FileInputStream(f); InputStreamReader isr = new InputStreamReader(fin, "JISAutoDetect"); config.load(isr); isr.close(); String claimSend = config.getProperty("diagnosis.claim.send"); if (claimSend != null && claimSend.equals("false")) { return; } // s.oh$ // 新規病名 List<RegisteredDiagnosisModel> addedDiagnosis = wrapper.getAddedDiagnosis(); // 更新病名 List<RegisteredDiagnosisModel> updatedDiagnosis = wrapper.getUpdatedDiagnosis(); // minagawa^ LSC 1.4 傷病名の削除 2013/06/24 // 削除病名 List<RegisteredDiagnosisModel> deletedDiagnosis = wrapper.getDeletedDiagnosis(); // minagawa$ // 実際にCLAIM送信する病名 List<RegisteredDiagnosisModel> actualList = new ArrayList<RegisteredDiagnosisModel>(); // 新規病名を送信する if (addedDiagnosis != null && addedDiagnosis.size() > 0) { for (RegisteredDiagnosisModel rdm : addedDiagnosis) { if (isDorcaUpdatedDisease(rdm) || isPureDisease(rdm)) { actualList.add(rdm); } } if (!actualList.isEmpty()) { if (DEBUG) { debug("-------- Send Diagnosis List to add ----------------"); for (RegisteredDiagnosisModel r : actualList) { debug(r.getDiagnosis()); } } } } // 更新された病名を CLAIM 送信する // detuched object のみ if (updatedDiagnosis != null && updatedDiagnosis.size() > 0) { if (DEBUG) { debug("-------- Send Diagnosis List to update ----------------"); for (RegisteredDiagnosisModel r : updatedDiagnosis) { debug(r.getDiagnosis()); } } actualList.addAll(updatedDiagnosis); } // minagawa^ LSC 1.4 傷病名の削除 2013/06/24 if (deletedDiagnosis != null && deletedDiagnosis.size() > 0) { if (DEBUG) { debug("-------- Send Diagnosis List to delete ----------------"); for (RegisteredDiagnosisModel r : updatedDiagnosis) { debug(r.getDiagnosis()); } } actualList.addAll(deletedDiagnosis); } if (actualList.isEmpty()) { return; } // minagawa$ // DocInfo & RD をカプセル化したアイテムを生成する ArrayList<DiagnosisModuleItem> moduleItems = new ArrayList<DiagnosisModuleItem>(); for (RegisteredDiagnosisModel rd : actualList) { DocInfoModel docInfo = new DocInfoModel(); docInfo.setDocId(GUIDGenerator.generate(docInfo)); docInfo.setTitle(IInfoModel.DEFAULT_DIAGNOSIS_TITLE); docInfo.setPurpose(IInfoModel.PURPOSE_RECORD); docInfo.setFirstConfirmDate(ModelUtils.getDateTimeAsObject(rd.getConfirmDate())); docInfo.setConfirmDate(ModelUtils.getDateTimeAsObject(rd.getFirstConfirmDate())); // s.oh^ 2013/05/10 傷病名対応 rd.setDiagnosisCode(HAND_CODE); // ORCAから取り込んだ場合、コードに0000999を設定する // s.oh$ DiagnosisModuleItem mItem = new DiagnosisModuleItem(); mItem.setDocInfo(docInfo); mItem.setRegisteredDiagnosisModule(rd); moduleItems.add(mItem); } // ヘルパー用の値を生成する String confirmDate = wrapper.getConfirmDate(); // ヘルパークラスを生成する DiseaseHelper dhl = new DiseaseHelper(); dhl.setPatientId(wrapper.getPatientId()); // 患者ID dhl.setConfirmDate(confirmDate); // 確定日 dhl.setDiagnosisModuleItems(moduleItems); // RD+DocInfo dhl.setGroupId(GUIDGenerator.generate(dhl)); // GroupId dhl.setDepartment(wrapper.getDepartment()); // 診療科コード dhl.setDepartmentDesc(wrapper.getDepartmentDesc()); // 診療科名 dhl.setCreatorName(wrapper.getCreatorName()); // 担当医名 dhl.setCreatorId(wrapper.getCreatorLicense()); // 担当医コード dhl.setJmariCode(wrapper.getJamariCode()); // JMARI code dhl.setCreatorLicense(wrapper.getCreatorLicense()); // 医療資格 dhl.setFacilityName(wrapper.getFacilityName()); // 施設名 if (DEBUG) { debug("患者ID=" + dhl.getPatientId()); debug("確定日=" + dhl.getConfirmDate()); debug("GroupId=" + dhl.getGroupId()); debug("診療科コード=" + dhl.getDepartment()); debug("診療科名=" + dhl.getDepartmentDesc()); debug("担当医名=" + dhl.getCreatorName()); debug("担当医コード=" + dhl.getCreatorId()); debug("JMARI code=" + dhl.getJmariCode()); debug("医療資格=" + dhl.getCreatorLicense()); debug("施設名=" + dhl.getFacilityName()); } // ログのために基本情報を生成する StringBuilder sb = new StringBuilder(); sb.append(confirmDate).append(" "); sb.append(wrapper.getPatientId()).append(" "); sb.append(wrapper.getPatientName()).append(" "); sb.append(wrapper.getPatientGender()); String baseInfo = sb.toString(); // -------------------------------------------------------- // CLIAM message を生成する // -------------------------------------------------------- VelocityContext context = VelocityHelper.getContext(); context.put(OBJECT_NAME, dhl); StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); Velocity.mergeTemplate(TEMPLATE_NAME, TEMPLATE_ENC, context, bw); bw.flush(); bw.close(); String claimMessage = sw.toString(); // minagawa^ CLAIM Log log(claimMessage); // if (DEBUG) { // debug(claimMessage); // } // minagawa$ // -------------------------------------------------------- // ORCAへ接続する Socket socket = new Socket(host, port); OutputStream out = socket.getOutputStream(); DataOutputStream dout = new DataOutputStream(out); BufferedOutputStream writer = new BufferedOutputStream(dout); InputStream in = socket.getInputStream(); DataInputStream din = new DataInputStream(in); BufferedInputStream reader = new BufferedInputStream(din); // Writes UTF8 data writer.write(claimMessage.getBytes(enc)); writer.write(EOT); writer.flush(); // Reads result int c = reader.read(); if (c == ACK) { sb = new StringBuilder(); sb.append(ACK_STR).append(baseInfo); log(sb.toString()); } else if (c == NAK) { sb = new StringBuilder(); sb.append(NAK_STR).append(baseInfo); log(sb.toString()); } writer.close(); reader.close(); socket.close(); }