Guest User

Untitled

a guest
Apr 20th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 89.06 KB | None | 0 0
  1. package com.taashee.controller;
  2. import java.io.BufferedOutputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.OutputStream;
  8. import java.io.PrintWriter;
  9. import java.net.URLDecoder;
  10. import java.nio.file.Files;
  11. import java.text.SimpleDateFormat;
  12. import java.util.ArrayList;
  13. import java.util.Date;
  14. import java.util.LinkedHashSet;
  15. import java.util.LinkedList;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.Set;
  19. import java.util.TreeMap;
  20. import java.util.TreeSet;
  21.  
  22. import javax.servlet.ServletConfig;
  23. import javax.servlet.ServletContext;
  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import javax.servlet.http.HttpSession;
  27. import javax.validation.Valid;
  28.  
  29. import org.apache.commons.httpclient.HttpClient;
  30. import org.apache.commons.httpclient.HttpException;
  31. import org.apache.commons.httpclient.HttpStatus;
  32. import org.apache.commons.httpclient.methods.GetMethod;
  33. import org.apache.commons.httpclient.methods.PostMethod;
  34. import org.apache.commons.httpclient.methods.StringRequestEntity;
  35. import org.apache.commons.httpclient.methods.multipart.FilePart;
  36. import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
  37. import org.apache.commons.httpclient.methods.multipart.Part;
  38. import org.apache.commons.httpclient.methods.multipart.StringPart;
  39. import org.apache.commons.net.PrintCommandListener;
  40. import org.apache.commons.net.ftp.FTP;
  41. import org.apache.commons.net.ftp.FTPClient;
  42. import org.apache.commons.net.ftp.FTPFile;
  43. import org.apache.commons.net.ftp.FTPReply;
  44. import org.json.JSONArray;
  45. import org.json.JSONObject;
  46. import org.springframework.beans.factory.annotation.Autowired;
  47. import org.springframework.beans.factory.annotation.Value;
  48. import org.springframework.beans.propertyeditors.CustomDateEditor;
  49. import org.springframework.stereotype.Controller;
  50. import org.springframework.transaction.annotation.Transactional;
  51. import org.springframework.transaction.interceptor.TransactionInterceptor;
  52. import org.springframework.ui.Model;
  53. import org.springframework.validation.BindingResult;
  54. import org.springframework.web.bind.WebDataBinder;
  55. import org.springframework.web.bind.annotation.InitBinder;
  56. import org.springframework.web.bind.annotation.ModelAttribute;
  57. import org.springframework.web.bind.annotation.RequestBody;
  58. import org.springframework.web.bind.annotation.RequestMapping;
  59. import org.springframework.web.bind.annotation.RequestMethod;
  60. import org.springframework.web.bind.annotation.RequestParam;
  61. import org.springframework.web.bind.annotation.ResponseBody;
  62. import org.springframework.web.context.request.WebRequest;
  63. import org.springframework.web.multipart.MultipartFile;
  64. import org.springframework.web.servlet.ModelAndView;
  65.  
  66. import com.taashee.dao.VendorDAO;
  67. import com.taashee.globalexception.CustomGenericException;
  68. import com.taashee.service.CommonService;
  69. import com.taashee.service.GridEmployeeService;
  70. import com.taashee.service.VendorService;
  71. import com.taashee.vo.Coordinator;
  72.  
  73. import com.taashee.vo.Document;
  74. import com.taashee.vo.FtpFile;
  75. import com.taashee.vo.GridEmployee;
  76. import com.taashee.vo.MasterDetails;
  77. import com.taashee.vo.MasterEntry;
  78. import com.taashee.vo.RTN;
  79. import com.taashee.vo.RTNType;
  80. import com.taashee.vo.Vendor;
  81. import com.taashee.vo1.FileDetails;
  82. import com.taashee.vo1.Workflow;
  83. @Controller
  84. public class VendorController {
  85.  
  86. //-------------------------------------
  87. @Autowired
  88. private VendorDAO vendao;
  89. //-------------------------------------
  90.  
  91. @Autowired
  92. private VendorService venser;
  93. @Autowired
  94. private GridEmployeeService empser;
  95. @Autowired
  96. ServletContext servletContext;
  97. @Autowired
  98. ServletConfig config;
  99. @Autowired
  100. GridEmployeeService empservice;
  101. @Autowired
  102. CommonService comnsevice;
  103.  
  104. @Value("${alfresco.category_root_children}")
  105. private String alfresco_category_root_children;
  106. @Value("${alfresco.site_folders_custom}")
  107. private String alfresco_site_folders_custom;
  108. @Value("${alferesco.ta_categories}")
  109. private String alferesco_ta_categories;
  110. @Value("${alfresco.forms_picker}")
  111. private String alfresco_forms_picker;
  112. // alfresco.folder_exists
  113. @Value("${alfresco.folder_exists}")
  114. private String alfresco_folder_exists;
  115.  
  116. //Anurag Revision docs API
  117. @Value("${alfresco.document_uploadR}")
  118. private String alfresco_document_uploadR;
  119. @Value("${alfresco.folder_details}")
  120. private String alfresco_folder_details;
  121.  
  122. @Value("${alfresco.insert_nodeRef}")
  123. private String alfresco_insert_nodeRef;
  124.  
  125. @Value("${alfresco.people}")
  126. private String alfresco_people;
  127. @Value("${alfresco.tl_fileupload}")
  128. private String alfresco_tl_fileupload;
  129. @Value("${alfresco.ss_fileupload}")
  130. private String alfresco_ss_fileupload;
  131. @Value("${alfresco.document_upload}")
  132. private String alfresco_document_upload;
  133. @Value("${alfresco.login}")
  134. private String alfresco_login;
  135. @Value("${alfresco.formpicker_workspace_spacesstore}")
  136. private String alfresco_formpicker_workspace_spacesstore;
  137. @Value("${alfresco.nodes_treenode}")
  138. private String alfresco_nodes_treenode;
  139. //ftp values
  140. @Value("${alfresco.mailserverip}")
  141. private String alfresco_mailserverip;
  142. @Value("${ftp.username}")
  143. private String ftp_username;
  144. @Value("${ftp.password}")
  145. private String ftp_password;
  146.  
  147.  
  148.  
  149.  
  150. String sitename;
  151. String description;
  152. String noderefId;
  153.  
  154. @InitBinder
  155. public void initBinder(WebDataBinder binder) {
  156.  
  157. // binder.setDisallowedFields(new String[]{"experience","dateofbirth"});
  158. SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd");
  159. binder.registerCustomEditor(Date.class, "registereddate", new CustomDateEditor(sfd, false));
  160. binder.registerCustomEditor(Date.class, "CreatedDate", new CustomDateEditor(sfd, false));
  161.  
  162. }
  163.  
  164.  
  165. /****************************** Navigates to Vendor Registration Page *******************************
  166. *
  167. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  168. * Status :: Not in use
  169. * Inputs :: -
  170. * Output :: Navigates to Vendor Registration Page
  171. */
  172. @RequestMapping(value = "/vendorregistration.tls", method = RequestMethod.GET)
  173. public String ReDirectRegistration() {
  174.  
  175. return "VendorRegistration";
  176. }
  177.  
  178.  
  179. /*
  180. *//******************************To Delete Document Permanently*******************************
  181. *
  182. * Author @ Ramesh K, Written on 07-02-2018 12:00:00,
  183. * Status :: In use
  184. * Inputs :: rtnid
  185. * Output :: status
  186. *//*
  187.  
  188. @ResponseBody
  189. @RequestMapping(value = "/documentDeletion.vendor", method = RequestMethod.POST)
  190. public String deleteDocument(@RequestParam(value = "documentid") long documentid, Model model, WebRequest wr)
  191. throws HttpException, IOException {
  192. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  193. System.out.println("documentDeletion now working");
  194.  
  195.  
  196. boolean flag=venser.deleteDocument(documentid);
  197.  
  198.  
  199. if (flag)
  200. {
  201. System.out.println("flag:- "+ flag);
  202.  
  203.  
  204.  
  205.  
  206. return "true";
  207. }
  208.  
  209.  
  210. else {
  211. System.out.println("flag:- "+ flag);
  212. return "500,DocumentDeletion";
  213. }
  214.  
  215. }
  216. else {
  217. model.addAttribute("Message", "500,SessionExpiry");
  218. return "login";
  219.  
  220. }
  221. }
  222. */
  223.  
  224. /****************************** Navigates to Documents Submission Page *******************************
  225. *
  226. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  227. * Status :: in use
  228. * Inputs :: -
  229. * Output :: Navigates to Document Submission Page
  230. */
  231. @RequestMapping(value = "/documentSubmission.grid", method = RequestMethod.GET)
  232. public String documentSubmission(WebRequest wr, Model model) {
  233.  
  234. if (wr.getAttribute("vendor", WebRequest.SCOPE_SESSION) != null) {
  235.  
  236. return "DocumentSubmission";
  237. }
  238. model.addAttribute("Message", "500,SessionExpiry");
  239. return "login";
  240.  
  241. }
  242.  
  243.  
  244. /****************************** Navigates to Documents Planner Page *******************************
  245. *
  246. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  247. * Status :: in use
  248. * Inputs :: -
  249. * Output :: Navigates to Documents Planner Page
  250. */
  251. @RequestMapping(value = "/documentplanner.vendor", method = RequestMethod.GET)
  252. public String documentPlanner(WebRequest wr, Model model) {
  253.  
  254. // if(wr.getAttribute("vendor", WebRequest.SCOPE_SESSION)!=null){
  255.  
  256. return "DocumentPlanner";
  257. // }
  258. // model.addAttribute("Message","500,SessionExpiry");
  259. /// return "login";
  260.  
  261. }
  262.  
  263.  
  264. /****************************** Will fetch the data of existing stations of an RTN *******************************
  265. *
  266. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  267. * Status :: Not in use
  268. * Inputs :: -
  269. * Output :: Navigates to Vendor Registration Page
  270. */
  271. public Set<String> getListOfExistingStations(String rtn, WebRequest wr) {
  272.  
  273. if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  274.  
  275. Set<String> stations = new TreeSet<String>();
  276. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  277. HttpClient client = new HttpClient();
  278. GetMethod createSitePost = new GetMethod(
  279. alfresco_site_folders_custom + "?siteName=" + rtn + "&alf_ticket=" + employee.getAlf_ticket());
  280. try {
  281.  
  282. createSitePost.setRequestHeader("Accept", "application/json");
  283. int status = client.executeMethod(createSitePost);
  284. if (status == HttpStatus.SC_OK) {
  285. //System.out.println(">>>>>>>>>>>" + createSitePost.getResponseBodyAsString());
  286. JSONObject response = new JSONObject(createSitePost.getResponseBodyAsString());
  287. JSONArray array = response.getJSONArray("data");
  288. for (int i = 0; i < array.length(); i++) {
  289.  
  290. JSONObject obj = array.getJSONObject(i);
  291. stations.add(obj.getString("folderName"));
  292. }
  293. return stations;
  294. } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
  295.  
  296. //System.out.println("internal server error");
  297. return stations;
  298.  
  299. } else {
  300. //System.out.println("Shit happend..");
  301. return stations;
  302. }
  303. } catch (Exception err) {
  304.  
  305. //System.out.println("shit happend in catch");
  306. return stations;
  307. }
  308.  
  309. } else
  310. return null;
  311.  
  312. }
  313.  
  314.  
  315. /****************************** Naviagtes to the Planner Status Page *******************************
  316. *
  317. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  318. * Status :: in use
  319. * Inputs :: -
  320. * Output :: Navigates to Planner Status Page
  321. */
  322. @SuppressWarnings("unchecked")
  323. @RequestMapping(value = "/plannerstatus.vendor", method = RequestMethod.GET)
  324. public String documentsPlannerAprover(WebRequest wr, Model model) {
  325.  
  326. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  327.  
  328. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  329. RTN rtn = empser.getRTN(coordinator.getRtnid());
  330. RTNType rtntype = empser.getRTNType(rtn.getRtnid());
  331. // Coordinator coordinator=empser.getCoordinator(rtn.getRtn());
  332.  
  333.  
  334. long masterId = comnsevice.hasMasterEntry(rtn.getRtnid());
  335. if (masterId <= 0) {
  336.  
  337. MasterEntry masterentry = new MasterEntry();
  338. masterentry.setRtnid(rtn.getRtnid());
  339. masterId = comnsevice.resgisterMasterEntry(masterentry);
  340. }
  341.  
  342. MasterEntry master = empser.getMaster(rtn.getRtnid());
  343.  
  344.  
  345. List<MasterDetails> masterdetails = empser.getMasterDetails(master.getMasterid());
  346. for(MasterDetails masterdetail : masterdetails) {
  347.  
  348.  
  349. int docCount =(int) (masterdetail.getNoOfDocs() - venser.getDocCount(masterdetail.getEntryid()));
  350.  
  351. masterdetail.setDocCount(docCount);
  352.  
  353. //System.out.println("entryID:------------ "+masterdetail.getDocCount());
  354. }
  355.  
  356.  
  357.  
  358.  
  359.  
  360. if (rtntype.getRtntype().equalsIgnoreCase("TL-Conductor")
  361. || rtntype.getRtntype().equalsIgnoreCase("TL-Foundation")
  362. || rtntype.getRtntype().equalsIgnoreCase("TL-Hardware")
  363. || rtntype.getRtntype().equalsIgnoreCase("TL-Insulator")
  364. || rtntype.getRtntype().equalsIgnoreCase("TL-Tower")) {
  365.  
  366. TreeSet<String> columns = new TreeSet<String>();
  367. model.addAttribute("rtn", rtn);
  368. model.addAttribute("masterdetails", masterdetails);
  369. Map<Long, TreeMap<String, String>> entrydata = new TreeMap<Long, TreeMap<String, String>>();
  370. for (MasterDetails masterdetailsentry : masterdetails) {
  371.  
  372. TreeMap<String, String> rowdata = new TreeMap<String, String>();
  373. JSONObject entryobj = new JSONObject(masterdetailsentry.getEntry());
  374. Set<String> keys = entryobj.keySet();
  375. TreeSet<String> sortedkeys = new TreeSet<String>();
  376.  
  377. for (String key : keys) {
  378.  
  379. columns.add(key);
  380. sortedkeys.add(key);
  381. }
  382. for (String key : sortedkeys) {
  383.  
  384. // System.out.println(key+
  385. // "<===================================================================================");
  386. rowdata.put(key, entryobj.getString(key));
  387. }
  388. entrydata.put(masterdetailsentry.getEntryid(), rowdata);
  389.  
  390. }
  391. model.addAttribute("columns", columns);
  392. model.addAttribute("entrydata", entrydata);
  393. model.addAttribute("coordinator", coordinator);
  394. model.addAttribute("master", master);
  395. model.addAttribute("department", "TL");
  396. return "TLDocumentPlannerStatus";
  397.  
  398. } else {
  399.  
  400. JSONArray kvjson = new JSONArray(getStations("kv", wr, model));
  401. Set<String> kvls = new LinkedHashSet<String>();
  402. for (int q = 0; q < kvjson.length(); q++) {
  403.  
  404. kvls.add(kvjson.getJSONObject(q).getString("name"));
  405. }
  406. model.addAttribute("rtn", rtn);
  407. model.addAttribute("masterdetails", masterdetails);
  408. model.addAttribute("coordinator", coordinator);
  409. model.addAttribute("master", master);
  410. model.addAttribute("kvs", kvls);
  411. //model.addAttribute("docCountPlanner", docCountPlanner);
  412. return "DocumentPlannerStatus";
  413. }
  414. } else {
  415.  
  416. model.addAttribute("Message", "500,SessionExpiry");
  417. return "login";
  418. }
  419. }
  420.  
  421.  
  422. /****************************** Naviagtes to the Planner Status Page *******************************
  423. *
  424. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  425. * Status :: in use
  426. * Inputs :: entryid(Masteerdetails)
  427. * Output :: Navigates to Planner Status Page
  428. */
  429. @RequestMapping(value = "/docdetails.vendor", method = RequestMethod.GET)
  430. public String documentsDetails( WebRequest wr, Model model) {
  431.  
  432. return "redirect:plannerstatus.vendor";
  433. }
  434.  
  435. /****************************** Naviagtes to the Document Details Page *******************************
  436. *
  437. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  438. * Status :: in use
  439. * Inputs :: entryid(Masteerdetails)
  440. * Output :: Navigates to Documents Details Page
  441. */
  442. @SuppressWarnings({ "unchecked" })
  443. @RequestMapping(value = "/docdetails.vendor", method = RequestMethod.POST)
  444. public String documentsDetails(@RequestParam(value = "entryid") long entryid, WebRequest wr, Model model) {
  445.  
  446. ////document upload exceeded code
  447.  
  448. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  449.  
  450. MasterDetails masterdetails = venser.getMasterDetails(entryid);
  451. List<Document> documents = venser.getDocuments(entryid);
  452. int docCount = venser.getDocCount(entryid);
  453. int noOfDocs= (int) masterdetails.getNoOfDocs();
  454. /*System.out.println("Db documents size :: "+documents.size());
  455. System.out.println("Master details values "+masterdetails.getNoOfDocs());
  456. System.out.println("DB no of docs :: "+docCount);
  457. System.out.println("DB Count of docs :: "+noOfDocs);*/
  458. int docCountt =(int) (masterdetails.getNoOfDocs() - venser.getDocCount(masterdetails.getEntryid()));
  459.  
  460. masterdetails.setDocCount(docCountt);
  461.  
  462. if(docCount <= noOfDocs )
  463. {
  464. //System.out.println("NotExceeded");
  465. model.addAttribute("Message", "200,notExceeded");
  466. }
  467. else{
  468. //System.out.println("Exceeded");
  469. model.addAttribute("Message", "500,Exceeded");
  470. }
  471.  
  472. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  473. RTN rtn = empser.getRTN(coordinator.getRtnid());
  474. RTNType rtntype = empser.getRTNType(rtn.getRtnid());
  475.  
  476. model.addAttribute("masterdetails", masterdetails);
  477. model.addAttribute("documents", comnsevice.processDocumentDetails(documents, wr, model));
  478. //System.out.println("documents size :: "+comnsevice.processDocumentDetails(documents, wr, model).size());
  479.  
  480. // if()
  481. if (rtntype.getRtntype().equalsIgnoreCase("TL-Conductor")
  482. || rtntype.getRtntype().equalsIgnoreCase("TL-Foundation")
  483. || rtntype.getRtntype().equalsIgnoreCase("TL-Hardware")
  484. || rtntype.getRtntype().equalsIgnoreCase("TL-Insulator")
  485. || rtntype.getRtntype().equalsIgnoreCase("TL-Tower")
  486. ) {
  487.  
  488. TreeMap<String, String> entrydata = new TreeMap<String, String>();
  489. JSONObject entryjson = new JSONObject(masterdetails.getEntry());
  490. Set<String> keys = entryjson.keySet();
  491. for (String key : keys) {
  492.  
  493. entrydata.put(key, entryjson.getString(key));
  494. }
  495. model.addAttribute("entrydata", entrydata);
  496. if( noOfDocs <= docCount )
  497. {
  498. model.addAttribute("Message","500,Exceeded");
  499. //return "TLDocumentDetails";
  500. }
  501. return "TLDocumentDetails";
  502.  
  503. } else {
  504. if( noOfDocs <= docCount )
  505. {
  506. //System.out.println("Exceded");
  507. model.addAttribute("Message","500,Exceeded");
  508. //return "DocumentsDetails";
  509.  
  510. }
  511. return "DocumentsDetails";
  512. }
  513.  
  514. } else {
  515. model.addAttribute("Message", "500,SessionExpiry");
  516. return "login";
  517. }
  518. }
  519.  
  520.  
  521. /****************************** Naviagtes to the Document Details Page with duplicates check *******************************
  522. *
  523. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  524. * Status :: in use
  525. * Inputs :: -
  526. * Output :: Navigates to Document Deatils Page
  527. */
  528. @SuppressWarnings("unchecked")
  529. @RequestMapping(value = "/duplicatedocdetails.vendor", method = RequestMethod.POST)
  530. public String documentsHasDuplicate(@RequestParam(value = "entryid") long entryid, WebRequest wr, Model model) {
  531.  
  532. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  533.  
  534. MasterDetails masterdetails = venser.getMasterDetails(entryid);
  535. List<Document> documents = venser.getDocuments(entryid);
  536.  
  537.  
  538.  
  539. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  540. RTN rtn = empser.getRTN(coordinator.getRtnid());
  541. RTNType rtntype = empser.getRTNType(rtn.getRtnid());
  542. model.addAttribute("masterdetails", masterdetails);
  543.  
  544. if (rtntype.getRtntype().equalsIgnoreCase("TL-Conductor")
  545. || rtntype.getRtntype().equalsIgnoreCase("TL-Foundation")
  546. || rtntype.getRtntype().equalsIgnoreCase("TL-Hardware")
  547. || rtntype.getRtntype().equalsIgnoreCase("TL-Insulator")
  548. || rtntype.getRtntype().equalsIgnoreCase("TL-Tower")) {
  549.  
  550. TreeMap<String, String> entrydata = new TreeMap<String, String>();
  551. JSONObject entryjson = new JSONObject(masterdetails.getEntry());
  552. Set<String> keys = entryjson.keySet();
  553. for (String key : keys) {
  554.  
  555. entrydata.put(key, entryjson.getString(key));
  556. }
  557. model.addAttribute("documents", documents);
  558. model.addAttribute("entrydata", entrydata);
  559. /*System.out.println(
  560. "Uploading failed Documents length ::::::::::::::::::::::::::::::: " + documents.size());*/
  561. model.addAttribute("Message", "500,DocumentUpload");
  562. return "TLDocumentDetails";
  563.  
  564. } else {
  565.  
  566. model.addAttribute("documents", documents);
  567. //System.out.println("Documents length ::::::::::::::::::::::::::::::: " + documents.size());
  568. model.addAttribute("Message", "500,DocumentUpload");
  569. return "DocumentsDetails";
  570.  
  571. }
  572.  
  573. } else {
  574. model.addAttribute("Message", "500,SessionExpiry");
  575. return "login";
  576. }
  577. }
  578.  
  579.  
  580.  
  581.  
  582. /****************************** Naviagtes to the Documents Submissions Page *******************************
  583. *
  584. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  585. * Status :: in use
  586. * Inputs :: entryid(Masteerdetails)
  587. * Output :: Navigates to Document Submission Page
  588. */
  589. @RequestMapping(value = "/documetupload.vendor", method = RequestMethod.POST)
  590. public String documentUpload(@RequestParam(value = "entryid") long entryid, WebRequest wr, Model model) {
  591.  
  592. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  593.  
  594. MasterDetails masterdetails = venser.getMasterDetails(entryid);
  595. model.addAttribute("masterdetails", masterdetails);
  596.  
  597. return "DocumentSubmission";
  598.  
  599. } else {
  600.  
  601. model.addAttribute("Message", "500,SessionExpiry");
  602. return "login";
  603. }
  604. }
  605.  
  606. /****************************** Naviagtes to the Planner Status Page *******************************
  607. *
  608. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  609. * Status :: in use
  610. * Inputs :: -
  611. * Output :: Navigates to Planner Status Page
  612. */
  613. @RequestMapping(value = "/documetupload.vendor", method = RequestMethod.GET)
  614. public String documentUploadGet(WebRequest wr, Model model) {
  615.  
  616. return "redirect:plannerstatus.vendor";
  617. }
  618.  
  619. /****************************** Naviagtes to the Planner Status Page *******************************
  620. *
  621. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  622. * Status :: in use
  623. * Inputs :: -
  624. * Output :: Navigates to Planner Status Page
  625. */
  626. @RequestMapping(value = "/documetrevision.vendor", method = RequestMethod.GET)
  627. public String documentRevisionGET(WebRequest wr, Model model) {
  628. return "redirect:plannerstatus.vendor";
  629. }
  630.  
  631. /****************************** Naviagtes to the Document Revision Page *******************************
  632. *
  633. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  634. * Status :: in use
  635. * Inputs :: -
  636. * Output :: Navigates to Document Revision Page
  637. */
  638. @RequestMapping(value = "/documetrevision.vendor", method = RequestMethod.POST)
  639. public String documentRevision(@RequestParam(value = "documentid") long documentid, WebRequest wr, Model model) {
  640.  
  641. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  642.  
  643. // MasterDetails masterdetails = venser.getMasterDetails(entryid);
  644. Document document = venser.getDocument(documentid);
  645. model.addAttribute("document", document);
  646.  
  647. return "DocumentRevision";
  648.  
  649. } else {
  650. model.addAttribute("Message", "500,SessionExpiry");
  651. return "login";
  652. }
  653. }
  654.  
  655. /****************************** To Fetch Stations Details of an RTN*******************************
  656. *
  657. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  658. * Status :: in use
  659. * Inputs :: Category(Station)
  660. * Output :: String(JSON Array of Stations)
  661. */
  662. public String getStations(String category, WebRequest wr, Model model) {
  663.  
  664. if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  665.  
  666. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  667. HttpClient client = new HttpClient();
  668. GetMethod createSitePost = new GetMethod(
  669. alfresco_category_root_children + "?alf_ticket=" + employee.getAlf_ticket());
  670. try {
  671.  
  672. createSitePost.setRequestHeader("Accept", "application/json");
  673. int status = client.executeMethod(createSitePost);
  674. if (status == HttpStatus.SC_OK) {
  675.  
  676. JSONObject root = new JSONObject(createSitePost.getResponseBodyAsString());
  677. JSONObject data = root.getJSONObject("data");
  678. JSONArray items = data.getJSONArray("items");
  679. for (int i = 0; i < items.length(); i++) {
  680.  
  681. JSONObject item = (JSONObject) items.get(i);
  682. if (item.getString("name").equalsIgnoreCase(category)) {
  683.  
  684. String noderef = item.getString("nodeRef");
  685. //System.out.println("************ node ref ********* " + noderef);
  686.  
  687. JSONObject childs = new JSONObject(
  688. fetchChilds("category", noderef, employee.getAlf_ticket()));
  689. JSONObject stationsdata = childs.getJSONObject("data");
  690. //System.out.println(stationsdata.getJSONArray("items").length());
  691. return stationsdata.getJSONArray("items").toString();
  692. }
  693. }
  694.  
  695. return null;
  696. } else {
  697.  
  698. return null;
  699.  
  700. }
  701. } catch (Exception err) {
  702.  
  703. err.printStackTrace();
  704. }
  705. } else {
  706.  
  707. model.addAttribute("Message", "Your Session Experied..");
  708. return null;
  709. }
  710. model.addAttribute("Message", "500,SessionExpiry");
  711. return null;
  712. }
  713.  
  714.  
  715. /****************************** To Save the Document Planner Line Items *******************************
  716. *
  717. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  718. * Status :: in use
  719. * Inputs :: String(JSON Object with Document Planner Line Items)
  720. * Output :: boolean
  721. */
  722.  
  723. @Transactional
  724. @ResponseBody
  725. @RequestMapping(value = "/checkDocCount.vendor", method = RequestMethod.POST)
  726. public int checkDocCount(@RequestParam(value = "entryid") long entryid,@RequestParam(value = "entryValu") long entryValu, WebRequest wr, Model model) {
  727.  
  728.  
  729. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  730.  
  731. //System.out.println("entryid"+entryValu);
  732. int docCount =(int) (entryValu - venser.getDocCount(entryid));
  733. //System.out.println("docCount: "+docCount);
  734.  
  735. /*if(docCount > 0 )
  736. {
  737. //System.out.println("docCount else");
  738. return docCount+"notExceeded";
  739.  
  740. }
  741. else{
  742. //System.out.println("docCount IF");
  743. return docCount+"Exceeded";
  744.  
  745. }*/
  746.  
  747. return venser.getDocCount(entryid);
  748. }
  749. return -1;
  750. }
  751.  
  752.  
  753. /****************************** To Save the Document Planner Line Items *******************************
  754. *
  755. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  756. * Status :: in use
  757. * Inputs :: String(JSON Object with Document Planner Line Items)
  758. * Output :: boolean
  759. */
  760. @Transactional
  761. @RequestMapping(value = "savedocumentplanner.vendor", method = RequestMethod.POST, consumes = "application/json")
  762. public @ResponseBody String inviteeCreation(@RequestBody String documentplanner, WebRequest wr, Model model) {
  763.  
  764. //System.out.println("savedocumentplanner");
  765.  
  766. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  767.  
  768. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  769. JSONObject plannerjson = new JSONObject(documentplanner);
  770. JSONArray existingentries = plannerjson.getJSONArray("existingentries");
  771. JSONArray newentries = plannerjson.getJSONArray("newentries");
  772. JSONArray deletedentries = plannerjson.getJSONArray("deletedentries");
  773. //System.out.println("existing ::: " + existingentries.length());
  774. //System.out.println("new ::: " + newentries.length());
  775.  
  776.  
  777. RTNType rtntype = empser.getRTNType(coordinator.getRtnid());
  778. String department = rtntype.getRtntype().split("-")[0];
  779. if (department.equals("CL") || department.equals("EL")
  780. || rtntype.getRtntype().equalsIgnoreCase("SubStation") || rtntype.getRtntype().equals("Cable")
  781. || rtntype.getRtntype().equals("Reactor") || rtntype.getRtntype().equals("Transformer")) {
  782.  
  783. Set<Integer> entries_tobe_deleted = new TreeSet<Integer>();
  784. for (int i = 0; i < deletedentries.length(); i++) {
  785.  
  786. entries_tobe_deleted.add(deletedentries.getInt(i));
  787. }
  788. if (entries_tobe_deleted.size() > 0) {
  789.  
  790. venser.deleteEntries(entries_tobe_deleted);
  791. }
  792.  
  793. long masterid = comnsevice.hasMasterEntry(coordinator.getRtnid());
  794. List<MasterDetails> newmasterdetails = new ArrayList<MasterDetails>();
  795. if (masterid > 0) {
  796.  
  797. String save = plannerjson.getString("save");
  798. if (!save.equals("true")) {
  799.  
  800. venser.updateSubmissionStatus(masterid);
  801. }
  802. List<MasterDetails> existingmasterdetails = new ArrayList<MasterDetails>();
  803.  
  804. for (int i = 0; i < existingentries.length(); i++) {
  805.  
  806.  
  807. JSONObject entry = existingentries.getJSONObject(i);
  808.  
  809.  
  810. int docCount =(int) (entry.getLong("NoOfDocs") - venser.getDocCount(entry.getLong("entryid")));
  811.  
  812.  
  813. if(docCount < 0)
  814. {
  815. //model.addAttribute("message", "500,NotAllow");
  816. return "500,NotAllow";
  817. }
  818. else {
  819. MasterDetails masterdetails = new MasterDetails();
  820. masterdetails.setEntryid(entry.getLong("entryid"));
  821. masterdetails.setRoot(entry.getString("root"));
  822. masterdetails.setCategory(entry.getString("category"));
  823. masterdetails.setSubcategory(entry.getString("subcategory"));
  824. masterdetails.setSubsubcategory(entry.getString("subsubcategory"));
  825. masterdetails.setKvid(entry.getString("kvid"));
  826. masterdetails.setMetakv(entry.getString("metakv"));
  827. masterdetails.setStations(entry.getString("stations"));
  828. masterdetails.setStatusid(8);
  829. masterdetails.setDrawingtype(entry.getString("drawingtype"));
  830. masterdetails.setNoOfDocs(entry.getLong("NoOfDocs"));
  831. existingmasterdetails.add(masterdetails);
  832. }
  833. }
  834. if (existingentries.length() > 0) {
  835.  
  836. venser.updateExistingmasterEntries(existingmasterdetails);
  837. }
  838.  
  839. MasterEntry masterentry = empser.getMaster(coordinator.getRtnid());
  840.  
  841. for (int i = 0; i < newentries.length(); i++) {
  842.  
  843. JSONObject entry = newentries.getJSONObject(i);
  844. //System.out.println("kvid" + entry.getString("kvid"));
  845. //System.out.println("docs" + entry.getLong("NoOfDocs"));
  846. MasterDetails masterdetails = new MasterDetails();
  847. masterdetails.setRoot(entry.getString("root"));
  848. masterdetails.setCategory(entry.getString("category"));
  849. masterdetails.setSubcategory(entry.getString("subcategory"));
  850. masterdetails.setSubsubcategory(entry.getString("subsubcategory"));
  851. masterdetails.setMetakv(entry.getString("metakv"));
  852. masterdetails.setKvid(entry.getString("kvid"));
  853. masterdetails.setStations(entry.getString("stations"));
  854. masterdetails.setStatusid(entry.getLong("statusid"));
  855. masterdetails.setNoOfDocs(entry.getLong("NoOfDocs"));
  856. masterdetails.setDrawingtype(entry.getString("drawingtype"));
  857. masterdetails.setMasterid(masterentry.getMasterid());
  858. newmasterdetails.add(masterdetails);
  859. }
  860. if (newentries.length() > 0) {
  861.  
  862. venser.registerMasterEntries(newmasterdetails);
  863. }
  864. if (newentries.length() > 0 || existingentries.length() > 0) {
  865. venser.updateRTNStatus(coordinator.getRtnid(), "DocTypeModified");
  866. venser.updateMasterEntryStatus(masterentry.getMasterid(), 8);
  867. }
  868.  
  869. } else {
  870.  
  871. MasterEntry masterentry = new MasterEntry();
  872. masterentry.setRtnid(coordinator.getRtnid());
  873. long masterId = comnsevice.resgisterMasterEntry(masterentry);
  874. if (masterId > 0) {
  875.  
  876. for (int i = 0; i < newentries.length(); i++) {
  877.  
  878. JSONObject entry = newentries.getJSONObject(i);
  879. MasterDetails masterdetails = new MasterDetails();
  880. masterdetails.setRoot(entry.getString("root"));
  881. masterdetails.setCategory(entry.getString("category"));
  882. masterdetails.setSubcategory(entry.getString("subcategory"));
  883. masterdetails.setSubsubcategory(entry.getString("subsubcategory"));
  884. masterdetails.setMetakv(entry.getString("metakv"));
  885. masterdetails.setKvid(entry.getString("kvid"));
  886. masterdetails.setStations(entry.getString("stations"));
  887. masterdetails.setStatusid(entry.getLong("statusid"));
  888. masterdetails.setNoOfDocs(entry.getLong("NoOfDocs"));
  889. masterdetails.setDrawingtype(entry.getString("drawingtype"));
  890. masterdetails.setMasterid(masterId);
  891. /*System.out.println(
  892. "masterid ::::::::::::::::::::::::::::::::::::::::::::::::::::::: " + masterId);*/
  893. //System.out.println(" ");
  894. //System.out.println("Planned document is: ="+masterdetails.getNoOfDocs());
  895. //System.out.println(" ");
  896. newmasterdetails.add(masterdetails);
  897. }
  898. if (newentries.length() > 0) {
  899.  
  900. venser.registerMasterEntries(newmasterdetails);
  901. venser.updateRTNStatus(coordinator.getRtnid(), "DocTypeSubmitted");
  902. venser.updateMasterCreatedStatus(masterId);
  903. venser.updateMasterEntryStatus(masterId, 2);
  904. }
  905. }
  906. }
  907. }
  908. if (department.equals("TL")) {
  909.  
  910. Set<Integer> entries_tobe_deleted = new TreeSet<Integer>();
  911. for (int i = 0; i < deletedentries.length(); i++) {
  912.  
  913. entries_tobe_deleted.add(deletedentries.getInt(i));
  914. }
  915. if (entries_tobe_deleted.size() > 0) {
  916.  
  917. venser.deleteEntries(entries_tobe_deleted);
  918. }
  919.  
  920. List<MasterDetails> newmasterdetails = new ArrayList<MasterDetails>();
  921. long masterid = comnsevice.hasMasterEntry(coordinator.getRtnid());
  922. if (masterid > 0) {
  923.  
  924. boolean save = plannerjson.getBoolean("save");
  925. if (!save) {
  926.  
  927. venser.updateSubmissionStatus(masterid);
  928. }
  929. List<MasterDetails> existingmasterdetails = new ArrayList<MasterDetails>();
  930. for (int i = 0; i < existingentries.length(); i++) {
  931.  
  932. MasterDetails masterdetails = new MasterDetails();
  933. JSONObject entry = existingentries.getJSONObject(i);
  934. //System.out.println("hello: "+entry.getLong("docs"));
  935.  
  936. int docCount =(int) (entry.getLong("docs") - venser.getDocCount(entry.getLong("entryid")));
  937.  
  938.  
  939. if(docCount < 0)
  940. {
  941. //model.addAttribute("message", "500,NotAllow");
  942. return "500,NotAllow";
  943. }
  944. else {
  945.  
  946.  
  947. masterdetails.setEntry(entry.getJSONObject("entry").toString().replaceAll("\"", "\\\""));
  948. masterdetails.setEntryid(entry.getLong("entryid"));
  949. masterdetails.setRoot("TL");
  950. masterdetails.setStations(entry.getString("stations"));
  951. masterdetails.setEntry(entry.getJSONObject("entry").toString());
  952. masterdetails.setStatusid(8);
  953. masterdetails.setNoOfDocs(entry.getLong("docs"));
  954. existingmasterdetails.add(masterdetails);
  955. }
  956. }
  957. if (existingentries.length() > 0) {
  958.  
  959. venser.updateTLExistingmasterEntries(existingmasterdetails);
  960. }
  961.  
  962. MasterEntry masterentry = empser.getMaster(coordinator.getRtnid());
  963. //System.out.println(masterentry.getMasterid());
  964. for (int i = 0; i < newentries.length(); i++) {
  965.  
  966. MasterDetails masterdetails = new MasterDetails();
  967. JSONObject entry = newentries.getJSONObject(i);
  968. masterdetails.setEntry(entry.getJSONObject("entry").toString().replaceAll("\"", "\\\""));
  969. masterdetails.setRoot("TL");
  970. masterdetails.setStations(entry.getString("stations"));
  971. masterdetails.setStatusid(entry.getLong("statusid"));
  972. masterdetails.setNoOfDocs(entry.getLong("docs"));
  973. masterdetails.setMasterid(masterentry.getMasterid());
  974. newmasterdetails.add(masterdetails);
  975. }
  976. if (newentries.length() > 0) {
  977.  
  978. venser.registerTLMasterEntries(newmasterdetails);
  979. }
  980. if (newentries.length() > 0 || existingentries.length() > 0) {
  981. venser.updateRTNStatus(coordinator.getRtnid(), "DocTypeModified");
  982. venser.updateMasterEntryStatus(masterentry.getMasterid(), 8);
  983. }
  984.  
  985. } else {
  986. MasterEntry masterentry = new MasterEntry();
  987. masterentry.setRtnid(coordinator.getRtnid());
  988. long masterId = comnsevice.resgisterMasterEntry(masterentry);
  989. if (masterId > 0) {
  990.  
  991. for (int i = 0; i < newentries.length(); i++) {
  992.  
  993. MasterDetails masterdetails = new MasterDetails();
  994. JSONObject entry = newentries.getJSONObject(i);
  995. masterdetails.setEntry(entry.getJSONObject("entry").toString().replaceAll("\"", "\\\""));
  996. masterdetails.setRoot("TL");
  997. masterdetails.setStations(entry.getString("stations"));
  998. masterdetails.setEntry(entry.getJSONObject("entry").toString());
  999. masterdetails.setStatusid(entry.getLong("statusid"));
  1000. masterdetails.setNoOfDocs(entry.getLong("docs"));
  1001. masterdetails.setMasterid(masterId);
  1002. /*System.out.println(
  1003. "masterid ::::::::::::::::::::::::::::::::::::::::::::::::::::::: " + masterId);*/
  1004. newmasterdetails.add(masterdetails);
  1005. }
  1006. if (newentries.length() > 0) {
  1007.  
  1008. venser.registerTLMasterEntries(newmasterdetails);
  1009. venser.updateRTNStatus(coordinator.getRtnid(), "DocTypeSubmitted");
  1010. venser.updateMasterCreatedStatus(masterId);
  1011. venser.updateMasterEntryStatus(masterId, 2);
  1012. }
  1013.  
  1014. }
  1015. }
  1016. }
  1017. }
  1018. return "true";
  1019. }
  1020.  
  1021.  
  1022. /****************************** To Expand the session for Document Planner*******************************
  1023. *
  1024. * Author @ Ramesh K, Written on 19-04-2018 12:00:00,
  1025. * Status :: in use
  1026. * Output :: Naviagtes to Document Plannaer Page
  1027. */
  1028. @RequestMapping(value = "/sessionReload", method = RequestMethod.GET)
  1029. public String getsessionReload(WebRequest wr, Model model, HttpSession session) {
  1030.  
  1031. //session.setMaxInactiveInterval(1*60*60);
  1032.  
  1033.  
  1034.  
  1035. /*System.out.println(
  1036. "*************************************************************************************************************************************");*/
  1037. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  1038.  
  1039. System.out.println("Session time is----- "+session.getMaxInactiveInterval());
  1040.  
  1041. }
  1042. return "ElectricalDocumentPlanner";
  1043. }
  1044.  
  1045. /****************************** To Fetch Category Root Details of an RTN*******************************
  1046. *
  1047. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  1048. * Status :: in use
  1049. * Inputs :: String(JSON Object with Document Planner Line Items)
  1050. * Output :: Naviagtes to Document Plannaer Page
  1051. */
  1052. @RequestMapping(value = "/documentplanner", method = RequestMethod.GET)
  1053. public String getRTNDataForDocumentPlanner(WebRequest wr, Model model, HttpSession session) {
  1054.  
  1055. //session.setMaxInactiveInterval(1*60*60);
  1056.  
  1057. System.out.println("Session time is "+session.getMaxInactiveInterval());
  1058.  
  1059. /*System.out.println(
  1060. "*************************************************************************************************************************************");*/
  1061. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  1062.  
  1063. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  1064. RTN rtn = empservice.getRTN(coordinator.getRtnid());
  1065. model.addAttribute("rtn", rtn.getRtn());
  1066. model.addAttribute("session", session.getMaxInactiveInterval());
  1067. Set<String> stations = (Set<String>) getListOfExistingStations(rtn.getRtn(), wr);
  1068. model.addAttribute("stations", stations);
  1069. JSONArray kvjson = new JSONArray(getStations("kv", wr, model));
  1070. Set<String> kvls = new LinkedHashSet<String>();
  1071. for (int q = 0; q < kvjson.length(); q++) {
  1072.  
  1073. kvls.add(kvjson.getJSONObject(q).getString("name"));
  1074. }
  1075.  
  1076. model.addAttribute("kvvalues", kvls);
  1077. boolean hadenrties = true;
  1078. MasterEntry master = null;
  1079. List<MasterDetails> masterdetails = null;
  1080. try {
  1081.  
  1082. /*System.out.println(
  1083. "RTNid :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" + rtn.getRtnid());*/
  1084. master = empser.getMaster(rtn.getRtnid());
  1085. //System.out.println("Master id" + master.getMasterid());
  1086. masterdetails = empser.getMasterDetails(master.getMasterid());
  1087.  
  1088.  
  1089. for(MasterDetails masterdetail : masterdetails) {
  1090. // System.out.println("entryID:------------ "+masterdetail.getEntryid());
  1091.  
  1092. int docCount =(int) (masterdetail.getNoOfDocs() - venser.getDocCount(masterdetail.getEntryid()));
  1093. //System.out.println("entryID:------------ "+docCount);
  1094. masterdetail.setDocCount(docCount);
  1095.  
  1096. // System.out.println("entryID:------------ "+masterdetail.getDocCount());
  1097. }
  1098.  
  1099.  
  1100. } catch (Exception e) {
  1101.  
  1102. // e.printStackTrace();
  1103.  
  1104. master = null;
  1105. masterdetails = null;
  1106. hadenrties = false;
  1107.  
  1108. }
  1109. comnsevice.fetchAdminAccessToken("admin", "admin", wr);
  1110.  
  1111. model.addAttribute("existingmasterdetails", masterdetails);
  1112. RTNType rtntype = empservice.getRTNType(rtn.getRtnid());
  1113. String rtntypename = rtntype.getRtntype();
  1114. String department = "";
  1115. String departmenttype = "";
  1116. if (rtntypename.equalsIgnoreCase("Substation") || rtntypename.equalsIgnoreCase("Transformer")
  1117. || rtntypename.equalsIgnoreCase("Cable") || rtntypename.equalsIgnoreCase("Reactor")) {
  1118.  
  1119. department = rtntypename;
  1120. } else {
  1121.  
  1122. department = rtntypename.split("-")[0];
  1123. departmenttype = rtntypename.split("-")[1];
  1124.  
  1125. }
  1126.  
  1127. if (department.equalsIgnoreCase("SubStation") || department.equalsIgnoreCase("Reactor")
  1128. || department.equalsIgnoreCase("Cable") || department.equalsIgnoreCase("Transformer")) {
  1129.  
  1130. TreeMap<String, TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>>> overallresponse = new TreeMap<String, TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>>>();
  1131. try {
  1132.  
  1133. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  1134. HttpClient client = new HttpClient();
  1135. GetMethod createSitePost = new GetMethod(alferesco_ta_categories
  1136. + "?path=Departments&recurse=1&alf_ticket=" + employee.getAlf_ticket());
  1137. createSitePost.setRequestHeader("Accept", "application/json");
  1138. int status = client.executeMethod(createSitePost);
  1139. if (status == HttpStatus.SC_OK) {
  1140.  
  1141. JSONObject root = new JSONObject(createSitePost.getResponseBodyAsString());
  1142. JSONArray items = root.getJSONArray("items");
  1143. for (int m = 0; m < items.length(); m++) {
  1144.  
  1145. JSONObject item = (JSONObject) items.get(m);
  1146. //System.out.println("Electrical>>>>>>>" + item.getString("name"));
  1147. if (item.getString("name").equalsIgnoreCase("Electrical")) {
  1148.  
  1149. //System.out.println("Electrical>>>>>>>");
  1150. JSONArray categories = item.getJSONArray("children");
  1151. TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>> response = new TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>>();
  1152. response = venser.SSDocumentBuilder(categories, response, masterdetails, hadenrties);
  1153. model.addAttribute("hasentries", masterdetails.size() > 0);
  1154. overallresponse.put("Electrical", response);
  1155. model.addAttribute("department", "Electrical");
  1156. }
  1157. if (item.getString("name").equalsIgnoreCase("Civil")) {
  1158.  
  1159. //System.out.println("In Civil..");
  1160. JSONArray categories = item.getJSONArray("children");
  1161. TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>> response = new TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>>();
  1162. response = venser.SSDocumentBuilder(categories, response, masterdetails, hadenrties);
  1163. model.addAttribute("hasentries", masterdetails.size() > 0);
  1164. overallresponse.put("Civil", response);
  1165. model.addAttribute("department", "Electrical");
  1166. }
  1167.  
  1168. //System.out.println("*********************NOT matched2***************");
  1169. }
  1170. model.addAttribute("rootcategories", overallresponse);
  1171.  
  1172. return "ElectricalDocumentPlanner";
  1173. }
  1174.  
  1175. } catch (Exception err) {
  1176.  
  1177. err.printStackTrace();
  1178. }
  1179.  
  1180. } else if (department.equals("TL")) {
  1181.  
  1182. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  1183. HttpClient client = new HttpClient();
  1184. GetMethod createSitePost = new GetMethod(
  1185. alferesco_ta_categories + "?path=Departments&recurse=1&alf_ticket=" + employee.getAlf_ticket());
  1186.  
  1187. TreeSet<String> columns = new TreeSet<String>();
  1188. TreeSet<String> sortedkeys = new TreeSet<String>();
  1189. Map<Long, TreeMap<String, String>> entrydata = new TreeMap<Long, TreeMap<String, String>>();
  1190. try {
  1191.  
  1192. createSitePost.setRequestHeader("Accept", "application/json");
  1193. int status = client.executeMethod(createSitePost);
  1194. if (status == HttpStatus.SC_OK) {
  1195.  
  1196. JSONObject root = new JSONObject(createSitePost.getResponseBodyAsString());
  1197. JSONArray items = root.getJSONArray("items");
  1198. for (int m = 0; m < items.length(); m++) {
  1199.  
  1200. JSONObject item = (JSONObject) items.get(m);
  1201. //System.out.println("Electrical>>>>>>>" + item.getString("name"));
  1202. if (item.getString("name").equalsIgnoreCase("TL")) {
  1203.  
  1204.  
  1205. JSONArray categories = item.getJSONArray("children");
  1206. TreeMap<String, Map<String, TreeSet<String>>> tldata = new TreeMap<String, Map<String, TreeSet<String>>>();
  1207. for (int j = 0; j < categories.length(); j++) {
  1208.  
  1209. JSONObject categoryobj = (JSONObject) categories.get(j);
  1210. JSONArray subcategories = categoryobj.getJSONArray("children");
  1211. if (categoryobj.getString("name").equals(departmenttype)) {
  1212.  
  1213. Map<String, TreeSet<String>> fields = new TreeMap<String, TreeSet<String>>();
  1214. for (int k = 0; k < subcategories.length(); k++) {
  1215.  
  1216. JSONObject subcategoryobj = (JSONObject) subcategories.get(k);
  1217. String fieldname = subcategoryobj.getString("name");
  1218. columns.add(fieldname);
  1219. TreeSet<String> dropdowns = new TreeSet<String>();
  1220.  
  1221. if (subcategoryobj.has("children")) {
  1222.  
  1223. JSONArray subsubcategories = subcategoryobj.getJSONArray("children");
  1224. for (int l = 0; l < subsubcategories.length(); l++) {
  1225.  
  1226. JSONObject dpvalue = (JSONObject) subsubcategories.get(l);
  1227. dropdowns.add(dpvalue.getString("name"));
  1228. }
  1229. }
  1230. fields.put(fieldname, dropdowns);
  1231.  
  1232. }
  1233. tldata.put(categoryobj.getString("name"), fields);
  1234. }
  1235.  
  1236. }
  1237.  
  1238. for (String key : columns) {
  1239.  
  1240. sortedkeys.add(key);
  1241. }
  1242. for (MasterDetails masterdetailsentry : masterdetails) {
  1243.  
  1244. TreeMap<String, String> rowdata = new TreeMap<String, String>();
  1245. JSONObject entryobj = new JSONObject(masterdetailsentry.getEntry());
  1246. for (String key : sortedkeys) {
  1247.  
  1248. rowdata.put(key, entryobj.getString(key));
  1249. }
  1250. entrydata.put(masterdetailsentry.getEntryid(), rowdata);
  1251. }
  1252. model.addAttribute("columns", sortedkeys);
  1253. model.addAttribute("entrydata", entrydata);
  1254. model.addAttribute("categories", tldata);
  1255. model.addAttribute("department", "TL");
  1256. //System.out.println("departmenttype :::::::::::::" + departmenttype);
  1257. model.addAttribute("departmenttype", departmenttype);
  1258. return "TLDocumentPlanner";
  1259. }
  1260. }
  1261.  
  1262. return null;
  1263. } else {
  1264.  
  1265. return null;
  1266.  
  1267. }
  1268. } catch (Exception err) {
  1269.  
  1270. err.printStackTrace();
  1271. }
  1272.  
  1273. } else if (department.equals("SSTL")) {
  1274. }
  1275.  
  1276. } else {
  1277.  
  1278. model.addAttribute("Message", "500,SessionExpiry");
  1279. return "login";
  1280. }
  1281. model.addAttribute("Message", "500,SessionExpiry");
  1282. return "login";
  1283. }
  1284.  
  1285.  
  1286. public String fetchChilds(String type, String noderef, String token) {
  1287.  
  1288. HttpClient client = new HttpClient();
  1289. noderef = noderef.substring(noderef.lastIndexOf('/') + 1, noderef.length());
  1290. //System.out.println(noderef);
  1291. GetMethod createSitePost = new GetMethod(alfresco_forms_picker + "/" + type + "/workspace/SpacesStore/"
  1292. + noderef + "/children?alf_ticket=" + token);
  1293. // http://localhost:8080/alfresco/s/api/forms/picker/category/workspace/SpacesStore/e24fa1ff-807d-4645-a514-01a0ef5e2be0/children
  1294. // workspace://SpacesStore/e24fa1ff-807d-4645-a514-01a0ef5e2be0
  1295. try {
  1296.  
  1297. createSitePost.setRequestHeader("Accept", "application/json");
  1298. int status = client.executeMethod(createSitePost);
  1299. if (status == HttpStatus.SC_OK) {
  1300.  
  1301. return createSitePost.getResponseBodyAsString();
  1302. } else {
  1303.  
  1304. return null;
  1305. }
  1306. } catch (Exception err) {
  1307.  
  1308. err.printStackTrace();
  1309. }
  1310. return null;
  1311.  
  1312. }
  1313.  
  1314.  
  1315. @RequestMapping(value = "/foldercheck", method = RequestMethod.POST)
  1316. public @ResponseBody String folderCheck(@RequestParam(value = "site") String site,
  1317. @RequestParam(value = "station") String station, WebRequest wr, Model model) {
  1318.  
  1319. //System.out.println("Reached Server..");
  1320.  
  1321. if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  1322.  
  1323. try {
  1324.  
  1325. //System.out.println("Session is active..");
  1326. station = URLDecoder.decode(station, "UTF-8");
  1327. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  1328.  
  1329. HttpClient client = new HttpClient();
  1330. GetMethod createSitePost = new GetMethod(alfresco_folder_exists + "?site=" + site + "&station="
  1331. + station + "&alf_ticket=" + employee.getAlf_ticket());
  1332.  
  1333. int status = client.executeMethod(createSitePost);
  1334. return status+"";
  1335. /*if (status == HttpStatus.SC_OK) {
  1336.  
  1337. return createSitePost.getResponseBodyAsString();
  1338. } else if(status==805) {
  1339.  
  1340. return createSitePost.getResponseBodyAsString();
  1341.  
  1342. }
  1343. else if(status==801) {
  1344.  
  1345. return createSitePost.getResponseBodyAsString();
  1346.  
  1347. }
  1348. else{
  1349. return createSitePost.getResponseBodyAsString();
  1350. }
  1351. */ } catch (Exception err) {
  1352.  
  1353. err.printStackTrace();
  1354. return "500";
  1355. }
  1356. } else {
  1357.  
  1358. model.addAttribute("Message", "Your Session Experied..");
  1359. return "500";
  1360. }
  1361. }
  1362.  
  1363. //chandu starting
  1364.  
  1365. @RequestMapping(value = "/ftptrack.vendor", method = RequestMethod.GET)
  1366. public ModelAndView ftpTrack(Model model, WebRequest wr) throws HttpException, IOException, CustomGenericException {
  1367.  
  1368.  
  1369. //System.out.println("controller ftp tracking()*************************************");
  1370. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  1371.  
  1372. //System.out.println("logge in coordinator..."+coordinator.getUsername());
  1373. FTPClient ftp = new FTPClient();
  1374. ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
  1375. int reply;
  1376. ftp.connect(alfresco_mailserverip);
  1377. //System.out.println("ip configuration number------:"+alfresco_mailserverip);
  1378. reply = ftp.getReplyCode();
  1379. if (!FTPReply.isPositiveCompletion(reply)) {
  1380. ftp.disconnect();
  1381. try {
  1382. throw new Exception("Exception in connecting to FTP Server");
  1383. } catch (Exception e) {
  1384. // TODO Auto-generated catch block
  1385. e.printStackTrace();
  1386. }
  1387. }
  1388. ftp.login(ftp_username, ftp_password);
  1389.  
  1390. //System.out.println("username--- "+ftp_username+" password---"+ftp_password);
  1391.  
  1392. ftp.setFileType(FTP.BINARY_FILE_TYPE);
  1393. ftp.enterLocalPassiveMode();
  1394. FtpFile files= new FtpFile();
  1395.  
  1396. //System.out.println(" ftp status:------"+ftp.isConnected());
  1397. // ftp.changeWorkingDirectory("/Alfresco/VendorDocuments/"+coordinator.getUsername()");
  1398.  
  1399. FTPFile[] a=ftp.listFiles("/Alfresco/VendorDocuments/"+coordinator.getUsername());
  1400. //System.out.println("document count="+a.length);
  1401. String[] filenames =new String[a.length+1];
  1402. filenames[0]=coordinator.getUsername();
  1403.  
  1404. for(int i=1;i<a.length+1;i++)
  1405. {
  1406. filenames[i]= a[i-1].getName();
  1407.  
  1408. //System.out.println("document name="+filenames[i]);
  1409. }
  1410.  
  1411.  
  1412. files.setFiles(a);
  1413. return new ModelAndView("ftpFiles","files", filenames);
  1414. }
  1415.  
  1416. //---------------------------------------------------------------------------
  1417. /* private static final int BUFFER_SIZE = 4096;
  1418. @RequestMapping(value = "/download.vendor", method = RequestMethod.GET)
  1419. public void fileDownload(@RequestParam(value = "sta") String files1,HttpServletRequest request, HttpServletResponse response, WebRequest wr)
  1420. throws HttpException, IOException, CustomGenericException {
  1421.  
  1422.  
  1423. System.out.println("controller ftp tracking()*************************************");
  1424. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  1425. String serverAddress = "10.0.0.205"; // ftp server address
  1426. int port = 21; // ftp uses default port Number 21
  1427. String username = "admin";// username of ftp server
  1428. String password = "admin"; // password of ftp server
  1429.  
  1430. FTPClient ftpClient = new FTPClient();
  1431. try {
  1432.  
  1433. ftpClient.connect(serverAddress, port);
  1434. ftpClient.login(username,password);
  1435.  
  1436. ftpClient.enterLocalPassiveMode();
  1437. ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
  1438. String remoteFilePath = "/Alfresco/VendorDocuments/"+coordinator.getUsername()+"/"+files1;
  1439. // String dataDirectory = request.;
  1440. //System.out.println("Alfresco file path :::" +dataDirectory);
  1441.  
  1442. File localfile = new File("/Users/"+files1);
  1443. OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localfile));
  1444. boolean success = ftpClient.retrieveFile(remoteFilePath, outputStream);
  1445. outputStream.close();
  1446.  
  1447. if (success) {
  1448. System.out.println("Ftp file successfully download.");
  1449. }
  1450.  
  1451. } catch (IOException ex) {
  1452. System.out.println("Error occurs in downloading files from ftp Server : " + ex.getMessage());
  1453. } finally {
  1454. try {
  1455. if (ftpClient.isConnected()) {
  1456. ftpClient.logout();
  1457. ftpClient.disconnect();
  1458. }
  1459. } catch (IOException ex) {
  1460. ex.printStackTrace();
  1461. }
  1462. }
  1463. }*/
  1464.  
  1465. //chandu ending
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471. /*
  1472. * @RequestMapping(value = "/emailsender.grid", method = RequestMethod.POST,
  1473. * produces = "application/xml") public @ResponseBody String
  1474. * emailSender(String username, String noderef, String filename, WebRequest
  1475. * wr) {
  1476. *
  1477. * if (wr.getAttribute("vendor", WebRequest.SCOPE_SESSION) != null) {
  1478. *
  1479. * GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee",
  1480. * WebRequest.SCOPE_SESSION); System.out.println(
  1481. * "*********************************************************" +
  1482. * employee.getAlf_ticket()); HttpClient client = new HttpClient();
  1483. * GetMethod createSitePost = new GetMethod(alfresco_people+"/" + username +
  1484. * "?alf_ticket=" + employee.getAlf_ticket()); try {
  1485. *
  1486. * createSitePost.setRequestHeader("Accept", "application/json"); int status
  1487. * = client.executeMethod(createSitePost); if (status == HttpStatus.SC_OK) {
  1488. *
  1489. * JSONObject obj = new
  1490. * JSONObject(createSitePost.getResponseBodyAsString()); noderef =
  1491. * noderef.substring(noderef.lastIndexOf("/") + 1, noderef.length());
  1492. * System.out.println("Dsdfsdf " + obj.getString("email") +
  1493. * " http://localhost:8080/alfresco/guestDownload/a/" + noderef + "/" +
  1494. * filename); // GmailComposer.sendMail("Dear User,\n \n Please find the //
  1495. * DownloadUrl for recently uploaded resource ", // obj.getString("email"),
  1496. * //
  1497. * "http://localhost:8080/alfresco/guestDownload/a/workspace/SpacesStore/"+
  1498. * noderef+"/"+filename, // "Download Link");
  1499. *
  1500. * } else {
  1501. *
  1502. * return null;
  1503. *
  1504. * } } catch (Exception err) {
  1505. *
  1506. * err.printStackTrace(); } return null; } else return null;
  1507. *
  1508. * }
  1509. */
  1510.  
  1511.  
  1512. /****************************** To Register a Vendor*******************************
  1513. *
  1514. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  1515. * Status :: in use
  1516. * Inputs :: Vendor name
  1517. * Output :: Status
  1518. */
  1519. @ResponseBody
  1520. @RequestMapping(value = "/vendorregistration.grid", method = RequestMethod.POST)
  1521. public String vendorCreation(@RequestParam(value = "vendor") String vendorname, WebRequest wr, Model model) {
  1522.  
  1523. if (wr.getAttribute("employee", WebRequest.SCOPE_SESSION) != null) {
  1524.  
  1525. Vendor vendor = new Vendor();
  1526. vendor.setStatus("active");
  1527. vendor.setAlternateemailid("");
  1528. vendor.setAddress("");
  1529. vendor.setDescription("");
  1530. ;
  1531. vendor.setEmailid("");
  1532. vendor.setFullname(vendorname);
  1533. if (!venser.checkvendorExistance(vendorname)) {
  1534.  
  1535. long vendorid = venser.createVendor(vendor);
  1536. if (vendorid > 0) {
  1537.  
  1538. vendor.setVendorid(vendorid);
  1539. return "200,VendorCreation";
  1540. } else {
  1541.  
  1542. return "500,VendorCreation";
  1543. }
  1544.  
  1545. }
  1546.  
  1547. return "501,VendorCreation";
  1548. }
  1549. model.addAttribute("Message", "500,SessionExpiry");
  1550. return "GridLogin";
  1551. }
  1552.  
  1553. /****************************** To Register a Coordinator*******************************
  1554. *
  1555. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  1556. * Status :: in use
  1557. * Inputs :: Coordinator Deatils(Coordinator Class Object)
  1558. * Output :: Naviagtes to RTN Search Page
  1559. */
  1560. @RequestMapping(value = "/coordinatorregistration", method = RequestMethod.POST)
  1561. public String vendorRegistration(@Valid @ModelAttribute("coordinator") Coordinator coordinator,
  1562. BindingResult bindingerror, Model model) {
  1563.  
  1564. /*System.out.println(
  1565. ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> COORDINATOR VENDOR >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");*/
  1566.  
  1567. coordinator.setStatus("waitingforapproval");
  1568. long coordinatorid = venser.checkRTNCoordinator(coordinator.getRtnid());
  1569. if (coordinatorid > 0) {
  1570.  
  1571. /*System.out.println(
  1572. ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> IN IF >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");*/
  1573. coordinator.setCoordinatorid(coordinatorid);
  1574. if (venser.updateCoordinator(coordinator)) {
  1575.  
  1576. venser.updateRTNStatus(coordinator.getRtnid(), "waitingforapproval");
  1577. model.addAttribute("Message", "200,CoordinatorRegistration");
  1578. return "RTNSearch";
  1579. } else {
  1580.  
  1581. model.addAttribute("Message", "500,CoordinatorRegistration");
  1582. return "Coordinator";
  1583. }
  1584. } else {
  1585.  
  1586. /*System.out.println(
  1587. ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> IN ELSE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");*/
  1588. coordinatorid = venser.registeCoordinator(coordinator);
  1589. if (coordinatorid > 0) {
  1590.  
  1591. venser.updateRTNStatus(coordinator.getRtnid(), "waitingforapproval");
  1592. model.addAttribute("Message", "200,CoordinatorRegistration");
  1593. return "RTNSearch";
  1594. } else {
  1595.  
  1596. model.addAttribute("Message", "500,CoordinatorRegistration");
  1597. return "Coordinator";
  1598. }
  1599. }
  1600.  
  1601. }
  1602.  
  1603. /****************************** NAvigates to login Page*******************************
  1604. *
  1605. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  1606. * Status :: in use
  1607. * Inputs :: -
  1608. * Output :: Naviagtes to Login Page
  1609. */
  1610. @RequestMapping(value = "/vendorupdation.do", method = RequestMethod.GET)
  1611. public String vendorupdation(Model model, WebRequest wr) throws HttpException, IOException {
  1612.  
  1613. /*if (wr.getAttribute("employee", WebRequest.SCOPE_SESSION) != null) {
  1614.  
  1615. model.addAttribute("rtn", rtnname);
  1616. model.addAttribute("po", po);
  1617. return "ChangePO";
  1618. }
  1619. model.addAttribute("Message", "500,SessionExpiry");
  1620. return "GridLogin";*/
  1621. return "login";
  1622. }
  1623.  
  1624. /****************************** To Vendor Status Updater*******************************
  1625. *
  1626. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  1627. * Status :: in use
  1628. * Inputs :: Coordiantor ID & Password
  1629. * Output :: Naviagtes to Login Page
  1630. */
  1631. @RequestMapping(value = "/vendorupdation.do", method = RequestMethod.POST)
  1632. public String vendoupdataion(@RequestParam(value = "coordinatorid") long coordinatorid,
  1633. @RequestParam(value = "password") String password, Model model, WebRequest wr) {
  1634.  
  1635. RTN rtn = empser.getCoordinatorRTN(coordinatorid);
  1636. int flag = venser.setCoordinatorPassword(coordinatorid, password);
  1637. if (flag > 0) {
  1638.  
  1639. if (empser.setRTNStatus(rtn.getRtnid(), "approved")) {
  1640.  
  1641. //System.out.println("rtn status updated..");
  1642. }
  1643. model.addAttribute("Message", "200,PasswordReset");
  1644. // return
  1645. // "redirect:updatevendor.vendor?vendorid="+vendor.getVendorid();
  1646. return "login";
  1647. } else {
  1648.  
  1649. model.addAttribute("Message", "500,PasswordReset");
  1650. // return
  1651. // "redirect:updatevendor.vendor?vendorid="+vendor.getVendorid();
  1652. return "login";
  1653. }
  1654. }
  1655.  
  1656.  
  1657.  
  1658.  
  1659. /****************************** To Save the document in Alfresco*******************************
  1660. *
  1661. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  1662. * Status :: in use
  1663. * Inputs :: file, titel, sheeno, description, entryid & description
  1664. * Output :: Status
  1665. */
  1666. @Transactional
  1667. @SuppressWarnings({ "unchecked" })
  1668. @RequestMapping(value = "/documentsubmission.vendor", method = RequestMethod.POST)
  1669. public @ResponseBody String documentUpload(@RequestParam(value = "file") MultipartFile file,
  1670. @RequestParam("entryid") long entryid, @RequestParam("title") String tilte,
  1671. @RequestParam("description") String description, @RequestParam("sheet") long sheet, WebRequest wr,
  1672. Model model, FileDetails filedtls, @ModelAttribute("WorkFlow") Workflow workflow, HttpServletRequest req) {
  1673.  
  1674. //System.out.println("reached here.." + file.getOriginalFilename());
  1675.  
  1676. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  1677.  
  1678. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  1679. RTN rtn = empser.getRTN(coordinator.getRtnid());
  1680. if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  1681.  
  1682. MasterDetails masterdetail = venser.getMasterDetails(entryid);
  1683. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  1684. HttpClient client = new HttpClient();
  1685. //System.out.println("ticket: "+employee.getAlf_ticket());
  1686. RTNType rtntype = empser.getRTNType(rtn.getRtnid());
  1687. MasterDetails masterdetails = venser.getMasterDetails(entryid);
  1688. model.addAttribute("masterdetails", masterdetails);
  1689.  
  1690. try {
  1691. //System.out.println(" file original : "+file.getOriginalFilename());
  1692. File convFile = new File(file.getOriginalFilename());
  1693. file.transferTo(convFile);
  1694. sitename = rtn.getRtn();
  1695. List<Document> docs = venser.getDocuments(entryid);
  1696. // String stationsshortname = "";
  1697. /////////////////////////////////////////
  1698.  
  1699. // STATIONS SHORT NAMES CODE
  1700.  
  1701. /////////////////////////////////////////////
  1702. Document document = new Document();
  1703. document.setDescription(description);
  1704. document.setEntryid(entryid);
  1705. document.setTitle(tilte);
  1706. document.setVersion(1);
  1707. document.setDocument(file.getOriginalFilename());
  1708. document.setSheet(sheet);
  1709. JSONObject filemeta = new JSONObject();
  1710. filemeta.put("masterdetails", masterdetail);
  1711. filemeta.put("rtn", rtn);
  1712. filemeta.put("coordinator", coordinator);
  1713. filemeta.put("docs", docs);
  1714. filemeta.put("documentdetails", document);
  1715. //System.out.println(filemeta.toString());
  1716. String stations = masterdetail.getStations().replace(", ", "-");
  1717. stations = stations.replace(" ", "");
  1718. stations = stations.replace(",", "");
  1719. String uniquekey = "";
  1720.  
  1721. // for (int i = 0; i < stations.length; i++) {
  1722.  
  1723. if (rtntype.getRtntype().contains("TL")) {
  1724. //System.out.println("TL-file entered");
  1725.  
  1726. uniquekey += rtn.getRtn() + "-";
  1727. uniquekey += rtn.getNoa() + "-";
  1728. uniquekey += stations + "-";
  1729. uniquekey += masterdetail.getRoot() + "-";
  1730. uniquekey += masterdetail.getKvid() + "-";
  1731. uniquekey += sheet;
  1732.  
  1733.  
  1734. JSONObject entryobj = new JSONObject(masterdetail.getEntry());
  1735. Set<String> keys = entryobj.keySet();
  1736. Part[] parts = new Part[keys.size() + 13];
  1737. int index = 0;
  1738. //System.out.println("reached here..");
  1739. for (String key : keys) {
  1740. /*System.out.println("key:-- "+key);
  1741. System.out.println("key2:-- "+entryobj.getString(key));*/
  1742. parts[index] = new StringPart(key, entryobj.getString(key));
  1743. index++;
  1744. }
  1745.  
  1746. parts[index] = new StringPart("title", tilte);
  1747. parts[++index] = new StringPart("RTN", rtn.getRtn());
  1748. parts[++index] = new StringPart("description", description);
  1749. parts[++index] = new StringPart("stationname", stations.trim());
  1750. parts[++index] = new StringPart("NOA", rtn.getNoa());
  1751. parts[++index] = new StringPart("coordinator", coordinator.getEmailid());
  1752. //System.out.println(parts[++index] = new StringPart("coordinator", coordinator.getEmailid()));
  1753. parts[++index] = new StringPart("RTNTYPE", rtntype.getRtntype());
  1754. parts[++index] = new StringPart("sheetno", sheet + "");
  1755. parts[++index] = new StringPart("revisionno", 0 + "");
  1756. parts[++index] = new StringPart("uniquekey", uniquekey);
  1757. parts[++index] = new StringPart("firstname", coordinator.getFirstname());
  1758. parts[++index] = new StringPart("address", coordinator.getAddress());
  1759. parts[++index] = new FilePart("file", convFile);
  1760. /*System.out.println("reached here..2 "+index);
  1761. System.out.println("reached here..3 "+coordinator.getAddress());
  1762. System.out.println(parts.length);
  1763. System.out.println(rtntype.getRtntype());*/
  1764. PostMethod createSitePost = new PostMethod(
  1765. alfresco_tl_fileupload + "?alf_ticket=" + employee.getAlf_ticket());
  1766.  
  1767. createSitePost.setRequestEntity(new MultipartRequestEntity(parts, createSitePost.getParams()));
  1768. int respstatus = client.executeMethod(createSitePost);
  1769.  
  1770. //System.out.println("respstatus: "+respstatus);
  1771. if (respstatus == HttpStatus.SC_OK) {
  1772.  
  1773. //System.out.println("alfresco saved sucessfully");
  1774.  
  1775. model.addAttribute("Message", "200,DocumentUpload");
  1776.  
  1777. String response = createSitePost.getResponseBodyAsString();
  1778. //System.out.println("response ::::::::::::::::::: " + response);
  1779. JSONObject obj = new JSONObject(response);
  1780. String noderef = obj.getString("message");
  1781. document.setNoderef(noderef);
  1782. document.setUniquekey(uniquekey);
  1783. document.setStation(stations.trim());
  1784.  
  1785. if (venser.saveDocument(document)) {
  1786.  
  1787. //System.out.println("saved sucessfully");
  1788. return "200,DocumentUpload";
  1789. } else {
  1790.  
  1791. //System.out.println("not saved sucessfully");
  1792. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  1793. return "500,DocumentUpload";
  1794. }
  1795. }else if(respstatus ==808) {
  1796.  
  1797. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  1798. return "808,DocumentUpload";
  1799. }
  1800. else {
  1801.  
  1802. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  1803. return "500,DocumentUpload";
  1804. }
  1805.  
  1806. } else {
  1807.  
  1808. uniquekey += rtn.getRtn() + "-";
  1809. uniquekey += rtn.getNoa() + "-";
  1810. uniquekey += stations + "-";
  1811. uniquekey += masterdetail.getRoot() + "-";
  1812. uniquekey += masterdetail.getKvid() + "-";
  1813. uniquekey += masterdetail.getDrawingtype() + "-";
  1814. uniquekey += sheet;
  1815.  
  1816. String drawingname = "";
  1817. String drawingtype = "";
  1818. if (masterdetail.getSubsubcategory().trim().equalsIgnoreCase("NA")) {
  1819.  
  1820. drawingname = masterdetail.getDrawingtype() + "-" + masterdetail.getSubcategory();
  1821. drawingtype = masterdetail.getSubsubcategory();
  1822. } else {
  1823. drawingname = masterdetail.getSubcategory();
  1824. drawingtype = masterdetail.getDrawingtype() + "-" + masterdetail.getSubsubcategory();
  1825. }
  1826.  
  1827. String kv = "NA";
  1828. String make = "NA";
  1829. String kvmake = "";
  1830. String kvlist[] = masterdetail.getKvid().split("-");
  1831. String metalist[] = masterdetail.getMetakv().split("-");
  1832.  
  1833. for (int j = 0; j < metalist.length; j++) {
  1834.  
  1835. if (metalist[j].trim().equalsIgnoreCase("KV")) {
  1836.  
  1837. kv = kvlist[j];
  1838. }
  1839. if (metalist[j].trim().equalsIgnoreCase("MAKE")) {
  1840.  
  1841. make = kvlist[j];
  1842. }
  1843. if (j == metalist.length - 1) {
  1844.  
  1845. kvmake += metalist[j].trim() + "-" + metalist[j].trim();
  1846. } else {
  1847.  
  1848. kvmake += metalist[j].trim() + "-" + metalist[j].trim() + ",";
  1849. }
  1850.  
  1851. }
  1852.  
  1853. Part[] parts = {
  1854.  
  1855.  
  1856. new StringPart("title", document.getTitle()), new StringPart("RTN", rtn.getRtn()),
  1857. new StringPart("description", document.getDescription()),
  1858. new StringPart("stationname", stations), new StringPart("NOA", rtn.getNoa()),
  1859. new StringPart("coordinator", coordinator.getEmailid()),
  1860. new StringPart("address", coordinator.getAddress()),
  1861. new StringPart("firstname", coordinator.getFirstname()),
  1862. new StringPart("RTNTYPE", rtntype.getRtntype()),
  1863. new StringPart("structuretype", masterdetail.getCategory()),
  1864. new StringPart("drawingname", drawingname), new StringPart("drawingtype", drawingtype),
  1865. new StringPart("department", masterdetail.getRoot()),
  1866. new StringPart("vendormail", coordinator.getEmailid()),
  1867. new StringPart("drawingshortname", masterdetail.getDrawingtype()),
  1868. new StringPart("KV", kv), new StringPart("make", make),
  1869. new StringPart("kvmake", kvmake), new StringPart("sheetno", sheet + ""),
  1870. new StringPart("revisionno", 0 + ""), new StringPart("uniquekey", uniquekey),
  1871. new FilePart("file", convFile)
  1872.  
  1873. };
  1874.  
  1875.  
  1876. PostMethod createSitePost = new PostMethod(
  1877. alfresco_ss_fileupload + "?alf_ticket=" + employee.getAlf_ticket());
  1878. createSitePost.setRequestEntity(new MultipartRequestEntity(parts, createSitePost.getParams()));
  1879. int respstatus = client.executeMethod(createSitePost);
  1880.  
  1881. if (respstatus == HttpStatus.SC_OK) {
  1882.  
  1883. String response = createSitePost.getResponseBodyAsString();
  1884.  
  1885. JSONObject obj = new JSONObject(response);
  1886. String noderef = obj.getString("message");
  1887. document.setNoderef(noderef);
  1888. document.setUniquekey(uniquekey);
  1889. document.setStation(stations.trim());
  1890. if (venser.saveDocument(document)) {
  1891.  
  1892. return "200,DocumentUpload";
  1893. } else {
  1894.  
  1895. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  1896. return "500,DocumentUpload";
  1897. }
  1898. } else if(respstatus ==808) {
  1899.  
  1900. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  1901. return "808,DocumentUpload";
  1902. }else {
  1903.  
  1904. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  1905. return "500,DocumentUpload";
  1906. }
  1907.  
  1908. }
  1909. } catch (Exception err) {
  1910.  
  1911. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  1912. return "500,DocumentUpload";
  1913. }
  1914.  
  1915. } else {
  1916.  
  1917. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  1918. return "500,DocumentUpload";
  1919. }
  1920.  
  1921. }
  1922. return "500,DocumentUpload";
  1923. }
  1924.  
  1925. /****************************** To upload revision document in Alfresco*******************************
  1926. *
  1927. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  1928. * Status :: in use
  1929. * Inputs :: file, titel, sheeno, description, entryid & description
  1930. * Output :: Status
  1931. */
  1932. @Transactional
  1933. @RequestMapping(value = "/documentrevision.vendor", method = RequestMethod.POST)
  1934. public @ResponseBody String documnetRevision(@RequestParam(value = "file") MultipartFile file,
  1935. @RequestParam("title") String tilte, @RequestParam("description") String description,
  1936. @RequestParam("sheet") long sheet, @RequestParam("documentid") long documentid,
  1937. @ModelAttribute("WorkFlow") Workflow workflow, WebRequest wr, Model model, FileDetails filedtls,
  1938. HttpServletRequest req) {
  1939.  
  1940. //System.out.println("reached here..");
  1941. if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
  1942.  
  1943. Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
  1944. RTN rtn = empser.getRTN(coordinator.getRtnid());
  1945. if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  1946.  
  1947. Document revisiondocument = venser.getDocument(documentid);
  1948.  
  1949. //MasterDetails masterdetail = venser.getMasterDetails(revisiondocument.getEntryid());
  1950. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  1951. HttpClient client = new HttpClient();
  1952. PostMethod createSitePost = new PostMethod(
  1953. alfresco_document_upload + "?alf_ticket=" + employee.getAlf_ticket());
  1954. System.out.println("Post method testing 1--- " +createSitePost);
  1955.  
  1956. //Anurag written code start
  1957. PostMethod createSitePostR = new PostMethod(
  1958. alfresco_document_uploadR + "?alf_ticket=" + employee.getAlf_ticket());
  1959. System.out.println("Post method testing 2--- " +createSitePostR);
  1960.  
  1961. GetMethod createSiteGet = new GetMethod(alfresco_folder_details + "?nodeId=" + revisiondocument.getNoderef() +
  1962. "&alf_ticket=" + employee.getAlf_ticket());
  1963. //System.out.println("Get method testing 3--- " +createSiteGet);
  1964. String foldernoderef=null;
  1965.  
  1966. //Anurag written code end
  1967.  
  1968. File convFile = new File(file.getOriginalFilename());
  1969. try {
  1970. file.transferTo(convFile);
  1971. sitename = rtn.getRtn();
  1972. long entryid = revisiondocument.getEntryid();
  1973. //if(revisiondocument.getStatusid()==5)
  1974. {
  1975.  
  1976. Part[] parts = {
  1977.  
  1978. new StringPart("description", description),
  1979. new StringPart("overwrite", "false"),
  1980. new StringPart("updatenoderef", revisiondocument.getNoderef()),
  1981. new StringPart("updatenameandmimetype","true"),
  1982. new StringPart("thumbnails","true"),
  1983. new StringPart("majorversion", "true"), new FilePart("filedata", convFile) };
  1984.  
  1985. //System.out.println("Parts testing 1--- " +parts);
  1986. //System.out.println("revision noderef " +revisiondocument.getNoderef());
  1987. //.out.println("original file name " +file.getOriginalFilename());
  1988.  
  1989.  
  1990. MasterDetails masterdetails = venser.getMasterDetails(entryid);
  1991. createSitePost.setRequestEntity(new MultipartRequestEntity(parts, createSitePost.getParams()));
  1992.  
  1993.  
  1994. //Anurag written code start
  1995. createSiteGet.setRequestHeader("Accept", "application/json");
  1996.  
  1997. int statusG = client.executeMethod(createSiteGet);
  1998. System.out.println("status: "+statusG);
  1999. JSONObject response = new JSONObject(createSiteGet.getResponseBodyAsString());
  2000. System.out.println("response "+response);
  2001. JSONArray array = response.getJSONArray("results");
  2002. JSONObject obj = null;
  2003. String folderName=null;
  2004. for (int i = 0; i < array.length(); i++) {
  2005.  
  2006. obj= array.getJSONObject(i);
  2007. foldernoderef=obj.getString("spaceStoreId");
  2008. folderName=obj.getString("foldername");
  2009. //foldernoderef='"'+foldernoderef+'"';
  2010. //System.out.println("folder node ref "+foldernoderef);
  2011. }
  2012.  
  2013. JSONObject siteObject = new JSONObject();
  2014.  
  2015. int respstatus=0;
  2016. int statusR=0;
  2017. //System.out.println("folder Name123: "+folderName);
  2018.  
  2019. if(folderName.contains("Unread"))
  2020. {
  2021.  
  2022.  
  2023.  
  2024. //System.out.println("folder Name: "+folderName);
  2025. siteObject.put("page", "1");
  2026. siteObject.put("inplace", "true");
  2027. siteObject.put("nodeRef", revisiondocument.getNoderef());
  2028. siteObject.put("insert-content","workspace://SpacesStore/"+alfresco_insert_nodeRef);
  2029. siteObject.put("destination-folder",foldernoderef);
  2030. siteObject.put("destination-name", file.getOriginalFilename());
  2031. siteObject.put("majorVersion", "true");
  2032.  
  2033.  
  2034. createSitePostR.setRequestHeader("Content-Type", "application/json");
  2035. createSitePostR.setRequestHeader("Accept", "application/json");
  2036. createSitePostR.setRequestEntity(new StringRequestEntity(siteObject.toString(), "application/json", "UTF-8"));
  2037.  
  2038. //int status = client.executeMethod(createSitePostR);
  2039. //System.out.println("create a site script status :: " + status);
  2040.  
  2041. respstatus = client.executeMethod(createSitePost);
  2042. //System.out.println("respstatus testing 1--- " +respstatus);
  2043.  
  2044. //int respstatusR = client.executeMethod(createSitePostR);
  2045. statusR = client.executeMethod(createSitePostR);
  2046.  
  2047. //System.out.println("respstatusR testing 1--- " +statusR);
  2048. //System.out.println("statusG testing 3--- " +statusG);
  2049.  
  2050. }
  2051.  
  2052.  
  2053. else
  2054.  
  2055. {
  2056. //System.out.println("respstatusR testing 2--- " +statusR);
  2057. respstatus = client.executeMethod(createSitePost);
  2058. //System.out.println("respstatus testing 2--- " +respstatus);
  2059. }
  2060. if (respstatus == HttpStatus.SC_OK ) {
  2061.  
  2062. //Anurag written code end
  2063. //System.out.println("respstatus Status 1 " +respstatus);
  2064.  
  2065. RTNType rtntype = empser.getRTNType(rtn.getRtnid());
  2066. model.addAttribute("masterdetails", masterdetails);
  2067. if (rtntype.getRtntype().equalsIgnoreCase("TL-Conductor")
  2068. || rtntype.getRtntype().equalsIgnoreCase("TL-Foundation")
  2069. || rtntype.getRtntype().equalsIgnoreCase("TL-Hardware")
  2070. || rtntype.getRtntype().equalsIgnoreCase("TL-Insulator")
  2071. || rtntype.getRtntype().equalsIgnoreCase("TL-Tower")) {
  2072.  
  2073. TreeMap<String, String> entrydata = new TreeMap<String, String>();
  2074. JSONObject entryjson = new JSONObject(masterdetails.getEntry());
  2075. @SuppressWarnings("unchecked")
  2076. Set<String> keys = entryjson.keySet();
  2077. for (String key : keys) {
  2078.  
  2079. entrydata.put(key, entryjson.getString(key));
  2080. }
  2081. model.addAttribute("entrydata", entrydata);
  2082. model.addAttribute("Message", "");
  2083. // return "TLDocumentDetails";
  2084. } else {
  2085.  
  2086. model.addAttribute("Message", "");
  2087. // return "DocumentsDetails";
  2088.  
  2089. }
  2090.  
  2091. //String response = createSitePost.getResponseBodyAsString();
  2092. //System.out.println("response ::::::::::::::::::: " + response);
  2093. Document document = new Document();
  2094. document.setDocumentid(revisiondocument.getDocumentid());
  2095. document.setDescription(description);
  2096. document.setEntryid(entryid);
  2097. document.setVersion(revisiondocument.getVersion() + 1);
  2098. document.setSheet(sheet);
  2099. document.setNoderef(revisiondocument.getNoderef());
  2100. document.setDocument(file.getOriginalFilename());
  2101. document.setStation(revisiondocument.getStation());
  2102. document.setTitle(tilte);
  2103. document.setUniquekey(revisiondocument.getUniquekey());
  2104. document.setStatusid(11);
  2105. if(venser.updateDocument(document)){
  2106.  
  2107. return "200,DocumentUpload";
  2108.  
  2109. }
  2110. /*if (venser.saveDocument(document)) {
  2111.  
  2112. venser.updateDocumentStatus(revisiondocument.getDocumentid(), 11);
  2113. return "true";
  2114.  
  2115. } */else {
  2116.  
  2117. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  2118. return "500,DocumentUpload";
  2119.  
  2120. }
  2121. }else if(respstatus ==808) {
  2122.  
  2123. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  2124. return "808,DocumentUpload";
  2125. } else {
  2126.  
  2127. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  2128. return "500,DocumentUpload";
  2129.  
  2130. }
  2131. }
  2132.  
  2133. } catch (Exception err) {
  2134.  
  2135. err.printStackTrace();
  2136. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  2137. return "500,DocumentUpload";
  2138. }
  2139.  
  2140. } else {
  2141.  
  2142. TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
  2143. return "500,DocumentUpload";
  2144. }
  2145.  
  2146. }
  2147. model.addAttribute("Message", "500,SessionExpery");
  2148. return "500,DocumentUpload";
  2149. }
  2150.  
  2151. @RequestMapping(value = "/vendorhome.tls", method = RequestMethod.GET)
  2152. public String ReDirectHome(WebRequest wr, Model model) {
  2153.  
  2154. if (wr.getAttribute("vendor", WebRequest.SCOPE_SESSION) != null) {
  2155.  
  2156. return "VendorHome";
  2157. }
  2158. model.addAttribute("Message", "Your Login Sesssion has Experied.. Please, login again");
  2159. return "GridLogin";
  2160.  
  2161. }
  2162.  
  2163. // Categories and Subcategories
  2164.  
  2165. /****************************** To get the Subcategories of Root caegory from Alfresco*******************************
  2166. *
  2167. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  2168. * Status :: in use
  2169. * Inputs :: Dept name
  2170. * Output :: String(JSON array with childs)
  2171. */
  2172. @RequestMapping(value = "/subCategories.vendor", method = RequestMethod.POST, produces = "application/json")
  2173. public @ResponseBody String getSubCategories(WebRequest wr, Model model,
  2174. @RequestParam(value = "DeptName") String DeptName) throws HttpException, IOException {
  2175.  
  2176. HttpClient client = new HttpClient();
  2177. JSONObject categoryResponse;
  2178. JSONObject subcategoryResponse = null;
  2179. if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  2180.  
  2181. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  2182. String url = alfresco_category_root_children + "?alf_ticket=" + employee.getAlf_ticket();
  2183. GetMethod category = new GetMethod(url);
  2184. /* try { */
  2185. category.setRequestHeader("Accept", "application/json");
  2186. int status = client.executeMethod(category);
  2187. if (status == HttpStatus.SC_OK) {
  2188.  
  2189. categoryResponse = new JSONObject(category.getResponseBodyAsString());
  2190. for (int i = 0; i < categoryResponse.getJSONObject("data").getJSONArray("items").length(); i++) {
  2191.  
  2192. GetMethod subcategory = null;
  2193. JSONObject allcategories = (JSONObject) categoryResponse.getJSONObject("data").getJSONArray("items")
  2194. .get(i);
  2195. if (allcategories.getString("name").equals("Departments")) {
  2196.  
  2197. String noderef = allcategories.getString("nodeRef").replace("workspace://SpacesStore/", "");
  2198. String url1 = alfresco_formpicker_workspace_spacesstore + "/" + noderef + "/children"
  2199. + "?alf_ticket=" + employee.getAlf_ticket();
  2200. GetMethod category1 = new GetMethod(url1);
  2201. client.executeMethod(category1);
  2202. JSONObject DeptcategoryResponse = new JSONObject(category1.getResponseBodyAsString());
  2203. JSONArray DeptResponseArray = DeptcategoryResponse.getJSONObject("data").getJSONArray("items");
  2204. for (int subcat = 0; subcat < DeptResponseArray.length(); subcat++) {
  2205.  
  2206. JSONObject Deptallcategories = (JSONObject) DeptResponseArray.get(subcat);
  2207.  
  2208. if (Deptallcategories.getString("name").equalsIgnoreCase(DeptName)) {
  2209. String Civilnoderef = Deptallcategories.getString("nodeRef")
  2210. .replace("workspace://SpacesStore/", "");
  2211.  
  2212. String Civilurl = alfresco_formpicker_workspace_spacesstore + "/" + Civilnoderef
  2213. + "/children" + "?alf_ticket=" + employee.getAlf_ticket();
  2214.  
  2215. subcategory = new GetMethod(Civilurl);
  2216. client.executeMethod(subcategory);
  2217. subcategoryResponse = new JSONObject(subcategory.getResponseBodyAsString());
  2218. return subcategoryResponse.getJSONObject("data").getJSONArray("items").toString();
  2219.  
  2220. }
  2221.  
  2222. }
  2223.  
  2224. }
  2225.  
  2226. }
  2227.  
  2228. } else {
  2229.  
  2230. }
  2231. } else {
  2232. }
  2233. return "";
  2234. }
  2235.  
  2236. /****************************** Tofetch the category root from Alfresco*******************************
  2237. *
  2238. * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
  2239. * Status :: in use
  2240. * Inputs :: -
  2241. * Output :: String(JSON array with category root)
  2242. */
  2243. @SuppressWarnings("unused")
  2244. @RequestMapping(value = "/Categories.vendor", method = RequestMethod.POST, produces = "application/json")
  2245. public @ResponseBody String getCategories(WebRequest wr, Model model) throws HttpException, IOException {
  2246.  
  2247. HttpClient client = new HttpClient();
  2248. JSONObject categoryResponse;
  2249. JSONObject DeptcategoryResponse = null;
  2250. if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  2251.  
  2252. GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
  2253. //System.out.println("In category Vendorsssssssssssssssssss");
  2254. String url = alfresco_category_root_children + "?alf_ticket=" + employee.getAlf_ticket();
  2255.  
  2256. GetMethod category = new GetMethod(url);
  2257. /* try { */
  2258. category.setRequestHeader("Accept", "application/json");
  2259. int status = client.executeMethod(category);
  2260. if (status == HttpStatus.SC_OK) {
  2261.  
  2262. categoryResponse = new JSONObject(category.getResponseBodyAsString());
  2263. for (int i = 0; i < categoryResponse.getJSONObject("data").getJSONArray("items").length(); i++) {
  2264.  
  2265. JSONObject allcategories = (JSONObject) categoryResponse.getJSONObject("data").getJSONArray("items")
  2266. .get(i);
  2267. if (allcategories.getString("name").equals("Departments")) {
  2268.  
  2269. String noderef = allcategories.getString("nodeRef").replace("workspace://SpacesStore/", "");
  2270. String url1 = alfresco_formpicker_workspace_spacesstore + "/" + noderef + "/children"
  2271. + "?alf_ticket=" + employee.getAlf_ticket();
  2272. GetMethod category1 = new GetMethod(url1);
  2273. client.executeMethod(category1);
  2274. DeptcategoryResponse = new JSONObject(category1.getResponseBodyAsString());
  2275. /*System.out.println("getjson"
  2276. + DeptcategoryResponse.getJSONObject("data").getJSONArray("items").toString());*/
  2277. return DeptcategoryResponse.getJSONObject("data").getJSONArray("items").toString();
  2278.  
  2279. } else {
  2280.  
  2281. return "500,Category";
  2282. }
  2283. }
  2284. } else {
  2285.  
  2286. }
  2287. } else {
  2288. }
  2289. return "";
  2290. }
  2291.  
  2292. /*
  2293. * @RequestMapping(value = "/workFlow.vendor", method = RequestMethod.GET,
  2294. * produces = "application/json") public @ResponseBody String
  2295. * getWorkflows(WebRequest wr, Model model) throws HttpException,
  2296. * IOException {
  2297. *
  2298. * HttpClient client = new HttpClient(); JSONObject workflowResp = null;
  2299. *
  2300. * if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  2301. * GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee",
  2302. * WebRequest.SCOPE_SESSION); String workflowUrl =
  2303. * "http://localhost:8080/alfresco/service/api/workflow-definitions" +
  2304. * "?alf_ticket=" + employee.getAlf_ticket(); GetMethod workflowResponse =
  2305. * new GetMethod(workflowUrl); client.executeMethod(workflowResponse);
  2306. * workflowResp = new
  2307. * JSONObject(workflowResponse.getResponseBodyAsString());
  2308. * System.out.println("workflowResponse" +
  2309. * workflowResp.getJSONArray("data"));
  2310. *
  2311. * }
  2312. *
  2313. * return workflowResp.getJSONArray("data").toString();
  2314. *
  2315. * }
  2316. *
  2317. *
  2318. * This method is used for Apply the waterMark On doc
  2319. *
  2320. * private String applyWaterMarkOnDocs(String ticket, String docnoderef,
  2321. * String uniquekey) { String WaterMark_nodeRef = null; HttpClient client =
  2322. * new HttpClient(); PostMethod createSitePost = new PostMethod(
  2323. * "http://localhost:8080/alfresco/service/pdftoolkit/powergrid/pdfWaterMark"
  2324. * + "?alf_ticket=" + ticket);
  2325. *
  2326. * // Pass the Request Body Data as json payload JSONObject siteObject = new
  2327. * JSONObject(); try { siteObject.put("nodeRef", docnoderef);
  2328. * siteObject.put("paramPage", "1"); siteObject.put("paramPosition",
  2329. * "topleft"); siteObject.put("paramWaterMarkerText", "Desc," + uniquekey);
  2330. * System.out.println("Site Object " + siteObject.toString());
  2331. *
  2332. * createSitePost.setRequestHeader("Content-Type", "application/json");
  2333. * createSitePost.setRequestHeader("Accept", "application/json");
  2334. * createSitePost .setRequestEntity(new
  2335. * StringRequestEntity(siteObject.toString(), "application/json", "UTF-8"));
  2336. *
  2337. * int status = client.executeMethod(createSitePost);
  2338. * System.out.println("create a site script status :: " + status);
  2339. *
  2340. * if (status == HttpStatus.SC_OK) {
  2341. *
  2342. * System.out.println("Site created OK"); String response =
  2343. * createSitePost.getResponseBodyAsString(); JSONObject obj = new
  2344. * JSONObject(response); WaterMark_nodeRef = obj.getString("nodeRef");
  2345. *
  2346. * } else {
  2347. *
  2348. * System.out.println("There is a problem of while applying waterMark"); } }
  2349. * catch (Exception err) { err.printStackTrace(); }
  2350. *
  2351. * return WaterMark_nodeRef;
  2352. *
  2353. * }
  2354. *
  2355. */ /*
  2356. * This method is used for start the workflow while uploading the
  2357. * document successfully
  2358. *
  2359. */
  2360.  
  2361. /*
  2362. * private int startWorkFlow(Workflow workflow, String waterMark_NoderRef,
  2363. * String stations, String rtn, String vendorEmailId, WebRequest wr) throws
  2364. * HttpException, IOException {
  2365. *
  2366. * // Workflow workflow = null; int status = 0;
  2367. *
  2368. * System.out.println("Cell" + waterMark_NoderRef + "Stations ----->" +
  2369. * stations);
  2370. *
  2371. * GetMethod createSitePost = null; if
  2372. * (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
  2373. *
  2374. * GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee",
  2375. * WebRequest.SCOPE_SESSION); HttpClient client = new HttpClient();
  2376. *
  2377. * createSitePost = new
  2378. * GetMethod("http://localhost:8080/alfresco/s/api/sites/" + sitename +
  2379. * "?alf_ticket=" + employee.getAlf_ticket().trim()); int respstatus =
  2380. * client.executeMethod(createSitePost); System.out.println("Status :: " +
  2381. * respstatus); JSONObject js = new
  2382. * JSONObject(createSitePost.getResponseBodyAsString()); for (int i = 0; i <
  2383. * js.getJSONArray("siteManagers").length(); i++) {
  2384. *
  2385. * System.out.println("sitenamevvvvvv" +
  2386. * js.getJSONArray("siteManagers").get(i)); String managerName = (String)
  2387. * js.getJSONArray("siteManagers").get(i); PostMethod startworkflow = new
  2388. * PostMethod(
  2389. * "http://localhost:8080/alfresco/service/powergrid/startworkflow/assigne"
  2390. * + "?alf_ticket=" + employee.getAlf_ticket());
  2391. * workflow.setWorkFlowName("activiti$vendormanagement");
  2392. * workflow.setNodeRef(waterMark_NoderRef);
  2393. * workflow.setDescription("Please Review The File Uploaded By" + "," + rtn
  2394. * + "," + stations.toString() + "," + vendorEmailId);
  2395. * workflow.setAssigneName(managerName);
  2396. *
  2397. * startworkflow.setRequestHeader("Content-Type", "application/json");
  2398. * startworkflow .setRequestEntity(new
  2399. * StringRequestEntity(workflow.toString(), "application/json", "UTF-8"));
  2400. * status = client.executeMethod(startworkflow); }
  2401. *
  2402. * } if (status == HttpStatus.SC_OK) {
  2403. *
  2404. * System.out.println(vendorEmailId);
  2405. *
  2406. * return 1; }
  2407. *
  2408. * return 0;
  2409. *
  2410. * }
  2411. */}
Add Comment
Please, Sign In to add comment