1
|
package eu.dnetlib.data.claims;
|
2
|
|
3
|
import eu.dnetlib.data.claims.entity.Claim;
|
4
|
import eu.dnetlib.data.claims.handler.ClaimHandler;
|
5
|
import eu.dnetlib.data.claims.handler.FetchClaimHandler;
|
6
|
import eu.dnetlib.data.claims.sql.SQLStoreException;
|
7
|
import org.apache.logging.log4j.Level;
|
8
|
import org.apache.logging.log4j.LogManager;
|
9
|
import org.apache.logging.log4j.Logger;
|
10
|
import org.apache.logging.log4j.core.config.Configurator;
|
11
|
import org.apache.logging.log4j.core.config.DefaultConfiguration;
|
12
|
import org.junit.Before;
|
13
|
import org.junit.Test;
|
14
|
import org.junit.runner.RunWith;
|
15
|
import org.springframework.context.ApplicationContext;
|
16
|
import org.springframework.context.annotation.PropertySource;
|
17
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
18
|
import org.springframework.test.context.ContextConfiguration;
|
19
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
20
|
|
21
|
import java.io.PrintWriter;
|
22
|
import java.util.ArrayList;
|
23
|
import java.util.List;
|
24
|
|
25
|
@RunWith(SpringJUnit4ClassRunner.class)
|
26
|
@ContextConfiguration(locations = {"springContext-claims.xml"})
|
27
|
@PropertySource("springContext-claims.properties")
|
28
|
public class CopyFromBetaTest {
|
29
|
private Logger log = LogManager.getLogger(this.getClass());
|
30
|
ClaimHandler claimHandler = null;
|
31
|
FetchClaimHandler fetchClaimHandler = null;
|
32
|
private PrintWriter out;
|
33
|
|
34
|
|
35
|
@Before
|
36
|
public void init() throws Exception {
|
37
|
Configurator.initialize(new DefaultConfiguration());
|
38
|
Configurator.setRootLevel(Level.INFO);
|
39
|
ApplicationContext context = new ClassPathXmlApplicationContext("eu/dnetlib/data/claims/springContext-claims.xml");
|
40
|
claimHandler = context.getBean(ClaimHandler.class);
|
41
|
fetchClaimHandler = context.getBean(FetchClaimHandler.class);
|
42
|
|
43
|
}
|
44
|
@Test
|
45
|
public void CopyFromBetaToProduction(){
|
46
|
try {
|
47
|
ArrayList<String> communities = new ArrayList<>();
|
48
|
// 5 connect communities: 793 - done
|
49
|
// communities.add("ee");
|
50
|
// communities.add("mes");
|
51
|
// communities.add("fam");
|
52
|
// communities.add("ni");
|
53
|
// communities.add("dh-ch");
|
54
|
|
55
|
//2nd group - 1073 - done
|
56
|
//duplicates ids [20587 -22214]
|
57
|
// select id, source_id, claimed_in_dashboard from claim where id>20586 and id < 22215 and (source_id like 'elixir-gr%' or source_id like 'enermaps%' or source_id like 'dariah%' or source_id like 'science-innovation-policy%' or source_id like 'oa-pg%');
|
58
|
// communities.add("elixir-gr");
|
59
|
// communities.add("enermaps");
|
60
|
// communities.add("dariah");
|
61
|
// communities.add("science-innovation-policy");
|
62
|
// communities.add("oa-pg");
|
63
|
|
64
|
// 3rd group - 555 - done
|
65
|
// communities.add("egi");
|
66
|
// communities.add("rda");
|
67
|
|
68
|
|
69
|
// 4th group - 32673 - done
|
70
|
// communities.add("covid-19");
|
71
|
String startDate = "2018-03-01";
|
72
|
String endDate = "2020-11-24";
|
73
|
|
74
|
//local
|
75
|
fetchClaimHandler.getSqlDAO().getSqlStore().setDbUrl("jdbc:postgresql://localhost:5432/claims_beta");
|
76
|
//beta
|
77
|
// fetchClaimHandler.getSqlDAO().getSqlStore().setDbUser("dnet");
|
78
|
// fetchClaimHandler.getSqlDAO().getSqlStore().setDbPassword("dnetPwd");
|
79
|
// fetchClaimHandler.getSqlDAO().getSqlStore().setDbUrl("jdbc:postgresql://beta.services.openaire.eu:5432/dnet_openaireplus");
|
80
|
List<Claim> claims = fetchClaimHandler.fetchClaimsByDateForDashboards(startDate,endDate, null,null,true, communities);
|
81
|
System.out.println("Beta claims: ");
|
82
|
System.out.println(claims.size());
|
83
|
|
84
|
// fetchClaimHandler.getSqlDAO().getSqlStore().setDbUser("postgres");
|
85
|
// fetchClaimHandler.getSqlDAO().getSqlStore().setDbPassword("snowflakes");
|
86
|
// claimHandler.getSqlDAO().getSqlStore().setDbUrl("jdbc:postgresql://localhost:5432/movedb");
|
87
|
//prod
|
88
|
claimHandler.getSqlDAO().getSqlStore().setDbUser("dnet");
|
89
|
claimHandler.getSqlDAO().getSqlStore().setDbPassword("dnetPwd");
|
90
|
claimHandler.getSqlDAO().getSqlStore().setDbUrl("jdbc:postgresql://postgresql.services.openaire.eu:5432/dnet_openaireplus");
|
91
|
/* out = new PrintWriter(new BufferedWriter(new FileWriter("/home/argirok/claims_migration/claims_migratedFromBeta_record_paths.txt", true)));
|
92
|
|
93
|
for (Claim claim : claims) {
|
94
|
|
95
|
if(out!=null) {
|
96
|
if(!claim.getTargetType().equals("project") && !claim.getTargetType().equals("context")){
|
97
|
System.out.println(((Result)claim.getTarget()).getRecordPath());
|
98
|
out.println("cp beta_records/" + ((Result)claim.getTarget()).getRecordPath() + " records/"+((Result)claim.getTarget()).getRecordPath());
|
99
|
}
|
100
|
if(!claim.getSourceType().equals("project") && !claim.getSourceType().equals("context")){
|
101
|
System.out.println(((Result)claim.getSource()).getRecordPath());
|
102
|
out.println("cp beta_records/" + ((Result)claim.getSource()).getRecordPath() + " records/"+((Result)claim.getSource()).getRecordPath());
|
103
|
}
|
104
|
|
105
|
}
|
106
|
|
107
|
System.out.println(claim.getId());
|
108
|
// claimHandler.saveClaim(claim);
|
109
|
}
|
110
|
if(out!=null) {
|
111
|
out.close();
|
112
|
}*/
|
113
|
// List<Claim> claimsmoveDB = fetchClaimHandler.countAllClaims(startDate,endDate, null, null, true);
|
114
|
// System.out.println("Prod claims:");
|
115
|
// System.out.println(claimsmoveDB.size());
|
116
|
|
117
|
|
118
|
} catch (Exception | SQLStoreException e) {
|
119
|
log.error("Error in migration",e);
|
120
|
|
121
|
}
|
122
|
|
123
|
}
|
124
|
|
125
|
}
|