1
|
package gr.uoa.di.validatorweb.actions.compTest;
|
2
|
|
3
|
import gr.uoa.di.validatorweb.actions.BaseValidatorAction;
|
4
|
import gr.uoa.di.validatorweb.configs.Constants;
|
5
|
|
6
|
import java.util.ArrayList;
|
7
|
import java.util.List;
|
8
|
import java.util.Map;
|
9
|
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.apache.struts2.interceptor.RequestAware;
|
12
|
import org.apache.struts2.interceptor.SessionAware;
|
13
|
|
14
|
|
15
|
@SuppressWarnings("serial")
|
16
|
public class PopulateRules extends BaseValidatorAction implements RequestAware, SessionAware {
|
17
|
private int ruleSetId;
|
18
|
private Map<String,String> ruleSetMap;
|
19
|
private Map<String, Object> request;
|
20
|
private List<String> repositories = new ArrayList<String>();
|
21
|
private Map<String, Object> session;
|
22
|
private List<String> crisEntities= new ArrayList<String>();
|
23
|
|
24
|
private static Logger logger = Logger.getLogger(PopulateRules.class);
|
25
|
@Override
|
26
|
public String execute() throws Exception{
|
27
|
|
28
|
try {
|
29
|
// repositories = Arrays.asList(this.getRepoAPI().getBaseUrls());
|
30
|
repositories = getRepoAPI().getUrlsOfRepos((String) session.get(Constants.loggedInField));
|
31
|
setRuleSetMap(this.getOpenAIREValidator().getRuleSetsMap(this.getDeployEnvironment()));
|
32
|
crisEntities.add("Person");
|
33
|
crisEntities.add("Publication");
|
34
|
//add dummy all rules
|
35
|
// getRuleSetMap().put("-1", "All Rules");
|
36
|
return SUCCESS;
|
37
|
} catch (Exception e) {
|
38
|
logger.error("error while populating rules", e);
|
39
|
this.addActionError(this.getText("generic.error"));
|
40
|
reportException(e);
|
41
|
return "exception";
|
42
|
}
|
43
|
|
44
|
|
45
|
}
|
46
|
|
47
|
|
48
|
public String populate() throws Exception {
|
49
|
|
50
|
List<RuleD> cRules = null;
|
51
|
List<RuleD> uRules = null;
|
52
|
logger.debug("populate- rulesetId: "+ruleSetId);
|
53
|
if (ruleSetId == -1) {
|
54
|
cRules = this.getOpenAIREValidator().getRulesForJobValidationByJobType("content");
|
55
|
uRules = this.getOpenAIREValidator().getRulesForJobValidationByJobType("usage");
|
56
|
|
57
|
} else {
|
58
|
cRules = this.getOpenAIREValidator().getRulesForJobValidationByJobTypeByRuleSet(ruleSetId,"content");
|
59
|
uRules = this.getOpenAIREValidator().getRulesForJobValidationByJobTypeByRuleSet(ruleSetId,"usage");
|
60
|
}
|
61
|
|
62
|
String jsonResult = this.jsonise(cRules, uRules);
|
63
|
// logger.debug("json: "+jsonResult);
|
64
|
request.put("jsonization", jsonResult);
|
65
|
return SUCCESS;
|
66
|
|
67
|
}
|
68
|
|
69
|
|
70
|
|
71
|
|
72
|
private String jsonise(List<RuleD> cRules, List<RuleD> uRules) throws Exception{
|
73
|
// logger.debug("jsonizing with conSize:"+ cRules.size()+"and usageSize:");
|
74
|
StringBuilder sb = new StringBuilder();
|
75
|
|
76
|
sb.append("{\"contentRules\":[");
|
77
|
|
78
|
for (int i = 0; i < cRules.size(); i++) {
|
79
|
if (i > 0)
|
80
|
sb.append(", ");
|
81
|
|
82
|
sb.append("{\"id\":").append(cRules.get(i).getId());
|
83
|
sb.append(", \"name\":\"").append(cRules.get(i).getName());
|
84
|
sb.append("\", \"description\":\"").append(cRules.get(i).getDescription().split("<p>")[0]);
|
85
|
sb.append("\"}");
|
86
|
}
|
87
|
|
88
|
sb.append("], \"usageRules\": [");
|
89
|
|
90
|
for (int i = 0; i < uRules.size(); i++) {
|
91
|
if (i > 0)
|
92
|
sb.append(", ");
|
93
|
|
94
|
sb.append("{\"id\":").append(uRules.get(i).getId());
|
95
|
sb.append(", \"name\":\"").append(uRules.get(i).getName());
|
96
|
sb.append("\", \"description\":\"").append(uRules.get(i).getDescription().split("<p>")[0]);
|
97
|
sb.append("\"}");
|
98
|
}
|
99
|
|
100
|
sb.append("]}");
|
101
|
|
102
|
return sb.toString().replace('\n', ' ').replace('\r',' ');
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
public void setRequest(Map<String, Object> request) {
|
107
|
this.request = request;
|
108
|
|
109
|
}
|
110
|
|
111
|
public void setRuleSetMap(Map<String,String> ruleSetMap) {
|
112
|
this.ruleSetMap = ruleSetMap;
|
113
|
}
|
114
|
|
115
|
public Map<String,String> getRuleSetMap() {
|
116
|
return ruleSetMap;
|
117
|
}
|
118
|
|
119
|
public int getRuleSetId() {
|
120
|
return ruleSetId;
|
121
|
}
|
122
|
|
123
|
public void setRuleSetId(int ruleSetId) {
|
124
|
this.ruleSetId = ruleSetId;
|
125
|
}
|
126
|
|
127
|
public void setRepositories(List<String> repositories) {
|
128
|
this.repositories = repositories;
|
129
|
}
|
130
|
|
131
|
public List<String> getRepositories() {
|
132
|
return repositories;
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public void setSession(Map<String, Object> session) {
|
137
|
this.session = session;
|
138
|
}
|
139
|
|
140
|
|
141
|
public List<String> getCrisEntities() {
|
142
|
return crisEntities;
|
143
|
}
|
144
|
|
145
|
|
146
|
public void setCrisEntities(List<String> crisEntities) {
|
147
|
this.crisEntities = crisEntities;
|
148
|
}
|
149
|
|
150
|
|
151
|
|
152
|
}
|