# HG changeset patch # User Zoe Hong # Date 1446478883 -3600 # Node ID be7787c36e589fea7d3c8203a8c403b28d1c362a # Parent d3374217e19ee1e79a059f644cc50570bf47b93f new: nofity LGSercies for deleted files diff -r d3374217e19e -r be7787c36e58 src/main/java/config.properties --- a/src/main/java/config.properties Wed Sep 30 13:55:57 2015 +0200 +++ b/src/main/java/config.properties Mon Nov 02 16:41:23 2015 +0100 @@ -1,8 +1,11 @@ #Local #LGMap=http://localhost:1080/localgazetteers-dev/LGMap +#LGServices=http://localhost:8080/LGServices # Production one: #LGMap=http://localgazetteers.mpiwg-berlin.mpg.de/LGMap +#LGServices=http://localgazetteers.mpiwg-berlin.mpg.de/LGServices # Development one: LGMap=http://localgazetteers-test.mpiwg-berlin.mpg.de/LGMap +LGServices=http://localgazetteers-test.mpiwg-berlin.mpg.de/LGServices \ No newline at end of file diff -r d3374217e19e -r be7787c36e58 src/main/java/de/mpiwg/gazetteer/servlet/GetDatafile.java --- a/src/main/java/de/mpiwg/gazetteer/servlet/GetDatafile.java Wed Sep 30 13:55:57 2015 +0200 +++ b/src/main/java/de/mpiwg/gazetteer/servlet/GetDatafile.java Mon Nov 02 16:41:23 2015 +0100 @@ -105,7 +105,7 @@ String str; while ((str = in.readLine()) != null) { // TODO file may not be from LGServices which are not in the right format we can parse here - + dataString += str.replace("\t", ","); dataString += "\n"; } diff -r d3374217e19e -r be7787c36e58 src/main/java/de/mpiwg/gazetteer/servlet/SaveResource.java --- a/src/main/java/de/mpiwg/gazetteer/servlet/SaveResource.java Wed Sep 30 13:55:57 2015 +0200 +++ b/src/main/java/de/mpiwg/gazetteer/servlet/SaveResource.java Mon Nov 02 16:41:23 2015 +0100 @@ -35,6 +35,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.lang.StringUtils; +import org.primefaces.json.JSONArray; import org.primefaces.json.JSONException; import org.primefaces.json.JSONObject; import org.primefaces.model.UploadedFile; @@ -94,6 +95,9 @@ protected JSONObject saveFile(UpFile upFile) { + + JSONObject jsonSavedResult= new JSONObject(); + //String datasetGlobalId = "doi:10.5072/FK2/1EWLIR"; String datasetGlobalId = params.get("datasetGlobalId"); dataset = datasetService.findByGlobalId(datasetGlobalId); @@ -107,18 +111,27 @@ InputStream fileStream = new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)); dFileList = ingestService.createDataFiles(workingVersion, fileStream, fileName, contentType); + } catch (IOException ioex) { logger.warning("Failed to process and/or save the file " + upFile.getFileName() + "; " + ioex.getMessage()); - + + try { + jsonSavedResult.put("status", "error"); + jsonSavedResult.put("message", "Failed to process and/or save the file " + upFile.getFileName() + "; " + ioex.getMessage()); + } catch (JSONException e) { + + e.printStackTrace(); + } + return jsonSavedResult; } - + // get file list in the dataset first (before add file), in order to compare with the list after saving, to get saved fileId + List beforeAdding = dataset.getFiles(); - ingestService.addFiles(workingVersion, dFileList); - - JSONObject jsonSavedResult= new JSONObject(); - + ingestService.addFiles(workingVersion, dFileList); + + // Use the API to save the dataset: Command cmd; try { @@ -164,10 +177,14 @@ // queue the data ingest jobs for asynchronous execution: ingestService.startIngestJobs(dataset, (AuthenticatedUser) this.authUser); - - // returning fields, got after saving to dataset, returning info for the saved file. - // indicating the file has been published, since the saving is asynchronous execution, cannot get new file id here? - + // saved fileId is not obvious + List afterAdding = dataset.getFiles(); // get file list after ingestService.addFiles() + List diffList = this.getAddedDataFile(afterAdding, beforeAdding); + + + // try to return fields, got after saving to dataset, returning info for the saved file. + // indicating the file has been uploaded + try { jsonSavedResult.put("status", "ok"); jsonSavedResult.put("message", "Dataset Saved!"); @@ -177,7 +194,12 @@ System.out.println(dataset.getDisplayName()); fileMetadata.put("datasetTitle", dataset.getDisplayName()); - + + // compare beforeAdding and afterAdding list, but it's not efficient to do that. + if (diffList != null) { + fileMetadata.put("fileId", diffList.get(0).getId()); + } + jsonSavedResult.put("fileMetadata", fileMetadata); @@ -188,6 +210,20 @@ return jsonSavedResult; } + + + + + private List getAddedDataFile(List a, + List b) { + + List diff = new ArrayList(a); + diff.removeAll(b); + + return diff; + } + + private void loadParameters(HttpServletRequest request) { params.put("user", request.getParameter("user")); diff -r d3374217e19e -r be7787c36e58 src/main/java/de/mpiwg/gazetteer/utils/HTTPUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/HTTPUtils.java Mon Nov 02 16:41:23 2015 +0100 @@ -0,0 +1,114 @@ +package de.mpiwg.gazetteer.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; + +public class HTTPUtils { + + final static TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { + @Override + public void checkClientTrusted( final X509Certificate[] chain, final String authType ) { + } + @Override + public void checkServerTrusted( final X509Certificate[] chain, final String authType ) { + } + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + } }; + + + + + public static HttpStringResponse getStringResponse(String url) throws IOException, KeyManagementException, NoSuchAlgorithmException{ + if(url.startsWith("https") || url.startsWith("HTTPS")) + return getHttpSSLStringResponse(url); + return getHttpStringResponse(url); + } + + private static HttpStringResponse getHttpSSLStringResponse(String link) throws IOException, KeyManagementException, NoSuchAlgorithmException{ + + // Install the all-trusting trust manager + final SSLContext sslContext = SSLContext.getInstance( "SSL" ); + sslContext.init( null, trustAllCerts, new java.security.SecureRandom() ); + // Create an ssl socket factory with our all-trusting manager + final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); + + URL url = new URL(link); + HttpURLConnection httpConn = (HttpURLConnection)url.openConnection(); + + ( (HttpsURLConnection) httpConn ).setSSLSocketFactory( sslSocketFactory ); + + + BufferedReader in = null; + if (httpConn.getResponseCode() >= 400) { + in = new BufferedReader( + new InputStreamReader( + httpConn.getErrorStream())); + } else { + in = new BufferedReader( + new InputStreamReader( + httpConn.getInputStream())); + } + + String inputLine; + StringBuilder sb = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + sb.append(inputLine + "\n"); + in.close(); + + return new HttpStringResponse(httpConn.getResponseCode(), sb.toString()); + } + + private static HttpStringResponse getHttpStringResponse(String link) throws IOException{ + + //System.out.println(url); + + URL url = new URL(link); + HttpURLConnection httpConn = (HttpURLConnection)url.openConnection(); + + BufferedReader in = null; + if (httpConn.getResponseCode() >= 400) { + in = new BufferedReader( + new InputStreamReader( + httpConn.getErrorStream())); + } else { + in = new BufferedReader( + new InputStreamReader( + httpConn.getInputStream())); + } + + + String inputLine; + StringBuilder sb = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + sb.append(inputLine + "\n"); + in.close(); + + return new HttpStringResponse(httpConn.getResponseCode(), sb.toString()); + } + + public static class HttpStringResponse{ + public int code; + public String content; + public HttpStringResponse(int code, String content){ + this.code = code; + this.content = content; + } + } + +} diff -r d3374217e19e -r be7787c36e58 src/main/java/de/mpiwg/gazetteer/utils/LGDatasetPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/LGDatasetPage.java Mon Nov 02 16:41:23 2015 +0100 @@ -0,0 +1,85 @@ +package de.mpiwg.gazetteer.utils; + + +import java.io.IOException; +import java.net.URLEncoder; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.util.logging.Logger; + +import javax.ejb.EJB; +import javax.faces.context.FacesContext; +import javax.inject.Named; + +import org.apache.commons.lang.StringUtils; +import org.primefaces.json.JSONException; +import org.primefaces.json.JSONObject; + +import de.mpiwg.gazetteer.utils.HTTPUtils.HttpStringResponse; +import edu.harvard.iq.dataverse.DatasetServiceBean; +import edu.harvard.iq.dataverse.FileMetadata; + +@Named("LGDatasetPage") +public class LGDatasetPage{ + + private static final Logger logger = Logger.getLogger(LGDatasetPage.class.getCanonicalName()); + + @EJB + DatasetServiceBean datasetService; + + + // synchronize dataset to LGServices + public String syncDatasetToLGServices(String datasetId, String persistentId) { + logger.info("syncDatasetToLGServices. datasetId: " + datasetId); + + // notify LGServices the deleted file + // this is not efficient + // sync the dataset at once, need to go through all files in the dataset + + HttpStringResponse response = null; + try { + //String LGServicesPath = "http://localhost:8080/LGServices"; + String LGServicesPath = PropertiesUtils.getPropValue("LGServices"); // get property in config.properties file + + String query = LGServicesPath + "/updateFileStatus?datasetId="+datasetId+"&datasetPersistentId="+persistentId; // get all dataverse alias from LGDataverse + + response = HTTPUtils.getStringResponse(query); + JSONObject data = new JSONObject(response.content); + String status = data.getString("status"); + //logger.info("status: " + status); + if (!StringUtils.equals(status, "OK")) { + logger.warning("error when updateFileStatus in LGServices."); + } + + } catch (KeyManagementException | NoSuchAlgorithmException + | IOException | JSONException e) { + + e.printStackTrace(); + } + + return ""; + } + + + // out link to LGMap + public String viewLGMapOutputLink(FileMetadata fm) { + System.out.println("viewLGMapOutputLink"); + + Long fileId = fm.getDataFile().getId(); + + try { + // get LGMap url from the config.properties file + String LGMapPath = PropertiesUtils.getPropValue("LGMap"); // get property in config.properties file + String retVal = LGMapPath + "/map.php?mode=1&name="+URLEncoder.encode(fm.getLabel(), "UTF-8")+"&fileId="+fileId; + //logger.info("open LGMap at " + retVal); + + FacesContext.getCurrentInstance().getExternalContext().redirect(retVal); + } catch (IOException ex) { + logger.warning("Failed to issue a redirect to file download url."); + } + + return ""; + } + + +} diff -r d3374217e19e -r be7787c36e58 src/main/java/edu/harvard/iq/dataverse/DatasetPage.java --- a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java Wed Sep 30 13:55:57 2015 +0200 +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java Mon Nov 02 16:41:23 2015 +0100 @@ -1190,29 +1190,7 @@ return ""; } - // zoe added - // out link to LGMap - public String viewLGMapOutputLink(FileMetadata fm) { - System.out.println("viewLGMapOutputLink"); - - Long fileId = fm.getDataFile().getId(); - - try { - // get LGMap url from the config.properties file - String LGMapPath = PropertiesUtils.getPropValue("LGMap"); // get property in config.properties file - String retVal = LGMapPath + "/map.php?mode=1&name="+URLEncoder.encode(fm.getLabel(), "UTF-8")+"&fileId="+fileId; - - logger.info("open LGMap at " + retVal); - - FacesContext.getCurrentInstance().getExternalContext().redirect(retVal); - } catch (IOException ex) { - logger.info("Failed to issue a redirect to file download url."); - } - - return ""; - } - - // zoe end + public String exploreOutputLink(FileMetadata fm, String type){ createSilentGuestbookEntry(fm, type); @@ -1732,6 +1710,7 @@ return restrictedFileCount; } + private List filesToBeDeleted = new ArrayList(); public void deleteFiles() { @@ -1775,7 +1754,9 @@ JsfHelper.addFlashMessage(successMessage); } } - + + + public String save() { // Validate Set constraintViolations = workingVersion.validate(); @@ -2634,9 +2615,9 @@ public String getDataExploreURLComplete(Long fileid) { String TwoRavensUrl = settingsService.getValueForKey(SettingsServiceBean.Key.TwoRavensUrl); - //String TwoRavensDefaultLocal = "/dataexplore/gui.html?dfId="; + String TwoRavensDefaultLocal = "/dataexplore/gui.html?dfId="; // zoe modified - String TwoRavensDefaultLocal = "http://localhost:1080/dataexplore/gui.html?dfId="; + //String TwoRavensDefaultLocal = "http://localhost:1080/dataexplore/gui.html?dfId="; // end diff -r d3374217e19e -r be7787c36e58 src/main/webapp/dataset.xhtml --- a/src/main/webapp/dataset.xhtml Wed Sep 30 13:55:57 2015 +0200 +++ b/src/main/webapp/dataset.xhtml Mon Nov 02 16:41:23 2015 +0100 @@ -510,7 +510,7 @@
+
+ + + + + Notify LGServices the deleted files + + + #{bundle['file.uploadOrEdit']} +
@@ -729,17 +740,17 @@ - + + action="#{LGDatasetPage.viewLGMapOutputLink(fileMetadata)}" target="_blank"> #{bundle.viewLGMap} - + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+ + +
+ + + +
+ + + #{bundle['dataset.publish.btn']} + + + + #{bundle['dataset.publish.btn']} + + + + #{bundle['dataset.publish.btn']} + + + + #{bundle['dataset.publish.btn']} + + + + #{bundle['dataset.publish.btn']} + + + + + + #{bundle['dataset.rejectBtn']} + + + + + + +
+ + + +
+ + + + + + + + + + + + + +
+ +

