comparison 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
comparison
equal deleted inserted replaced
13:d3374217e19e 14:be7787c36e58
1 package de.mpiwg.gazetteer.utils;
2
3
4 import java.io.IOException;
5 import java.net.URLEncoder;
6 import java.security.KeyManagementException;
7 import java.security.NoSuchAlgorithmException;
8 import java.util.logging.Logger;
9
10 import javax.ejb.EJB;
11 import javax.faces.context.FacesContext;
12 import javax.inject.Named;
13
14 import org.apache.commons.lang.StringUtils;
15 import org.primefaces.json.JSONException;
16 import org.primefaces.json.JSONObject;
17
18 import de.mpiwg.gazetteer.utils.HTTPUtils.HttpStringResponse;
19 import edu.harvard.iq.dataverse.DatasetServiceBean;
20 import edu.harvard.iq.dataverse.FileMetadata;
21
22 @Named("LGDatasetPage")
23 public class LGDatasetPage{
24
25 private static final Logger logger = Logger.getLogger(LGDatasetPage.class.getCanonicalName());
26
27 @EJB
28 DatasetServiceBean datasetService;
29
30
31 // synchronize dataset to LGServices
32 public String syncDatasetToLGServices(String datasetId, String persistentId) {
33 logger.info("syncDatasetToLGServices. datasetId: " + datasetId);
34
35 // notify LGServices the deleted file
36 // this is not efficient
37 // sync the dataset at once, need to go through all files in the dataset
38
39 HttpStringResponse response = null;
40 try {
41 //String LGServicesPath = "http://localhost:8080/LGServices";
42 String LGServicesPath = PropertiesUtils.getPropValue("LGServices"); // get property in config.properties file
43
44 String query = LGServicesPath + "/updateFileStatus?datasetId="+datasetId+"&datasetPersistentId="+persistentId; // get all dataverse alias from LGDataverse
45
46 response = HTTPUtils.getStringResponse(query);
47 JSONObject data = new JSONObject(response.content);
48 String status = data.getString("status");
49 //logger.info("status: " + status);
50 if (!StringUtils.equals(status, "OK")) {
51 logger.warning("error when updateFileStatus in LGServices.");
52 }
53
54 } catch (KeyManagementException | NoSuchAlgorithmException
55 | IOException | JSONException e) {
56
57 e.printStackTrace();
58 }
59
60 return "";
61 }
62
63
64 // out link to LGMap
65 public String viewLGMapOutputLink(FileMetadata fm) {
66 System.out.println("viewLGMapOutputLink");
67
68 Long fileId = fm.getDataFile().getId();
69
70 try {
71 // get LGMap url from the config.properties file
72 String LGMapPath = PropertiesUtils.getPropValue("LGMap"); // get property in config.properties file
73 String retVal = LGMapPath + "/map.php?mode=1&name="+URLEncoder.encode(fm.getLabel(), "UTF-8")+"&fileId="+fileId;
74 //logger.info("open LGMap at " + retVal);
75
76 FacesContext.getCurrentInstance().getExternalContext().redirect(retVal);
77 } catch (IOException ex) {
78 logger.warning("Failed to issue a redirect to file download url.");
79 }
80
81 return "";
82 }
83
84
85 }