Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.taashee.controller;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.PrintWriter;
- import java.net.URLDecoder;
- import java.nio.file.Files;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.LinkedHashSet;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.TreeMap;
- import java.util.TreeSet;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletContext;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import javax.validation.Valid;
- import org.apache.commons.httpclient.HttpClient;
- import org.apache.commons.httpclient.HttpException;
- import org.apache.commons.httpclient.HttpStatus;
- import org.apache.commons.httpclient.methods.GetMethod;
- import org.apache.commons.httpclient.methods.PostMethod;
- import org.apache.commons.httpclient.methods.StringRequestEntity;
- import org.apache.commons.httpclient.methods.multipart.FilePart;
- import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
- import org.apache.commons.httpclient.methods.multipart.Part;
- import org.apache.commons.httpclient.methods.multipart.StringPart;
- import org.apache.commons.net.PrintCommandListener;
- import org.apache.commons.net.ftp.FTP;
- import org.apache.commons.net.ftp.FTPClient;
- import org.apache.commons.net.ftp.FTPFile;
- import org.apache.commons.net.ftp.FTPReply;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.beans.propertyeditors.CustomDateEditor;
- import org.springframework.stereotype.Controller;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.transaction.interceptor.TransactionInterceptor;
- import org.springframework.ui.Model;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.WebDataBinder;
- import org.springframework.web.bind.annotation.InitBinder;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.context.request.WebRequest;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.servlet.ModelAndView;
- import com.taashee.dao.VendorDAO;
- import com.taashee.globalexception.CustomGenericException;
- import com.taashee.service.CommonService;
- import com.taashee.service.GridEmployeeService;
- import com.taashee.service.VendorService;
- import com.taashee.vo.Coordinator;
- import com.taashee.vo.Document;
- import com.taashee.vo.FtpFile;
- import com.taashee.vo.GridEmployee;
- import com.taashee.vo.MasterDetails;
- import com.taashee.vo.MasterEntry;
- import com.taashee.vo.RTN;
- import com.taashee.vo.RTNType;
- import com.taashee.vo.Vendor;
- import com.taashee.vo1.FileDetails;
- import com.taashee.vo1.Workflow;
- @Controller
- public class VendorController {
- //-------------------------------------
- @Autowired
- private VendorDAO vendao;
- //-------------------------------------
- @Autowired
- private VendorService venser;
- @Autowired
- private GridEmployeeService empser;
- @Autowired
- ServletContext servletContext;
- @Autowired
- ServletConfig config;
- @Autowired
- GridEmployeeService empservice;
- @Autowired
- CommonService comnsevice;
- @Value("${alfresco.category_root_children}")
- private String alfresco_category_root_children;
- @Value("${alfresco.site_folders_custom}")
- private String alfresco_site_folders_custom;
- @Value("${alferesco.ta_categories}")
- private String alferesco_ta_categories;
- @Value("${alfresco.forms_picker}")
- private String alfresco_forms_picker;
- // alfresco.folder_exists
- @Value("${alfresco.folder_exists}")
- private String alfresco_folder_exists;
- //Anurag Revision docs API
- @Value("${alfresco.document_uploadR}")
- private String alfresco_document_uploadR;
- @Value("${alfresco.folder_details}")
- private String alfresco_folder_details;
- @Value("${alfresco.insert_nodeRef}")
- private String alfresco_insert_nodeRef;
- @Value("${alfresco.people}")
- private String alfresco_people;
- @Value("${alfresco.tl_fileupload}")
- private String alfresco_tl_fileupload;
- @Value("${alfresco.ss_fileupload}")
- private String alfresco_ss_fileupload;
- @Value("${alfresco.document_upload}")
- private String alfresco_document_upload;
- @Value("${alfresco.login}")
- private String alfresco_login;
- @Value("${alfresco.formpicker_workspace_spacesstore}")
- private String alfresco_formpicker_workspace_spacesstore;
- @Value("${alfresco.nodes_treenode}")
- private String alfresco_nodes_treenode;
- //ftp values
- @Value("${alfresco.mailserverip}")
- private String alfresco_mailserverip;
- @Value("${ftp.username}")
- private String ftp_username;
- @Value("${ftp.password}")
- private String ftp_password;
- String sitename;
- String description;
- String noderefId;
- @InitBinder
- public void initBinder(WebDataBinder binder) {
- // binder.setDisallowedFields(new String[]{"experience","dateofbirth"});
- SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd");
- binder.registerCustomEditor(Date.class, "registereddate", new CustomDateEditor(sfd, false));
- binder.registerCustomEditor(Date.class, "CreatedDate", new CustomDateEditor(sfd, false));
- }
- /****************************** Navigates to Vendor Registration Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: Not in use
- * Inputs :: -
- * Output :: Navigates to Vendor Registration Page
- */
- @RequestMapping(value = "/vendorregistration.tls", method = RequestMethod.GET)
- public String ReDirectRegistration() {
- return "VendorRegistration";
- }
- /*
- *//******************************To Delete Document Permanently*******************************
- *
- * Author @ Ramesh K, Written on 07-02-2018 12:00:00,
- * Status :: In use
- * Inputs :: rtnid
- * Output :: status
- *//*
- @ResponseBody
- @RequestMapping(value = "/documentDeletion.vendor", method = RequestMethod.POST)
- public String deleteDocument(@RequestParam(value = "documentid") long documentid, Model model, WebRequest wr)
- throws HttpException, IOException {
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- System.out.println("documentDeletion now working");
- boolean flag=venser.deleteDocument(documentid);
- if (flag)
- {
- System.out.println("flag:- "+ flag);
- return "true";
- }
- else {
- System.out.println("flag:- "+ flag);
- return "500,DocumentDeletion";
- }
- }
- else {
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- }
- */
- /****************************** Navigates to Documents Submission Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: Navigates to Document Submission Page
- */
- @RequestMapping(value = "/documentSubmission.grid", method = RequestMethod.GET)
- public String documentSubmission(WebRequest wr, Model model) {
- if (wr.getAttribute("vendor", WebRequest.SCOPE_SESSION) != null) {
- return "DocumentSubmission";
- }
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- /****************************** Navigates to Documents Planner Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: Navigates to Documents Planner Page
- */
- @RequestMapping(value = "/documentplanner.vendor", method = RequestMethod.GET)
- public String documentPlanner(WebRequest wr, Model model) {
- // if(wr.getAttribute("vendor", WebRequest.SCOPE_SESSION)!=null){
- return "DocumentPlanner";
- // }
- // model.addAttribute("Message","500,SessionExpiry");
- /// return "login";
- }
- /****************************** Will fetch the data of existing stations of an RTN *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: Not in use
- * Inputs :: -
- * Output :: Navigates to Vendor Registration Page
- */
- public Set<String> getListOfExistingStations(String rtn, WebRequest wr) {
- if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- Set<String> stations = new TreeSet<String>();
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- HttpClient client = new HttpClient();
- GetMethod createSitePost = new GetMethod(
- alfresco_site_folders_custom + "?siteName=" + rtn + "&alf_ticket=" + employee.getAlf_ticket());
- try {
- createSitePost.setRequestHeader("Accept", "application/json");
- int status = client.executeMethod(createSitePost);
- if (status == HttpStatus.SC_OK) {
- //System.out.println(">>>>>>>>>>>" + createSitePost.getResponseBodyAsString());
- JSONObject response = new JSONObject(createSitePost.getResponseBodyAsString());
- JSONArray array = response.getJSONArray("data");
- for (int i = 0; i < array.length(); i++) {
- JSONObject obj = array.getJSONObject(i);
- stations.add(obj.getString("folderName"));
- }
- return stations;
- } else if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
- //System.out.println("internal server error");
- return stations;
- } else {
- //System.out.println("Shit happend..");
- return stations;
- }
- } catch (Exception err) {
- //System.out.println("shit happend in catch");
- return stations;
- }
- } else
- return null;
- }
- /****************************** Naviagtes to the Planner Status Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: Navigates to Planner Status Page
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = "/plannerstatus.vendor", method = RequestMethod.GET)
- public String documentsPlannerAprover(WebRequest wr, Model model) {
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- RTN rtn = empser.getRTN(coordinator.getRtnid());
- RTNType rtntype = empser.getRTNType(rtn.getRtnid());
- // Coordinator coordinator=empser.getCoordinator(rtn.getRtn());
- long masterId = comnsevice.hasMasterEntry(rtn.getRtnid());
- if (masterId <= 0) {
- MasterEntry masterentry = new MasterEntry();
- masterentry.setRtnid(rtn.getRtnid());
- masterId = comnsevice.resgisterMasterEntry(masterentry);
- }
- MasterEntry master = empser.getMaster(rtn.getRtnid());
- List<MasterDetails> masterdetails = empser.getMasterDetails(master.getMasterid());
- for(MasterDetails masterdetail : masterdetails) {
- int docCount =(int) (masterdetail.getNoOfDocs() - venser.getDocCount(masterdetail.getEntryid()));
- masterdetail.setDocCount(docCount);
- //System.out.println("entryID:------------ "+masterdetail.getDocCount());
- }
- if (rtntype.getRtntype().equalsIgnoreCase("TL-Conductor")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Foundation")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Hardware")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Insulator")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Tower")) {
- TreeSet<String> columns = new TreeSet<String>();
- model.addAttribute("rtn", rtn);
- model.addAttribute("masterdetails", masterdetails);
- Map<Long, TreeMap<String, String>> entrydata = new TreeMap<Long, TreeMap<String, String>>();
- for (MasterDetails masterdetailsentry : masterdetails) {
- TreeMap<String, String> rowdata = new TreeMap<String, String>();
- JSONObject entryobj = new JSONObject(masterdetailsentry.getEntry());
- Set<String> keys = entryobj.keySet();
- TreeSet<String> sortedkeys = new TreeSet<String>();
- for (String key : keys) {
- columns.add(key);
- sortedkeys.add(key);
- }
- for (String key : sortedkeys) {
- // System.out.println(key+
- // "<===================================================================================");
- rowdata.put(key, entryobj.getString(key));
- }
- entrydata.put(masterdetailsentry.getEntryid(), rowdata);
- }
- model.addAttribute("columns", columns);
- model.addAttribute("entrydata", entrydata);
- model.addAttribute("coordinator", coordinator);
- model.addAttribute("master", master);
- model.addAttribute("department", "TL");
- return "TLDocumentPlannerStatus";
- } else {
- JSONArray kvjson = new JSONArray(getStations("kv", wr, model));
- Set<String> kvls = new LinkedHashSet<String>();
- for (int q = 0; q < kvjson.length(); q++) {
- kvls.add(kvjson.getJSONObject(q).getString("name"));
- }
- model.addAttribute("rtn", rtn);
- model.addAttribute("masterdetails", masterdetails);
- model.addAttribute("coordinator", coordinator);
- model.addAttribute("master", master);
- model.addAttribute("kvs", kvls);
- //model.addAttribute("docCountPlanner", docCountPlanner);
- return "DocumentPlannerStatus";
- }
- } else {
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- }
- /****************************** Naviagtes to the Planner Status Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: entryid(Masteerdetails)
- * Output :: Navigates to Planner Status Page
- */
- @RequestMapping(value = "/docdetails.vendor", method = RequestMethod.GET)
- public String documentsDetails( WebRequest wr, Model model) {
- return "redirect:plannerstatus.vendor";
- }
- /****************************** Naviagtes to the Document Details Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: entryid(Masteerdetails)
- * Output :: Navigates to Documents Details Page
- */
- @SuppressWarnings({ "unchecked" })
- @RequestMapping(value = "/docdetails.vendor", method = RequestMethod.POST)
- public String documentsDetails(@RequestParam(value = "entryid") long entryid, WebRequest wr, Model model) {
- ////document upload exceeded code
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- MasterDetails masterdetails = venser.getMasterDetails(entryid);
- List<Document> documents = venser.getDocuments(entryid);
- int docCount = venser.getDocCount(entryid);
- int noOfDocs= (int) masterdetails.getNoOfDocs();
- /*System.out.println("Db documents size :: "+documents.size());
- System.out.println("Master details values "+masterdetails.getNoOfDocs());
- System.out.println("DB no of docs :: "+docCount);
- System.out.println("DB Count of docs :: "+noOfDocs);*/
- int docCountt =(int) (masterdetails.getNoOfDocs() - venser.getDocCount(masterdetails.getEntryid()));
- masterdetails.setDocCount(docCountt);
- if(docCount <= noOfDocs )
- {
- //System.out.println("NotExceeded");
- model.addAttribute("Message", "200,notExceeded");
- }
- else{
- //System.out.println("Exceeded");
- model.addAttribute("Message", "500,Exceeded");
- }
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- RTN rtn = empser.getRTN(coordinator.getRtnid());
- RTNType rtntype = empser.getRTNType(rtn.getRtnid());
- model.addAttribute("masterdetails", masterdetails);
- model.addAttribute("documents", comnsevice.processDocumentDetails(documents, wr, model));
- //System.out.println("documents size :: "+comnsevice.processDocumentDetails(documents, wr, model).size());
- // if()
- if (rtntype.getRtntype().equalsIgnoreCase("TL-Conductor")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Foundation")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Hardware")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Insulator")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Tower")
- ) {
- TreeMap<String, String> entrydata = new TreeMap<String, String>();
- JSONObject entryjson = new JSONObject(masterdetails.getEntry());
- Set<String> keys = entryjson.keySet();
- for (String key : keys) {
- entrydata.put(key, entryjson.getString(key));
- }
- model.addAttribute("entrydata", entrydata);
- if( noOfDocs <= docCount )
- {
- model.addAttribute("Message","500,Exceeded");
- //return "TLDocumentDetails";
- }
- return "TLDocumentDetails";
- } else {
- if( noOfDocs <= docCount )
- {
- //System.out.println("Exceded");
- model.addAttribute("Message","500,Exceeded");
- //return "DocumentsDetails";
- }
- return "DocumentsDetails";
- }
- } else {
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- }
- /****************************** Naviagtes to the Document Details Page with duplicates check *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: Navigates to Document Deatils Page
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = "/duplicatedocdetails.vendor", method = RequestMethod.POST)
- public String documentsHasDuplicate(@RequestParam(value = "entryid") long entryid, WebRequest wr, Model model) {
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- MasterDetails masterdetails = venser.getMasterDetails(entryid);
- List<Document> documents = venser.getDocuments(entryid);
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- RTN rtn = empser.getRTN(coordinator.getRtnid());
- RTNType rtntype = empser.getRTNType(rtn.getRtnid());
- model.addAttribute("masterdetails", masterdetails);
- if (rtntype.getRtntype().equalsIgnoreCase("TL-Conductor")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Foundation")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Hardware")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Insulator")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Tower")) {
- TreeMap<String, String> entrydata = new TreeMap<String, String>();
- JSONObject entryjson = new JSONObject(masterdetails.getEntry());
- Set<String> keys = entryjson.keySet();
- for (String key : keys) {
- entrydata.put(key, entryjson.getString(key));
- }
- model.addAttribute("documents", documents);
- model.addAttribute("entrydata", entrydata);
- /*System.out.println(
- "Uploading failed Documents length ::::::::::::::::::::::::::::::: " + documents.size());*/
- model.addAttribute("Message", "500,DocumentUpload");
- return "TLDocumentDetails";
- } else {
- model.addAttribute("documents", documents);
- //System.out.println("Documents length ::::::::::::::::::::::::::::::: " + documents.size());
- model.addAttribute("Message", "500,DocumentUpload");
- return "DocumentsDetails";
- }
- } else {
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- }
- /****************************** Naviagtes to the Documents Submissions Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: entryid(Masteerdetails)
- * Output :: Navigates to Document Submission Page
- */
- @RequestMapping(value = "/documetupload.vendor", method = RequestMethod.POST)
- public String documentUpload(@RequestParam(value = "entryid") long entryid, WebRequest wr, Model model) {
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- MasterDetails masterdetails = venser.getMasterDetails(entryid);
- model.addAttribute("masterdetails", masterdetails);
- return "DocumentSubmission";
- } else {
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- }
- /****************************** Naviagtes to the Planner Status Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: Navigates to Planner Status Page
- */
- @RequestMapping(value = "/documetupload.vendor", method = RequestMethod.GET)
- public String documentUploadGet(WebRequest wr, Model model) {
- return "redirect:plannerstatus.vendor";
- }
- /****************************** Naviagtes to the Planner Status Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: Navigates to Planner Status Page
- */
- @RequestMapping(value = "/documetrevision.vendor", method = RequestMethod.GET)
- public String documentRevisionGET(WebRequest wr, Model model) {
- return "redirect:plannerstatus.vendor";
- }
- /****************************** Naviagtes to the Document Revision Page *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: Navigates to Document Revision Page
- */
- @RequestMapping(value = "/documetrevision.vendor", method = RequestMethod.POST)
- public String documentRevision(@RequestParam(value = "documentid") long documentid, WebRequest wr, Model model) {
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- // MasterDetails masterdetails = venser.getMasterDetails(entryid);
- Document document = venser.getDocument(documentid);
- model.addAttribute("document", document);
- return "DocumentRevision";
- } else {
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- }
- /****************************** To Fetch Stations Details of an RTN*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: Category(Station)
- * Output :: String(JSON Array of Stations)
- */
- public String getStations(String category, WebRequest wr, Model model) {
- if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- HttpClient client = new HttpClient();
- GetMethod createSitePost = new GetMethod(
- alfresco_category_root_children + "?alf_ticket=" + employee.getAlf_ticket());
- try {
- createSitePost.setRequestHeader("Accept", "application/json");
- int status = client.executeMethod(createSitePost);
- if (status == HttpStatus.SC_OK) {
- JSONObject root = new JSONObject(createSitePost.getResponseBodyAsString());
- JSONObject data = root.getJSONObject("data");
- JSONArray items = data.getJSONArray("items");
- for (int i = 0; i < items.length(); i++) {
- JSONObject item = (JSONObject) items.get(i);
- if (item.getString("name").equalsIgnoreCase(category)) {
- String noderef = item.getString("nodeRef");
- //System.out.println("************ node ref ********* " + noderef);
- JSONObject childs = new JSONObject(
- fetchChilds("category", noderef, employee.getAlf_ticket()));
- JSONObject stationsdata = childs.getJSONObject("data");
- //System.out.println(stationsdata.getJSONArray("items").length());
- return stationsdata.getJSONArray("items").toString();
- }
- }
- return null;
- } else {
- return null;
- }
- } catch (Exception err) {
- err.printStackTrace();
- }
- } else {
- model.addAttribute("Message", "Your Session Experied..");
- return null;
- }
- model.addAttribute("Message", "500,SessionExpiry");
- return null;
- }
- /****************************** To Save the Document Planner Line Items *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: String(JSON Object with Document Planner Line Items)
- * Output :: boolean
- */
- @Transactional
- @ResponseBody
- @RequestMapping(value = "/checkDocCount.vendor", method = RequestMethod.POST)
- public int checkDocCount(@RequestParam(value = "entryid") long entryid,@RequestParam(value = "entryValu") long entryValu, WebRequest wr, Model model) {
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- //System.out.println("entryid"+entryValu);
- int docCount =(int) (entryValu - venser.getDocCount(entryid));
- //System.out.println("docCount: "+docCount);
- /*if(docCount > 0 )
- {
- //System.out.println("docCount else");
- return docCount+"notExceeded";
- }
- else{
- //System.out.println("docCount IF");
- return docCount+"Exceeded";
- }*/
- return venser.getDocCount(entryid);
- }
- return -1;
- }
- /****************************** To Save the Document Planner Line Items *******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: String(JSON Object with Document Planner Line Items)
- * Output :: boolean
- */
- @Transactional
- @RequestMapping(value = "savedocumentplanner.vendor", method = RequestMethod.POST, consumes = "application/json")
- public @ResponseBody String inviteeCreation(@RequestBody String documentplanner, WebRequest wr, Model model) {
- //System.out.println("savedocumentplanner");
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- JSONObject plannerjson = new JSONObject(documentplanner);
- JSONArray existingentries = plannerjson.getJSONArray("existingentries");
- JSONArray newentries = plannerjson.getJSONArray("newentries");
- JSONArray deletedentries = plannerjson.getJSONArray("deletedentries");
- //System.out.println("existing ::: " + existingentries.length());
- //System.out.println("new ::: " + newentries.length());
- RTNType rtntype = empser.getRTNType(coordinator.getRtnid());
- String department = rtntype.getRtntype().split("-")[0];
- if (department.equals("CL") || department.equals("EL")
- || rtntype.getRtntype().equalsIgnoreCase("SubStation") || rtntype.getRtntype().equals("Cable")
- || rtntype.getRtntype().equals("Reactor") || rtntype.getRtntype().equals("Transformer")) {
- Set<Integer> entries_tobe_deleted = new TreeSet<Integer>();
- for (int i = 0; i < deletedentries.length(); i++) {
- entries_tobe_deleted.add(deletedentries.getInt(i));
- }
- if (entries_tobe_deleted.size() > 0) {
- venser.deleteEntries(entries_tobe_deleted);
- }
- long masterid = comnsevice.hasMasterEntry(coordinator.getRtnid());
- List<MasterDetails> newmasterdetails = new ArrayList<MasterDetails>();
- if (masterid > 0) {
- String save = plannerjson.getString("save");
- if (!save.equals("true")) {
- venser.updateSubmissionStatus(masterid);
- }
- List<MasterDetails> existingmasterdetails = new ArrayList<MasterDetails>();
- for (int i = 0; i < existingentries.length(); i++) {
- JSONObject entry = existingentries.getJSONObject(i);
- int docCount =(int) (entry.getLong("NoOfDocs") - venser.getDocCount(entry.getLong("entryid")));
- if(docCount < 0)
- {
- //model.addAttribute("message", "500,NotAllow");
- return "500,NotAllow";
- }
- else {
- MasterDetails masterdetails = new MasterDetails();
- masterdetails.setEntryid(entry.getLong("entryid"));
- masterdetails.setRoot(entry.getString("root"));
- masterdetails.setCategory(entry.getString("category"));
- masterdetails.setSubcategory(entry.getString("subcategory"));
- masterdetails.setSubsubcategory(entry.getString("subsubcategory"));
- masterdetails.setKvid(entry.getString("kvid"));
- masterdetails.setMetakv(entry.getString("metakv"));
- masterdetails.setStations(entry.getString("stations"));
- masterdetails.setStatusid(8);
- masterdetails.setDrawingtype(entry.getString("drawingtype"));
- masterdetails.setNoOfDocs(entry.getLong("NoOfDocs"));
- existingmasterdetails.add(masterdetails);
- }
- }
- if (existingentries.length() > 0) {
- venser.updateExistingmasterEntries(existingmasterdetails);
- }
- MasterEntry masterentry = empser.getMaster(coordinator.getRtnid());
- for (int i = 0; i < newentries.length(); i++) {
- JSONObject entry = newentries.getJSONObject(i);
- //System.out.println("kvid" + entry.getString("kvid"));
- //System.out.println("docs" + entry.getLong("NoOfDocs"));
- MasterDetails masterdetails = new MasterDetails();
- masterdetails.setRoot(entry.getString("root"));
- masterdetails.setCategory(entry.getString("category"));
- masterdetails.setSubcategory(entry.getString("subcategory"));
- masterdetails.setSubsubcategory(entry.getString("subsubcategory"));
- masterdetails.setMetakv(entry.getString("metakv"));
- masterdetails.setKvid(entry.getString("kvid"));
- masterdetails.setStations(entry.getString("stations"));
- masterdetails.setStatusid(entry.getLong("statusid"));
- masterdetails.setNoOfDocs(entry.getLong("NoOfDocs"));
- masterdetails.setDrawingtype(entry.getString("drawingtype"));
- masterdetails.setMasterid(masterentry.getMasterid());
- newmasterdetails.add(masterdetails);
- }
- if (newentries.length() > 0) {
- venser.registerMasterEntries(newmasterdetails);
- }
- if (newentries.length() > 0 || existingentries.length() > 0) {
- venser.updateRTNStatus(coordinator.getRtnid(), "DocTypeModified");
- venser.updateMasterEntryStatus(masterentry.getMasterid(), 8);
- }
- } else {
- MasterEntry masterentry = new MasterEntry();
- masterentry.setRtnid(coordinator.getRtnid());
- long masterId = comnsevice.resgisterMasterEntry(masterentry);
- if (masterId > 0) {
- for (int i = 0; i < newentries.length(); i++) {
- JSONObject entry = newentries.getJSONObject(i);
- MasterDetails masterdetails = new MasterDetails();
- masterdetails.setRoot(entry.getString("root"));
- masterdetails.setCategory(entry.getString("category"));
- masterdetails.setSubcategory(entry.getString("subcategory"));
- masterdetails.setSubsubcategory(entry.getString("subsubcategory"));
- masterdetails.setMetakv(entry.getString("metakv"));
- masterdetails.setKvid(entry.getString("kvid"));
- masterdetails.setStations(entry.getString("stations"));
- masterdetails.setStatusid(entry.getLong("statusid"));
- masterdetails.setNoOfDocs(entry.getLong("NoOfDocs"));
- masterdetails.setDrawingtype(entry.getString("drawingtype"));
- masterdetails.setMasterid(masterId);
- /*System.out.println(
- "masterid ::::::::::::::::::::::::::::::::::::::::::::::::::::::: " + masterId);*/
- //System.out.println(" ");
- //System.out.println("Planned document is: ="+masterdetails.getNoOfDocs());
- //System.out.println(" ");
- newmasterdetails.add(masterdetails);
- }
- if (newentries.length() > 0) {
- venser.registerMasterEntries(newmasterdetails);
- venser.updateRTNStatus(coordinator.getRtnid(), "DocTypeSubmitted");
- venser.updateMasterCreatedStatus(masterId);
- venser.updateMasterEntryStatus(masterId, 2);
- }
- }
- }
- }
- if (department.equals("TL")) {
- Set<Integer> entries_tobe_deleted = new TreeSet<Integer>();
- for (int i = 0; i < deletedentries.length(); i++) {
- entries_tobe_deleted.add(deletedentries.getInt(i));
- }
- if (entries_tobe_deleted.size() > 0) {
- venser.deleteEntries(entries_tobe_deleted);
- }
- List<MasterDetails> newmasterdetails = new ArrayList<MasterDetails>();
- long masterid = comnsevice.hasMasterEntry(coordinator.getRtnid());
- if (masterid > 0) {
- boolean save = plannerjson.getBoolean("save");
- if (!save) {
- venser.updateSubmissionStatus(masterid);
- }
- List<MasterDetails> existingmasterdetails = new ArrayList<MasterDetails>();
- for (int i = 0; i < existingentries.length(); i++) {
- MasterDetails masterdetails = new MasterDetails();
- JSONObject entry = existingentries.getJSONObject(i);
- //System.out.println("hello: "+entry.getLong("docs"));
- int docCount =(int) (entry.getLong("docs") - venser.getDocCount(entry.getLong("entryid")));
- if(docCount < 0)
- {
- //model.addAttribute("message", "500,NotAllow");
- return "500,NotAllow";
- }
- else {
- masterdetails.setEntry(entry.getJSONObject("entry").toString().replaceAll("\"", "\\\""));
- masterdetails.setEntryid(entry.getLong("entryid"));
- masterdetails.setRoot("TL");
- masterdetails.setStations(entry.getString("stations"));
- masterdetails.setEntry(entry.getJSONObject("entry").toString());
- masterdetails.setStatusid(8);
- masterdetails.setNoOfDocs(entry.getLong("docs"));
- existingmasterdetails.add(masterdetails);
- }
- }
- if (existingentries.length() > 0) {
- venser.updateTLExistingmasterEntries(existingmasterdetails);
- }
- MasterEntry masterentry = empser.getMaster(coordinator.getRtnid());
- //System.out.println(masterentry.getMasterid());
- for (int i = 0; i < newentries.length(); i++) {
- MasterDetails masterdetails = new MasterDetails();
- JSONObject entry = newentries.getJSONObject(i);
- masterdetails.setEntry(entry.getJSONObject("entry").toString().replaceAll("\"", "\\\""));
- masterdetails.setRoot("TL");
- masterdetails.setStations(entry.getString("stations"));
- masterdetails.setStatusid(entry.getLong("statusid"));
- masterdetails.setNoOfDocs(entry.getLong("docs"));
- masterdetails.setMasterid(masterentry.getMasterid());
- newmasterdetails.add(masterdetails);
- }
- if (newentries.length() > 0) {
- venser.registerTLMasterEntries(newmasterdetails);
- }
- if (newentries.length() > 0 || existingentries.length() > 0) {
- venser.updateRTNStatus(coordinator.getRtnid(), "DocTypeModified");
- venser.updateMasterEntryStatus(masterentry.getMasterid(), 8);
- }
- } else {
- MasterEntry masterentry = new MasterEntry();
- masterentry.setRtnid(coordinator.getRtnid());
- long masterId = comnsevice.resgisterMasterEntry(masterentry);
- if (masterId > 0) {
- for (int i = 0; i < newentries.length(); i++) {
- MasterDetails masterdetails = new MasterDetails();
- JSONObject entry = newentries.getJSONObject(i);
- masterdetails.setEntry(entry.getJSONObject("entry").toString().replaceAll("\"", "\\\""));
- masterdetails.setRoot("TL");
- masterdetails.setStations(entry.getString("stations"));
- masterdetails.setEntry(entry.getJSONObject("entry").toString());
- masterdetails.setStatusid(entry.getLong("statusid"));
- masterdetails.setNoOfDocs(entry.getLong("docs"));
- masterdetails.setMasterid(masterId);
- /*System.out.println(
- "masterid ::::::::::::::::::::::::::::::::::::::::::::::::::::::: " + masterId);*/
- newmasterdetails.add(masterdetails);
- }
- if (newentries.length() > 0) {
- venser.registerTLMasterEntries(newmasterdetails);
- venser.updateRTNStatus(coordinator.getRtnid(), "DocTypeSubmitted");
- venser.updateMasterCreatedStatus(masterId);
- venser.updateMasterEntryStatus(masterId, 2);
- }
- }
- }
- }
- }
- return "true";
- }
- /****************************** To Expand the session for Document Planner*******************************
- *
- * Author @ Ramesh K, Written on 19-04-2018 12:00:00,
- * Status :: in use
- * Output :: Naviagtes to Document Plannaer Page
- */
- @RequestMapping(value = "/sessionReload", method = RequestMethod.GET)
- public String getsessionReload(WebRequest wr, Model model, HttpSession session) {
- //session.setMaxInactiveInterval(1*60*60);
- /*System.out.println(
- "*************************************************************************************************************************************");*/
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- System.out.println("Session time is----- "+session.getMaxInactiveInterval());
- }
- return "ElectricalDocumentPlanner";
- }
- /****************************** To Fetch Category Root Details of an RTN*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: String(JSON Object with Document Planner Line Items)
- * Output :: Naviagtes to Document Plannaer Page
- */
- @RequestMapping(value = "/documentplanner", method = RequestMethod.GET)
- public String getRTNDataForDocumentPlanner(WebRequest wr, Model model, HttpSession session) {
- //session.setMaxInactiveInterval(1*60*60);
- System.out.println("Session time is "+session.getMaxInactiveInterval());
- /*System.out.println(
- "*************************************************************************************************************************************");*/
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- RTN rtn = empservice.getRTN(coordinator.getRtnid());
- model.addAttribute("rtn", rtn.getRtn());
- model.addAttribute("session", session.getMaxInactiveInterval());
- Set<String> stations = (Set<String>) getListOfExistingStations(rtn.getRtn(), wr);
- model.addAttribute("stations", stations);
- JSONArray kvjson = new JSONArray(getStations("kv", wr, model));
- Set<String> kvls = new LinkedHashSet<String>();
- for (int q = 0; q < kvjson.length(); q++) {
- kvls.add(kvjson.getJSONObject(q).getString("name"));
- }
- model.addAttribute("kvvalues", kvls);
- boolean hadenrties = true;
- MasterEntry master = null;
- List<MasterDetails> masterdetails = null;
- try {
- /*System.out.println(
- "RTNid :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" + rtn.getRtnid());*/
- master = empser.getMaster(rtn.getRtnid());
- //System.out.println("Master id" + master.getMasterid());
- masterdetails = empser.getMasterDetails(master.getMasterid());
- for(MasterDetails masterdetail : masterdetails) {
- // System.out.println("entryID:------------ "+masterdetail.getEntryid());
- int docCount =(int) (masterdetail.getNoOfDocs() - venser.getDocCount(masterdetail.getEntryid()));
- //System.out.println("entryID:------------ "+docCount);
- masterdetail.setDocCount(docCount);
- // System.out.println("entryID:------------ "+masterdetail.getDocCount());
- }
- } catch (Exception e) {
- // e.printStackTrace();
- master = null;
- masterdetails = null;
- hadenrties = false;
- }
- comnsevice.fetchAdminAccessToken("admin", "admin", wr);
- model.addAttribute("existingmasterdetails", masterdetails);
- RTNType rtntype = empservice.getRTNType(rtn.getRtnid());
- String rtntypename = rtntype.getRtntype();
- String department = "";
- String departmenttype = "";
- if (rtntypename.equalsIgnoreCase("Substation") || rtntypename.equalsIgnoreCase("Transformer")
- || rtntypename.equalsIgnoreCase("Cable") || rtntypename.equalsIgnoreCase("Reactor")) {
- department = rtntypename;
- } else {
- department = rtntypename.split("-")[0];
- departmenttype = rtntypename.split("-")[1];
- }
- if (department.equalsIgnoreCase("SubStation") || department.equalsIgnoreCase("Reactor")
- || department.equalsIgnoreCase("Cable") || department.equalsIgnoreCase("Transformer")) {
- TreeMap<String, TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>>> overallresponse = new TreeMap<String, TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>>>();
- try {
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- HttpClient client = new HttpClient();
- GetMethod createSitePost = new GetMethod(alferesco_ta_categories
- + "?path=Departments&recurse=1&alf_ticket=" + employee.getAlf_ticket());
- createSitePost.setRequestHeader("Accept", "application/json");
- int status = client.executeMethod(createSitePost);
- if (status == HttpStatus.SC_OK) {
- JSONObject root = new JSONObject(createSitePost.getResponseBodyAsString());
- JSONArray items = root.getJSONArray("items");
- for (int m = 0; m < items.length(); m++) {
- JSONObject item = (JSONObject) items.get(m);
- //System.out.println("Electrical>>>>>>>" + item.getString("name"));
- if (item.getString("name").equalsIgnoreCase("Electrical")) {
- //System.out.println("Electrical>>>>>>>");
- JSONArray categories = item.getJSONArray("children");
- TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>> response = new TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>>();
- response = venser.SSDocumentBuilder(categories, response, masterdetails, hadenrties);
- model.addAttribute("hasentries", masterdetails.size() > 0);
- overallresponse.put("Electrical", response);
- model.addAttribute("department", "Electrical");
- }
- if (item.getString("name").equalsIgnoreCase("Civil")) {
- //System.out.println("In Civil..");
- JSONArray categories = item.getJSONArray("children");
- TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>> response = new TreeMap<String, TreeMap<String, TreeMap<String, List<MasterDetails>>>>();
- response = venser.SSDocumentBuilder(categories, response, masterdetails, hadenrties);
- model.addAttribute("hasentries", masterdetails.size() > 0);
- overallresponse.put("Civil", response);
- model.addAttribute("department", "Electrical");
- }
- //System.out.println("*********************NOT matched2***************");
- }
- model.addAttribute("rootcategories", overallresponse);
- return "ElectricalDocumentPlanner";
- }
- } catch (Exception err) {
- err.printStackTrace();
- }
- } else if (department.equals("TL")) {
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- HttpClient client = new HttpClient();
- GetMethod createSitePost = new GetMethod(
- alferesco_ta_categories + "?path=Departments&recurse=1&alf_ticket=" + employee.getAlf_ticket());
- TreeSet<String> columns = new TreeSet<String>();
- TreeSet<String> sortedkeys = new TreeSet<String>();
- Map<Long, TreeMap<String, String>> entrydata = new TreeMap<Long, TreeMap<String, String>>();
- try {
- createSitePost.setRequestHeader("Accept", "application/json");
- int status = client.executeMethod(createSitePost);
- if (status == HttpStatus.SC_OK) {
- JSONObject root = new JSONObject(createSitePost.getResponseBodyAsString());
- JSONArray items = root.getJSONArray("items");
- for (int m = 0; m < items.length(); m++) {
- JSONObject item = (JSONObject) items.get(m);
- //System.out.println("Electrical>>>>>>>" + item.getString("name"));
- if (item.getString("name").equalsIgnoreCase("TL")) {
- JSONArray categories = item.getJSONArray("children");
- TreeMap<String, Map<String, TreeSet<String>>> tldata = new TreeMap<String, Map<String, TreeSet<String>>>();
- for (int j = 0; j < categories.length(); j++) {
- JSONObject categoryobj = (JSONObject) categories.get(j);
- JSONArray subcategories = categoryobj.getJSONArray("children");
- if (categoryobj.getString("name").equals(departmenttype)) {
- Map<String, TreeSet<String>> fields = new TreeMap<String, TreeSet<String>>();
- for (int k = 0; k < subcategories.length(); k++) {
- JSONObject subcategoryobj = (JSONObject) subcategories.get(k);
- String fieldname = subcategoryobj.getString("name");
- columns.add(fieldname);
- TreeSet<String> dropdowns = new TreeSet<String>();
- if (subcategoryobj.has("children")) {
- JSONArray subsubcategories = subcategoryobj.getJSONArray("children");
- for (int l = 0; l < subsubcategories.length(); l++) {
- JSONObject dpvalue = (JSONObject) subsubcategories.get(l);
- dropdowns.add(dpvalue.getString("name"));
- }
- }
- fields.put(fieldname, dropdowns);
- }
- tldata.put(categoryobj.getString("name"), fields);
- }
- }
- for (String key : columns) {
- sortedkeys.add(key);
- }
- for (MasterDetails masterdetailsentry : masterdetails) {
- TreeMap<String, String> rowdata = new TreeMap<String, String>();
- JSONObject entryobj = new JSONObject(masterdetailsentry.getEntry());
- for (String key : sortedkeys) {
- rowdata.put(key, entryobj.getString(key));
- }
- entrydata.put(masterdetailsentry.getEntryid(), rowdata);
- }
- model.addAttribute("columns", sortedkeys);
- model.addAttribute("entrydata", entrydata);
- model.addAttribute("categories", tldata);
- model.addAttribute("department", "TL");
- //System.out.println("departmenttype :::::::::::::" + departmenttype);
- model.addAttribute("departmenttype", departmenttype);
- return "TLDocumentPlanner";
- }
- }
- return null;
- } else {
- return null;
- }
- } catch (Exception err) {
- err.printStackTrace();
- }
- } else if (department.equals("SSTL")) {
- }
- } else {
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- model.addAttribute("Message", "500,SessionExpiry");
- return "login";
- }
- public String fetchChilds(String type, String noderef, String token) {
- HttpClient client = new HttpClient();
- noderef = noderef.substring(noderef.lastIndexOf('/') + 1, noderef.length());
- //System.out.println(noderef);
- GetMethod createSitePost = new GetMethod(alfresco_forms_picker + "/" + type + "/workspace/SpacesStore/"
- + noderef + "/children?alf_ticket=" + token);
- // http://localhost:8080/alfresco/s/api/forms/picker/category/workspace/SpacesStore/e24fa1ff-807d-4645-a514-01a0ef5e2be0/children
- // workspace://SpacesStore/e24fa1ff-807d-4645-a514-01a0ef5e2be0
- try {
- createSitePost.setRequestHeader("Accept", "application/json");
- int status = client.executeMethod(createSitePost);
- if (status == HttpStatus.SC_OK) {
- return createSitePost.getResponseBodyAsString();
- } else {
- return null;
- }
- } catch (Exception err) {
- err.printStackTrace();
- }
- return null;
- }
- @RequestMapping(value = "/foldercheck", method = RequestMethod.POST)
- public @ResponseBody String folderCheck(@RequestParam(value = "site") String site,
- @RequestParam(value = "station") String station, WebRequest wr, Model model) {
- //System.out.println("Reached Server..");
- if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- try {
- //System.out.println("Session is active..");
- station = URLDecoder.decode(station, "UTF-8");
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- HttpClient client = new HttpClient();
- GetMethod createSitePost = new GetMethod(alfresco_folder_exists + "?site=" + site + "&station="
- + station + "&alf_ticket=" + employee.getAlf_ticket());
- int status = client.executeMethod(createSitePost);
- return status+"";
- /*if (status == HttpStatus.SC_OK) {
- return createSitePost.getResponseBodyAsString();
- } else if(status==805) {
- return createSitePost.getResponseBodyAsString();
- }
- else if(status==801) {
- return createSitePost.getResponseBodyAsString();
- }
- else{
- return createSitePost.getResponseBodyAsString();
- }
- */ } catch (Exception err) {
- err.printStackTrace();
- return "500";
- }
- } else {
- model.addAttribute("Message", "Your Session Experied..");
- return "500";
- }
- }
- //chandu starting
- @RequestMapping(value = "/ftptrack.vendor", method = RequestMethod.GET)
- public ModelAndView ftpTrack(Model model, WebRequest wr) throws HttpException, IOException, CustomGenericException {
- //System.out.println("controller ftp tracking()*************************************");
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- //System.out.println("logge in coordinator..."+coordinator.getUsername());
- FTPClient ftp = new FTPClient();
- ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
- int reply;
- ftp.connect(alfresco_mailserverip);
- //System.out.println("ip configuration number------:"+alfresco_mailserverip);
- reply = ftp.getReplyCode();
- if (!FTPReply.isPositiveCompletion(reply)) {
- ftp.disconnect();
- try {
- throw new Exception("Exception in connecting to FTP Server");
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- ftp.login(ftp_username, ftp_password);
- //System.out.println("username--- "+ftp_username+" password---"+ftp_password);
- ftp.setFileType(FTP.BINARY_FILE_TYPE);
- ftp.enterLocalPassiveMode();
- FtpFile files= new FtpFile();
- //System.out.println(" ftp status:------"+ftp.isConnected());
- // ftp.changeWorkingDirectory("/Alfresco/VendorDocuments/"+coordinator.getUsername()");
- FTPFile[] a=ftp.listFiles("/Alfresco/VendorDocuments/"+coordinator.getUsername());
- //System.out.println("document count="+a.length);
- String[] filenames =new String[a.length+1];
- filenames[0]=coordinator.getUsername();
- for(int i=1;i<a.length+1;i++)
- {
- filenames[i]= a[i-1].getName();
- //System.out.println("document name="+filenames[i]);
- }
- files.setFiles(a);
- return new ModelAndView("ftpFiles","files", filenames);
- }
- //---------------------------------------------------------------------------
- /* private static final int BUFFER_SIZE = 4096;
- @RequestMapping(value = "/download.vendor", method = RequestMethod.GET)
- public void fileDownload(@RequestParam(value = "sta") String files1,HttpServletRequest request, HttpServletResponse response, WebRequest wr)
- throws HttpException, IOException, CustomGenericException {
- System.out.println("controller ftp tracking()*************************************");
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- String serverAddress = "10.0.0.205"; // ftp server address
- int port = 21; // ftp uses default port Number 21
- String username = "admin";// username of ftp server
- String password = "admin"; // password of ftp server
- FTPClient ftpClient = new FTPClient();
- try {
- ftpClient.connect(serverAddress, port);
- ftpClient.login(username,password);
- ftpClient.enterLocalPassiveMode();
- ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
- String remoteFilePath = "/Alfresco/VendorDocuments/"+coordinator.getUsername()+"/"+files1;
- // String dataDirectory = request.;
- //System.out.println("Alfresco file path :::" +dataDirectory);
- File localfile = new File("/Users/"+files1);
- OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localfile));
- boolean success = ftpClient.retrieveFile(remoteFilePath, outputStream);
- outputStream.close();
- if (success) {
- System.out.println("Ftp file successfully download.");
- }
- } catch (IOException ex) {
- System.out.println("Error occurs in downloading files from ftp Server : " + ex.getMessage());
- } finally {
- try {
- if (ftpClient.isConnected()) {
- ftpClient.logout();
- ftpClient.disconnect();
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }*/
- //chandu ending
- /*
- * @RequestMapping(value = "/emailsender.grid", method = RequestMethod.POST,
- * produces = "application/xml") public @ResponseBody String
- * emailSender(String username, String noderef, String filename, WebRequest
- * wr) {
- *
- * if (wr.getAttribute("vendor", WebRequest.SCOPE_SESSION) != null) {
- *
- * GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee",
- * WebRequest.SCOPE_SESSION); System.out.println(
- * "*********************************************************" +
- * employee.getAlf_ticket()); HttpClient client = new HttpClient();
- * GetMethod createSitePost = new GetMethod(alfresco_people+"/" + username +
- * "?alf_ticket=" + employee.getAlf_ticket()); try {
- *
- * createSitePost.setRequestHeader("Accept", "application/json"); int status
- * = client.executeMethod(createSitePost); if (status == HttpStatus.SC_OK) {
- *
- * JSONObject obj = new
- * JSONObject(createSitePost.getResponseBodyAsString()); noderef =
- * noderef.substring(noderef.lastIndexOf("/") + 1, noderef.length());
- * System.out.println("Dsdfsdf " + obj.getString("email") +
- * " http://localhost:8080/alfresco/guestDownload/a/" + noderef + "/" +
- * filename); // GmailComposer.sendMail("Dear User,\n \n Please find the //
- * DownloadUrl for recently uploaded resource ", // obj.getString("email"),
- * //
- * "http://localhost:8080/alfresco/guestDownload/a/workspace/SpacesStore/"+
- * noderef+"/"+filename, // "Download Link");
- *
- * } else {
- *
- * return null;
- *
- * } } catch (Exception err) {
- *
- * err.printStackTrace(); } return null; } else return null;
- *
- * }
- */
- /****************************** To Register a Vendor*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: Vendor name
- * Output :: Status
- */
- @ResponseBody
- @RequestMapping(value = "/vendorregistration.grid", method = RequestMethod.POST)
- public String vendorCreation(@RequestParam(value = "vendor") String vendorname, WebRequest wr, Model model) {
- if (wr.getAttribute("employee", WebRequest.SCOPE_SESSION) != null) {
- Vendor vendor = new Vendor();
- vendor.setStatus("active");
- vendor.setAlternateemailid("");
- vendor.setAddress("");
- vendor.setDescription("");
- ;
- vendor.setEmailid("");
- vendor.setFullname(vendorname);
- if (!venser.checkvendorExistance(vendorname)) {
- long vendorid = venser.createVendor(vendor);
- if (vendorid > 0) {
- vendor.setVendorid(vendorid);
- return "200,VendorCreation";
- } else {
- return "500,VendorCreation";
- }
- }
- return "501,VendorCreation";
- }
- model.addAttribute("Message", "500,SessionExpiry");
- return "GridLogin";
- }
- /****************************** To Register a Coordinator*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: Coordinator Deatils(Coordinator Class Object)
- * Output :: Naviagtes to RTN Search Page
- */
- @RequestMapping(value = "/coordinatorregistration", method = RequestMethod.POST)
- public String vendorRegistration(@Valid @ModelAttribute("coordinator") Coordinator coordinator,
- BindingResult bindingerror, Model model) {
- /*System.out.println(
- ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> COORDINATOR VENDOR >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");*/
- coordinator.setStatus("waitingforapproval");
- long coordinatorid = venser.checkRTNCoordinator(coordinator.getRtnid());
- if (coordinatorid > 0) {
- /*System.out.println(
- ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> IN IF >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");*/
- coordinator.setCoordinatorid(coordinatorid);
- if (venser.updateCoordinator(coordinator)) {
- venser.updateRTNStatus(coordinator.getRtnid(), "waitingforapproval");
- model.addAttribute("Message", "200,CoordinatorRegistration");
- return "RTNSearch";
- } else {
- model.addAttribute("Message", "500,CoordinatorRegistration");
- return "Coordinator";
- }
- } else {
- /*System.out.println(
- ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> IN ELSE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");*/
- coordinatorid = venser.registeCoordinator(coordinator);
- if (coordinatorid > 0) {
- venser.updateRTNStatus(coordinator.getRtnid(), "waitingforapproval");
- model.addAttribute("Message", "200,CoordinatorRegistration");
- return "RTNSearch";
- } else {
- model.addAttribute("Message", "500,CoordinatorRegistration");
- return "Coordinator";
- }
- }
- }
- /****************************** NAvigates to login Page*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: Naviagtes to Login Page
- */
- @RequestMapping(value = "/vendorupdation.do", method = RequestMethod.GET)
- public String vendorupdation(Model model, WebRequest wr) throws HttpException, IOException {
- /*if (wr.getAttribute("employee", WebRequest.SCOPE_SESSION) != null) {
- model.addAttribute("rtn", rtnname);
- model.addAttribute("po", po);
- return "ChangePO";
- }
- model.addAttribute("Message", "500,SessionExpiry");
- return "GridLogin";*/
- return "login";
- }
- /****************************** To Vendor Status Updater*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: Coordiantor ID & Password
- * Output :: Naviagtes to Login Page
- */
- @RequestMapping(value = "/vendorupdation.do", method = RequestMethod.POST)
- public String vendoupdataion(@RequestParam(value = "coordinatorid") long coordinatorid,
- @RequestParam(value = "password") String password, Model model, WebRequest wr) {
- RTN rtn = empser.getCoordinatorRTN(coordinatorid);
- int flag = venser.setCoordinatorPassword(coordinatorid, password);
- if (flag > 0) {
- if (empser.setRTNStatus(rtn.getRtnid(), "approved")) {
- //System.out.println("rtn status updated..");
- }
- model.addAttribute("Message", "200,PasswordReset");
- // return
- // "redirect:updatevendor.vendor?vendorid="+vendor.getVendorid();
- return "login";
- } else {
- model.addAttribute("Message", "500,PasswordReset");
- // return
- // "redirect:updatevendor.vendor?vendorid="+vendor.getVendorid();
- return "login";
- }
- }
- /****************************** To Save the document in Alfresco*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: file, titel, sheeno, description, entryid & description
- * Output :: Status
- */
- @Transactional
- @SuppressWarnings({ "unchecked" })
- @RequestMapping(value = "/documentsubmission.vendor", method = RequestMethod.POST)
- public @ResponseBody String documentUpload(@RequestParam(value = "file") MultipartFile file,
- @RequestParam("entryid") long entryid, @RequestParam("title") String tilte,
- @RequestParam("description") String description, @RequestParam("sheet") long sheet, WebRequest wr,
- Model model, FileDetails filedtls, @ModelAttribute("WorkFlow") Workflow workflow, HttpServletRequest req) {
- //System.out.println("reached here.." + file.getOriginalFilename());
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- RTN rtn = empser.getRTN(coordinator.getRtnid());
- if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- MasterDetails masterdetail = venser.getMasterDetails(entryid);
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- HttpClient client = new HttpClient();
- //System.out.println("ticket: "+employee.getAlf_ticket());
- RTNType rtntype = empser.getRTNType(rtn.getRtnid());
- MasterDetails masterdetails = venser.getMasterDetails(entryid);
- model.addAttribute("masterdetails", masterdetails);
- try {
- //System.out.println(" file original : "+file.getOriginalFilename());
- File convFile = new File(file.getOriginalFilename());
- file.transferTo(convFile);
- sitename = rtn.getRtn();
- List<Document> docs = venser.getDocuments(entryid);
- // String stationsshortname = "";
- /////////////////////////////////////////
- // STATIONS SHORT NAMES CODE
- /////////////////////////////////////////////
- Document document = new Document();
- document.setDescription(description);
- document.setEntryid(entryid);
- document.setTitle(tilte);
- document.setVersion(1);
- document.setDocument(file.getOriginalFilename());
- document.setSheet(sheet);
- JSONObject filemeta = new JSONObject();
- filemeta.put("masterdetails", masterdetail);
- filemeta.put("rtn", rtn);
- filemeta.put("coordinator", coordinator);
- filemeta.put("docs", docs);
- filemeta.put("documentdetails", document);
- //System.out.println(filemeta.toString());
- String stations = masterdetail.getStations().replace(", ", "-");
- stations = stations.replace(" ", "");
- stations = stations.replace(",", "");
- String uniquekey = "";
- // for (int i = 0; i < stations.length; i++) {
- if (rtntype.getRtntype().contains("TL")) {
- //System.out.println("TL-file entered");
- uniquekey += rtn.getRtn() + "-";
- uniquekey += rtn.getNoa() + "-";
- uniquekey += stations + "-";
- uniquekey += masterdetail.getRoot() + "-";
- uniquekey += masterdetail.getKvid() + "-";
- uniquekey += sheet;
- JSONObject entryobj = new JSONObject(masterdetail.getEntry());
- Set<String> keys = entryobj.keySet();
- Part[] parts = new Part[keys.size() + 13];
- int index = 0;
- //System.out.println("reached here..");
- for (String key : keys) {
- /*System.out.println("key:-- "+key);
- System.out.println("key2:-- "+entryobj.getString(key));*/
- parts[index] = new StringPart(key, entryobj.getString(key));
- index++;
- }
- parts[index] = new StringPart("title", tilte);
- parts[++index] = new StringPart("RTN", rtn.getRtn());
- parts[++index] = new StringPart("description", description);
- parts[++index] = new StringPart("stationname", stations.trim());
- parts[++index] = new StringPart("NOA", rtn.getNoa());
- parts[++index] = new StringPart("coordinator", coordinator.getEmailid());
- //System.out.println(parts[++index] = new StringPart("coordinator", coordinator.getEmailid()));
- parts[++index] = new StringPart("RTNTYPE", rtntype.getRtntype());
- parts[++index] = new StringPart("sheetno", sheet + "");
- parts[++index] = new StringPart("revisionno", 0 + "");
- parts[++index] = new StringPart("uniquekey", uniquekey);
- parts[++index] = new StringPart("firstname", coordinator.getFirstname());
- parts[++index] = new StringPart("address", coordinator.getAddress());
- parts[++index] = new FilePart("file", convFile);
- /*System.out.println("reached here..2 "+index);
- System.out.println("reached here..3 "+coordinator.getAddress());
- System.out.println(parts.length);
- System.out.println(rtntype.getRtntype());*/
- PostMethod createSitePost = new PostMethod(
- alfresco_tl_fileupload + "?alf_ticket=" + employee.getAlf_ticket());
- createSitePost.setRequestEntity(new MultipartRequestEntity(parts, createSitePost.getParams()));
- int respstatus = client.executeMethod(createSitePost);
- //System.out.println("respstatus: "+respstatus);
- if (respstatus == HttpStatus.SC_OK) {
- //System.out.println("alfresco saved sucessfully");
- model.addAttribute("Message", "200,DocumentUpload");
- String response = createSitePost.getResponseBodyAsString();
- //System.out.println("response ::::::::::::::::::: " + response);
- JSONObject obj = new JSONObject(response);
- String noderef = obj.getString("message");
- document.setNoderef(noderef);
- document.setUniquekey(uniquekey);
- document.setStation(stations.trim());
- if (venser.saveDocument(document)) {
- //System.out.println("saved sucessfully");
- return "200,DocumentUpload";
- } else {
- //System.out.println("not saved sucessfully");
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- }else if(respstatus ==808) {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "808,DocumentUpload";
- }
- else {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- } else {
- uniquekey += rtn.getRtn() + "-";
- uniquekey += rtn.getNoa() + "-";
- uniquekey += stations + "-";
- uniquekey += masterdetail.getRoot() + "-";
- uniquekey += masterdetail.getKvid() + "-";
- uniquekey += masterdetail.getDrawingtype() + "-";
- uniquekey += sheet;
- String drawingname = "";
- String drawingtype = "";
- if (masterdetail.getSubsubcategory().trim().equalsIgnoreCase("NA")) {
- drawingname = masterdetail.getDrawingtype() + "-" + masterdetail.getSubcategory();
- drawingtype = masterdetail.getSubsubcategory();
- } else {
- drawingname = masterdetail.getSubcategory();
- drawingtype = masterdetail.getDrawingtype() + "-" + masterdetail.getSubsubcategory();
- }
- String kv = "NA";
- String make = "NA";
- String kvmake = "";
- String kvlist[] = masterdetail.getKvid().split("-");
- String metalist[] = masterdetail.getMetakv().split("-");
- for (int j = 0; j < metalist.length; j++) {
- if (metalist[j].trim().equalsIgnoreCase("KV")) {
- kv = kvlist[j];
- }
- if (metalist[j].trim().equalsIgnoreCase("MAKE")) {
- make = kvlist[j];
- }
- if (j == metalist.length - 1) {
- kvmake += metalist[j].trim() + "-" + metalist[j].trim();
- } else {
- kvmake += metalist[j].trim() + "-" + metalist[j].trim() + ",";
- }
- }
- Part[] parts = {
- new StringPart("title", document.getTitle()), new StringPart("RTN", rtn.getRtn()),
- new StringPart("description", document.getDescription()),
- new StringPart("stationname", stations), new StringPart("NOA", rtn.getNoa()),
- new StringPart("coordinator", coordinator.getEmailid()),
- new StringPart("address", coordinator.getAddress()),
- new StringPart("firstname", coordinator.getFirstname()),
- new StringPart("RTNTYPE", rtntype.getRtntype()),
- new StringPart("structuretype", masterdetail.getCategory()),
- new StringPart("drawingname", drawingname), new StringPart("drawingtype", drawingtype),
- new StringPart("department", masterdetail.getRoot()),
- new StringPart("vendormail", coordinator.getEmailid()),
- new StringPart("drawingshortname", masterdetail.getDrawingtype()),
- new StringPart("KV", kv), new StringPart("make", make),
- new StringPart("kvmake", kvmake), new StringPart("sheetno", sheet + ""),
- new StringPart("revisionno", 0 + ""), new StringPart("uniquekey", uniquekey),
- new FilePart("file", convFile)
- };
- PostMethod createSitePost = new PostMethod(
- alfresco_ss_fileupload + "?alf_ticket=" + employee.getAlf_ticket());
- createSitePost.setRequestEntity(new MultipartRequestEntity(parts, createSitePost.getParams()));
- int respstatus = client.executeMethod(createSitePost);
- if (respstatus == HttpStatus.SC_OK) {
- String response = createSitePost.getResponseBodyAsString();
- JSONObject obj = new JSONObject(response);
- String noderef = obj.getString("message");
- document.setNoderef(noderef);
- document.setUniquekey(uniquekey);
- document.setStation(stations.trim());
- if (venser.saveDocument(document)) {
- return "200,DocumentUpload";
- } else {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- } else if(respstatus ==808) {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "808,DocumentUpload";
- }else {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- }
- } catch (Exception err) {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- } else {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- }
- return "500,DocumentUpload";
- }
- /****************************** To upload revision document in Alfresco*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: file, titel, sheeno, description, entryid & description
- * Output :: Status
- */
- @Transactional
- @RequestMapping(value = "/documentrevision.vendor", method = RequestMethod.POST)
- public @ResponseBody String documnetRevision(@RequestParam(value = "file") MultipartFile file,
- @RequestParam("title") String tilte, @RequestParam("description") String description,
- @RequestParam("sheet") long sheet, @RequestParam("documentid") long documentid,
- @ModelAttribute("WorkFlow") Workflow workflow, WebRequest wr, Model model, FileDetails filedtls,
- HttpServletRequest req) {
- //System.out.println("reached here..");
- if (wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION) != null) {
- Coordinator coordinator = (Coordinator) wr.getAttribute("coordinator", WebRequest.SCOPE_SESSION);
- RTN rtn = empser.getRTN(coordinator.getRtnid());
- if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- Document revisiondocument = venser.getDocument(documentid);
- //MasterDetails masterdetail = venser.getMasterDetails(revisiondocument.getEntryid());
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- HttpClient client = new HttpClient();
- PostMethod createSitePost = new PostMethod(
- alfresco_document_upload + "?alf_ticket=" + employee.getAlf_ticket());
- System.out.println("Post method testing 1--- " +createSitePost);
- //Anurag written code start
- PostMethod createSitePostR = new PostMethod(
- alfresco_document_uploadR + "?alf_ticket=" + employee.getAlf_ticket());
- System.out.println("Post method testing 2--- " +createSitePostR);
- GetMethod createSiteGet = new GetMethod(alfresco_folder_details + "?nodeId=" + revisiondocument.getNoderef() +
- "&alf_ticket=" + employee.getAlf_ticket());
- //System.out.println("Get method testing 3--- " +createSiteGet);
- String foldernoderef=null;
- //Anurag written code end
- File convFile = new File(file.getOriginalFilename());
- try {
- file.transferTo(convFile);
- sitename = rtn.getRtn();
- long entryid = revisiondocument.getEntryid();
- //if(revisiondocument.getStatusid()==5)
- {
- Part[] parts = {
- new StringPart("description", description),
- new StringPart("overwrite", "false"),
- new StringPart("updatenoderef", revisiondocument.getNoderef()),
- new StringPart("updatenameandmimetype","true"),
- new StringPart("thumbnails","true"),
- new StringPart("majorversion", "true"), new FilePart("filedata", convFile) };
- //System.out.println("Parts testing 1--- " +parts);
- //System.out.println("revision noderef " +revisiondocument.getNoderef());
- //.out.println("original file name " +file.getOriginalFilename());
- MasterDetails masterdetails = venser.getMasterDetails(entryid);
- createSitePost.setRequestEntity(new MultipartRequestEntity(parts, createSitePost.getParams()));
- //Anurag written code start
- createSiteGet.setRequestHeader("Accept", "application/json");
- int statusG = client.executeMethod(createSiteGet);
- System.out.println("status: "+statusG);
- JSONObject response = new JSONObject(createSiteGet.getResponseBodyAsString());
- System.out.println("response "+response);
- JSONArray array = response.getJSONArray("results");
- JSONObject obj = null;
- String folderName=null;
- for (int i = 0; i < array.length(); i++) {
- obj= array.getJSONObject(i);
- foldernoderef=obj.getString("spaceStoreId");
- folderName=obj.getString("foldername");
- //foldernoderef='"'+foldernoderef+'"';
- //System.out.println("folder node ref "+foldernoderef);
- }
- JSONObject siteObject = new JSONObject();
- int respstatus=0;
- int statusR=0;
- //System.out.println("folder Name123: "+folderName);
- if(folderName.contains("Unread"))
- {
- //System.out.println("folder Name: "+folderName);
- siteObject.put("page", "1");
- siteObject.put("inplace", "true");
- siteObject.put("nodeRef", revisiondocument.getNoderef());
- siteObject.put("insert-content","workspace://SpacesStore/"+alfresco_insert_nodeRef);
- siteObject.put("destination-folder",foldernoderef);
- siteObject.put("destination-name", file.getOriginalFilename());
- siteObject.put("majorVersion", "true");
- createSitePostR.setRequestHeader("Content-Type", "application/json");
- createSitePostR.setRequestHeader("Accept", "application/json");
- createSitePostR.setRequestEntity(new StringRequestEntity(siteObject.toString(), "application/json", "UTF-8"));
- //int status = client.executeMethod(createSitePostR);
- //System.out.println("create a site script status :: " + status);
- respstatus = client.executeMethod(createSitePost);
- //System.out.println("respstatus testing 1--- " +respstatus);
- //int respstatusR = client.executeMethod(createSitePostR);
- statusR = client.executeMethod(createSitePostR);
- //System.out.println("respstatusR testing 1--- " +statusR);
- //System.out.println("statusG testing 3--- " +statusG);
- }
- else
- {
- //System.out.println("respstatusR testing 2--- " +statusR);
- respstatus = client.executeMethod(createSitePost);
- //System.out.println("respstatus testing 2--- " +respstatus);
- }
- if (respstatus == HttpStatus.SC_OK ) {
- //Anurag written code end
- //System.out.println("respstatus Status 1 " +respstatus);
- RTNType rtntype = empser.getRTNType(rtn.getRtnid());
- model.addAttribute("masterdetails", masterdetails);
- if (rtntype.getRtntype().equalsIgnoreCase("TL-Conductor")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Foundation")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Hardware")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Insulator")
- || rtntype.getRtntype().equalsIgnoreCase("TL-Tower")) {
- TreeMap<String, String> entrydata = new TreeMap<String, String>();
- JSONObject entryjson = new JSONObject(masterdetails.getEntry());
- @SuppressWarnings("unchecked")
- Set<String> keys = entryjson.keySet();
- for (String key : keys) {
- entrydata.put(key, entryjson.getString(key));
- }
- model.addAttribute("entrydata", entrydata);
- model.addAttribute("Message", "");
- // return "TLDocumentDetails";
- } else {
- model.addAttribute("Message", "");
- // return "DocumentsDetails";
- }
- //String response = createSitePost.getResponseBodyAsString();
- //System.out.println("response ::::::::::::::::::: " + response);
- Document document = new Document();
- document.setDocumentid(revisiondocument.getDocumentid());
- document.setDescription(description);
- document.setEntryid(entryid);
- document.setVersion(revisiondocument.getVersion() + 1);
- document.setSheet(sheet);
- document.setNoderef(revisiondocument.getNoderef());
- document.setDocument(file.getOriginalFilename());
- document.setStation(revisiondocument.getStation());
- document.setTitle(tilte);
- document.setUniquekey(revisiondocument.getUniquekey());
- document.setStatusid(11);
- if(venser.updateDocument(document)){
- return "200,DocumentUpload";
- }
- /*if (venser.saveDocument(document)) {
- venser.updateDocumentStatus(revisiondocument.getDocumentid(), 11);
- return "true";
- } */else {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- }else if(respstatus ==808) {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "808,DocumentUpload";
- } else {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- }
- } catch (Exception err) {
- err.printStackTrace();
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- } else {
- TransactionInterceptor.currentTransactionStatus().setRollbackOnly();
- return "500,DocumentUpload";
- }
- }
- model.addAttribute("Message", "500,SessionExpery");
- return "500,DocumentUpload";
- }
- @RequestMapping(value = "/vendorhome.tls", method = RequestMethod.GET)
- public String ReDirectHome(WebRequest wr, Model model) {
- if (wr.getAttribute("vendor", WebRequest.SCOPE_SESSION) != null) {
- return "VendorHome";
- }
- model.addAttribute("Message", "Your Login Sesssion has Experied.. Please, login again");
- return "GridLogin";
- }
- // Categories and Subcategories
- /****************************** To get the Subcategories of Root caegory from Alfresco*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: Dept name
- * Output :: String(JSON array with childs)
- */
- @RequestMapping(value = "/subCategories.vendor", method = RequestMethod.POST, produces = "application/json")
- public @ResponseBody String getSubCategories(WebRequest wr, Model model,
- @RequestParam(value = "DeptName") String DeptName) throws HttpException, IOException {
- HttpClient client = new HttpClient();
- JSONObject categoryResponse;
- JSONObject subcategoryResponse = null;
- if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- String url = alfresco_category_root_children + "?alf_ticket=" + employee.getAlf_ticket();
- GetMethod category = new GetMethod(url);
- /* try { */
- category.setRequestHeader("Accept", "application/json");
- int status = client.executeMethod(category);
- if (status == HttpStatus.SC_OK) {
- categoryResponse = new JSONObject(category.getResponseBodyAsString());
- for (int i = 0; i < categoryResponse.getJSONObject("data").getJSONArray("items").length(); i++) {
- GetMethod subcategory = null;
- JSONObject allcategories = (JSONObject) categoryResponse.getJSONObject("data").getJSONArray("items")
- .get(i);
- if (allcategories.getString("name").equals("Departments")) {
- String noderef = allcategories.getString("nodeRef").replace("workspace://SpacesStore/", "");
- String url1 = alfresco_formpicker_workspace_spacesstore + "/" + noderef + "/children"
- + "?alf_ticket=" + employee.getAlf_ticket();
- GetMethod category1 = new GetMethod(url1);
- client.executeMethod(category1);
- JSONObject DeptcategoryResponse = new JSONObject(category1.getResponseBodyAsString());
- JSONArray DeptResponseArray = DeptcategoryResponse.getJSONObject("data").getJSONArray("items");
- for (int subcat = 0; subcat < DeptResponseArray.length(); subcat++) {
- JSONObject Deptallcategories = (JSONObject) DeptResponseArray.get(subcat);
- if (Deptallcategories.getString("name").equalsIgnoreCase(DeptName)) {
- String Civilnoderef = Deptallcategories.getString("nodeRef")
- .replace("workspace://SpacesStore/", "");
- String Civilurl = alfresco_formpicker_workspace_spacesstore + "/" + Civilnoderef
- + "/children" + "?alf_ticket=" + employee.getAlf_ticket();
- subcategory = new GetMethod(Civilurl);
- client.executeMethod(subcategory);
- subcategoryResponse = new JSONObject(subcategory.getResponseBodyAsString());
- return subcategoryResponse.getJSONObject("data").getJSONArray("items").toString();
- }
- }
- }
- }
- } else {
- }
- } else {
- }
- return "";
- }
- /****************************** Tofetch the category root from Alfresco*******************************
- *
- * Author @ Sathish Punna, Written on 20-05-2017 12:00:00,
- * Status :: in use
- * Inputs :: -
- * Output :: String(JSON array with category root)
- */
- @SuppressWarnings("unused")
- @RequestMapping(value = "/Categories.vendor", method = RequestMethod.POST, produces = "application/json")
- public @ResponseBody String getCategories(WebRequest wr, Model model) throws HttpException, IOException {
- HttpClient client = new HttpClient();
- JSONObject categoryResponse;
- JSONObject DeptcategoryResponse = null;
- if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee", WebRequest.SCOPE_SESSION);
- //System.out.println("In category Vendorsssssssssssssssssss");
- String url = alfresco_category_root_children + "?alf_ticket=" + employee.getAlf_ticket();
- GetMethod category = new GetMethod(url);
- /* try { */
- category.setRequestHeader("Accept", "application/json");
- int status = client.executeMethod(category);
- if (status == HttpStatus.SC_OK) {
- categoryResponse = new JSONObject(category.getResponseBodyAsString());
- for (int i = 0; i < categoryResponse.getJSONObject("data").getJSONArray("items").length(); i++) {
- JSONObject allcategories = (JSONObject) categoryResponse.getJSONObject("data").getJSONArray("items")
- .get(i);
- if (allcategories.getString("name").equals("Departments")) {
- String noderef = allcategories.getString("nodeRef").replace("workspace://SpacesStore/", "");
- String url1 = alfresco_formpicker_workspace_spacesstore + "/" + noderef + "/children"
- + "?alf_ticket=" + employee.getAlf_ticket();
- GetMethod category1 = new GetMethod(url1);
- client.executeMethod(category1);
- DeptcategoryResponse = new JSONObject(category1.getResponseBodyAsString());
- /*System.out.println("getjson"
- + DeptcategoryResponse.getJSONObject("data").getJSONArray("items").toString());*/
- return DeptcategoryResponse.getJSONObject("data").getJSONArray("items").toString();
- } else {
- return "500,Category";
- }
- }
- } else {
- }
- } else {
- }
- return "";
- }
- /*
- * @RequestMapping(value = "/workFlow.vendor", method = RequestMethod.GET,
- * produces = "application/json") public @ResponseBody String
- * getWorkflows(WebRequest wr, Model model) throws HttpException,
- * IOException {
- *
- * HttpClient client = new HttpClient(); JSONObject workflowResp = null;
- *
- * if (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- * GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee",
- * WebRequest.SCOPE_SESSION); String workflowUrl =
- * "http://localhost:8080/alfresco/service/api/workflow-definitions" +
- * "?alf_ticket=" + employee.getAlf_ticket(); GetMethod workflowResponse =
- * new GetMethod(workflowUrl); client.executeMethod(workflowResponse);
- * workflowResp = new
- * JSONObject(workflowResponse.getResponseBodyAsString());
- * System.out.println("workflowResponse" +
- * workflowResp.getJSONArray("data"));
- *
- * }
- *
- * return workflowResp.getJSONArray("data").toString();
- *
- * }
- *
- *
- * This method is used for Apply the waterMark On doc
- *
- * private String applyWaterMarkOnDocs(String ticket, String docnoderef,
- * String uniquekey) { String WaterMark_nodeRef = null; HttpClient client =
- * new HttpClient(); PostMethod createSitePost = new PostMethod(
- * "http://localhost:8080/alfresco/service/pdftoolkit/powergrid/pdfWaterMark"
- * + "?alf_ticket=" + ticket);
- *
- * // Pass the Request Body Data as json payload JSONObject siteObject = new
- * JSONObject(); try { siteObject.put("nodeRef", docnoderef);
- * siteObject.put("paramPage", "1"); siteObject.put("paramPosition",
- * "topleft"); siteObject.put("paramWaterMarkerText", "Desc," + uniquekey);
- * System.out.println("Site Object " + siteObject.toString());
- *
- * createSitePost.setRequestHeader("Content-Type", "application/json");
- * createSitePost.setRequestHeader("Accept", "application/json");
- * createSitePost .setRequestEntity(new
- * StringRequestEntity(siteObject.toString(), "application/json", "UTF-8"));
- *
- * int status = client.executeMethod(createSitePost);
- * System.out.println("create a site script status :: " + status);
- *
- * if (status == HttpStatus.SC_OK) {
- *
- * System.out.println("Site created OK"); String response =
- * createSitePost.getResponseBodyAsString(); JSONObject obj = new
- * JSONObject(response); WaterMark_nodeRef = obj.getString("nodeRef");
- *
- * } else {
- *
- * System.out.println("There is a problem of while applying waterMark"); } }
- * catch (Exception err) { err.printStackTrace(); }
- *
- * return WaterMark_nodeRef;
- *
- * }
- *
- */ /*
- * This method is used for start the workflow while uploading the
- * document successfully
- *
- */
- /*
- * private int startWorkFlow(Workflow workflow, String waterMark_NoderRef,
- * String stations, String rtn, String vendorEmailId, WebRequest wr) throws
- * HttpException, IOException {
- *
- * // Workflow workflow = null; int status = 0;
- *
- * System.out.println("Cell" + waterMark_NoderRef + "Stations ----->" +
- * stations);
- *
- * GetMethod createSitePost = null; if
- * (comnsevice.fetchAdminAccessToken("admin", "admin", wr)) {
- *
- * GridEmployee employee = (GridEmployee) wr.getAttribute("tempemployee",
- * WebRequest.SCOPE_SESSION); HttpClient client = new HttpClient();
- *
- * createSitePost = new
- * GetMethod("http://localhost:8080/alfresco/s/api/sites/" + sitename +
- * "?alf_ticket=" + employee.getAlf_ticket().trim()); int respstatus =
- * client.executeMethod(createSitePost); System.out.println("Status :: " +
- * respstatus); JSONObject js = new
- * JSONObject(createSitePost.getResponseBodyAsString()); for (int i = 0; i <
- * js.getJSONArray("siteManagers").length(); i++) {
- *
- * System.out.println("sitenamevvvvvv" +
- * js.getJSONArray("siteManagers").get(i)); String managerName = (String)
- * js.getJSONArray("siteManagers").get(i); PostMethod startworkflow = new
- * PostMethod(
- * "http://localhost:8080/alfresco/service/powergrid/startworkflow/assigne"
- * + "?alf_ticket=" + employee.getAlf_ticket());
- * workflow.setWorkFlowName("activiti$vendormanagement");
- * workflow.setNodeRef(waterMark_NoderRef);
- * workflow.setDescription("Please Review The File Uploaded By" + "," + rtn
- * + "," + stations.toString() + "," + vendorEmailId);
- * workflow.setAssigneName(managerName);
- *
- * startworkflow.setRequestHeader("Content-Type", "application/json");
- * startworkflow .setRequestEntity(new
- * StringRequestEntity(workflow.toString(), "application/json", "UTF-8"));
- * status = client.executeMethod(startworkflow); }
- *
- * } if (status == HttpStatus.SC_OK) {
- *
- * System.out.println(vendorEmailId);
- *
- * return 1; }
- *
- * return 0;
- *
- * }
- */}
Add Comment
Please, Sign In to add comment