# HG changeset patch # User "jurzua " # Date 1429796761 -7200 # Node ID 3e62083dbcbfec2a9530e1df52a1c4b9b84d5a8c First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery. diff -r 000000000000 -r 3e62083dbcbf pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,208 @@ + + 4.0.0 + de.mpiwg + LGServices + war + 1.0-SNAPSHOT + LGServices Maven Webapp + http://maven.apache.org + + + + + + + cl.talca + hashMapping + 1.0 + + + + javax.servlet.jsp + jsp-api + 2.2.1-b03 + provided + + + javax.el + el-api + 2.2.1-b04 + provided + + + + javax.servlet + jstl + 1.2 + + + + + + + + org.apache.tomcat + tomcat-servlet-api + 7.0.59 + provided + + + + commons-fileupload + commons-fileupload + 1.3.1 + + + + org.slf4j + slf4j-log4j12 + 1.6.4 + + + log4j + log4j + 1.2.17 + + + + + asm + asm + 3.3.1 + + + + + commons-lang + commons-lang + 2.6 + + + org.json + json + 20090211 + + + + org.hibernate + hibernate-core + 4.3.8.Final + + + org.hibernate + hibernate-entitymanager + 4.3.8.Final + + + org.hibernate + hibernate-c3p0 + 4.3.8.Final + + + + c3p0 + c3p0 + 0.9.1.2 + + + + mysql + mysql-connector-java + 5.1.6 + + + + + + + LGServices + + + false + src/main/resources + + + false + src/main/java + + ** + + + **/*.java + + + + + + + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.10 + + 10 + foo + 9999 + + + + start-jetty + pre-integration-test + + run + + + 0 + true + + + + stop-jetty + post-integration-test + + stop + + + + + + + + + + diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/bo/DBEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/DBEntry.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,119 @@ +package de.mpiwg.gazetteer.bo; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public abstract class DBEntry { + + private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy-HH:mm"); + + public DBEntry(){} + + @Id + @GeneratedValue(strategy = GenerationType.TABLE) + @Column(name="id") + protected Long id; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="creationDate") + private Date creationDate; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name="lastChangeDate") + private Date lastChangeDate; + + public boolean isPersistent(){ + if(this.getId() == null){ + return false; + }else{ + return true; + } + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public Date getLastChangeDate() { + return lastChangeDate; + } + + public void setLastChangeDate(Date lastChangeDate) { + this.lastChangeDate = lastChangeDate; + } + + public String getFomattedLastChange(){ + if(this.lastChangeDate != null) + return DATE_FORMAT.format(this.lastChangeDate); + return null; + } + + public String getFomattedCreation(){ + if(this.creationDate != null) + return DATE_FORMAT.format(this.creationDate); + return null; + } + + + public String getInfo(){ + if(isPersistent()){ + StringBuilder sb = new StringBuilder("id=" + id); + + if(creationDate != null){ + sb.append(", creation date=" + creationDate); + } + + if(lastChangeDate != null){ + sb.append(", last change=" + lastChangeDate); + } + return sb.toString(); + } + return new String(); + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof DBEntry)) { + return false; + } + DBEntry other = (DBEntry) object; + + if(this.id != null && other.id != null && this.id.longValue() == other.id.longValue()) + return true; + + return false; + } + + @Override + public String toString(){ + StringBuilder sb = new StringBuilder(); + sb.append(this.getClass().toString()); + sb.append(" [id=" + this.id + "] "); + return sb.toString(); + } +} \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/bo/LGBranch.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/LGBranch.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,263 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import javax.persistence.Transient; + +import org.json.JSONArray; + +import cl.maps.duplex.DuplexKey; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; +import de.mpiwg.gazetteer.utils.DataProvider; + + +@Entity +@Table(name="Branch") +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public class LGBranch extends DBEntry implements Cloneable, Serializable { + private static final long serialVersionUID = 7805209462045170778L; + + + @Column(name="sectionId") + private Long sectionId; + + @Column(name="userId") + private Long userId; + + @Column(name="contributors") + private String contributors = "[]"; + + @Column(name="label") + private String label; + + @Column(name="description") + private String description; + + @Column(name="currentLastFileId") + private Long currentLastFileId; + + @Transient + private List contributorsList; + + @Transient + private String contributorsLabel; + + @Transient + private DBBook book; + + @Transient + private DBSection section; + + @Transient + private boolean transientDataLoaded = false; + + @Transient + private boolean published = false; + + public void loadTransientData(){ + try { + this.section = DBService.getSectionWithContent(sectionId); + this.book = section.getBook(); + this.transientDataLoaded = true; + this.published = atLeastOneFilePublished(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public boolean atLeastOneFilePublished(){ + + List files = DataProvider.getInstance().getAllFiles(this.id); + for(LGFile file : files){ + if(file.getDvId() != null){ + return true; + } + } + return false; + } + + public boolean isTransientDataLoaded() { + return transientDataLoaded; + } + + + + public Object clone() throws CloneNotSupportedException { + LGBranch clone = (LGBranch)super.clone(); + clone.setContributorsList(new ArrayList(clone.getContributorsList())); + clone.book = this.book; + return clone; + } + + + + public boolean hasContributor(Long userId){ + for(Long id : getContributorsList()){ + if(id.equals(userId)){ + return true; + } + } + return false; + } + + public List getContributorsList(){ + if(contributorsList == null){ + reloadContributorsList(); + } + return contributorsList; + } + + public List getContributorsNameList(){ + List list = new ArrayList(); + for(Long userId : getContributorsList()){ + list.add(DataverseUtils.getUsername(userId)); + } + return list; + } + + public String getUsername(){ + if(this.userId != null){ + return DataverseUtils.getUsername(this.userId); + } + return null; + } + + private void reloadContributorsList(){ + this.contributorsList = new ArrayList(); + try { + JSONArray array = new JSONArray(this.contributors); + for(int i=0; i getKey(){ + return new DuplexKey(this.userId, this.id); + } + + + @Override + public String toString(){ + return "LGBranch[label=" + label + ", id=" + id + ", sectionId=" + sectionId + "]"; + } + + public String getContributorsLabel() { + return contributorsLabel; + } + + public void setContributorsLabel(String contributorsLabel) { + this.contributorsLabel = contributorsLabel; + } + + public void setContributorsList(List contributorsList) { + this.contributorsList = contributorsList; + } + + public DBSection getSection() { + return section; + } + + public void setSection(DBSection section) { + this.section = section; + } + + public DBBook getBook() { + return book; + } + + public void setBook(DBBook book) { + this.book = book; + } + + public boolean isPublished() { + return published; + } + + public void setPublished(boolean published) { + this.published = published; + } + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/bo/LGFile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/LGFile.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,134 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import javax.persistence.Transient; + +import cl.maps.duplex.DuplexKey; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; + + +@Entity +@Table(name="File") +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public class LGFile extends DBEntry implements Cloneable, Serializable, Comparable { + + private static final long serialVersionUID = 1638482732212457961L; + + //many files can have the same fileId + @Column(name="branchId") + private Long branchId; + + //if this file has been exported to DV, here is saved the id. + @Column(name="dvId") + private Long dvId; + + @Column(name="version") + private Integer version = 0; + + @Column(name="fileName") + private String fileName; + + @Column(name="userId") + private Long userId; + + @Column(name="lastVersion") + private boolean lastVersion = true; + + + @Column(name="notes") + private String notes; + + @Transient + private String content; + + public Long getDvId() { + return dvId; + } + + public void setDvId(Long dvId) { + this.dvId = dvId; + } + + public Integer getVersion() { + return version; + } + + public void setVersion(Integer version) { + this.version = version; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getUsername(){ + if(this.userId != null){ + return DataverseUtils.getUsername(this.userId); + } + return null; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public boolean isLastVersion() { + return lastVersion; + } + + public void setLastVersion(boolean lastVersion) { + this.lastVersion = lastVersion; + } + + public Long getBranchId() { + return branchId; + } + + public void setBranchId(Long branchId) { + this.branchId = branchId; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + @Override + public int compareTo(LGFile o) { + return getCreationDate().compareTo(o.getCreationDate()); + } + + public DuplexKey getKey(){ + return new DuplexKey(this.branchId, this.id); + } + + @Override + public String toString(){ + return "LGFile [id=" + id + ", branchId=" + branchId + ", fileName=" + fileName + "]"; + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/bo/SearchRulesFile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/SearchRulesFile.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,67 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; + +import cl.maps.duplex.DuplexKey; + +@Entity +@Table(name="SearchRulesFile.java") +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public class SearchRulesFile extends DBEntry implements Cloneable, Serializable { + + private static final long serialVersionUID = -3717062037374537162L; + + @Column(name="fileName") + private String fileName; + + @Column(name="description") + private String description; + + @Column(name="content") + private String content; + + @Column(name="userId") + private Long userId; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public DuplexKey getKey(){ + return new DuplexKey(this.userId, this.id); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/bo/Sequence.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/Sequence.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,94 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * + * @author jurzua + */ +@Entity +@Table(name="row_sequence") +public class Sequence implements Serializable { + + private static final long serialVersionUID = 120128920808559599L; + + public Sequence(){} + + public Sequence(String name, Long value){ + this.lastValue = value; + this.name = name; + } + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @Column(name="name") + private String name; + + @Column(name="last_value") + private Long lastValue; + + public Long generateId(){ + return this.lastValue++; + } + + public Long getLastValue() { + return lastValue; + } + + public void setLastValue(Long lastValue) { + this.lastValue = lastValue; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + + @Override + public int hashCode() { + int hash = 0; + hash += (id != null ? id.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof Sequence)) { + return false; + } + Sequence other = (Sequence) object; + if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "org.mpi.openmind.ontology.joins.Sequence[id=" + id + "]"; + } + +} + diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/dataverse/DVDataDepositAPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DVDataDepositAPI.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,43 @@ +package de.mpiwg.gazetteer.dataverse; + +import de.mpiwg.gazetteer.utils.HTTPUtils; +import de.mpiwg.gazetteer.utils.HTTPUtils.HttpStringResponse; + +/** + * Doc: http://thedata.harvard.edu/guides/dataverse-api-main.html#data-deposit-api + * @author jurzua + * + */ +public class DVDataDepositAPI { + + private static String user = "jurzua"; + private static String pwd = "221082"; + //curl https://jurzua:221082@thedata.harvard.edu/dvn/api/data-deposit/v1/swordv2/service-document + + + public static String retrieveSWORDServiceDocument(String user, String pwd) throws Exception{ + HttpStringResponse resp = + HTTPUtils.getStringResponse("https://" + user + ":" + pwd + "@thedata.harvard.edu/dvn/api/data-deposit/v1/swordv2/service-document"); + return resp.content; + } + + public static void createStudy(String xmlFile){ + //TODO + } + + public static void addFiles2Study(){ + + } + + public static void listStudies(){ + + } + + public static void deleteStudy(){} + + public static void deaccessStudy() {} + + public static void releaseStudy() {} + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/dataverse/DVFileAccessAPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DVFileAccessAPI.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.gazetteer.dataverse; + +public class DVFileAccessAPI { + + ///dvn/api/downloadInfo/9956 + public String downloadInfo(){ + return ""; + } + + ///dvn/api/download/9956 + public Byte[] download(){ + return null; + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/dataverse/DVMetadataAPI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DVMetadataAPI.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,33 @@ +package de.mpiwg.gazetteer.dataverse; + +import java.io.IOException; + +import de.mpiwg.gazetteer.utils.HTTPUtils; +import de.mpiwg.gazetteer.utils.HTTPUtils.HttpStringResponse; + +public class DVMetadataAPI { + + //public static String dataverseInstance = "https://thedata.harvard.edu/dvn/api/"; + public static String dataverseInstance = "https://localhost/dvn/api/"; + + public static String metadataSearchFields() throws Exception{ + HttpStringResponse res = HTTPUtils.getStringResponse(dataverseInstance + "metadataSearchFields"); + return res.content; + } + + public static void metadataSearch(){} + + public static void metadataFormatsAvailable(){} + + public static void metadata(){} + + + public static void main(String[] args){ + try { + System.out.println(DVMetadataAPI.metadataSearchFields()); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/dataverse/DataverseUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/DataverseUtils.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,214 @@ +package de.mpiwg.gazetteer.dataverse; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONArray; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.dataverse.bo.Study; +import de.mpiwg.gazetteer.dataverse.bo.VDCUser; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.FileManager; +import de.mpiwg.gazetteer.utils.HTTPUtils; +import de.mpiwg.gazetteer.utils.HTTPUtils.HttpStringResponse; +import de.mpiwg.gazetteer.utils.PropertiesUtils; + +public class DataverseUtils { + + private static List userList; + + static{ + userList = new ArrayList(); + userList.add(new VDCUser(new Long(10), "jurzua", "1234")); + userList.add(new VDCUser(new Long(11), "john", "1234")); + userList.add(new VDCUser(new Long(12), "zoe", "1234")); + userList.add(new VDCUser(new Long(13), "paul", "1234")); + } + + + /** + * + * curl --form upload=@pom.xml --form user=networkAdmin --form password=networkAdmin --form studyId=hdl:TEST/10002 http://localhost/dvn/saveResource + * see: http://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically + * @param branchId + * @param studyGlobalId + * @throws Exception + */ + public static JSONObject publishFile(Long fileId, String studyGlobalId, String userName, String password) throws Exception{ + + LGFile lgFile = DataProvider.getInstance().getFile(fileId); + LGBranch branch = DataProvider.getInstance().getBranch(lgFile.getBranchId()); + String link = PropertiesUtils.getPropValue("dvn_server") + "/saveResource"; + + + MultipartUtility multipart = new MultipartUtility(link, "UTF-8"); + + multipart.addFormField("studyId", studyGlobalId); + multipart.addFormField("password", password); + multipart.addFormField("user", userName); + //multipart.addFormField("fileLabel", branch.getLabel() + ".html"); + + + String table = HTTPUtils.getTableOfFile(lgFile.getId()); + System.out.println("Table string lenght" + table.length()); + + multipart.addFilePart0(branch.getLabel() + ".html", table); + + String response = multipart.finish(); + + System.out.println(response); + + return new JSONObject(response); + } + + public static List getStudies(String userName, String password) throws IOException{ + List list = new ArrayList(); + + String query = PropertiesUtils.getPropValue("dvn_server") + "/getStudies?user=" + userName + "&password=" + password; + + HttpStringResponse response = null; + try { + response = HTTPUtils.getStringResponse(query); + JSONObject json = new JSONObject(response.content); + if(json.has("studies")){ + + JSONArray userArray = json.getJSONArray("studies"); + + for(int i=0; i getAllUsers0(){ + return userList; + } + + public static VDCUser getUser(Long id){ + try { + for(VDCUser user : getAllUsers()){ + if(user.getId().equals(id)){ + return user; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static String getUsername(Long id){ + try { + for(VDCUser user : getAllUsers()){ + if(user.getId().equals(id)){ + return user.getUserName(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return "user-no-found ("+ id +")"; + } + + public static List getAllUsers() throws Exception{ + List list = new ArrayList(); + + String query = PropertiesUtils.getPropValue("dvn_server") + "/getAllUsers"; + /* + System.out.println("************************************************"); + System.out.println("URL: " + query); + System.out.println("************************************************"); + */ + HttpStringResponse response = null; + try { + response = HTTPUtils.getStringResponse(query); + JSONObject json = new JSONObject(response.content); + if(StringUtils.equals(json.getString("state"), "ok")){ + + JSONArray userArray = json.getJSONArray("users"); + + for(int i=0; i + * @param uploadFile a File to be uploaded + * @throws IOException + */ + public void addFilePart(String fieldName, File uploadFile) + throws IOException { + String fileName = uploadFile.getName(); + writer.append("--" + boundary).append(LINE_FEED); + writer.append( + "Content-Disposition: form-data; name=\"" + fieldName + + "\"; filename=\"" + fileName + "\"") + .append(LINE_FEED); + writer.append( + "Content-Type: " + + URLConnection.guessContentTypeFromName(fileName)) + .append(LINE_FEED); + writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED); + writer.append(LINE_FEED); + writer.flush(); + + FileInputStream inputStream = new FileInputStream(uploadFile); + byte[] buffer = new byte[4096]; + int bytesRead = -1; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + outputStream.flush(); + inputStream.close(); + + writer.append(LINE_FEED); + writer.flush(); + } + + public void addFilePart0(String fieldName, String fileContent) + throws IOException { + writer.append("--" + boundary).append(LINE_FEED); + writer.append( + "Content-Disposition: form-data; name=\"" + fieldName + + "\"; filename=\"" + fieldName + "\"") + .append(LINE_FEED); + writer.append( + "Content-Type: " + + URLConnection.guessContentTypeFromName(fieldName)) + .append(LINE_FEED); + writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED); + writer.append(LINE_FEED); + writer.flush(); + + InputStream inputStream = new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)); + byte[] buffer = new byte[4096]; + int bytesRead = -1; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + outputStream.flush(); + inputStream.close(); + + writer.append(LINE_FEED); + writer.flush(); + } + + /** + * Adds a header field to the request. + * @param name - name of the header field + * @param value - value of the header field + */ + public void addHeaderField(String name, String value) { + writer.append(name + ": " + value).append(LINE_FEED); + writer.flush(); + } + + /** + * Completes the request and receives response from the server. + * @return a list of Strings as response in case the server returned + * status OK, otherwise an exception is thrown. + * @throws IOException + */ + public String finish() throws IOException { + StringBuilder sb = new StringBuilder(); + + writer.append(LINE_FEED).flush(); + writer.append("--" + boundary + "--").append(LINE_FEED); + writer.close(); + + // checks server's status code first + int status = httpConn.getResponseCode(); + if (status == HttpURLConnection.HTTP_OK) { + BufferedReader reader = new BufferedReader(new InputStreamReader( + httpConn.getInputStream())); + String line = null; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + reader.close(); + httpConn.disconnect(); + } else { + throw new IOException("Server returned non-OK status: " + status); + } + + return sb.toString(); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/dataverse/bo/Dataverse.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/bo/Dataverse.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,47 @@ +package de.mpiwg.gazetteer.dataverse.bo; + +import org.json.JSONException; +import org.json.JSONObject; + +public class Dataverse { + + private String name; + private String aboutThis; + private Integer version; + private String alias; + + public Dataverse(JSONObject json) throws JSONException{ + this.name = json.getString("name"); + this.aboutThis = json.getString("aboutThis"); + this.alias = json.getString("alias"); + this.version = json.getInt("version"); + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getAboutThis() { + return aboutThis; + } + public void setAboutThis(String aboutThis) { + this.aboutThis = aboutThis; + } + public Integer getVersion() { + return version; + } + public void setVersion(Integer version) { + this.version = version; + } + public String getAlias() { + return alias; + } + public void setAlias(String alias) { + this.alias = alias; + } + + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/dataverse/bo/Study.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/bo/Study.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,142 @@ +package de.mpiwg.gazetteer.dataverse.bo; + +import org.json.JSONException; +import org.json.JSONObject; + +public class Study { + + private Long id; + private String authority; + private String globalId; + private String persistentURL; + private String protocol; + private String studyId; + private String createTime; + private String title; + private String status; + private String creator; + + private Integer numberOfDownloads; + private Integer version; + + private Dataverse dataverse; + + public Study(JSONObject json) throws JSONException{ + + this.authority = json.getString("authority"); + this.globalId = json.getString("globalId"); + this.persistentURL = json.getString("persistentURL"); + this.protocol = json.getString("protocol"); + this.studyId = json.getString("studyId"); + this.createTime = json.getString("createTime"); + this.title = json.getJSONObject("metadata").getString("title"); + this.status = json.getString("status"); + + this.id = json.getLong("id"); + + this.numberOfDownloads = json.getInt("numberOfDownloads"); + this.version = json.getInt("version"); + + this.creator = json.getJSONObject("creator").getString("userName"); + + this.dataverse = new Dataverse(json.getJSONObject("owner")); + + } + + + public String getAuthority() { + return authority; + } + public void setAuthority(String authority) { + this.authority = authority; + } + public String getGlobalId() { + return globalId; + } + public void setGlobalId(String globalId) { + this.globalId = globalId; + } + public String getPersistentURL() { + return persistentURL; + } + public void setPersistentURL(String persistentURL) { + this.persistentURL = persistentURL; + } + public String getProtocol() { + return protocol; + } + public void setProtocol(String protocol) { + this.protocol = protocol; + } + public Integer getVersion() { + return version; + } + public void setVersion(Integer version) { + this.version = version; + } + public String getStudyId() { + return studyId; + } + public void setStudyId(String studyId) { + this.studyId = studyId; + } + public String getCreateTime() { + return createTime; + } + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + public Integer getNumberOfDownloads() { + return numberOfDownloads; + } + public void setNumberOfDownloads(Integer numberOfDownloads) { + this.numberOfDownloads = numberOfDownloads; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + public String getStatus() { + return status; + } + + + public void setStatus(String status) { + this.status = status; + } + + + public String getCreator() { + return creator; + } + + + public void setCreator(String creator) { + this.creator = creator; + } + + + public Dataverse getDataverse() { + return dataverse; + } + + + public void setDataverse(Dataverse dataverse) { + this.dataverse = dataverse; + } + + + + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/dataverse/bo/VDCUser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/dataverse/bo/VDCUser.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,117 @@ +package de.mpiwg.gazetteer.dataverse.bo; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.utils.JSONUtils; + +/** + * See: edu.harvard.iq.dvn.core.admin.VDCUser + * @author jurzua + * + */ +public class VDCUser { + + private String userName; + private String email; + private String firstName; + private String lastName; + private String institution; + private Long id; + private Long version; + private Long position; + + private String password; + public VDCUser(Long id, String userName, String password){ + this.id = id; + this.userName = userName; + this.password = password; + } + + public VDCUser(JSONObject json){ + + this.email = JSONUtils.getString(json, "email"); + this.firstName = JSONUtils.getString(json, "firstName"); + this.userName = JSONUtils.getString(json, "userName"); + this.lastName = JSONUtils.getString(json, "lastName"); + this.institution = JSONUtils.getString(json, "institution"); + + this.id = JSONUtils.getLong(json, "id"); + this.position = JSONUtils.getLong(json, "position"); + this.version = JSONUtils.getLong(json, "version"); + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getInstitution() { + return institution; + } + + public void setInstitution(String institution) { + this.institution = institution; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } + + public Long getPosition() { + return position; + } + + public void setPosition(Long position) { + this.position = position; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + +} + diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/db/DBBook.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBBook.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,188 @@ +package de.mpiwg.gazetteer.db; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class DBBook { + + private String id; + private String name; + private Integer line; + private String period; + // + private String author; + private String edition; + private String volume; + private String dynasty; + + private String level1; + private String level2; + private String admin_type; + private String in_jibengujiku; + + private Integer start_year; + private Integer end_year; + + + public DBBook(ResultSet rs) throws SQLException{ + this.name = rs.getString("name"); + this.id = rs.getString("id"); + this.line = rs.getInt("line"); + this.period = rs.getString("period"); + this.author = rs.getString("author"); + this.edition = rs.getString("edition"); + this.volume = rs.getString("volume"); + this.dynasty = rs.getString("dynasty"); + + this.level1 = rs.getString("level1"); + this.level2 = rs.getString("level2"); + this.admin_type = rs.getString("admin_type"); + this.in_jibengujiku = rs.getString("in_jibengujiku"); + + this.start_year = rs.getInt("start_year"); + this.end_year = rs.getInt("end_year"); + + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public Integer getLine() { + return line; + } + + + public void setLine(Integer line) { + this.line = line; + } + + + public String getPeriod() { + return period; + } + + + public void setPeriod(String period) { + this.period = period; + } + + + public String getAuthor() { + return author; + } + + + public void setAuthor(String author) { + this.author = author; + } + + + public String getEdition() { + return edition; + } + + + public void setEdition(String edition) { + this.edition = edition; + } + + + public String getVolume() { + return volume; + } + + + public void setVolume(String volume) { + this.volume = volume; + } + + + public String getDynasty() { + return dynasty; + } + + + public void setDynasty(String dynasty) { + this.dynasty = dynasty; + } + + + public String getLevel1() { + return level1; + } + + + public void setLevel1(String level1) { + this.level1 = level1; + } + + + public String getLevel2() { + return level2; + } + + + public void setLevel2(String level2) { + this.level2 = level2; + } + + + public String getAdmin_type() { + return admin_type; + } + + + public void setAdmin_type(String admin_type) { + this.admin_type = admin_type; + } + + + public String getIn_jibengujiku() { + return in_jibengujiku; + } + + + public void setIn_jibengujiku(String in_jibengujiku) { + this.in_jibengujiku = in_jibengujiku; + } + + + public Integer getStart_year() { + return start_year; + } + + + public void setStart_year(Integer start_year) { + this.start_year = start_year; + } + + + public Integer getEnd_year() { + return end_year; + } + + + public void setEnd_year(Integer end_year) { + this.end_year = end_year; + } + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/db/DBSection.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBSection.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,113 @@ +package de.mpiwg.gazetteer.db; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import de.mpiwg.gazetteer.bo.LGBranch; + +public class DBSection implements Comparable{ + + private Long id; + private String name; + private String text; + + private String bookId; + private DBBook book; + + private Integer start_page; + private Integer end_page; + + private List branches; + + /* + public DBSection(Long id){ + this.id = id; + } + + + public DBSection(Long id, String name, String bookId){ + this.id = id; + this.name = name; + this.bookId = bookId; + }*/ + + public DBSection(ResultSet rs) throws SQLException{ + this.name = rs.getString("name"); + this.id = rs.getLong("id"); + this.bookId = rs.getString("books_id"); + this.start_page = rs.getInt("start_page"); + this.end_page = rs.getInt("end_page"); + } + + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public String getBookId() { + return bookId; + } + + public void setBookId(String bookId) { + this.bookId = bookId; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public DBBook getBook() { + return book; + } + + public void setBook(DBBook book) { + this.book = book; + } + + public List getBranches() { + return branches; + } + + public void setBranches(List branches) { + this.branches = branches; + } + + public Integer getStart_page() { + return start_page; + } + + public void setStart_page(Integer start_page) { + this.start_page = start_page; + } + + public Integer getEnd_page() { + return end_page; + } + + public void setEnd_page(Integer end_page) { + this.end_page = end_page; + } + + public String getPages(){ + return this.start_page + " - " + this.end_page; + } + + @Override + public int compareTo(DBSection o) { + return this.getName().compareTo(o.getName()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/AbstractServletMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/AbstractServletMethod.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,104 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.Part; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONObject; + + +public abstract class AbstractServletMethod { + + private static Logger LOGGER = Logger.getLogger(AbstractServletMethod.class); + + + + protected static void writeError(HttpServletResponse response, String message){ + try { + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", message); + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected static Long getQueryLongParam(HttpServletRequest request, String paraName) { + String value = request.getParameter(paraName); + if (StringUtils.isNotEmpty(value)) { + try { + return Long.parseLong(value); + } catch (Exception e) { + } + } + return null; + } + + protected static Long getRequestLongPart(HttpServletRequest request, String partName) throws IOException, + IllegalStateException, ServletException { + + String value = getRequestPart(request, partName); + + try { + Long v = Long.parseLong(value); + return v; + } catch (Exception e) { + } + + return null; + + } + + protected static String getRequestPart(HttpServletRequest request, String partName) throws IOException, + IllegalStateException, ServletException { + + String partText = null; + final Part filePart = request.getPart(partName); + + if (filePart != null) { + OutputStream out = null; + InputStream filecontent = null; + + try { + out = new ByteArrayOutputStream(); + filecontent = filePart.getInputStream(); + + int read = 0; + final byte[] bytes = new byte[1024]; + + while ((read = filecontent.read(bytes)) != -1) { + out.write(bytes, 0, read); + } + + partText = out.toString(); + + } catch (FileNotFoundException fne) { + LOGGER.info("Problems during file upload. Error: " + fne.getMessage()); + } finally { + if (out != null) { + out.close(); + } + if (filecontent != null) { + filecontent.close(); + } + } + } + + return partText; + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/GetFileText.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetFileText.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,56 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.FileManager; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; + +public class GetFileText extends AbstractServletMethod { + + public static String name = "getFileText"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long fileId = getQueryLongParam(request, "fileId"); + + System.out.println("%%%%% GetFileText [fileId=" + fileId + "]"); + + if(fileId != null){ + LGFile file = DataProvider.getInstance().getFile(fileId); + if(file != null){ + + String text = FileManager.getFileAsText(file); + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain; charset=UTF-8"); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "File no found (" + fileId + ")"); + json.put("code", GazetteerException.CODE); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: fileId."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetSectionMetadata.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,89 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; + +public class GetSectionMetadata extends AbstractServletMethod { + + public static String name = "getSectionMetadata"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long sectionId = getQueryLongParam(request, "sectionId"); + + if(sectionId != null){ + DBSection section = DBService.getSectionWithContent(sectionId); + if(section != null){ + //DBBook book = DBService.getBookFromDB(section.getBookId()); + DBBook book = DBService.getInstance().getBook(section.getBookId()); + + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "ok"); + + + JSONObject sectionJson = new JSONObject(); + sectionJson.put("id", section.getId()); + sectionJson.put("name", section.getName()); + sectionJson.put("start_page", section.getStart_page()); + sectionJson.put("end_page", section.getEnd_page()); + + + JSONObject bookJson = new JSONObject(); + bookJson.put("id", book.getId()); + bookJson.put("name", book.getName()); + bookJson.put("author", book.getAuthor()); + bookJson.put("edition", book.getEdition()); + bookJson.put("line", book.getLine()); + bookJson.put("period", book.getPeriod()); + bookJson.put("volume", book.getVolume()); + + bookJson.put("level1", book.getLevel1()); + bookJson.put("level2", book.getLevel2()); + bookJson.put("admin_type", book.getAdmin_type()); + bookJson.put("in_jibengujiku", book.getIn_jibengujiku()); + + + bookJson.put("dynasty", book.getDynasty()); + bookJson.put("start_year", book.getStart_year()); + bookJson.put("end_year", book.getEnd_year()); + + + sectionJson.put("book", bookJson); + + + json.put("section", sectionJson); + + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Section no found (" + sectionId + ")"); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: sectionId."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/GetSectionText.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetSectionText.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,50 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.utils.DBService; + +public class GetSectionText extends AbstractServletMethod { + + public static String name = "getSectionText"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long sectionId = getQueryLongParam(request, "sectionId"); + + if(sectionId != null){ + String text = DBService.getSectionWithContent(sectionId).getText(); + if(StringUtils.isNotEmpty(text)){ + + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain; charset=UTF-8"); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Section no found (" + sectionId + ")"); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: sectionId."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/GetTable4File.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetTable4File.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,54 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.HTTPUtils; + +public class GetTable4File extends AbstractServletMethod { + public static String name = "getTable4File"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long fileId = getQueryLongParam(request, "fileId"); + + if(fileId != null){ + LGFile file = DataProvider.getInstance().getFile(fileId); + if(file != null){ + String text = HTTPUtils.getTableOfFile(fileId); + if(StringUtils.isNotEmpty(text)){ + + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain; charset=UTF-8"); + + } + } else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "File no found (" + fileId + ")"); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: fileId."); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/GetUser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetUser.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,45 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; + +public class GetUser extends AbstractServletMethod{ + + public static String name = "getUser"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + response.setContentType("application/json"); + Long userId = getQueryLongParam(request, "userId"); + + JSONObject json = new JSONObject(); + + if(userId != null){ + //TODO + /* + VDCUser user = DataProvider.getInstance().get + if(file != null){ + + String text = FileManager.getFile(file.getFileName()); + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain"); + + }else{ + json.put("status", "error"); + json.put("message", "User not found (" + userId + ")"); + }*/ + }else{ + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: userId."); + } + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/SaveNewText.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/SaveNewText.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,65 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.JSONUtils; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; + +public class SaveNewText extends AbstractServletMethod{ + + public static String name = "saveNew"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + + System.out.println("%%%%% SaveNewText"); + + if (ServletFileUpload.isMultipartContent(request)) { + String text = getRequestPart(request, "text"); + Long userId = getRequestLongPart(request, "userId"); + Long sectionId = getRequestLongPart(request, "sectionId"); + String label = getRequestPart(request, "label"); + + if(StringUtils.isNotEmpty(text) && userId != null && sectionId != null){ + Long branchId = DataProvider.getInstance().saveNewFile(text, label, sectionId, userId); + LGBranch branch = DataProvider.getInstance().getBranch(branchId); + LGFile file = DataProvider.getInstance().getFile(branch.getCurrentLastFileId()); + + JSONObject jsonBranch = JSONUtils.branch2JSON(branch); + JSONObject jsonFile = JSONUtils.file2JSON(file, true); + + json.put("branch", jsonBranch); + json.put("file", jsonFile); + json.put("status", "ok"); + + }else{ + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: text, userId, sectionId."); + json.put("code", GazetteerException.CODE); + } + + } else { + json.put("status", "error"); + json.put("message", "Content-type wrong. It should be: multipart/form-data"); + json.put("code", GazetteerException.CODE); + } + + + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/SaveText.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/SaveText.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,83 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.JSONUtils; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; +import de.mpiwg.gazetteer.utils.exceptions.VersioningException; + +public class SaveText extends AbstractServletMethod{ + + public static String name = "save"; + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + + if (ServletFileUpload.isMultipartContent(request)) { + String text = getRequestPart(request, "text"); + ;//getRequestPart(request, "text"); + Long userId = getRequestLongPart(request, "userId"); + Long branchId = getRequestLongPart(request, "branchId"); + Long userPreviousFileId = getRequestLongPart(request, "userPreviousFileId"); + + System.out.println("%%%%% SaveText [branchId=" + branchId + ", userId=" + userId + "]"); + + if(StringUtils.isNotEmpty(text) && userId != null && branchId != null && userPreviousFileId != null){ + //text = new String(text.getBytes("iso-8859-1"), "UTF-8"); + try { + LGFile file = DataProvider.getInstance().saveFile(branchId, text, userId, userPreviousFileId); + LGBranch branch = DataProvider.getInstance().getBranch(file.getBranchId()); + + JSONObject jsonBranch = JSONUtils.branch2JSON(branch); + JSONObject jsonFile = JSONUtils.file2JSON(file, true); + + json.put("branch", jsonBranch); + json.put("file", jsonFile); + json.put("status", "ok"); + } catch (GazetteerException e){ + json.put("status", "error"); + json.put("message", e.getMessage()); + json.put("code", e.getCode()); + if(e instanceof VersioningException){ + + JSONObject curentFile = JSONUtils.file2JSON(((VersioningException) e).getCurrentFile(), false); + JSONObject userFile = JSONUtils.file2JSON(((VersioningException) e).getUserFile(), false); + + json.put("currentFile", curentFile); + json.put("userFile", userFile); + } + } catch (Exception e) { + e.printStackTrace(); + json.put("status", "error"); + json.put("message", e.getMessage()); + json.put("code", GazetteerException.CODE); + } + + + }else{ + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: text, userId, branchId, userPreviousFileId."); + } + + } else { + json.put("status", "error"); + json.put("message", "Content-type wrong. It should be: multipart/form-data"); + } + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/TextServlet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/TextServlet.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,90 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONObject; + +@WebServlet("/rest/text/*") +@MultipartConfig +public class TextServlet extends HttpServlet { + + private static final long serialVersionUID = -8809504256505388787L; + + private final static Logger LOGGER = Logger.getLogger(TextServlet.class.getCanonicalName()); + + @Override + public void init() throws ServletException { + + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + processRequest(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + processRequest(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { + + String method = getLastPathComponent(request); + request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); + + if(StringUtils.equals(SaveNewText.name, method)){ + SaveNewText.execute(request, response); + }else if(StringUtils.equals(SaveText.name, method)){ + SaveText.execute(request, response); + }else if(StringUtils.equals(GetFileText.name, method)){ + GetFileText.execute(request, response); + }else if(StringUtils.equals(GetUser.name, method)){ + GetUser.execute(request, response); + }else if(StringUtils.equals(GetSectionText.name, method)){ + GetSectionText.execute(request, response); + }else if(StringUtils.equals(GetSectionMetadata.name, method)){ + GetSectionMetadata.execute(request, response); + }else if(StringUtils.equals(GetTable4File.name, method)){ + GetTable4File.execute(request, response); + }else{ + writeError(response, "Content-type wrong. It should be: multipart/form-data"); + } + } + + private static void writeError(HttpServletResponse response, String message){ + try { + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", message); + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } catch (Exception e) { + LOGGER.error(e); + } + } + + public static String getLastPathComponent(HttpServletRequest request){ + String uri = request.getRequestURI(); + String[] array = uri.split("/"); + return array[array.length-1]; + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/rest/UtilsServlet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/UtilsServlet.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,111 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.annotation.MultipartConfig; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONObject; + +import de.mpiwg.web.jsp.SessionBean; +import de.mpiwg.web.jsp.utils.SessionCollectorListener; +import sun.reflect.ReflectionFactory.GetReflectionFactoryAction; + +@WebServlet("/rest/utils/*") +public class UtilsServlet extends HttpServlet { + + private static final long serialVersionUID = -8809504256505388787L; + + private final static Logger LOGGER = Logger.getLogger(UtilsServlet.class.getCanonicalName()); + + private final static int MINS_30 = 60 * 30; + + @Override + public void init() throws ServletException { + + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + processRequest(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + processRequest(request, response); + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { + + String method = TextServlet.getLastPathComponent(request); + request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); + + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + //System.out.println("Own Session: " + request.getSession().getId()); + + if(StringUtils.equals(method, "getUser")){ + String sessionId = getString(request, "sessionId"); + ServletContext context = request.getSession().getServletContext(); + + Map sessionCollector = (Map) context.getAttribute(SessionCollectorListener.SESSION_COLLECTOR); + + if(sessionCollector.get(sessionId) != null){ + HttpSession session = sessionCollector.get(sessionId); + session.setMaxInactiveInterval(MINS_30); + SessionBean sessionBean = (SessionBean)session.getAttribute("sessionBean"); + + json.put("status", "ok"); + json.put("sessionId", sessionId); + json.put("userName", sessionBean.getUserName()); + + }else{ + json.put("status", "error"); + json.put("message", "The session has not been found."); + json.put("sessionId", sessionId); + } + } + + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + + } + + public static Long getLong(HttpServletRequest request, String name){ + Long value = null; + try{ + String s = request.getParameter(name); + value = new Long(s); + }catch (Exception e) { + } + return value; + } + + public static String getString(HttpServletRequest request, String name){ + String value = null; + try{ + value = request.getParameter(name); + }catch (Exception e) { + } + return value; + } +} \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/scripts/SectionsIndex.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/scripts/SectionsIndex.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,360 @@ +package de.mpiwg.gazetteer.scripts; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Map; + + + +/** + * + * mvn exec:java -Dexec.mainClass="de.mpiwg.gazetteer.scripts.SectionsIndex" -Dexec.args="Gazetteer root admin" + * + * @author jurzua + * + */ +public class SectionsIndex { + + private static String TABLE_NAME = "sections_index"; + + private static String DROP_TABLE = + "DROP TABLE IF EXISTS `"+ TABLE_NAME +"`;"; + + private static String CREATE_TABLE = + "CREATE TABLE `" + TABLE_NAME + "` (`id` int(10) NOT NULL AUTO_INCREMENT, " + + "`name` varchar(255) NOT NULL, " + + "`books_id` varchar(5) NOT NULL, " + + "`section_after` varchar(255) NOT NULL, " + + "`start_page` int(5) NOT NULL, `end_page` int(5) NOT NULL, " + + "`level` int(5) NOT NULL, " + + "`split_from` int(10) DEFAULT NULL, PRIMARY KEY (`id`) ) " + + "ENGINE=MyISAM DEFAULT CHARSET=utf8;"; + + private static String SELECT_SECTIONS = + "SELECT * FROM sections"; + + private static String SECTIONS_COUNT = + "SELECT count(*) FROM sections"; + + private static String SELECT_SECTIONS_VERSIONS = + "SELECT * from sections_versions"; + + + private static void execute(String dbName, String dbUser, String dbPwd){ + + Connection conn = null; + + + try { + //Class.forName("com.mysql.jdbc.Driver").newInstance(); + String dbURL = "jdbc:mysql://localhost/"+ dbName +"?characterEncoding=UTF-8"; + conn = DriverManager.getConnection(dbURL, dbUser, dbPwd); + + createTable(conn); + copyFromSectionsTable(conn); + replaceFromSectionsRevisions(conn); + + } catch (Exception e) { + e.printStackTrace(); + }finally{ + try { + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + private static void replaceFromSectionsRevisions(Connection conn){ + Statement stmt = null; + ResultSet rs = null; + try { + + stmt = conn.createStatement(); + rs = stmt.executeQuery(SELECT_SECTIONS_VERSIONS); + + Map mapVersions = new HashMap(); + + while(rs.next()){ + SectionVersion version = new SectionVersion(rs); + if(!mapVersions.containsKey(version.books_id)){ + mapVersions.put(version.books_id, version); + }else if(version.version > mapVersions.get(version.books_id).version){ + mapVersions.put(version.books_id, version); + } + } + + for(SectionVersion sectionVersion : mapVersions.values()){ + + String query = "SELECT * FROM sections_revisions WHERE " + + "books_id = '"+ sectionVersion.books_id +"' AND " + + "versions_id = " + sectionVersion.id + " AND " + + "deleted = 0"; + stmt = conn.createStatement(); + rs = stmt.executeQuery(query); + + while(rs.next()){ + Section section = new Section(rs, false); + + if(section.deleted == 0){ + if(section.id == -1){ + + PreparedStatement stmt0 = section.getInsertStatementWithoutId(conn); + stmt0.executeUpdate(); + ResultSet rs0 = stmt0.getGeneratedKeys(); + rs0.next(); + int newSectionId = rs0.getInt(1); + + //Updating sections_revisions (from -1 to new id) + String sqlUpdateRevision = "UPDATE sections_revisions SET sections_id = ? WHERE id = ?"; + PreparedStatement stmt1 = conn.prepareStatement(sqlUpdateRevision); + stmt1.setInt(1, newSectionId); + stmt1.setInt(2, section.sectionsRevisionsId); + int rowsUpdated = stmt1.executeUpdate(); + + System.out.println("Changing revision section with id: " + section.sectionsRevisionsId + " from -1 to " + newSectionId + ". Rows updated: " + rowsUpdated); + //System.out.print("#"); + }else{ + PreparedStatement stm = section.getUpdateStatement(conn); + stm.execute(); + } + } + } + } + + System.out.println(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void copyFromSectionsTable(Connection conn){ + Statement stmt = null; + ResultSet rs = null; + try { + /* + stmt = conn.createStatement(); + rs = stmt.executeQuery(SECTIONS_COUNT); + rs.next(); + int count = rs.getInt(1); + */ + stmt = conn.createStatement(); + rs = stmt.executeQuery(SELECT_SECTIONS); + + int index = 0; + while(rs.next()){ + Section section = new Section(rs, true); + + //stmt = conn.createStatement(); + //stmt.executeUpdate(section.getInsertStatement()); + PreparedStatement stm = section.getInsertStatementWithId(conn); + stm.execute(); + + if(index % 100 == 0){ + System.out.print("*"); + } + index++; + } + System.out.println(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + private static void createTable(Connection conn){ + Statement stmt = null; + + try { + stmt = conn.createStatement(); + int rows = stmt.executeUpdate(DROP_TABLE); + System.out.println("DROP table: " + rows); + + } catch (Exception e) { + System.err.println("\n" + DROP_TABLE); + e.printStackTrace(); + } + + try { + stmt = conn.createStatement(); + int rows = stmt.executeUpdate(CREATE_TABLE); + System.out.println("CREATE table: " + rows); + } catch (Exception e) { + System.err.println("\n" + CREATE_TABLE); + e.printStackTrace(); + } + } + + + private static void printSetting(){ + + int mb = 1024*1024; + + //Getting the runtime reference from system + Runtime runtime = Runtime.getRuntime(); + + System.out.println("##### Heap utilization statistics [MB] #####"); + + //Print used memory + System.out.println("Used Memory:" + + (runtime.totalMemory() - runtime.freeMemory()) / mb); + + //Print free memory + System.out.println("Free Memory:" + + runtime.freeMemory() / mb); + + //Print total available memory + System.out.println("Total Memory:" + runtime.totalMemory() / mb); + + //Print Maximum available memory + System.out.println("Max Memory:" + runtime.maxMemory() / mb); + } + + public static void main(String[] args){ + + printSetting(); + + String dbName = args[0]; + String dbUser = args[1]; + String dbPwd = args[2]; + + SectionsIndex.execute(dbName, dbUser, dbPwd); + + System.exit(0); + } + //table: sections_revisions + private static class SectionVersion{ + + private int id; + private int version; + private String editor; + private String books_id; + + public SectionVersion(ResultSet rs) throws SQLException{ + this.id = rs.getInt("id"); + this.version = rs.getInt("version"); + this.editor = rs.getString("editor"); + this.books_id = rs.getString("books_id"); + } + + public int getVersion(){ + return this.version; + } + } + + private static class Section{ + private int id; + private String name; + private String books_id; + private String section_after; + private int start_page; + private int end_page; + private int level; + private int split_from; + //private int sections_id; + + //tables for the revisions_sections + private int sectionsRevisionsId; + private int deleted; + + public Section(ResultSet rs, boolean isSectionTable) throws SQLException{ + + this.name = rs.getString("name"); + this.books_id = rs.getString("books_id"); + this.section_after = rs.getString("section_after"); + this.start_page = rs.getInt("start_page"); + this.end_page = rs.getInt("end_page"); + this.level = rs.getInt("level"); + this.split_from = rs.getInt("split_from"); + if(isSectionTable){ + this.id = rs.getInt("id"); + }else{ + this.id = rs.getInt("sections_id"); + this.sectionsRevisionsId = rs.getInt("id"); + this.deleted = rs.getInt("deleted"); + } + } + + public PreparedStatement getInsertStatementWithId(Connection conn) throws SQLException{ + + String sql = "INSERT INTO " + TABLE_NAME + " " + + "(id, name, books_id, section_after, start_page, end_page, level, split_from) VALUES" + + "(?,?,?,?,?,?,?,?)"; + PreparedStatement stm = conn.prepareStatement(sql); + + stm.setInt(1, id); + stm.setString(2, name); + stm.setString(3, books_id); + stm.setString(4, section_after); + stm.setInt(5, start_page); + stm.setInt(6, end_page); + stm.setInt(7, level); + stm.setInt(8, split_from); + + return stm; + } + + public PreparedStatement getInsertStatementWithoutId(Connection conn) throws SQLException{ + + String sql = "INSERT INTO " + TABLE_NAME + " " + + "(name, books_id, section_after, start_page, end_page, level, split_from) VALUES" + + "(?,?,?,?,?,?,?)"; + PreparedStatement stm = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + + stm.setString(1, name); + stm.setString(2, books_id); + stm.setString(3, section_after); + stm.setInt(4, start_page); + stm.setInt(5, end_page); + stm.setInt(6, level); + stm.setInt(7, split_from); + + return stm; + } + + public PreparedStatement getUpdateStatement(Connection conn) throws SQLException{ + String s = "UPDATE " + TABLE_NAME + " " + + "SET id = ?, name = ?, books_id = ?, section_after = ?, start_page = ?, end_page = ?, level = ?, split_from = ? " + + "WHERE id = ?"; + PreparedStatement stm = conn.prepareStatement(s); + + stm.setInt(1, id); + stm.setString(2, name); + stm.setString(3, books_id); + stm.setString(4, section_after); + stm.setInt(5, start_page); + stm.setInt(6, end_page); + stm.setInt(7, level); + stm.setInt(8, split_from); + stm.setInt(9, id); + + return stm; + } + /* + public String getUpdateStatement(){ + + String statement = "UPDATE " + TABLE_NAME + " "; + statement += "WHERE id = " + sections_id + " "; + //statement += " (id, name, books_id, section_after, start_page, end_page, level, split_from) "; + statement += " VALUES (" + + sections_id + ", '" + + name + "', '"+ + books_id +"', '"+ + section_after+"', "+ + start_page +", " + + end_page + ", "+ + level +", " + + split_from + ")"; + + return statement; + }*/ + + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/AbstractDataProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/AbstractDataProvider.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,50 @@ +package de.mpiwg.gazetteer.utils; + +import java.util.List; + +import cl.maps.duplex.DuplexMap; +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.SearchRulesFile; + +public class AbstractDataProvider { + + + //############################### + + private DuplexMap branchMap = null; + + protected DuplexMap getBranchMap(){ + if(branchMap == null){ + loadBranches(); + } + return branchMap; + } + + public void loadBranches(){ + List list = DBService.getAllLGBranchFromDB(); + this.branchMap = new DuplexMap(); + for(LGBranch item : list){ + this.branchMap.put(item.getKey(), item); + } + } + + + private DuplexMap fileMap = null; + + protected DuplexMap getFileMap(){ + if(fileMap == null){ + loadFiles(); + } + return fileMap; + } + + + private void loadFiles(){ + List list = DBService.getAllLGFileFromDB(); + this.fileMap = new DuplexMap(); + for(LGFile file : list){ + this.fileMap.put(file.getKey(), file); + } + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/DBService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,538 @@ + package de.mpiwg.gazetteer.utils; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.hibernate.Query; +import org.hibernate.Session; + +import de.mpiwg.gazetteer.bo.DBEntry; +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.SearchRulesFile; +import de.mpiwg.gazetteer.bo.Sequence; +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBSection; + +public class DBService { + + private static Logger logger = Logger.getLogger(DBService.class); + + // JDBC driver name and database URL + static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; + static final String DB_URL = "jdbc:mysql://localhost/"; + + private static String SECTIONS_TABLE = "sections_index"; + + private static DBService instance = null; + + public static DBService getInstance(){ + if(instance == null){ + instance = new DBService(); + } + return instance; + } + + private Map bookMap; + private List dynastyList; + + public List getDynastyList() throws SQLException{ + if(this.dynastyList == null){ + this.loadDynastyList(); + } + return dynastyList; + } + + private void loadDynastyList() throws SQLException{ + Long start = System.currentTimeMillis(); + Connection conn = null; + Statement stmt = null; + this.dynastyList = new ArrayList(); + + try { + String query = "SELECT DISTINCT dynasty FROM books"; + logger.debug(query); + conn = getNewConnection(); + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + + while(rs.next()){ + this.dynastyList.add(rs.getString("dynasty")); + } + } catch (Exception e) { + e.printStackTrace(); + }finally{ + conn.close(); + } + + long end = System.currentTimeMillis(); + logger.debug("Time execution loading Book Map [ms]: " + (end - start)); + } + + public DBBook getBook(String id){ + return getBookMap().get(id); + } + + private Map getBookMap(){ + if(bookMap == null){ + try { + this.loadBookMap(); + } catch (Exception e) { + e.printStackTrace(); + } + } + return this.bookMap; + } + + private void loadBookMap() throws SQLException{ + Long start = System.currentTimeMillis(); + Connection conn = null; + Statement stmt = null; + this.bookMap = new HashMap(); + + try { + String query = "SELECT * FROM books"; + logger.debug(query); + conn = getNewConnection(); + stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + + while(rs.next()){ + DBBook book = new DBBook(rs); + this.bookMap.put(book.getId(), book); + } + } catch (Exception e) { + e.printStackTrace(); + }finally{ + conn.close(); + } + + long end = System.currentTimeMillis(); + logger.debug("Time execution loading Book Map [ms]: " + (end - start)); + } + + public static List searchBook(List termList, String field) throws SQLException{ + Long start = System.currentTimeMillis(); + + List list = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + + //TODO this query should join the section table + String query = "SELECT * FROM books WHERE "; + for(int i=0; i0){ + query += " OR "; + } + query += field + " like '%" + term + "%' "; + } + + try { + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + DBBook book = new DBBook(rs); + + String sql = "SELECT * FROM "+ SECTIONS_TABLE +" WHERE " + "books_id = '" + book.getId() + "'"; + logger.debug(sql); + stmt = conn.createStatement(); + ResultSet rs0 = stmt.executeQuery(sql); + while(rs0.next()){ + DBSection section = new DBSection(rs0); + section.setBook(book); + list.add(section); + } + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + + long end = System.currentTimeMillis(); + logger.debug("Time execution serching Books [ms]: " + (end - start)); + + return list; + } + + /** + * This methods search from a list of terms. + * Every term is considered a subsequence of whole section name. + * + * @param termList + * @return + * @throws SQLException + */ + public static List searchSection(List termList) throws SQLException{ + + Long start = System.currentTimeMillis(); + + List list = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + + String query = "SELECT * FROM "+ SECTIONS_TABLE +" WHERE "; + for(int i=0; i0){ + query += " OR "; + } + query += "name like '%" + term + "%' "; + } + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + DBSection section = new DBSection(rs); + DBBook book = getInstance().getBook(section.getBookId()); + section.setBook(book); + list.add(section); + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + + long end = System.currentTimeMillis(); + logger.debug("Time execution serching Sections [ms]: " + (end - start)); + + return list; + } + + public static List suggestBookName(String term, int limit) throws SQLException{ + List list = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + + String query = "SELECT name FROM books WHERE name like '" + term + "%' limit " + limit; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + String name = rs.getString("name"); + if(!list.contains(name)){ + list.add(name); + } + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + return list; + } + + public static List suggestSectionName(String term, int limit) throws SQLException { + List list = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + + String query = "SELECT name FROM "+SECTIONS_TABLE+" WHERE name like '" + term + "%' limit " + limit; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + String name = rs.getString("name"); + if(!list.contains(name)){ + list.add(name); + } + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + return list; + } + + + public static List suggestSectionId(String input, int limit) throws SQLException { + List list = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + + String query = "SELECT id FROM "+SECTIONS_TABLE+" WHERE id like '" + input + "%' limit " + limit; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + + String id = rs.getString("id"); + list.add(id); + + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + + + + return list; + } + + public static DBSection getSectionWithContent(Long sectionId) throws SQLException { + + Connection conn = null; + Statement stmt = null; + DBSection section = null; + + String query = "SELECT * FROM "+SECTIONS_TABLE+" WHERE id = '" + sectionId + "'"; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + while (rs.next()) { + + section = new DBSection(rs); + /* + String bookId = rs.getString("books_id"); + int startPage = rs.getInt("start_page"); + int endPage = rs.getInt("end_page"); + String sectionName = rs.getString("name"); + + response.setBookId(bookId); + response.setName(sectionName); + */ + //System.out.println("bookId=" + bookId + ", startPage=" + startPage + ", endPage=" + endPage); + //String content = getContent(conn, bookId, startPage, endPage); + String content = getContent(conn, section); + section.setText(content); + + //DBBook book = getBook0FromDB(conn, bookId); + DBBook book = DBService.getInstance().getBook(section.getBookId()); + section.setBook(book); + + } + rs.close(); + } catch (Exception e) { + } finally { + conn.close(); + } + return section; + } + + public static String fixToNewline(String orig){ + char[] chars = orig.toCharArray(); + StringBuilder sb = new StringBuilder(100); + for(char c : chars){ + switch(c){ + case '\r': + case '\f': + break; + case '\n': + sb.append("
"); + break; + default: + sb.append(c); + } + } + return sb.toString(); + } + + //"SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d + //private static String getContent(Connection conn, String bookId, Integer startLine, Integer endLine) throws Exception{ + private static String getContent(Connection conn, DBSection section) throws Exception{ + String query = "SELECT content, line FROM contents WHERE books_id = '" + section.getBookId() + "' AND line >= '" + section.getStart_page() + "' AND line <= '" + section.getEnd_page() + "'"; + + logger.debug(query); + + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + + StringBuilder sb = new StringBuilder(); + while(rs.next()){ + String line = rs.getString("line"); + String content = rs.getString("content"); + sb.append("【" + line + "】" + content + "\n"); + } + + return sb.toString(); + } + + /* + public static DBBook getBookFromDB(String id) throws SQLException{ + Connection conn = null; + DBBook book = null; + + try { + //Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + book = getBook0FromDB(conn, id); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + return book; + }*/ + /* + private static DBBook getBook0FromDB(Connection conn, String id) throws SQLException{ + DBBook book = null; + + String query = "SELECT * FROM books WHERE id = '" + id + "'"; + logger.debug(query); + + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery(query); + + if(rs.next()){ + book = new DBBook(rs); + } + + return book; + }*/ + + /** + * This method removed all files for a particular fileId. + * The elimination includes the current version as well as the old versions. + * @param fileId + * @return + */ + protected static int deleteBranchFromDB(Long branchId){ + logger.info("Deleting Branch by branchId=" + branchId); + + int modifiedFiles; + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + Query query = session.createQuery("delete LGBranch where id = :id"); + query.setLong("id", branchId); + modifiedFiles = query.executeUpdate(); + + Query query0 = session.createQuery("delete LGFile where branchId = :branchId"); + query0.setLong("branchId", branchId); + modifiedFiles += query0.executeUpdate(); + + session.getTransaction().commit(); + + return modifiedFiles; + } + + protected static int deleteFileFromDB(Long fileId){ + + int modifiedFiles; + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + + Query query0 = session.createQuery("delete LGFile where id = :fileId"); + query0.setLong("fileId", fileId); + modifiedFiles = query0.executeUpdate(); + + session.getTransaction().commit(); + + return modifiedFiles; + + } + + protected static List getAllLGFileFromDB(){ + List list = null; + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + Query query = session.createQuery("from LGFile"); + list = query.list(); + session.getTransaction().commit(); + + return list; + } + + protected static List getCurrentLGFilesFromDB(){ + List list = null; + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + Query query = session.createQuery("from LGFile where lastVersion = :lastVersion"); + query.setBoolean("lastVersion", true); + list = query.list(); + session.getTransaction().commit(); + + return list; + } + + protected static List getAllLGBranchFromDB(){ + List list = null; + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + Query query = session.createQuery("from LGBranch"); + list = query.list(); + session.getTransaction().commit(); + + return list; + } + + protected static void saveDBEntry(DBEntry entry, Date date){ + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + saveDBEntry0(session, entry, date); + + session.getTransaction().commit(); + } + + public static void saveDBEntry0(Session session, DBEntry entry, Date date){ + entry.setLastChangeDate(date); + if (entry.isPersistent()) { + session.update(entry); + } else { + entry.setCreationDate(date); + session.save(entry); + } + logger.info("saveDBEntry: " + entry.toString()); + } + + public static Connection getNewConnection() throws SQLException, IOException{ + return DriverManager.getConnection( + DB_URL + PropertiesUtils.getPropValue("db_gazetter_name") + "?useUnicode=yes&characterEncoding=UTF-8", + PropertiesUtils.getPropValue("db_gazetter_username"), + PropertiesUtils.getPropValue("db_gazetter_password")); + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,246 @@ +package de.mpiwg.gazetteer.utils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import org.apache.log4j.Logger; +import org.hibernate.Session; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.utils.exceptions.NoAuthorizedException; +import de.mpiwg.gazetteer.utils.exceptions.VersioningException; + +public class DataProvider extends AbstractDataProvider{ + + private static Logger logger = Logger.getLogger(DBService.class); + private static DataProvider instance; + + public static DataProvider getInstance(){ + if(instance == null) + instance = new DataProvider(); + return instance; + } + + public DataProvider(){ + logger.info("##### Starting DataProvider #####"); + } + + public LGFile getFile(Long fileId){ + return getFileMap().getValuesByOwnKey(fileId); + } + + public List getAllFiles(Long branchId){ + List list = getFileMap().getValuesByAKey(branchId); + Collections.sort(list); + Collections.reverse(list); + return list; + } + + public List getBranches(Long userId){ + List list = new ArrayList(); + for(LGBranch branch : getBranchMap().values()){ + if(branch.hasContributor(userId)){ + list.add(branch); + } + } + return list; + } + + public LGBranch getBranch(Long branchId){ + return getBranchMap().getValuesByOwnKey(branchId); + } + + public void deleteFile(LGFile file) throws Exception{ + + LGBranch branch = getBranch(file.getBranchId()); + + if(branch == null){ + throw new Exception("There is any Branch for " + file); + } + + List files = getAllFiles(file.getBranchId()); + + if(files.size() == 1){ + throw new Exception("This file could not be deleted, because it is part of a branch that has only one file. A Branch without files is a inconsistency."); + } + + // if the file is the last version of a branch, we must replace the current file with the penultimate file. + if(branch.getCurrentLastFileId().equals(file.getId())){ + LGFile penultimateFile = getPenultimateFile(files); + + penultimateFile.setLastVersion(true); + branch.setCurrentLastFileId(penultimateFile.getId()); + + this.updateBranch(branch); + this.updateFile(penultimateFile); + + } + + //deleting file from DB and cache + int modifiedFiles = DBService.deleteFileFromDB(file.getId()); + getFileMap().remove(file.getKey()); + + logger.info(modifiedFiles + " items deleted by removing file " + file); + } + + private LGFile getPenultimateFile(List files){ + LGFile penultimateFile = null; + LGFile lastFile = null; + + for(LGFile file : files){ + if(lastFile == null){ + lastFile = file; + }else if(penultimateFile == null){ + lastFile = (lastFile.getVersion() > file.getVersion()) ? lastFile : file; + penultimateFile = (lastFile.getVersion() < file.getVersion()) ? lastFile : file; + }else{ + if(file.getVersion() > lastFile.getVersion()){ + penultimateFile = lastFile; + lastFile = file; + }else if(file.getVersion() > penultimateFile.getVersion()){ + penultimateFile = file; + } + } + } + + return penultimateFile; + } + + public void deleteBranch(LGBranch branch){ + + int modifiedFiles = DBService.deleteBranchFromDB(branch.getId()); + List fileToDelete = getFileMap().getValuesByAKey(branch.getId()); + + for(LGFile file : new ArrayList(fileToDelete)){ + getFileMap().remove(file.getKey()); + } + getBranchMap().remove(branch.getKey()); + + logger.info(modifiedFiles + " items deleted by removing branch " + branch.toString()); + } + + public void updateFile(LGFile file) throws Exception{ + if(!file.isPersistent()){ + throw new Exception("Trying to update a file that it is not persistent!"); + } + + Date date = new Date(); + DBService.saveDBEntry(file, date); + this.getFileMap().put(file.getKey(), file); + } + + public void updateBranch(LGBranch branch) throws Exception{ + if(!branch.isPersistent()){ + throw new Exception("Trying to update a branch that it is not persistent!"); + } + + Date date = new Date(); + DBService.saveDBEntry(branch, date); + this.getBranchMap().put(branch.getKey(), branch); + } + + public LGFile saveFile(Long branchId, String text, Long userId, Long userPreviousFileId) throws Exception{ + + + + Date date = new Date(); + + LGBranch branch = getBranchMap().getValuesByOwnKey(branchId); + + if(!branch.hasContributor(userId)){ + throw new NoAuthorizedException(userId, branchId); + } + + if(!branch.getCurrentLastFileId().equals(userPreviousFileId)){ + LGFile userPreviousFile = getFileMap().getValuesByOwnKey(userPreviousFileId); + LGFile currentLastFile = getFileMap().getValuesByOwnKey(branch.getCurrentLastFileId()); + + throw new VersioningException(userPreviousFile, currentLastFile); + } + + LGFile previousFile = getFileMap().getValuesByOwnKey(branch.getCurrentLastFileId()); + + LGFile file = new LGFile(); + file.setBranchId(branchId); + file.setVersion(previousFile.getVersion() + 1); + file.setUserId(userId); + file.setContent(text); + + //Saving into DB + //################################## + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + + file.setBranchId(branch.getId()); + DBService.saveDBEntry0(session, file, date); + + previousFile.setLastVersion(false); + DBService.saveDBEntry0(session, previousFile, date); + + branch.setCurrentLastFileId(file.getId()); + DBService.saveDBEntry0(session, branch, date); + + //Saving physical file in the operating system + String fileName = FileManager.saveFile(branch, file, date, userId); + file.setFileName(fileName); + DBService.saveDBEntry0(session, file, date); + + session.getTransaction().commit(); + //################################## + + + //Saving into Cache + getBranchMap().put(branch.getKey(), branch); + getFileMap().put(file.getKey(), file); + getFileMap().put(previousFile.getKey(), previousFile); + + return file; + } + + public Long saveNewFile(String text, String label, Long sectionId, Long userId) throws Exception{ + + Date date = new Date(); + + LGBranch branch = new LGBranch(); + branch.setSectionId(sectionId); + branch.setUserId(userId); + branch.setLabel(label); + branch.addContributor(userId); + branch.loadTransientData(); + + LGFile file = new LGFile(); + file.setUserId(userId); + file.setContent(text); + + //Saving into DB + //################################## + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + DBService.saveDBEntry0(session, branch, date); + file.setBranchId(branch.getId()); + + DBService.saveDBEntry0(session, file, date); + branch.setCurrentLastFileId(file.getId()); + + //Saving physical file in the operating system + String fileName = FileManager.saveFile(branch, file, date, userId); + file.setFileName(fileName); + DBService.saveDBEntry0(session, file, date); + + session.getTransaction().commit(); + //################################## + + + //Saving into Cache + getBranchMap().put(branch.getKey(), branch); + getFileMap().put(file.getKey(), file); + + return branch.getId(); + + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/FileManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,87 @@ +package de.mpiwg.gazetteer.utils; + +import java.io.File; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; + +public class FileManager { + + private static Logger logger = Logger.getLogger(FileManager.class); + + private static DateFormat dfmt = new SimpleDateFormat( "yyyy.MM.dd_hh.mm.ss.SSS" ); + + + + private static String getRootPath() throws Exception{ + String base = PropertiesUtils.getPropValue("files_root"); + + if(StringUtils.isEmpty(base)){ + throw new Exception("Property files_root no found. The files can be stored without this property."); + } + + if(!base.endsWith("/")){ + base += "/"; + } + + logger.info("files_root=" + base); + + return base; + } + + public static String saveFile(LGBranch branch, LGFile file, Date date, Long userId) throws Exception{ + + String absolutePath = getRootPath() + branch.getSectionId() + "/"; + String fileName = + branch.getSectionId() + "_" + + branch.getId() + "_" + + file.getId() + "_" + + dfmt.format(date) + "_" + + userId + + ".txt"; + + File folder = new File(absolutePath); + folder.mkdirs(); + + logger.info("Trying to save file " + absolutePath + fileName + "."); + + PrintWriter out = new PrintWriter(absolutePath + fileName); + out.println(file.getContent()); + out.close(); + + logger.info("The file " + fileName + " has been saved correctly."); + return fileName; + } + + public static String getFileAsText(LGFile file) throws Exception{ + + LGBranch branch = DataProvider.getInstance().getBranch(file.getBranchId()); + + String absolutePath = getRootPath() + branch.getSectionId() + "/" + file.getFileName(); + System.out.println("Loading: " + absolutePath); + byte[] encoded = Files.readAllBytes(Paths.get(absolutePath)); + return new String(encoded, "UTF8"); + } + + public static File getFileAsFile(LGFile file) throws Exception{ + + LGBranch branch = DataProvider.getInstance().getBranch(file.getBranchId()); + + String absolutePath = getRootPath() + branch.getSectionId() + "/" + file.getFileName(); + System.out.println("Loading: " + absolutePath); + return new File(absolutePath); + } + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/HTTPUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/HTTPUtils.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,178 @@ +package de.mpiwg.gazetteer.utils; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.StringReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; + +public class HTTPUtils { + + final static TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { + @Override + public void checkClientTrusted( final X509Certificate[] chain, final String authType ) { + } + @Override + public void checkServerTrusted( final X509Certificate[] chain, final String authType ) { + } + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + } }; + + + + /** + * This method returns a table that is generated by the extraction interface from a file id. + * + * @TODO: Currently, the extraction interface runs over HTTP, when it changes to HTTPS, this methods should be adapted to this. + * + * @param fileId + * @return + * @throws Exception some HTTP code different higher than 400 + */ + public static String getTableOfFile(Long fileId) throws Exception{ + + + String link = PropertiesUtils.getPropValue("extraction_interface") + "/Extractapp/ExportTable"; + + System.out.println(link); + + URL url = new URL(link); + HttpURLConnection httpConn = (HttpURLConnection)url.openConnection(); + + httpConn.setReadTimeout(10000); + httpConn.setConnectTimeout(15000); + httpConn.setRequestMethod("POST"); + httpConn.setDoInput(true); + httpConn.setDoOutput(true); + + //Send request + DataOutputStream wr = new DataOutputStream (httpConn.getOutputStream ()); + wr.writeBytes ("fileId=" + fileId); + wr.flush (); + wr.close (); + + BufferedReader in = null; + if (httpConn.getResponseCode() >= 400) { + in = new BufferedReader( + new InputStreamReader( + httpConn.getErrorStream())); + + String inputLine; + StringBuilder sb = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + sb.append(inputLine + "\n"); + + throw new Exception("HTTP Error, code " + httpConn.getResponseCode()); + + } else { + in = new BufferedReader( + new InputStreamReader( + httpConn.getInputStream())); + } + + String inputLine; + StringBuilder sb = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + sb.append(inputLine + "\n"); + in.close(); + + return sb.toString(); + } + + public static HttpStringResponse getStringResponse(String link) throws IOException, KeyManagementException, NoSuchAlgorithmException{ + if(link.startsWith("https") || link.startsWith("HTTPS")) + return getHttpSSLStringResponse(link); + return getHttpStringResponse(link); + } + + private static HttpStringResponse getHttpSSLStringResponse(String link) throws IOException, KeyManagementException, NoSuchAlgorithmException{ + + // Install the all-trusting trust manager + final SSLContext sslContext = SSLContext.getInstance( "SSL" ); + sslContext.init( null, trustAllCerts, new java.security.SecureRandom() ); + // Create an ssl socket factory with our all-trusting manager + final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); + + URL url = new URL(link); + HttpURLConnection httpConn = (HttpURLConnection)url.openConnection(); + + ( (HttpsURLConnection) httpConn ).setSSLSocketFactory( sslSocketFactory ); + + + BufferedReader in = null; + if (httpConn.getResponseCode() >= 400) { + in = new BufferedReader( + new InputStreamReader( + httpConn.getErrorStream())); + } else { + in = new BufferedReader( + new InputStreamReader( + httpConn.getInputStream())); + } + + String inputLine; + StringBuilder sb = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + sb.append(inputLine + "\n"); + in.close(); + + return new HttpStringResponse(httpConn.getResponseCode(), sb.toString()); + } + + private static HttpStringResponse getHttpStringResponse(String link) throws IOException{ + + //System.out.println(link); + + URL url = new URL(link); + HttpURLConnection httpConn = (HttpURLConnection)url.openConnection(); + + BufferedReader in = null; + if (httpConn.getResponseCode() >= 400) { + in = new BufferedReader( + new InputStreamReader( + httpConn.getErrorStream())); + } else { + in = new BufferedReader( + new InputStreamReader( + httpConn.getInputStream())); + } + + + String inputLine; + StringBuilder sb = new StringBuilder(); + while ((inputLine = in.readLine()) != null) + sb.append(inputLine + "\n"); + in.close(); + + return new HttpStringResponse(httpConn.getResponseCode(), sb.toString()); + } + + public static class HttpStringResponse{ + public int code; + public String content; + public HttpStringResponse(int code, String content){ + this.code = code; + this.content = content; + } + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/HibernateUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/HibernateUtil.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,31 @@ +package de.mpiwg.gazetteer.utils; + +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AnnotationConfiguration; + + +public class HibernateUtil { + + private static final SessionFactory sessionFactory; + + static { + try { + // Create the SessionFactory from hibernate.cfg.xml + AnnotationConfiguration cfg = new AnnotationConfiguration().configure("hibernate.cfg.xml"); + if(System.getProperty("hibernate.hbm2ddl.auto") != null && System.getProperty("hibernate.hbm2ddl.auto").equals("create")){ + cfg.setProperty("hibernate.hbm2ddl.auto", "create"); + } + sessionFactory = cfg.buildSessionFactory(); + } catch (Throwable ex) { + // Make sure you log the exception, as it might be swallowed + System.err.println("Initial SessionFactory creation failed." + ex); + ex.printStackTrace(); + throw new ExceptionInInitializerError(ex); + } + } + + public static SessionFactory getSessionFactory() { + return sessionFactory; + } + +} \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/JSONUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/JSONUtils.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,66 @@ +package de.mpiwg.gazetteer.utils; + +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; + +public class JSONUtils { + + public static String getString(JSONObject json, String label){ + try { + return (json.has(label)) ? json.getString(label) : null; + } catch (Exception e) {} + return null; + } + + public static Long getLong(JSONObject json, String label){ + try { + return (json.has(label)) ? json.getLong(label) : null; + } catch (Exception e) {} + return null; + } + + public static JSONObject branch2JSON(LGBranch branch){ + JSONObject json = new JSONObject(); + + try { + + json.put("id", branch.getId()); + json.put("label", branch.getLabel()); + json.put("sectionId", branch.getSectionId()); + json.put("currentLastFileId", branch.getCurrentLastFileId()); + json.put("creatorId", branch.getUserId()); + json.put("creationDate", branch.getFomattedCreation()); + json.put("info", branch.getInfo()); + + } catch (Exception e) { + e.printStackTrace(); + } + + return json; + } + + public static JSONObject file2JSON(LGFile file, boolean includeText){ + JSONObject json = new JSONObject(); + + try { + + json.put("id", file.getId()); + json.put("version", file.getVersion()); + json.put("fileName", file.getFileName()); + json.put("info", file.getInfo()); + json.put("creatorId", file.getUserId()); + json.put("creationDate", file.getFomattedCreation()); + + if(includeText){ + json.put("text", file.getContent()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return json; + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/PropertiesUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/PropertiesUtils.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,50 @@ +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); + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/SelectableObject.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/SelectableObject.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,43 @@ +package de.mpiwg.gazetteer.utils; + +import java.io.Serializable; + +public class SelectableObject implements Serializable{ + + private static final long serialVersionUID = 1L; + + private boolean selected; + private N obj; + private String label; + + public SelectableObject(N obj){ + this.obj = obj; + this.selected = false; + } + + public SelectableObject(N obj, String label){ + this.obj = obj; + this.selected = false; + this.label = label; + } + + public boolean isSelected() { + return selected; + } + public void setSelected(boolean selected) { + this.selected = selected; + } + public N getObj() { + return obj; + } + public void setObj(N obj) { + this.obj = obj; + } + public String getLabel() { + return label; + } + public void setLabel(String label) { + this.label = label; + } +} + diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/exceptions/GazetteerException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/exceptions/GazetteerException.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,13 @@ +package de.mpiwg.gazetteer.utils.exceptions; + +public abstract class GazetteerException extends Exception{ + + private static final long serialVersionUID = -7540131287577085722L; + + public static int CODE = 0; + + public int getCode(){ + return CODE; + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/exceptions/NoAuthorizedException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/exceptions/NoAuthorizedException.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,22 @@ +package de.mpiwg.gazetteer.utils.exceptions; + +public class NoAuthorizedException extends GazetteerException{ + private static final long serialVersionUID = 3483644794781830882L; + + private static int CODE = 2; + private Long userId; + private Long branchId; + + public NoAuthorizedException(Long userId, Long branchId){ + this.userId = userId; + this.branchId = branchId; + } + public String getMessage(){ + return "NoAuthorizedException: This user " + userId + " is not authorized to modify this branch (" + branchId + ")!"; + } + + public int getCode(){ + return CODE; + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/gazetteer/utils/exceptions/VersioningException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/exceptions/VersioningException.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,45 @@ +package de.mpiwg.gazetteer.utils.exceptions; + +import de.mpiwg.gazetteer.bo.LGFile; + +public class VersioningException extends GazetteerException{ + + private static final long serialVersionUID = 3686916552150745726L; + + private static int CODE = 1; + + public LGFile userFile; + public LGFile currentFile; + + public VersioningException(LGFile userFile, LGFile currentFile){ + this.userFile = userFile; + this.currentFile = currentFile; + } + + public String getMessage(){ + String msg = "VersioningException: In the between time, somebody else saved a new version of this file. "; + msg += " You modified the version " + this.userFile.getVersion() + ", however the current version is " + this.currentFile.getVersion() + "."; + return msg; + } + + + public LGFile getUserFile() { + return userFile; + } + + public void setUserFile(LGFile userFile) { + this.userFile = userFile; + } + + public LGFile getCurrentFile() { + return currentFile; + } + + public void setCurrentFile(LGFile currentFile) { + this.currentFile = currentFile; + } + + public int getCode(){ + return CODE; + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/AbstractJSPPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/AbstractJSPPage.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,92 @@ +package de.mpiwg.web.jsp; + +import java.util.ArrayList; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public abstract class AbstractJSPPage { + + protected HttpServletRequest request; + protected HttpServletResponse response; + + public HttpServletRequest getRequest() { + return request; + } + public void setRequest(HttpServletRequest request) { + this.request = request; + } + public HttpServletResponse getResponse() { + return response; + } + public void setResponse(HttpServletResponse response) { + this.response = response; + } + + public void addMsg(String msg){ + if(getSessionBean().getMsgList() == null){ + getSessionBean().setMsgList(new ArrayList()); + } + getSessionBean().getMsgList().add(msg); + } + + public void init(){ + Map parameters = request.getParameterMap(); + for(String parameter : parameters.keySet()) { + System.out.println(parameter + "= " + printVars(parameters.get(parameter))); + } + } + + public String getParameter(String name){ + String[] array = request.getParameterValues(name); + if(array != null && array.length > 0){ + return array[0]; + } + return new String(); + } + + public Long getLongParameter(String name){ + String param = getParameter(name); + try { + return Long.parseLong(param); + } catch (Exception e) { + } + return null; + } + + public Integer getIntParameter(String name){ + String param = getParameter(name); + try { + return Integer.parseInt(param); + } catch (Exception e) { + } + return null; + } + + public String printVars(String[] array){ + String response = new String(); + for(String s : array){ + response += s + ", "; + } + return response; + } + + + public void internalError(Exception e){ + addMsg("Internal Error: " + e.getMessage()); + e.printStackTrace(); + } + + public SessionBean getSessionBean(){ + SessionBean bean = (SessionBean)((HttpServletRequest) request).getSession().getAttribute("sessionBean"); + if(bean == null){ + ((HttpServletRequest) request).getSession().setAttribute("sessionBean", new SessionBean()); + } + return (SessionBean)((HttpServletRequest) request).getSession().getAttribute("sessionBean"); + } + + public ApplicationBean getApplicationBean(){ + return ApplicationBean.getInstance(); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/ApplicationBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/ApplicationBean.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,153 @@ +package de.mpiwg.web.jsp; + +import java.io.Serializable; + +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.utils.PropertiesUtils; + +public class ApplicationBean implements Serializable{ + + private static final long serialVersionUID = 804932192506497432L; + + private static Logger logger = Logger.getLogger(ApplicationBean.class); + + private static ApplicationBean instance; + + public static ApplicationBean getInstance(){ + if(instance == null){ + instance = new ApplicationBean(); + } + return instance; + } + + public ApplicationBean(){ + System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); + System.out.println("Starting Application Bean"); + System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"); + } + + + public String getExtractionInterfaceUrl(){ + String value = null; + try { + value = PropertiesUtils.getPropValue("extraction_interface"); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + public String getTocInterfaceUrl(){ + String value = null; + try { + value = PropertiesUtils.getPropValue("toc_interface"); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + public String getRootServer(){ + String value = null; + try { + value = PropertiesUtils.getPropValue("root_server"); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + public String getDvnRootServer(){ + String value = null; + try { + value = PropertiesUtils.getPropValue("dvn_server"); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + public String getShowImage(){ + return getRootServer() + "/resources/images/show_16.png"; + } + + public String getEditImage(){ + return getRootServer() + "/resources/images/edit_16.png"; + } + + public String getPublishImage(){ + return getRootServer() + "/resources/images/publish_16.png"; + } + + public String getBranchDetailsImage(){ + return getRootServer() + "/resources/images/branch_details_16.png"; + } + + public String getNewBranchImage(){ + return getRootServer() + "/resources/images/new_branch_16.png"; + } + + public String getEditBranchImage(){ + return getRootServer() + "/resources/images/edit_branch_16.png"; + } + + public String getSearchImage(){ + return getRootServer() + "/resources/images/search_32.png"; + } + + public String getPaginatorFirst(){ + return getRootServer() + "/resources/images/arrow-first.gif"; + } + + public String getPaginatorFr(){ + return getRootServer() + "/resources/images/arrow-fr.gif"; + } + + public String getPaginatorPrevious(){ + return getRootServer() + "/resources/images/arrow-previous.gif"; + } + + public String getPaginatorNext(){ + return getRootServer() + "/resources/images/arrow-next.gif"; + } + public String getPaginatorFf(){ + return getRootServer() + "/resources/images/arrow-ff.gif"; + } + + public String getPaginatorLast(){ + return getRootServer() + "/resources/images/arrow-last.gif"; + } + + public String getUpImage(){ + return getRootServer() + "/resources/images/up_16.png"; + } + + public String getFilterImage(){ + return getRootServer() + "/resources/images/filter_16.png"; + } + + public String getDownImage(){ + return getRootServer() + "/resources/images/down_16.png"; + } + + public String getDeleteImage(){ + return getRootServer() + "/resources/images/delete_16.png"; + } + + public String getMoreInfoImage(){ + return getRootServer() + "/resources/images/more_info_16.png"; + } + + public String getJSConfirmationDelete(){ + return "if(!confirm('Do you really want to delete this?')){ return false; };"; + } + + public String getJSConfirmationPublish(){ + return "if(!confirm('Do you really want to publish this?')){ return false; };"; + } + + public String getJSConfirmationSave(){ + return "if(!confirm('Do you really want to save this?')){ return false; };"; + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/BranchPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/BranchPage.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,262 @@ +package de.mpiwg.web.jsp; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; +import de.mpiwg.gazetteer.dataverse.bo.VDCUser; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.FileManager; + +public class BranchPage extends AbstractJSPPage{ + + private static Logger logger = Logger.getLogger(CreateFilePage.class); + + public static String bean = "branchBean"; + public static String page = "pages/branchPage.jsp"; + + private LGBranch branch; + private LGFile lastFile; + private Long branchId; + private List allFiles; + private String text; + private List suggestionUserList; + private List contributors; + + private Long fileId; + + private Long userId; + + private String studyGlobalId; + + + public void loadParameters(HttpServletRequest request, HttpServletResponse response){ + this.request = request; + this.response = response; + this.userId = getLongParameter("userId"); + this.fileId = getLongParameter("fileId"); + this.studyGlobalId = getParameter("studyGlobalId"); + } + + public void publishFile(){ + System.out.println("publishFile: " + this.fileId + " in " + studyGlobalId); + if(fileId != null && StringUtils.isNotEmpty(studyGlobalId)){ + + try { + JSONObject resp = DataverseUtils.publishFile(fileId, studyGlobalId, getSessionBean().getUser().getUserName(), getSessionBean().getUser().getPassword()); + if(resp.has("fileMetadata")){ + + Long dvId = resp.getJSONObject("fileMetadata").getLong("id"); + String fileNameInDv = resp.getJSONObject("fileMetadata").getString("label"); + + LGFile file = DataProvider.getInstance().getFile(getFileId()); + //LGBranch branch = DataProvider.getInstance().getBranch(file.getBranchId()); + file.setDvId(dvId); + DataProvider.getInstance().updateFile(file); + + addMsg("The File has been published."); + addMsg("The id of the file in Dataverse is: " + dvId + "."); + addMsg("The name of the file in Dataverse is: " + fileNameInDv + "."); + + }else{ + if(resp.has("status") && StringUtils.equals(resp.getString("status"), "error")){ + addMsg("Dataverse reported an error: " + resp.getString("message")); + }else{ + addMsg("Internal Error: problems generating the table for the file " + fileId); + } + } + + } catch (Exception e) { + internalError(e); + } + } + } + + public void loadBranch(String branchId0){ + try { + + this.branchId = Long.parseLong(branchId0); + + LGBranch branch = DataProvider.getInstance().getBranch(branchId); + if(branch != null){ + this.loadBranch(branch); + }else{ + addMsg("Branch [id=" + branchId0 + "] no found."); + } + + + } catch (Exception e) { + internalError(e); + } + } + + public void addContributor(){ + if(userId != null){ + + VDCUser user = DataverseUtils.getUser(userId); + System.out.println("Adding user: " + user.getUserName()); + + this.branch.addContributor(userId); + this.saveBranch0(); + } + } + + public void deleteFile(){ + if(this.fileId != null){ + + try { + LGFile file = DataProvider.getInstance().getFile(fileId); + DataProvider.getInstance().deleteFile(file); + LGBranch branch = DataProvider.getInstance().getBranch(file.getBranchId()); + this.loadBranch(branch); + + } catch (Exception e) { + internalError(e); + } + } + } + + public void removeContributor(){ + if(userId != null){ + + VDCUser user = DataverseUtils.getUser(userId); + System.out.println("Removing user: " + user.getUserName()); + + this.branch.removeContributor(userId); + this.saveBranch0(); + } + } + + private void saveBranch0(){ + try { + DataProvider.getInstance().updateBranch(branch); + this.loadBranch(branch); + addMsg("The branch has been updated!"); + } catch (Exception e) { + internalError(e); + } + } + + public void loadBranch(LGBranch branch){ + logger.info("Loading Branch: " + branch.toString()); + this.reset(); + if(branch != null && branch.isPersistent()){ + + try { + this.branch = (LGBranch)branch.clone(); + this.lastFile = DataProvider.getInstance().getFile(branch.getCurrentLastFileId()); + this.allFiles = DataProvider.getInstance().getAllFiles(branch.getId()); + this.text = FileManager.getFileAsText(this.lastFile); + this.contributors = new ArrayList(); + for(Long userId : this.branch.getContributorsList()){ + VDCUser user = DataverseUtils.getUser(userId); + if(user != null){ + this.contributors.add(user); + } + + } + + this.loadSuggestionUserList(); + } catch (Exception e) { + internalError(e); + } + + logger.info("allFiles.size=" + allFiles.size()); + } + } + + private void loadSuggestionUserList() throws Exception{ + this.suggestionUserList = new ArrayList(); + for(VDCUser user : DataverseUtils.getAllUsers()){ + if(!branch.hasContributor(user.getId())){ + this.suggestionUserList.add(user); + } + } + } + + public void reset(){ + this.branch = null; + this.lastFile = null; + this.allFiles = null; + } + + public LGBranch getBranch() { + return branch; + } + public void setBranch(LGBranch branch) { + this.branch = branch; + } + public LGFile getLastFile() { + return lastFile; + } + public void setLastFile(LGFile lastFile) { + this.lastFile = lastFile; + } + public Long getBranchId() { + return branchId; + } + public void setBranchId(Long branchId) { + this.branchId = branchId; + } + public List getAllFiles() { + return allFiles; + } + public void setAllFiles(List allFiles) { + this.allFiles = allFiles; + } + public String getText() { + return text; + } + public void setText(String text) { + this.text = text; + } + + + + public List getContributors() { + return contributors; + } + + public void setContributors(List contributors) { + this.contributors = contributors; + } + + public List getSuggestionUserList() { + return suggestionUserList; + } + public void setSuggestionUserList(List suggestionUserList) { + this.suggestionUserList = suggestionUserList; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getFileId() { + return fileId; + } + + public void setFileId(Long fileId) { + this.fileId = fileId; + } + public String getStudyGlobalId() { + return studyGlobalId; + } + + public void setStudyGlobalId(String studyGlobalId) { + this.studyGlobalId = studyGlobalId; + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/CreateFilePage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/CreateFilePage.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,63 @@ +package de.mpiwg.web.jsp; + +import java.sql.SQLException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; + +public class CreateFilePage extends AbstractJSPPage{ + + private static Logger logger = Logger.getLogger(CreateFilePage.class); + + public static String bean = "createFileBean"; + public static String page = "pages/createFile.jsp"; + + private Long sectionId; + private DBSection section; + + public void loadParameters(HttpServletRequest request, HttpServletResponse response){ + this.request = request; + this.response = response; + + this.sectionId = getLongParameter("sectionId"); + } + + public void loadSection(){ + System.out.println("$$$$$ loadSection= " + sectionId); + try { + + this.section = DBService.getSectionWithContent(sectionId); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void reset(){ + this.section = null; + this.sectionId = null; + } + + public Long getSectionId() { + return sectionId; + } + + public void setSectionId(Long sectionId) { + this.sectionId = sectionId; + } + + public DBSection getSection() { + return section; + } + + public void setSection(DBSection section) { + this.section = section; + } + + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/DataPaginator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/DataPaginator.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,127 @@ +package de.mpiwg.web.jsp; +import java.text.MessageFormat; + +public class DataPaginator { + + private int itemsPerPage = 100; + private int rewindFastForwardBy = 10; + + private int currentPage; + private int numberOfPages; + + private String recordStatus; + + public void first(){ + this.currentPage = 0; + } + + public void last(){ + this.currentPage = this.numberOfPages -1; + } + + public void fastRewind () { + this.rewind(this.rewindFastForwardBy); + } + + private void rewind (int aRewindFastForwardBy) { + int newPageNumber = currentPage - aRewindFastForwardBy; + if (newPageNumber < 0) { + currentPage = 0; + } else { + currentPage = newPageNumber; + } + } + + public void goToPage(int newPageNumber){ + if (newPageNumber > this.numberOfPages -1) { + currentPage = this.numberOfPages -1; + } else if(newPageNumber < 0 ){ + currentPage = 0; + }else{ + currentPage = newPageNumber; + } + + } + + private void forward (int aRewindFastForwardBy) { + int newPageNumber = currentPage + aRewindFastForwardBy; + if (newPageNumber > this.numberOfPages - 1) { + currentPage = this.numberOfPages -1; + } else { + currentPage = newPageNumber; + } + } + + public void previous () { + this.rewind(1); + } + + public void next () { + this.forward(1); + } + + public void fastForward () { + this.forward(this.rewindFastForwardBy); + } + + public void initCount() { + if (currentPage > numberOfPages) { + currentPage=numberOfPages; + } + } + + public int getNumberOfPages() { + return numberOfPages; + } + + public void setNumberOfPages(int numberOfPages) { + this.numberOfPages = numberOfPages; + } + + public void resetNumberOfPages(int itemsTotal){ + int numberOfPages = (itemsTotal + % this.getItemsPerPage() == 0) ? + itemsTotal + / this.getItemsPerPage() : + (itemsTotal + / this.getItemsPerPage()) + 1; + this.setNumberOfPages(numberOfPages); + } + + public int getCurrentPage() { + return currentPage; + } + + public void setCurrentPage(int currentPage) { + this.currentPage = currentPage; + } + + public String getRecordStatus () { + this.recordStatus = MessageFormat.format("{0} of {1}", + new Object []{ + Integer.valueOf(currentPage + 1), + Integer.valueOf(numberOfPages) + }); + return recordStatus; + } + + public void setRecordStatus(String recordStatus) { + this.recordStatus = recordStatus; + } + + public int getItemsPerPage() { + return itemsPerPage; + } + + public void setItemsPerPage(int itemsPerPage) { + this.itemsPerPage = itemsPerPage; + } + + public int getRewindFastForwardBy() { + return rewindFastForwardBy; + } + + public void setRewindFastForwardBy(int rewindFastForwardBy) { + this.rewindFastForwardBy = rewindFastForwardBy; + } +} \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/HomePage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/HomePage.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,80 @@ +package de.mpiwg.web.jsp; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import com.sun.org.apache.bcel.internal.generic.GETSTATIC; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.utils.DataProvider; + +public class HomePage extends AbstractJSPPage{ + + private static Logger logger = Logger.getLogger(HomePage.class); + + public static String bean = "homeBean"; + public static String page = "pages/home.jsp"; + + + private List branches; + private Long branchId; + + + public void loadParameters(HttpServletRequest request, HttpServletResponse response){ + this.request = request; + this.response = response; + + this.branchId = getLongParameter("branchId"); + } + + public void reloadBranches(){ + + logger.debug("reloadBranches"); + + this.branches = new ArrayList(); + if(getSessionBean().getUser() != null){ + for(LGBranch branch : DataProvider.getInstance().getBranches(getSessionBean().getUser().getId())){ + if(!branch.isTransientDataLoaded()){ + branch.loadTransientData(); + } + this.branches.add(branch); + } + } + } + + public void deleteBranch(){ + + logger.debug("deleteBranch " + branchId); + + if(branchId != null){ + LGBranch branch = DataProvider.getInstance().getBranch(branchId); + if(branch != null){ + DataProvider.getInstance().deleteBranch(branch); + this.reloadBranches(); + } + } + } + + public List getBranches() { + return branches; + } + + + public void setBranches(List branches) { + this.branches = branches; + } + + public Long getBranchId() { + return branchId; + } + + public void setBranchId(Long branchId) { + this.branchId = branchId; + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/JSPProxy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,178 @@ +package de.mpiwg.web.jsp; + +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.utils.DBService; + +public class JSPProxy extends AbstractJSPPage { + + private static Logger logger = Logger.getLogger(JSPProxy.class); + + private String action; + private String bean; + + public void init(){ + /* + Map parameters = request.getParameterMap(); + for(String parameter : parameters.keySet()) { + if(parameter.toLowerCase().startsWith("token")) { + String[] values = parameters.get(parameter); + System.out.println(parameter + "= " + values); + } + }*/ + } + + + public String processRequest(){ + + logger.info("processRequest [bean= " + bean + ", action=" + action +"]"); + + if(StringUtils.equals(bean, BranchPage.bean)){ + + getSessionBean().getBranchPage().loadParameters(request, response); + + if(StringUtils.equals(action, "addContributor")){ + getSessionBean().getBranchPage().addContributor(); + } else if(StringUtils.equals(action, "removeContributor")){ + getSessionBean().getBranchPage().removeContributor(); + }else if(StringUtils.equals(action, "deleteFile")){ + getSessionBean().getBranchPage().deleteFile(); + }else if(StringUtils.equals(action, "publishFile")){ + getSessionBean().getBranchPage().publishFile(); + } + + return BranchPage.page; + + + }else if(StringUtils.equals(bean, CreateFilePage.bean)){ + + getSessionBean().getCreateFilePage().loadParameters(request, response); + + if(StringUtils.equals(action, "loadSection")){ + getSessionBean().getCreateFilePage().loadSection(); + }else if(StringUtils.equals(action, "reset")){ + getSessionBean().getCreateFilePage().reset(); + } + + return CreateFilePage.page; + + }else if(StringUtils.equals(bean, HomePage.bean)){ + + getSessionBean().getHomePage().loadParameters(request, response); + + if(StringUtils.equals(action, "deleteBranch")){ + getSessionBean().getHomePage().deleteBranch(); + }else if(StringUtils.equals(action, "reloadBranches")){ + getSessionBean().getHomePage().reloadBranches(); + } + + return HomePage.page; + + }else if(StringUtils.equals(bean, "loginBean")){ + getSessionBean().loadParameters(request, response); + + if(StringUtils.equals(action, "login")){ + getSessionBean().login(); + }else if(StringUtils.equals(action, "logout")){ + getSessionBean().logout(); + } + + return "pages/home.jsp"; + + }else if(StringUtils.equals(bean, SearchPage.bean)){ + getSessionBean().getSearchPage().loadParameters(request, response); + + if(StringUtils.equals(action, "search")){ + getSessionBean().getSearchPage().search(); + } else if(StringUtils.equals(action, "filter")){ + getSessionBean().getSearchPage().filter(); + //PAGINATOR + } else if(StringUtils.equals(action, "firstPage")){ + getSessionBean().getSearchPage().firstPage(); + } else if(StringUtils.equals(action, "fastRewind")){ + getSessionBean().getSearchPage().fastRewind(); + } else if(StringUtils.equals(action, "previousPage")){ + getSessionBean().getSearchPage().previousPage(); + } else if(StringUtils.equals(action, "nextPage")){ + getSessionBean().getSearchPage().nextPage(); + } else if(StringUtils.equals(action, "fastForward")){ + getSessionBean().getSearchPage().fastForward(); + } else if(StringUtils.equals(action, "lastPage")){ + getSessionBean().getSearchPage().lastPage(); + + //SORTING + } else if(StringUtils.equals(action, "sortByBookIdUp")){ + getSessionBean().getSearchPage().sortByBookIdUp(); + } else if(StringUtils.equals(action, "sortByBookIdDown")){ + getSessionBean().getSearchPage().sortByBookIdDown(); + } else if(StringUtils.equals(action, "sortByBookNameUp")){ + getSessionBean().getSearchPage().sortByBookNameUp(); + } else if(StringUtils.equals(action, "sortByBookNameDown")){ + getSessionBean().getSearchPage().sortByBookNameDown(); + } else if(StringUtils.equals(action, "sortByDynastyUp")){ + getSessionBean().getSearchPage().sortByDynastyUp(); + } else if(StringUtils.equals(action, "sortByDynastyDown")){ + getSessionBean().getSearchPage().sortByDynastyDown(); + } else if(StringUtils.equals(action, "sortByPeriodUp")){ + getSessionBean().getSearchPage().sortByPeriodUp(); + } else if(StringUtils.equals(action, "sortByPeriodDown")){ + getSessionBean().getSearchPage().sortByPeriodDown(); + } else if(StringUtils.equals(action, "sortByVolumeUp")){ + getSessionBean().getSearchPage().sortByVolumeUp(); + } else if(StringUtils.equals(action, "sortByVolumeDown")){ + getSessionBean().getSearchPage().sortByVolumeDown(); + } else if(StringUtils.equals(action, "sortBySectionNameUp")){ + getSessionBean().getSearchPage().sortBySectionNameUp(); + } else if(StringUtils.equals(action, "sortBySectionNameDown")){ + getSessionBean().getSearchPage().sortBySectionNameDown(); + + } else if(StringUtils.equals(action, "sortByLevel1Up")){ + getSessionBean().getSearchPage().sortByLevel1Up(); + } else if(StringUtils.equals(action, "sortByLevel1Down")){ + getSessionBean().getSearchPage().sortByLevel1Down(); + + } else if(StringUtils.equals(action, "sortByAdminTypeUp")){ + getSessionBean().getSearchPage().sortByAdminTypeUp(); + } else if(StringUtils.equals(action, "sortByAdminTypeDown")){ + getSessionBean().getSearchPage().sortByAdminTypeDown(); + + } else if(StringUtils.equals(action, "sortByStartPageUp")){ + getSessionBean().getSearchPage().sortByStartPageUp(); + } else if(StringUtils.equals(action, "sortByStartPageDown")){ + getSessionBean().getSearchPage().sortByStartPageDown(); + } + + + + + return SearchPage.page; + + } + + //Default Page + return "pages/search.jsp"; + } + + + public String getAction() { + return action; + } + + + public void setAction(String action) { + this.action = action; + } + + + public String getBean() { + return bean; + } + + + public void setBean(String bean) { + this.bean = bean; + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/SearchPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/SearchPage.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,502 @@ +package de.mpiwg.web.jsp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.web.search.SortSectionByAdminType; +import de.mpiwg.web.search.SortSectionByAuthor; +import de.mpiwg.web.search.SortSectionByBookId; +import de.mpiwg.web.search.SortSectionByBookName; +import de.mpiwg.web.search.SortSectionByDynasty; +import de.mpiwg.web.search.SortSectionByEdition; +import de.mpiwg.web.search.SortSectionById; +import de.mpiwg.web.search.SortSectionByLevel1; +import de.mpiwg.web.search.SortSectionByPeriod; +import de.mpiwg.web.search.SortSectionByStartPage; +import de.mpiwg.web.search.SortSectionByVolume; + +public class SearchPage extends AbstractJSPPage{ + + private static Logger logger = Logger.getLogger(SearchPage.class); + + public static String bean = "searchBean"; + public static String page = "pages/search.jsp"; + + private static Integer SEARCH_IN_SECTION_NAME = 0; + private static Integer SEARCH_IN_BOOK_NAME = 1; + + + + private Map> branchesMap; + private List completeSectionList; + private List filteredSectionList; + private List displaySectionList; + + private String searchTerm = new String(); + private Integer searchIn = SEARCH_IN_SECTION_NAME; + + private String dynastyFilter = new String(); + private String adminTypeFilter = new String(); + private String level1Filter = new String(); + + private DataPaginator paginator = new DataPaginator(); + private String searchMessage; + private String filteringMessage; + + @Override + public void init(){ + super.init(); + } + + public void loadParameters(HttpServletRequest request, HttpServletResponse response){ + this.request = request; + this.response = response; + + this.searchTerm = getParameter("searchTerm"); + this.dynastyFilter = getParameter("dynastyFilter"); + this.adminTypeFilter = getParameter("adminTypeFilter"); + this.level1Filter = getParameter("level1Filter"); + this.searchIn = getIntParameter("searchIn"); + } + + public void search(){ + logger.debug("Searching: " + this.searchTerm); + + this.dynastyFilter = new String(); + this.level1Filter = new String(); + this.adminTypeFilter = new String(); + + if(StringUtils.isNotEmpty(this.searchTerm)){ + this.loadBranches(); + try { + List terms = splitTerms(); + + if(SEARCH_IN_SECTION_NAME.equals(this.searchIn)){ + System.out.println("Search in Section Name"); + this.completeSectionList = DBService.searchSection(terms); + }else if(SEARCH_IN_BOOK_NAME.equals(this.searchIn)){ + System.out.println("Search in Book Name"); + this.completeSectionList = DBService.searchBook(terms, "name"); + } + + Collections.sort(this.completeSectionList); + + filter(); + + + } catch (Exception e) { + internalError(e); + } + } + } + + public void filter(){ + this.filteredSectionList = new ArrayList(); + for(DBSection section : this.completeSectionList){ + if(!this.filteredSectionList.contains(section)){ + + if( (StringUtils.isEmpty(dynastyFilter) || StringUtils.startsWith(section.getBook().getDynasty(), dynastyFilter)) && + (StringUtils.isEmpty(level1Filter) || StringUtils.startsWith(section.getBook().getLevel1(), level1Filter)) && + (StringUtils.isEmpty(adminTypeFilter) || StringUtils.startsWith(section.getBook().getAdmin_type(), adminTypeFilter)) + ){ + this.filteredSectionList.add(section); + } + } + } + + if(completeSectionList.size() > 0){ + this.searchMessage = completeSectionList.size() + " section(s) found for the term(s): " + this.searchTerm; + this.filteringMessage = this.filteredSectionList.size() + " section(s) listed after the filtering"; + this.paginator.setCurrentPage(0); + this.paginator.resetNumberOfPages(filteredSectionList.size()); + this.updateCurrentSections(); + }else{ + this.searchMessage = "No sections found for the term(s): " + this.searchTerm; + this.filteredSectionList = null; + } + } + + private void updateCurrentSections() { + this.paginator.initCount(); + int startRecord = this.paginator.getCurrentPage() + * this.paginator.getItemsPerPage(); + if(this.paginator.getNumberOfPages() == 0){ + this.displaySectionList = new ArrayList(); + }else if((this.paginator.getCurrentPage() + 1) == this.paginator.getNumberOfPages()){ + int mod = this.filteredSectionList.size() % paginator.getItemsPerPage(); + if(mod == 0){ + this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + this.paginator.getItemsPerPage()); + }else{ + this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + mod); + } + + }else{ + this.displaySectionList = filteredSectionList.subList(startRecord, startRecord + this.paginator.getItemsPerPage()); + } + + for(DBSection section : this.displaySectionList){ + section.setBranches(this.branchesMap.get(section.getId())); + } + } + + private void loadBranches(){ + this.branchesMap = new HashMap>(); + List list = DataProvider.getInstance().getBranches(getSessionBean().getUser().getId()); + for(LGBranch branch : list){ + branch.loadTransientData(); + if(this.branchesMap.get(branch.getSectionId()) == null){ + this.branchesMap.put(branch.getSectionId(), new ArrayList()); + } + this.branchesMap.get(branch.getSectionId()).add(branch); + } + } + + private List splitTerms(){ + List rs = new ArrayList(); + String[] array = this.searchTerm.split(","); + + for(String tmp : array){ + tmp = tmp.replace(" ", ""); + if(StringUtils.isNotEmpty(tmp)){ + rs.add(tmp); + } + } + return rs; + } + + public List suggestDynasty(String term, int limit){ + List list = new ArrayList(); + for(DBSection section : this.completeSectionList){ + String dynasty = section.getBook().getDynasty(); + if(!list.contains(dynasty) && dynasty.startsWith(term)){ + list.add(dynasty); + } + if(limit == list.size()){ + break; + } + } + return list; + } + + public List suggestLevel1(String term, int limit){ + List list = new ArrayList(); + for(DBSection section : this.completeSectionList){ + String level1 = section.getBook().getLevel1(); + if(!list.contains(level1) && level1.startsWith(term)){ + list.add(level1); + } + if(limit == list.size()){ + break; + } + } + return list; + } + + public List suggestAdminType(String term, int limit){ + List list = new ArrayList(); + for(DBSection section : this.completeSectionList){ + String adminType = section.getBook().getAdmin_type(); + if(!list.contains(adminType) && adminType.startsWith(term)){ + list.add(adminType); + } + if(limit == list.size()){ + break; + } + } + return list; + } + + + public static Integer getSEARCH_IN_SECTION_NAME() { + return SEARCH_IN_SECTION_NAME; + } + + + public static void setSEARCH_IN_SECTION_NAME(Integer sEARCH_IN_SECTION_NAME) { + SEARCH_IN_SECTION_NAME = sEARCH_IN_SECTION_NAME; + } + + + public Map> getBranchesMap() { + return branchesMap; + } + + + public void setBranchesMap(Map> branchesMap) { + this.branchesMap = branchesMap; + } + + + public List getCompleteSectionList() { + return completeSectionList; + } + + + public void setCompleteSectionList(List completeSectionList) { + this.completeSectionList = completeSectionList; + } + + + public String getSearchTerm() { + return searchTerm; + } + + + public void setSearchTerm(String searchTerm) { + this.searchTerm = searchTerm; + } + + + public Integer getSearchIn() { + return searchIn; + } + + + public void setSearchIn(Integer searchIn) { + this.searchIn = searchIn; + } + + public List getFilteredSectionList() { + return filteredSectionList; + } + + public void setFilteredSectionList(List filteredSectionList) { + this.filteredSectionList = filteredSectionList; + } + + public List getDisplaySectionList() { + return displaySectionList; + } + + public void setDisplaySectionList(List displaySectionList) { + this.displaySectionList = displaySectionList; + } + + public DataPaginator getPaginator() { + return paginator; + } + + public void setPaginator(DataPaginator paginator) { + this.paginator = paginator; + } + + public void firstPage() { + this.paginator.first(); + this.updateCurrentSections(); + } + + public void lastPage() { + this.paginator.last(); + this.updateCurrentSections(); + } + + public void fastForward() { + this.paginator.fastForward(); + this.updateCurrentSections(); + } + + public void fastRewind() { + this.paginator.fastRewind(); + this.updateCurrentSections(); + } + + public void previousPage() { + this.paginator.previous(); + this.updateCurrentSections(); + } + + public void nextPage() { + this.paginator.next(); + this.updateCurrentSections(); + } + + public String getSearchMessage() { + return searchMessage; + } + + public void setSearchMessage(String searchMessage) { + this.searchMessage = searchMessage; + } + + public String getFilteringMessage() { + return filteringMessage; + } + + public void setFilteringMessage(String filteringMessage) { + this.filteringMessage = filteringMessage; + } + + /////// Sorting + + public String getDynastyFilter() { + return dynastyFilter; + } + + public void setDynastyFilter(String dynastyFilter) { + this.dynastyFilter = dynastyFilter; + } + + public void sortByBookNameUp(){ + Collections.sort(this.completeSectionList, new SortSectionByBookName()); + filter(); + } + + public void sortByBookNameDown(){ + Collections.sort(this.completeSectionList, new SortSectionByBookName()); + Collections.reverse(this.completeSectionList); + filter(); + } + + public void sortBySectionNameUp(){ + Collections.sort(this.completeSectionList); + filter(); + } + + public void sortBySectionNameDown(){ + Collections.sort(this.completeSectionList); + Collections.reverse(this.completeSectionList); + filter(); + } + + public void sortByAuthorUp(){ + Collections.sort(this.completeSectionList, new SortSectionByAuthor()); + filter(); + } + + public void sortByAuthorDown(){ + Collections.sort(this.completeSectionList, new SortSectionByAuthor()); + Collections.reverse(this.completeSectionList); + filter(); + } + + public void sortByPeriodUp(){ + Collections.sort(this.completeSectionList, new SortSectionByPeriod()); + filter(); + } + + public void sortByPeriodDown(){ + Collections.sort(this.completeSectionList, new SortSectionByPeriod()); + Collections.reverse(this.completeSectionList); + filter(); + } + + public void sortByVolumeUp(){ + Collections.sort(this.completeSectionList, new SortSectionByVolume()); + filter(); + } + + public void sortByVolumeDown(){ + Collections.sort(this.completeSectionList, new SortSectionByVolume()); + Collections.reverse(this.completeSectionList); + filter(); + } + + + public void sortBySectionIdUp(){ + Collections.sort(this.completeSectionList, new SortSectionById()); + this.filter(); + } + + public void sortBySectionIdDown(){ + Collections.sort(this.completeSectionList, new SortSectionById()); + Collections.reverse(completeSectionList); + this.filter(); + } + + public void sortByEditionUp(){ + Collections.sort(this.completeSectionList, new SortSectionByEdition()); + filter(); + } + + public void sortByEditionDown(){ + Collections.sort(this.completeSectionList, new SortSectionByEdition()); + Collections.reverse(completeSectionList); + filter(); + } + + public void sortByDynastyUp(){ + Collections.sort(this.completeSectionList, new SortSectionByDynasty()); + filter(); + } + + public void sortByDynastyDown(){ + Collections.sort(this.completeSectionList, new SortSectionByDynasty()); + Collections.reverse(completeSectionList); + filter(); + } + + public void sortByBookIdUp(){ + Collections.sort(this.completeSectionList, new SortSectionByBookId()); + filter(); + } + + public void sortByBookIdDown(){ + Collections.sort(this.completeSectionList, new SortSectionByBookId()); + Collections.reverse(completeSectionList); + filter(); + } + + public void sortByLevel1Up(){ + Collections.sort(this.completeSectionList, new SortSectionByLevel1()); + filter(); + } + + public void sortByLevel1Down(){ + Collections.sort(this.completeSectionList, new SortSectionByLevel1()); + Collections.reverse(completeSectionList); + filter(); + } + + public void sortByAdminTypeUp(){ + Collections.sort(this.completeSectionList, new SortSectionByAdminType()); + filter(); + } + + public void sortByAdminTypeDown(){ + Collections.sort(this.completeSectionList, new SortSectionByAdminType()); + Collections.reverse(completeSectionList); + filter(); + } + + public void sortByStartPageUp(){ + Collections.sort(this.completeSectionList, new SortSectionByStartPage()); + filter(); + } + + public void sortByStartPageDown(){ + Collections.sort(this.completeSectionList, new SortSectionByStartPage()); + Collections.reverse(completeSectionList); + filter(); + } + + public String getAdminTypeFilter() { + return adminTypeFilter; + } + + public void setAdminTypeFilter(String adminTypeFilter) { + this.adminTypeFilter = adminTypeFilter; + } + + public String getLevel1Filter() { + return level1Filter; + } + + public void setLevel1Filter(String level1Filter) { + this.level1Filter = level1Filter; + } + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/SessionBean.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/SessionBean.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,162 @@ +package de.mpiwg.web.jsp; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.dataverse.DataverseUtils; +import de.mpiwg.gazetteer.dataverse.bo.VDCUser; +import de.mpiwg.gazetteer.utils.DataProvider; + +public class SessionBean extends AbstractJSPPage { + + private static Logger logger = Logger.getLogger(SessionBean.class); + public static final String BEAN_NAME = "sessionBean"; + + private List msgList = new ArrayList(); + + + + private VDCUser user; + private String userName; + private String password; + + private String currentSectionId = "5190882"; + private SearchPage searchPage = new SearchPage(); + private HomePage homePage = new HomePage(); + private CreateFilePage createFilePage = new CreateFilePage(); + private BranchPage branchPage = new BranchPage(); + + public SessionBean(){ + logger.info("\n\n### SessionBean #####\n\n"); + } + + + public void loadParameters(HttpServletRequest request, HttpServletResponse response){ + this.request = request; + this.response = response; + + this.userName = getParameter("userName"); + this.password = getParameter("password"); + } + + public void reset(){ + this.user = null; + this.searchPage = new SearchPage(); + this.homePage = new HomePage(); + this.createFilePage = new CreateFilePage(); + this.branchPage = new BranchPage(); + this.userName = new String(); + this.password = new String(); + } + + public List getMsgList() { + return msgList; + } + + public void setMsgList(List msgList) { + this.msgList = msgList; + } + + public void resetMsgList(){ + this.msgList = null; + } + + public void logout(){ + this.reset(); + } + + public void login(){ + try { + this.user = DataverseUtils.login(userName, password); + if(user != null){ + this.user.setPassword(this.password); + this.homePage.loadParameters(request, response); + this.homePage.reloadBranches(); + + }else{ + addMsg("User account no found or userName and password do not match!"); + } + + } catch (Exception e) { + internalError(e); + } + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public VDCUser getUser() { + return user; + } + + public void setUser(VDCUser user) { + this.user = user; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getCurrentSectionId() { + return currentSectionId; + } + + public void setCurrentSectionId(String currentSectionId) { + this.currentSectionId = currentSectionId; + } + + public SearchPage getSearchPage() { + return searchPage; + } + + public void setSearchPage(SearchPage searchPage) { + this.searchPage = searchPage; + } + + + public HomePage getHomePage() { + return homePage; + } + + + public void setHomePage(HomePage homePage) { + this.homePage = homePage; + } + + + public CreateFilePage getCreateFilePage() { + return createFilePage; + } + + + public void setCreateFilePage(CreateFilePage createFilePage) { + this.createFilePage = createFilePage; + } + + + public BranchPage getBranchPage() { + return branchPage; + } + + + public void setBranchPage(BranchPage branchPage) { + this.branchPage = branchPage; + } + + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/utils/CharsetFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/utils/CharsetFilter.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,39 @@ +package de.mpiwg.web.jsp.utils; + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +public class CharsetFilter implements Filter { + private String encoding; + + public void init(FilterConfig config) throws ServletException { + encoding = config.getInitParameter("requestEncoding"); + + if (encoding == null) + encoding = "UTF-8"; + } + + public void doFilter(ServletRequest request, ServletResponse response, FilterChain next) throws IOException, + ServletException { + // Respect the client-specified character encoding + // (see HTTP specification section 3.4.1) + if (null == request.getCharacterEncoding()) + request.setCharacterEncoding(encoding); + + /** + * Set the default response content type and encoding + */ + response.setContentType("text/html; charset=UTF-8"); + response.setCharacterEncoding("UTF-8"); + + next.doFilter(request, response); + } + + public void destroy() { + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/jsp/utils/SessionCollectorListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/utils/SessionCollectorListener.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,61 @@ +package de.mpiwg.web.jsp.utils; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionEvent; +import javax.servlet.http.HttpSessionListener; + +import org.apache.log4j.Logger; + +import de.mpiwg.web.jsp.SessionBean; + +public class SessionCollectorListener implements HttpSessionListener { + + + private static Logger logger = Logger.getLogger(SessionCollectorListener.class); + + public static String SESSION_COLLECTOR = "sessionCollector"; + public static String SESSION_TIMER = "sessionTimer"; + + @Override + public void sessionCreated(final HttpSessionEvent se) { + final HttpSession session = se.getSession(); + final ServletContext context = session.getServletContext(); + + Map sessionCollector = (Map)context.getAttribute(SESSION_COLLECTOR); + if(sessionCollector == null){ + sessionCollector = new HashMap(); + context.setAttribute(SESSION_COLLECTOR, sessionCollector); + } + + Map sessionTimer = (Map)context.getAttribute(SESSION_TIMER); + if(sessionTimer == null){ + sessionTimer = new HashMap(); + context.setAttribute(SESSION_TIMER, sessionTimer); + } + + + + sessionCollector.put(session.getId(), session); + sessionTimer.put(session.getId(), System.currentTimeMillis()); + logger.info("sessionCreated: " + session.getId()); + } + + @Override + public void sessionDestroyed(final HttpSessionEvent se) { + final HttpSession session = se.getSession(); + final ServletContext context = session.getServletContext(); + + Map sessionCollector = (Map)context.getAttribute(SESSION_COLLECTOR); + sessionCollector.remove(session.getId()); + + Map sessionTimer = (Map)context.getAttribute(SESSION_TIMER); + + logger.info("sessionDestroyed: " + session.getId() + " timeOut [ms]: " + (System.currentTimeMillis() - sessionTimer.get(session.getId()))); + + } + +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByAdminType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByAdminType.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByAdminType implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getAdmin_type().compareTo(o2.getBook().getAdmin_type()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByAuthor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByAuthor.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByAuthor implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getAuthor().compareTo(o2.getBook().getAuthor()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByBookId.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByBookId.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByBookId implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getId().compareTo(o2.getBook().getId()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByBookName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByBookName.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByBookName implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getName().compareTo(o2.getBook().getName()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByDynasty.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByDynasty.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByDynasty implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getDynasty().compareTo(o2.getBook().getDynasty()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByEdition.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByEdition.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByEdition implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getEdition().compareTo(o2.getBook().getEdition()); + } +} \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionById.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionById.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,12 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionById implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + return o1.getId().compareTo(o2.getId()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByLevel1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByLevel1.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByLevel1 implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getLevel1().compareTo(o2.getBook().getLevel1()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByPeriod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByPeriod.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByPeriod implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getPeriod().compareTo(o2.getBook().getPeriod()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByStartPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByStartPage.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByStartPage implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getStart_page().compareTo(o2.getStart_page()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/java/de/mpiwg/web/search/SortSectionByVolume.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/search/SortSectionByVolume.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,15 @@ +package de.mpiwg.web.search; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBSection; + +public class SortSectionByVolume implements Comparator{ + + public int compare(DBSection o1, DBSection o2) { + if(o1.getBook() == null || o2.getBook() == null){ + return o1.getName().compareTo(o2.getName()); + } + return o1.getBook().getVolume().compareTo(o2.getBook().getVolume()); + } +} diff -r 000000000000 -r 3e62083dbcbf src/main/resources/config.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/config.properties Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,12 @@ +db_gazetter_username=root +db_gazetter_password=admin +db_gazetter_name=Gazetteer +files_root=/gazetteer-server/data +#extraction_interface=http://141.14.239.50:1080/localmonographs +extraction_interface=http://localgazetteers-dev/extraction-interface +toc_interface=http://localgazetteers-dev/LGToc +dvn_server=http://localgazetteers-dev/dvn +#dvn_server=http://localhost/dvn +#root_server=http://localgazetteers.mpiwg-berlin.mpg.de:8080/gazetteer-server +#root_server=http://localhost:8080/LGServices +root_server=http://localgazetteers-dev/LGServices diff -r 000000000000 -r 3e62083dbcbf src/main/resources/hibernate.cfg.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/hibernate.cfg.xml Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,42 @@ + + + + + + 5 + 20 + 1800 + 50 + org.hibernate.connection.C3P0ConnectionProvider + + + + com.mysql.jdbc.Driver + jdbc:mysql://localhost/LGServer?characterEncoding=UTF-8 + + root + admin + UTF-8 + + + 1 + + + thread + + + + + + + + + diff -r 000000000000 -r 3e62083dbcbf src/main/resources/log4j.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/log4j.properties Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,31 @@ +### direct log messages to stdout ### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %5p %c{1}:%L - %m%n + +### set log levels - for more verbose logging change 'info' to 'debug' ## + +log4j.rootLogger=info, stdout + +log4j.logger.de.mpiwg=debug, file + +#log4j.logger.cl.dialectic=info, stdout + +#log4j.logger.net.sf.hibernate=debug, stdout +#Hibernate +#log4j.logger.org.hibernate.cfg=debug, file +#log4j.logger.org.hibernate.cfg.annotations.Version=info, stdout +#log4j.logger.org.hibernate.cfg.Environment=info, stdout +#log4j.logger.org.hibernate.cfg.AnnotationBinder=info, stdout + + +### enable the following line if you want to track down connection ### +### leakages when using DriverManagerConnectionProvider ### +#log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace + +### log JDBC bind parameters ### +#log4j.logger.net.sf.hibernate.type=debug + +### log prepared statement cache activity ### +#log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=debug diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/WEB-INF/web.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/WEB-INF/web.xml Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,49 @@ + + + + LGServices + + + pages/home.jsp + + + + + *.jsp + UTF-8 + + + + + de.mpiwg.web.jsp.utils.SessionCollectorListener + + + + CharsetFilter + de.mpiwg.web.jsp.utils.CharsetFilter + + requestEncoding + UTF-8 + + + + + CharsetFilter + /* + + + + jsp + *.jsp + *.dcss + + + + 30 + + + + diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/componentes/headContent.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/componentes/headContent.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,16 @@ + + +LGServices + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/componentes/paginator.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/componentes/paginator.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,47 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + + + + + + + + + + + + +
+ + + + + + <%=sessionBean.getSearchPage().getPaginator().getRecordStatus()%> + + + + + +
\ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/componentes/template.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/componentes/template.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,68 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + +<% if(sessionBean.getMsgList() != null && !sessionBean.getMsgList().isEmpty()) { %> + + +
+ + <% for(String msg : sessionBean.getMsgList()) { %> + + <% } %> +
+
+ <% sessionBean.resetMsgList(); %> +<% } %> + + + +
+
+ +
+ + + <% if(sessionBean.getUser() == null) { %> + + + + + + + + + +
Create Account + +
+ <% } else { %> + + + + + + + +
Logged in as: <%=sessionBean.getUser().getUserName() %>|Go To Dataverse
+ <% } %> +
+ +
+
+ + \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/methods/adminTypeAutocomplete.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/methods/adminTypeAutocomplete.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,26 @@ +<%@page import="java.util.List"%> +<%@page import="de.mpiwg.gazetteer.utils.DBService"%> +<%@page import="org.json.JSONObject"%> +<%@page import="org.json.JSONArray"%> + + + +<% + + + + String term = request.getParameter("term"); + List list = sessionBean.getSearchPage().suggestAdminType(term, 10); + + + JSONArray jsonArr = new JSONArray(); + + for(String item : list){ + JSONObject json = new JSONObject(); + json.put("name", item); + json.put("value", item); + jsonArr.put(json); + System.out.print("*"); + } + out.println(jsonArr); +%> \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/methods/dynastyAutocomplete.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/methods/dynastyAutocomplete.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,27 @@ +<%@page import="java.util.List"%> +<%@page import="de.mpiwg.gazetteer.utils.DBService"%> +<%@page import="org.json.JSONObject"%> +<%@page import="org.json.JSONArray"%> + + + +<% + + + + String term = request.getParameter("term"); + List list = sessionBean.getSearchPage().suggestDynasty(term, 10); + + System.out.println("dynastyFilter: " + term + " " + list.size()); + + JSONArray jsonArr = new JSONArray(); + + for(String item : list){ + JSONObject json = new JSONObject(); + json.put("name", item); + json.put("value", item); + jsonArr.put(json); + System.out.print("*"); + } + out.println(jsonArr); +%> \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/methods/getDataverseForm.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/methods/getDataverseForm.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,73 @@ +<%@page import="de.mpiwg.gazetteer.dataverse.DataverseUtils"%> +<%@page import="de.mpiwg.gazetteer.dataverse.bo.Study"%> +<%@page import="java.util.List"%> + +<% + + + List studies = DataverseUtils.getStudies(sessionBean.getUser().getUserName(), sessionBean.getUser().getPassword()); + System.out.println("%%%%% Studies: " + studies.size()); + + if(studies.isEmpty()){ +%> + + + +<% + } else { +%> + +
+ + " /> + + + + + + + + + + + + + + + + + + <% + for(Study study : studies){ + %> + + + + + + + + + + + + <% + } + %> +
<%= study.getGlobalId()%><%= study.getTitle() %><%= study.getCreator() %><%= study.getCreateTime() %><%= study.getStatus() %><%= study.getDataverse().getName() %> + +
+
+<% + } +%> \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/methods/level1Autocomplete.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/methods/level1Autocomplete.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,26 @@ +<%@page import="java.util.List"%> +<%@page import="de.mpiwg.gazetteer.utils.DBService"%> +<%@page import="org.json.JSONObject"%> +<%@page import="org.json.JSONArray"%> + + + +<% + + + + String term = request.getParameter("term"); + List list = sessionBean.getSearchPage().suggestLevel1(term, 10); + + + JSONArray jsonArr = new JSONArray(); + + for(String item : list){ + JSONObject json = new JSONObject(); + json.put("name", item); + json.put("value", item); + jsonArr.put(json); + System.out.print("*"); + } + out.println(jsonArr); +%> \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/methods/searchAutocomplete.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/methods/searchAutocomplete.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,38 @@ +<%@page import="java.util.List"%> +<%@page import="de.mpiwg.gazetteer.utils.DBService"%> +<%@page import="org.json.JSONObject"%> +<%@page import="org.json.JSONArray"%> +<% + + String term = request.getParameter("term"); + String searchIn0 = request.getParameter("searchIn"); + Integer searchIn = 0; + try{ + searchIn = Integer.parseInt(searchIn0); + }catch(Exception e){} + + + + List list = null; + + if(searchIn == 0){ + System.out.println("By Section"); + list = DBService.suggestSectionName(term, 10); + }else{ + System.out.println("By Book"); + list = DBService.suggestBookName(term, 10); + } + + System.out.println("AutoComplete: " + term + " " + list.size()); + + JSONArray jsonArr = new JSONArray(); + + for(String item : list){ + JSONObject json = new JSONObject(); + json.put("name", item); + json.put("value", item); + jsonArr.put(json); + System.out.print("*"); + } + out.println(jsonArr); +%> \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/methods/sectionIdAutocomplete.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/methods/sectionIdAutocomplete.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,20 @@ +<%@page import="java.util.List"%> +<%@page import="de.mpiwg.gazetteer.utils.DBService"%> +<%@page import="org.json.JSONObject"%> +<%@page import="org.json.JSONArray"%> +<% + + String term = request.getParameter("term"); + List list = DBService.suggestSectionId(term, 10); + + + JSONArray jsonArr = new JSONArray(); + + for(String item : list){ + JSONObject json = new JSONObject(); + json.put("name", item); + json.put("value", item); + jsonArr.put(json); + } + out.println(jsonArr); +%> \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/methods/sectionTableDetails.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/methods/sectionTableDetails.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,102 @@ + + +<%@page import="de.mpiwg.gazetteer.db.DBSection"%> +<%@page import="de.mpiwg.gazetteer.utils.DBService"%> +<%@page import="de.mpiwg.gazetteer.utils.DataProvider"%> +<% + if(request.getParameter("sectionId") != null){ + Long sectionId = Long.parseLong(request.getParameter("sectionId")); + DBSection section = DBService.getSectionWithContent(sectionId); + if(section != null){ +%> + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ + + + + + + + + + + + + + + + + + + + + +
+
+ + +<% + } + } +%> \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/pages/branchPage.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/pages/branchPage.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,330 @@ +<%@page import="de.mpiwg.gazetteer.dataverse.bo.VDCUser"%> +<%@page import="de.mpiwg.gazetteer.bo.LGFile"%> +<%@page import="org.apache.commons.lang.StringUtils"%> +<%@page import="de.mpiwg.gazetteer.db.DBSection"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + + + + <% + sessionBean.getBranchPage().loadParameters(request, response); + if(request.getParameter("branchId") != null){ + sessionBean.getBranchPage().loadBranch(request.getParameter("branchId")); + } + %> + + + + + + + +
+
XXXX
+
+ +
+ + <% if(sessionBean.getUser() == null) { %> + + <% } else { %> + + + + + <% if(sessionBean.getBranchPage().getBranch() != null) { %> +
+
+ + + <% for(VDCUser user : sessionBean.getBranchPage().getSuggestionUserList()) { %> + + + + <% } %> +
<%=user.getUserName()%>
+
+
+ <% } %> + + <% if(sessionBean.getBranchPage().getBranch() == null) { %> + + <% } else { %> + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+ + + <% for(VDCUser contr : sessionBean.getBranchPage().getContributors()) { %> + + + + + <% } %> +
+ +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + + + + + + + + + + + + + + + + <% for(LGFile file : sessionBean.getBranchPage().getAllFiles()) { %> + + + + + + + + + + + <% } %> +
+ + Show text + + + + Show text + + + <% if(file.getDvId() == null) {%> + + <% } else { %> + + <% } %> + + +
+ +
+
+ + <% } %> + + + + + + <% } %> + +
+ + \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/pages/createFile.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/pages/createFile.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,127 @@ +<%@page import="org.apache.commons.lang.StringUtils"%> +<%@page import="de.mpiwg.gazetteer.db.DBSection"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + + + + + + + + + + + + + + + +
+ + <% if(sessionBean.getUser() == null) { %> + + <% } else { %> + + + +
+ + + + + + + + +
+ " + style="width: 150px;" /> + + +
+ + <% if(sessionBean.getCreateFilePage().getSection() != null) { %> + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +
+ + + <% } %> + +
+ <% } %> + +
+ + \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/pages/home.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/pages/home.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,106 @@ +<%@page import="de.mpiwg.gazetteer.bo.LGBranch"%> +<%@page import="org.apache.commons.lang.StringUtils"%> +<%@page import="de.mpiwg.gazetteer.db.DBSection"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + + + + + + + + + + +
+ + <% if(sessionBean.getUser() == null) { %> + + <% } else { + sessionBean.getHomePage().loadParameters(request, response); + sessionBean.getHomePage().reloadBranches(); + %> + + + <% if(sessionBean.getHomePage().getBranches().isEmpty()) { %> + + <% } else { %> + +
+ + + + + + + + + + + + + + + + + + + <% for(LGBranch branch : sessionBean.getHomePage().getBranches()) { %> + + + + + + + + + + + + + + + + + + <% } %> +
<%=branch.getId() %><%=branch.getBook().getId() %><%=branch.getBook().getName() %><%=branch.getSection().getName() %><%=branch.getLabel() %> + + <% for(String contributor : branch.getContributorsNameList()) { %> + + <% } %> +
+
<%=branch.getFomattedLastChange() %> + + Show Branch in Extraction Interface + + + <%=branch.isPublished() %> + + + Manage Branch + + + +
+ +
+ <% } %> + <% } %> +
+ + \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/pages/search.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/pages/search.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,520 @@ +<%@page import="de.mpiwg.gazetteer.bo.LGBranch"%> +<%@page import="org.apache.commons.lang.StringUtils"%> +<%@page import="de.mpiwg.gazetteer.db.DBSection"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + + + + + + + + + + + + + + + + + + +
+
XXXX
+
+ + +
+ + <% if(sessionBean.getUser() == null) { %> + + <% } else { %> + + + +
+ + + + + + + + + + + + + +
+ + + +
+ + > + /> +
+ + + <% + if (sessionBean.getSearchPage().getCompleteSectionList() != null) { + %> + + + + + + + + + + + + + + + + + + + + + + + <% + for (DBSection section : sessionBean.getSearchPage().getDisplaySectionList()) { + %> + + + + + + + + + + + + + + + <% + } + %> + +
+ + + + + +
+ + + +
+ +
+ +
+
+
+ + + + + +
+ + + +
+ +
+ +
+
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + +
+ + + +
+ +
+ +
+
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + +
+ + + +
+ +
+ +
+
+
+ + + + + +
+ + + +
+ +
+ +
+
+ +
+ + <%=section.getBook().getId()%> + + More Information + <%=section.getBook().getName()%><%=section.getBook().getLevel1()%><%=section.getBook().getLevel2()%><%=section.getBook().getDynasty()%><%=section.getBook().getPeriod()%><%=section.getBook().getAdmin_type() %><%=section.getName()%><%=section.getPages()%> + + Show Section in Extraction Interface + + + <% if(section.getBranches() != null && !section.getBranches().isEmpty()) { %> + + <% for(LGBranch branch : section.getBranches()) { %> + + + + + <% } %> +
+ + + +
<%=branch.getFomattedLastChange() %>
<%=branch.getLabel() %>
+
+ + Manage Branch + +
+ <% } %> +
+ + + + <% + } + %> + + + + + <% } %> + +
+ + + diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/proxy.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/proxy.jsp Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,23 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + + + + + + + + + + + <% + response.sendRedirect(proxy.processRequest()); + %> + + + + + + \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/css/style.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/resources/css/style.css Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,260 @@ +body { + margin: 0; + padding: 0; + font-family: Verdana, Arial, sans-serif; + background-color: #FCF2DF ; + font-size: 12px; +} + +label{ + font-family: Verdana, Arial, sans-serif; + color: #485297; + font-size: 12px; +} + +.ui-btn.my-tooltip-btn, +.ui-btn.my-tooltip-btn:hover, +.ui-btn.my-tooltip-btn:active { + background: none; + border: 0; +} + +#header { + background-color: #fcf2df; + box-shadow: 0 0 5px 3px #d0d0d0; + height: 120px; + margin: 0 auto; + width: 80%; +} + + +.lgButton{ + font-size: 12px !important; +} + +.titelPage{ + color: #485297; + font-family: Verdana,Arial,sans-serif; + padding: 2px 0; + font-size: 20px; +} + +.label { + color: #485297; + font-family: Verdana,Arial,sans-serif; + padding: 2px 0; + font-size: small; +} + +/* Logo */ + +#logo { + width: 920px; + height: 40px; + margin: 0; + padding: 20px 45px 0px 40px; + /*color: #000000;*/ +} + +#logo h1, #logo p { + margin: 0px; + padding: 0px; + //text-transform: uppercase; +} + +#logo h1 { + font-family: Verdana, Verdana, Arial, sans-serif; + font-size: x-large; +} + +#logo p { + font-size: 12px; + font-weight: bold; + color: #FFFFFF; +} + +#logo a { + border: none; + background: none; + text-decoration: none; + color: #FFFFFF; +} + +.link { + margin: 0; + border: 0; + background: none; + overflow: visible; + color: blue; + cursor: pointer; + font-size: 16px; + font-family: Verdana,Arial,sans-serif; +} + +#page { + background-color: #fcf2df; + box-shadow: 0 0 5px 3px #d0d0d0; + margin: 0 auto; + padding-bottom: 50px; + width: 80%; +} + +.subTitel{ + width: 100%; + display: inline-block; + font-size: x-large; + padding: 10px 0; + color: #485297; + text-align: center; +} + +.contentForm{ + +} + +.searchInput{ + width: 300px; + box-shadow: inset 0 2px 2px #d3d3d3; + border: 1px solid #d3d3d3; + color: #555555; + margin: 0; + outline: medium none; + padding: 4px; +} + +.tableComponent { + margin-top: 10px; + padding-top: 10px; + width: 300px; + border-top: 5px solid #ABABCC; + width: 100%; +} + +.pageTable{ + width: 90%; + margin-left: auto; + margin-right: auto; + background-color: white; + border-collapse: collapse; +} + + + +.pageTable tr:nth-child(odd) { + background:#EBEBEB; +} + + +.pageTable td { + border-color: inherit; + border-style: solid; + border-width: 1px; + text-align: center; + border-collapse: collapse; + font-size: 12px; +} + +.pageTable th { + background-color: #F2F2F6; + border-left:1px solid #555; + border-right: 1px solid #777; + border-top: 1px solid #555; + +} + +.dialogTable0{ + /* + border-style: solid; + border-width: 2px; + border-color: #485297;*/ + margin: 5px 5px 5px 5px; + +} + +.dialogTable0 hr{ + border:solid #485297 2px; +} + +.dialogTable0 label{ + font-size: 15px; +} + +.dialogTable tr:nth-child(odd) { + background:#ebebeb; +} + +.dialogTable{ + margin-top: 5px; + margin-bottom: 5px; +} + +.tableTitle{ + + font-size: 14px; + color: black; + font-weight: bold; + position: relative; +} + +.sortTable td{ + border-style: none; +} + +.sortTable tr{ + background: none !important; + +} + +#login { + background-color: #fcf2df; + color: black; + font-size: 11px; + height: 25px; + margin: 0 auto; + padding-bottom: 2px; + width: 80%; +} + +#loginContent { + float: right; + width: 600px; + font-size: 12px; +} + +/* MENU */ + +div.menu +{ + /*width:500px;margin:0 auto;*//*Uncomment this line to make the menu center-aligned.*/ + text-align:center; + background-color: white; + font-size:0; + width: 80%; + margin-left: auto; + margin-right: auto; + margin-bottom: 10px; + +} + +div.menu a +{ + + display: inline-block; + padding: 0 20px; + background-color: white; + color:black; + text-decoration:none; + font: bold 12px Arial; + line-height: 32px; +} + +div.menu a:hover, div.menu2 a.current +{ + background-color: #C2E0FF; +} + +div.menu a.dummy +{ + width:2px; + padding:0 0; +} \ No newline at end of file diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/arrow-ff.gif Binary file src/main/webapp/resources/images/arrow-ff.gif has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/arrow-first.gif Binary file src/main/webapp/resources/images/arrow-first.gif has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/arrow-fr.gif Binary file src/main/webapp/resources/images/arrow-fr.gif has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/arrow-last.gif Binary file src/main/webapp/resources/images/arrow-last.gif has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/arrow-next.gif Binary file src/main/webapp/resources/images/arrow-next.gif has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/arrow-previous.gif Binary file src/main/webapp/resources/images/arrow-previous.gif has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/branch_details_16.png Binary file src/main/webapp/resources/images/branch_details_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/branch_details_32.png Binary file src/main/webapp/resources/images/branch_details_32.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/delete_16.png Binary file src/main/webapp/resources/images/delete_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/down_16.png Binary file src/main/webapp/resources/images/down_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/down_20.png Binary file src/main/webapp/resources/images/down_20.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/edit_16.png Binary file src/main/webapp/resources/images/edit_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/edit_32.png Binary file src/main/webapp/resources/images/edit_32.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/edit_branch_16.png Binary file src/main/webapp/resources/images/edit_branch_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/edit_branch_32.png Binary file src/main/webapp/resources/images/edit_branch_32.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/filter_16.png Binary file src/main/webapp/resources/images/filter_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/filter_24.png Binary file src/main/webapp/resources/images/filter_24.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/more_info_16.png Binary file src/main/webapp/resources/images/more_info_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/new_branch_16.png Binary file src/main/webapp/resources/images/new_branch_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/new_branch_32.png Binary file src/main/webapp/resources/images/new_branch_32.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/publish_16.png Binary file src/main/webapp/resources/images/publish_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/publish_32.png Binary file src/main/webapp/resources/images/publish_32.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/search_16.png Binary file src/main/webapp/resources/images/search_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/search_32.png Binary file src/main/webapp/resources/images/search_32.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/search_64.png Binary file src/main/webapp/resources/images/search_64.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/show_16.png Binary file src/main/webapp/resources/images/show_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/show_32.png Binary file src/main/webapp/resources/images/show_32.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/up_16.png Binary file src/main/webapp/resources/images/up_16.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/images/up_20.png Binary file src/main/webapp/resources/images/up_20.png has changed diff -r 000000000000 -r 3e62083dbcbf src/main/webapp/resources/js/bootstrap.min.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/resources/js/bootstrap.min.js Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,6 @@ +/*! +* Bootstrap.js by @fat & @mdo +* Copyright 2012 Twitter, Inc. +* http://www.apache.org/licenses/LICENSE-2.0.txt +*/ +!function(e){"use strict";e(function(){e.support.transition=function(){var e=function(){var e=document.createElement("bootstrap"),t={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"},n;for(n in t)if(e.style[n]!==undefined)return t[n]}();return e&&{end:e}}()})}(window.jQuery),!function(e){"use strict";var t='[data-dismiss="alert"]',n=function(n){e(n).on("click",t,this.close)};n.prototype.close=function(t){function s(){i.trigger("closed").remove()}var n=e(this),r=n.attr("data-target"),i;r||(r=n.attr("href"),r=r&&r.replace(/.*(?=#[^\s]*$)/,"")),i=e(r),t&&t.preventDefault(),i.length||(i=n.hasClass("alert")?n:n.parent()),i.trigger(t=e.Event("close"));if(t.isDefaultPrevented())return;i.removeClass("in"),e.support.transition&&i.hasClass("fade")?i.on(e.support.transition.end,s):s()};var r=e.fn.alert;e.fn.alert=function(t){return this.each(function(){var r=e(this),i=r.data("alert");i||r.data("alert",i=new n(this)),typeof t=="string"&&i[t].call(r)})},e.fn.alert.Constructor=n,e.fn.alert.noConflict=function(){return e.fn.alert=r,this},e(document).on("click.alert.data-api",t,n.prototype.close)}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.options=e.extend({},e.fn.button.defaults,n)};t.prototype.setState=function(e){var t="disabled",n=this.$element,r=n.data(),i=n.is("input")?"val":"html";e+="Text",r.resetText||n.data("resetText",n[i]()),n[i](r[e]||this.options[e]),setTimeout(function(){e=="loadingText"?n.addClass(t).attr(t,t):n.removeClass(t).removeAttr(t)},0)},t.prototype.toggle=function(){var e=this.$element.closest('[data-toggle="buttons-radio"]');e&&e.find(".active").removeClass("active"),this.$element.toggleClass("active")};var n=e.fn.button;e.fn.button=function(n){return this.each(function(){var r=e(this),i=r.data("button"),s=typeof n=="object"&&n;i||r.data("button",i=new t(this,s)),n=="toggle"?i.toggle():n&&i.setState(n)})},e.fn.button.defaults={loadingText:"loading..."},e.fn.button.Constructor=t,e.fn.button.noConflict=function(){return e.fn.button=n,this},e(document).on("click.button.data-api","[data-toggle^=button]",function(t){var n=e(t.target);n.hasClass("btn")||(n=n.closest(".btn")),n.button("toggle")})}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.$indicators=this.$element.find(".carousel-indicators"),this.options=n,this.options.pause=="hover"&&this.$element.on("mouseenter",e.proxy(this.pause,this)).on("mouseleave",e.proxy(this.cycle,this))};t.prototype={cycle:function(t){return t||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(e.proxy(this.next,this),this.options.interval)),this},getActiveIndex:function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(),this.$items.index(this.$active)},to:function(t){var n=this.getActiveIndex(),r=this;if(t>this.$items.length-1||t<0)return;return this.sliding?this.$element.one("slid",function(){r.to(t)}):n==t?this.pause().cycle():this.slide(t>n?"next":"prev",e(this.$items[t]))},pause:function(t){return t||(this.paused=!0),this.$element.find(".next, .prev").length&&e.support.transition.end&&(this.$element.trigger(e.support.transition.end),this.cycle(!0)),clearInterval(this.interval),this.interval=null,this},next:function(){if(this.sliding)return;return this.slide("next")},prev:function(){if(this.sliding)return;return this.slide("prev")},slide:function(t,n){var r=this.$element.find(".item.active"),i=n||r[t](),s=this.interval,o=t=="next"?"left":"right",u=t=="next"?"first":"last",a=this,f;this.sliding=!0,s&&this.pause(),i=i.length?i:this.$element.find(".item")[u](),f=e.Event("slide",{relatedTarget:i[0],direction:o});if(i.hasClass("active"))return;this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var t=e(a.$indicators.children()[a.getActiveIndex()]);t&&t.addClass("active")}));if(e.support.transition&&this.$element.hasClass("slide")){this.$element.trigger(f);if(f.isDefaultPrevented())return;i.addClass(t),i[0].offsetWidth,r.addClass(o),i.addClass(o),this.$element.one(e.support.transition.end,function(){i.removeClass([t,o].join(" ")).addClass("active"),r.removeClass(["active",o].join(" ")),a.sliding=!1,setTimeout(function(){a.$element.trigger("slid")},0)})}else{this.$element.trigger(f);if(f.isDefaultPrevented())return;r.removeClass("active"),i.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return s&&this.cycle(),this}};var n=e.fn.carousel;e.fn.carousel=function(n){return this.each(function(){var r=e(this),i=r.data("carousel"),s=e.extend({},e.fn.carousel.defaults,typeof n=="object"&&n),o=typeof n=="string"?n:s.slide;i||r.data("carousel",i=new t(this,s)),typeof n=="number"?i.to(n):o?i[o]():s.interval&&i.pause().cycle()})},e.fn.carousel.defaults={interval:5e3,pause:"hover"},e.fn.carousel.Constructor=t,e.fn.carousel.noConflict=function(){return e.fn.carousel=n,this},e(document).on("click.carousel.data-api","[data-slide], [data-slide-to]",function(t){var n=e(this),r,i=e(n.attr("data-target")||(r=n.attr("href"))&&r.replace(/.*(?=#[^\s]+$)/,"")),s=e.extend({},i.data(),n.data()),o;i.carousel(s),(o=n.attr("data-slide-to"))&&i.data("carousel").pause().to(o).cycle(),t.preventDefault()})}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.options=e.extend({},e.fn.collapse.defaults,n),this.options.parent&&(this.$parent=e(this.options.parent)),this.options.toggle&&this.toggle()};t.prototype={constructor:t,dimension:function(){var e=this.$element.hasClass("width");return e?"width":"height"},show:function(){var t,n,r,i;if(this.transitioning||this.$element.hasClass("in"))return;t=this.dimension(),n=e.camelCase(["scroll",t].join("-")),r=this.$parent&&this.$parent.find("> .accordion-group > .in");if(r&&r.length){i=r.data("collapse");if(i&&i.transitioning)return;r.collapse("hide"),i||r.data("collapse",null)}this.$element[t](0),this.transition("addClass",e.Event("show"),"shown"),e.support.transition&&this.$element[t](this.$element[0][n])},hide:function(){var t;if(this.transitioning||!this.$element.hasClass("in"))return;t=this.dimension(),this.reset(this.$element[t]()),this.transition("removeClass",e.Event("hide"),"hidden"),this.$element[t](0)},reset:function(e){var t=this.dimension();return this.$element.removeClass("collapse")[t](e||"auto")[0].offsetWidth,this.$element[e!==null?"addClass":"removeClass"]("collapse"),this},transition:function(t,n,r){var i=this,s=function(){n.type=="show"&&i.reset(),i.transitioning=0,i.$element.trigger(r)};this.$element.trigger(n);if(n.isDefaultPrevented())return;this.transitioning=1,this.$element[t]("in"),e.support.transition&&this.$element.hasClass("collapse")?this.$element.one(e.support.transition.end,s):s()},toggle:function(){this[this.$element.hasClass("in")?"hide":"show"]()}};var n=e.fn.collapse;e.fn.collapse=function(n){return this.each(function(){var r=e(this),i=r.data("collapse"),s=e.extend({},e.fn.collapse.defaults,r.data(),typeof n=="object"&&n);i||r.data("collapse",i=new t(this,s)),typeof n=="string"&&i[n]()})},e.fn.collapse.defaults={toggle:!0},e.fn.collapse.Constructor=t,e.fn.collapse.noConflict=function(){return e.fn.collapse=n,this},e(document).on("click.collapse.data-api","[data-toggle=collapse]",function(t){var n=e(this),r,i=n.attr("data-target")||t.preventDefault()||(r=n.attr("href"))&&r.replace(/.*(?=#[^\s]+$)/,""),s=e(i).data("collapse")?"toggle":n.data();n[e(i).hasClass("in")?"addClass":"removeClass"]("collapsed"),e(i).collapse(s)})}(window.jQuery),!function(e){"use strict";function r(){e(".dropdown-backdrop").remove(),e(t).each(function(){i(e(this)).removeClass("open")})}function i(t){var n=t.attr("data-target"),r;n||(n=t.attr("href"),n=n&&/#/.test(n)&&n.replace(/.*(?=#[^\s]*$)/,"")),r=n&&e(n);if(!r||!r.length)r=t.parent();return r}var t="[data-toggle=dropdown]",n=function(t){var n=e(t).on("click.dropdown.data-api",this.toggle);e("html").on("click.dropdown.data-api",function(){n.parent().removeClass("open")})};n.prototype={constructor:n,toggle:function(t){var n=e(this),s,o;if(n.is(".disabled, :disabled"))return;return s=i(n),o=s.hasClass("open"),r(),o||("ontouchstart"in document.documentElement&&e('