Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Provenance Filter in FreieSuche #257

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 47 additions & 11 deletions src/main/java/de/uni_tuebingen/ub/nppm/db/SucheDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.persistence.criteria.Root;
import javax.persistence.Tuple;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
import org.hibernate.Session;
Expand Down Expand Up @@ -89,23 +90,58 @@ public static List<Map<String, String>> getSearchResult(String fieldsString, Str

try (Session session = getSession()) {
NativeQuery sqlQuery = session.createNativeQuery(sql);
List<Object[]> rows = sqlQuery.getResultList();
List<?> rows = sqlQuery.getResultList();
//return var
List<Map<String, String>> ret = new ArrayList<>();
//loop over the rows
for (Object[] row : rows) {
//convert the fields from the row to a map
Map<String, String> fieldVal = new HashMap<>();
for (int i = 0; i < fields.length; i++) {
String[] name = fields[i].split(" AS ");

//determine the first element which is not null
//this is necessary to get the type of the return class
Object firstElement = null;
for(Object o : rows){
if(o != null){
firstElement = o;
break;
}
}
/*
the return value is from type Object[]
This means that the array fields has more than one element
and we need to iterate over it
*/
if(firstElement instanceof Object[]){
//loop over the rows
for (Object[] row : (List<Object[]>) rows) {
//convert the fields from the row to a map
Map<String, String> fieldVal = new HashMap<>();
for (int i = 0; i < fields.length; i++) {
String[] name = fields[i].split(" AS ");
if (name.length == 2) {
fields[i] = name[1];
}
if (row != null && row[i] != null) {
fieldVal.put(fields[i].trim(), row[i].toString());
}
}
ret.add(fieldVal);
}
/*
the return value is from type Object
This means that the array fields has only one element
and we dont need to iterate over it
*/
}else if(firstElement instanceof Object){
for (Object row : (List<Object>) rows) {
//convert the fields from the row to a map
Map<String, String> fieldVal = new HashMap<>();
String[] name = fields[0].split(" AS ");
if (name.length == 2) {
fields[i] = name[1];
fields[0] = name[1];
}
if (row[i] != null) {
fieldVal.put(fields[i].trim(), row[i].toString());
if (row != null) {
fieldVal.put(fields[0].trim(), row.toString());
}
ret.add(fieldVal);
}
ret.add(fieldVal);
}

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@MappedSuperclass
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public abstract class SelektionProvenance extends SelektionBezeichnung {
public abstract class SelektionAbstractProvenance extends SelektionBezeichnung {
@Column(name = "provenance_source")
private String provenanceSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_angabe")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
class SelektionAngabe extends SelektionProvenance {
class SelektionAngabe extends SelektionAbstractProvenance {

@ManyToMany(mappedBy = "angaben")
private Set<Einzelbeleg> einzelbelege = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_areal")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionAreal extends SelektionProvenance {
public class SelektionAreal extends SelektionAbstractProvenance {

@ManyToMany(mappedBy = "areal")
private Set<Person> personen = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_arealtyp")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionArealTyp extends SelektionProvenance {
public class SelektionArealTyp extends SelektionAbstractProvenance {
@ManyToMany(mappedBy = "arealTyp")
private Set<Einzelbeleg> einzelbelege = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Table(name = "selektion_bearbeitungsstatus")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionBearbeitungsstatus extends SelektionProvenance {
public class SelektionBearbeitungsstatus extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Table(name = "selektion_bewertung")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionBewertung extends SelektionProvenance {
public class SelektionBewertung extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Table(name = "selektion_beziehung_gemeinschaft")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionBeziehungGemeinschaft extends SelektionProvenance{
public class SelektionBeziehungGemeinschaft extends SelektionAbstractProvenance{

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Table(name = "selektion_bkz")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionBkz extends SelektionProvenance {
public class SelektionBkz extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Table(name = "selektion_datgenauigkeit")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionDatGenauigkeit extends SelektionProvenance {
public class SelektionDatGenauigkeit extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Table(name = "selektion_dmghband")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionDmghBand extends SelektionProvenance {
public class SelektionDmghBand extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Table(name = "selektion_echtheit")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionEchtheit extends SelektionProvenance {
public class SelektionEchtheit extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_editor")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionEditor extends SelektionProvenance {
public class SelektionEditor extends SelektionAbstractProvenance {

@Column(name = "Nachname", length = 50)
private String nachname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_ethnie")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionEthnie extends SelektionProvenance {
public class SelektionEthnie extends SelektionAbstractProvenance {
@ManyToMany(mappedBy = "ethnie")
private Set<Person> personen = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_ethnienerhalt")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionEthnienErhalt extends SelektionProvenance {
public class SelektionEthnienErhalt extends SelektionAbstractProvenance {
@ManyToMany(mappedBy = "ethnieErhalt")
private Set<Person> personen = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_funktion")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionFunktion extends SelektionProvenance {
public class SelektionFunktion extends SelektionAbstractProvenance {
@ManyToMany(mappedBy = "funktion")
private Set<Einzelbeleg> einzelbeleg = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Table(name = "selektion_geschlecht")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionGeschlecht extends SelektionProvenance {
public class SelektionGeschlecht extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Table(name = "selektion_grammatikgeschlecht")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionGrammatikgeschlecht extends SelektionProvenance {
public class SelektionGrammatikgeschlecht extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Table(name = "selektion_janein")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionJaNein extends SelektionProvenance {
public class SelektionJaNein extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Table(name = "selektion_kasus")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionKasus extends SelektionProvenance {
public class SelektionKasus extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_kritik")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionKritik extends SelektionProvenance {
public class SelektionKritik extends SelektionAbstractProvenance {

@ManyToMany(mappedBy = "titelKritiken")
private Set<Einzelbeleg> einzelbelege = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Table(name = "selektion_lebendverstorben")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionLebendVerstorben extends SelektionProvenance {
public class SelektionLebendVerstorben extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Table(name = "selektion_ort")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionOrt extends SelektionProvenance {
public class SelektionOrt extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.uni_tuebingen.ub.nppm.model;

import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "selektion_provenienz")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionProvenienz extends SelektionBezeichnung{

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Table(name = "selektion_reihe")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionReihe extends SelektionProvenance {
public class SelektionReihe extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Table(name = "selektion_sammelband")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionSammelband extends SelektionProvenance {
public class SelektionSammelband extends SelektionAbstractProvenance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Table(name = "selektion_urkundeausstellerempfaenger")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionUrkundeAusstellerEmpfaenger extends SelektionProvenance {
public class SelektionUrkundeAusstellerEmpfaenger extends SelektionAbstractProvenance {
@ManyToMany(mappedBy = "empfaenger")
private Set<Urkunde> urkundeEmpfaenger = new HashSet<Urkunde>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@Table(name = "selektion_verwandtschaftsgrad")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SelektionVerwandtschaftsgrad extends SelektionProvenance {
public class SelektionVerwandtschaftsgrad extends SelektionAbstractProvenance {

}
42 changes: 41 additions & 1 deletion src/main/webapp/freie_suche.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
</jsp:include>
</td>
</tr>

<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th width="200" valign="top">
Expand Down Expand Up @@ -238,6 +239,7 @@
Format: 6Jh2, 750, 750-810, 5Jh1-7Jh2
</td>
</tr>

<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th width="200" valign="top">
Expand Down Expand Up @@ -338,6 +340,19 @@
<% Language.printTextfield(out,session, formular,"Datumsformat");%>: 6Jh2, 750, 750-810, 5Jh1-7Jh2
</td>
</tr>
<!-- Provenance information Einzelbeleg-->
<tr>
<th width="200" valign="top">
<% Language.printDatafield(out,session, formular,"ProvenanceEinzelbeleg");%>
</th>
<td width="450">
<jsp:include page="inc.erzeugeFormular.jsp">
<jsp:param name="Formular" value="freie_suche"/>
<jsp:param name="Datenfeld" value="ProvenanceEinzelbeleg"/>
</jsp:include>
</td>
</tr>

</tbody>
</table>
<!--p>&nbsp;<font color="red">*</font> <br>
Expand Down Expand Up @@ -436,7 +451,21 @@
<td width="350" valign="top">
<% Language.printDatafield(out,session, formular,"Ausgabe_MGHLemma");%>
</td>
</tr> <tr><td colspan="2">&nbsp;</td></tr>
</tr>

<tr>
<td width="25">
<jsp:include page="inc.erzeugeFormular.jsp">
<jsp:param name="Formular" value="freie_suche"/>
<jsp:param name="Datenfeld" value="Ausgabe_Provenance_Lemma"/>
</jsp:include>
</td>
<td width="350" valign="top">
<% Language.printDatafield(out,session, formular,"Ausgabe_Provenance_Lemma");%>
</td>
</tr>

<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2"><h3>
<% Language.printTextfield(out,session, formular,"ZurPerson");%>
</h3></td></tr>
Expand Down Expand Up @@ -700,6 +729,17 @@
<font color="red">*</font>
</td>
</tr>
<tr>
<td width="25">
<jsp:include page="inc.erzeugeFormular.jsp">
<jsp:param name="Formular" value="freie_suche"/>
<jsp:param name="Datenfeld" value="Ausgabe_Provenance_Einzelbeleg"/>
</jsp:include>
</td>
<td width="350" valign="top">
<% Language.printDatafield(out,session, formular,"Ausgabe_Provenance_Einzelbeleg");%>
</td>
</tr>
</tbody>
</table>
<p>
Expand Down
Loading