# HG changeset patch # User "jurzua " # Date 1431003406 -7200 # Node ID 9b408c9b05abc742bdf267a19ef7b5474a472218 # Parent 65774fc878b739c55210104c0caeab31178d13d9 Integration with LGServices. diff -r 65774fc878b7 -r 9b408c9b05ab DVN-web/.classpath --- a/DVN-web/.classpath Tue Mar 10 15:47:07 2015 +0100 +++ b/DVN-web/.classpath Thu May 07 14:56:46 2015 +0200 @@ -29,16 +29,8 @@ - - - - - - - - @@ -123,16 +115,12 @@ - - - - diff -r 65774fc878b7 -r 9b408c9b05ab DVN-web/docs/readme.txt --- a/DVN-web/docs/readme.txt Tue Mar 10 15:47:07 2015 +0100 +++ b/DVN-web/docs/readme.txt Thu May 07 14:56:46 2015 +0200 @@ -51,7 +51,7 @@ -curl --form upload=@pom.xml --form user=networkAdmin --form password=networkAdmin --form studyId=hdl:TEST/10001 http://localhost/dvn/saveResource +curl --form upload=@pom.xml --form user=networkAdmin --form password=networkAdmin --form studyId=hdl:TEST/10002 http://localhost/dvn/saveResource GET USER http://localhost/dvn/getUser?user=jurzua&password=221082 diff -r 65774fc878b7 -r 9b408c9b05ab DVN-web/src/main/java/de/mpiwg/monographs/servlet/GetAllUsers.java --- a/DVN-web/src/main/java/de/mpiwg/monographs/servlet/GetAllUsers.java Tue Mar 10 15:47:07 2015 +0100 +++ b/DVN-web/src/main/java/de/mpiwg/monographs/servlet/GetAllUsers.java Thu May 07 14:56:46 2015 +0200 @@ -36,11 +36,8 @@ jsonResponse.put("state", "ok"); jsonResponse.put("users", array); } catch (JSONException e) { - // TODO Auto-generated catch block e.printStackTrace(); - } - - + } java.io.PrintWriter out = response.getWriter(); out.print(jsonResponse); diff -r 65774fc878b7 -r 9b408c9b05ab DVN-web/src/main/java/de/mpiwg/monographs/servlet/MonographUtils.java --- a/DVN-web/src/main/java/de/mpiwg/monographs/servlet/MonographUtils.java Tue Mar 10 15:47:07 2015 +0100 +++ b/DVN-web/src/main/java/de/mpiwg/monographs/servlet/MonographUtils.java Thu May 07 14:56:46 2015 +0200 @@ -7,12 +7,60 @@ import edu.harvard.iq.dvn.core.admin.UserGroup; import edu.harvard.iq.dvn.core.admin.VDCUser; import edu.harvard.iq.dvn.core.study.FileMetadata; +import edu.harvard.iq.dvn.core.study.Metadata; import edu.harvard.iq.dvn.core.study.Study; import edu.harvard.iq.dvn.core.study.StudyVersion; import edu.harvard.iq.dvn.core.vdc.VDCGroup; +import edu.harvard.iq.dvn.core.web.study.StudyUI; +import edu.harvard.iq.dvn.core.vdc.VDC; public class MonographUtils { + public static JSONObject jsonStudyUI(StudyUI studyUI){ + JSONObject json = null; + + if(studyUI != null){ + try { + json = jsonStudy(studyUI.getStudy()); + json.put("metadata", jsonMetadata(studyUI.getMetadata())); + + String status = + (studyUI.getStudy().getLatestVersion().isDraft()) ? + "Draft" : + ((studyUI.getStudy().getLatestVersion().isInReview()) ? + "In Review" :(studyUI.getStudy().getLatestVersion().isReleased()) ? + "Released" : "Deaccessioned"); + json.put("status", status); + + } catch (Exception e) { + e.printStackTrace(); + } + } + return json; + } + + public static JSONObject jsonMetadata(Metadata meta){ + JSONObject json = new JSONObject(); + + try { + + json.put("accessToSources", meta.getAccessToSources()); + json.put("actionsToMinimizeLoss", meta.getActionsToMinimizeLoss()); + json.put("authorsStr", meta.getAuthorsStr()); + json.put("availabilityStatus", meta.getAvailabilityStatus()); + json.put("citationRequirements", meta.getCitationRequirements()); + json.put("subTitle", meta.getSubTitle()); + json.put("title", meta.getTitle()); + + } catch (Exception e) { + e.printStackTrace(); + } + + + + return json; + } + public static JSONObject jsonStudy(Study study){ JSONObject json = new JSONObject(); @@ -26,8 +74,15 @@ json.put("protocol", study.getProtocol()); json.put("version", study.getVersion()); json.put("studyId", study.getStudyId()); + json.put("createTime", study.getCreateTime()); json.put("numberOfDownloads", study.getNumberOfDownloads()); + JSONObject owner = jsonVDC(study.getOwner()); + json.put("owner", owner); + + JSONObject creator = jsonVDCUser(study.getCreator()); + json.put("creator", creator); + JSONArray array0 = new JSONArray(); for(VDCUser user : study.getAllowedUsers()){ array0.put(jsonVDCUser(user)); @@ -42,6 +97,27 @@ return json; } + + public static JSONObject jsonVDC(VDC vdc){ + JSONObject json = new JSONObject(); + + try { + + json.put("name", vdc.getName()); + json.put("aboutThis", vdc.getAboutThisDataverse()); + json.put("visibility", vdc.getVisibility()); + json.put("version", vdc.getVersion()); + json.put("parentSite", vdc.getParentSite()); + json.put("logo", vdc.getLogo()); + json.put("header", vdc.getHeader()); + json.put("alias", vdc.getAlias()); + + } catch (Exception e) { + e.printStackTrace(); + } + + return json; + } public static JSONObject jsonVDCUser(VDCUser user){ JSONObject json = new JSONObject(); diff -r 65774fc878b7 -r 9b408c9b05ab DVN-web/src/main/java/de/mpiwg/monographs/servlet/SaveResource.java --- a/DVN-web/src/main/java/de/mpiwg/monographs/servlet/SaveResource.java Tue Mar 10 15:47:07 2015 +0100 +++ b/DVN-web/src/main/java/de/mpiwg/monographs/servlet/SaveResource.java Thu May 07 14:56:46 2015 +0200 @@ -28,6 +28,7 @@ import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.lang.StringUtils; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.swordapp.server.AuthCredentials; @@ -57,10 +58,10 @@ private static final long serialVersionUID = 1L; - private static final String TMP_DIR = "/home/jurzua/glassfish3/glassfish/domains/domain1/config/files/temp/monographs/"; + private static final String TMP_DIR = "/gazetteer-server/tmp/"; - private int maxFileSize = 50 * 1024; + private int maxFileSize = 100 * 1024; private int maxMemSize = 4 * 1024; private static final Logger logger = Logger.getLogger("monographs.SaveResource"); @@ -82,53 +83,69 @@ } @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, - IOException { + protected void doPost(HttpServletRequest request, HttpServletResponse response) { - logger.info("SaveResource"); - - response.setContentType("application/json"); - JSONObject jsonResponse = new JSONObject(); + try { + response.setContentType("application/json"); + JSONObject jsonResponse = new JSONObject(); + + File file = getFile(request, response); - File file = getFile(request, response); + if (file != null && file.length() > 0) { + String studyGlobalId = params.get("studyId"); + String user = params.get("user"); + String password = params.get("password"); + //String fileLabel = params.get("fileLabel"); - if (file != null) { - String studyGlobalId = params.get("studyId"); - String user = params.get("user"); - String password = params.get("password"); - AuthCredentials authCredentials = new AuthCredentials(user, password, null); + if(StringUtils.isNotEmpty(studyGlobalId) && + StringUtils.isNotEmpty(user) && + StringUtils.isNotEmpty(password)/* && + StringUtils.isNotEmpty(fileLabel)*/){ + AuthCredentials authCredentials = new AuthCredentials(user, password, null); - try { - List list = saveFile(file, studyGlobalId, authCredentials); - - JSONObject fileMetatdata = new JSONObject(); - fileMetatdata.put("id", list.get(0).getFileMetadata().getId()); - fileMetatdata.put("label", list.get(0).getFileMetadata().getLabel()); - fileMetatdata.put("version", list.get(0).getFileMetadata().getVersion()); - fileMetatdata.put("description", list.get(0).getFileMetadata().getDescription()); - - - jsonResponse.put("fileMetadata", fileMetatdata); - - } catch (Exception e) { - logger.log(Level.SEVERE, "Error!!!!!!", e); - error(jsonResponse, e); + try { + List list = saveFile(file, studyGlobalId, authCredentials/*, fileLabel*/); + + JSONObject fileMetatdata = new JSONObject(); + fileMetatdata.put("id", list.get(0).getFileMetadata().getId()); + fileMetatdata.put("label", list.get(0).getFileMetadata().getLabel()); + fileMetatdata.put("version", list.get(0).getFileMetadata().getVersion()); + fileMetatdata.put("description", list.get(0).getFileMetadata().getDescription()); + + + jsonResponse.put("fileMetadata", fileMetatdata); + jsonResponse.put("status", "ok"); + + } catch (Exception e) { + logger.log(Level.SEVERE, "Error!!!!!!", e); + error(jsonResponse, e); + } + }else{ + jsonResponse.put("status", "error"); + jsonResponse.put("error", "The parameters studyId, user and password."); + jsonResponse.put("studyId", studyGlobalId); + jsonResponse.put("user", user); + jsonResponse.put("password", password); + //jsonResponse.put("fileLabel", fileLabel); + } + + }else if(file == null){ + jsonResponse.put("status", "error"); + jsonResponse.put("message", "No file found in the request."); + }else { + jsonResponse.put("status", "error"); + jsonResponse.put("message", "A file has been found as parameter, however it was empty. Check the temporal folder configured in Dataverse. " + TMP_DIR); } - }else{ - try { - jsonResponse.put("error", "No file found in the request."); - } catch (JSONException e) { - logger.log(Level.SEVERE, e.getMessage()); - error(jsonResponse, e); - } + + java.io.PrintWriter out = response.getWriter(); + out.print(jsonResponse); + out.flush(); + } catch (Exception e) { + e.printStackTrace(); } - java.io.PrintWriter out = response.getWriter(); - out.print(jsonResponse); - out.flush(); } private File getFile(HttpServletRequest request, HttpServletResponse response) throws IOException { - File file = null; boolean isMultipart = ServletFileUpload.isMultipartContent(request); @@ -143,7 +160,7 @@ ServletFileUpload upload = new ServletFileUpload(factory); // maximum file size to be uploaded. upload.setSizeMax(maxFileSize); - + StringBuilder sb = new StringBuilder(); try { // Parse the request to get file items. List fileItems = upload.parseRequest(request); @@ -154,9 +171,13 @@ while (i.hasNext()) { FileItem fi = (FileItem) i.next(); + sb.append(fi.getFieldName()); + if(fi.isFormField()){ + sb.append(" is Field"); params.put(fi.getFieldName(), fi.getString()); } else { + sb.append(" is FILE ***"); // Get the uploaded file parameters String fileName = fi.getName(); // Write the file @@ -166,20 +187,25 @@ file = new File(TMP_DIR + fileName.substring(fileName.lastIndexOf("\\") + 1)); } fi.write(file); + sb.append(" Size: " + file.length()); } + sb.append("\n"); } } catch (Exception ex) { ex.printStackTrace(); } + + sb.append((file == null) ? "File is null" : "File Size=" + file.length() + ".\nWhen the file is empty, maybe the tmp folder is wrong configured.\nTMP_DIR: " + TMP_DIR); + logger.log(Level.INFO, "getFile Information:\n" + sb.toString()); + return file; } return null; } - private List saveFile(File file, String studyGlobalId, AuthCredentials authCredentials) throws SwordAuthException, - SwordServerException, SwordError, IOException { + private List saveFile(File file, String studyGlobalId, AuthCredentials authCredentials/*, String fileLabel*/) throws Exception { VDCUser vdcUser = swordAuth.auth(authCredentials); Study study = getStudy(studyGlobalId); @@ -187,19 +213,29 @@ try { List files = getFileList(file, study); studyFileService.addFiles(study.getLatestVersion(), files, vdcUser); - System.out.println("AAAA"); return files; } catch (EJBException ex) { throw new SwordError(UriRegistry.ERROR_BAD_REQUEST, "Unable to add file(s) to study: " + ex.getMessage()); } } - public List getFileList(File file, Study study) throws IOException { + public List getFileList(File uploadedInputFile, Study study) throws Exception { List fbList = new ArrayList(); - if (file.length() != 0) { - StudyFileEditBean tempFileBean = new StudyFileEditBean(file, studyService.generateFileSystemNameSequence(), - study); + if (uploadedInputFile.length() != 0) { + + File dir = new File(uploadedInputFile.getParentFile(), study.getId().toString() ); + if ( !dir.exists() ) { + dir.mkdir(); + } + File file = FileUtil.createTempFile(dir, uploadedInputFile.getName()); + if (!uploadedInputFile.renameTo(file)) { + // in windows environment, rename doesn't work, so we will copy the file instead + FileUtil.copyFile(uploadedInputFile, file); + uploadedInputFile.delete(); + } + + StudyFileEditBean tempFileBean = new StudyFileEditBean(file, studyService.generateFileSystemNameSequence(), study); tempFileBean.setSizeFormatted(file.length()); fbList.add(tempFileBean); } diff -r 65774fc878b7 -r 9b408c9b05ab DVN-web/src/main/java/edu/harvard/iq/dvn/core/study/StudyFileEditBean.java --- a/DVN-web/src/main/java/edu/harvard/iq/dvn/core/study/StudyFileEditBean.java Tue Mar 10 15:47:07 2015 +0100 +++ b/DVN-web/src/main/java/edu/harvard/iq/dvn/core/study/StudyFileEditBean.java Thu May 07 14:56:46 2015 +0200 @@ -68,9 +68,18 @@ public StudyFileEditBean(File file, String fileSystemName, Study study) throws IOException { this(file,fileSystemName,study,false); } - + public StudyFileEditBean(File file, String fileSystemName, Study study, boolean asOtherMaterial) throws IOException { + StringBuilder sb = new StringBuilder(); + sb.append("\n### StudyFileEditBean Information ###\n"); + sb.append("\tfileSystemName: " + fileSystemName + "\n"); + sb.append("\tstudy: " + study.getGlobalId() + "\n"); + sb.append("\tfile: " + file.getAbsolutePath() + "\n"); + sb.append("-----------------------------------------\n\n"); + + dbgLog.log(Level.INFO, sb.toString()); + dbgLog.fine("***** within StudyFileEditBean: constructor: start *****"); dbgLog.fine("reached before studyFile constructor"); diff -r 65774fc878b7 -r 9b408c9b05ab DVN-web/src/main/java/edu/harvard/iq/dvn/core/study/StudyFileServiceBean.java --- a/DVN-web/src/main/java/edu/harvard/iq/dvn/core/study/StudyFileServiceBean.java Tue Mar 10 15:47:07 2015 +0100 +++ b/DVN-web/src/main/java/edu/harvard/iq/dvn/core/study/StudyFileServiceBean.java Thu May 07 14:56:46 2015 +0200 @@ -31,6 +31,7 @@ import edu.harvard.iq.dvn.core.web.util.MD5Checksum; import edu.harvard.iq.dvn.ingest.dsb.DSBIngestMessage; import edu.harvard.iq.dvn.ingest.dsb.DSBWrapper; + import java.io.File; import java.io.FileOutputStream; import java.io.FileInputStream; @@ -41,7 +42,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.logging.Level; import java.util.logging.Logger; + import javax.annotation.Resource; import javax.ejb.EJB; import javax.ejb.EJBException; @@ -58,7 +61,9 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; + import org.apache.commons.io.FileUtils; + import java.util.zip.*; /** @@ -370,6 +375,7 @@ List otherFiles = new ArrayList(); Iterator iter = newFiles.iterator(); + StringBuilder sb = new StringBuilder("\n ******************************* step 1: divide the files, based on subsettable or not\n"); while (iter.hasNext()) { StudyFileEditBean fileBean = (StudyFileEditBean) iter.next(); // Note that for the "special" OtherFiles we want to utilize the @@ -378,14 +384,17 @@ // - L.A. if (fileBean.getStudyFile().isSubsettable() || fileBean.getStudyFile() instanceof SpecialOtherFile) { subsettableFiles.add(fileBean); + sb.append("\tsubsettableFiles.add(fileBean): " + fileBean.getOriginalFileName() + "\n"); } else { otherFiles.add(fileBean); // also add to study, so that it will be flushed for the ids fileBean.getStudyFile().setStudy(study); study.getStudyFiles().add(fileBean.getStudyFile()); + sb.append("\totherFiles.add(fileBean): " + fileBean.getOriginalFileName() + "\n"); } } + logger.log(Level.INFO, sb.toString()); if (otherFiles.size()>0) { // Only persist the studyVersion we are adding a file that doesn't need to be ingested (non-subsettable) @@ -404,6 +413,7 @@ } // step 2: iterate through nonsubsettable files, moving from temp to new location + sb = new StringBuilder("\n ******************************* step 2: iterate through nonsubsettable files, moving from temp to new location *******************************/m"); File newDir = FileUtil.getStudyFileDir(study); iter = otherFiles.iterator(); while (iter.hasNext()) { @@ -420,14 +430,19 @@ em.persist(fileBean.getStudyFile()); em.persist(fileBean.getFileMetadata()); - + sb.append("\t##### em.persist OK\n"); + sb.append("\ttempFile: " + tempFile.getAbsolutePath() + "\n"); + sb.append("\tnewLocationFile: " + newLocationFile.getAbsolutePath() + "\n"); + } catch (IOException ex) { throw new EJBException(ex); } f.setMd5(md5Checksum.CalculateMD5(f.getFileSystemLocation())); } + logger.log(Level.INFO, sb.toString()); // step 3: iterate through subsettable files, sending a message via JMS + logger.log(Level.INFO, "\n step 3: iterate through subsettable files, sending a message via JMS \n"); if (subsettableFiles.size() > 0) { QueueConnection conn = null; QueueSession session = null; @@ -489,7 +504,7 @@ if (!otherFiles.isEmpty()) { studyService.saveStudyVersion(studyVersion, user.getId()); - + logger.log(Level.INFO, "\n ******************************* saveStudyVersion OK!!! \n\n\n ----------------------------------------------------------------------------------------------------"); } @@ -646,7 +661,7 @@ } else if (fileBean.getControlCardType().equals("ddi")) { f.setOriginalFileType("application/x-dvn-tabddi-zip"); } else { - logger.info("WARNING: unknown control card-based Ingest type? -- "+fileBean.getControlCardType()); + logger.log(Level.INFO, "WARNING: unknown control card-based Ingest type? -- "+fileBean.getControlCardType()); f.setOriginalFileType(originalFileType); } f.setMd5(md5Checksum.CalculateMD5(tempOriginalFile.getAbsolutePath())); diff -r 65774fc878b7 -r 9b408c9b05ab DVN-web/src/main/webapp/WEB-INF/web.xml --- a/DVN-web/src/main/webapp/WEB-INF/web.xml Tue Mar 10 15:47:07 2015 +0100 +++ b/DVN-web/src/main/webapp/WEB-INF/web.xml Thu May 07 14:56:46 2015 +0200 @@ -540,5 +540,16 @@ de.mpiwg.monographs.servlet.GetAllUsers de.mpiwg.monographs.servlet.GetAllUsers - + + + + + de.mpiwg.monographs.servlet.GetStudies + /getStudies + + + de.mpiwg.monographs.servlet.GetStudies + de.mpiwg.monographs.servlet.GetStudies + +