#{bundle['dataset.share.datasetShare.tip']}

+ +
+ +
+ +
+
+ + + +
+ + +
+ + + +
+
+ #{bundle['metrics.title']} +
+
+
+
+ #{bundle['metrics.views']} #{bundle['metrics.comingsoon']} +
+
+ + + +
+
+ #{bundle['metrics.citations']} #{bundle['metrics.comingsoon']} +
+
+ #{bundle['metrics.shares']} #{bundle['metrics.comingsoon']} +
+
+
+
+   +
+
+   +
+
+   +
+
+   +
+
+
+
+ +
+
+
+ #{DatasetPage.datasetVersionUI.title.value} + + + +
+
+
+ + + + +
#{bundle['dataset.cite.whyCite.tip']} #{bundle['dataset.cite.whyCite']}
+
+
+ +
+
+
+
#{bundle['dataset.deaccession.reason']}
+

#{DatasetPage.workingVersion.versionNote}

+ +

#{bundle['dataset.beAccessedAt']} #{DatasetPage.workingVersion.archiveNote}

+
+
+
+
+
+ +
+
+
+ +
#{DatasetPage.datasetVersionUI.subject.displayValue}
+
+
+ +
#{DatasetPage.datasetVersionUI.keywordDisplay}
+
+
+ + +
+
+ +
+ + +
+
+
+
+
+
+ + + + +
+ +
+ + + + + + + +
+
+
+ +
+ + + + + +
+
+
+
+ +
+
+
+ + + + + + + + + + + + +
+ + + + +
+ + + +
+ + + + + + + +

