changeset 12:c2e2d794847f

new: add config.properties file for gazetteer
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Wed, 30 Sep 2015 13:43:54 +0200
parents 08c950a22cee
children d3374217e19e
files pom.xml src/main/java/config.properties src/main/java/de/mpiwg/gazetteer/servlet/AbstractMonographServlet.java src/main/java/de/mpiwg/gazetteer/servlet/GetAllDataverseAlias.java src/main/java/de/mpiwg/gazetteer/servlet/GetAllUsers.java src/main/java/de/mpiwg/gazetteer/servlet/GetDatafile.java src/main/java/de/mpiwg/gazetteer/servlet/GetRoleAssignments.java src/main/java/de/mpiwg/gazetteer/servlet/GetUser.java src/main/java/de/mpiwg/gazetteer/servlet/MonographUtils.java src/main/java/de/mpiwg/gazetteer/servlet/SaveResource.java src/main/java/de/mpiwg/gazetteer/utils/PropertiesUtils.java src/main/java/de/mpiwg/monographs/servlet/AbstractMonographServlet.java src/main/java/de/mpiwg/monographs/servlet/GetAllDataverseAlias.java src/main/java/de/mpiwg/monographs/servlet/GetAllUsers.java src/main/java/de/mpiwg/monographs/servlet/GetDatafile.java src/main/java/de/mpiwg/monographs/servlet/GetRoleAssignments.java src/main/java/de/mpiwg/monographs/servlet/GetUser.java src/main/java/de/mpiwg/monographs/servlet/MonographUtils.java src/main/java/de/mpiwg/monographs/servlet/SaveResource.java src/main/java/edu/harvard/iq/dataverse/DatasetPage.java src/main/java/edu/harvard/iq/dataverse/DataverseHeaderFragment.java src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java src/main/webapp/WEB-INF/faces-config.xml src/main/webapp/WEB-INF/glassfish-web.xml src/main/webapp/WEB-INF/web.xml
diffstat 26 files changed, 1211 insertions(+), 1157 deletions(-) [+]
line wrap: on
line diff
--- a/pom.xml	Wed Sep 09 17:13:18 2015 +0200
+++ b/pom.xml	Wed Sep 30 13:43:54 2015 +0200
@@ -332,6 +332,7 @@
     </dependencies>
 
     <build>
+	    <finalName>LGDataverse</finalName>
         <resources>
             <resource>
                 <directory>src/main/java</directory>
@@ -361,6 +362,7 @@
                     </compilerArguments>
                     <!-- for use with `mvn -DcompilerArgument=-Xlint:unchecked compile` -->
                     <compilerArgument>${compilerArgument}</compilerArgument>
+                    
                 </configuration>
             </plugin>
             <plugin>
@@ -382,7 +384,7 @@
                             <goal>copy</goal>
                         </goals>
                         <configuration>
-                            <outputDirectory>${endorsed.dir}</outputDirectory>
+	                        <outputDirectory>${endorsed.dir}</outputDirectory>
                             <silent>true</silent>
                             <artifactItems>
                                 <artifactItem>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/config.properties	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,8 @@
