List of usage examples for javax.servlet.http HttpServletRequest getRealPath
public String getRealPath(String path);
From source file:co.com.rempe.impresiones.negocio.servlets.SubirArchivosServlet.java
private Respuesta subirArchivo(HttpServletRequest request) throws FileUploadException, Exception { Respuesta respuesta = new Respuesta(); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); // req es la HttpServletRequest que recibimos del formulario. // Los items obtenidos sern cada uno de los campos del formulario, // tanto campos normales como ficheros subidos. // System.out.println("Items-------"); List items = upload.parseRequest(request); System.out.println(items);//from w ww . j a va2s . c om // System.out.println("Request-----------------"); System.out.println(request); // Se recorren todos los items, que son de tipo FileItem for (Object item : items) { FileItem uploaded = (FileItem) item; // Hay que comprobar si es un campo de formulario. Si no lo es, se guarda el fichero // subido donde nos interese // System.out.println("Item---------------"); System.out.println(uploaded.isFormField()); if (!uploaded.isFormField()) { // No es campo de formulario, guardamos el fichero en algn sitio //El sisguiente bloque simplemente es para divorciar el nombre del archivo de las rutas //posibles que pueda traernos el getName() sobre el objeto de la clase FileItem, //pues he descuvierto que el explorer especificamente es el nico que enva //la ruta adjuntada al nombre, por lo cual es importante corregirlo. String nombreArchivo = uploaded.getName(); String cadena = nombreArchivo; System.out.println(cadena); while (cadena.contains("\\")) { cadena = cadena.replace("\\", "&"); } // System.out.println(cadena); String[] ruta = cadena.split("&"); for (int i = 0; i < ruta.length; i++) { String string = ruta[i]; System.out.println(string); } nombreArchivo = ruta[ruta.length - 1]; // System.out.println("Ruta archivo: " + nombreArchivo); //Fin correccin nombre. String nombreArchivoEscrito = System.currentTimeMillis() + "-" + nombreArchivo; String rutaEscritura = new File(request.getRealPath("archivos-subidos"), nombreArchivoEscrito) .toString(); File fichero = new File(rutaEscritura); ArchivosAdjuntos archivo = new ArchivosAdjuntos(); archivo.setNombreArchivo(nombreArchivo); archivo.setRutaArchivo(rutaEscritura); archivo.setTamanioArchivo(uploaded.getSize()); if (nombreArchivo.endsWith(".pdf") || nombreArchivo.endsWith(".png") || nombreArchivo.endsWith(".jpg") || nombreArchivo.endsWith(".bmp") || nombreArchivo.endsWith(".svg")) { // System.out.println("Archivo subido: " + uploaded.getName()); uploaded.write(fichero); respuesta.setCodigo(1); respuesta.setDatos(archivo); respuesta.setMensaje("Se ha subido exitosamente el archivo: " + uploaded.getName()); } else { respuesta.setCodigo(0); respuesta.setDatos(archivo); respuesta.setMensaje("El formato del archivo " + nombreArchivo + " es invalido!"); } } // else { // // es un campo de formulario, podemos obtener clave y valor // String key = uploaded.getFieldName(); // String valor = uploaded.getString(); // System.out.println("Archivo subido: " + key); // } } return respuesta; }
From source file:com.ycszh.ssh.service.veh.impl.SlgVehServiceImpl.java
public Integer insertOrUpdateSlgDrvXxcjb(DbjgZjxxb dbZjxxb, DydjYwsbspb dydjYwsbspb, HttpServletRequest request, File file1, File file2, File file01, File file02, File gpyfile0, File gpyfile1, File gpyfile2, File gpyfile3, File gpyfile4, File gpyfile5, File gpyfile6, File gpyfile7) throws Exception { int result = -1; if (dbZjxxb != null) { String id = dbZjxxb.getId(); User user = (User) request.getSession().getAttribute(SysConst.USERBEAN); if ("1".equals(dbZjxxb.getBllx())) { dbZjxxb.setDbrsfzmmc(""); dbZjxxb.setDbrSfzCardname1(""); dbZjxxb.setDbrSfzCardsex1(""); dbZjxxb.setDbrSfzCardno1(""); dbZjxxb.setDbrSfzCardaddress1(""); file2 = null;//from w ww. j ava 2s . c o m } dbZjxxb.setLrr(user.getName()); dbZjxxb.setLrrxm(user.getYgxm()); dbZjxxb.setLrbmdm(user.getBmid()); dbZjxxb.setLrbmmc(user.getBmmc()); dbZjxxb.setLrsj(new Date()); dbZjxxb.setLrip(getLoginIp(request)); dbZjxxb.setLrmac(request.getLocalAddr()); String hphm = dbZjxxb.getHphm(); if (!StringUtil.isNull(hphm)) { hphm = hphm.toUpperCase(); if (hphm.contains("")) { hphm = hphm.replaceAll("", ""); } dbZjxxb.setHphm(hphm); } if (id == null || "".equals(id)) { /********************************?*****************************************/ String basePath = request.getRealPath("/"); File f = new File(basePath + "\\images\\shuiyin.png"); if (null != file1) { String strtemp = slgDrvFileUpload.uploadFile(file1); if (null != strtemp && !"".equals(strtemp)) { dbZjxxb.setDsrSfzCardphoto1(strtemp); } else { Exception etemp = new Exception( ":?,??!"); throw etemp; } } if (null != file2) { String strtemp = slgDrvFileUpload.uploadFile(file2); if (null != strtemp && !"".equals(strtemp)) { dbZjxxb.setDbrSfzCardphoto1(strtemp); } else { Exception etemp = new Exception( ":?,??!"); throw etemp; } } if (null != file01) { ImageUtils.pressImage(file01, f); String strtemp = slgDrvFileUpload.uploadFile(file01); if (null != strtemp && !"".equals(strtemp)) { dbZjxxb.setDsrSfzSxtZp(strtemp); } else { Exception etemp = new Exception( ":?,??!"); throw etemp; } } if (null != file02) { ImageUtils.pressImage(file02, f); String strtemp = slgDrvFileUpload.uploadFile(file02); if (null != strtemp && !"".equals(strtemp)) { dbZjxxb.setDsrSfzGpyZp(strtemp); } else { Exception etemp = new Exception( ":?,??!"); throw etemp; } } /********************************?*****************************************/ String lsh = request.getParameter("lshval"); String firtst = ""; if (lsh != null && !"".equals(lsh)) { firtst = lsh.substring(0, 1); } if (lsh != null && !"".equals(lsh) && !"L".equals(firtst)) { if ("D".equals(firtst)) { // //?????? DydjYwsbspbTemp dydjYwsbspb2 = dydjService.getDydjYwwbspByLsh(request, lsh); if (dydjYwsbspb2 == null) { return -1; } if ("11".equals(dydjYwsbspb2.getSqlx())) { //???1? dbZjxxb.setDsrSfzCardname1(dydjYwsbspb2.getDyrSfzCardname()); dbZjxxb.setDsrSfzCardno1(dydjYwsbspb2.getDyrSfzCardno()); dbZjxxb.setDsrSfzCardsex1(dydjYwsbspb2.getDyrSfzCardsex()); dbZjxxb.setDsrSfzCardaddress1(dydjYwsbspb2.getDyrSfzCardaddress()); // if (!StringUtil.isNull(dydjYwsbspb2.getDyrSfzCardphotoId())) { int photoid = Integer.parseInt(dydjYwsbspb2.getDyrSfzCardphotoId()); byte[] bytes = dydjService.getImageBlob(request, photoid); if (bytes != null) { String imgtemp = slgDrvFileUpload.uploadFileBybyte(bytes); dbZjxxb.setDsrSfzCardphoto1(imgtemp); } } } else if ("12".equals(dydjYwsbspb2.getSqlx())) { //?????1?,???2? dbZjxxb.setDsrZzjgZh1(dydjYwsbspb2.getDyrZzjgZh()); dbZjxxb.setDsrZzjgFrdb1(dydjYwsbspb2.getDyrZzjgFrdb()); dbZjxxb.setDsrZzjgYyzz1(dydjYwsbspb2.getDyrZzjgYyzz()); dbZjxxb.setDsrZzjgDwmc1(dydjYwsbspb2.getDyrZzjgDwmc()); dbZjxxb.setDsrZzjgDz1(dydjYwsbspb2.getDyrZzjgDz()); dbZjxxb.setDsrZzjgNjrq1(dydjYwsbspb2.getDyrZzjgNjrq()); dbZjxxb.setDsrZzjgNjyxq1(dydjYwsbspb2.getDyrZzjgNjyxq()); dbZjxxb.setDbrSfzCardname2(dydjYwsbspb2.getDyrSfzCardname()); dbZjxxb.setDbrSfzCardno2(dydjYwsbspb2.getDyrSfzCardno()); dbZjxxb.setDbrSfzCardsex2(dydjYwsbspb2.getDyrSfzCardsex()); dbZjxxb.setDbrSfzCardaddress2(dydjYwsbspb2.getDyrSfzCardaddress()); // if (!StringUtil.isNull(dydjYwsbspb2.getDyrSfzCardphotoId())) { int photoid = Integer.parseInt(dydjYwsbspb2.getDyrSfzCardphotoId()); byte[] bytes = dydjService.getImageBlob(request, photoid); if (bytes != null) { String imgtemp = slgDrvFileUpload.uploadFileBybyte(bytes); dbZjxxb.setDbrSfzCardphoto2(imgtemp); } } } else { //??????????????? dbZjxxb.setDbrZzjgZh2(dbZjxxb.getDbrZzjgZh1()); dbZjxxb.setDbrZzjgFrdb2(dbZjxxb.getDbrZzjgFrdb1()); dbZjxxb.setDbrZzjgYyzz2(dbZjxxb.getDbrZzjgYyzz1()); dbZjxxb.setDbrZzjgDwmc2(dbZjxxb.getDbrZzjgDwmc1()); dbZjxxb.setDbrZzjgDz2(dbZjxxb.getDbrZzjgDz1()); dbZjxxb.setDbrZzjgNjrq2(dbZjxxb.getDbrZzjgNjrq1()); dbZjxxb.setDbrZzjgNjyxq2(dbZjxxb.getDbrZzjgNjyxq1()); dbZjxxb.setDbrSfzCardname2(dbZjxxb.getDbrSfzCardname1()); dbZjxxb.setDbrSfzCardno2(dbZjxxb.getDbrSfzCardno1()); dbZjxxb.setDbrSfzCardsex2(dbZjxxb.getDbrSfzCardsex1()); dbZjxxb.setDbrSfzCardaddress2(dbZjxxb.getDbrSfzCardaddress1()); dbZjxxb.setDbrSfzCardphoto2(dbZjxxb.getDbrSfzCardphoto1()); } //????1 dbZjxxb.setDbrZzjgZh1(dydjYwsbspb2.getYhZzjgZh()); dbZjxxb.setDbrZzjgFrdb1(dydjYwsbspb2.getYhZzjgFrdb()); dbZjxxb.setDbrZzjgYyzz1(dydjYwsbspb2.getYhZzjgYyzz()); dbZjxxb.setDbrZzjgDwmc1(dydjYwsbspb2.getYhZzjgDwmc()); dbZjxxb.setDbrZzjgDz1(dydjYwsbspb2.getYhZzjgDz()); dbZjxxb.setDbrZzjgNjrq1(dydjYwsbspb2.getYhZzjgNjrq()); dbZjxxb.setDbrZzjgNjyxq1(dydjYwsbspb2.getYhZzjgNjyxq()); //????1? dbZjxxb.setDbrSfzCardname1(dydjYwsbspb2.getYhSfzCardname()); dbZjxxb.setDbrSfzCardno1(dydjYwsbspb2.getYhSfzCardno()); dbZjxxb.setDbrSfzCardsex1(dydjYwsbspb2.getYhSfzCardsex()); dbZjxxb.setDbrSfzCardaddress1(dydjYwsbspb2.getYhSfzCardaddress()); // if (!StringUtil.isNull(dydjYwsbspb2.getYhSfzCardphotoId())) { int photoid = Integer.parseInt(dydjYwsbspb2.getYhSfzCardphotoId()); byte[] bytes = dydjService.getImageBlob(request, photoid); if (bytes != null) { String imgtemp = slgDrvFileUpload.uploadFileBybyte(bytes); dbZjxxb.setDbrSfzCardphoto1(imgtemp); } } dbZjxxb.setLsh(lsh); DbjgZjxxb zjxxb1 = this.slgVehDao.addRepository(dbZjxxb); // DbjgZjxxbLog dZjxxbLog = new DbjgZjxxbLog(); dZjxxbLog = (DbjgZjxxbLog) getXclog(dZjxxbLog, zjxxb1); dZjxxbLog.setCzr(user.getName()); dZjxxbLog.setCzrxm(user.getYgxm()); dZjxxbLog.setCzrbm(user.getBmid()); dZjxxbLog.setCznr("I"); dZjxxbLog.setCzsj(new Date()); dZjxxbLog.setCzip(getLoginIp(request)); dZjxxbLog.setCzmac(""); this.slgVehDao.addObj(dZjxxbLog, request); //??DYDJ_YWSBSPB String upsql = "update dydj_ywsbspb set cg_yhdm = '" + user.getName() + "', cg_yhxm = '" + user.getYgxm() + "', cg_ip = '" + getLoginIp(request) + "', cg_yhsj = to_char(sysdate, 'yyyy-MM-dd HH24:mi:ss') where id = " + dydjYwsbspb2.getId(); this.slgVehDao.updateRepositoryBySql(upsql); //??DYDJ_YWSBSPB_log DydjYwsbspbLog ywsbspbLog = new DydjYwsbspbLog(); ywsbspbLog = (DydjYwsbspbLog) getXclog(ywsbspbLog, dydjYwsbspb2); ywsbspbLog.setCzr(user.getName()); ywsbspbLog.setCzrxm(user.getYgxm()); ywsbspbLog.setCzrbm(user.getBmid()); ywsbspbLog.setCzsj(new Date()); ywsbspbLog.setCznr("???"); ywsbspbLog.setCzip(getLoginIp(request)); this.slgVehDao.addObj(dZjxxbLog, request); result = 1; } else { //?? if ("D".equals(dbZjxxb.getYwlx()) && ("D:P".equals(dbZjxxb.getYwyy()) || "D:A".equals(dbZjxxb.getYwyy()) || "D:J".equals(dbZjxxb.getYwyy()))) { //???outin String sql = "insert into vehicle_temp_mid_write select * from vehicle_temp_mid_read where lsh= '" + lsh + "'"; this.slgVehDao.updateRepositoryBySql(sql); } //???_in? VehicleTempMidIn tempMidIn = getVehicleMidInByLsh(lsh, request); //_test if (tempMidIn != null) { VehicleTempMidTest tempMidTest = new VehicleTempMidTest(); tempMidTest = (VehicleTempMidTest) getXclog(tempMidTest, tempMidIn); tempMidTest.setLocalIshandle("1"); tempMidTest.setLocalOperat(dbZjxxb.getLrr()); tempMidTest.setLocalOpertime(new Date()); tempMidTest.setLocalName(dbZjxxb.getLrrxm()); this.slgVehDao.addObj(tempMidTest, request); //_in tempMidIn.setLocalIshandle("1"); tempMidIn.setLocalOperat(dbZjxxb.getLrr()); tempMidIn.setLocalOpertime(new Date()); tempMidIn.setLocalName(dbZjxxb.getLrrxm()); this.slgVehDao.updateObj(tempMidIn); dbZjxxb.setLsh(lsh); DbjgZjxxb zjxxb1 = this.slgVehDao.addRepository(dbZjxxb); // DbjgZjxxbLog dZjxxbLog = new DbjgZjxxbLog(); dZjxxbLog = (DbjgZjxxbLog) getXclog(dZjxxbLog, zjxxb1); dZjxxbLog.setCzr(user.getName()); dZjxxbLog.setCzrxm(user.getYgxm()); dZjxxbLog.setCzrbm(user.getBmid()); dZjxxbLog.setCznr("I"); dZjxxbLog.setCzsj(new Date()); dZjxxbLog.setCzip(getLoginIp(request)); dZjxxbLog.setCzmac(""); this.slgVehDao.addObj(dZjxxbLog, request); result = 1; } } //????? YwlsglVehFlow ywFlow = (YwlsglVehFlow) this.defaultDao.getRepository(lsh, YwlsglVehFlow.class); if (ywFlow != null) { ywFlow.setLszt("E"); this.defaultDao.updateRepository(ywFlow); YwlsglVehFlowLog log = new YwlsglVehFlowLog(); log = (YwlsglVehFlowLog) getXclog(log, ywFlow); log.setCzr(user.getYgid()); log.setCzrxm(user.getYgxm()); log.setCzrbm(user.getBmid()); log.setCzrbmKj(getDeptUpid(user.getBmid())); log.setCzip(getLoginIp(request)); log.setCznr("U"); log.setCzsj(new Date()); this.defaultDao.addRepository(log); } } else { DbjgZjxxb zjxxb = this.slgVehDao.addRepository(dbZjxxb); // String filecount = request.getParameter("filecount"); if (null != filecount) { if (!"0".equals(filecount)) { for (int i = 0; i < Integer.parseInt(filecount); i++) { DbjgFzxp fzxpBean = new DbjgFzxp(); fzxpBean.setJdcxxcjid(zjxxb.getId()); fzxpBean.setYwlxid(zjxxb.getYwlx()); fzxpBean.setYwlxms(SlgVehServiceImpl.getYwlxMessage(zjxxb.getYwlx())); fzxpBean.setPzid(request.getParameter("gpyid" + i)); fzxpBean.setPztitle(request.getParameter("gpytitle" + i)); //???? File file = null; switch (i) { case 0: file = gpyfile0; break; case 1: file = gpyfile1; break; case 2: file = gpyfile2; break; case 3: file = gpyfile3; break; case 4: file = gpyfile4; break; case 5: file = gpyfile5; break; case 6: file = gpyfile6; break; case 7: file = gpyfile7; break; default: break; } if (null != file) { ImageUtils.pressImage(file, f); String twm = slgDrvFileUpload.uploadFile(file); if (null != twm && !"".equals(twm)) { fzxpBean.setTwm(twm); } else { Exception etemp = new Exception( ":?,??!"); throw etemp; } } fzxpBean.setCzr(user.getName()); fzxpBean.setCzrxm(user.getYgxm()); fzxpBean.setCzbm(user.getBmmc()); fzxpBean.setCzrq(new Date()); fzxpBean.setCzip(getLoginIp(request)); fzxpBean.setVehOrDrv("VEH"); this.defaultDao.addRepository(fzxpBean); } } } VehicleTempMidInJdc vehInJdc = new VehicleTempMidInJdc(); vehInJdc.setLsh(zjxxb.getId()); vehInJdc.setHphm(zjxxb.getHphm()); vehInJdc.setHpzl(zjxxb.getHpzl()); vehInJdc.setSfzmhm(zjxxb.getDsrsfzmhm()); vehInJdc.setSyr(zjxxb.getDsrxm()); vehInJdc.setNetSmzmhm(zjxxb.getDbrsfzmhm()); vehInJdc.setNetXm(zjxxb.getDbrxm()); vehInJdc.setLocalIshandle("1"); vehInJdc.setLocalOperat(zjxxb.getLrr()); vehInJdc.setLocalName(zjxxb.getLrrxm()); vehInJdc.setLocalOpertime(new Date()); vehInJdc.setPostZj("0"); vehInJdc.setPostTp("0"); vehInJdc.setYwlx("B"); vehInJdc.setYwyy("B"); String bzval = ""; if (zjxxb.getYwyy() != null && !"".equals(zjxxb.getYwyy())) { String ywlxval = ""; String ywyyval = ""; String[] ywyys = zjxxb.getYwyy().split(","); if (ywyys != null && ywyys.length > 0) { for (int m = 0; m < ywyys.length; m++) { String ywlxs = ywyys[m]; if (ywlxs != null && !"".equals(ywlxs)) { String[] ywyyarr = ywlxs.split(":"); ywlxval = ywyyarr[0]; ywyyval += ywyyarr[1] + ","; } } } if (ywyyval.endsWith(",")) { ywyyval = ywyyval.substring(0, ywyyval.length() - 1); } bzval = ywlxval + ":" + ywyyval; } else { bzval = zjxxb.getYwlx(); } vehInJdc.setBz(bzval); this.slgVehDao.addObj(vehInJdc, request); // DbjgZjxxbLog dZjxxbLog = new DbjgZjxxbLog(); dZjxxbLog = (DbjgZjxxbLog) getXclog(dZjxxbLog, zjxxb); dZjxxbLog.setCzr(user.getName()); dZjxxbLog.setCzrxm(user.getYgxm()); dZjxxbLog.setCzrbm(user.getBmid()); dZjxxbLog.setCznr("I"); dZjxxbLog.setCzsj(new Date()); dZjxxbLog.setCzip(getLoginIp(request)); dZjxxbLog.setCzmac(""); this.slgVehDao.addObj(dZjxxbLog, request); result = 1; } //? String zbyzflag = request.getParameter("zbyzflag"); if ("1".equals(zbyzflag)) { StringBuffer srcs = new StringBuffer("<request><head><dqgw>3</dqgw></head><body>"); srcs.append("<lsh>" + (dbZjxxb.getLsh() == null ? "" : dbZjxxb.getLsh()) + "</lsh>"); srcs.append("<hphm>" + (dbZjxxb.getHphm() == null ? "" : dbZjxxb.getHphm()) + "</hphm>"); srcs.append("<hpzl>" + (dbZjxxb.getHpzl() == null ? "" : dbZjxxb.getHpzl()) + "</hpzl>"); srcs.append("<syxz>" + (dbZjxxb.getSyxz() == null ? "" : dbZjxxb.getSyxz()) + "</syxz>"); srcs.append("<sfzmmc>" + (dbZjxxb.getDsrsfzmmc() == null ? "" : dbZjxxb.getDsrsfzmmc()) + "</sfzmmc>"); srcs.append("<sfzmhm>"); srcs.append(dbZjxxb.getDsrsfzmhm() == null ? dbZjxxb.getDsrZzjgZh1() : dbZjxxb.getDsrsfzmhm()); srcs.append("</sfzmhm>"); srcs.append("<syr>"); srcs.append(dbZjxxb.getDsrxm()); srcs.append("</syr>"); srcs.append("<ip>" + (dbZjxxb.getLrip() == null ? "" : dbZjxxb.getLrip()) + "</ip>"); srcs.append("<sffq>" + (dbZjxxb.getSffq() == null ? "" : dbZjxxb.getSffq()) + "</sffq>"); srcs.append("<jhzbh>" + (dbZjxxb.getJhzbh() == null ? "" : dbZjxxb.getJhzbh()) + "</jhzbh>"); srcs.append("<ywlx>" + (dbZjxxb.getYwlx() == null ? "" : dbZjxxb.getYwlx()) + "</ywlx>"); srcs.append("<ywyy>" + (dbZjxxb.getYwyy() == null ? "" : dbZjxxb.getYwyy()) + "</ywyy>"); srcs.append("<hdfs>" + (dbZjxxb.getHdfs() == null ? "" : dbZjxxb.getHdfs()) + "</hdfs>"); srcs.append( "<tyblsh>" + (dbZjxxb.getTyblsh() == null ? "" : dbZjxxb.getTyblsh()) + "</tyblsh>"); srcs.append("<clsbdh></clsbdh>"); srcs.append("<cllx>" + (dbZjxxb.getCllx() == null ? "" : dbZjxxb.getCllx()) + "</cllx>"); srcs.append("<syq></syq>"); srcs.append("<glbm></glbm>"); srcs.append("<zczxlsh>" + (dbZjxxb.getLsh() == null ? "" : dbZjxxb.getLsh()) + "</zczxlsh>"); srcs.append("<zczxhfhljzyqchzx>" + (dbZjxxb.getZczxhfhljzyqchzx() == null ? "" : dbZjxxb.getZczxhfhljzyqchzx()) + "</zczxhfhljzyqchzx>"); srcs.append("<tbr>" + (dbZjxxb.getTbr() == null ? "" : dbZjxxb.getTbr()) + "</tbr>"); srcs.append("<tbyy>" + (dbZjxxb.getTbyy() == null ? "" : dbZjxxb.getTbyy()) + "</tbyy>"); srcs.append("<zblx>" + (dbZjxxb.getZblx() == null ? "" : dbZjxxb.getZblx()) + "</zblx>"); srcs.append("<zbh>" + (dbZjxxb.getZbh() == null ? "" : dbZjxxb.getZbh()) + "</zbh>"); srcs.append("</body></request>"); String msg = this.slgVehDao.insertShenjiinfo(request, StringUtil.isNull(dbZjxxb.getZjxxblsh()) ? dbZjxxb.getLsh() : dbZjxxb.getZjxxblsh(), srcs.toString()); if (!"[0000]".equals(msg.substring(0, 6))) { throw new Exception(msg.substring(6)); } } } else { // DbjgZjxxb dbZjxxb2 = this.slgVehDao.updateRepository(dbZjxxb); // DbjgZjxxbLog dZjxxbLog = new DbjgZjxxbLog(); dZjxxbLog = (DbjgZjxxbLog) getXclog(dZjxxbLog, dbZjxxb2); dZjxxbLog.setCzr(user.getName()); dZjxxbLog.setCzrxm(user.getYgxm()); dZjxxbLog.setCzrbm(user.getBmid()); dZjxxbLog.setCznr("U"); dZjxxbLog.setCzsj(new Date()); dZjxxbLog.setCzip(getLoginIp(request)); dZjxxbLog.setCzmac(""); this.slgVehDao.addObj(dZjxxbLog, request); result = 1; } } return result; }
From source file:ispyb.client.common.shipping.UploadShipmentAction.java
/** * PopulateTemplate/*from w w w.jav a2 s.c om*/ * * @param request * @param getTemplateFullPathOnly * @param getTemplateFilenameOnly * @param populateDMCodes * @param selectedBeamlineName * @param hashDMCodesForBeamline * @param populateForExport * @param nbContainersToExport * @param populateForShipment * @param shippingId * @return */ public static String PopulateTemplate(HttpServletRequest request, boolean getTemplateFullPathOnly, boolean getTemplateFilenameOnly, boolean populateDMCodes, String selectedBeamlineName, List hashDMCodesForBeamline, boolean populateForExport, int nbContainersToExport, boolean populateForShipment, int shippingId) { String populatedTemplatePath = ""; try { String xlsPath; String proposalCode; String proposalNumber; String populatedTemplateFileName; String today = ".xls"; if (request != null) { xlsPath = Constants.TEMPLATE_POPULATED_RELATIVE_PATH; if (populateForShipment) xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FROM_SHIPMENT; else if (populateForExport) { switch (nbContainersToExport) { case 1: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME1; break; case 2: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME2; break; case 3: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME3; break; case 4: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME4; break; case 5: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME5; break; case 6: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME6; break; case 7: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME7; break; case 8: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME8; break; case 9: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME9; break; case 10: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME10; break; } } proposalCode = (String) request.getSession().getAttribute(Constants.PROPOSAL_CODE); proposalNumber = String.valueOf(request.getSession().getAttribute(Constants.PROPOSAL_NUMBER)); if (populateForShipment) populatedTemplateFileName = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + proposalCode + proposalNumber + "_shipment_" + shippingId + today; else populatedTemplateFileName = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + proposalCode + proposalNumber + ((populateDMCodes) ? "_#" : "") + today; populatedTemplatePath = request.getContextPath() + populatedTemplateFileName; if (getTemplateFilenameOnly && populateForShipment) return proposalCode + proposalNumber + "_shipment_" + shippingId + today; if (getTemplateFilenameOnly && !populateForShipment) return proposalCode + proposalNumber + ((populateDMCodes) ? "_#" : "") + today; xlsPath = request.getRealPath(xlsPath); populatedTemplateFileName = request.getRealPath(populatedTemplateFileName); } else { xlsPath = "C:/" + Constants.TEMPLATE_POPULATED_RELATIVE_PATH; proposalCode = "ehtpx"; proposalNumber = "1"; populatedTemplateFileName = "C:/" + Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + proposalCode + proposalNumber + today; } if (getTemplateFullPathOnly) return populatedTemplateFileName; // Retrieve DM codes from DB String beamlineName = selectedBeamlineName; String[][] dmCodesinSC = null; File originalTemplate = new File(xlsPath); File populatedTemplate = new File(populatedTemplateFileName); FileUtils.copyFile(originalTemplate, populatedTemplate); ISPyBParser parser = new ISPyBParser(); // Copy template to tmp folder File xlsTemplate = new File(xlsPath); File xlsPopulatedTemplate = new File(populatedTemplateFileName); FileUtils.copyFile(xlsTemplate, xlsPopulatedTemplate); Ejb3ServiceLocator ejb3ServiceLocator = Ejb3ServiceLocator.getInstance(); Proposal3Service proposal3Service = (Proposal3Service) ejb3ServiceLocator .getLocalService(Proposal3Service.class); // Get the list of Proteins // old List proposals = (List) _proposal.findByCodeAndNumber(proposalCode, new Integer(proposalNumber)); List<Proposal3VO> proposals = proposal3Service.findByCodeAndNumber(proposalCode, proposalNumber, false, false, false); // ProposalLightValue proposalLight = (ProposalLightValue) proposals.get(0); Protein3Service protein3Service = (Protein3Service) ejb3ServiceLocator .getLocalService(Protein3Service.class); // List listProteins = (List) protein3Service..findByProposalId(proposalLight.getPrimaryKey()); List<Protein3VO> listProteins = protein3Service.findByProposalId(proposals.get(0).getProposalId(), true, true); LOG.info("xlsPath = " + xlsPath + "populatedTemplateFileName = " + populatedTemplateFileName); parser.populate(xlsPath, populatedTemplateFileName, listProteins, dmCodesinSC); if (populateForShipment) parser.populateExistingShipment(populatedTemplateFileName, populatedTemplateFileName, shippingId); } catch (Exception ex) { ex.printStackTrace(); } return populatedTemplatePath; }
From source file:ispyb.common.util.upload.UploadShipmentUtils.java
/** * PopulateTemplate/* w w w . jav a 2 s . c o m*/ * * @param request * @param getTemplateFullPathOnly * @param getTemplateFilenameOnly * @param populateDMCodes * @param selectedBeamlineName * @param hashDMCodesForBeamline * @param populateForExport * @param nbContainersToExport * @param populateForShipment * @param shippingId * @return */ public static String PopulateTemplate(HttpServletRequest request, boolean getTemplateFullPathOnly, boolean getTemplateFilenameOnly, boolean populateDMCodes, String selectedBeamlineName, List hashDMCodesForBeamline, boolean populateForExport, int nbContainersToExport, boolean populateForShipment, int shippingId) { String populatedTemplatePath = ""; try { String xlsPath; String proposalCode; String proposalNumber; String populatedTemplateFileName; // GregorianCalendar calendar = new GregorianCalendar(); String today = ".xls"; if (request != null) { xlsPath = Constants.TEMPLATE_POPULATED_RELATIVE_PATH; if (populateForShipment) xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FROM_SHIPMENT; else if (populateForExport) { switch (nbContainersToExport) { case 1: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME1; break; case 2: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME2; break; case 3: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME3; break; case 4: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME4; break; case 5: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME5; break; case 6: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME6; break; case 7: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME7; break; case 8: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME8; break; case 9: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME9; break; case 10: xlsPath = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + Constants.TEMPLATE_XLS_POPULATED_FOR_EXPORT_FILENAME10; break; } } proposalCode = (String) request.getSession().getAttribute(Constants.PROPOSAL_CODE); proposalNumber = String.valueOf(request.getSession().getAttribute(Constants.PROPOSAL_NUMBER)); if (populateForShipment) populatedTemplateFileName = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + proposalCode + proposalNumber + "_shipment_" + shippingId + today; else populatedTemplateFileName = Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + proposalCode + proposalNumber + ((populateDMCodes) ? "_#" : "") + today; populatedTemplatePath = request.getContextPath() + populatedTemplateFileName; if (getTemplateFilenameOnly && populateForShipment) return proposalCode + proposalNumber + "_shipment_" + shippingId + today; if (getTemplateFilenameOnly && !populateForShipment) return proposalCode + proposalNumber + ((populateDMCodes) ? "_#" : "") + today; String requestPath = request.getRealPath("/"); xlsPath = requestPath + xlsPath; String prefix = new File(xlsPath).getParent(); populatedTemplateFileName = (prefix + "/" + new File(populatedTemplateFileName).getName()); } else { xlsPath = "C:/" + Constants.TEMPLATE_POPULATED_RELATIVE_PATH; proposalCode = "ehtpx"; proposalNumber = "1"; populatedTemplateFileName = "C:/" + Constants.TEMPLATE_RELATIVE_DIRECTORY_PATH + proposalCode + proposalNumber + today; } if (getTemplateFullPathOnly) return populatedTemplateFileName; // Retrieve DM codes from DB String beamlineName = selectedBeamlineName; String[][] dmCodesinSC = null; File originalTemplate = new File(xlsPath); File populatedTemplate = new File(populatedTemplateFileName); FileUtils.copyFile(originalTemplate, populatedTemplate); ISPyBParser parser = new ISPyBParser(); // Copy template to tmp folder File xlsTemplate = new File(xlsPath); File xlsPopulatedTemplate = new File(populatedTemplateFileName); FileUtils.copyFile(xlsTemplate, xlsPopulatedTemplate); // Get the list of Proteins Proposal3Service proposalService = (Proposal3Service) Ejb3ServiceLocator.getInstance() .getLocalService(Proposal3Service.class); List<Proposal3VO> proposals = proposalService.findByCodeAndNumber(proposalCode, proposalNumber, false, true, false); Proposal3VO proposalLight = proposals.get(0); // List<Protein3VO> listProteins = new ArrayList<Protein3VO>(proposalLight.getProteinVOs()); Protein3Service protein3Service = (Protein3Service) ejb3ServiceLocator .getLocalService(Protein3Service.class); List<Protein3VO> listProteins = protein3Service.findByProposalId(proposalLight.getProposalId(), true, true); parser.populate(xlsPath, populatedTemplateFileName, listProteins, dmCodesinSC); if (populateForShipment) parser.populateExistingShipment(populatedTemplateFileName, populatedTemplateFileName, shippingId); } catch (Exception ex) { ex.printStackTrace(); } return populatedTemplatePath; }
From source file:ispyb.client.common.shipping.CreateShippingFileAction.java
/** * uploadCsvFile// w ww .ja va2 s. c o m * * @param mapping * @param actForm * @param request * @param in_reponse * @return */ @SuppressWarnings({ "deprecation", "unchecked" }) public ActionForward uploadCsvFile(ActionMapping mapping, ActionForm actForm, HttpServletRequest request, HttpServletResponse in_reponse) { ActionMessages errors = new ActionMessages(); ActionMessages messages = new ActionMessages(); try { CreateShippingFileForm form = (CreateShippingFileForm) actForm; // Parameters submitted by form String currentProposalCode = (String) request.getSession().getAttribute(Constants.PROPOSAL_CODE); String currentProposalNumber = (String) request.getSession().getAttribute(Constants.PROPOSAL_NUMBER); Integer proposalId = (Integer) request.getSession().getAttribute(Constants.PROPOSAL_ID); boolean errorFile = false; Proposal3VO proposalVO = proposalService.findByPk(proposalId); List<LabContact3VO> listLabContacts = labContactService.findFiltered(proposalId, null); LabContact3VO shippingLabContactVO = null; if (listLabContacts != null && listLabContacts.size() > 0) { shippingLabContactVO = listLabContacts.get(0); } else { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.upload", "No labConctact found")); errorFile = true; } List<String> allowedSpaceGroups = (List<String>) request.getSession() .getAttribute(Constants.ISPYB_ALLOWED_SPACEGROUPS_LIST); String fieldSeparator = form.getFieldSeparator(); String textSeparator = form.getTextSeparator(); char fieldSep = fieldSeparator.charAt(0); char textSep = ' '; if (textSeparator.length() > 0) textSep = textSeparator.charAt(0); String uploadedFileName; String realCSVPath; List<Shipping3VO> listShippingCreated = new ArrayList<Shipping3VO>(); List<Dewar3VO> listDewarCreated = new ArrayList<Dewar3VO>(); List<Container3VO> listContainerCreated = new ArrayList<Container3VO>(); // List<Crystal3VO> listCrystalCreated = new ArrayList<Crystal3VO>(); List<Crystal3VO> listCrystalCreated = crystalService.findByProposalId(proposalId); List<DiffractionPlan3VO> listDifPlanCreated = new ArrayList<DiffractionPlan3VO>(); List<BLSample3VO> listSampleCreated = new ArrayList<BLSample3VO>(); if (request != null) { uploadedFileName = form.getRequestFile().getFileName(); if (uploadedFileName.equals("")) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.empty")); errorFile = true; } else if (!uploadedFileName.endsWith(".csv")) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.format")); errorFile = true; } if (!errorFile) { realCSVPath = request.getRealPath("/") + "/tmp/" + uploadedFileName; // Write the received file to tmp directory FormFile f = form.getRequestFile(); InputStream in = f.getInputStream(); File outputFile = new File(realCSVPath); if (outputFile.exists()) outputFile.delete(); FileOutputStream out = new FileOutputStream(outputFile); while (in.available() != 0) { out.write(in.read()); out.flush(); } out.flush(); out.close(); // received file Reader inFile = new FileReader(realCSVPath); LOG.info(" ---[uploadFile] Upload Shipment csv "); CSVStrategy csvStrategy = new CSVStrategy(fieldSep, textSep, CSVStrategy.COMMENTS_DISABLED); CSVParser parser = new CSVParser(inFile, csvStrategy); String[][] values = parser.getAllValues(); int nbRows = values.length; boolean isError = false; for (int i = 0; i < nbRows; i++) { int nbCol = values[i].length; if (nbCol != NB_COL) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The number of columns is incorrect (" + nbCol + " instead of " + NB_COL + ")")); isError = true; break; } int j = 0; // proposalCode & proposalNumber String proposalCode = values[i][j++]; String proposalNumber = values[i][j++]; if (proposalCode == null || proposalNumber == null || !(proposalCode.equalsIgnoreCase(currentProposalCode)) || !(proposalNumber.equals(currentProposalNumber))) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The proposal is incorrect line " + (i + 1))); isError = true; break; } // visitNumber j++; // shippingName String shippingName = values[i][j++]; if (shippingName == null || shippingName.trim().length() == 0 || shippingName.length() > MAX_SHIPPING_NAME) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The shipping name is incorrect line " + (i + 1) + " (required and < " + MAX_SHIPPING_NAME + " characters)")); isError = true; break; } // dewarCode String dewarCode = values[i][j++]; if (dewarCode == null || dewarCode.trim().length() == 0 || dewarCode.length() > MAX_DEWAR_CODE) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The dewar code is incorrect line " + (i + 1) + " (required and < " + MAX_DEWAR_CODE + " characters)")); isError = true; break; } // containerCode String containerCode = values[i][j++]; if (containerCode == null || containerCode.trim().length() == 0 || containerCode.length() > MAX_CONTAINER_CODE) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The container code is incorrect line " + (i + 1) + " (required and < " + MAX_CONTAINER_CODE + " characters)")); isError = true; break; } // preObsResolution String preObsResolutionS = values[i][j++]; Double preObsResolution = null; if (preObsResolutionS == null || preObsResolutionS.trim().length() != 0) { try { preObsResolution = Double.parseDouble(preObsResolutionS); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for preObsResolution line " + (i + 1))); isError = true; break; } } // neededResolution String neededResolutionS = values[i][j++]; Double neededResolution = null; if (neededResolutionS == null || neededResolutionS.trim().length() != 0) { try { neededResolution = Double.parseDouble(neededResolutionS); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for neededResolution line " + (i + 1))); isError = true; break; } } // oscillationRange String oscillationRangeS = values[i][j++]; Double oscillationRange = null; if (oscillationRangeS == null || oscillationRangeS.trim().length() != 0) { try { oscillationRange = Double.parseDouble(oscillationRangeS); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for oscillationRange line " + (i + 1))); isError = true; break; } } // proteinAcronym String proteinAcronym = values[i][j++]; Protein3VO protein = null; if (proteinAcronym == null || proteinAcronym.trim().length() == 0) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The protein Acronym is required line " + (i + 1))); isError = true; break; } List<Protein3VO> proteinTab = proteinService.findByAcronymAndProposalId(proposalId, proteinAcronym); if (proteinTab == null || proteinTab.size() == 0) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( "error.user.shipping.upload.file.data", "Protein " + proteinAcronym + " can not be found in ISPyB, line " + (i + 1))); isError = true; break; } else { protein = proteinTab.get(0); } // proteinName String proteinName = values[i][j++]; if (proteinName == null || proteinName.trim().length() == 0 || !protein.getName().equalsIgnoreCase(proteinName)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( "error.user.shipping.upload.file.data", "The protein name is incorrect line " + (i + 1) + " (required and must correspond to the proteinAcronym). The expected proteinName is " + protein.getName())); isError = true; break; } // spaceGroup String spaceGroup = values[i][j++]; if (spaceGroup != null && !spaceGroup.equals("") && !allowedSpaceGroups.contains(spaceGroup.toUpperCase())) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The space group can not be found in ISPyB line " + (i + 1))); isError = true; break; } // sampleBarcode String sampleBarcode = values[i][j++]; if (sampleBarcode != null && sampleBarcode.length() > MAX_SAMPLE_BARCODE) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The sample barcode is incorrect line " + (i + 1) + " (< " + MAX_SAMPLE_BARCODE + " characters)")); isError = true; break; } // sampleName String sampleName = values[i][j++]; if (sampleName == null || sampleName.trim().length() == 0 || sampleName.length() > MAX_SAMPLE_NAME || !sampleName .matches(Constants.MASK_BASIC_CHARACTERS_WITH_DASH_UNDERSCORE_NO_SPACE)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( "error.user.shipping.upload.file.data", "The sample name is incorrect line " + (i + 1) + " (required and < " + MAX_SAMPLE_NAME + " characters, unique name for the protein acronym, must contain only a-z, A-Z or 0-9 or - or _ characters.)")); isError = true; break; } // samplePosition String samplePos = values[i][j++]; int samplePosition = 0; try { samplePosition = Integer.parseInt(samplePos); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The sample position is incorrect: " + samplePos + ", line " + (i + 1) + " (required number between 1 and 10)")); isError = true; break; } if (samplePosition < 1 || samplePosition > Constants.BASKET_SAMPLE_CAPACITY) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The sample position is incorrect: " + samplePos + ", line " + (i + 1) + " (required number between 1 and 10)")); isError = true; break; } // sample comments String sampleComments = values[i][j++]; if (sampleComments != null && sampleComments.length() > MAX_SAMPLE_COMMENTS) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The sample comments is incorrect line " + (i + 1) + " ( < " + MAX_SAMPLE_COMMENTS + " characters)")); isError = true; break; } // cell_a String cellA = values[i][j++]; Double cell_a = null; if (cellA == null || cellA.trim().length() != 0) { try { cell_a = Double.parseDouble(cellA); } catch (NumberFormatException e) { isError = true; errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for cell_a line " + (i + 1))); break; } } // cell_b String cellB = values[i][j++]; Double cell_b = null; if (cellB == null || cellB.trim().length() != 0) { try { cell_b = Double.parseDouble(cellB); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for cell_b line " + (i + 1))); isError = true; break; } } // cell_c String cellC = values[i][j++]; Double cell_c = null; if (cellC == null || cellC.trim().length() != 0) { try { cell_c = Double.parseDouble(cellC); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for cell_c line " + (i + 1))); isError = true; break; } } // cell_alpha String cellAlpha = values[i][j++]; Double cell_alpha = null; if (cellAlpha == null || cellAlpha.trim().length() != 0) { try { cell_alpha = Double.parseDouble(cellAlpha); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for cell_alpha line " + (i + 1))); isError = true; break; } } // cell_beta String cellBeta = values[i][j++]; Double cell_beta = null; if (cellBeta == null || cellBeta.trim().length() != 0) { try { cell_beta = Double.parseDouble(cellBeta); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for cell_beta line " + (i + 1))); isError = true; break; } } // cell_gamma String cellGamma = values[i][j++]; Double cell_gamma = null; if (cellGamma == null || cellGamma.trim().length() != 0) { try { cell_gamma = Double.parseDouble(cellGamma); } catch (NumberFormatException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "Wrong fromat for cell_gamma line " + (i + 1))); isError = true; break; } } // creation of the objects // Shipping Shipping3VO shippingVO = new Shipping3VO(); shippingVO.setProposalVO(proposalVO); shippingVO.setShippingName(shippingName); shippingVO.setCreationDate(new Date()); shippingVO.setShippingStatus(Constants.SHIPPING_STATUS_OPENED); shippingVO.setTimeStamp(StringUtils.getCurrentTimeStamp()); shippingVO.setShippingType(Constants.DEWAR_TRACKING_SHIPPING_TYPE); shippingVO.setSendingLabContactVO(shippingLabContactVO); shippingVO.setReturnLabContactVO(shippingLabContactVO); Shipping3VO shipment = getShipment(listShippingCreated, shippingVO); if (shipment == null) { shippingVO = shippingService.create(shippingVO); listShippingCreated.add(shippingVO); } else { shippingVO = shipment; } // Dewar Dewar3VO dewarVO = new Dewar3VO(); dewarVO.setShippingVO(shippingVO); dewarVO.setCode(dewarCode); dewarVO.setType(Constants.PARCEL_DEWAR_TYPE); dewarVO.setDewarStatus(Constants.SHIPPING_STATUS_OPENED); dewarVO.setTimeStamp(StringUtils.getCurrentTimeStamp()); dewarVO.setCustomsValue(shippingLabContactVO.getDewarAvgCustomsValue()); dewarVO.setTransportValue(shippingLabContactVO.getDewarAvgTransportValue()); Dewar3VO dewar = getDewar(listDewarCreated, dewarVO); if (dewar == null) { dewarVO = dewarService.create(dewarVO); listDewarCreated.add(dewarVO); } else { dewarVO = dewar; } // Container Container3VO containerVO = new Container3VO(); containerVO.setContainerType("Puck"); containerVO.setCode(containerCode); containerVO.setCapacity(Constants.BASKET_SAMPLE_CAPACITY); containerVO.setTimeStamp(StringUtils.getCurrentTimeStamp()); containerVO.setDewarVO(dewarVO); Container3VO container = getContainer(listContainerCreated, containerVO); if (container == null) { containerVO = containerService.create(containerVO); listContainerCreated.add(containerVO); } else { containerVO = container; } if (isLocationOccInContainer(samplePosition, listSampleCreated, containerVO)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( "error.user.shipping.upload.file.data", "The sample position is incorrect: " + samplePos + ", line " + (i + 1))); isError = true; break; } // DiffractionPlan DiffractionPlan3VO difPlan = new DiffractionPlan3VO(); difPlan.setObservedResolution(preObsResolution); difPlan.setRequiredResolution(neededResolution); difPlan.setExposureTime((double) 0); difPlan.setOscillationRange(oscillationRange); difPlan.setExperimentKind(DEFAULT_EXPERIMENT_TYPE); difPlan = difPlanService.create(difPlan); listDifPlanCreated.add(difPlan); // Crystal Crystal3VO crystalVO = new Crystal3VO(); String crystalID = UUID.randomUUID().toString(); crystalVO.setProteinVO(protein); crystalVO.setCrystalUUID(crystalID); crystalVO.setSpaceGroup(spaceGroup); crystalVO.setName(crystalID); crystalVO.setCellA(cell_a); crystalVO.setCellB(cell_b); crystalVO.setCellC(cell_c); crystalVO.setCellAlpha(cell_alpha); crystalVO.setCellBeta(cell_beta); crystalVO.setCellGamma(cell_gamma); crystalVO.setDiffractionPlanVO(difPlan); if ((crystalVO.getSpaceGroup() == null) || (crystalVO.getSpaceGroup().equals(""))) { crystalVO.setSpaceGroup(DEFAULT_SPACE_GROUP); } Crystal3VO crystal = getCrystal(listCrystalCreated, crystalVO); if (crystal == null) { crystalVO = crystalService.create(crystalVO); listCrystalCreated.add(crystalVO); } else { crystalVO = crystal; } if (!crystalVO.hasCellInfo()) { messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.free", "Warning: the unit cell parameters are not filled for the spaceGroup " + crystalVO.getSpaceGroup() + "!")); } // BLSample BLSample3VO sample = new BLSample3VO(); sample.setCrystalVO(crystalVO); sample.setDiffractionPlanVO(difPlan); sample.setName(sampleName); sample.setCode(sampleBarcode); sample.setLocation("" + samplePosition); sample.setHolderLength(DEFAULT_HOLDER_LENGTH); sample.setLoopLength(DEFAULT_LOOP_LENGTH); sample.setLoopType(DEFAULT_LOOP_TYPE); sample.setWireWidth(DEFAULT_WIRE_WIDTH); sample.setComments(sampleComments); sample.setContainerVO(containerVO); if (isSampleNameAlreadyExist(sampleName, protein, listSampleCreated)) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.user.shipping.upload.file.data", "The sample name already exists: " + sampleName + ", line " + (i + 1))); isError = true; break; } sample = sampleService.create(sample); listSampleCreated.add(sample); } if (isError) { // remove created in db for (Iterator<Shipping3VO> ship = listShippingCreated.iterator(); ship.hasNext();) { Shipping3VO shipVO = ship.next(); shippingService.delete(shipVO); } } else { messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.upload.shipping")); } } } } catch (Exception e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.detail", e.toString())); LOG.error(e.toString()); saveErrors(request, errors); return mapping.findForward("error"); } if (!messages.isEmpty()) saveMessages(request, messages); if (!errors.isEmpty()) saveErrors(request, errors); return display(mapping, actForm, request, in_reponse); }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping("/fileDownload.do") //fileName-??? fileRealName ?? public ModelAndView download(HttpServletRequest request, HttpServletResponse response) throws Exception { String realFileName = request.getParameter("fileName"); String realFileName2 = new String(realFileName.getBytes("utf-8"), "ISO-8859-1"); String oriFileName = request.getParameter("fileRealName"); request.setAttribute("oriFileName", oriFileName); String dir = request.getRealPath("images/egovframework/board_img/"); File downloadFile = new File(dir + "/" + realFileName); // ? ?? ? return new ModelAndView("downloadView", "downloadFile", downloadFile); }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping(value = "/boardReply.do", method = RequestMethod.POST) public String boardReply(@ModelAttribute("searchVO") SampleDefaultVO searchVO, // BindingResult bindingResult, @RequestPart(required = false, value = "file") List<MultipartFile> imgFile, HttpServletRequest request, @RequestParam("bName") String bName, @RequestParam("bPass") String bPass, @RequestParam("bTitle") String bTitle, @RequestParam("bContent") String bContent, @RequestParam("bUuid") String bUuid, @RequestParam("bNum") int bNum, @RequestParam("bReSeq") int bReSeq, @RequestParam("bSeq") int bSeq, Model model, SessionStatus status ) throws Exception { if (!imgFile.isEmpty()) { String dir = request.getRealPath("images/egovframework/board_img"); System.out.println("dd" + imgFile.size()); for (int i = 0; i < imgFile.size() - 1; i++) { //?/* w ww .j av a 2s .c o m*/ String genId = UUID.randomUUID().toString(); //? String originalFileName = imgFile.get(i).getOriginalFilename(); //? // String saveFileName = genId+"."+originalFileName; String saveFileName = genId; // System.out.println("???="+ originalFileName); // System.out.println("??="+ saveFileName); String savePath = dir + "/" + saveFileName; imgFile.get(i).transferTo(new File(savePath)); SampleVO vo = new SampleVO(); vo.setiOriName(originalFileName); vo.setiFileName(saveFileName); vo.setiSize((int) imgFile.get(i).getSize()); vo.setiUrl(savePath); vo.setiUuid(bUuid); sampleService.uploadImg(vo); status.setComplete(); } } SampleVO samVO = new SampleVO(); samVO.setbName(bName); samVO.setbPass(bPass); samVO.setbTitle(bTitle); samVO.setbContent(bContent); samVO.setbUuid(bUuid); samVO.setbNum(bNum); samVO.setbReSeq(bReSeq); sampleService.insertReply(samVO); SampleVO samVO2 = new SampleVO(); samVO2.setbSeq(bSeq); sampleService.getReply(samVO2); status.setComplete(); // model.addAttribute("main", "goFreebbs.jsp"); return "forward:/egovSampleList.do"; // return "sample/home"; }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping(value = "/boardInsert.do", method = RequestMethod.POST) public String boardInsert(HttpServletRequest request, Model model, @RequestPart(required = false, value = "file") List<MultipartFile> imgFile, @ModelAttribute("searchVO") SampleDefaultVO searchVO, @RequestParam("bName") String bName, @RequestParam("bPass") String bPass, @RequestParam("bTitle") String bTitle, @RequestParam("bContent") String bContent, @RequestParam("bUuid") String bUuid, SessionStatus status ) throws Exception { if (!imgFile.isEmpty()) { String dir = request.getRealPath("images/egovframework/board_img"); System.out.println("dd" + imgFile.size()); for (int i = 0; i < imgFile.size() - 1; i++) { //?/*from w w w. j a v a2s. c o m*/ String genId = UUID.randomUUID().toString(); //? String originalFileName = imgFile.get(i).getOriginalFilename(); //? // String saveFileName = genId+"."+originalFileName; String saveFileName = genId; // System.out.println("???="+ originalFileName); // System.out.println("??="+ saveFileName); String savePath = dir + "/" + saveFileName; imgFile.get(i).transferTo(new File(savePath)); SampleVO vo = new SampleVO(); vo.setiOriName(originalFileName); vo.setiFileName(saveFileName); vo.setiSize((int) imgFile.get(i).getSize()); vo.setiUrl(savePath); vo.setiUuid(bUuid); sampleService.uploadImg(vo); status.setComplete(); } } ////////// SampleVO samVO = new SampleVO(); samVO.setbName(bName); samVO.setbPass(bPass); samVO.setbTitle(bTitle); samVO.setbContent(bContent); samVO.setbUuid(bUuid); sampleService.insertSample(samVO); status.setComplete(); // model.addAttribute("main", "egovSampleList.jsp"); // return "sample/home"; return "forward:/egovSampleList.do"; }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping(value = "/qnaInsert.do", method = RequestMethod.POST) public String qnaInsert(HttpServletRequest request, Model model, @RequestPart(required = false, value = "file") List<MultipartFile> imgFile, @ModelAttribute("searchVO") SampleDefaultVO searchVO, @RequestParam("qName") String qName, @RequestParam("qPass") String qPass, @RequestParam("qTitle") String qTitle, @RequestParam("qContent") String qContent, @RequestParam("qUuid") String qUuid, @RequestParam("selectedId") int selectedId, //? seq @RequestParam("type") String type, SessionStatus status/* w w w . ja v a 2 s .com*/ ) throws Exception { if (!imgFile.isEmpty()) { String dir = request.getRealPath("images/egovframework/board_img"); System.out.println("dd" + imgFile.size()); for (int i = 0; i < imgFile.size() - 1; i++) { //? String genId = UUID.randomUUID().toString(); //? String originalFileName = imgFile.get(i).getOriginalFilename(); //? // String saveFileName = genId+"."+originalFileName; String saveFileName = genId; String savePath = dir + "/" + saveFileName; imgFile.get(i).transferTo(new File(savePath)); SampleVO vo = new SampleVO(); vo.setiOriName(originalFileName); vo.setiFileName(saveFileName); vo.setiSize((int) imgFile.get(i).getSize()); vo.setiUrl(savePath); vo.setiUuid(qUuid); sampleService.uploadImg(vo); status.setComplete(); } } ////////// // ? String buy = ""; int orderSeetPSeq = 0; OrderSeetVO vo = new OrderSeetVO(); vo.setO_id(qName); List<OrderSeetVO> orderSeetVOList = sampleService.selectOrderSeetbyId(vo); for (int i = 0; i < orderSeetVOList.size(); i++) { orderSeetPSeq = orderSeetVOList.get(i).getO_pseq(); if (selectedId == orderSeetPSeq) { buy = ""; } } QnaVO qnaVO = new QnaVO(qName, qTitle, qContent, qUuid, qPass, type, buy, selectedId); sampleService.insertQnA(qnaVO); status.setComplete(); // model.addAttribute("main", "egovSampleList.jsp"); // return "sample/home"; return "forward:/selectProduct.do?searchKeyword2=not&pageIndex=1&selectedId=" + selectedId + "#qna"; }
From source file:egovframework.example.sample.web.EgovSampleController.java
@RequestMapping("/fileUploadX.do") public void fileUploadX(HttpServletRequest request, HttpServletResponse response, SessionStatus status) throws Exception { //System.out.println(" ? uuid--"+request.getParameter("uuid")); String chkType = request.getHeader("Content-Type"); if (chkType == null) { return;/*w w w . j a va 2 s.com*/ } request.setCharacterEncoding("utf-8"); String contextRealPath = request.getSession().getServletContext().getRealPath("/"); String PATH = request.getParameter("PATH"); String savePath = contextRealPath + PATH; // System.out.println("savePath------@@-----"+savePath); // int maxSize = 500 * 1024 * 1024; // ? ? 500MB() PlatformData resData = new PlatformData(); VariableList resVarList = resData.getVariableList(); String sMsg = " A "; try { MultipartHttpServletRequest msReq = (MultipartHttpServletRequest) request; Iterator<String> filesd = msReq.getFileNames(); String dir = request.getRealPath("images/egovframework/board_img"); while (filesd.hasNext()) { sMsg += "D "; //String name = (String)files.nextElement(); String name = filesd.next(); // System.out.println("? ^^-----"+name); MultipartFile mfile = msReq.getFile(name); //? String genId = UUID.randomUUID().toString(); //? String originalFileName = mfile.getOriginalFilename(); //? String saveFileName = genId; // System.out.println("???="+ originalFileName); System.out.println("??=" + saveFileName); String savePathh = dir + "/" + saveFileName; mfile.transferTo(new File(savePathh)); System.out.println(name + "??"); System.out.println("? ?-" + genId); //?? SampleVO vo = new SampleVO(); vo.setiOriName(originalFileName); vo.setiFileName(saveFileName); vo.setiSize((int) mfile.getSize()); vo.setiUrl(savePathh); vo.setiUuid(request.getParameter("uuid")); sampleService.uploadImg(vo); status.setComplete(); } resVarList.add("ErrorCode", 200); resVarList.add("ErrorMsg", "SUCC"); } catch (Exception e) { resVarList.add("ErrorCode", 500); resVarList.add("ErrorMsg", sMsg + " " + e); } HttpPlatformResponse res = new HttpPlatformResponse(response); res.setData(resData); res.sendData(); }