Mercurial > hg > LGDataverses
view src/main/java/de/mpiwg/gazetteer/utils/LGDatasetPage.java @ 14:be7787c36e58 default tip
new: nofity LGSercies for deleted files
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 02 Nov 2015 16:41:23 +0100 |
parents | |
children |
line wrap: on
line source
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 ""; } }