1 3 package org.contineo.actions.rest; 4 5 import java.io.FileNotFoundException ; 6 import java.io.IOException ; 7 8 import javax.servlet.http.HttpServletResponse ; 9 10 import org.contineo.actions.documan.util.DownloadDocUtil; 11 import org.contineo.admin.Menu; 12 import org.contineo.admin.dao.MenuDAO; 13 import org.contineo.apis.rest.HttpStatusCodes; 14 import org.contineo.documan.Document; 15 import org.contineo.documan.dao.DocumentDAO; 16 17 21 public class CheckoutDocumentRestAction extends RESTAction { 22 23 24 private final int thisDocId; 25 26 27 public CheckoutDocumentRestAction(String p_schemaName, 28 String requestedRESTUrl, String p_userName, 29 HttpServletResponse p_response, int p_docId) { 30 super(p_schemaName, requestedRESTUrl, p_userName, p_response, "GET REST/document/XX/checkout: checkout doc XX"); 31 thisDocId = p_docId; 32 33 processRequest(); 34 } 35 36 @Override 37 protected void processRequest() { 38 MenuDAO menuDao = new MenuDAO(); 40 Menu thisMenu = menuDao.findByPrimaryKey(thisDocId); 41 DocumentDAO ddao = new DocumentDAO(); 42 Document thisDoc = ddao.findByMenuId(thisDocId); 43 if (thisMenu == null || thisDoc == null) { 44 setHttpStatusCode(HttpStatusCodes.NOT_FOUND); 45 return; 46 } 47 48 if (!menuDao.isWriteEnable(thisDocId, userName)) { 50 setHttpStatusCode(HttpStatusCodes.FORBIDDEN); 51 return; 52 } 53 54 if (thisDoc.getDocStatus() == Document.DOC_CHECKED_OUT) { 56 setHttpStatusCode(HttpStatusCodes.FORBIDDEN); 57 return; 58 } 59 60 thisDoc.setCheckoutUser(userName); 62 thisDoc.setDocStatus(Document.DOC_CHECKED_OUT); 63 thisDoc.setMenu(thisMenu); 64 if (ddao.store(thisDoc) == false) { 65 setHttpStatusCode(HttpStatusCodes.INTERNAL_SERVER_ERROR); 66 addLogMessage("Document can not be stored, so updating the status of the document to checked out was not possible."); 67 return; 68 } 69 70 try { 72 DownloadDocUtil.downloadDocument(response, thisDocId, null); 73 } catch (FileNotFoundException e) { 74 setHttpStatusCode(HttpStatusCodes.NOT_FOUND); 75 return; 76 } catch (IOException e) { 77 setHttpStatusCode(HttpStatusCodes.BAD_REQUEST); 78 return; 79 } 80 } 81 } 82 | Popular Tags |