1
|
package eu.dnetlib.goldoa.service.dao;
|
2
|
|
3
|
//import eu.dnetlib.goldoa.domain.Currency;
|
4
|
|
5
|
import eu.dnetlib.goldoa.domain.Journal;
|
6
|
import org.apache.log4j.Logger;
|
7
|
import org.hibernate.criterion.Disjunction;
|
8
|
import org.hibernate.criterion.MatchMode;
|
9
|
import org.hibernate.criterion.Restrictions;
|
10
|
import org.springframework.stereotype.Repository;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
14
|
/**
|
15
|
* Created by antleb on 3/18/15.
|
16
|
*/
|
17
|
@Repository
|
18
|
public class JournalDAO extends AbstractDao<String,Journal>{
|
19
|
|
20
|
private static Logger logger = Logger.getLogger(JournalDAO.class);
|
21
|
@SuppressWarnings("unchecked")
|
22
|
public List<Object> search(String term) {
|
23
|
|
24
|
Disjunction d = Restrictions.disjunction();
|
25
|
d.add(Restrictions.ilike("alttitle",term, MatchMode.ANYWHERE));
|
26
|
d.add(Restrictions.ilike("title",term, MatchMode.ANYWHERE));
|
27
|
d.add(Restrictions.ilike("issn",term, MatchMode.ANYWHERE));
|
28
|
|
29
|
|
30
|
return createEntityCriteria().add(d).list();
|
31
|
}
|
32
|
|
33
|
@SuppressWarnings("unchecked")
|
34
|
public Journal getJournal(String id) {
|
35
|
List<Journal> rs = createEntityCriteria().add(Restrictions.eq("id",id)).list();
|
36
|
if(rs.isEmpty())
|
37
|
return null;
|
38
|
return rs.get(0);
|
39
|
}
|
40
|
|
41
|
@SuppressWarnings("unchecked")
|
42
|
public Journal getJournalByTitle(String title) {
|
43
|
List<Journal> rs = createEntityCriteria().add(Restrictions.eq("title",title)).list();
|
44
|
if(rs.size() > 0)
|
45
|
return rs.get(0);
|
46
|
return null;
|
47
|
}
|
48
|
|
49
|
public Journal saveJournal(Journal journal) {
|
50
|
logger.debug("save journal dao");
|
51
|
|
52
|
Journal j = getJournal(journal.getId());
|
53
|
Journal journal_merged = null;
|
54
|
|
55
|
if(j!=null)
|
56
|
journal_merged = (Journal) getSession().merge(journal);
|
57
|
else
|
58
|
persist(journal);
|
59
|
|
60
|
return journal;
|
61
|
}
|
62
|
}
|