1
|
package eu.dnetlib.data.claims.utils;
|
2
|
|
3
|
import eu.dnetlib.data.claims.entity.*;
|
4
|
|
5
|
import java.text.SimpleDateFormat;
|
6
|
import java.util.ArrayList;
|
7
|
import java.util.Date;
|
8
|
import java.util.List;
|
9
|
import org.apache.log4j.Logger;
|
10
|
|
11
|
|
12
|
public class QueryGenerator {
|
13
|
boolean updateOnInsert;
|
14
|
String migrationTable ="claims"; //a table or a view containing old schema claims - But only user claims, not those where agent='inference'
|
15
|
private static final Logger logger = Logger.getLogger(QueryGenerator.class);
|
16
|
|
17
|
public boolean isUpdateOnInsert() {
|
18
|
return updateOnInsert;
|
19
|
}
|
20
|
|
21
|
public void setUpdateOnInsert(boolean updateOnInsert) {
|
22
|
this.updateOnInsert = updateOnInsert;
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
** Insert Queries **
|
27
|
**/
|
28
|
public String generateInsertQueryForClaimsOrphanIds(String id){
|
29
|
return "INSERT INTO claims_orphan_ids values (" + id + ");";
|
30
|
}
|
31
|
private String generateInsertResultQuery(String openaire_id, String result_type, String title, String collected_from , String external_url, String doi, String orcidworkid, String access_rights , String embargo_end_date, String best_license, String record_path, String record_format, ArrayList<Object> params) {
|
32
|
if(title!=null&&title.contains("'")){
|
33
|
title=title.replace("'","''");
|
34
|
}
|
35
|
String fields="openaire_id";
|
36
|
if(result_type!=null){
|
37
|
fields+=", result_type";
|
38
|
}
|
39
|
if(title!=null){
|
40
|
fields+=", title";
|
41
|
}
|
42
|
if(collected_from!=null){
|
43
|
fields+=", collected_from";
|
44
|
}
|
45
|
if(external_url!=null){
|
46
|
fields+=", external_url";
|
47
|
}
|
48
|
if(doi!=null){
|
49
|
fields+=", doi";
|
50
|
}
|
51
|
if(orcidworkid!=null){
|
52
|
fields+=", orcidworkid";
|
53
|
}
|
54
|
if(access_rights!=null){
|
55
|
fields+=", access_rights";
|
56
|
}
|
57
|
if(embargo_end_date!=null){
|
58
|
fields+=", embargo_end_date";
|
59
|
}
|
60
|
if(best_license!=null){
|
61
|
fields+=", best_license";
|
62
|
}
|
63
|
if(record_path!=null){
|
64
|
fields+=", record_path";
|
65
|
}
|
66
|
if(record_format!=null){
|
67
|
fields+=", record_format";
|
68
|
}
|
69
|
String values="?";
|
70
|
params.add(openaire_id);
|
71
|
if(result_type!=null){
|
72
|
values+=",?";
|
73
|
params.add(result_type);
|
74
|
}
|
75
|
if(title!=null){
|
76
|
values+=",?";
|
77
|
params.add(title);
|
78
|
}
|
79
|
if(collected_from!=null){
|
80
|
values+=",?";
|
81
|
params.add(collected_from);
|
82
|
}
|
83
|
if(external_url!=null){
|
84
|
values+=",?";
|
85
|
params.add(external_url);
|
86
|
}
|
87
|
if(doi!=null){
|
88
|
values+=",?";
|
89
|
params.add(doi);
|
90
|
}
|
91
|
if(orcidworkid!=null){
|
92
|
values+=",?";
|
93
|
params.add(orcidworkid);
|
94
|
}
|
95
|
if(access_rights!=null){
|
96
|
values+=",?";
|
97
|
params.add(access_rights);
|
98
|
}
|
99
|
if(embargo_end_date!=null){
|
100
|
values+=",?::date";
|
101
|
params.add(embargo_end_date);
|
102
|
}
|
103
|
if(best_license!=null){
|
104
|
values+=",?";
|
105
|
params.add(best_license);
|
106
|
}
|
107
|
if(record_path!=null){
|
108
|
values+=",?";
|
109
|
params.add(record_path);
|
110
|
}
|
111
|
if(record_format!=null){
|
112
|
values+=",?";
|
113
|
params.add(record_format);
|
114
|
}
|
115
|
params.add(openaire_id);
|
116
|
return "INSERT INTO result("+fields+")\n" +
|
117
|
" Select "+values+
|
118
|
" where not exists (select openaire_id from result where openaire_id=?)\n" +
|
119
|
" RETURNING openaire_id";
|
120
|
//TODO update on insert when exists
|
121
|
}
|
122
|
public String generateInsertProjectQuery(String openaire_id, String name, String acronym, String funder_id, String funder_name, String funder_acronym, List<String> contactEmails, ArrayList<Object> params) {
|
123
|
if(name!=null) {
|
124
|
name = name.replace("'", "''");
|
125
|
}
|
126
|
String fields="openaire_id";
|
127
|
if(name!=null){
|
128
|
fields+=",name";
|
129
|
}
|
130
|
if(acronym!=null){
|
131
|
fields+=",acronym";
|
132
|
}
|
133
|
if(funder_id!=null){
|
134
|
fields+=",funder_id";
|
135
|
}
|
136
|
if(funder_name!=null){
|
137
|
fields+=",funder_name";
|
138
|
}
|
139
|
if(funder_acronym!=null){
|
140
|
fields+=",funder_acronym";
|
141
|
}
|
142
|
if(contactEmails != null && contactEmails.size() > 0){
|
143
|
fields+=",contact_person";
|
144
|
}
|
145
|
String values="?";
|
146
|
params.add(openaire_id);
|
147
|
if(name!=null){
|
148
|
values+=",?";
|
149
|
params.add(name);
|
150
|
}
|
151
|
if(acronym!=null){
|
152
|
values+=",?";
|
153
|
params.add(acronym);
|
154
|
}
|
155
|
if(funder_id!=null){
|
156
|
values+=",?";
|
157
|
params.add(funder_id);
|
158
|
}
|
159
|
if(funder_name!=null){
|
160
|
values+=",?";
|
161
|
params.add(funder_name);
|
162
|
}
|
163
|
if(funder_acronym!=null){
|
164
|
values+=",?";
|
165
|
params.add(funder_acronym);
|
166
|
}
|
167
|
if(contactEmails != null && contactEmails.size() > 0){
|
168
|
values+=",string_to_array(?, ',')";
|
169
|
//String email_json = "{";
|
170
|
String email_json = "";
|
171
|
for(int i = 0; i< contactEmails.size(); i++){
|
172
|
email_json+=contactEmails.get(i)+((i < contactEmails.size() -1 )?",":"");
|
173
|
//params.add(contactEmails.get(i));
|
174
|
}
|
175
|
//email_json+="";
|
176
|
params.add(email_json);
|
177
|
}
|
178
|
params.add(openaire_id);
|
179
|
return "INSERT INTO project("+fields+")\n" +
|
180
|
" Select "+values +
|
181
|
" where not exists (select openaire_id from project where openaire_id=?)\n" +
|
182
|
" RETURNING openaire_id";
|
183
|
//TODO update on insert when exists
|
184
|
}
|
185
|
private String generateInsertContextQuery(String openaire_id, String name, ArrayList<Object> params) {
|
186
|
String fields="openaire_id";
|
187
|
if(name!=null){
|
188
|
fields+=",name";
|
189
|
}
|
190
|
String values="?";
|
191
|
params.add(openaire_id);
|
192
|
if(name!=null){
|
193
|
values+=",?";
|
194
|
params.add(name);
|
195
|
}
|
196
|
params.add(openaire_id);
|
197
|
return "INSERT INTO context("+fields+")\n" +
|
198
|
" Select "+values+
|
199
|
" where not exists (select openaire_id from context where openaire_id=?)\n" +
|
200
|
" RETURNING openaire_id";
|
201
|
//TODO update on insert when exists
|
202
|
}
|
203
|
private String generateInsertClaimQuery(Date date, String claimedBy, String source_type, String target_type , String source_id , String target_id, String semantics, ArrayList<Object> params) {
|
204
|
|
205
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
206
|
String dateStr=null;
|
207
|
dateStr=(format.format(date));
|
208
|
String fields="claim_date,claimedBy,source_type,target_type, source_id, target_id";
|
209
|
if(semantics!=null){
|
210
|
fields+=",semantics";
|
211
|
}
|
212
|
String values="?::timestamp,?,?,?,?,?";
|
213
|
params.add(dateStr);
|
214
|
params.add(claimedBy);
|
215
|
params.add(source_type);
|
216
|
params.add(target_type);
|
217
|
params.add(source_id);
|
218
|
params.add(target_id);
|
219
|
if(semantics!=null){
|
220
|
values+=",?";
|
221
|
params.add(semantics);
|
222
|
}
|
223
|
|
224
|
return " INSERT INTO claim( "+fields+")\n" +
|
225
|
" VALUES ( "+values+")\n" +
|
226
|
" RETURNING id, source_id, target_id\n";
|
227
|
}
|
228
|
|
229
|
private String generateInsertFullClaimQuery(String targetQuery, String sourceQuery, Claim claim, ArrayList<Object> params) {
|
230
|
if (claim ==null || targetQuery ==null || sourceQuery == null){
|
231
|
return null;
|
232
|
}
|
233
|
String sourceTableName= getSourceTableName(claim.getSourceType());
|
234
|
String targetTableName= getTargetTableName(claim.getTargetType());
|
235
|
if (sourceTableName ==null || targetTableName ==null ){
|
236
|
return null;
|
237
|
}
|
238
|
return " WITH target AS (\n" +
|
239
|
targetQuery+
|
240
|
" ),\n source AS (\n" +
|
241
|
sourceQuery+
|
242
|
" ),\n myclaim AS (\n" +
|
243
|
generateInsertClaimQuery(claim.getDate(), claim.getUserMail(), claim.getSourceType(), claim.getTargetType(), claim.getSource().getOpenaireId(), claim.getTarget().getOpenaireId(),this.createSemanticsType(claim.getSourceType(),claim.getTargetType()), params) +
|
244
|
" ),\n ins4 AS (\n" +
|
245
|
" INSERT INTO "+sourceTableName+" (claim_id, openaire_id)\n" +
|
246
|
" SELECT id, source_id\n" +
|
247
|
" FROM myclaim) \n"+
|
248
|
" INSERT INTO "+targetTableName+"(claim_id, openaire_id)\n" +
|
249
|
" SELECT id, target_id\n" +
|
250
|
" FROM myclaim "+
|
251
|
" RETURNING claim_id;";
|
252
|
}
|
253
|
public String generateInsertFullClaimQuery( Claim claim, ArrayList<Object> params) {
|
254
|
String targetQuery =null;
|
255
|
String sourceQuery=null;
|
256
|
targetQuery=generateInsertEntityQuery(claim.getTarget(),claim.getTargetType(), params);
|
257
|
sourceQuery=generateInsertEntityQuery(claim.getSource(),claim.getSourceType(), params);
|
258
|
return generateInsertFullClaimQuery(targetQuery,sourceQuery,claim, params);
|
259
|
|
260
|
}
|
261
|
private String generateInsertEntityQuery(OpenaireEntity openaireEntity, String type, ArrayList<Object> params){
|
262
|
String query=null;
|
263
|
if(type==null){
|
264
|
return null;
|
265
|
}
|
266
|
if(type.equals(ClaimUtils.DATASET)||type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.SOFTWARE)||type.equals(ClaimUtils.OTHER)){
|
267
|
Result result=(Result)openaireEntity;
|
268
|
query=generateInsertResultQuery(result.getOpenaireId(),result.getResultType(),result.getTitle(),result.getCollectedFrom(),result.getExternalUrl(),result.getDoi(), result.getOrcidworkid(), result.getAccessRights(),result.getEmbargoEndDate(),result.getBestLicense(),result.getRecordPath(), result.getRecordFormat(), params);
|
269
|
}else if(type.equals(ClaimUtils.PROJECT)){
|
270
|
Project project=(Project)openaireEntity;
|
271
|
query=generateInsertProjectQuery(project.getOpenaireId(),project.getName(),project.getAcronym(),project.getFunderId(),project.getFunderName(),project.getFunderShortName(),project.getContactEmails(), params);
|
272
|
}else if(type.equals(ClaimUtils.CONTEXT)){
|
273
|
Context context= (Context)openaireEntity;
|
274
|
query=generateInsertContextQuery(context.getOpenaireId(),context.getTitle(), params);
|
275
|
}
|
276
|
|
277
|
return query;
|
278
|
}
|
279
|
|
280
|
private String getSourceTableName(String type){
|
281
|
String tablename="has_source_";
|
282
|
if(type==null){
|
283
|
return null;
|
284
|
}else{
|
285
|
tablename+=getTypeForTable(type);
|
286
|
}
|
287
|
return tablename;
|
288
|
}
|
289
|
private String getTargetTableName(String type){
|
290
|
String tablename="has_target_";
|
291
|
if(type==null){
|
292
|
return null;
|
293
|
}else{
|
294
|
tablename+=getTypeForTable(type);
|
295
|
}
|
296
|
return tablename;
|
297
|
}
|
298
|
public String generateInsertClaimResultQuery(String targetQuery, String sourceQuery, Claim claim, ArrayList<Object> params) {
|
299
|
|
300
|
return " WITH ins1 AS (\n" +
|
301
|
targetQuery+
|
302
|
" ),\n ins2 AS (\n" +
|
303
|
sourceQuery+
|
304
|
" ),\n ins3 AS (\n" +
|
305
|
generateInsertClaimQuery(claim.getDate(), claim.getUserMail(), claim.getSourceType(), claim.getTargetType(), claim.getSource().getOpenaireId(), claim.getTarget().getOpenaireId(),this.createSemanticsType(claim.getSourceType(),claim.getTargetType()), params) +
|
306
|
" ),\n ins4 AS (\n" +
|
307
|
" INSERT INTO has_source_result (claim_id, openaire_id)\n" +
|
308
|
" SELECT id, source_id\n" +
|
309
|
" FROM ins3) \n"+
|
310
|
" INSERT INTO has_target_result(claim_id, openaire_id)\n" +
|
311
|
" SELECT id, target_id\n" +
|
312
|
" FROM ins3;";
|
313
|
}
|
314
|
|
315
|
/**
|
316
|
*
|
317
|
* @param sourceType
|
318
|
* @param targetType
|
319
|
* @return "resultResult_"+targetType+sourceType+"_isRelatedTo"
|
320
|
*/
|
321
|
private String createSemanticsType(String sourceType,String targetType){
|
322
|
String semantics=null;
|
323
|
// if((targetType.equals(ClaimUtils.PUBLICATION))&&(sourceType.equals(ClaimUtils.DATASET))){
|
324
|
// semantics="resultResult_relationship_isRelatedTo";
|
325
|
// }
|
326
|
// else if(targetType.equals(ClaimUtils.DATASET)&&sourceType.equals(ClaimUtils.PUBLICATION)){
|
327
|
// semantics="resultResult_relationship_isRelatedTo";
|
328
|
// }
|
329
|
// if((targetType.equals(ClaimUtils.PUBLICATION))&&(sourceType.equals(ClaimUtils.SOFTWARE))){
|
330
|
// semantics="resultResult_relationship_isRelatedTo";
|
331
|
// }
|
332
|
// else if(targetType.equals(ClaimUtils.SOFTWARE)&&sourceType.equals(ClaimUtils.PUBLICATION)){
|
333
|
// semantics="resultResult_relationship_isRelatedTo";
|
334
|
// }
|
335
|
// if((targetType.equals(ClaimUtils.DATASET))&&(sourceType.equals(ClaimUtils.SOFTWARE))){
|
336
|
// semantics="resultResult_relationship_isRelatedTo";
|
337
|
// }
|
338
|
// else if(targetType.equals(ClaimUtils.SOFTWARE)&&sourceType.equals(ClaimUtils.DATASET)){
|
339
|
// semantics="resultResult_relationship_isRelatedTo";
|
340
|
// }
|
341
|
// else if((targetType.equals(ClaimUtils.PUBLICATION))&&(sourceType.equals(ClaimUtils.PUBLICATION))){
|
342
|
// semantics="resultResult_relationship_isRelatedTo";
|
343
|
// }
|
344
|
// else if(targetType.equals(ClaimUtils.DATASET)&&sourceType.equals(ClaimUtils.DATASET)){
|
345
|
// semantics="resultResult_relationship_isRelatedTo";
|
346
|
// }
|
347
|
// else if(targetType.equals(ClaimUtils.SOFTWARE)&&sourceType.equals(ClaimUtils.SOFTWARE)){
|
348
|
// semantics="resultResult_supplement_isSupplementTo";
|
349
|
// }
|
350
|
//add above more specific semantics for pub,data and software
|
351
|
if((targetType.equals(ClaimUtils.PUBLICATION)||targetType.equals(ClaimUtils.DATASET)||targetType.equals(ClaimUtils.SOFTWARE)||targetType.equals(ClaimUtils.OTHER))&&(sourceType.equals(ClaimUtils.PUBLICATION)||sourceType.equals(ClaimUtils.DATASET)||sourceType.equals(ClaimUtils.SOFTWARE)||sourceType.equals(ClaimUtils.OTHER))){
|
352
|
semantics="resultResult_relationship_isRelatedTo";
|
353
|
}
|
354
|
else if((targetType.equals(ClaimUtils.PUBLICATION)||targetType.equals(ClaimUtils.DATASET)||targetType.equals(ClaimUtils.SOFTWARE)||targetType.equals(ClaimUtils.OTHER))&&(sourceType.equals(ClaimUtils.PROJECT))){
|
355
|
semantics= "resultProject_outcome_produces"; //"resultProject_outcome_isProducedBy";
|
356
|
}
|
357
|
else if((targetType.equals(ClaimUtils.PUBLICATION)||targetType.equals(ClaimUtils.DATASET)||targetType.equals(ClaimUtils.SOFTWARE)||targetType.equals(ClaimUtils.OTHER))&&(sourceType.equals(ClaimUtils.CONTEXT))){
|
358
|
semantics= "isRelevantTo";
|
359
|
}
|
360
|
|
361
|
return semantics;
|
362
|
}
|
363
|
/* public String generateInsertClaimResultQuery(Result targetResult, Result sourceResult, Claim claim) {
|
364
|
|
365
|
return generateInsertClaimResultQuery(generateInsertResultQuery(targetResult.getOpenaireId(), targetResult.getResultType(), targetResult.getTitle(), targetResult.getCollectedFrom(), targetResult.getExternalUrl(), targetResult.getDOI(),targetResult.getOrcidworkid(), targetResult.getAccessRights(), targetResult.getEmbargoEndDate(), targetResult.getBestLicense(), targetResult.getRecordPath(), targetResult.getRecordFormat()),
|
366
|
generateInsertResultQuery(sourceResult.getOpenaireId(), sourceResult.getResultType(), sourceResult.getTitle(), sourceResult.getCollectedFrom(), sourceResult.getExternalUrl(), sourceResult.getDOI(), sourceResult.getOrcidworkid(), sourceResult.getAccessRights(), targetResult.getEmbargoEndDate(), sourceResult.getBestLicense(), sourceResult.getRecordPath(),sourceResult.getRecordFormat()),claim);
|
367
|
}
|
368
|
public String generateInsertClaimProjectQuery(String targetQuery, String projectQuery, Claim claim) {
|
369
|
|
370
|
return " WITH ins1 AS (\n" +
|
371
|
targetQuery+
|
372
|
" ),\n ins2 AS (\n" +
|
373
|
projectQuery+
|
374
|
" ),\n ins3 AS (\n" +
|
375
|
generateInsertClaimQuery(claim.getDate(), claim.getUserMail(), claim.getSourceType(), claim.getTargetType(), claim.getSource().getOpenaireId(), claim.getTarget().getOpenaireId(),"resultProject_outcome_isProducedBy") +
|
376
|
" ),\n ins4 AS (\n" +
|
377
|
" INSERT INTO has_source_project (claim_id, openaire_id)\n" +
|
378
|
" SELECT id, source_id\n" +
|
379
|
" FROM ins3) \n"+
|
380
|
" INSERT INTO has_target_result(claim_id, openaire_id)\n" +
|
381
|
" SELECT id, target_id\n" +
|
382
|
" FROM ins3;";
|
383
|
}
|
384
|
public String generateInsertClaimProjectQuery(Result targetResult, Project project, Claim claim) {
|
385
|
|
386
|
return
|
387
|
generateInsertClaimProjectQuery(generateInsertResultQuery(targetResult.getOpenaireId(), targetResult.getResultType(), targetResult.getTitle(), targetResult.getCollectedFrom(), targetResult.getExternalUrl(), targetResult.getDOI(), targetResult.getOrcidworkid(), targetResult.getAccessRights(), targetResult.getEmbargoEndDate(), targetResult.getBestLicense(), targetResult.getRecordPath(),targetResult.getRecordFormat()),
|
388
|
generateInsertProjectQuery(project.getOpenaireId(), project.getName(), project.getAcronym(), project.getFunderId(), project.getFunderName(), project.getFunderShortName()), claim);
|
389
|
}
|
390
|
public String generateInsertClaimContextQuery(Result targetResult, Context context, Claim claim) {
|
391
|
|
392
|
return generateInsertClaimContextQuery
|
393
|
(generateInsertResultQuery(targetResult.getOpenaireId(), targetResult.getResultType(), targetResult.getTitle(), targetResult.getCollectedFrom(), targetResult.getExternalUrl(), targetResult.getDOI(), targetResult.getOrcidworkid(), targetResult.getAccessRights(), targetResult.getEmbargoEndDate(), targetResult.getBestLicense(), targetResult.getRecordPath(),targetResult.getRecordFormat())
|
394
|
,generateInsertContextQuery(context.getOpenaireId(), context.getTitle()),claim);
|
395
|
}
|
396
|
public String generateInsertClaimContextQuery(String targetQuery,String sourceQuery, Claim claim) {
|
397
|
|
398
|
return " WITH ins1 AS (\n" +targetQuery+
|
399
|
" ),\n ins2 AS (\n" +
|
400
|
sourceQuery+
|
401
|
" ),\n ins3 AS (\n" +
|
402
|
generateInsertClaimQuery(claim.getDate(), claim.getUserMail(), claim.getSourceType(), claim.getTargetType(), claim.getSource().getOpenaireId(), claim.getTarget().getOpenaireId(),"") +
|
403
|
" ), ins4 AS (\n" +
|
404
|
" INSERT INTO has_source_context(claim_id, openaire_id)\n" +
|
405
|
" SELECT id, source_id\n" +
|
406
|
" FROM ins3) \n"+
|
407
|
" INSERT INTO has_target_result(claim_id, openaire_id)\n" +
|
408
|
" SELECT id, target_id\n" +
|
409
|
" FROM ins3;";
|
410
|
}
|
411
|
*/
|
412
|
/**
|
413
|
** Delete Tables Queries **
|
414
|
**/
|
415
|
|
416
|
public String generateDeleteClaimTablesQuery() {
|
417
|
return "drop table if exists has_source_context;\n" +
|
418
|
"drop table if exists has_source_project;\n" +
|
419
|
"drop table if exists has_source_result;\n" +
|
420
|
"drop table if exists has_target_project;\n" +
|
421
|
"drop table if exists has_target_result;\n" +
|
422
|
"drop table if exists claim;\n" +
|
423
|
"drop table if exists project;\n" +
|
424
|
"drop table if exists result;\n" +
|
425
|
"drop table if exists context;\n" +
|
426
|
"drop table if exists claims_orphan_ids;\n" +
|
427
|
"\n ";
|
428
|
|
429
|
}
|
430
|
|
431
|
/**
|
432
|
** Create Tables Queries **
|
433
|
**/
|
434
|
|
435
|
public String generateCreateClaimTablesQuery() {
|
436
|
return "CREATE TABLE project (\n" +
|
437
|
" openaire_id varchar(60) primary key NOT NULL,\n" +
|
438
|
" name text NOT NULL,\n" +
|
439
|
" acronym text,\n" +
|
440
|
" funder_id varchar(60) NOT NULL,\n" +
|
441
|
" funder_name text NOT NULL,\n" +
|
442
|
" funder_acronym text NOT NULL,\n" +
|
443
|
" notify boolean DEFAULT TRUE,\n" +
|
444
|
" contact_person text[],\n" +
|
445
|
" token varchar(60)\n" +
|
446
|
");\n" +
|
447
|
"\n" +
|
448
|
"CREATE TABLE result (\n" +
|
449
|
" id serial NOT NULL,\n" +
|
450
|
" openaire_id varchar(60) primary key NOT NULL,\n" +
|
451
|
"\t\tresult_type varchar(30) NOT NULL,\n" +
|
452
|
"\t\tdoi text,\n" +
|
453
|
"\t\torcidworkid text,\n" +
|
454
|
"\t\ttitle text,\n" +
|
455
|
"\t\taccess_rights varchar(30),\n" +
|
456
|
"\t\tembargo_end_date date,\n" +
|
457
|
"\t\tbest_license varchar(30),\t\t\n" +
|
458
|
"\t\texternal_url text,\n" +
|
459
|
"\t\tcollected_from varchar(60) ,\n" +
|
460
|
"\t\trecord_path text , \n" +
|
461
|
"\t\trecord_format varchar(10)\n" +
|
462
|
");\n" +
|
463
|
"\n" +
|
464
|
"CREATE TABLE context (\n" +
|
465
|
" openaire_id varchar(60) primary key,\n" +
|
466
|
" name text\n" +
|
467
|
");\n" +
|
468
|
"CREATE TABLE claim (\n" +
|
469
|
" id serial primary key NOT NULL,\n" +
|
470
|
" claim_date timestamp without time zone NOT NULL,\n" +
|
471
|
" claimedBy text NOT NULL,\n" +
|
472
|
" source_type varchar(30) NOT NULL,\n" +
|
473
|
" target_type varchar(30) NOT NULL,\n" +
|
474
|
" source_id varchar(60) NOT NULL,\n" +
|
475
|
" target_id varchar(60) references result(openaire_id) NOT NULL,\n" +
|
476
|
" curation_date timestamp without time zone,\n" +
|
477
|
" curated_by text,\n" +
|
478
|
" approved boolean DEFAULT TRUE,\n" +
|
479
|
" claim_status varchar(30),\n" +
|
480
|
" semantics varchar(60) NOT NULL\n" +
|
481
|
");\n" +
|
482
|
"\n" +
|
483
|
"CREATE TABLE has_source_context(\n" +
|
484
|
"\tclaim_id int references claim(id) NOT NULL,\n" +
|
485
|
"\topenaire_id varchar(60) references context(openaire_id) NOT NULL\n" +
|
486
|
");\n" +
|
487
|
"CREATE TABLE has_source_project(\n" +
|
488
|
"\tclaim_id int references claim(id) NOT NULL,\n" +
|
489
|
"\topenaire_id varchar(60) references project(openaire_id) NOT NULL\n" +
|
490
|
");\n" +
|
491
|
"CREATE TABLE has_source_result(\n" +
|
492
|
"\tclaim_id int references claim(id) NOT NULL,\n" +
|
493
|
"\topenaire_id varchar(60) references result(openaire_id) NOT NULL\n" +
|
494
|
");\n"+
|
495
|
"CREATE TABLE has_target_project(\n" +
|
496
|
"\tclaim_id int references claim(id) NOT NULL,\n" +
|
497
|
"\topenaire_id varchar(60) references project(openaire_id) NOT NULL\n" +
|
498
|
");\n" +
|
499
|
"CREATE TABLE has_target_result(\n" +
|
500
|
"\tclaim_id int references claim(id) NOT NULL,\n" +
|
501
|
"\topenaire_id varchar(60) references result(openaire_id) NOT NULL\n" +
|
502
|
");\n"+
|
503
|
"CREATE TABLE claims_orphan_ids (\n" +
|
504
|
" id integer "+
|
505
|
");\n"
|
506
|
|
507
|
;
|
508
|
|
509
|
}
|
510
|
|
511
|
/**
|
512
|
** Select Queries *Old* Database **
|
513
|
**/
|
514
|
|
515
|
|
516
|
public String generateSelectDMFByIdQuery(String id) {
|
517
|
return " Select * from "+this.migrationTable+" where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' and resultid='"+id+"' order by date desc limit 1";
|
518
|
}
|
519
|
|
520
|
public String generateSelectConceptDMFClaimsQuery(Integer limit) {
|
521
|
return " Select * from "+this.migrationTable+" where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' "+(limit>0?" limit "+limit:"");
|
522
|
}
|
523
|
/**
|
524
|
*
|
525
|
* @param limit : for limit > 0 the query adds limit clause, for limit < 0 query skips limit clause
|
526
|
* @return
|
527
|
*/
|
528
|
public String generateSelectRelationEnrichedWithDMFClaimsQuery(Integer limit) {
|
529
|
return " select rel.*, dmf.dmf from (Select * from "+this.migrationTable+" where type='rels2actions' order by id) as rel left outer join \n" +
|
530
|
"(Select DISTINCT ON (resultid) resultid,date, xml as dmf from "+this.migrationTable+" where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' order by resultid,date desc , xml) as dmf on rel.resultid=dmf.resultid "+
|
531
|
" order by rel.id "
|
532
|
+(limit>0?" limit "+limit:"");
|
533
|
|
534
|
}
|
535
|
|
536
|
/**
|
537
|
*
|
538
|
* @param limit : for limit > 0 the query adds limit clause, for limit < 0 query skips limit clause
|
539
|
* @return
|
540
|
*/
|
541
|
public String generateSelectConceptClaimsEnrichedWithDMFClaimsQuery(Integer limit) {
|
542
|
return " select rel.*, dmf.dmf from (Select * from "+this.migrationTable+" where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' order by id) as rel left outer join \n" +
|
543
|
"(Select DISTINCT ON (resultid) resultid,date, xml as dmf from "+this.migrationTable+" where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' order by resultid,date desc , xml) as dmf on rel.resultid=dmf.resultid"
|
544
|
+" order by rel.id "
|
545
|
+(limit>0?" limit "+limit:"");
|
546
|
|
547
|
}
|
548
|
|
549
|
public String generateSelectConceptClaimByIDEnrichedWithDMFClaimsQuery(Integer limit, String claimID) {
|
550
|
return " select rel.*, dmf.dmf from (Select * from "+this.migrationTable+" where id='"+claimID+"' and ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%') as rel left outer join \n" +
|
551
|
"(Select DISTINCT ON (resultid) resultid,date, xml as dmf from "+this.migrationTable+" where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' order by resultid,date desc , xml) as dmf on rel.resultid=dmf.resultid"
|
552
|
+(limit>0?" limit "+limit:"");
|
553
|
}
|
554
|
public String generateSelectRelationClaimByIDEnrichedWithDMFClaimsQuery(Integer limit, String claimID) {
|
555
|
return " select rel.*, dmf.dmf from (Select * from "+this.migrationTable+" where id='"+claimID+"' and type='rels2actions' ) as rel left outer join \n" +
|
556
|
"(Select DISTINCT ON (resultid) resultid,date, xml as dmf from "+this.migrationTable+" where type='dmf2actions' and xml NOT ILIKE '%<oaf:concept%' order by resultid,date desc , xml) as dmf on rel.resultid=dmf.resultid"
|
557
|
+(limit>0?" limit "+limit:"");
|
558
|
}
|
559
|
|
560
|
|
561
|
public String generateSelectConceptClaimByIdQuery(String id) {
|
562
|
return " Select * from "+this.migrationTable+" where ( type='dmf2actions' or type='updates2actions' ) and xml LIKE '%<oaf:concept%' and id='"+id+"'";
|
563
|
|
564
|
}
|
565
|
public String generateSelectRelationClaimByIdQuery(String id) {
|
566
|
return " Select * from "+this.migrationTable+" where type='rels2actions' and id='"+id+"'";
|
567
|
|
568
|
}
|
569
|
|
570
|
|
571
|
/**
|
572
|
** Select - Fetch Queries *New* Database **
|
573
|
**/
|
574
|
|
575
|
|
576
|
private String addPagingClause(Integer limit, Integer offset) {
|
577
|
if(limit==null && offset==null){
|
578
|
return "";
|
579
|
}
|
580
|
else if((limit==null || offset==null || offset <0 || limit<=0)){
|
581
|
limit=10;
|
582
|
offset=0;
|
583
|
}
|
584
|
return " limit " + limit + " offset " + offset;
|
585
|
|
586
|
}
|
587
|
private String addOrderByClause( String orderBy, boolean desc) {
|
588
|
if(orderBy==null){
|
589
|
return null;
|
590
|
}else if(orderBy.equals("date")){
|
591
|
return " order by claim.claim_date "+((desc)?"desc":"asc");
|
592
|
}else if(orderBy.equals("user")){
|
593
|
return " order by claim.claimedBy "+((desc)?"desc":"asc");
|
594
|
|
595
|
}else if(orderBy.equals("source")){
|
596
|
return " order by claim.source_title "+((desc)?"desc":"asc");
|
597
|
|
598
|
}else if(orderBy.equals("target")){
|
599
|
return " order by claim.target_title "+((desc)?"desc":"asc");
|
600
|
|
601
|
}else{
|
602
|
return " order by claim.claim_date desc";
|
603
|
}
|
604
|
|
605
|
}
|
606
|
|
607
|
private String addFilterByType( List<String> types, ArrayList<Object> params) {
|
608
|
logger.debug(types);
|
609
|
if(types == null || types.isEmpty() || (types.size() == 1 && types.get(0).isEmpty())){
|
610
|
return null;
|
611
|
}else if (types.contains(ClaimUtils.PUBLICATION) && types.contains(ClaimUtils.DATASET) && types.contains(ClaimUtils.SOFTWARE) && types.contains(ClaimUtils.PROJECT) && types.contains(ClaimUtils.CONTEXT) && types.contains(ClaimUtils.OTHER) ){
|
612
|
//it's all types - no need to filter
|
613
|
return null;
|
614
|
}
|
615
|
else{
|
616
|
String filter = "";
|
617
|
for(String type: types){
|
618
|
filter+=((filter.length()>0)?" or ":"")+" claim.source_type = ? or claim.target_type = ?";
|
619
|
params.add(type);
|
620
|
params.add(type);
|
621
|
}
|
622
|
return filter;
|
623
|
}
|
624
|
}
|
625
|
|
626
|
public String generateCountByUser(String user ,String keyword,List<String> types, ArrayList<Object> params) {
|
627
|
if((keyword == null || keyword.equals(""))&&types.isEmpty()){
|
628
|
params.add(user);
|
629
|
return " select count(*) from claim where "+ " claim.claimedBy=?";
|
630
|
}
|
631
|
return " select count(*) from claim where claim.id in ( select claim.id from ("+generateFetchClaimsByUser(user, null,null,keyword,null,false,types, params)+")as claim )";
|
632
|
}
|
633
|
public String generateCountByDate(String dateFrom, String dateTo ,String keyword,List<String> types, ArrayList<Object> params) {
|
634
|
if((keyword == null || keyword.equals(""))&&types.isEmpty()){
|
635
|
params.add(dateFrom);
|
636
|
params.add(dateTo);
|
637
|
return " select count(*) from claim where "+ " claim.claim_date >= ?::timestamp and claim.claim_date <= ?::timestamp ";
|
638
|
}
|
639
|
return " select count(*) from claim where claim.id in ( select claim.id from ("+generateFetchClaimsByDate(dateFrom,dateTo, null,null,keyword,null,false, types, params)+")as claim )";
|
640
|
}
|
641
|
public String generateCountByProject(String projectId ,String keyword, List<String> types, ArrayList<Object> params) {
|
642
|
if((keyword == null || keyword.equals(""))&&types.isEmpty()){
|
643
|
params.add(projectId);
|
644
|
return " select count(*) from claim where "+"claim.source_id =?";
|
645
|
}
|
646
|
return " select count(*) from claim where claim.id in ( select claim.id from ("+generateFetchClaimsByProject(projectId, null,null,keyword,null,false, types, params)+")as claim )";
|
647
|
}
|
648
|
/*
|
649
|
public String generateCountByProjectToken(String projectToken,String email ,String keyword, List<String> types ) {
|
650
|
return " select count(*) from claim where claim.id in ( select claim.id from ("+generateFetchClaimsByProjectToken(projectToken, email,null,null,keyword,null,false, types)+")as claim )";
|
651
|
}
|
652
|
*/
|
653
|
public String generateCountByFunder(String funderId ,String keyword, List<String> types, ArrayList<Object> params) {
|
654
|
if((keyword == null || keyword.equals(""))&&types.isEmpty()){
|
655
|
params.add(funderId);
|
656
|
return " select count(*) from claim,project as source where claim.source_id = source.openaire_id and source.funder_id =?";
|
657
|
}
|
658
|
return " select count(*) from claim where claim.id in ( select claim.id from ("+generateFetchClaimsByFunder(funderId, null,null,keyword,null,false, types, params)+")as claim )";
|
659
|
}
|
660
|
public String generateCountByContext(String contextId ,String keyword, List<String> types, ArrayList<Object> params) {
|
661
|
if((keyword == null || keyword.equals(""))&&types.isEmpty()){
|
662
|
params.add(contextId+"%");
|
663
|
return " select count(*) from claim where "+" claim.source_id like ?";
|
664
|
}
|
665
|
return " select count(*) from claim where claim.id in ( select claim.id from ("+generateFetchClaimsByContext(contextId, null,null,keyword,null,false, types, params)+")as claim )";
|
666
|
|
667
|
}
|
668
|
public String generateCountByResult(String resultId ,String keyword, List<String> types, ArrayList<Object> params) {
|
669
|
if((keyword == null || keyword.equals(""))&&types.isEmpty()){
|
670
|
params.add(resultId);
|
671
|
params.add(resultId);
|
672
|
return " select count(*) from claim where "+" ( claim.source_id= ? or claim.target_id = ? )";
|
673
|
}
|
674
|
return " select count(*) from claim where claim.id in ( select claim.id from ("+generateFetchClaimsByResult(resultId, null,null,keyword,null,false,types, params)+")as claim )";
|
675
|
|
676
|
}
|
677
|
|
678
|
public String generateCountAllClaims(String keyword,List<String> types, ArrayList<Object> params) {
|
679
|
if((keyword == null || keyword.equals(""))&&types.isEmpty()){
|
680
|
String filterByType = addFilterByType(types, params);
|
681
|
//if(filterByType!= null){
|
682
|
// params.add(filterByType);
|
683
|
//}
|
684
|
return "select count(*) from claim "+((filterByType==null)?"":" where " + filterByType);
|
685
|
}
|
686
|
return " select count(*) from claim where claim.id in ( select claim.id from ("+generateFetchClaims(null,null,keyword,null,false,types, params)+" ) as claim )";
|
687
|
|
688
|
}
|
689
|
public String generateFetchAllProjectsQuery() {
|
690
|
return " select "+getProjectFields("source")+" from project as source";
|
691
|
|
692
|
}
|
693
|
public String generateFetchAllContextsQuery() {
|
694
|
return " select "+getContextFields("source")+" from context as source";
|
695
|
}
|
696
|
public String generateFetchClaimsByUser(String user, Integer limit, Integer offset,String keyword,String orderBy, boolean desc,List<String> types, ArrayList<Object> params) {
|
697
|
// "claim.claim_date", true
|
698
|
String clause= " claim.claimedBy=?";
|
699
|
ArrayList<Object> clauseParams = new ArrayList<>();
|
700
|
clauseParams.add(user);
|
701
|
return generateSelectClaimQueryAsUnionOfAllRelations(limit, offset, orderBy,desc,clause,clauseParams, keyword, types, params);
|
702
|
|
703
|
}
|
704
|
/**
|
705
|
*
|
706
|
* @param limit how many results to return
|
707
|
* @param offset starting from
|
708
|
* @param keyword containing keyword
|
709
|
* @return
|
710
|
*/
|
711
|
|
712
|
public String generateFetchClaims(Integer limit, Integer offset,String keyword,String orderBy, boolean desc,List<String> types, ArrayList<Object> params) {
|
713
|
return generateSelectClaimQueryAsUnionOfAllRelations(limit, offset, orderBy,desc,null,null, keyword, types, params)+"";
|
714
|
}
|
715
|
/**
|
716
|
*
|
717
|
* @param limit how many results to return
|
718
|
* @param offset starting from
|
719
|
* @return
|
720
|
*/
|
721
|
public String generateFetchClaims(Integer limit, Integer offset, String orderBy, boolean desc,List<String> types, ArrayList<Object> params) {
|
722
|
String keyword = null;
|
723
|
return generateSelectClaimQueryAsUnionOfAllRelations(limit, offset, orderBy,desc,null,null,keyword,types, params)+"";
|
724
|
|
725
|
}
|
726
|
public String generateFetchClaimsByDate(String dateFrom, String dateTo, Integer limit, Integer offset,String keyword, String orderBy, boolean desc,List<String> types, ArrayList<Object> params) {
|
727
|
String clause= " claim.claim_date >= ?::timestamp and claim.claim_date <= ?::timestamp ";
|
728
|
ArrayList<Object> clauseParams = new ArrayList<>();
|
729
|
clauseParams.add(dateFrom);
|
730
|
clauseParams.add(dateTo);
|
731
|
return generateSelectClaimQueryAsUnionOfAllRelations(limit, offset, orderBy,desc,clause, clauseParams,keyword,types, params);
|
732
|
}
|
733
|
|
734
|
public String generateFetchNumberOfClaimsByDateAndOpenaireId(String dateFrom, String dateTo, String openaireId, Integer limit, Integer offset,String keyword, String orderBy, boolean desc,List<String> types, ArrayList<Object> params) {
|
735
|
String clause= " claim.claim_date >= ?::timestamp and claim.claim_date <= ?::timestamp and source.openaire_id =? ";
|
736
|
ArrayList<Object> clauseParams = new ArrayList<>();
|
737
|
clauseParams.add(dateFrom);
|
738
|
clauseParams.add(dateTo);
|
739
|
clauseParams.add(openaireId);
|
740
|
return generateSelectCountClaimQueryAsUnionOfAllRelations(limit, offset, orderBy,desc,clause, clauseParams,keyword,types, params);
|
741
|
}
|
742
|
|
743
|
public String generateFetchClaimsByProject(String projectId, Integer limit, Integer offset,String keyword, String orderBy, boolean desc, List<String> types, ArrayList<Object> params) {
|
744
|
String clause = "source.openaire_id =?";
|
745
|
ArrayList<Object> clauseParams = new ArrayList<>();
|
746
|
clauseParams.add(projectId);
|
747
|
String filterByType = addFilterByType(types, clauseParams);
|
748
|
clause+= ((filterByType==null)?"":" and ("+filterByType+") ");
|
749
|
String query = " select * from ("+" select * from ( " + generateSelectclaimQuery(ClaimUtils.PROJECT, ClaimUtils.PUBLICATION, limit, offset, orderBy, desc, clause, clauseParams, keyword, params) + " ) as claim "+
|
750
|
") as claim ";
|
751
|
|
752
|
return query;
|
753
|
}
|
754
|
/*
|
755
|
public String generateFetchClaimsByProjectToken(String token, String email, Integer limit, Integer offset,String keyword, String orderBy, boolean desc, List<String> types) {
|
756
|
String clause = "source.token = '" + token + "' and '" + email + "' = ANY(source.contact_person)";
|
757
|
String filterByType = addFilterByType(types);
|
758
|
return " select * from ("+" select * from ( " + generateSelectclaimQuery(ClaimUtils.PROJECT, ClaimUtils.PUBLICATION, limit, offset, orderBy, desc, clause, keyword) + " ) as claim "+
|
759
|
") as claim "+
|
760
|
((filterByType==null)?"":" where "+filterByType+" ");
|
761
|
}
|
762
|
*/
|
763
|
public String generateSelectProjectIdByTokenAndEmailQuery(String token, String email, ArrayList<Object> params) {
|
764
|
params.add(token);
|
765
|
params.add(email);
|
766
|
return "SELECT openaire_id FROM project WHERE token=? AND ?= ANY(contact_person);";
|
767
|
}
|
768
|
|
769
|
public String generateSelectProjectIdByTokenQuery(String token, ArrayList<Object> params) {
|
770
|
params.add(token);
|
771
|
return "SELECT openaire_id FROM project WHERE token=?;";
|
772
|
}
|
773
|
|
774
|
public String generateFetchClaimsByContext(String contextId, Integer limit, Integer offset,String keyword, String orderBy, boolean desc, List<String> types, ArrayList<Object> params) {
|
775
|
String clause= "claim.source_id like ?";
|
776
|
ArrayList<Object> clauseParams = new ArrayList<>();
|
777
|
clauseParams.add(contextId+'%');
|
778
|
String filterByType = addFilterByType(types, clauseParams);
|
779
|
clause+= ((filterByType==null)?"":" and ("+filterByType+") ");
|
780
|
String query = " select * from ("+" ( " +generateSelectclaimQuery(ClaimUtils.CONTEXT,ClaimUtils.PUBLICATION,limit, offset, orderBy,desc,clause,clauseParams, keyword, params)+")"+
|
781
|
") as claim ";
|
782
|
return query;
|
783
|
}
|
784
|
public String generateFetchClaimsByFunder(String funderId, Integer limit, Integer offset,String keyword, String orderBy, boolean desc, List<String> types, ArrayList<Object> params) {
|
785
|
String whereClause = "source_id =source.openaire_id ";
|
786
|
ArrayList<Object> whereParams = new ArrayList<>();
|
787
|
String filterByType = addFilterByType(types, whereParams);
|
788
|
whereClause+= ((filterByType==null)?"":" and ("+filterByType+") ");
|
789
|
String query = " select * from ("+" ( " +generateSelectclaimQuery(ClaimUtils.PROJECT,ClaimUtils.PUBLICATION, limit, offset, orderBy,desc,whereClause,whereParams, keyword, params)+" )"+
|
790
|
") as claim ";
|
791
|
|
792
|
|
793
|
return query;
|
794
|
}
|
795
|
public String generateFetchClaimsByResult(String resultId, Integer limit, Integer offset, String keyword, String orderBy, boolean desc, List<String> types, ArrayList<Object> params) {
|
796
|
String queryWhereClause=" ( source.openaire_id = ? or target.openaire_id = ? )";
|
797
|
ArrayList<Object> whereParams = new ArrayList<>();
|
798
|
whereParams.add(resultId);
|
799
|
whereParams.add(resultId);
|
800
|
String filterByType = addFilterByType(types, whereParams);
|
801
|
queryWhereClause+= ((filterByType==null)?"":" and ("+filterByType+") ");
|
802
|
String query = " select * from ("+" ( " +generateSelectclaimQuery(ClaimUtils.PUBLICATION,ClaimUtils.PUBLICATION, limit, offset, orderBy,desc,queryWhereClause,whereParams, keyword, params)+" ) \nunion "+
|
803
|
" ( " +generateSelectclaimQuery(ClaimUtils.PROJECT,ClaimUtils.PUBLICATION, limit, offset, orderBy,desc,queryWhereClause,whereParams, keyword, params)+" ) \nunion "+
|
804
|
" ( " +generateSelectclaimQuery(ClaimUtils.CONTEXT,ClaimUtils.PUBLICATION, limit, offset, orderBy,desc,queryWhereClause,whereParams, keyword, params)+" ) "+
|
805
|
") as claim ";
|
806
|
|
807
|
return query;
|
808
|
|
809
|
}
|
810
|
|
811
|
public String generateFetchClaimsByClaimId(String claimId, String sourceType, String targetType, ArrayList<Object> params) {
|
812
|
String keyword = null;
|
813
|
String clause= " claim.id = ?::int ";
|
814
|
ArrayList<Object> clauseParams = new ArrayList<>();
|
815
|
clauseParams.add(claimId);
|
816
|
String orderbyLimitClause= null;
|
817
|
if(sourceType.equals(ClaimUtils.PUBLICATION)||sourceType.equals(ClaimUtils.DATASET)||sourceType.equals(ClaimUtils.SOFTWARE)||sourceType.equals(ClaimUtils.OTHER)){
|
818
|
return generateSelectclaimQuery(sourceType,targetType,null,null,null,false, clause,clauseParams,keyword, params);
|
819
|
}else if(sourceType.equals(ClaimUtils.PROJECT)){
|
820
|
return generateSelectclaimQuery(sourceType,targetType,null,null,null,false, clause,clauseParams,keyword, params);
|
821
|
}else if(sourceType.equals(ClaimUtils.CONTEXT)){
|
822
|
return generateSelectclaimQuery(sourceType,targetType,null,null,null,false, clause,clauseParams,keyword, params);
|
823
|
}
|
824
|
return null;
|
825
|
}
|
826
|
|
827
|
private String getClaimFields() {
|
828
|
return " claim.id, claim.claim_date, claim.claimedBy, claim.source_type, claim.target_type, claim.semantics, claim.curation_date, claim.curated_by, claim.approved ";
|
829
|
}
|
830
|
private String getResultFields(String tableAlias) {
|
831
|
return " "+tableAlias+".openaire_id, "+tableAlias+".title "+tableAlias+"_title, "+tableAlias+".result_type, "+tableAlias+".doi, "+tableAlias+".orcidworkid, "+tableAlias+".access_rights, "+tableAlias+".embargo_end_date, "+tableAlias+".best_license, "+tableAlias+".external_url, "+tableAlias+".collected_from, "+tableAlias+".record_path, "+tableAlias+".record_format ";
|
832
|
}
|
833
|
private String getProjectFields(String tableAlias) {
|
834
|
return " "+tableAlias+".openaire_id, "+tableAlias+".name as "+tableAlias+"_title, "+tableAlias+".acronym, "+tableAlias+".funder_id, "+tableAlias+".funder_name, "+tableAlias+".funder_acronym, null as field7, array_to_string("+tableAlias+".contact_person,','), null as field9, null as field10, null as field11, null as field12 ";
|
835
|
}
|
836
|
private String getContextFields(String tableAlias) {
|
837
|
return " "+tableAlias+".openaire_id, "+tableAlias+".name "+tableAlias+"_title, "+" null as field4, null as field5, null as field6, null as field7, null as field8, null as field9, null as field10, null as field11, null as field12, null as field13 ";
|
838
|
}
|
839
|
|
840
|
private String getFieldsPerType(String type, String tableAlias){
|
841
|
String fields= null;
|
842
|
|
843
|
if (type != null) {
|
844
|
if (type.equals(ClaimUtils.PUBLICATION) || type.equals(ClaimUtils.DATASET) || type.equals(ClaimUtils.SOFTWARE)||type.equals(ClaimUtils.OTHER)) {
|
845
|
fields = getResultFields(tableAlias);
|
846
|
|
847
|
} else if (type.equals(ClaimUtils.PROJECT)) {
|
848
|
fields = getProjectFields(tableAlias);
|
849
|
|
850
|
} else if (type.equals(ClaimUtils.CONTEXT)) {
|
851
|
fields = getContextFields(tableAlias);
|
852
|
}
|
853
|
}
|
854
|
|
855
|
return fields;
|
856
|
}
|
857
|
//private String generateSelectclaimQuery(String sourceType, String targetType, Integer limit,Integer offset,String orderBy, boolean desc,String whereClause, String keyword, ArrayList<Object> params) {
|
858
|
private String generateSelectclaimQuery(String sourceType, String targetType, Integer limit,Integer offset,String orderBy, boolean desc,String whereClause, ArrayList<Object> whereParams, String keyword, ArrayList<Object> params) {
|
859
|
if(sourceType == null || targetType == null){
|
860
|
return null;
|
861
|
}
|
862
|
/*
|
863
|
" select "+getClaimFields()+" ,"+getFieldsPerType(sourceType, "source")+" , "+getFieldsPerType(targetType,"target")+
|
864
|
" \nfrom claim, "+getTypeForTable(sourceType)+" as source, "+getTypeForTable(targetType)+" as target \n" +
|
865
|
"where claim.source_id = source.openaire_id and claim.target_id = target.openaire_id "+((specificWhereClause==null)?"":" and "+specificWhereClause+" ");
|
866
|
*/
|
867
|
String orderByClause= addOrderByClause(orderBy,desc);
|
868
|
String pagingClause= addPagingClause(limit,offset);
|
869
|
String query = " select "+getClaimFields()+" ,"+getFieldsPerType(sourceType, "source")+" , "+getFieldsPerType(targetType,"target")+
|
870
|
" \nfrom claim, "+getTypeForTable(sourceType)+" as source, has_source_"+getTypeForTable(sourceType)+", has_target_"+getTypeForTable(targetType)+", "+getTypeForTable(targetType)+" as target \n" +
|
871
|
"where claim.id = has_source_"+getTypeForTable(sourceType)+".claim_id and has_source_"+getTypeForTable(sourceType)+".openaire_id = source.openaire_id " +
|
872
|
"and claim.id = has_target_"+getTypeForTable(targetType)+".claim_id and has_target_"+getTypeForTable(targetType)+".openaire_id = target.openaire_id "+
|
873
|
((keyword==null)?"":(" and ("+getKeywordClauseForType(sourceType, "source", keyword, params)+" or "+getKeywordClauseForType(targetType, "target", keyword, params)+" ")+" or "+getKeywordClauseForClaim( keyword, params)+" )")+
|
874
|
((whereClause==null)?"":" and "+whereClause+" ")+
|
875
|
((orderByClause==null)?"":" "+orderByClause+" ")+
|
876
|
pagingClause;
|
877
|
if(whereParams != null && !whereParams.isEmpty()) {
|
878
|
params.addAll(whereParams);
|
879
|
}
|
880
|
return query;
|
881
|
}
|
882
|
private String getKeywordClauseForType(String type,String tableAlias,String keyword, ArrayList<Object> params){
|
883
|
if (type == null ||keyword == null){
|
884
|
return "";
|
885
|
}
|
886
|
keyword=keyword.toLowerCase();
|
887
|
if (type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET)||type.equals(ClaimUtils.SOFTWARE)||type.equals(ClaimUtils.OTHER)){
|
888
|
params.add("%" + keyword + "%");
|
889
|
params.add("%" + keyword + "%");
|
890
|
return " (lower("+tableAlias+".title) like ? or lower("+tableAlias+".doi) like ?"+")";
|
891
|
}else if (type.equals(ClaimUtils.PROJECT)){
|
892
|
params.add("%" + keyword + "%");
|
893
|
params.add("%" + keyword + "%");
|
894
|
params.add("%" + keyword + "%");
|
895
|
params.add("%" + keyword + "%");
|
896
|
return " (lower("+tableAlias+".name) like ? or lower("+tableAlias+".acronym) like ? or lower("+tableAlias+".funder_name) like ? or lower("+tableAlias+".funder_acronym) like ? "+")";
|
897
|
}else if (type.equals(ClaimUtils.CONTEXT)){
|
898
|
params.add("%" + keyword + "%");
|
899
|
return " (lower("+tableAlias+".name) like ? )";
|
900
|
}
|
901
|
return "";
|
902
|
}
|
903
|
private String getKeywordClauseForClaim(String keyword, ArrayList<Object> params){
|
904
|
if (keyword == null){
|
905
|
return "";
|
906
|
}else {
|
907
|
params.add("%" + keyword.toLowerCase() + "%");
|
908
|
return " (lower(claim.claimedby) like ?)";
|
909
|
}
|
910
|
}
|
911
|
private String generateSelectClaimQueryAsUnionOfAllRelations(Integer limit,Integer offset,String orderBy, boolean desc,String specificWhereClause,ArrayList<Object> whereParams, String keyword,List<String> types, ArrayList<Object> params) {
|
912
|
//TODO eliminate unions based on the to
|
913
|
// ClaimUtils.PUBLICATION or ClaimUtils.DATASET it
|
914
|
String orderByClause= addOrderByClause(orderBy,desc);
|
915
|
String pagingClause= addPagingClause(limit,offset);
|
916
|
String query = "select * from ("+
|
917
|
|
918
|
" ( " +generateSelectclaimQuery(ClaimUtils.PUBLICATION,ClaimUtils.PUBLICATION,null,null,null,false, specificWhereClause,whereParams,keyword, params)+" ) \nunion "+
|
919
|
" ( " +generateSelectclaimQuery(ClaimUtils.DATASET,ClaimUtils.DATASET,null,null,null,false, specificWhereClause, whereParams,keyword, params)+" ) \nunion "+
|
920
|
" ( " +generateSelectclaimQuery(ClaimUtils.SOFTWARE,ClaimUtils.SOFTWARE,null,null,null,false, specificWhereClause, whereParams,keyword, params)+" ) \nunion "+
|
921
|
" ( " +generateSelectclaimQuery(ClaimUtils.OTHER,ClaimUtils.OTHER,null,null,null,false, specificWhereClause, whereParams,keyword, params)+" ) \nunion "+
|
922
|
" ( " +generateSelectclaimQuery(ClaimUtils.PROJECT,ClaimUtils.PUBLICATION, null,null,null,false, specificWhereClause, whereParams,keyword, params)+" ) \nunion "+
|
923
|
" ( " +generateSelectclaimQuery(ClaimUtils.CONTEXT,ClaimUtils.PUBLICATION,null,null,null,false, specificWhereClause, whereParams, keyword, params)+" )" +
|
924
|
|
925
|
") as claim ";
|
926
|
String filterByType = addFilterByType(types, params);
|
927
|
query += ((filterByType==null)?"":" where "+filterByType+" ")+
|
928
|
((orderByClause==null)?"":" "+orderByClause+" ")+
|
929
|
pagingClause;
|
930
|
|
931
|
return query;
|
932
|
}
|
933
|
private String generateSelectCountClaimQueryAsUnionOfAllRelations(Integer limit,Integer offset,String orderBy, boolean desc,String specificWhereClause,ArrayList<Object> whereParams, String keyword,List<String> types, ArrayList<Object> params) {
|
934
|
//TODO eliminate unions based on the to
|
935
|
// ClaimUtils.PUBLICATION or ClaimUtils.DATASET it
|
936
|
String orderByClause= addOrderByClause(orderBy,desc);
|
937
|
String pagingClause= addPagingClause(limit,offset);
|
938
|
String query = "select count(id) from ("+
|
939
|
|
940
|
" ( " +generateSelectclaimQuery(ClaimUtils.PUBLICATION,ClaimUtils.PUBLICATION,null,null,null,false, specificWhereClause,whereParams,keyword, params)+" ) \nunion "+
|
941
|
" ( " +generateSelectclaimQuery(ClaimUtils.DATASET,ClaimUtils.DATASET,null,null,null,false, specificWhereClause, whereParams,keyword, params)+" ) \nunion "+
|
942
|
" ( " +generateSelectclaimQuery(ClaimUtils.SOFTWARE,ClaimUtils.SOFTWARE,null,null,null,false, specificWhereClause, whereParams,keyword, params)+" ) \nunion "+
|
943
|
" ( " +generateSelectclaimQuery(ClaimUtils.OTHER,ClaimUtils.OTHER,null,null,null,false, specificWhereClause, whereParams,keyword, params)+" ) \nunion "+
|
944
|
" ( " +generateSelectclaimQuery(ClaimUtils.PROJECT,ClaimUtils.PUBLICATION, null,null,null,false, specificWhereClause, whereParams,keyword, params)+" ) \nunion "+
|
945
|
" ( " +generateSelectclaimQuery(ClaimUtils.CONTEXT,ClaimUtils.PUBLICATION,null,null,null,false, specificWhereClause, whereParams, keyword, params)+" )" +
|
946
|
|
947
|
") as claim ";
|
948
|
String filterByType = addFilterByType(types, params);
|
949
|
query += ((filterByType==null)?"":" where "+filterByType+" ")+
|
950
|
((orderByClause==null)?"":" "+orderByClause+" ")+
|
951
|
pagingClause;
|
952
|
|
953
|
return query;
|
954
|
}
|
955
|
|
956
|
private String getTypeForTable(String type){
|
957
|
if(type == null){
|
958
|
return null;
|
959
|
}
|
960
|
if(type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET) ||type.equals(ClaimUtils.SOFTWARE)||type.equals(ClaimUtils.OTHER)){
|
961
|
return "result";
|
962
|
}else{
|
963
|
return type;
|
964
|
}
|
965
|
}
|
966
|
/**
|
967
|
** Update - Queries *New* Database **
|
968
|
**/
|
969
|
|
970
|
private void updateResult(){
|
971
|
|
972
|
}
|
973
|
private void updateProject(){
|
974
|
|
975
|
}
|
976
|
/**
|
977
|
** Delete - Queries *New* Database **
|
978
|
**/
|
979
|
|
980
|
private String generateDeleteEntityQuery(String resultid, String claimId, String type, ArrayList<Object> params){
|
981
|
if(type == null||resultid == null||claimId == null ){
|
982
|
return null;
|
983
|
}
|
984
|
String query = null;
|
985
|
if(type.equals(ClaimUtils.PUBLICATION)||type.equals(ClaimUtils.DATASET) ||type.equals(ClaimUtils.SOFTWARE) ||type.equals(ClaimUtils.OTHER)){
|
986
|
query = generateDeleteResultQuery(resultid,claimId, params);
|
987
|
}else if(type.equals(ClaimUtils.PROJECT)){
|
988
|
query = generateDeleteProjectQuery(resultid,claimId, params);
|
989
|
}else if (type.equals(ClaimUtils.CONTEXT)){
|
990
|
query = generateDeleteContextQuery(resultid,claimId, params);
|
991
|
}
|
992
|
return query;
|
993
|
}
|
994
|
/*
|
995
|
Before delete check a Result, Project, Context
|
996
|
check if there is another claim in has_source_* or has_target_* relation
|
997
|
for the entity
|
998
|
*/
|
999
|
private String generateDeleteResultQuery(String resultid, String claimId, ArrayList<Object> params){
|
1000
|
params.add(resultid);
|
1001
|
String query = " DELETE FROM "+getTypeForTable(ClaimUtils.PUBLICATION)+" WHERE openaire_id = ? and NOT EXISTS \n" +
|
1002
|
" ( " +generateSelectOthersFromRelationTableQuery(resultid,claimId,getSourceTableName(ClaimUtils.PUBLICATION), params) + " union " +
|
1003
|
generateSelectOthersFromRelationTableQuery(resultid,claimId,getTargetTableName(ClaimUtils.PUBLICATION), params)+" ) ;\n" ;
|
1004
|
return query;
|
1005
|
}
|
1006
|
private String generateDeleteProjectQuery(String resultid, String claimId, ArrayList<Object> params){
|
1007
|
params.add(resultid);
|
1008
|
String query = " DELETE FROM "+getTypeForTable(ClaimUtils.PROJECT)+" WHERE openaire_id = ? and NOT EXISTS \n" +
|
1009
|
" ( " +generateSelectOthersFromRelationTableQuery(resultid,claimId,getSourceTableName(ClaimUtils.PROJECT), params) + " union " +
|
1010
|
generateSelectOthersFromRelationTableQuery(resultid,claimId,getTargetTableName(ClaimUtils.PROJECT), params)+" ) ;\n" ;
|
1011
|
return query;
|
1012
|
}
|
1013
|
private String generateDeleteContextQuery(String resultid, String claimId, ArrayList<Object> params){
|
1014
|
params.add(resultid);
|
1015
|
String query = " DELETE FROM "+getTypeForTable(ClaimUtils.CONTEXT)+" WHERE openaire_id = ? and NOT EXISTS \n" +
|
1016
|
" ( " +generateSelectOthersFromRelationTableQuery(resultid,claimId,getSourceTableName(ClaimUtils.CONTEXT), params) +" ) ;\n" ;
|
1017
|
return query;
|
1018
|
}
|
1019
|
|
1020
|
public String generateCountClaimsForResultQuery(String resultId){
|
1021
|
return " Select count(*) from claim where source_id = '"+ resultId +"' or target_id = '"+resultId+"' ";
|
1022
|
}
|
1023
|
public String generateSelectResultSource(String resultId){
|
1024
|
return " Select collected_from from result where openaire_id = '"+ resultId +"' ";
|
1025
|
}
|
1026
|
|
1027
|
/**
|
1028
|
* Select form a has_source_* or has_target_* table
|
1029
|
* ...
|
1030
|
* @param resultid
|
1031
|
* @param claimId
|
1032
|
* @param tableName
|
1033
|
* @return
|
1034
|
*/
|
1035
|
private String generateSelectOthersFromRelationTableQuery(String resultid, String claimId , String tableName, ArrayList<Object> params){
|
1036
|
params.add(resultid);
|
1037
|
params.add(claimId);
|
1038
|
String query =
|
1039
|
" SELECT 1 FROM "+ tableName+" WHERE openaire_id = ? and claim_id != ?::int " ;
|
1040
|
return query;
|
1041
|
}
|
1042
|
public String generateDeleteFullClaimQuery(String id, String user, String sourceType, String sourceId, String targetType, String targetId, ArrayList<Object> params){
|
1043
|
//TODO generate delete query
|
1044
|
params.add(id);
|
1045
|
params.add(id);
|
1046
|
params.add(id);
|
1047
|
String query =
|
1048
|
"BEGIN;\n" +
|
1049
|
//delete has_source_*
|
1050
|
"DELETE FROM "+ getSourceTableName(sourceType)+" WHERE claim_id = ?::int ;\n" +
|
1051
|
|
1052
|
//delete has_target_*
|
1053
|
"DELETE FROM "+ getTargetTableName(targetType)+" WHERE claim_id = ?::int ;\n" +
|
1054
|
|
1055
|
//delete claim
|
1056
|
"DELETE FROM claim where id = ?::int ;\n" +
|
1057
|
|
1058
|
//delete source
|
1059
|
generateDeleteEntityQuery(sourceId,id,sourceType, params)+
|
1060
|
|
1061
|
//delete target
|
1062
|
generateDeleteEntityQuery(targetId,id,targetType, params)+
|
1063
|
"COMMIT";
|
1064
|
return query;
|
1065
|
}
|
1066
|
public String generateSelectClaimQuery(String id, String user, ArrayList<Object> params){
|
1067
|
|
1068
|
params.add(id);
|
1069
|
params.add(user);
|
1070
|
String query =" ";
|
1071
|
return " Select id, source_type, source_id, target_type, target_id from claim where id = ?::int and claimedBy = ? ";
|
1072
|
}
|
1073
|
|
1074
|
public String generateSelectClaimQuery(String id, ArrayList<Object> params){
|
1075
|
|
1076
|
params.add(id);
|
1077
|
String query =" ";
|
1078
|
return " Select id, source_type, source_id, target_type, target_id,claimedBy from claim where id = ?::int";
|
1079
|
}
|
1080
|
/**
|
1081
|
* used to fetch the information from DB
|
1082
|
* @param ids
|
1083
|
* @param users
|
1084
|
* @return
|
1085
|
*/
|
1086
|
public String generateSelectClaimQuery(List<String> ids, List<String> users, ArrayList<Object> params){
|
1087
|
|
1088
|
String query =" Select id, source_type, source_id, target_type, target_id from claim where ";
|
1089
|
if(ids.size()>0 && users.size() > 0 && ids.size() == users.size()) {
|
1090
|
for (int i = 0; i < ids.size(); i++) {
|
1091
|
query+=" ( id = ? and claimedBy = ? ) or";
|
1092
|
params.add(ids.get(i));
|
1093
|
params.add(users.get(i));
|
1094
|
}
|
1095
|
query = query.substring(0, query.length()-2);
|
1096
|
return query;
|
1097
|
}
|
1098
|
return null;
|
1099
|
}
|
1100
|
|
1101
|
public String generateSelectFirstContextByCommunityIdQuery(String communityId, ArrayList<Object> params) {
|
1102
|
params.add(communityId+"%");
|
1103
|
return " Select " + getContextFields("context") + " from context where openaire_id like ? LIMIT 1;";
|
1104
|
}
|
1105
|
|
1106
|
public String generateSelectProjectByIdQuery(String projectId, ArrayList<Object> params) {
|
1107
|
params.add(projectId);
|
1108
|
return " Select " + getProjectFields("project") + " from project where openaire_id = ?";
|
1109
|
}
|
1110
|
|
1111
|
public String generateSelectContactEmailsByProjectIdQuery(String projectId, ArrayList<Object> params) {
|
1112
|
params.add(projectId);
|
1113
|
//return " SELECT contact_person FROM project WHERE openaire_id = ? ;";
|
1114
|
return "SELECT DISTINCT unnest(contact_person) as contact_person FROM project WHERE openaire_id = ?;";
|
1115
|
}
|
1116
|
|
1117
|
public String generateSelectProjectIdsAndNamesByProjectManagerMail(String userMail, ArrayList<Object> params) {
|
1118
|
params.add(userMail);
|
1119
|
return "SELECT openaire_id, name FROM project WHERE ? = ANY (contact_person);";
|
1120
|
}
|
1121
|
|
1122
|
public String generateUpdateTokenByProjectId(String projectdId, String newToken, ArrayList<Object> params) {
|
1123
|
params.add(newToken);
|
1124
|
params.add(projectdId);
|
1125
|
return "UPDATE project SET token = ? WHERE openaire_id = ?";
|
1126
|
}
|
1127
|
public String generateUpdateContactEmailsByProjectIdByProjectId(String projectdId, List<String> contactEmails, ArrayList<Object> params) {
|
1128
|
String emails = "";
|
1129
|
if(contactEmails != null && contactEmails.size() > 0){
|
1130
|
//emails+="'{";
|
1131
|
for(int i = 0; i< contactEmails.size(); i++){
|
1132
|
|
1133
|
emails+=contactEmails.get(i)+((i < contactEmails.size() -1 )?",":"");
|
1134
|
//params.add(contactEmails.get(i));
|
1135
|
}
|
1136
|
//emails+="}'";
|
1137
|
}
|
1138
|
|
1139
|
params.add(emails);
|
1140
|
params.add(projectdId);
|
1141
|
return "UPDATE project SET contact_person = string_to_array(?, ',') WHERE openaire_id = ?;";
|
1142
|
}
|
1143
|
|
1144
|
public String generateUpdateClaimCuration(String curatedBy, String claimId, boolean approved, ArrayList<Object> params) {
|
1145
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
1146
|
Date date = new Date();
|
1147
|
String dateStr=null;
|
1148
|
dateStr=(format.format(date));
|
1149
|
|
1150
|
params.add(dateStr);
|
1151
|
params.add(curatedBy);
|
1152
|
params.add(approved);
|
1153
|
params.add(claimId);
|
1154
|
String query = "UPDATE claim "
|
1155
|
+ "SET curation_date = ?::timestamp, curated_by = ?, approved = ? "
|
1156
|
+ "WHERE id = ?::int";// RETURNING curation_date, curated_by, approved";
|
1157
|
|
1158
|
logger.debug("Query to execute: "+query);
|
1159
|
|
1160
|
return query;
|
1161
|
}
|
1162
|
|
1163
|
public String generateInsertNotificationQuery(Date date, String openaire_id, String userMail, int frequency, boolean notify , ArrayList<Object> params) {
|
1164
|
|
1165
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
1166
|
String dateStr=null;
|
1167
|
dateStr=(format.format(date));
|
1168
|
String fields="last_interaction_date, user_email, frequency, notify, openaire_id";
|
1169
|
|
1170
|
String values="?::timestamp,?,?,?,?";
|
1171
|
params.add(dateStr);
|
1172
|
params.add(userMail);
|
1173
|
params.add(frequency);
|
1174
|
params.add(notify);
|
1175
|
params.add(openaire_id);
|
1176
|
|
1177
|
return " INSERT INTO notification( "+fields+")\n" +
|
1178
|
" VALUES ( "+values+")\n" +
|
1179
|
" RETURNING openaire_id, user_email\n";
|
1180
|
}
|
1181
|
|
1182
|
public String generateUpdateNotificationPreferences(String openaire_id, String userMail, int frequency, boolean notify, ArrayList<Object> params) {
|
1183
|
params.add(frequency);
|
1184
|
params.add(notify);
|
1185
|
params.add(userMail);
|
1186
|
params.add(openaire_id);
|
1187
|
String query = "UPDATE notification "
|
1188
|
+ "SET frequency = ?, notify = ? "
|
1189
|
+ "WHERE user_email = ? AND openaire_id = ?";// RETURNING curation_date, curated_by, approved";
|
1190
|
|
1191
|
logger.debug("Query to execute: "+query);
|
1192
|
|
1193
|
return query;
|
1194
|
}
|
1195
|
|
1196
|
public String generateUpdateNotificationLastInteractionDate(String openaire_id, String userMail, Date date, ArrayList<Object> params) {
|
1197
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
1198
|
String dateStr=null;
|
1199
|
dateStr=(format.format(date));
|
1200
|
|
1201
|
params.add(dateStr);
|
1202
|
params.add(userMail);
|
1203
|
params.add(openaire_id);
|
1204
|
String query = "UPDATE notification "
|
1205
|
+ "SET last_interaction_date = ?::timestamp "
|
1206
|
+ "WHERE user_email = ? AND openaire_id = ?";// RETURNING curation_date, curated_by, approved";
|
1207
|
|
1208
|
logger.debug("Query to execute: "+query);
|
1209
|
|
1210
|
return query;
|
1211
|
}
|
1212
|
|
1213
|
public String generateSelectNotificationQuery(String openaire_id, String userMail, ArrayList<Object> params) {
|
1214
|
params.add(userMail);
|
1215
|
params.add(openaire_id);
|
1216
|
String query = "SELECT * FROM notification WHERE user_email = ? AND openaire_id = ?";
|
1217
|
|
1218
|
logger.debug("Query to execute: "+query);
|
1219
|
|
1220
|
return query;
|
1221
|
}
|
1222
|
|
1223
|
public String generateSelectTrueNotificationsQuery() {
|
1224
|
String query = "SELECT * FROM notification WHERE notify=true";
|
1225
|
|
1226
|
logger.debug("Query to execute: "+query);
|
1227
|
|
1228
|
return query;
|
1229
|
}
|
1230
|
|
1231
|
public String getMigrationTable() {
|
1232
|
return migrationTable;
|
1233
|
}
|
1234
|
|
1235
|
public void setMigrationTable(String migrationTable) {
|
1236
|
this.migrationTable = migrationTable;
|
1237
|
}
|
1238
|
}
|