Revision 40941
Added by Argiro Kokogiannaki over 8 years ago
modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/Claim.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.claims.migration; |
2 | 2 |
|
3 |
import java.text.SimpleDateFormat; |
|
3 | 4 |
import java.util.Date; |
4 | 5 |
|
5 | 6 |
/** |
... | ... | |
79 | 80 |
|
80 | 81 |
@Override |
81 | 82 |
public String toString() { |
83 |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); |
|
82 | 84 |
return "Claim{" + |
83 | 85 |
"\ntarget={" + target.toString() + |
84 | 86 |
"},\n source={" + source.toString() + |
85 | 87 |
"},\n id='" + id + '\'' + |
86 | 88 |
", userMail='" + userMail + '\'' + |
87 |
", date=" + date.toString() +
|
|
89 |
", date=" + format.format(date)+
|
|
88 | 90 |
'}'; |
89 | 91 |
} |
90 | 92 |
} |
modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claims/migration/QueryOperations.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import eu.dnetlib.data.claimsDemo.ClaimOperations; |
4 | 4 |
import eu.dnetlib.data.claimsDemo.SqlDAO; |
5 |
import org.apache.log4j.BasicConfigurator; |
|
6 | 5 |
import org.apache.log4j.Logger; |
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
import org.springframework.test.context.ContextConfiguration; |
|
9 | 6 |
|
10 | 7 |
import java.sql.ResultSet; |
11 |
import java.util.Calendar; |
|
12 | 8 |
|
13 | 9 |
import static junit.framework.Assert.assertNotNull; |
14 | 10 |
|
... | ... | |
19 | 15 |
public class QueryOperations { |
20 | 16 |
|
21 | 17 |
private Logger log = Logger.getLogger(this.getClass()); |
18 |
private SqlDAO sqlDAO; |
|
22 | 19 |
private ClaimOperations claimOperations; |
23 |
private SqlDAO sqlDAO; |
|
24 | 20 |
|
25 | 21 |
public QueryOperations(){ |
26 |
// log.info(sqlDAO.getQueryGenerator().selectClaims()); |
|
27 | 22 |
} |
28 | 23 |
|
29 | 24 |
public void dropClaimTables() throws Exception { |
... | ... | |
37 | 32 |
while(rs.next()){ |
38 | 33 |
log.info(rs.getString("xml")); |
39 | 34 |
Claim claim=claimOperations.getConceptDMFClaim(rs); |
40 |
//log.info(claim.toString());
|
|
41 |
log.info(JsonldBuilder.toJsonld(claim)); |
|
35 |
log.info(claim.toString()); |
|
36 |
//log.info(JsonldBuilder.toJsonld(claim));
|
|
42 | 37 |
if(insertToDB) { |
43 |
log.info(claimOperations.getQueryInsertClaim(claim, sqlDAO));
|
|
44 |
//sqlDAO.executeUpdateQuery(claimOperations.getQueryInsertClaim(claim,sqlDAO));
|
|
38 |
log.info(claimOperations.getQueryInsertClaim(claim)); |
|
39 |
sqlDAO.executeUpdateQuery(claimOperations.getQueryInsertClaim(claim));
|
|
45 | 40 |
} |
46 | 41 |
} |
47 | 42 |
} |
... | ... | |
51 | 46 |
Claim claim = claimOperations.getRelationClaim(rs); |
52 | 47 |
log.info(claim.toString()); |
53 | 48 |
if(insertToDB) { |
54 |
sqlDAO.executeUpdateQuery(claimOperations.getQueryInsertClaim(claim, sqlDAO)); |
|
49 |
log.info(claimOperations.getQueryInsertClaim(claim)); |
|
50 |
sqlDAO.executeUpdateQuery(claimOperations.getQueryInsertClaim(claim)); |
|
55 | 51 |
} |
56 | 52 |
} |
57 | 53 |
} |
58 | 54 |
|
59 | 55 |
public void getAndTransformAllClaims(Integer limit, boolean insertToDB) throws Exception { |
60 | 56 |
ResultSet rs=sqlDAO.executePreparedQuery("Select * from claims_view limit "+limit); |
61 |
//ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectClaimById("169480")); |
|
57 |
transformAllClaims(insertToDB,rs); |
|
58 |
} |
|
59 |
public void getAndTransformClaimById(String id, boolean insertToDB) throws Exception { |
|
60 |
ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectClaimById(id)); |
|
61 |
transformAllClaims(insertToDB,rs); |
|
62 |
} |
|
63 |
public void transformAllClaims( boolean insertToDB, ResultSet rs) throws Exception { |
|
62 | 64 |
while(rs.next()){ |
63 | 65 |
String claimType=rs.getString("type"); |
64 | 66 |
String xml=rs.getString("xml"); |
65 | 67 |
if(claimType!=null && claimType.equals("rels2actions")){ |
66 | 68 |
log.info("*Relation *"); |
67 | 69 |
Claim claim=claimOperations.getRelationClaim(rs); |
68 |
log.info(JsonldBuilder.toJsonld(claim)); |
|
70 |
//log.info(JsonldBuilder.toJsonld(claim)); |
|
71 |
log.info(claim.toString()); |
|
69 | 72 |
if(insertToDB){ |
70 |
log.info(claimOperations.getQueryInsertClaim(claim, sqlDAO)); |
|
73 |
log.info(claimOperations.getQueryInsertClaim(claim)); |
|
74 |
// sqlDAO.executeUpdateQuery((claimOperations.getQueryInsertClaim(claim))); |
|
71 | 75 |
} |
72 | 76 |
}else{ |
73 | 77 |
//type ="dmf2actions" |
... | ... | |
76 | 80 |
Claim claim=claimOperations.getConceptDMFClaim(rs); |
77 | 81 |
log.info(claim.toString()); |
78 | 82 |
if(insertToDB){ |
79 |
log.info(claimOperations.getQueryInsertClaim(claim, sqlDAO)); |
|
83 |
log.info(claimOperations.getQueryInsertClaim(claim)); |
|
84 |
sqlDAO.executeUpdateQuery((claimOperations.getQueryInsertClaim(claim))); |
|
80 | 85 |
} |
81 | 86 |
}else{ |
82 | 87 |
log.info("* DMF *"); |
83 |
log.info(claimOperations.getDMFClaim(rs).toString()); |
|
88 |
// log.info(claimOperations.getDMFClaim(rs).toString());
|
|
84 | 89 |
} |
85 | 90 |
} |
86 | 91 |
} |
modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/TestClass.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
//import eu.dnetlib.data.claims.migration.Claim; |
9 | 9 |
|
10 |
import com.google.gson.Gson; |
|
11 |
import com.google.gson.GsonBuilder; |
|
12 |
import eu.dnetlib.data.claims.migration.*; |
|
13 |
|
|
14 |
import static junit.framework.Assert.assertNotNull; |
|
15 |
|
|
16 |
import java.io.IOException; |
|
17 |
import java.sql.ResultSet; |
|
18 |
import java.util.ArrayList; |
|
19 |
import java.util.List; |
|
20 |
|
|
21 |
import javax.xml.parsers.ParserConfigurationException; |
|
22 |
import javax.xml.xpath.XPathExpressionException; |
|
23 |
|
|
10 |
import eu.dnetlib.data.claims.migration.QueryOperations; |
|
11 |
import eu.dnetlib.data.claims.migration.Result; |
|
24 | 12 |
import org.apache.log4j.BasicConfigurator; |
25 | 13 |
import org.apache.log4j.Logger; |
26 | 14 |
import org.junit.Before; |
... | ... | |
31 | 19 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
32 | 20 |
import org.xml.sax.SAXException; |
33 | 21 |
|
34 |
import eu.dnetlib.data.claims.migration.Claim; |
|
35 |
import eu.dnetlib.data.claims.migration.JsonldBuilder; |
|
36 |
import eu.dnetlib.data.claims.migration.Result; |
|
22 |
import javax.xml.parsers.ParserConfigurationException; |
|
23 |
import javax.xml.xpath.XPathExpressionException; |
|
24 |
import java.io.BufferedWriter; |
|
25 |
import java.io.FileWriter; |
|
26 |
import java.io.IOException; |
|
27 |
import java.io.PrintWriter; |
|
28 |
import java.sql.Timestamp; |
|
29 |
import java.text.ParseException; |
|
30 |
import java.text.SimpleDateFormat; |
|
31 |
import java.util.Date; |
|
37 | 32 |
|
33 |
import static junit.framework.Assert.assertNotNull; |
|
34 |
|
|
38 | 35 |
/** |
39 | 36 |
* @author eri |
40 | 37 |
*/ |
... | ... | |
83 | 80 |
|
84 | 81 |
@Test |
85 | 82 |
public void transformClaims() throws Exception { |
86 |
queryOperations.getAndTransformAllClaims(5,false);
|
|
83 |
queryOperations.getAndTransformAllClaims(100,false);
|
|
87 | 84 |
} |
88 | 85 |
|
89 | 86 |
@Test |
90 | 87 |
public void getRelationClaims() throws Exception { |
91 |
queryOperations.getAndTransformRelationClaims(1,false);
|
|
88 |
queryOperations.getAndTransformRelationClaims(200,false);
|
|
92 | 89 |
} |
93 | 90 |
@Test |
94 | 91 |
public void getDMFClaims() throws Exception { |
... | ... | |
98 | 95 |
|
99 | 96 |
@Test |
100 | 97 |
public void buildResultById() throws Exception { |
101 |
Result r= ParsingClaimUtils.buildResult("od_______908::78d04355429972fa6ab43a5ebb9df0c8","publication");
|
|
98 |
Result r= ParsingClaimUtils.buildResult("datacite____::c33d24d689a29abb39f5261876c2a3ed","publication","");
|
|
102 | 99 |
log.info(r.toString()); |
103 | 100 |
} |
104 | 101 |
@Test |
105 | 102 |
public void getConceptDMFClaims() throws Exception { |
106 |
queryOperations.getAndTransformConceptClaims(1,false);
|
|
103 |
queryOperations.getAndTransformConceptClaims(203,true);
|
|
107 | 104 |
} |
108 |
//@Test |
|
109 |
public void checkForDMFDOIS() throws Exception { |
|
110 |
//Select * from claims where type='dmf2actions' and xml NOT ILIKE '%concept%' |
|
111 |
//ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectDMFClaims(10)); |
|
112 |
ResultSet rs=sqlDAO.executePreparedQuery("Select * from claims_view where type='dmf2actions' and xml ILIKE '%doi%' "); |
|
113 |
int i=0; |
|
114 |
//List<Result> dois=new ArrayList<Result>(); |
|
115 |
while(rs.next()){ |
|
116 |
i++; |
|
117 |
Result r=claimOperations.getDMFClaim(rs); |
|
118 |
String doi=r.getDoi(); |
|
119 |
|
|
120 |
|
|
121 |
if(doi!=null&& doi.contains("_")){ |
|
122 |
int count = doi.length() - doi.replace("_", "").length(); |
|
123 |
if(count==1) { |
|
124 |
// dois.add(r); |
|
125 |
System.err.println(rs.getString("id")+r.getDoi()); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
} |
|
130 |
/* for(Iterator<Result> d = dois.iterator(); d.hasNext(); ) { |
|
131 |
Result result = d.next(); |
|
132 |
|
|
133 |
System.out.println(result.getExternal_url()); |
|
134 |
} |
|
135 |
for(Iterator<Result> d = dois.iterator(); d.hasNext(); ) { |
|
136 |
Result result = d.next(); |
|
137 |
|
|
138 |
System.err.println(result.getExternal_url().replace("_","-")); |
|
139 |
} |
|
140 |
System.err.println("lenght::::"+dois.size()); |
|
141 |
log.info("Total::"+i); |
|
142 |
*/ |
|
143 |
|
|
144 |
} |
|
145 | 105 |
@Test |
146 | 106 |
public void testHttpRequest() throws Exception { |
147 | 107 |
SearchUtils searchUtils= new SearchUtils(); |
... | ... | |
203 | 163 |
} |
204 | 164 |
@Test |
205 | 165 |
public void dropClaimTables() throws Exception { |
206 |
// queryOperations.dropClaimTables();
|
|
166 |
// queryOperations.dropClaimTables();
|
|
207 | 167 |
} |
208 | 168 |
@Test |
209 | 169 |
public void createClaimTables() throws Exception { |
210 |
//queryOperations.createClaimTables();
|
|
170 |
// queryOperations.createClaimTables();
|
|
211 | 171 |
} |
212 | 172 |
@Test |
213 |
public void testClassQueryOperations() throws Exception { |
|
214 |
queryOperations.getClaimOperations(); |
|
215 |
|
|
173 |
public void testGetAndTransformClaimById() throws Exception { |
|
174 |
queryOperations.getAndTransformClaimById("169470",true); |
|
216 | 175 |
} |
217 | 176 |
|
218 | 177 |
|
178 |
|
|
219 | 179 |
} |
modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/SearchUtils.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.claimsDemo; |
2 | 2 |
|
3 |
import java.io.BufferedReader; |
|
4 |
import java.io.InputStreamReader; |
|
5 |
import java.io.UnsupportedEncodingException; |
|
3 |
import java.io.*; |
|
6 | 4 |
import java.net.HttpURLConnection; |
7 | 5 |
import java.net.URL; |
8 | 6 |
import java.net.URLEncoder; |
7 |
import java.sql.Timestamp; |
|
8 |
import java.util.Date; |
|
9 | 9 |
|
10 | 10 |
/** |
11 | 11 |
* Created by argirok on 20/11/2015. |
... | ... | |
87 | 87 |
System.out.println(response.toString()); |
88 | 88 |
return response.toString(); |
89 | 89 |
} |
90 |
|
|
91 |
// HTTP GET request |
|
92 |
private boolean findDOI(String doi) throws Exception { |
|
93 |
String url="http://api.crossref.org/works?filter=doi:"+doi; |
|
94 |
URL obj = new URL(url); |
|
95 |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
|
96 |
int responseCode = con.getResponseCode(); |
|
97 |
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
|
98 |
StringBuffer response = new StringBuffer(); |
|
99 |
String inputLine; |
|
100 |
while ((inputLine = in.readLine()) != null) { |
|
101 |
response.append(inputLine); |
|
102 |
} |
|
103 |
in.close(); |
|
104 |
boolean found=false; |
|
105 |
String responseStr=response.toString(); |
|
106 |
if(responseStr.contains("\"status\":\"ok\"")&&responseStr.contains("\"DOI\":\""+doi.replace("/","\\/")+"\"")){ |
|
107 |
found=true; |
|
108 |
} |
|
109 |
return found; |
|
110 |
} |
|
111 |
/* |
|
112 |
Checks if the the crossref API returns a response for the requested DOI |
|
113 |
If there is no such a DOI we try some transformations to resolve an bug in the portal |
|
114 |
*/ |
|
115 |
public String isValidDoi(String doi) throws Exception { |
|
116 |
if(doi==null){ |
|
117 |
return null; |
|
118 |
} |
|
119 |
try{ |
|
120 |
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("invalid_dois.txt", true))); |
|
121 |
boolean valid=findDOI(doi); |
|
122 |
if(!valid&&(doi.length() - (doi.replace("_", "")).length() > 1)){ |
|
123 |
String transformDoi = doi.replace("_", "-"); |
|
124 |
if(findDOI(transformDoi)){ |
|
125 |
Date date= new java.util.Date(); |
|
126 |
out.println(new Timestamp(date.getTime())+" - Invalid doi: "+doi+" replaced with : "+transformDoi); |
|
127 |
doi=transformDoi; |
|
128 |
} |
|
129 |
}else if(!valid&&(doi.length() - (doi.replace("_", "")).length() == 1)) { |
|
130 |
String transformDoi = doi.replace("_", "-"); |
|
131 |
if (findDOI(transformDoi)) { |
|
132 |
Date date= new java.util.Date(); |
|
133 |
out.println(new Timestamp(date.getTime())+" - Invalid doi: "+doi+" replaced with : "+transformDoi); |
|
134 |
doi = transformDoi; |
|
135 |
} |
|
136 |
} |
|
137 |
out.close(); |
|
138 |
}catch (IOException e) { |
|
139 |
e.printStackTrace(); |
|
140 |
System.err.println("Couldn't write to file " + "invalid_dois.txt"); |
|
141 |
} |
|
142 |
return doi; |
|
143 |
} |
|
90 | 144 |
} |
91 | 145 |
|
92 | 146 |
|
modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/ClaimOperations.java | ||
---|---|---|
5 | 5 |
import org.xml.sax.SAXException; |
6 | 6 |
|
7 | 7 |
import javax.xml.parsers.ParserConfigurationException; |
8 |
import java.io.BufferedWriter; |
|
9 |
import java.io.FileWriter; |
|
8 | 10 |
import java.io.IOException; |
11 |
import java.io.PrintWriter; |
|
9 | 12 |
import java.sql.ResultSet; |
10 | 13 |
import java.sql.SQLException; |
14 |
import java.sql.Timestamp; |
|
15 |
import java.text.ParseException; |
|
16 |
import java.text.SimpleDateFormat; |
|
17 |
import java.util.Date; |
|
11 | 18 |
|
12 | 19 |
/** |
13 | 20 |
* Created by argirok on 24/11/2015. |
14 | 21 |
*/ |
15 | 22 |
public class ClaimOperations { |
23 |
private SqlDAO sqlDAO; |
|
16 | 24 |
public ClaimOperations() { |
17 | 25 |
|
18 | 26 |
} |
19 | 27 |
|
20 |
public Result getDMFClaimById(String resultId,SqlDAO sqlDAO) throws Exception { |
|
21 |
ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectDMFById(resultId)); |
|
22 |
Result r =null; |
|
23 |
if(rs.next()) { |
|
24 |
r = this.getDMFClaim(rs); |
|
25 |
} |
|
26 |
return r; |
|
28 |
public SqlDAO getSqlDAO() { |
|
29 |
return sqlDAO; |
|
27 | 30 |
} |
31 |
|
|
32 |
public void setSqlDAO(SqlDAO sqlDAO) { |
|
33 |
this.sqlDAO = sqlDAO; |
|
34 |
} |
|
35 |
|
|
36 |
|
|
28 | 37 |
public Result getDMFClaim(ResultSet rs) throws Exception { |
29 | 38 |
String xml = rs.getString("xml"); |
30 | 39 |
Result r = ParsingClaimUtils.getResultFromDMF(xml); |
... | ... | |
39 | 48 |
claim = ParsingClaimUtils.getClaimFromConceptDMF(claim, xml); |
40 | 49 |
claim.setTargetType(((Result) claim.getTarget()).getResultType()); |
41 | 50 |
claim.setSourceType("context"); |
51 |
claim=this.enrichClaimFromDMF(claim); |
|
42 | 52 |
return claim; |
43 | 53 |
} |
44 | 54 |
|
45 | 55 |
public Claim getRelationClaim(ResultSet rs) throws SQLException, IOException, SAXException, ParserConfigurationException { |
46 | 56 |
Claim claim = new Claim(); |
47 | 57 |
claim.setId(rs.getString("id")); |
48 |
claim.setDate(rs.getDate("date")); |
|
58 |
SimpleDateFormat format = new SimpleDateFormat("YYY-MM-dd HH:mm:ss.SSS"); |
|
59 |
String dateStr = rs.getString("date"); |
|
60 |
Date date = null; |
|
61 |
try { |
|
62 |
date = format.parse(dateStr); |
|
63 |
claim.setDate(date); |
|
64 |
} catch (ParseException e) { |
|
65 |
e.printStackTrace(); |
|
66 |
claim.setDate(rs.getDate("date")); |
|
67 |
} |
|
68 |
|
|
49 | 69 |
claim.setUserMail(rs.getString("agent")); |
50 | 70 |
claim=ParsingClaimUtils.getRelationClaim(claim,rs.getString("xml")); |
71 |
claim=this.enrichClaimFromDMF(claim); |
|
51 | 72 |
return claim; |
52 | 73 |
} |
53 |
public String getQueryInsertClaim(Claim claim,SqlDAO sqlDAO) {
|
|
74 |
public String getQueryInsertClaim(Claim claim) { |
|
54 | 75 |
if (claim.getSourceType().equals("context")) { |
55 | 76 |
return sqlDAO.getQueryGenerator().insertClaimhasContext( (Result)claim.getTarget(), (Context) claim.getSource(), claim); |
56 | 77 |
} else if (claim.getSourceType().equals("project")) { |
... | ... | |
59 | 80 |
return sqlDAO.getQueryGenerator().insertClaimhasResult( (Result)claim.getTarget(), (Result) claim.getSource(), claim); |
60 | 81 |
} |
61 | 82 |
} |
83 |
|
|
84 |
private Claim enrichClaimFromDMF(Claim claim){ |
|
85 |
if((claim.getSourceType()==null)||(claim.getSourceType().equals("publication")||claim.getSourceType().equals("dataset"))){ |
|
86 |
Result source=(Result)claim.getSource(); |
|
87 |
claim.setSource(enrichResultFromDMF(claim.getId(), source)); |
|
88 |
claim.setSourceType(((Result) claim.getSource()).getResultType()); |
|
89 |
} |
|
90 |
if(claim.getTargetType()==null||(claim.getTargetType().equals("publication")||claim.getTargetType().equals("dataset"))){ |
|
91 |
Result target=(Result)claim.getTarget(); |
|
92 |
claim.setTarget(enrichResultFromDMF(claim.getId(),target)); |
|
93 |
claim.setTargetType(((Result) claim.getTarget()).getResultType()); |
|
94 |
} |
|
95 |
return claim; |
|
96 |
} |
|
97 |
private Result enrichResultFromDMF(String claimId, Result r){ |
|
98 |
try { |
|
99 |
/*if(r.getCollectedFrom().contains("::openaire")){ |
|
100 |
return r; |
|
101 |
}*/ |
|
102 |
r=checkForDOI(r); |
|
103 |
Result dmfResult=this.getDMFClaimById(r.getOpenaireId()); |
|
104 |
if(dmfResult!=null){ |
|
105 |
if(r.getResultType()==null){ |
|
106 |
r.setResultType(dmfResult.getResultType()); |
|
107 |
} |
|
108 |
if(r.getTitle()==null){ |
|
109 |
r.setTitle(dmfResult.getTitle()); |
|
110 |
} |
|
111 |
if(r.getDoi()==null){ |
|
112 |
r.setDoi(dmfResult.getDoi()); |
|
113 |
} |
|
114 |
if(r.getCollectedFrom()==null){ |
|
115 |
r.setCollectedFrom(dmfResult.getCollectedFrom()); |
|
116 |
} |
|
117 |
if(r.getAccessRights()==null){ |
|
118 |
r.setAccessRights(dmfResult.getAccessRights()); |
|
119 |
} |
|
120 |
if(r.getExternal_url()==null){ |
|
121 |
r.setExternal_url(dmfResult.getExternal_url()); |
|
122 |
} |
|
123 |
r.setXml(dmfResult.getXml()); |
|
124 |
try{ |
|
125 |
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("enriched_results.txt", true))); |
|
126 |
Date date= new java.util.Date(); |
|
127 |
out.println(new Timestamp(date.getTime())+" - In claim - "+claimId+" result - "+r.getOpenaireId()+" enriched from dmf"); |
|
128 |
out.close(); |
|
129 |
}catch (IOException e) { |
|
130 |
e.printStackTrace(); |
|
131 |
System.err.println("Couldn't write to file " + "enriched_results.txt"); |
|
132 |
} |
|
133 |
} |
|
134 |
r=checkForDOI(r); |
|
135 |
//if type is still null => decide on provider |
|
136 |
if(r.getResultType()==null){ |
|
137 |
if(r.getCollectedFrom()!=null) { |
|
138 |
if (r.getCollectedFrom().contains("crossref") || r.getCollectedFrom().contains("orcid")) { |
|
139 |
r.setResultType("publication"); |
|
140 |
} else if (r.getCollectedFrom().contains("datacite")) { |
|
141 |
r.setResultType("dataset"); |
|
142 |
} |
|
143 |
}else{ |
|
144 |
r.setResultType("unknown"); |
|
145 |
} |
|
146 |
} |
|
147 |
return r; |
|
148 |
} catch (Exception e) { |
|
149 |
e.printStackTrace(); |
|
150 |
return r; |
|
151 |
} |
|
152 |
} |
|
153 |
/* |
|
154 |
Checks if the doi is valid. If it is not then replaces the DOI with the valid one. |
|
155 |
*/ |
|
156 |
private Result checkForDOI(Result r) throws Exception { |
|
157 |
if(r.getDoi()==null){ |
|
158 |
return r; |
|
159 |
} |
|
160 |
SearchUtils s= new SearchUtils(); |
|
161 |
String validDOI=s.isValidDoi(r.getDoi()); |
|
162 |
if(!validDOI.equals(r.getDoi())){ |
|
163 |
r.setXml(r.getXml().replace(r.getDoi(),validDOI)); |
|
164 |
r.setDoi(validDOI); |
|
165 |
} |
|
166 |
return r; |
|
167 |
} |
|
168 |
public Result getDMFClaimById(String resultId) throws Exception { |
|
169 |
ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectDMFById(resultId)); |
|
170 |
Result r =null; |
|
171 |
if(rs.next()) { |
|
172 |
r = this.getDMFClaim(rs); |
|
173 |
} |
|
174 |
return r; |
|
175 |
} |
|
62 | 176 |
} |
modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/ParsingClaimUtils.java | ||
---|---|---|
19 | 19 |
import javax.xml.xpath.XPathConstants; |
20 | 20 |
import javax.xml.xpath.XPathExpression; |
21 | 21 |
import javax.xml.xpath.XPathFactory; |
22 |
import java.io.IOException; |
|
23 |
import java.io.StringReader; |
|
22 |
import java.io.*; |
|
23 |
import java.sql.Timestamp; |
|
24 |
import java.util.Date; |
|
24 | 25 |
|
25 | 26 |
/** |
26 | 27 |
* Created by argirok on 20/11/2015. |
... | ... | |
193 | 194 |
|
194 | 195 |
} |
195 | 196 |
|
196 |
claim.setTarget(buildResult(r.getOpenaireId(), null)); |
|
197 |
claim.setTarget(buildResult(r.getOpenaireId(), null,claim.getId()));
|
|
197 | 198 |
claim.setSource(context); |
198 | 199 |
return claim; |
199 | 200 |
} |
... | ... | |
227 | 228 |
return null; |
228 | 229 |
|
229 | 230 |
} |
230 |
claim.setTarget(buildResult(targetId, getTargetType(relationType))); |
|
231 |
claim.setTarget(buildResult(targetId, getTargetType(relationType),claim.getId()));
|
|
231 | 232 |
String bodyType=getBodyType(relationType); |
232 | 233 |
if (bodyType.equals("project")) { |
233 |
claim.setSource(buildProject(sourceId)); |
|
234 |
claim.setSource(buildProject(sourceId, claim.getId()));
|
|
234 | 235 |
} else { |
235 |
claim.setSource(buildResult(sourceId, bodyType)); |
|
236 |
claim.setSource(buildResult(sourceId, bodyType,claim.getId()));
|
|
236 | 237 |
bodyType=((Result)claim.getSource()).getResultType(); |
237 | 238 |
} |
238 | 239 |
claim.setTargetType(((Result) claim.getTarget()).getResultType()); |
... | ... | |
240 | 241 |
return claim; |
241 | 242 |
} |
242 | 243 |
|
243 |
static Result buildResult(String id, String type) { |
|
244 |
static Result buildResult(String id, String type,String claimId) {
|
|
244 | 245 |
Result body= new Result(); |
245 | 246 |
if (id.contains("|")) { |
246 | 247 |
id = id.split("\\|")[1]; |
247 | 248 |
} |
248 | 249 |
body.setOpenaireId(id); |
249 | 250 |
body.setResultType(type); |
250 |
body=getResultFromSearch(body); |
|
251 |
body=getResultFromSearch(body,claimId);
|
|
251 | 252 |
|
252 | 253 |
return body; |
253 | 254 |
} |
254 |
private static Result getResultFromSearch(Result r){ |
|
255 |
private static Result getResultFromSearch(Result r,String claimId){
|
|
255 | 256 |
SearchUtils searchUtils= new SearchUtils(); |
256 | 257 |
String searchUri=searchUtils.getResultSearchUrl(r.getOpenaireId()); |
257 | 258 |
if(searchUri==null){ |
... | ... | |
311 | 312 |
|
312 | 313 |
|
313 | 314 |
}else{ |
314 |
System.err.println("Result Not Found " + r.getOpenaireId()); |
|
315 |
try{ |
|
316 |
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("results_not_found.txt", true))); |
|
317 |
Date date= new java.util.Date(); |
|
318 |
out.println(new Timestamp(date.getTime())+" - Result Not Found: "+r.getOpenaireId()+ " in claim "+claimId); |
|
319 |
out.close(); |
|
320 |
}catch (IOException e) { |
|
321 |
e.printStackTrace(); |
|
322 |
System.err.println("Couldn't write to file " + "results_not_found.txt"); |
|
323 |
} |
|
324 |
//System.err.println("Result Not Found " + r.getOpenaireId()); |
|
315 | 325 |
r.setFound(false); |
316 | 326 |
} |
317 | 327 |
|
... | ... | |
325 | 335 |
//TODO |
326 | 336 |
return r; |
327 | 337 |
} |
328 |
private static Project buildProject(String id){ |
|
338 |
private static Project buildProject(String id, String claimId){
|
|
329 | 339 |
Project body=new Project(); |
330 | 340 |
if (id.contains("|")) { |
331 | 341 |
id = id.split("\\|")[1]; |
332 | 342 |
} |
333 | 343 |
body.setOpenaireId(id); |
334 |
return getProjectFromSearch(body); |
|
344 |
return getProjectFromSearch(body, claimId);
|
|
335 | 345 |
} |
336 |
private static Project getProjectFromSearch(Project project){ |
|
346 |
private static Project getProjectFromSearch(Project project, String claimId){
|
|
337 | 347 |
SearchUtils s=new SearchUtils(); |
338 | 348 |
String searchUri=s.getProjectSearchUrl(project.getOpenaireId()); |
339 | 349 |
if(searchUri==null){ |
... | ... | |
377 | 387 |
} |
378 | 388 |
|
379 | 389 |
}else{ |
380 |
System.err.println("PROJECT Not Found " + project.getOpenaireId()); |
|
390 |
try{ |
|
391 |
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("projects_not_found.txt", true))); |
|
392 |
Date date= new java.util.Date(); |
|
393 |
out.println(new Timestamp(date.getTime())+" - Result Not Found: "+project.getOpenaireId()+ " in claim "+claimId); |
|
394 |
out.close(); |
|
395 |
}catch (IOException e) { |
|
396 |
e.printStackTrace(); |
|
397 |
System.err.println("Couldn't write to file " + "projects_not_found.txt"); |
|
398 |
} |
|
399 |
//System.err.println("PROJECT Not Found " + project.getOpenaireId()); |
|
381 | 400 |
project.setFound(false); |
382 | 401 |
|
383 | 402 |
} |
modules/uoa-claims -demo/claims-demo/src/main/java/eu/dnetlib/data/claimsDemo/QueryGenerator.java | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import java.io.IOException; |
10 | 10 |
import java.io.InputStream; |
11 |
import java.text.SimpleDateFormat; |
|
12 |
import java.util.Date; |
|
11 | 13 |
|
12 | 14 |
|
13 | 15 |
public class QueryGenerator { |
... | ... | |
36 | 38 |
if(title!=null&&title.contains("'")){ |
37 | 39 |
title=title.replace("'","''"); |
38 | 40 |
} |
39 |
return "INSERT INTO result(openaire_id, result_type,title,collected_from,external_url,doi,access_rights,best_license, found)\n" + |
|
40 |
" Select '"+openaire_id+"', '"+result_type+"','"+title+"','"+collected_from+"', '"+external_url+"','"+doi+"','"+access_rights+"', '"+best_license+"', '"+found+"'"+ |
|
41 |
String fields="openaire_id, found"; |
|
42 |
if(result_type!=null){ |
|
43 |
fields+=", result_type"; |
|
44 |
} |
|
45 |
if(title!=null){ |
|
46 |
fields+=", title"; |
|
47 |
} |
|
48 |
if(collected_from!=null){ |
|
49 |
fields+=", collected_from"; |
|
50 |
} |
|
51 |
if(external_url!=null){ |
|
52 |
fields+=", external_url"; |
|
53 |
} |
|
54 |
if(doi!=null){ |
|
55 |
fields+=", doi"; |
|
56 |
} |
|
57 |
if(access_rights!=null){ |
|
58 |
fields+=", access_rights"; |
|
59 |
} |
|
60 |
if(best_license!=null){ |
|
61 |
fields+=", best_license"; |
|
62 |
} |
|
63 |
String values="'"+openaire_id+"','"+found+"'"; |
|
64 |
if(result_type!=null){ |
|
65 |
values+=",'"+result_type+"'"; |
|
66 |
} |
|
67 |
if(title!=null){ |
|
68 |
values+=",'"+title+"'"; |
|
69 |
} |
|
70 |
if(collected_from!=null){ |
|
71 |
values+=",'"+collected_from+"'"; |
|
72 |
} |
|
73 |
if(external_url!=null){ |
|
74 |
values+=",'"+external_url+"'"; |
|
75 |
} |
|
76 |
if(doi!=null){ |
|
77 |
values+=",'"+doi+"'"; |
|
78 |
} |
|
79 |
if(access_rights!=null){ |
|
80 |
values+=",'"+access_rights+"'"; |
|
81 |
} |
|
82 |
if(best_license!=null){ |
|
83 |
values+=",'"+best_license+"'"; |
|
84 |
} |
|
85 |
return "INSERT INTO result("+fields+")\n" + |
|
86 |
" Select "+values+ |
|
41 | 87 |
" where not exists (select openaire_id from result where openaire_id='"+openaire_id+"')\n" + |
42 | 88 |
" RETURNING openaire_id"; |
43 | 89 |
} |
44 | 90 |
private String insertProject(String openaire_id, String name,String acronym, String funder_id,String funder_name, boolean found) { |
45 |
name=name.replace("'","''"); |
|
46 |
return "INSERT INTO project(openaire_id, name,acronym,funder_id,funder_name, found)\n" + |
|
47 |
" Select '"+openaire_id+"', '"+name+"','"+acronym+"','"+funder_id+"', '"+funder_name+"', '"+found+"'" + |
|
91 |
if(name!=null) { |
|
92 |
name = name.replace("'", "''"); |
|
93 |
} |
|
94 |
String fields="openaire_id"; |
|
95 |
if(name!=null){ |
|
96 |
fields+=",name"; |
|
97 |
} |
|
98 |
if(acronym!=null){ |
|
99 |
fields+=",acronym"; |
|
100 |
} |
|
101 |
if(funder_id!=null){ |
|
102 |
fields+=",funder_id"; |
|
103 |
} |
|
104 |
if(funder_name!=null){ |
|
105 |
fields+=",funder_name"; |
|
106 |
} |
|
107 |
fields+=",found"; |
|
108 |
String values="'"+openaire_id+"'"; |
|
109 |
if(name!=null){ |
|
110 |
values+=",'"+name+"'"; |
|
111 |
} |
|
112 |
if(acronym!=null){ |
|
113 |
values+=",'"+acronym+"'"; |
|
114 |
} |
|
115 |
if(funder_id!=null){ |
|
116 |
values+=",'"+funder_id+"'"; |
|
117 |
} |
|
118 |
if(funder_name!=null){ |
|
119 |
values+=",'"+funder_name+"'"; |
|
120 |
} |
|
121 |
values+=",'"+found+"'"; |
|
122 |
return "INSERT INTO project("+fields+")\n" + |
|
123 |
" Select "+values + |
|
48 | 124 |
" where not exists (select openaire_id from project where openaire_id='"+openaire_id+"')\n" + |
49 | 125 |
" RETURNING openaire_id"; |
50 | 126 |
} |
51 | 127 |
private String insertContext(String openaire_id, String name) { |
52 |
|
|
53 |
return "INSERT INTO context(openaire_id, name)\n" + |
|
54 |
" Select '"+openaire_id+"', '"+name+"'" + |
|
128 |
String fields="openaire_id"; |
|
129 |
if(name!=null){ |
|
130 |
fields+=",name"; |
|
131 |
} |
|
132 |
String values="'"+openaire_id+"'"; |
|
133 |
if(name!=null){ |
|
134 |
values+=",'"+name+"'"; |
|
135 |
} |
|
136 |
return "INSERT INTO context("+fields+")\n" + |
|
137 |
" Select "+values+ |
|
55 | 138 |
" where not exists (select openaire_id from context where openaire_id='"+openaire_id+"')\n" + |
56 | 139 |
" RETURNING openaire_id"; |
57 | 140 |
} |
58 |
private String insertClaim(String date, String claimedBy,String source_type, String target_type ,String source_id , String target_id) {
|
|
141 |
private String insertClaim(Date date, String claimedBy,String source_type, String target_type ,String source_id , String target_id) {
|
|
59 | 142 |
|
143 |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); |
|
144 |
String dateStr=null; |
|
145 |
dateStr=(format.format(date)); |
|
146 |
|
|
60 | 147 |
return " INSERT INTO claim( claim_date,claimedBy,source_type,target_type, source_id, target_id)\n" + |
61 |
" VALUES ( '"+date+"','"+claimedBy+"','"+source_type+"', '"+target_type+"','"+source_id+"','"+target_id+"')\n" + |
|
148 |
" VALUES ( '"+dateStr+"','"+claimedBy+"','"+source_type+"', '"+target_type+"','"+source_id+"','"+target_id+"')\n" +
|
|
62 | 149 |
" RETURNING id, source_id, target_id\n"; |
63 | 150 |
} |
64 | 151 |
public String insertClaimhasResult(Result targetResult, Result sourceResult, Claim claim) { |
... | ... | |
68 | 155 |
" ),\n ins2 AS (\n" + |
69 | 156 |
insertResult(sourceResult.getOpenaireId(),sourceResult.getResultType(),sourceResult.getTitle(),sourceResult.getCollectedFrom(),sourceResult.getExternal_url(),sourceResult.getDoi(),sourceResult.getAccessRights(), sourceResult.getBestLicense(),sourceResult.isFound(),sourceResult.getXml())+ |
70 | 157 |
" ),\n ins3 AS (\n" + |
71 |
insertClaim(claim.getDate().toString(),claim.getUserMail(),claim.getSourceType(),claim.getTargetType(),claim.getSource().getOpenaireId(),claim.getTarget().getOpenaireId()) +
|
|
158 |
insertClaim(claim.getDate(),claim.getUserMail(),claim.getSourceType(),claim.getTargetType(),claim.getSource().getOpenaireId(),claim.getTarget().getOpenaireId()) + |
|
72 | 159 |
" ),\n ins4 AS (\n" + |
73 | 160 |
" INSERT INTO has_source_result (claim_id, openaire_id, semantics)\n" + |
74 | 161 |
" SELECT id, source_id,'resultResult_publicationDataset_isRelatedTo'\n" + |
... | ... | |
84 | 171 |
" ),\n ins2 AS (\n" + |
85 | 172 |
insertProject(project.getOpenaireId(), project.getName(), project.getAcronym(), project.getFunderId(), project.getFunderName(), project.isFound())+ |
86 | 173 |
" ),\n ins3 AS (\n" + |
87 |
insertClaim(claim.getDate().toString(),claim.getUserMail(),claim.getSourceType(),claim.getTargetType(),claim.getSource().getOpenaireId(),claim.getTarget().getOpenaireId()) +
|
|
174 |
insertClaim(claim.getDate(),claim.getUserMail(),claim.getSourceType(),claim.getTargetType(),claim.getSource().getOpenaireId(),claim.getTarget().getOpenaireId()) + |
|
88 | 175 |
" ),\n ins4 AS (\n" + |
89 | 176 |
" INSERT INTO has_source_project (claim_id, openaire_id,semantics)\n" + |
90 | 177 |
" SELECT id, source_id,'resultProject_outcome_isProducedBy'\n" + |
... | ... | |
100 | 187 |
" ),\n ins2 AS (\n" + |
101 | 188 |
insertContext(context.getOpenaireId(), context.getTitle())+ |
102 | 189 |
" ),\n ins3 AS (\n" + |
103 |
insertClaim(claim.getDate().toString(),claim.getUserMail(),claim.getSourceType(),claim.getTargetType(),claim.getSource().getOpenaireId(),claim.getTarget().getOpenaireId()) +
|
|
190 |
insertClaim(claim.getDate(),claim.getUserMail(),claim.getSourceType(),claim.getTargetType(),claim.getSource().getOpenaireId(),claim.getTarget().getOpenaireId()) + |
|
104 | 191 |
" ), ins4 AS (\n" + |
105 | 192 |
" INSERT INTO has_source_context(claim_id, openaire_id)\n" + |
106 | 193 |
" SELECT id, source_id\n" + |
... | ... | |
126 | 213 |
public String createClaimTables() { |
127 | 214 |
return "CREATE TABLE project (\n" + |
128 | 215 |
" openaire_id varchar(60) primary key NOT NULL,\n" + |
129 |
" name text NOT NULL,\n" +
|
|
216 |
" name text,\n" + |
|
130 | 217 |
" acronym varchar(60),\n" + |
131 |
" funder_id varchar(20),\n" +
|
|
218 |
" funder_id varchar(60),\n" +
|
|
132 | 219 |
" funder_name varchar(60),\n" + |
133 | 220 |
" found boolean\n" + |
134 | 221 |
");\n" + |
... | ... | |
137 | 224 |
" openaire_id varchar(60) primary key NOT NULL,\n" + |
138 | 225 |
"\t\tresult_type varchar(30) NOT NULL,\n" + |
139 | 226 |
"\t\tdoi varchar(60),\n" + |
140 |
"\t\ttitle text NOT NULL,\n" +
|
|
227 |
"\t\ttitle text,\n" + |
|
141 | 228 |
"\t\taccess_rights varchar(30),\n" + |
142 | 229 |
"\t\tbest_license varchar(30),\t\t\n" + |
143 |
"\t\texternal_url varchar(60),\n" +
|
|
144 |
"\t\tcollected_from varchar(60) NOT NULL,\n" +
|
|
230 |
"\t\texternal_url text,\n" +
|
|
231 |
"\t\tcollected_from varchar(60) ,\n" + |
|
145 | 232 |
" found boolean,\n" + |
146 | 233 |
"\t\txml text\n" + |
147 | 234 |
");\n" + |
148 | 235 |
"\n" + |
149 | 236 |
"CREATE TABLE context (\n" + |
150 | 237 |
" openaire_id varchar(60) primary key,\n" + |
151 |
" name text NOT NULL\n" +
|
|
238 |
" name text\n" + |
|
152 | 239 |
");\n" + |
153 | 240 |
"CREATE TABLE claim (\n" + |
154 | 241 |
" id int primary key NOT NULL DEFAULT nextval('claim_id'::regclass),\n" + |
... | ... | |
201 | 288 |
|
202 | 289 |
} |
203 | 290 |
public String selectDMFById(String id) { |
204 |
return " Select * from claims_view where type='dmf2actions' and resultid='"+id+"' order by date desc limit 1"; |
|
291 |
return " Select * from claims_view where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' and resultid='"+id+"' order by date desc limit 1";
|
|
205 | 292 |
} |
206 | 293 |
public String selectConceptDMFClaims(Integer limit) { |
207 | 294 |
return " Select * from claims_view where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' limit "+limit; |
modules/uoa-claims -demo/claims-demo/src/main/resources/eu/dnetlib/data/claimsDemo/springContext-claimsDemo.xml | ||
---|---|---|
29 | 29 |
|
30 | 30 |
|
31 | 31 |
<bean id="claimOperations" class="eu.dnetlib.data.claimsDemo.ClaimOperations"> |
32 |
<property name="sqlDAO" ref="sqlDao"/> |
|
32 | 33 |
</bean> |
33 | 34 |
|
34 | 35 |
|
Also available in: Unified diff
change insert-queries to ignore null values, change the date format in claim insert query, add enrich result methods, add bean for claimOperations class, export report files for not found projects/results, invalid dois and enriched results from dmfs