+#Local
+LGMap=http://localhost:1080/localgazetteers-dev/LGMap
+
+# Production one:
+#LGMap=http://localgazetteers.mpiwg-berlin.mpg.de
+
+# Development one:
+#LGMap=http://localgazetteers-test.mpiwg-berlin.mpg.de
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/servlet/AbstractMonographServlet.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,43 @@
+package de.mpiwg.gazetteer.servlet;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ejb.EJB;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.http.HttpServlet;
+
+import org.primefaces.json.JSONException;
+import org.primefaces.json.JSONObject;
+
+import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
+import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUserServiceBean;
+import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
+
+public class AbstractMonographServlet extends HttpServlet {
+	
+	private static final Logger logger = Logger.getLogger("monographs.AbstractMonographServlet");
+	
+	@EJB
+	protected BuiltinUserServiceBean builtinUserSvc;
+	@EJB 
+    protected AuthenticationServiceBean authSvc;
+
+	
+	protected AuthenticatedUser authUser;
+	
+	protected String credentialsAuthProviderId;
+	
+	protected void error(JSONObject jsonResponse, Exception e){
+		logger.log(Level.SEVERE, e.getMessage());
+		try {
+			jsonResponse.put("status", "error");
+			jsonResponse.put("error", e.getMessage());
+		} catch (JSONException e1) {
+			e1.printStackTrace();
+		}
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/servlet/GetAllDataverseAlias.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,56 @@
+package de.mpiwg.gazetteer.servlet;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ejb.EJB;
+import javax.persistence.EntityManager;
+import javax.persistence.NonUniqueResultException;
+import javax.persistence.PersistenceContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.primefaces.json.JSONArray;
+import org.primefaces.json.JSONException;
+import org.primefaces.json.JSONObject;
+
+import edu.harvard.iq.dataverse.Dataverse;
+import edu.harvard.iq.dataverse.DataverseServiceBean;
+
+public class GetAllDataverseAlias extends AbstractMonographServlet{
+	
+	private static final Logger logger = Logger.getLogger("monographs.GetAllDataverseAlias");
+	
+	@EJB
+	protected DataverseServiceBean dataverseServiceBean;
+	
+	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		// Set response content type
+		response.setContentType("application/json");
+		JSONObject jsonResponse = new JSONObject();	
+		
+		//get all dataverse records
+		List<Dataverse> dataverseList = dataverseServiceBean.findAll();
+		
+		JSONArray dataverseAliasArray = new JSONArray();
+		
+		for(Dataverse aDataverse : dataverseList){
+			dataverseAliasArray.put(aDataverse.getAlias());
+		}
+		
+		try {
+			jsonResponse.put("state", "ok");
+			jsonResponse.put("dataverseAlias", dataverseAliasArray);
+		} catch (JSONException e) {
+			e.printStackTrace();
+		}		
+		
+		java.io.PrintWriter out = response.getWriter();
+		out.print(jsonResponse);
+		out.flush();
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/servlet/GetAllUsers.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,44 @@
+package de.mpiwg.gazetteer.servlet;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.primefaces.json.JSONArray;
+import org.primefaces.json.JSONException;
+import org.primefaces.json.JSONObject;
+
+import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser;
+
+public class GetAllUsers extends AbstractMonographServlet{
+
+	
+	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		// Set response content type
+		response.setContentType("application/json");
+		JSONObject jsonResponse = new JSONObject();	
+
+		List<BuiltinUser> userList = builtinUserSvc.findAll(); 
+		
+		JSONArray array = new JSONArray();
+		for(BuiltinUser user : userList){
+			JSONObject json = MonographUtils.jsonBuiltinUser(user);
+			array.put(json);
+		}
+		
+		try {
+			jsonResponse.put("state", "ok");
+			jsonResponse.put("users", array);
+		} catch (JSONException e) {
+			e.printStackTrace();
+		}		
+		
+		java.io.PrintWriter out = response.getWriter();
+		out.print(jsonResponse);
+		out.flush();
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/servlet/GetDatafile.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,140 @@
+package de.mpiwg.gazetteer.servlet;
+
+import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Scanner;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ejb.EJB;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.lang.StringUtils;
+import org.primefaces.json.JSONArray;
+import org.primefaces.json.JSONException;
+import org.primefaces.json.JSONObject;
+
+import edu.harvard.iq.dataverse.DataFile;
+import edu.harvard.iq.dataverse.DataFileServiceBean;
+import edu.harvard.iq.dataverse.FileMetadata;
+import edu.harvard.iq.dataverse.api.DownloadInfo;
+import edu.harvard.iq.dataverse.api.DownloadInstance;
+import edu.harvard.iq.dataverse.authorization.AuthenticationRequest;
+import edu.harvard.iq.dataverse.authorization.CredentialsAuthenticationProvider;
+import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException;
+import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
+import edu.harvard.iq.dataverse.export.DDIExportServiceBean;
+
+
+
+public class GetDatafile extends AbstractMonographServlet{
+	
+
+	private static final Logger logger = Logger.getLogger(GetDatafile.class.getName());
+
+	@EJB
+    DataFileServiceBean dataFileService;
+	
+	
+	
+	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		// Set response content type
+		response.setContentType("application/json");
+		response.setCharacterEncoding("UTF-8");
+		
+		JSONObject jsonResponse = new JSONObject();	
+		
+		Long fileId = Long.parseLong(request.getParameter("fileId"));
+		
+		if(fileId != null){
+			// get datafile by fileId
+			System.out.println("getting file... fileId=" + fileId);
+			
+			DataFile df = dataFileService.find(fileId);
+			try {
+				if (df == null) {
+					logger.warning("Access: datafile service could not locate a DataFile object for id "+fileId+"!");
+					jsonResponse.put("state", "error");
+				
+				} else {
+					
+						JSONObject jsonFile = new JSONObject();
+					
+						jsonFile.put("fileLabel", df.getFileMetadata().getLabel());
+						jsonFile.put("fileName", df.getFileSystemName());
+						jsonFile.put("fileSize", df.getFilesize());
+
+						// get file data from file system
+						//Path filePath = df.getSavedOriginalFile();	// only works on tab-data 
+						
+						Path filePath = null;
+						if (df.getFileSystemName() != null && df.getFileSystemName().startsWith("/")) {
+							filePath = Paths.get(df.getFileSystemName());
+				        } else {
+				        	Path studyDirectoryPath = df.getOwner().getFileSystemDirectory();
+				        	if (studyDirectoryPath == null) {
+				        		jsonResponse.put("state", "error");
+				            	//return;
+				        	}
+				        	String studyDirectory = studyDirectoryPath.toString();
+				 
+				        	filePath = Paths.get(studyDirectory, df.getFileSystemName());
+				        }
+						
+				        if (filePath != null) {
+				        	String dataString = "";
+							File fileDir = new File(filePath.toString());
+							BufferedReader in = new BufferedReader( new InputStreamReader(
+												new FileInputStream(fileDir), "UTF8")); 
+							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";
+							}
+					    	in.close();
+						
+					    	jsonFile.put("dataString", dataString);
+							    
+					    	jsonResponse.put("file", jsonFile);	
+					    
+					    	jsonResponse.put("state", "ok");
+				        }
+						
+				}
+			} catch (JSONException e) {
+				
+				e.printStackTrace();
+			}
+		}
+	
+		
+		// ======================
+    
+		response.setHeader("Access-Control-Allow-Origin", "*");
+        
+		java.io.PrintWriter out = response.getWriter();
+		out.print(jsonResponse);
+		out.flush();
+		
+		
+		
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/servlet/GetRoleAssignments.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,170 @@
+package de.mpiwg.gazetteer.servlet;
+
+import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ejb.EJB;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.primefaces.json.JSONArray;
+import org.primefaces.json.JSONException;
+import org.primefaces.json.JSONObject;
+
+import edu.harvard.iq.dataverse.DataFile;
+import edu.harvard.iq.dataverse.Dataverse;
+import edu.harvard.iq.dataverse.DataverseRoleServiceBean;
+import edu.harvard.iq.dataverse.DvObject;
+import edu.harvard.iq.dataverse.DvObjectServiceBean;
+import edu.harvard.iq.dataverse.RoleAssigneeServiceBean;
+import edu.harvard.iq.dataverse.RoleAssignment;
+import edu.harvard.iq.dataverse.ManagePermissionsPage.RoleAssignmentRow;
+import edu.harvard.iq.dataverse.authorization.AuthenticationRequest;
+import edu.harvard.iq.dataverse.authorization.CredentialsAuthenticationProvider;
+import edu.harvard.iq.dataverse.authorization.Permission;
+import edu.harvard.iq.dataverse.authorization.RoleAssignee;
+import edu.harvard.iq.dataverse.authorization.RoleAssigneeDisplayInfo;
+import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException;
+import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
+
+
+public class GetRoleAssignments extends AbstractMonographServlet{
+	
+
+	private static final Logger logger = Logger.getLogger(GetRoleAssignments.class.getName());
+    
+	@EJB
+    DvObjectServiceBean dvObjectService;
+	@EJB
+    DataverseRoleServiceBean roleService;
+	@EJB
+    RoleAssigneeServiceBean roleAssigneeService;
+	
+	public List<JSONObject> getRoleAssignments (String datasetId) {
+		
+		List<JSONObject> raList = new ArrayList<JSONObject>();
+				
+		DvObject dvObject = dvObjectService.findDvObject(Long.parseLong(datasetId));
+		
+	    if (dvObject != null && dvObject.getId() != null) {
+	        Set<RoleAssignment> ras = roleService.rolesAssignments(dvObject);
+	        
+	        for (RoleAssignment roleAssignment : ras) {
+	           
+	            RoleAssignee roleAssignee = roleAssigneeService.getRoleAssignee(roleAssignment.getAssigneeIdentifier());
+	            if (roleAssignee != null) {
+	                
+	            	try {
+	                	JSONObject aroleAssignment = new JSONObject();
+						aroleAssignment.put("roleAssignment", roleAssignment);
+						raList.add(aroleAssignment);
+						
+							
+					} catch (JSONException e) {
+						
+						e.printStackTrace();
+					}
+	       
+	            } else {
+	               logger.info("Could not find role assignee based on role assignment id " + roleAssignment.getId());
+	            }
+	           
+	        }
+	    }
+		
+	    return raList;
+	}
+
+	
+	
+	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		// Set response content type
+		response.setContentType("application/json");
+		JSONObject jsonResponse = new JSONObject();	
+		
+		String user = request.getParameter("user");
+		String password = request.getParameter("password");
+		String datasetId = request.getParameter("datasetId");
+			
+		if(StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)){
+	
+			// authenticate checking. TODO use GetUser.java or something like that to do the authenticate checking.
+			AuthenticationRequest authReq = new AuthenticationRequest();
+	        authReq.putCredential("Username", user);
+	        authReq.putCredential("Password", password);
+	        try {
+		        String credentialsAuthProviderId = "builtin";
+		        this.authUser = authSvc.authenticate(credentialsAuthProviderId, authReq);
+		        System.out.println("User authenticated: " + authUser.getIdentifier()); 
+		    } catch (AuthenticationFailedException ex) {
+		       ex.printStackTrace();
+		       return;
+		    }
+	        if(authUser == null){
+				try {
+					jsonResponse.put("state", "error");
+					jsonResponse.put("error", "User " + user + " no found.");
+				} catch (JSONException e) {
+					
+					e.printStackTrace();
+				}
+			} else {
+		        // get roleAssignments
+				try {
+					jsonResponse.put("state", "ok");
+					
+					List<JSONObject> raJson = getRoleAssignments(datasetId);
+					// raJson contains all roleAssignments in the dataset
+					// find the roleAssignment for the user
+					JSONArray assignments = new JSONArray();
+					
+					
+					for (int i = 0; i < raJson.size(); i++) {
+					
+						RoleAssignment aUser = (RoleAssignment) raJson.get(i).get("roleAssignment");
+							
+						JSONObject assignment = new JSONObject();
+						assignment.put("identifier", aUser.getAssigneeIdentifier());
+						assignment.put("roleName", aUser.getRole().getName());
+						
+						assignments.put(assignment);
+						
+					}
+			
+					jsonResponse.put("roleAssignments", assignments);
+						
+				} catch (JSONException e) {
+			
+					e.printStackTrace();
+				}
+			}   
+			
+		} else {
+			try {
+				jsonResponse.put("state", "error");
+				jsonResponse.put("error", "Request error. Parameters 'user' and 'password' are mandatory");
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		
+		// ======================
+    
+		
+		java.io.PrintWriter out = response.getWriter();
+		out.print(jsonResponse);
+		out.flush();
+		
+		
+		
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/servlet/GetUser.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,147 @@
+package de.mpiwg.gazetteer.servlet;
+
+import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.primefaces.json.JSONException;
+import org.primefaces.json.JSONObject;
+
+import edu.harvard.iq.dataverse.authorization.AuthenticationRequest;
+import edu.harvard.iq.dataverse.authorization.CredentialsAuthenticationProvider;
+import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException;
+import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
+
+
+public class GetUser extends AbstractMonographServlet{
+	
+
+	private static final Logger logger = Logger.getLogger(GetUser.class.getName());
+	
+	
+	
+	/*
+	private List<FilledCredential> filledCredentials;
+	
+	public static class FilledCredential {
+        CredentialsAuthenticationProvider.Credential credential;
+        String value;
+
+        public FilledCredential() {
+        }
+
+        public FilledCredential(CredentialsAuthenticationProvider.Credential credential, String value) {
+            this.credential = credential;
+            this.value = value;
+        }
+        
+        public CredentialsAuthenticationProvider.Credential getCredential() {
+            return credential;
+        }
+
+        public void setCredential(CredentialsAuthenticationProvider.Credential credential) {
+            this.credential = credential;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+        public void setValue(String value) {
+            this.value = value;
+        }
+        
+    }
+	
+	public List<FilledCredential> getFilledCredentials() {
+        return filledCredentials;
+    }
+	
+	public String getCredentialsAuthProviderId() {
+	       return credentialsAuthProviderId;
+	}
+	  
+	public CredentialsAuthenticationProvider selectedCredentialsProvider() {
+        return (CredentialsAuthenticationProvider) authSvc.getAuthenticationProvider(getCredentialsAuthProviderId());
+    }
+	
+	public void setCredentialsAuthProviderId(String authProviderId) {
+        this.credentialsAuthProviderId = authProviderId;
+    }
+	public void resetFilledCredentials() {
+        if ( selectedCredentialsProvider()==null ) return;
+        
+        filledCredentials = new LinkedList<>();
+        for ( CredentialsAuthenticationProvider.Credential c : selectedCredentialsProvider().getRequiredCredentials() ) {
+            filledCredentials.add( new FilledCredential(c, ""));
+        }
+    }
+	*/
+	
+	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+		// Set response content type
+		response.setContentType("application/json");
+		JSONObject jsonResponse = new JSONObject();	
+		
+		String user = request.getParameter("user");
+		String password = request.getParameter("password");
+		
+			
+		if(StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)){
+			
+			AuthenticationRequest authReq = new AuthenticationRequest();
+	        authReq.putCredential("Username", user);
+	        authReq.putCredential("Password", password);
+	        try {
+	        	credentialsAuthProviderId = "builtin";
+	            //AuthenticatedUser authUser = authSvc.authenticate(credentialsAuthProviderId, authReq);
+	        	authUser = authSvc.authenticate(credentialsAuthProviderId, authReq);
+	            
+	        	System.out.println("User authenticated: " + authUser.getIdentifier());
+				
+	            if(authUser != null){
+					JSONObject jsonUser = MonographUtils.jsonAuthenticatedUser(authUser);
+					jsonResponse.put("state", "ok");
+					jsonResponse.put("user", jsonUser);
+
+				} else {
+					jsonResponse.put("state", "error");
+					jsonResponse.put("error", "User " + user + " no found.");
+				}
+	            
+	        } catch (AuthenticationFailedException ex) {
+	        	ex.printStackTrace();
+	        } catch (JSONException e) {
+				e.printStackTrace();
+			}
+			
+			
+		} else {
+			try {
+				jsonResponse.put("state", "error");
+				jsonResponse.put("error", "Request error. Parameters 'user' and 'password' are mandatory");
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		
+		// ======================
+    
+		
+		java.io.PrintWriter out = response.getWriter();
+		out.print(jsonResponse);
+		out.flush();
+		
+		
+		
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/servlet/MonographUtils.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,101 @@
+package de.mpiwg.gazetteer.servlet;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.primefaces.json.JSONObject;
+
+import edu.harvard.iq.dataverse.DataFile;
+import edu.harvard.iq.dataverse.RoleAssignment;
+import edu.harvard.iq.dataverse.ManagePermissionsPage.RoleAssignmentRow;
+import edu.harvard.iq.dataverse.authorization.Permission;
+import edu.harvard.iq.dataverse.authorization.RoleAssignee;
+import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup;
+import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser;
+import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
+
+
+public class MonographUtils {
+
+	
+	public static JSONObject jsonAuthenticatedUser(AuthenticatedUser user){
+		JSONObject json = new JSONObject();
+		
+		try {
+
+			json.put("email", user.getEmail());
+			json.put("firstName", user.getFirstName());
+			json.put("id", user.getId());
+			//json.put("version", user.getVersion());
+			json.put("userName", user.getUserIdentifier());	// getUserName->getUserIdentifier
+			json.put("position", user.getPosition());
+			json.put("lastName", user.getLastName());
+			json.put("affiliation", user.getAffiliation());
+			
+			// structure in dv4 does not support this
+			/*
+			JSONArray array0 = new JSONArray();
+			
+			// zoe added
+			Collection<ExplicitGroup> groups = findGroupsOfUser(user.getId());
+			
+			if( groups != null) {
+				for(ExplicitGroup group : groups){
+				array0.put(jsonGroup(group));
+			}
+				json.put("userGroups", array0);
+			}
+			*/
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		
+		
+		return json;
+	}
+	
+	
+	
+
+	public static JSONObject jsonGroup(ExplicitGroup group){
+		JSONObject json = new JSONObject();
+		
+		if(group != null){
+			try {
+				json.put("friendlyName", group.getDisplayName());
+				json.put("id", group.getId());
+				
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+		
+		return json;
+	}
+
+
+
+	public static JSONObject jsonBuiltinUser(BuiltinUser user) {
+		JSONObject json = new JSONObject();
+		
+		try {
+			json.put("email", user.getEmail());
+			json.put("firstName", user.getFirstName());
+			json.put("id", user.getId());
+			json.put("userName", user.getUserName());
+			json.put("position", user.getPosition());
+			json.put("lastName", user.getLastName());
+			json.put("affiliation", user.getAffiliation());
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		
+		
+		return json;
+	}
+	
+	
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/servlet/SaveResource.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,401 @@
+package de.mpiwg.gazetteer.servlet;
+
+import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletException;
+import javax.servlet.annotation.MultipartConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.Part;
+
+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.primefaces.json.JSONException;
+import org.primefaces.json.JSONObject;
+import org.primefaces.model.UploadedFile;
+
+import edu.harvard.iq.dataverse.DataFile;
+import edu.harvard.iq.dataverse.Dataset;
+import edu.harvard.iq.dataverse.DatasetServiceBean;
+import edu.harvard.iq.dataverse.DatasetVersion;
+import edu.harvard.iq.dataverse.DatasetVersionServiceBean;
+import edu.harvard.iq.dataverse.EjbDataverseEngine;
+import edu.harvard.iq.dataverse.UserNotification;
+import edu.harvard.iq.dataverse.DatasetPage.EditMode;
+import edu.harvard.iq.dataverse.authorization.AuthenticationRequest;
+import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException;
+import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
+import edu.harvard.iq.dataverse.engine.command.Command;
+import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
+import edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand;
+import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand;
+import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
+import edu.harvard.iq.dataverse.util.JsfHelper;
+
+
+@MultipartConfig 
+public class SaveResource extends AbstractMonographServlet {
+
+	private static final long serialVersionUID = 1L;
+
+
+	private static final String TMP_DIR = "/gazetteer-server/tmp/";
+
+
+	private int maxFileSize = 100 * 1024;
+	private int maxMemSize = 4 * 1024;
+
+	private static final Logger logger = Logger.getLogger("monographs.SaveResource");
+
+	@EJB
+    IngestServiceBean ingestService;
+	@EJB
+    DatasetServiceBean datasetService;
+	@EJB
+    DatasetVersionServiceBean datasetVersionService;
+	@EJB
+    EjbDataverseEngine commandEngine;
+	
+	private DatasetVersion workingVersion;
+	private Dataset dataset;
+	
+
+	Map<String, String> params = new HashMap<String, String>();
+	
+
+	public void init() throws ServletException {
+		super.init();
+	}
+
+
+	protected JSONObject saveFile(UpFile upFile) {
+		//String datasetGlobalId = "doi:10.5072/FK2/1EWLIR";
+		String datasetGlobalId = params.get("datasetGlobalId");
+		dataset = datasetService.findByGlobalId(datasetGlobalId);	
+        workingVersion = dataset.getEditVersion();
+     	
+		List<DataFile> dFileList = null;
+		try {
+	     	String fileContent = upFile.getFileContent();
+			String fileName = upFile.getFileName();
+			String contentType = upFile.getContentType();
+			
+			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());
+	        
+	    }
+		
+		
+		
+        ingestService.addFiles(workingVersion, dFileList);
+
+        JSONObject jsonSavedResult= new JSONObject();
+	
+        // Use the API to save the dataset: 
+        Command<Dataset> cmd;
+        try {
+            cmd = new UpdateDatasetCommand(dataset, this.authUser);
+            dataset = commandEngine.submit(cmd);
+            
+        } catch (EJBException ex) {
+            StringBuilder error = new StringBuilder();
+            error.append(ex).append(" ");
+            error.append(ex.getMessage()).append(" ");
+            Throwable cause = ex;
+            while (cause.getCause()!= null) {
+                cause = cause.getCause();
+                error.append(cause).append(" ");
+                error.append(cause.getMessage()).append(" ");
+            }
+            logger.log(Level.FINE, "Couldn''t save dataset: {0}", error.toString());
+            //populateDatasetUpdateFailureMessage();
+            try {
+				jsonSavedResult.put("status", "error");
+				jsonSavedResult.put("message", "Could not save dataset.");
+			} catch (JSONException e) {
+				
+				e.printStackTrace();
+			}
+            return jsonSavedResult;
+        } catch (CommandException ex) {
+            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
+            logger.severe(ex.getMessage());
+            //populateDatasetUpdateFailureMessage();
+            try {
+				jsonSavedResult.put("status", "error");
+				jsonSavedResult.put("message", "Dataset Save Failed");
+			} catch (JSONException e) {
+				
+				e.printStackTrace();
+			}
+            return jsonSavedResult;
+            
+        }
+      
+        // Call Ingest Service one more time, to 
+        // 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?
+
+		try {
+			jsonSavedResult.put("status", "ok");
+			jsonSavedResult.put("message", "Dataset Saved!");
+			
+			JSONObject fileMetadata = new JSONObject();
+			
+			System.out.println(dataset.getDisplayName());
+			
+			fileMetadata.put("datasetTitle", dataset.getDisplayName());
+			
+			jsonSavedResult.put("fileMetadata", fileMetadata);
+			
+			
+		} catch (JSONException e) {
+			e.printStackTrace();
+		}
+       
+		return jsonSavedResult;
+	}
+	
+	private void loadParameters(HttpServletRequest request) {	
+		
+		params.put("user", request.getParameter("user"));
+		params.put("password", request.getParameter("password"));
+		params.put("datasetGlobalId", request.getParameter("datasetGlobalId"));
+		
+		return;
+	}
+	
+	private class UpFile {
+		public String fileName;
+		public String fileContent;
+		public String contentType;
+
+		public UpFile (String fileName, String fileContent, String contentType) {
+			this.fileName = fileName;
+			this.fileContent = fileContent;
+			this.contentType = contentType;
+		}
+
+		public String getFileName() {
+			return fileName;
+		}
+		public void setFileName(String fileName) {
+			this.fileName = fileName;
+		}
+		public String getFileContent() {
+			return fileContent;
+		}
+
+		public void setFileContent(String fileContent) {
+			this.fileContent = fileContent;
+		}
+
+		public String getContentType() {
+			return contentType;
+		}
+
+		public void setContentType(String contentType) {
+			this.contentType = contentType;
+		}
+		
+	}
+	
+	
+	@Override
+	protected void doPost(HttpServletRequest request, HttpServletResponse response) {
+
+		try {
+			response.setContentType("application/json");
+			JSONObject jsonResponse = new JSONObject();
+				
+			loadParameters(request);
+			UpFile upFile = getFile(request);
+			
+			String fileName = upFile.getFileName();
+			String fileContent = upFile.getFileContent();
+			
+			if(StringUtils.isNotEmpty(fileContent) && StringUtils.isNotEmpty(fileName)){
+				
+				String datasetGlobalId = params.get("datasetGlobalId");	
+				String user = params.get("user");
+				String password = params.get("password");
+				
+				if(StringUtils.isNotEmpty(datasetGlobalId) && StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)){
+							
+					AuthenticationRequest authReq = new AuthenticationRequest();
+					
+				    authReq.putCredential("Username", user);
+				    authReq.putCredential("Password", password);
+				    try {
+				        String credentialsAuthProviderId = "builtin";
+				        this.authUser = authSvc.authenticate(credentialsAuthProviderId, authReq);
+				        System.out.println("User authenticated: " + authUser.getIdentifier()); 
+				    } catch (AuthenticationFailedException ex) {
+				       ex.printStackTrace();
+				    }
+				    
+				
+					JSONObject jsonSavedResult = saveFile(upFile);
+					jsonResponse.put("status", jsonSavedResult.getString("status"));
+					jsonResponse.put("message", jsonSavedResult.getString("message"));
+					if (jsonSavedResult.has("fileMetadata")) {
+						jsonResponse.put("fileMetadata", jsonSavedResult.getJSONObject("fileMetadata"));
+					}
+					
+								
+				}else{
+					jsonResponse.put("status", "error");
+					jsonResponse.put("error", "The parameters studyId, user and password.");
+					jsonResponse.put("datasetGlobalId", datasetGlobalId);
+					jsonResponse.put("user", user);
+					jsonResponse.put("password", password);
+					//jsonResponse.put("fileLabel", fileLabel);
+				}
+
+			}else if(StringUtils.isNotEmpty(fileName)){
+				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 {
+				jsonResponse.put("status", "error");
+				jsonResponse.put("message", "No file found in the request.");
+			}
+			
+			java.io.PrintWriter out = response.getWriter();
+			out.print(jsonResponse);
+			out.flush();
+		} catch (Exception e) {	
+			e.printStackTrace();
+		}
+	}
+	
+
+
+
+	private UpFile getFile(HttpServletRequest request) throws IOException {
+		JSONObject fileObj;
+		try {
+			fileObj = new JSONObject(request.getParameter("file"));
+			
+			String contentType = "text/plain; charset=UTF-8";
+
+			Iterator keys = fileObj.keys(); //gets all the keys
+			while (keys.hasNext()) {
+				String fileName = (String) keys.next();
+			    String fileTable = fileObj.getString(fileName);
+	
+				UpFile upFile = new UpFile(fileName, fileTable, contentType);
+				
+				return upFile;
+			}
+	
+		} catch (JSONException e) {
+			
+			e.printStackTrace();
+		} 
+		return null;
+
+	}
+	
+
+
+    // delete this
+	private File getFile_old(HttpServletRequest request, HttpServletResponse response) throws IOException {
+		File file = null;
+		boolean isMultipart = ServletFileUpload.isMultipartContent(request);		
+	
+		if(isMultipart){
+			DiskFileItemFactory factory = new DiskFileItemFactory();
+			// maximum size that will be stored in memory
+			factory.setSizeThreshold(maxMemSize);
+			// Location to save data that is larger than maxMemSize.
+			factory.setRepository(new File(TMP_DIR));
+
+			// Create a new file upload handler
+			ServletFileUpload upload = new ServletFileUpload(factory);
+			// maximum file size to be uploaded.
+			upload.setSizeMax(maxFileSize);
+			upload.setFileSizeMax(maxFileSize);
+			upload.setHeaderEncoding("UTF-8");
+			
+			StringBuilder sb = new StringBuilder();
+			try {
+				// Parse the request to get file items.
+				List<FileItem> fileItems = upload.parseRequest(request); 
+				
+				// Process the uploaded file items
+				Iterator<FileItem> i = fileItems.iterator();
+
+				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
+						if (fileName.lastIndexOf("\\") >= 0) {
+							file = new File(TMP_DIR + fileName.substring(fileName.lastIndexOf("\\")));
+						} else {
+							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" + ".\nWhen the file is empty, maybe the tmp folder is wrong configured.\nTMP_DIR: " + TMP_DIR : "File Size=" + file.length() );
+			logger.log(Level.INFO, "getFile Information:\n" + sb.toString());
+			
+			return file;	
+		}
+		
+		return null;
+	}
+	
+
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/mpiwg/gazetteer/utils/PropertiesUtils.java	Wed Sep 30 13:43:54 2015 +0200
@@ -0,0 +1,52 @@
+package de.mpiwg.gazetteer.utils;
+
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+
+public class PropertiesUtils {
+	
+	private static Logger logger = Logger.getLogger(PropertiesUtils.class);
+	private static PropertiesUtils instance;
+	
+	
+	private static String PROP_FILENAME = "config.properties";
+	private Properties prop;
+	
+	private PropertiesUtils() throws IOException{
+		loadProperties();
+	}
+	
+	
+	public void loadProperties() throws IOException {
+		
+		logger.info("##### Loading Propertis from " + PROP_FILENAME + " #####");
+		
+		prop = new Properties();
+		
+		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(PROP_FILENAME);
+		
+		if (inputStream != null) {
+			prop.load(inputStream);
+		} else {
+			prop = null;
+			throw new FileNotFoundException("property file '" + PROP_FILENAME + "' not found in the classpath");
+			
+		}
+	}
+
+	public static String getPropValue(String key) throws IOException{
+		if(instance == null){
+			instance = new PropertiesUtils();
+		}
+		if(instance.prop == null){
+			instance.loadProperties();
+		}
+		return instance.prop.getProperty(key);
+	}
+	
+}
--- a/src/main/java/de/mpiwg/monographs/servlet/AbstractMonographServlet.java	Wed Sep 09 17:13:18 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-package de.mpiwg.monographs.servlet;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.ejb.EJB;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.servlet.http.HttpServlet;
-
-import org.primefaces.json.JSONException;
-import org.primefaces.json.JSONObject;
-
-import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
-import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUserServiceBean;
-import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
-
-public class AbstractMonographServlet extends HttpServlet {
-	
-	private static final Logger logger = Logger.getLogger("monographs.AbstractMonographServlet");
-	
-	@EJB
-	protected BuiltinUserServiceBean builtinUserSvc;
-	@EJB 
-    protected AuthenticationServiceBean authSvc;
-
-	
-	protected AuthenticatedUser authUser;
-	
-	protected String credentialsAuthProviderId;
-	
-	protected void error(JSONObject jsonResponse, Exception e){
-		logger.log(Level.SEVERE, e.getMessage());
-		try {
-			jsonResponse.put("status", "error");
-			jsonResponse.put("error", e.getMessage());
-		} catch (JSONException e1) {
-			e1.printStackTrace();
-		}
-	}
-	
-}
--- a/src/main/java/de/mpiwg/monographs/servlet/GetAllDataverseAlias.java	Wed Sep 09 17:13:18 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-package de.mpiwg.monographs.servlet;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.ejb.EJB;
-import javax.persistence.EntityManager;
-import javax.persistence.NonUniqueResultException;
-import javax.persistence.PersistenceContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.primefaces.json.JSONArray;
-import org.primefaces.json.JSONException;
-import org.primefaces.json.JSONObject;
-
-import edu.harvard.iq.dataverse.Dataverse;
-import edu.harvard.iq.dataverse.DataverseServiceBean;
-
-public class GetAllDataverseAlias extends AbstractMonographServlet{
-	
-	private static final Logger logger = Logger.getLogger("monographs.GetAllDataverseAlias");
-	
-	@EJB
-	protected DataverseServiceBean dataverseServiceBean;
-	
-	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		// Set response content type
-		response.setContentType("application/json");
-		JSONObject jsonResponse = new JSONObject();	
-		
-		//get all dataverse records
-		List<Dataverse> dataverseList = dataverseServiceBean.findAll();
-		
-		JSONArray dataverseAliasArray = new JSONArray();
-		
-		for(Dataverse aDataverse : dataverseList){
-			dataverseAliasArray.put(aDataverse.getAlias());
-		}
-		
-		try {
-			jsonResponse.put("state", "ok");
-			jsonResponse.put("dataverseAlias", dataverseAliasArray);
-		} catch (JSONException e) {
-			e.printStackTrace();
-		}		
-		
-		java.io.PrintWriter out = response.getWriter();
-		out.print(jsonResponse);
-		out.flush();
-	}
-
-}
--- a/src/main/java/de/mpiwg/monographs/servlet/GetAllUsers.java	Wed Sep 09 17:13:18 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-package de.mpiwg.monographs.servlet;
-
-import java.io.IOException;
-import java.util.List;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.primefaces.json.JSONArray;
-import org.primefaces.json.JSONException;
-import org.primefaces.json.JSONObject;
-
-import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser;
-
-public class GetAllUsers extends AbstractMonographServlet{
-
-	
-	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		// Set response content type
-		response.setContentType("application/json");
-		JSONObject jsonResponse = new JSONObject();	
-
-		List<BuiltinUser> userList = builtinUserSvc.findAll(); 
-		
-		JSONArray array = new JSONArray();
-		for(BuiltinUser user : userList){
-			JSONObject json = MonographUtils.jsonBuiltinUser(user);
-			array.put(json);
-		}
-		
-		try {
-			jsonResponse.put("state", "ok");
-			jsonResponse.put("users", array);
-		} catch (JSONException e) {
-			e.printStackTrace();
-		}		
-		
-		java.io.PrintWriter out = response.getWriter();
-		out.print(jsonResponse);
-		out.flush();
-	}
-
-}
--- a/src/main/java/de/mpiwg/monographs/servlet/GetDatafile.java	Wed Sep 09 17:13:18 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-package de.mpiwg.monographs.servlet;
-
-import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Scanner;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.ejb.EJB;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
-
-import org.apache.commons.lang.StringUtils;
-import org.primefaces.json.JSONArray;
-import org.primefaces.json.JSONException;
-import org.primefaces.json.JSONObject;
-
-import edu.harvard.iq.dataverse.DataFile;
-import edu.harvard.iq.dataverse.DataFileServiceBean;
-import edu.harvard.iq.dataverse.FileMetadata;
-import edu.harvard.iq.dataverse.api.DownloadInfo;
-import edu.harvard.iq.dataverse.api.DownloadInstance;
-import edu.harvard.iq.dataverse.authorization.AuthenticationRequest;
-import edu.harvard.iq.dataverse.authorization.CredentialsAuthenticationProvider;
-import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException;
-import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
-import edu.harvard.iq.dataverse.export.DDIExportServiceBean;
-
-
-
-public class GetDatafile extends AbstractMonographServlet{
-	
-
-	private static final Logger logger = Logger.getLogger(GetDatafile.class.getName());
-
-	@EJB
-    DataFileServiceBean dataFileService;
-	
-	
-	
-	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		// Set response content type
-		response.setContentType("application/json");
-		response.setCharacterEncoding("UTF-8");
-		
-		JSONObject jsonResponse = new JSONObject();	
-		
-		Long fileId = Long.parseLong(request.getParameter("fileId"));
-		
-		if(fileId != null){
-			// get datafile by fileId
-			System.out.println("getting file... fileId=" + fileId);
-			
-			DataFile df = dataFileService.find(fileId);
-			try {
-				if (df == null) {
-					logger.warning("Access: datafile service could not locate a DataFile object for id "+fileId+"!");
-					jsonResponse.put("state", "error");
-				
-				} else {
-					
-						JSONObject jsonFile = new JSONObject();
-					
-						jsonFile.put("fileLabel", df.getFileMetadata().getLabel());
-						jsonFile.put("fileName", df.getFileSystemName());
-						jsonFile.put("fileSize", df.getFilesize());
-
-						// get file data from file system
-						//Path filePath = df.getSavedOriginalFile();	// only works on tab-data 
-						
-						Path filePath = null;
-						if (df.getFileSystemName() != null && df.getFileSystemName().startsWith("/")) {
-							filePath = Paths.get(df.getFileSystemName());
-				        } else {
-				        	Path studyDirectoryPath = df.getOwner().getFileSystemDirectory();
-				        	if (studyDirectoryPath == null) {
-				        		jsonResponse.put("state", "error");
-				            	//return;
-				        	}
-				        	String studyDirectory = studyDirectoryPath.toString();
-				 
-				        	filePath = Paths.get(studyDirectory, df.getFileSystemName());
-				        }
-						
-				        if (filePath != null) {
-				        	String dataString = "";
-							File fileDir = new File(filePath.toString());
-							BufferedReader in = new BufferedReader( new InputStreamReader(
-												new FileInputStream(fileDir), "UTF8")); 
-							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";
-							}
-					    	in.close();
-						
-					    	jsonFile.put("dataString", dataString);
-							    
-					    	jsonResponse.put("file", jsonFile);	
-					    
-					    	jsonResponse.put("state", "ok");
-				        }
-						
-				}
-			} catch (JSONException e) {
-				
-				e.printStackTrace();
-			}
-		}
-	
-		
-		// ======================
-    
-		response.setHeader("Access-Control-Allow-Origin", "*");
-        
-		java.io.PrintWriter out = response.getWriter();
-		out.print(jsonResponse);
-		out.flush();
-		
-		
-		
-	}
-}
--- a/src/main/java/de/mpiwg/monographs/servlet/GetRoleAssignments.java	Wed Sep 09 17:13:18 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,170 +0,0 @@
-package de.mpiwg.monographs.servlet;
-
-import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.ejb.EJB;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang.StringUtils;
-import org.primefaces.json.JSONArray;
-import org.primefaces.json.JSONException;
-import org.primefaces.json.JSONObject;
-
-import edu.harvard.iq.dataverse.DataFile;
-import edu.harvard.iq.dataverse.Dataverse;
-import edu.harvard.iq.dataverse.DataverseRoleServiceBean;
-import edu.harvard.iq.dataverse.DvObject;
-import edu.harvard.iq.dataverse.DvObjectServiceBean;
-import edu.harvard.iq.dataverse.RoleAssigneeServiceBean;
-import edu.harvard.iq.dataverse.RoleAssignment;
-import edu.harvard.iq.dataverse.ManagePermissionsPage.RoleAssignmentRow;
-import edu.harvard.iq.dataverse.authorization.AuthenticationRequest;
-import edu.harvard.iq.dataverse.authorization.CredentialsAuthenticationProvider;
-import edu.harvard.iq.dataverse.authorization.Permission;
-import edu.harvard.iq.dataverse.authorization.RoleAssignee;
-import edu.harvard.iq.dataverse.authorization.RoleAssigneeDisplayInfo;
-import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException;
-import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
-
-
-public class GetRoleAssignments extends AbstractMonographServlet{
-	
-
-	private static final Logger logger = Logger.getLogger(GetRoleAssignments.class.getName());
-    
-	@EJB
-    DvObjectServiceBean dvObjectService;
-	@EJB
-    DataverseRoleServiceBean roleService;
-	@EJB
-    RoleAssigneeServiceBean roleAssigneeService;
-	
-	public List<JSONObject> getRoleAssignments (String datasetId) {
-		
-		List<JSONObject> raList = new ArrayList<JSONObject>();
-				
-		DvObject dvObject = dvObjectService.findDvObject(Long.parseLong(datasetId));
-		
-	    if (dvObject != null && dvObject.getId() != null) {
-	        Set<RoleAssignment> ras = roleService.rolesAssignments(dvObject);
-	        
-	        for (RoleAssignment roleAssignment : ras) {
-	           
-	            RoleAssignee roleAssignee = roleAssigneeService.getRoleAssignee(roleAssignment.getAssigneeIdentifier());
-	            if (roleAssignee != null) {
-	                
-	            	try {
-	                	JSONObject aroleAssignment = new JSONObject();
-						aroleAssignment.put("roleAssignment", roleAssignment);
-						raList.add(aroleAssignment);
-						
-							
-					} catch (JSONException e) {
-						
-						e.printStackTrace();
-					}
-	       
-	            } else {
-	               logger.info("Could not find role assignee based on role assignment id " + roleAssignment.getId());
-	            }
-	           
-	        }
-	    }
-		
-	    return raList;
-	}
-
-	
-	
-	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		// Set response content type
-		response.setContentType("application/json");
-		JSONObject jsonResponse = new JSONObject();	
-		
-		String user = request.getParameter("user");
-		String password = request.getParameter("password");
-		String datasetId = request.getParameter("datasetId");
-			
-		if(StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)){
-	
-			// authenticate checking. TODO use GetUser.java or something like that to do the authenticate checking.
-			AuthenticationRequest authReq = new AuthenticationRequest();
-	        authReq.putCredential("Username", user);
-	        authReq.putCredential("Password", password);
-	        try {
-		        String credentialsAuthProviderId = "builtin";
-		        this.authUser = authSvc.authenticate(credentialsAuthProviderId, authReq);
-		        System.out.println("User authenticated: " + authUser.getIdentifier()); 
-		    } catch (AuthenticationFailedException ex) {
-		       ex.printStackTrace();
-		       return;
-		    }
-	        if(authUser == null){
-				try {
-					jsonResponse.put("state", "error");
-					jsonResponse.put("error", "User " + user + " no found.");
-				} catch (JSONException e) {
-					
-					e.printStackTrace();
-				}
-			} else {
-		        // get roleAssignments
-				try {
-					jsonResponse.put("state", "ok");
-					
-					List<JSONObject> raJson = getRoleAssignments(datasetId);
-					// raJson contains all roleAssignments in the dataset
-					// find the roleAssignment for the user
-					JSONArray assignments = new JSONArray();
-					
-					
-					for (int i = 0; i < raJson.size(); i++) {
-					
-						RoleAssignment aUser = (RoleAssignment) raJson.get(i).get("roleAssignment");
-							
-						JSONObject assignment = new JSONObject();
-						assignment.put("identifier", aUser.getAssigneeIdentifier());
-						assignment.put("roleName", aUser.getRole().getName());
-						
-						assignments.put(assignment);
-						
-					}
-			
-					jsonResponse.put("roleAssignments", assignments);
-						
-				} catch (JSONException e) {
-			
-					e.printStackTrace();
-				}
-			}   
-			
-		} else {
-			try {
-				jsonResponse.put("state", "error");
-				jsonResponse.put("error", "Request error. Parameters 'user' and 'password' are mandatory");
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-		
-		// ======================
-    
-		
-		java.io.PrintWriter out = response.getWriter();
-		out.print(jsonResponse);
-		out.flush();
-		
-		
-		
-	}
-}
--- a/src/main/java/de/mpiwg/monographs/servlet/GetUser.java	Wed Sep 09 17:13:18 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,147 +0,0 @@
-package de.mpiwg.monographs.servlet;
-
-import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
-
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang.StringUtils;
-import org.primefaces.json.JSONException;
-import org.primefaces.json.JSONObject;
-
-import edu.harvard.iq.dataverse.authorization.AuthenticationRequest;
-import edu.harvard.iq.dataverse.authorization.CredentialsAuthenticationProvider;
-import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException;
-import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
-
-
-public class GetUser extends AbstractMonographServlet{
-	
-
-	private static final Logger logger = Logger.getLogger(GetUser.class.getName());
-	
-	
-	
-	/*
-	private List<FilledCredential> filledCredentials;
-	
-	public static class FilledCredential {
-        CredentialsAuthenticationProvider.Credential credential;
-        String value;
-
-        public FilledCredential() {
-        }
-
-        public FilledCredential(CredentialsAuthenticationProvider.Credential credential, String value) {
-            this.credential = credential;
-            this.value = value;
-        }
-        
-        public CredentialsAuthenticationProvider.Credential getCredential() {
-            return credential;
-        }
-
-        public void setCredential(CredentialsAuthenticationProvider.Credential credential) {
-            this.credential = credential;
-        }
-
-        public String getValue() {
-            return value;
-        }
-
-        public void setValue(String value) {
-            this.value = value;
-        }
-        
-    }
-	
-	public List<FilledCredential> getFilledCredentials() {
-        return filledCredentials;
-    }
-	
-	public String getCredentialsAuthProviderId() {
-	       return credentialsAuthProviderId;
-	}
-	  
-	public CredentialsAuthenticationProvider selectedCredentialsProvider() {
-        return (CredentialsAuthenticationProvider) authSvc.getAuthenticationProvider(getCredentialsAuthProviderId());
-    }
-	
-	public void setCredentialsAuthProviderId(String authProviderId) {
-        this.credentialsAuthProviderId = authProviderId;
-    }
-	public void resetFilledCredentials() {
-        if ( selectedCredentialsProvider()==null ) return;
-        
-        filledCredentials = new LinkedList<>();
-        for ( CredentialsAuthenticationProvider.Credential c : selectedCredentialsProvider().getRequiredCredentials() ) {
-            filledCredentials.add( new FilledCredential(c, ""));
-        }
-    }
-	*/
-	
-	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		// Set response content type
-		response.setContentType("application/json");
-		JSONObject jsonResponse = new JSONObject();	
-		
-		String user = request.getParameter("user");
-		String password = request.getParameter("password");
-		
-			
-		if(StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)){
-			
-			AuthenticationRequest authReq = new AuthenticationRequest();
-	        authReq.putCredential("Username", user);
-	        authReq.putCredential("Password", password);
-	        try {
-	        	credentialsAuthProviderId = "builtin";
-	            //AuthenticatedUser authUser = authSvc.authenticate(credentialsAuthProviderId, authReq);
-	        	authUser = authSvc.authenticate(credentialsAuthProviderId, authReq);
-	            
-	        	System.out.println("User authenticated: " + authUser.getIdentifier());
-				
-	            if(authUser != null){
-					JSONObject jsonUser = MonographUtils.jsonAuthenticatedUser(authUser);
-					jsonResponse.put("state", "ok");
-					jsonResponse.put("user", jsonUser);
-
-				} else {
-					jsonResponse.put("state", "error");
-					jsonResponse.put("error", "User " + user + " no found.");
-				}
-	            
-	        } catch (AuthenticationFailedException ex) {
-	        	ex.printStackTrace();
-	        } catch (JSONException e) {
-				e.printStackTrace();
-			}
-			
-			
-		} else {
-			try {
-				jsonResponse.put("state", "error");
-				jsonResponse.put("error", "Request error. Parameters 'user' and 'password' are mandatory");
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-		
-		// ======================
-    
-		
-		java.io.PrintWriter out = response.getWriter();
-		out.print(jsonResponse);
-		out.flush();
-		
-		
-		
-	}
-}
--- a/src/main/java/de/mpiwg/monographs/servlet/MonographUtils.java	Wed Sep 09 17:13:18 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,101 +0,0 @@
-package de.mpiwg.monographs.servlet;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.primefaces.json.JSONObject;
-
-import edu.harvard.iq.dataverse.DataFile;
-import edu.harvard.iq.dataverse.RoleAssignment;
-import edu.harvard.iq.dataverse.ManagePermissionsPage.RoleAssignmentRow;
-import edu.harvard.iq.dataverse.authorization.Permission;
-import edu.harvard.iq.dataverse.authorization.RoleAssignee;
-import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup;
-import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser;
-import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
-
-
-public class MonographUtils {
-
-	
-	public static JSONObject jsonAuthenticatedUser(AuthenticatedUser user){
-		JSONObject json = new JSONObject();
-		
-		try {
-
-			json.put("email", user.getEmail());
-			json.put("firstName", user.getFirstName());
-			json.put("id", user.getId());
-			//json.put("version", user.getVersion());
-			json.put("userName", user.getUserIdentifier());	// getUserName->getUserIdentifier
-			json.put("position", user.getPosition());
-			json.put("lastName", user.getLastName());
-			json.put("affiliation", user.getAffiliation());
-			
-			// structure in dv4 does not support this
-			/*
-			JSONArray array0 = new JSONArray();
-			
-			// zoe added
-			Collection<ExplicitGroup> groups = findGroupsOfUser(user.getId());
-			
-			if( groups != null) {
-				for(ExplicitGroup group : groups){
-				array0.put(jsonGroup(group));
-			}
-				json.put("userGroups", array0);
-			}
-			*/
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		
-		
-		return json;
-	}
-	
-	
-	
-
-	public static JSONObject jsonGroup(ExplicitGroup group){
-		JSONObject json = new JSONObject();
-		
-		if(group != null){
-			try {
-				json.put("friendlyName", group.getDisplayName());
-				json.put("id", group.getId());
-				
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-		
-		return json;
-	}
-
-
-
-	public static JSONObject jsonBuiltinUser(BuiltinUser user) {
-		JSONObject json = new JSONObject();
-		
-		try {
-			json.put("email", user.getEmail());
-			json.put("firstName", user.getFirstName());
-			json.put("id", user.getId());
-			json.put("userName", user.getUserName());
-			json.put("position", user.getPosition());
-			json.put("lastName", user.getLastName());
-			json.put("affiliation", user.getAffiliation());
-			
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		
-		
-		return json;
-	}
-	
-	
-	
-}
--- a/src/main/java/de/mpiwg/monographs/servlet/SaveResource.java	Wed Sep 09 17:13:18 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,401 +0,0 @@
-package de.mpiwg.monographs.servlet;
-
-import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.MalformedURLException;
-import java.net.URLConnection;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.ejb.EJB;
-import javax.ejb.EJBException;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.MultipartConfig;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.Part;
-
-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.primefaces.json.JSONException;
-import org.primefaces.json.JSONObject;
-import org.primefaces.model.UploadedFile;
-
-import edu.harvard.iq.dataverse.DataFile;
-import edu.harvard.iq.dataverse.Dataset;
-import edu.harvard.iq.dataverse.DatasetServiceBean;
-import edu.harvard.iq.dataverse.DatasetVersion;
-import edu.harvard.iq.dataverse.DatasetVersionServiceBean;
-import edu.harvard.iq.dataverse.EjbDataverseEngine;
-import edu.harvard.iq.dataverse.UserNotification;
-import edu.harvard.iq.dataverse.DatasetPage.EditMode;
-import edu.harvard.iq.dataverse.authorization.AuthenticationRequest;
-import edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationFailedException;
-import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
-import edu.harvard.iq.dataverse.engine.command.Command;
-import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
-import edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetCommand;
-import edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand;
-import edu.harvard.iq.dataverse.ingest.IngestServiceBean;
-import edu.harvard.iq.dataverse.util.JsfHelper;
-
-
-@MultipartConfig 
-public class SaveResource extends AbstractMonographServlet {
-
-	private static final long serialVersionUID = 1L;
-
-
-	private static final String TMP_DIR = "/gazetteer-server/tmp/";
-
-
-	private int maxFileSize = 100 * 1024;
-	private int maxMemSize = 4 * 1024;
-
-	private static final Logger logger = Logger.getLogger("monographs.SaveResource");
-
-	@EJB
-    IngestServiceBean ingestService;
-	@EJB
-    DatasetServiceBean datasetService;
-	@EJB
-    DatasetVersionServiceBean datasetVersionService;
-	@EJB
-    EjbDataverseEngine commandEngine;
-	
-	private DatasetVersion workingVersion;
-	private Dataset dataset;
-	
-
-	Map<String, String> params = new HashMap<String, String>();
-	
-
-	public void init() throws ServletException {
-		super.init();
-	}
-
-
-	protected JSONObject saveFile(UpFile upFile) {
-		//String datasetGlobalId = "doi:10.5072/FK2/1EWLIR";
-		String datasetGlobalId = params.get("datasetGlobalId");
-		dataset = datasetService.findByGlobalId(datasetGlobalId);	
-        workingVersion = dataset.getEditVersion();
-     	
-		List<DataFile> dFileList = null;
-		try {
-	     	String fileContent = upFile.getFileContent();
-			String fileName = upFile.getFileName();
-			String contentType = upFile.getContentType();
-			
-			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());
-	        
-	    }
-		
-		
-		
-        ingestService.addFiles(workingVersion, dFileList);
-
-        JSONObject jsonSavedResult= new JSONObject();
-	
-        // Use the API to save the dataset: 
-        Command<Dataset> cmd;
-        try {
-            cmd = new UpdateDatasetCommand(dataset, this.authUser);
-            dataset = commandEngine.submit(cmd);
-            
-        } catch (EJBException ex) {
-            StringBuilder error = new StringBuilder();
-            error.append(ex).append(" ");
-            error.append(ex.getMessage()).append(" ");
-            Throwable cause = ex;
-            while (cause.getCause()!= null) {
-                cause = cause.getCause();
-                error.append(cause).append(" ");
-                error.append(cause.getMessage()).append(" ");
-            }
-            logger.log(Level.FINE, "Couldn''t save dataset: {0}", error.toString());
-            //populateDatasetUpdateFailureMessage();
-            try {
-				jsonSavedResult.put("status", "error");
-				jsonSavedResult.put("message", "Could not save dataset.");
-			} catch (JSONException e) {
-				
-				e.printStackTrace();
-			}
-            return jsonSavedResult;
-        } catch (CommandException ex) {
-            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
-            logger.severe(ex.getMessage());
-            //populateDatasetUpdateFailureMessage();
-            try {
-				jsonSavedResult.put("status", "error");
-				jsonSavedResult.put("message", "Dataset Save Failed");
-			} catch (JSONException e) {
-				
-				e.printStackTrace();
-			}
-            return jsonSavedResult;
-            
-        }
-      
-        // Call Ingest Service one more time, to 
-        // 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?
-
-		try {
-			jsonSavedResult.put("status", "ok");
-			jsonSavedResult.put("message", "Dataset Saved!");
-			
-			JSONObject fileMetadata = new JSONObject();
-			
-			System.out.println(dataset.getDisplayName());
-			
-			fileMetadata.put("datasetTitle", dataset.getDisplayName());
-			
-			jsonSavedResult.put("fileMetadata", fileMetadata);
-			
-			
-		} catch (JSONException e) {
-			e.printStackTrace();
-		}
-       
-		return jsonSavedResult;
-	}
-	
-	private void loadParameters(HttpServletRequest request) {	
-		
-		params.put("user", request.getParameter("user"));
-		params.put("password", request.getParameter("password"));
-		params.put("datasetGlobalId", request.getParameter("datasetGlobalId"));
-		
-		return;
-	}
-	
-	private class UpFile {
-		public String fileName;
-		public String fileContent;
-		public String contentType;
-
-		public UpFile (String fileName, String fileContent, String contentType) {
-			this.fileName = fileName;
-			this.fileContent = fileContent;
-			this.contentType = contentType;
-		}
-
-		public String getFileName() {
-			return fileName;
-		}
-		public void setFileName(String fileName) {
-			this.fileName = fileName;
-		}
-		public String getFileContent() {
-			return fileContent;
-		}
-
-		public void setFileContent(String fileContent) {
-			this.fileContent = fileContent;
-		}
-
-		public String getContentType() {
-			return contentType;
-		}
-
-		public void setContentType(String contentType) {
-			this.contentType = contentType;
-		}
-		
-	}
-	
-	
-	@Override
-	protected void doPost(HttpServletRequest request, HttpServletResponse response) {
-
-		try {
-			response.setContentType("application/json");
-			JSONObject jsonResponse = new JSONObject();
-				
-			loadParameters(request);
-			UpFile upFile = getFile(request);
-			
-			String fileName = upFile.getFileName();
-			String fileContent = upFile.getFileContent();
-			
-			if(StringUtils.isNotEmpty(fileContent) && StringUtils.isNotEmpty(fileName)){
-				
-				String datasetGlobalId = params.get("datasetGlobalId");	
-				String user = params.get("user");
-				String password = params.get("password");
-				
-				if(StringUtils.isNotEmpty(datasetGlobalId) && StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)){
-							
-					AuthenticationRequest authReq = new AuthenticationRequest();
-					
-				    authReq.putCredential("Username", user);
-				    authReq.putCredential("Password", password);
-				    try {
-				        String credentialsAuthProviderId = "builtin";
-				        this.authUser = authSvc.authenticate(credentialsAuthProviderId, authReq);
-				        System.out.println("User authenticated: " + authUser.getIdentifier()); 
-				    } catch (AuthenticationFailedException ex) {
-				       ex.printStackTrace();
-				    }
-				    
-				
-					JSONObject jsonSavedResult = saveFile(upFile);
-					jsonResponse.put("status", jsonSavedResult.getString("status"));
-					jsonResponse.put("message", jsonSavedResult.getString("message"));
-					if (jsonSavedResult.has("fileMetadata")) {
-						jsonResponse.put("fileMetadata", jsonSavedResult.getJSONObject("fileMetadata"));
-					}
-					
-								
-				}else{
-					jsonResponse.put("status", "error");
-					jsonResponse.put("error", "The parameters studyId, user and password.");
-					jsonResponse.put("datasetGlobalId", datasetGlobalId);
-					jsonResponse.put("user", user);
-					jsonResponse.put("password", password);
-					//jsonResponse.put("fileLabel", fileLabel);
-				}
-
-			}else if(StringUtils.isNotEmpty(fileName)){
-				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 {
-				jsonResponse.put("status", "error");
-				jsonResponse.put("message", "No file found in the request.");
-			}
-			
-			java.io.PrintWriter out = response.getWriter();
-			out.print(jsonResponse);
-			out.flush();
-		} catch (Exception e) {	
-			e.printStackTrace();
-		}
-	}
-	
-
-
-
-	private UpFile getFile(HttpServletRequest request) throws IOException {
-		JSONObject fileObj;
-		try {
-			fileObj = new JSONObject(request.getParameter("file"));
-			
-			String contentType = "text/plain; charset=UTF-8";
-
-			Iterator keys = fileObj.keys(); //gets all the keys
-			while (keys.hasNext()) {
-				String fileName = (String) keys.next();
-			    String fileTable = fileObj.getString(fileName);
-	
-				UpFile upFile = new UpFile(fileName, fileTable, contentType);
-				
-				return upFile;
-			}
-	
-		} catch (JSONException e) {
-			
-			e.printStackTrace();
-		} 
-		return null;
-
-	}
-	
-
-
-    // delete this
-	private File getFile_old(HttpServletRequest request, HttpServletResponse response) throws IOException {
-		File file = null;
-		boolean isMultipart = ServletFileUpload.isMultipartContent(request);		
-	
-		if(isMultipart){
-			DiskFileItemFactory factory = new DiskFileItemFactory();
-			// maximum size that will be stored in memory
-			factory.setSizeThreshold(maxMemSize);
-			// Location to save data that is larger than maxMemSize.
-			factory.setRepository(new File(TMP_DIR));
-
-			// Create a new file upload handler
-			ServletFileUpload upload = new ServletFileUpload(factory);
-			// maximum file size to be uploaded.
-			upload.setSizeMax(maxFileSize);
-			upload.setFileSizeMax(maxFileSize);
-			upload.setHeaderEncoding("UTF-8");
-			
-			StringBuilder sb = new StringBuilder();
-			try {
-				// Parse the request to get file items.
-				List<FileItem> fileItems = upload.parseRequest(request); 
-				
-				// Process the uploaded file items
-				Iterator<FileItem> i = fileItems.iterator();
-
-				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
-						if (fileName.lastIndexOf("\\") >= 0) {
-							file = new File(TMP_DIR + fileName.substring(fileName.lastIndexOf("\\")));
-						} else {
-							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" + ".\nWhen the file is empty, maybe the tmp folder is wrong configured.\nTMP_DIR: " + TMP_DIR : "File Size=" + file.length() );
-			logger.log(Level.INFO, "getFile Information:\n" + sb.toString());
-			
-			return file;	
-		}
-		
-		return null;
-	}
-	
-
-
-
-}
--- a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java	Wed Sep 09 17:13:18 2015 +0200
+++ b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java	Wed Sep 30 13:43:54 2015 +0200
@@ -1,9 +1,8 @@
 package edu.harvard.iq.dataverse;
 
-import de.mpiwg.monographs.servlet.MonographUtils;
+import de.mpiwg.gazetteer.utils.PropertiesUtils;
 import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
 import edu.harvard.iq.dataverse.authorization.Permission;
-import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser;
 import edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUserServiceBean;
 import edu.harvard.iq.dataverse.authorization.users.ApiToken;
 import edu.harvard.iq.dataverse.authorization.users.User;
@@ -1197,16 +1196,14 @@
     	System.out.println("viewLGMapOutputLink");
   
     	Long fileId = fm.getDataFile().getId();
-    	
-    	//System.out.println("fileId=" + fileId);
-   
-    	// implement a method which will send file data in post as json to LGMap
-    	// String retVal = "http://localhost:8082/api/dataverses/2/contents?key=9dd1f749-8c42-49ab-a2ba-fbb963c2ff90";	
-        // String retVal = "http://localhost:1080/localgazetteers-dev/LGMap/map.php?mode=1&name="+fm.getLabel()+"&fileId="+fileId;
-        
+    
     	try {
-        	String retVal = "http://localhost:1080/localgazetteers-dev/LGMap/map.php?mode=1&name="+URLEncoder.encode(fm.getLabel(), "UTF-8")+"&fileId="+fileId;
-            
+        	// 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.");
--- a/src/main/java/edu/harvard/iq/dataverse/DataverseHeaderFragment.java	Wed Sep 09 17:13:18 2015 +0200
+++ b/src/main/java/edu/harvard/iq/dataverse/DataverseHeaderFragment.java	Wed Sep 30 13:43:54 2015 +0200
@@ -12,9 +12,12 @@
 import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
 import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
 import edu.harvard.iq.dataverse.util.SystemConfig;
+
 import java.io.UnsupportedEncodingException;
+import java.net.InetAddress;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -22,12 +25,14 @@
 import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
 import javax.ejb.EJB;
 import javax.faces.context.FacesContext;
 import javax.faces.view.ViewScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.servlet.http.HttpServletRequest;
+
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -185,7 +190,9 @@
         boolean safeDefaultIfKeyNotFound = false;
         return settingsService.isTrueForKey(SettingsServiceBean.Key.AllowSignUp, safeDefaultIfKeyNotFound);
     }
-
+    
+   
+    
     public String getSignupUrl() {
         String nonNullDefaultIfKeyNotFound = "";
         String signUpUrl = settingsService.getValueForKey(SettingsServiceBean.Key.SignUpUrl, nonNullDefaultIfKeyNotFound);
--- a/src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java	Wed Sep 09 17:13:18 2015 +0200
+++ b/src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java	Wed Sep 30 13:43:54 2015 +0200
@@ -225,29 +225,14 @@
         return auth;
     }
     private String getRegistrationUrl(Dataset dataset) {
-        String siteUrl = getSiteUrl();
+       
         
-        String targetUrl = siteUrl + "/dataset.xhtml?persistentId=hdl:" + dataset.getAuthority() 
+        String targetUrl = "/dataset.xhtml?persistentId=hdl:" + dataset.getAuthority() 
                 + "/" + dataset.getIdentifier();       
         return targetUrl;
     }
     
-    public String getSiteUrl() {
-        String hostUrl = System.getProperty("dataverse.siteUrl");
-        if (hostUrl != null && !"".equals(hostUrl)) {
-            return hostUrl;
-        }
-        String hostName = System.getProperty("dataverse.fqdn");
-        if (hostName == null) {
-            try {
-                hostName = InetAddress.getLocalHost().getCanonicalHostName();
-            } catch (UnknownHostException e) {
-                return null;
-            }
-        }
-        hostUrl = "https://" + hostName;
-        return hostUrl;
-    }
+   
     
     private byte[] readKey(final String file) {
         byte[] key = null;
--- a/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java	Wed Sep 09 17:13:18 2015 +0200
+++ b/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java	Wed Sep 30 13:43:54 2015 +0200
@@ -38,7 +38,7 @@
      * with the protocol, port number etc. 
      */
     public static final String SITE_URL = "dataverse.siteUrl";
-
+    
     /**
      * A JVM option for where files are stored on the file system.
      */
--- a/src/main/webapp/WEB-INF/faces-config.xml	Wed Sep 09 17:13:18 2015 +0200
+++ b/src/main/webapp/WEB-INF/faces-config.xml	Wed Sep 30 13:43:54 2015 +0200
@@ -12,6 +12,7 @@
             <default-locale>en</default-locale>
             <supported-locale>zh_CN</supported-locale>
         </locale-config>
+        
     </application>
     <render-kit>
         <renderer>
--- a/src/main/webapp/WEB-INF/glassfish-web.xml	Wed Sep 09 17:13:18 2015 +0200
+++ b/src/main/webapp/WEB-INF/glassfish-web.xml	Wed Sep 30 13:43:54 2015 +0200
@@ -11,5 +11,7 @@
   <property name="alternatedocroot_1" value="from=/guides/* dir=./docroot"/>
   <property name="alternatedocroot_2" value="from=/dataexplore/* dir=./docroot"/>
   <property name="alternatedocroot_logos" value="from=/logos/* dir=./docroot"/>
+  
+  
   <parameter-encoding default-charset="UTF-8" />
 </glassfish-web-app>
--- a/src/main/webapp/WEB-INF/web.xml	Wed Sep 09 17:13:18 2015 +0200
+++ b/src/main/webapp/WEB-INF/web.xml	Wed Sep 30 13:43:54 2015 +0200
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
     <display-name>Dataverse</display-name>
+   	
     <!-- Error page -->
     <error-page>
         <error-code>404</error-code>
@@ -201,59 +202,58 @@
     
     
     
-    <!-- Monographs Configuration -->
+    <!-- Gazetteer Configuration -->
     <!-- zhong added -->
     
 	<!-- Get User -->
 	<servlet-mapping>
-        <servlet-name>de.mpiwg.monographs.servlet.GetUser</servlet-name>
+        <servlet-name>de.mpiwg.gazetteer.servlet.GetUser</servlet-name>
         <url-pattern>/getUser</url-pattern>
     </servlet-mapping>
    	<servlet>
-       <servlet-name>de.mpiwg.monographs.servlet.GetUser</servlet-name>
-       <servlet-class>de.mpiwg.monographs.servlet.GetUser</servlet-class>
+       <servlet-name>de.mpiwg.gazetteer.servlet.GetUser</servlet-name>
+       <servlet-class>de.mpiwg.gazetteer.servlet.GetUser</servlet-class>
 	</servlet>
 	
 
 	<!-- Get AllUsers -->
 	<servlet-mapping>
-        <servlet-name>de.mpiwg.monographs.servlet.GetAllUsers</servlet-name>
+        <servlet-name>de.mpiwg.gazetteer.servlet.GetAllUsers</servlet-name>
         <url-pattern>/getAllUsers</url-pattern>
     </servlet-mapping>
    	<servlet>
-       <servlet-name>de.mpiwg.monographs.servlet.GetAllUsers</servlet-name>
-       <servlet-class>de.mpiwg.monographs.servlet.GetAllUsers</servlet-class>
+       <servlet-name>de.mpiwg.gazetteer.servlet.GetAllUsers</servlet-name>
+       <servlet-class>de.mpiwg.gazetteer.servlet.GetAllUsers</servlet-class>
 	</servlet>
 	
-	
 	<!-- Get Datasets (Studies) -->
 	<servlet-mapping>
-        <servlet-name>de.mpiwg.monographs.servlet.GetDatasets</servlet-name>
+        <servlet-name>de.mpiwg.gazetteer.servlet.GetDatasets</servlet-name>
         <url-pattern>/getStudies</url-pattern>
     </servlet-mapping>
    	<servlet>
-       <servlet-name>de.mpiwg.monographs.servlet.GetDatasets</servlet-name>
-       <servlet-class>de.mpiwg.monographs.servlet.GetDatasets</servlet-class>
+       <servlet-name>de.mpiwg.gazetteer.servlet.GetDatasets</servlet-name>
+       <servlet-class>de.mpiwg.gazetteer.servlet.GetDatasets</servlet-class>
 	</servlet>
 	
 	<!-- Get RoleAssignments -->
 	<servlet-mapping>
-        <servlet-name>de.mpiwg.monographs.servlet.GetRoleAssignments</servlet-name>
+        <servlet-name>de.mpiwg.gazetteer.servlet.GetRoleAssignments</servlet-name>
         <url-pattern>/getRoleAssignments</url-pattern>
     </servlet-mapping>
    	<servlet>
-       <servlet-name>de.mpiwg.monographs.servlet.GetRoleAssignments</servlet-name>
-       <servlet-class>de.mpiwg.monographs.servlet.GetRoleAssignments</servlet-class>
+       <servlet-name>de.mpiwg.gazetteer.servlet.GetRoleAssignments</servlet-name>
+       <servlet-class>de.mpiwg.gazetteer.servlet.GetRoleAssignments</servlet-class>
 	</servlet>
 	
 	 <!-- Save -->
 	<servlet-mapping>
-        <servlet-name>de.mpiwg.monographs.servlet.SaveResource</servlet-name>
+        <servlet-name>de.mpiwg.gazetteer.servlet.SaveResource</servlet-name>
         <url-pattern>/saveResource</url-pattern>
     </servlet-mapping>
    	<servlet>
-       <servlet-name>de.mpiwg.monographs.servlet.SaveResource</servlet-name>
-       <servlet-class>de.mpiwg.monographs.servlet.SaveResource</servlet-class>
+       <servlet-name>de.mpiwg.gazetteer.servlet.SaveResource</servlet-name>
+       <servlet-class>de.mpiwg.gazetteer.servlet.SaveResource</servlet-class>
        <multipart-config>
             <max-file-size>10485760</max-file-size>
             <max-request-size>20971520</max-request-size>
@@ -263,22 +263,22 @@
 	
 	<!-- Get Datafile -->
 	<servlet-mapping>
-        <servlet-name>de.mpiwg.monographs.servlet.GetDatafile</servlet-name>
+        <servlet-name>de.mpiwg.gazetteer.servlet.GetDatafile</servlet-name>
         <url-pattern>/getDatafile</url-pattern>
     </servlet-mapping>
    	<servlet>
-       <servlet-name>de.mpiwg.monographs.servlet.GetDatafile</servlet-name>
-       <servlet-class>de.mpiwg.monographs.servlet.GetDatafile</servlet-class>
+       <servlet-name>de.mpiwg.gazetteer.servlet.GetDatafile</servlet-name>
+       <servlet-class>de.mpiwg.gazetteer.servlet.GetDatafile</servlet-class>
 	</servlet>
 	
 	<!-- Get AllDataverseAlias -->
 	<servlet-mapping>
-        <servlet-name>de.mpiwg.monographs.servlet.GetAllDataverseAlias</servlet-name>
+        <servlet-name>de.mpiwg.gazetteer.servlet.GetAllDataverseAlias</servlet-name>
         <url-pattern>/getAllDataverseAlias</url-pattern>
     </servlet-mapping>
    	<servlet>
-       <servlet-name>de.mpiwg.monographs.servlet.GetAllDataverseAlias</servlet-name>
-       <servlet-class>de.mpiwg.monographs.servlet.GetAllDataverseAlias</servlet-class>
+       <servlet-name>de.mpiwg.gazetteer.servlet.GetAllDataverseAlias</servlet-name>
+       <servlet-class>de.mpiwg.gazetteer.servlet.GetAllDataverseAlias</servlet-class>
 	</servlet>
 	
 	<!-- zoe end -->