Revision 41564
Added by Antonis Lempesis about 8 years ago
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/service/PublicationManagerImpl.java | ||
---|---|---|
195 | 195 |
|
196 | 196 |
publication.setLicense(root.path("message").path("license").path(0).path("URL").textValue()); |
197 | 197 |
|
198 |
System.out.println(publication.getLicense()); |
|
199 |
|
|
200 | 198 |
publication.setIdentifiers(new ArrayList<PublicationIdentifier>()); |
201 | 199 |
publication.getIdentifiers().add(new PublicationIdentifier("doi", doi)); |
202 | 200 |
} else { |
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/service/utils/LicenseUpdateTask.java | ||
---|---|---|
1 |
package eu.dnetlib.goldoa.service.utils; |
|
2 |
|
|
3 |
import eu.dnetlib.goldoa.domain.ManagerException; |
|
4 |
import eu.dnetlib.goldoa.domain.Publication; |
|
5 |
import eu.dnetlib.goldoa.domain.Request; |
|
6 |
import eu.dnetlib.goldoa.domain.stats.Tuple; |
|
7 |
import eu.dnetlib.goldoa.service.PublicationManager; |
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
9 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
10 |
import org.springframework.jdbc.core.RowMapper; |
|
11 |
|
|
12 |
import javax.sql.DataSource; |
|
13 |
import java.sql.ResultSet; |
|
14 |
import java.sql.SQLException; |
|
15 |
import java.sql.Types; |
|
16 |
import java.util.List; |
|
17 |
import java.util.logging.StreamHandler; |
|
18 |
|
|
19 |
/** |
|
20 |
* Created by antleb on 3/7/16. |
|
21 |
*/ |
|
22 |
public class LicenseUpdateTask implements Runnable { |
|
23 |
|
|
24 |
private static final String GET_MISSING_LICENSES = "select pub.id, pub.doi from publication pub join request r on r.publication=pub.id where doi is not null and license is null and r.status=" + Request.RequestStatus.ACCOUNTING_PAID.getCode(); |
|
25 |
private static final String UPDATE_LICENSE = "update publication set license=? where id=?"; |
|
26 |
|
|
27 |
private DataSource dataSource; |
|
28 |
private PublicationManager publicationManager; |
|
29 |
|
|
30 |
public LicenseUpdateTask(DataSource dataSource, PublicationManager publicationManager) { |
|
31 |
this.dataSource = dataSource; |
|
32 |
this.publicationManager = publicationManager; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public void run() { |
|
37 |
System.out.println("Updating paid request licenses!"); |
|
38 |
|
|
39 |
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); |
|
40 |
|
|
41 |
List<Tuple<String, String>> pubs = jdbcTemplate.query(GET_MISSING_LICENSES, new RowMapper<Tuple<String, String>>() { |
|
42 |
@Override |
|
43 |
public Tuple<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException { |
|
44 |
return new Tuple<String, String>(rs.getString("id"), rs.getString("doi")); |
|
45 |
} |
|
46 |
}); |
|
47 |
|
|
48 |
for (Tuple<String, String> pub:pubs) { |
|
49 |
try { |
|
50 |
Publication publication = publicationManager.resolveDOI(pub.getSecond()); |
|
51 |
|
|
52 |
if (publication.getLicense() != null) { |
|
53 |
jdbcTemplate.update(UPDATE_LICENSE, new String[] {publication.getLicense(), pub.getFirst()}, new int[] {Types.VARCHAR, Types.VARCHAR}); |
|
54 |
} |
|
55 |
} catch (ManagerException e) { |
|
56 |
System.out.print("Error updating license " + e.getErrorCause()); |
|
57 |
} catch (Exception e) { |
|
58 |
System.out.print("Error updating license " + e.getMessage()); |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
} |
modules/uoa-goldoa-service/trunk/src/main/java/eu/dnetlib/goldoa/service/utils/Scheduler.java | ||
---|---|---|
1 |
package eu.dnetlib.goldoa.service.utils; |
|
2 |
|
|
3 |
import eu.dnetlib.goldoa.service.PublicationManager; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.stereotype.Component; |
|
6 |
|
|
7 |
import javax.annotation.PostConstruct; |
|
8 |
import javax.sql.DataSource; |
|
9 |
import java.util.concurrent.Executors; |
|
10 |
import java.util.concurrent.ScheduledExecutorService; |
|
11 |
import java.util.concurrent.TimeUnit; |
|
12 |
|
|
13 |
/** |
|
14 |
* Created by antleb on 3/7/16. |
|
15 |
*/ |
|
16 |
public class Scheduler { |
|
17 |
|
|
18 |
@Autowired |
|
19 |
private DataSource dataSource; |
|
20 |
@Autowired |
|
21 |
private PublicationManager publicationManager; |
|
22 |
|
|
23 |
private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); |
|
24 |
|
|
25 |
@PostConstruct |
|
26 |
public void init() { |
|
27 |
|
|
28 |
executor.scheduleAtFixedRate(new LicenseUpdateTask(dataSource, publicationManager), 0, 3,TimeUnit.HOURS); |
|
29 |
} |
|
30 |
|
|
31 |
public void destroy() { |
|
32 |
executor.shutdown(); |
|
33 |
} |
|
34 |
} |
Also available in: Unified diff
added a period check for licenses based on doi