1
|
package eu.dnetlib.data.claims;
|
2
|
|
3
|
import eu.dnetlib.data.claims.entity.Claim;
|
4
|
import eu.dnetlib.data.claims.entity.Result;
|
5
|
import eu.dnetlib.data.claims.handler.*;
|
6
|
import eu.dnetlib.data.claims.sql.SQLStoreException;
|
7
|
import eu.dnetlib.data.claims.utils.*;
|
8
|
import org.apache.log4j.BasicConfigurator;
|
9
|
import org.apache.log4j.Level;
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.junit.Before;
|
12
|
import org.junit.Test;
|
13
|
import org.junit.runner.RunWith;
|
14
|
import org.springframework.context.ApplicationContext;
|
15
|
import org.springframework.context.annotation.PropertySource;
|
16
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
17
|
import org.springframework.test.context.ContextConfiguration;
|
18
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
19
|
|
20
|
import java.io.BufferedWriter;
|
21
|
import java.io.FileWriter;
|
22
|
import java.io.PrintWriter;
|
23
|
import java.util.ArrayList;
|
24
|
import java.util.List;
|
25
|
|
26
|
import static junit.framework.Assert.assertNotNull;
|
27
|
|
28
|
@RunWith(SpringJUnit4ClassRunner.class)
|
29
|
@ContextConfiguration(locations = {"springContext-claims.xml"})
|
30
|
@PropertySource("springContext-claims.properties")
|
31
|
public class CopyFromBetaTest {
|
32
|
private Logger log = Logger.getLogger(this.getClass());
|
33
|
ClaimHandler claimHandler = null;
|
34
|
FetchClaimHandler fetchClaimHandler = null;
|
35
|
private PrintWriter out;
|
36
|
|
37
|
|
38
|
@Before
|
39
|
public void init() throws Exception {
|
40
|
BasicConfigurator.configure();
|
41
|
ApplicationContext context = new ClassPathXmlApplicationContext("eu/dnetlib/data/claims/springContext-claims.xml");
|
42
|
claimHandler = context.getBean(ClaimHandler.class);
|
43
|
fetchClaimHandler = context.getBean(FetchClaimHandler.class);
|
44
|
|
45
|
}
|
46
|
@Test
|
47
|
public void CopyFromBetaToProduction(){
|
48
|
log.setLevel(Level.ERROR);
|
49
|
QueryGenerator q = new QueryGenerator();
|
50
|
System.out.println(q.generateCreateClaimTablesQuery());
|
51
|
try {
|
52
|
|
53
|
|
54
|
fetchClaimHandler.getQueryGenerator().setMigrationTable("claims_beta");
|
55
|
ArrayList<String> communities = new ArrayList<>();
|
56
|
communities.add("ee");
|
57
|
// communities.add("mes");
|
58
|
// communities.add("fam");
|
59
|
// communities.add("ni");
|
60
|
// communities.add("dh-ch");
|
61
|
// communities.add("covid-19");
|
62
|
String startDate = "2018-03-01";
|
63
|
String endDate = "2020-11-22";
|
64
|
|
65
|
fetchClaimHandler.getSqlDAO().getSqlStore().setDbUrl("jdbc:postgresql://scoobydoo.di.uoa.gr:5432/claims_beta");
|
66
|
List<Claim> claims = fetchClaimHandler.fetchClaimsByDateForDashboards(startDate,endDate, null,null,true, communities);
|
67
|
System.out.println("Beta claims: ");
|
68
|
System.out.println(claims.size());
|
69
|
|
70
|
claimHandler.getSqlDAO().getSqlStore().setDbUrl("jdbc:postgresql://scoobydoo.di.uoa.gr:5432/movedb");
|
71
|
|
72
|
out = new PrintWriter(new BufferedWriter(new FileWriter("/home/argirok/claims_migratedFromBeta_record_paths.txt", true)));
|
73
|
|
74
|
for (Claim claim : claims) {
|
75
|
|
76
|
if(out!=null) {
|
77
|
if(!claim.getTargetType().equals("project") && !claim.getTargetType().equals("context")){
|
78
|
System.out.println(((Result)claim.getTarget()).getRecordPath());
|
79
|
out.println("cp beta_records/" + ((Result)claim.getTarget()).getRecordPath() + " records/"+((Result)claim.getTarget()).getRecordPath());
|
80
|
}
|
81
|
if(!claim.getSourceType().equals("project") && !claim.getSourceType().equals("context")){
|
82
|
System.out.println(((Result)claim.getSource()).getRecordPath());
|
83
|
out.println("cp beta_records/" + ((Result)claim.getSource()).getRecordPath() + " records/"+((Result)claim.getSource()).getRecordPath());
|
84
|
}
|
85
|
|
86
|
}
|
87
|
|
88
|
System.out.println(claim.getId());
|
89
|
// claimHandler.saveClaim(claim);
|
90
|
}
|
91
|
if(out!=null) {
|
92
|
out.close();
|
93
|
}
|
94
|
List<Claim> claimsmoveDB = fetchClaimHandler.fetchClaimsByDate(startDate,endDate, null, null, true);
|
95
|
System.out.println("Movedb claims:");
|
96
|
System.out.println(claimsmoveDB.size());
|
97
|
|
98
|
|
99
|
} catch (Exception | SQLStoreException e) {
|
100
|
log.error("Error in migration",e);
|
101
|
|
102
|
}
|
103
|
|
104
|
}
|
105
|
|
106
|
}
|