1
|
|
2
|
package eu.dnetlib.goldoa.service.dao;
|
3
|
|
4
|
import eu.dnetlib.goldoa.domain.*;
|
5
|
import eu.dnetlib.goldoa.service.PublicationManagerImpl;
|
6
|
import eu.dnetlib.goldoa.service.UserManagerImpl;
|
7
|
import org.apache.commons.codec.digest.DigestUtils;
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.hibernate.criterion.Restrictions;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
12
|
import org.springframework.stereotype.Repository;
|
13
|
|
14
|
import javax.sql.DataSource;
|
15
|
import java.math.BigInteger;
|
16
|
import java.sql.PreparedStatement;
|
17
|
import java.sql.ResultSet;
|
18
|
import java.sql.SQLException;
|
19
|
import java.sql.Types;
|
20
|
import java.util.ArrayList;
|
21
|
import java.util.List;
|
22
|
|
23
|
@Repository
|
24
|
public class PublicationDAO extends AbstractDao<String,Publication>{
|
25
|
|
26
|
private static Logger logger = Logger.getLogger(PublicationDAO.class);
|
27
|
|
28
|
@SuppressWarnings("unchecked")
|
29
|
public Publication getPublication(final String publicationId) {
|
30
|
List<Publication> ps = createEntityCriteria().add(Restrictions.eq("id",publicationId)).list();
|
31
|
if(ps.size() > 0)
|
32
|
return ps.get(0);
|
33
|
return null;
|
34
|
}
|
35
|
|
36
|
public Publication savePublication(Publication publication) {
|
37
|
|
38
|
for(Author a : publication.getAuthors())
|
39
|
a.setId(DigestUtils.md5Hex(a.getFirstname()+ a.getLastname() + a.getEmail() +
|
40
|
(a.getOrganization()!=null?a.getOrganization().getId():"") +
|
41
|
(a.getDepartment()!=null?a.getDepartment():"")
|
42
|
) + publication.getId());
|
43
|
|
44
|
Publication p = getPublication(publication.getId());
|
45
|
Publication pub_merged = null;
|
46
|
|
47
|
if(p!=null)
|
48
|
pub_merged = (Publication) getSession().merge(publication);
|
49
|
else
|
50
|
persist(publication);
|
51
|
|
52
|
|
53
|
return publication;
|
54
|
}
|
55
|
|
56
|
public BigInteger generateIdentifierID() {
|
57
|
return (BigInteger) getSession().createSQLQuery("select nextval('identifier_id_seq') as id").list().get(0);
|
58
|
}
|
59
|
}
|