+ + + + + +

+ + + +
+
+
+
+ +
+ + + + + + +
+ +
+ + +
+
+ + + #{bundle['file.uploadOrEdit']} + +
+
+
+ + +
+ + #{bundle['file.delete']} + +
+
+ + +
+ + + + + + + + + + + + + + + + #{bundle['file.selectedThumbnail']} + + + +
+ +
+
+ +
+
+ + + + Preview + +
+ + + +
+ + #{bundle['file.editTags']} + + + + #{bundle['file.setThumbnail']} + + + + #{bundle['file.advancedIngestOptions']} + +
+
+ + + +
+ #{bundle['file.ingestInproGress']} +
+ +
+ + + + + + + + + + + + #{bundle.viewLGMap} + + + + + + #{bundle.explore} + + + #{bundle.explore} + + + +
+ + + #{bundle['file.mapData.viewMap']} + + + + #{bundle['file.mapData']} + + + + + +
+ + + + + + #{bundle.download} + + + + #{bundle.download} + + + +
+ + +
+ + + #{fileMetadata.dataFile.fileAccessRequesters.contains(dataverseSession.user) ? bundle['file.accessRequested'] : bundle['file.requestAccess']} + + + #{fileMetadata.dataFile.fileAccessRequesters.contains(dataverseSession.user) ? bundle['file.accessRequested'] : bundle['file.requestAccess']} + +
+ +
+
+
+ + +
+ + + #{bundle['file.dataFilesTab.metadata.addBtn']} + +
+ + + + + + + + +
+ + + + + + + +
+
+ + + +
+ #{bundle['file.metadataTip']} +
+ + +
+ + + + + +
+ + + + +

#{bundle['file.deleteDialog.tip']}

+
+ + +
+
+ +

#{bundle['file.deleteDraftDialog.tip']}

+
+ + +
+
+ +

#{bundle['file.deleteFileDialog.tip']}

+ +

#{bundle['file.deleteFileDialog.failed.tip']}

+
+
+ + +
+
+ +

#{bundle['file.deaccessionDialog.tip']}

+
+ + + + + + + +
+
+ + + + + + + + + + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +

#{bundle['file.deaccessionDialog.deaccession.tip']}

+
+ + +
+
+ +

#{bundle['file.deaccessionDialog.deaccessionDataset.tip']}

+
+ + +
+
+ + + + + +
+ +
+
+
+