public void saveDocumentMapping(JSONObject jobj) throws ServiceException { try { Docmap docMap = new Docmap(); if (jobj.has("docid") && !StringUtil.isNullOrEmpty(jobj.getString("docid"))) { Docs doc = (Docs) hibernateTemplate.get(Docs.class, jobj.getString("docid")); docMap.setDocid(doc); if (jobj.has("companyid") && !StringUtil.isNullOrEmpty(jobj.getString("companyid"))) { Company company = (Company) hibernateTemplate.get(Company.class, jobj.getString("companyid")); doc.setCompany(company); } if (jobj.has("userid") && !StringUtil.isNullOrEmpty(jobj.getString("userid"))) { User user = (User) hibernateTemplate.get(User.class, jobj.getString("userid")); doc.setUserid(user); } } if (jobj.has("refid")) { docMap.setRecid(jobj.getString("refid")); } if (jobj.has("map")) { docMap.setRelatedto(jobj.getString("map")); } hibernateTemplate.save(docMap); } catch (Exception ex) { throw ServiceException.FAILURE("documentDAOImpl.saveDocumentMapping", ex); } }
public KwlReturnObject addTag(HashMap<String, Object> requestParams) throws ServiceException { String tag = requestParams.containsKey("tag") ? requestParams.get("tag").toString() : ""; List ll = new ArrayList(); int dl = 0; try { String tags[] = tag.split(",,"); Docs c = (Docs) hibernateTemplate.get(Docs.class, tags[0]); c.setTags(tags[1]); ll.add(c); } catch (Exception ex) { throw ServiceException.FAILURE("documentDAOImpl.addTag", ex); } return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl); }
public KwlReturnObject uploadFile(FileItem fi, String userid) throws ServiceException { Docs docObj = new Docs(); List ll = new ArrayList(); int dl = 0; try { String fileName = new String(fi.getName().getBytes(), "UTF8"); String Ext = ""; String a = ""; if (fileName.contains(".")) { Ext = fileName.substring(fileName.indexOf(".") + 1, fileName.length()); a = Ext.toUpperCase(); } User userObj = (User) hibernateTemplate.get(User.class, userid); docObj.setDocname(fileName); docObj.setUserid(userObj); docObj.setStorename(""); docObj.setDoctype(a + " " + "File"); docObj.setUploadedon(new Date()); docObj.setStorageindex(1); docObj.setDocsize(fi.getSize() + ""); hibernateTemplate.save(docObj); String fileid = docObj.getDocid(); if (Ext.length() > 0) { fileid = fileid + Ext; } docObj.setStorename(fileid); hibernateTemplate.update(docObj); ll.add(docObj); // String temp = "/home/trainee"; String temp = storageHandlerImplObj.GetDocStorePath(); uploadFile(fi, temp, fileid); } catch (Exception e) { throw ServiceException.FAILURE(e.getMessage(), e); } return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl); }
public Hashtable getDocumentDownloadHash(List ll) { Hashtable<String, String> ht = new Hashtable<String, String>(); try { Iterator ite = ll.iterator(); while (ite.hasNext()) { com.krawler.common.admin.Docmap cDocMap = (com.krawler.common.admin.Docmap) ite.next(); ht.put("relatedto", cDocMap.getRelatedto()); ht.put("recid", cDocMap.getRecid()); com.krawler.common.admin.Docs t = cDocMap.getDocid(); ht.put("docid", t.getDocid()); ht.put("Name", t.getDocname()); ht.put("Size", t.getDocsize()); ht.put("Type", t.getDoctype()); ht.put("svnname", t.getStorename()); ht.put("storeindex", String.valueOf(t.getStorageindex())); } } catch (Exception e) { System.out.println(e.getMessage()); } return ht; }
public ModelAndView addDocuments(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = new JSONObject(); JSONObject myjobj = new JSONObject(); List fileItems = null; KwlReturnObject kmsg = null; String auditAction = ""; boolean applicant = false; String id = java.util.UUID.randomUUID().toString(); PrintWriter out = null; // Create transaction DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("JE_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txnManager.getTransaction(def); try { response.setContentType("text/html;charset=UTF-8"); out = response.getWriter(); String userid = sessionHandlerImplObj.getUserid(request); String map = request.getParameter("mapid"); HashMap<String, String> arrParam = new HashMap<String, String>(); boolean fileUpload = false; String docdesc; ArrayList<FileItem> fi = new ArrayList<FileItem>(); if (request.getParameter("fileAdd") != null) { DiskFileUpload fu = new DiskFileUpload(); fileItems = fu.parseRequest(request); documentDAOObj.parseRequest(fileItems, arrParam, fi, fileUpload); arrParam.put("IsIE", request.getParameter("IsIE")); if (arrParam.get("applicantid").equalsIgnoreCase("applicant")) { applicant = true; userid = arrParam.get("refid"); } if (StringUtil.isNullOrEmpty((String) arrParam.get("docdesc")) == false) { docdesc = (String) arrParam.get("docdesc"); } } for (int cnt = 0; cnt < fi.size(); cnt++) { String docID; if (applicant) { kmsg = hrmsExtApplDocsDAOObj.uploadFile( fi.get(cnt), userid, arrParam, profileHandlerDAOObj.getUserFullName(sessionHandlerImplObj.getUserid(request))); HrmsDocs doc = (HrmsDocs) kmsg.getEntityList().get(0); docID = doc.getDocid(); } else { kmsg = documentDAOObj.uploadFile(fi.get(cnt), userid, arrParam); Docs doc = (Docs) kmsg.getEntityList().get(0); docID = doc.getDocid(); } String companyID = sessionHandlerImplObj.getCompanyid(request); String userID = sessionHandlerImplObj.getUserid(request); String refid = arrParam.get("refid"); jobj.put("userid", userID); jobj.put("docid", docID); jobj.put("companyid", companyID); jobj.put("id", id); jobj.put("map", map); jobj.put("refid", refid); if (arrParam.get("applicantid").equalsIgnoreCase("applicant")) { hrmsExtApplDocsDAOObj.saveDocumentMapping(jobj); } else { documentDAOObj.saveDocumentMapping(jobj); } } myjobj.put("ID", id); txnManager.commit(status); } catch (Exception e) { System.out.println(e.getMessage()); txnManager.rollback(status); } finally { out.close(); } return new ModelAndView("jsonView", "model", myjobj.toString()); }