Mercurial > hg > LGDataverses
comparison src/main/java/de/mpiwg/monographs/servlet/RemoveFileMetadata.java @ 0:fcb8807fbd84
Fist commit!
| author | "jurzua <jurzua@mpiwg-berlin.mpg.de>" |
|---|---|
| date | Tue, 10 Mar 2015 15:15:30 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:fcb8807fbd84 |
|---|---|
| 1 package de.mpiwg.monographs.servlet; | |
| 2 | |
| 3 import java.io.IOException; | |
| 4 import java.util.List; | |
| 5 import java.util.logging.Level; | |
| 6 import java.util.logging.Logger; | |
| 7 | |
| 8 import javax.faces.application.FacesMessage; | |
| 9 import javax.faces.context.FacesContext; | |
| 10 import javax.inject.Inject; | |
| 11 import javax.naming.Context; | |
| 12 import javax.naming.InitialContext; | |
| 13 import javax.naming.NamingException; | |
| 14 import javax.servlet.ServletException; | |
| 15 import javax.servlet.http.HttpServlet; | |
| 16 import javax.servlet.http.HttpServletRequest; | |
| 17 import javax.servlet.http.HttpServletResponse; | |
| 18 | |
| 19 import org.codehaus.jettison.json.JSONException; | |
| 20 import org.codehaus.jettison.json.JSONObject; | |
| 21 import org.swordapp.server.AuthCredentials; | |
| 22 import org.swordapp.server.SwordServerException; | |
| 23 | |
| 24 import edu.harvard.iq.dvn.api.datadeposit.SwordAuth; | |
| 25 import edu.harvard.iq.dvn.core.admin.VDCUser; | |
| 26 import edu.harvard.iq.dvn.core.study.EditStudyFilesService; | |
| 27 import edu.harvard.iq.dvn.core.study.EditStudyService; | |
| 28 import edu.harvard.iq.dvn.core.study.Study; | |
| 29 import edu.harvard.iq.dvn.core.study.StudyFileEditBean; | |
| 30 | |
| 31 public class RemoveFileMetadata extends AbstractMonographServlet { | |
| 32 | |
| 33 private static final Logger logger = Logger.getLogger("monographs.RemoveFileMetadata"); | |
| 34 | |
| 35 private EditStudyFilesService editStudyFilesService; | |
| 36 private Context ctx = null; | |
| 37 | |
| 38 @Inject | |
| 39 private SwordAuth swordAuth; | |
| 40 | |
| 41 public void init() throws ServletException {} | |
| 42 | |
| 43 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
| 44 | |
| 45 JSONObject jsonResponse = new JSONObject(); | |
| 46 | |
| 47 String studyGlobalId = request.getParameter("studyId"); | |
| 48 String user = request.getParameter("user"); | |
| 49 String password = request.getParameter("password"); | |
| 50 Long fileMetadataId = null; | |
| 51 | |
| 52 try{ | |
| 53 fileMetadataId = Long.parseLong(request.getParameter("fileMetadataId")); | |
| 54 }catch(Exception e){ | |
| 55 e.printStackTrace(); | |
| 56 } | |
| 57 | |
| 58 try { | |
| 59 | |
| 60 editStudyFilesService = (EditStudyFilesService) getCtx().lookup("java:comp/env/editStudyFiles"); | |
| 61 | |
| 62 } catch (NamingException e) { | |
| 63 e.printStackTrace(); | |
| 64 FacesContext context = FacesContext.getCurrentInstance(); | |
| 65 FacesMessage errMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), null); | |
| 66 context.addMessage(null, errMessage); | |
| 67 } | |
| 68 | |
| 69 Study study = null; | |
| 70 try { | |
| 71 study = getStudy(studyGlobalId); | |
| 72 editStudyFilesService.setStudyVersion(study.getId());//ok | |
| 73 } catch (Exception e) { | |
| 74 logger.log(Level.WARNING, "Study no found. " + studyGlobalId); | |
| 75 error(jsonResponse, e); | |
| 76 } | |
| 77 | |
| 78 try { | |
| 79 | |
| 80 for(Object obj : editStudyFilesService.getCurrentFiles()){ | |
| 81 StudyFileEditBean file = (StudyFileEditBean)obj; | |
| 82 | |
| 83 if(file.getFileMetadata().getId().equals(fileMetadataId)){ | |
| 84 file.setDeleteFlag(true); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 AuthCredentials authCredentials = new AuthCredentials(user, password, null); | |
| 89 VDCUser vdcUser = swordAuth.auth(authCredentials); | |
| 90 | |
| 91 editStudyFilesService.save(vdcUser.getId(), vdcUser.getId()); | |
| 92 | |
| 93 jsonResponse.put("status", "ok"); | |
| 94 | |
| 95 | |
| 96 } catch (Exception e) { | |
| 97 logger.log(Level.SEVERE, e.getMessage()); | |
| 98 error(jsonResponse, e); | |
| 99 } | |
| 100 | |
| 101 java.io.PrintWriter out = response.getWriter(); | |
| 102 out.print(jsonResponse); | |
| 103 out.flush(); | |
| 104 } | |
| 105 } |
