Revision 32297
Added by Nikon Gasparis about 10 years ago
modules/uoa-validator/tags/uoa-validator-1.0.0/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" ?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<parent> |
|
4 |
<groupId>eu.dnetlib</groupId> |
|
5 |
<artifactId>dnet-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
</parent> |
|
8 |
<modelVersion>4.0.0</modelVersion> |
|
9 |
<groupId>eu.dnetlib</groupId> |
|
10 |
<artifactId>uoa-validator</artifactId> |
|
11 |
<packaging>jar</packaging> |
|
12 |
<version>1.0.0</version> |
|
13 |
<scm> |
|
14 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-validator/tags/uoa-validator-1.0.0</developerConnection> |
|
15 |
</scm> |
|
16 |
<dependencies> |
|
17 |
<dependency> |
|
18 |
<groupId>eu.dnetlib</groupId> |
|
19 |
<artifactId>uoa-clients</artifactId> |
|
20 |
<version>[1.0.0]</version> |
|
21 |
</dependency> |
|
22 |
<dependency> |
|
23 |
<groupId>eu.dnetlib</groupId> |
|
24 |
<artifactId>uoa-utils</artifactId> |
|
25 |
<version>[1.0.0]</version> |
|
26 |
</dependency> |
|
27 |
<dependency> |
|
28 |
<groupId>eu.dnetlib</groupId> |
|
29 |
<artifactId>uoa-api</artifactId> |
|
30 |
<version>[1.0.0]</version> |
|
31 |
</dependency> |
|
32 |
<dependency> |
|
33 |
<groupId>apache</groupId> |
|
34 |
<artifactId>commons-io</artifactId> |
|
35 |
<version>[1.4,)</version> |
|
36 |
</dependency> |
|
37 |
<dependency> |
|
38 |
<groupId>apache</groupId> |
|
39 |
<artifactId>commons-cli</artifactId> |
|
40 |
<version>[1.0,)</version> |
|
41 |
</dependency> |
|
42 |
<dependency> |
|
43 |
<groupId>log4j</groupId> |
|
44 |
<artifactId>log4j</artifactId> |
|
45 |
<version>[1.2.14,1.3.0)</version> |
|
46 |
</dependency> |
|
47 |
<dependency> |
|
48 |
<groupId>com.thoughtworks.xstream</groupId> |
|
49 |
<artifactId>xstream</artifactId> |
|
50 |
<version>[0.0.0,)</version> |
|
51 |
</dependency> |
|
52 |
<dependency> |
|
53 |
<groupId>junit</groupId> |
|
54 |
<artifactId>junit</artifactId> |
|
55 |
<version>[0.0.0,)</version> |
|
56 |
<scope>test</scope> |
|
57 |
</dependency> |
|
58 |
<dependency> |
|
59 |
<groupId>org.springframework</groupId> |
|
60 |
<artifactId>spring-jdbc</artifactId> |
|
61 |
<version>${spring.version}</version> |
|
62 |
</dependency> |
|
63 |
<dependency> |
|
64 |
<groupId>org.springframework</groupId> |
|
65 |
<artifactId>spring-tx</artifactId> |
|
66 |
<version>${spring.version}</version> |
|
67 |
</dependency> |
|
68 |
<dependency> |
|
69 |
<groupId>org.apache.velocity</groupId> |
|
70 |
<artifactId>velocity</artifactId> |
|
71 |
<version>1.7</version> |
|
72 |
</dependency> |
|
73 |
<dependency> |
|
74 |
<groupId>eu.dnetlib</groupId> |
|
75 |
<artifactId>cnr-blackboard-common</artifactId> |
|
76 |
<version>[1.0.0]</version> |
|
77 |
</dependency> |
|
78 |
<dependency> |
|
79 |
<groupId>postgresql</groupId> |
|
80 |
<artifactId>postgresql</artifactId> |
|
81 |
<version>9.1-901.jdbc4</version> |
|
82 |
</dependency> |
|
83 |
<dependency> |
|
84 |
<groupId>se.kb</groupId> |
|
85 |
<artifactId>oai4j</artifactId> |
|
86 |
<version>[0.6b1,)</version> |
|
87 |
</dependency> |
|
88 |
</dependencies> |
|
89 |
</project> |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/impls/rules/text/TextVocabularyRule.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.impls.rules.text; |
|
2 |
|
|
3 |
import gr.uoa.di.validator.data.RuleException; |
|
4 |
import gr.uoa.di.validator.execution.ValidationObject; |
|
5 |
import gr.uoa.di.validator.impls.rules.VocabularyRule; |
|
6 |
import gr.uoa.di.validator.impls.valobjs.TextValidationObject; |
|
7 |
|
|
8 |
import java.util.Properties; |
|
9 |
|
|
10 |
/** |
|
11 |
* Checks if the {@link TextValidationObject} containes a value contained in the {@link VocabularyRule#TERMS}. |
|
12 |
* @author Manos Karvounis |
|
13 |
* |
|
14 |
*/ |
|
15 |
public class TextVocabularyRule extends VocabularyRule implements TextRule { |
|
16 |
|
|
17 |
private static final long serialVersionUID = 7959834222669049476L; |
|
18 |
|
|
19 |
public TextVocabularyRule(Properties pros, int id) { |
|
20 |
super(pros, id); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public boolean apply(ValidationObject obj) throws RuleException { |
|
25 |
TextValidationObject tobj = (TextValidationObject) obj; |
|
26 |
String[] aterms = this.pros.getProperty(TERMS).split(","); |
|
27 |
for(String term : aterms) |
|
28 |
if(term.trim().equals(tobj.getContentAsText())) |
|
29 |
return true; |
|
30 |
return false; |
|
31 |
} |
|
32 |
} |
|
0 | 33 |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/service/ValidatorManagerImpl.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.service; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
6 |
import gr.uoa.di.validator.Validator; |
|
7 |
import gr.uoa.di.validator.ValidatorException; |
|
8 |
import gr.uoa.di.validator.dao.JobSubmitted; |
|
9 |
import gr.uoa.di.validator.dao.JobSubmittedDAO; |
|
10 |
import gr.uoa.di.validator.dao.RuleSet; |
|
11 |
import gr.uoa.di.validator.dao.RuleSetDAO; |
|
12 |
import gr.uoa.di.validator.dao.RuleStored; |
|
13 |
import gr.uoa.di.validator.dao.RuleStoredDAO; |
|
14 |
import gr.uoa.di.validator.dao.Utilities; |
|
15 |
import gr.uoa.di.validator.data.Rule; |
|
16 |
import gr.uoa.di.validator.execution.Job; |
|
17 |
import gr.uoa.di.validator.impls.MemoryThreadValidator; |
|
18 |
import gr.uoa.di.validator.impls.listeners.DnetListener; |
|
19 |
import gr.uoa.di.validator.impls.listeners.ValidatorJobListener; |
|
20 |
import gr.uoa.di.validator.impls.providers.OAIPMHRecordProvider; |
|
21 |
import gr.uoa.di.validator.impls.providers.OAIPMHSinglePageVerbProvider; |
|
22 |
import gr.uoa.di.validator.impls.rules.ChainRule; |
|
23 |
import gr.uoa.di.validator.impls.rules.RuleTypes; |
|
24 |
|
|
25 |
import java.io.Serializable; |
|
26 |
import java.lang.reflect.InvocationTargetException; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.HashSet; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Map; |
|
32 |
import java.util.Properties; |
|
33 |
import java.util.Set; |
|
34 |
|
|
35 |
import org.apache.log4j.Logger; |
|
36 |
import org.springframework.transaction.annotation.Propagation; |
|
37 |
import org.springframework.transaction.annotation.Transactional; |
|
38 |
|
|
39 |
@Transactional(propagation = Propagation.REQUIRED) |
|
40 |
public abstract class ValidatorManagerImpl implements ValidatorManager { |
|
41 |
|
|
42 |
private Validator validator; |
|
43 |
private JobSubmittedDAO jobSubmittedDao; |
|
44 |
private RuleSetDAO ruleSetDao; |
|
45 |
private RuleStoredDAO ruleStoredDao; |
|
46 |
|
|
47 |
// private Map<Integer, Integer> ruleLinkingMap = new HashMap<Integer, Integer>(); |
|
48 |
private Integer jobIdRegistry = 1; |
|
49 |
private Integer ruleIdRegistry = 1; |
|
50 |
|
|
51 |
private static Logger logger = Logger.getLogger(ValidatorManagerImpl.class); |
|
52 |
|
|
53 |
protected abstract ValidatorJobListener createListener(); |
|
54 |
protected abstract DnetListener createDnetListener(); |
|
55 |
|
|
56 |
public void start() { |
|
57 |
logger.debug("Initializing Validator Manager module"); |
|
58 |
} |
|
59 |
|
|
60 |
@Transactional(propagation = Propagation.REQUIRED) |
|
61 |
public JobSubmitted beginDataJobForWorkflow(String mdstoreId, String guidelines, String groupBy, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler, int workers) throws ValidatorException{ |
|
62 |
try { |
|
63 |
logger.debug("Submitting data job for workflow"); |
|
64 |
// String desiredCompatibility = "openaire3.0"; |
|
65 |
Set<Integer> ruleIdsContent = new HashSet<Integer>(); |
|
66 |
for (RuleSet ruleset : ruleSetDao.getRuleSets()) { |
|
67 |
if (ruleset.getGuidelinesAcronym().equals(guidelines)) { |
|
68 |
ruleIdsContent = Utilities.convertListToSet(ruleset.getRuleIdsContent()); |
|
69 |
} |
|
70 |
} |
|
71 |
Properties pros = new Properties(); |
|
72 |
|
|
73 |
pros.setProperty(DnetProvider.MDSTORE_ID, mdstoreId); |
|
74 |
// pros.setProperty(DnetProvider.BATCH_SIZE, bJob.getParameters().get("batchSize")); |
|
75 |
pros.setProperty(DnetProvider.BATCH_SIZE, "50"); |
|
76 |
pros.setProperty(DnetProvider.RECORDS, bJob.getParameters().get("records")); |
|
77 |
|
|
78 |
JobSubmitted newJob = new JobSubmitted(); |
|
79 |
|
|
80 |
Set<Integer> rules = new HashSet<Integer>(); |
|
81 |
|
|
82 |
Map<Integer,Integer> ruleLinkingMap = new HashMap<Integer,Integer>(); |
|
83 |
|
|
84 |
for (Integer ruleId : ruleIdsContent) { |
|
85 |
|
|
86 |
RuleStored tempRule=ruleStoredDao.get(ruleId.toString()); |
|
87 |
|
|
88 |
//special behaviour type of rule is chain |
|
89 |
if(tempRule.getType().equals("ChainRule")) { |
|
90 |
ChainRule<Rule> chainRule = this.handleChain(tempRule); |
|
91 |
validator.addToRegistry(ruleIdRegistry,chainRule, MemoryThreadValidator.RegistryType.rules); |
|
92 |
} |
|
93 |
else { |
|
94 |
validator.addToRegistry(ruleIdRegistry,this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), ruleIdRegistry), MemoryThreadValidator.RegistryType.rules); |
|
95 |
} |
|
96 |
rules.add(ruleIdRegistry); |
|
97 |
// this.linkRules(ruleIdRegistry, ruleId); |
|
98 |
ruleLinkingMap.put(ruleIdRegistry, ruleId); |
|
99 |
ruleIdRegistry++; |
|
100 |
} |
|
101 |
|
|
102 |
Job job = new Job(this.jobIdRegistry, 3, rules, pros); |
|
103 |
this.jobIdRegistry++; |
|
104 |
|
|
105 |
newJob.setUser("Workflow Service"); |
|
106 |
newJob.setValidationType("OAI Content"); |
|
107 |
newJob.setGuidelines(guidelines); |
|
108 |
// newJob.setType("OAI Content Validation"); |
|
109 |
newJob.setStatus("working"); |
|
110 |
newJob.setJobType("Workflow Request"); |
|
111 |
newJob.setDuration("--"); |
|
112 |
newJob.setRepo(mdstoreId); |
|
113 |
newJob.setRules(ruleIdsContent); |
|
114 |
newJob.setRecords(pros.getProperty(DnetProvider.RECORDS)); |
|
115 |
newJob.setSet("dnet-workflow"); |
|
116 |
newJob.setGroupBy_xpath(groupBy); |
|
117 |
newJob.setMetadata_prefix("oai_dc"); |
|
118 |
newJob.setId("-1"); |
|
119 |
int jobIdStored = jobSubmittedDao.save(newJob); |
|
120 |
ValidatorJobListener listener = createListener(); |
|
121 |
listener.setJobSubmittedId(jobIdStored); |
|
122 |
listener.setJobSubmittedUser("Workflow Service"); |
|
123 |
listener.setRuleLinkingMap(ruleLinkingMap); |
|
124 |
listener.setGroupBy_xpath(groupBy); |
|
125 |
listener.setInternalJobsSum(workers); |
|
126 |
// |
|
127 |
DnetListener dnetListener = createDnetListener(); |
|
128 |
dnetListener.setJob(bJob); |
|
129 |
dnetListener.setBlackboardHandler(blackboardHandler); |
|
130 |
|
|
131 |
// validator.submitJob(job, listener, dnetListener); |
|
132 |
validator.submitJob(job, workers, listener, dnetListener); |
|
133 |
|
|
134 |
return newJob; |
|
135 |
|
|
136 |
|
|
137 |
} catch (Exception e) { |
|
138 |
logger.error("Error Submitting content job", e); |
|
139 |
throw new ValidatorException(e); |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
|
|
144 |
/* public JobSubmitted beginDataJobForWorkflow(String mdstoreId, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler) throws ValidatorException{ |
|
145 |
try { |
|
146 |
logger.debug("Submitting data job for workflow"); |
|
147 |
Set<Integer> ruleIdsContent = new HashSet<Integer>(); |
|
148 |
|
|
149 |
for (RuleSet ruleset : ruleSetDao.getRuleSets()) { |
|
150 |
String regRuleset; |
|
151 |
|
|
152 |
regRuleset = "OpenAIRE For Literature Repositories"; |
|
153 |
|
|
154 |
if (ruleset.getName().equals(regRuleset)) { |
|
155 |
ruleIdsContent = Utilities.convertListToSet(ruleset.getRuleIdsContent()); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
Properties pros = new Properties(); |
|
160 |
|
|
161 |
pros.setProperty(DnetProvider.MDSTORE_ID, mdstoreId); |
|
162 |
pros.setProperty(DnetProvider.BATCH_SIZE, "10"); |
|
163 |
pros.setProperty(DnetProvider.RECORDS, "5"); |
|
164 |
|
|
165 |
JobSubmitted newJob = new JobSubmitted(); |
|
166 |
|
|
167 |
Set<Integer> rules = new HashSet<Integer>(); |
|
168 |
|
|
169 |
for (Integer ruleId : ruleIdsContent) { |
|
170 |
RuleStored tempRule = ruleStoredDao.get(ruleId.toString()); |
|
171 |
|
|
172 |
// special behaviour type of rule is chain |
|
173 |
if (tempRule.getType().equals("ChainRule")) { |
|
174 |
logger.debug("chain rule found"); |
|
175 |
RuleStored tempRuleChain1 = ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_1")); |
|
176 |
RuleStored tempRuleChain2 = ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_2")); |
|
177 |
List<Rule> rules_chain = new ArrayList<Rule>(); |
|
178 |
rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain1.getType(), tempRuleChain1.getConfiguration(), ruleIdRegistry)); |
|
179 |
ruleIdRegistry++; |
|
180 |
rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain2.getType(), tempRuleChain2.getConfiguration(), ruleIdRegistry)); |
|
181 |
ruleIdRegistry++; |
|
182 |
|
|
183 |
Properties chainPros = new Properties(); |
|
184 |
chainPros.setProperty(ChainRule.TYPE, tempRule.getConfiguration().getProperty(ChainRule.TYPE)); |
|
185 |
ChainRule<Rule> chainRule = new ChainRule<Rule>(chainPros, ruleIdRegistry, rules_chain); |
|
186 |
|
|
187 |
validator.addToRegistry(ruleIdRegistry, chainRule, MemoryThreadValidator.RegistryType.rules); |
|
188 |
} else { |
|
189 |
validator.addToRegistry(ruleIdRegistry, this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), ruleIdRegistry), MemoryThreadValidator.RegistryType.rules); |
|
190 |
} |
|
191 |
rules.add(ruleIdRegistry); |
|
192 |
this.linkRules(ruleIdRegistry, ruleId); |
|
193 |
ruleIdRegistry++; |
|
194 |
} |
|
195 |
|
|
196 |
Job job = new Job(this.jobIdRegistry, 3, rules, pros); |
|
197 |
this.jobIdRegistry++; |
|
198 |
|
|
199 |
newJob.setUser("Workflow Service"); |
|
200 |
newJob.setValidationType("OAI Content"); |
|
201 |
// newJob.setType("OAI Content Validation"); |
|
202 |
newJob.setStatus("working"); |
|
203 |
newJob.setJobType("Workflow Request"); |
|
204 |
// newJob.setRuleset("Workflow Request"); |
|
205 |
//TODO FIX |
|
206 |
newJob.setGuidelines("OpenAIRE For Literature Repositories"); |
|
207 |
newJob.setActivation_id(null); |
|
208 |
newJob.setDuration("--"); |
|
209 |
newJob.setRepo(mdstoreId); |
|
210 |
newJob.setRules(ruleIdsContent); |
|
211 |
newJob.setRecords(pros.getProperty(DnetProvider.RECORDS)); |
|
212 |
newJob.setSet("dnet-workflow"); |
|
213 |
newJob.setGroupBy_xpath(null); |
|
214 |
newJob.setMetadata_prefix(""); |
|
215 |
newJob.setId("-1"); |
|
216 |
|
|
217 |
int jobIdStored = jobSubmittedDao.save(newJob); |
|
218 |
|
|
219 |
ValidatorJobListener listener = createListener(); |
|
220 |
listener.setJobSubmittedId(jobIdStored); |
|
221 |
listener.setJobSubmittedUser("Workflow Service"); |
|
222 |
listener.setRuleLinkingMap(ruleLinkingMap); |
|
223 |
listener.setGroupBy_xpath(null); |
|
224 |
listener.setInternalJobsSum(1); |
|
225 |
|
|
226 |
DnetListener dnetListener = createDnetListener(); |
|
227 |
dnetListener.setJob(bJob); |
|
228 |
dnetListener.setBlackboardHandler(blackboardHandler); |
|
229 |
|
|
230 |
validator.submitJob(job, listener, dnetListener); |
|
231 |
return newJob; |
|
232 |
|
|
233 |
} catch (Exception e) { |
|
234 |
logger.error("Error Submitting content job for workflow", e); |
|
235 |
throw new ValidatorException(e); |
|
236 |
} |
|
237 |
|
|
238 |
} */ |
|
239 |
|
|
240 |
@Override |
|
241 |
public JobSubmitted beginContentJobForWorkflow(String baseUrl, String validationSet, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler) throws ValidatorException { |
|
242 |
try { |
|
243 |
logger.debug("Submitting content job for workflow"); |
|
244 |
Set<Integer> ruleIdsContent = new HashSet<Integer>(); |
|
245 |
for (RuleSet ruleset : ruleSetDao.getRuleSets()) { |
|
246 |
String regRuleset; |
|
247 |
if (validationSet.equalsIgnoreCase("openaire_data")) { |
|
248 |
regRuleset = "OpenAIRE For Data Archives"; |
|
249 |
} else { |
|
250 |
regRuleset = "OpenAIRE For Literature Repositories"; |
|
251 |
} |
|
252 |
if (ruleset.getName().equals(regRuleset)) { |
|
253 |
ruleIdsContent = Utilities.convertListToSet(ruleset.getRuleIdsContent()); |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
Properties pros = null; |
|
258 |
pros = new Properties(); |
|
259 |
pros.setProperty(OAIPMHRecordProvider.BASEURL, baseUrl); |
|
260 |
pros.setProperty(OAIPMHRecordProvider.METADATA_PREFIX, "oai_dc"); |
|
261 |
pros.setProperty(OAIPMHRecordProvider.TIMEOUT, "360000"); |
|
262 |
pros.setProperty(OAIPMHRecordProvider.DELAY, "1000"); |
|
263 |
pros.setProperty(OAIPMHRecordProvider.RETRY_DELAY, "60000"); |
|
264 |
pros.setProperty(OAIPMHRecordProvider.RETRY_EFFORTS, "3"); |
|
265 |
// pros.setProperty(OAIPMHRecordProvider.RECORDS, "20"); |
|
266 |
pros.setProperty(OAIPMHRecordProvider.RECORDS, "all"); |
|
267 |
pros.setProperty(OAIPMHRecordProvider.SET, validationSet); |
|
268 |
|
|
269 |
JobSubmitted newJob = new JobSubmitted(); |
|
270 |
|
|
271 |
Set<Integer> rules = new HashSet<Integer>(); |
|
272 |
|
|
273 |
Map<Integer,Integer> ruleLinkingMap = new HashMap<Integer,Integer>(); |
|
274 |
|
|
275 |
for (Integer ruleId : ruleIdsContent) { |
|
276 |
RuleStored tempRule = ruleStoredDao.get(ruleId.toString()); |
|
277 |
|
|
278 |
// special behaviour type of rule is chain |
|
279 |
if (tempRule.getType().equals("ChainRule")) { |
|
280 |
logger.debug("chain rule found"); |
|
281 |
RuleStored tempRuleChain1 = ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_1")); |
|
282 |
RuleStored tempRuleChain2 = ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_2")); |
|
283 |
List<Rule> rules_chain = new ArrayList<Rule>(); |
|
284 |
rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain1.getType(), tempRuleChain1.getConfiguration(), ruleIdRegistry)); |
|
285 |
ruleIdRegistry++; |
|
286 |
rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain2.getType(), tempRuleChain2.getConfiguration(), ruleIdRegistry)); |
|
287 |
ruleIdRegistry++; |
|
288 |
|
|
289 |
Properties chainPros = new Properties(); |
|
290 |
chainPros.setProperty(ChainRule.TYPE, tempRule.getConfiguration().getProperty(ChainRule.TYPE)); |
|
291 |
ChainRule<Rule> chainRule = new ChainRule<Rule>(chainPros, ruleIdRegistry, rules_chain); |
|
292 |
|
|
293 |
validator.addToRegistry(ruleIdRegistry, chainRule, MemoryThreadValidator.RegistryType.rules); |
|
294 |
} else { |
|
295 |
validator.addToRegistry(ruleIdRegistry, this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), ruleIdRegistry), MemoryThreadValidator.RegistryType.rules); |
|
296 |
} |
|
297 |
rules.add(ruleIdRegistry); |
|
298 |
// this.linkRules(ruleIdRegistry, ruleId); |
|
299 |
ruleLinkingMap.put(ruleIdRegistry, ruleId); |
|
300 |
ruleIdRegistry++; |
|
301 |
} |
|
302 |
if (pros.getProperty(OAIPMHRecordProvider.SET).equalsIgnoreCase( |
|
303 |
"openaire_data")) |
|
304 |
pros.setProperty(OAIPMHRecordProvider.METADATA_PREFIX, |
|
305 |
"oai_datacite"); |
|
306 |
|
|
307 |
Job job = new Job(this.jobIdRegistry, 1, rules, pros); |
|
308 |
this.jobIdRegistry++; |
|
309 |
|
|
310 |
newJob.setUser("Workflow Service"); |
|
311 |
newJob.setValidationType("OAI Content"); |
|
312 |
// newJob.setType("OAI Content Validation"); |
|
313 |
newJob.setStatus("working"); |
|
314 |
newJob.setJobType("Workflow Request"); |
|
315 |
//TODO FIX |
|
316 |
newJob.setGuidelines("OpenAIRE For Literature Repositories"); |
|
317 |
newJob.setActivation_id(null); |
|
318 |
newJob.setDuration("--"); |
|
319 |
newJob.setRepo(baseUrl); |
|
320 |
newJob.setRules(ruleIdsContent); |
|
321 |
newJob.setRecords(pros.getProperty(OAIPMHRecordProvider.RECORDS)); |
|
322 |
newJob.setSet(pros.getProperty(OAIPMHRecordProvider.SET)); |
|
323 |
newJob.setGroupBy_xpath(null); |
|
324 |
newJob.setMetadata_prefix(pros.getProperty(OAIPMHRecordProvider.METADATA_PREFIX)); |
|
325 |
newJob.setId("-1"); |
|
326 |
int jobIdStored = jobSubmittedDao.save(newJob); |
|
327 |
|
|
328 |
ValidatorJobListener listener = createListener(); |
|
329 |
listener.setJobSubmittedId(jobIdStored); |
|
330 |
listener.setJobSubmittedUser("Workflow Service"); |
|
331 |
listener.setRuleLinkingMap(ruleLinkingMap); |
|
332 |
listener.setGroupBy_xpath(null); |
|
333 |
listener.setInternalJobsSum(1); |
|
334 |
|
|
335 |
DnetListener dnetListener = createDnetListener(); |
|
336 |
dnetListener.setJob(bJob); |
|
337 |
dnetListener.setBlackboardHandler(blackboardHandler); |
|
338 |
|
|
339 |
validator.submitJob(job, 1, listener, dnetListener); |
|
340 |
return newJob; |
|
341 |
|
|
342 |
} catch (Exception e) { |
|
343 |
logger.error("Error Submitting content job for workflow", e); |
|
344 |
throw new ValidatorException(e); |
|
345 |
} |
|
346 |
|
|
347 |
} |
|
348 |
|
|
349 |
@Override |
|
350 |
public JobSubmitted beginUsageJobForWorkflow(String baseUrl, String validationSet, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler) throws ValidatorException { |
|
351 |
try { |
|
352 |
|
|
353 |
logger.debug("Submitting Usage job(s) for workflow"); |
|
354 |
|
|
355 |
Set<Integer> ruleIdsUsage = new HashSet<Integer>(); |
|
356 |
for (RuleSet ruleset : ruleSetDao.getRuleSets()) { |
|
357 |
String regRuleset; |
|
358 |
if (validationSet.equalsIgnoreCase("openaire_data")) { |
|
359 |
regRuleset = "OpenAIRE For Data Archives"; |
|
360 |
} else { |
|
361 |
regRuleset = "OpenAIRE For Literature Repositories"; |
|
362 |
} |
|
363 |
if (ruleset.getName().equals(regRuleset)) { |
|
364 |
ruleIdsUsage = Utilities.convertListToSet(ruleset |
|
365 |
.getRuleIdsUsage()); |
|
366 |
} |
|
367 |
} |
|
368 |
|
|
369 |
Properties pros = new Properties(); |
|
370 |
pros.setProperty(OAIPMHSinglePageVerbProvider.BASEURL, baseUrl); |
|
371 |
pros.setProperty(OAIPMHSinglePageVerbProvider.TIMEOUT, "360000"); |
|
372 |
pros.setProperty(OAIPMHSinglePageVerbProvider.DELAY, "1000"); |
|
373 |
pros.setProperty(OAIPMHSinglePageVerbProvider.RETRY_DELAY, "60000"); |
|
374 |
pros.setProperty(OAIPMHSinglePageVerbProvider.RETRY_EFFORTS, "3"); |
|
375 |
|
|
376 |
JobSubmitted newJob = new JobSubmitted(); |
|
377 |
|
|
378 |
List<RuleStored> rulesStored = new ArrayList<RuleStored>(); |
|
379 |
for (Integer id : ruleIdsUsage) { |
|
380 |
logger.debug("Rule with id: " + id + " added"); |
|
381 |
rulesStored.add(ruleStoredDao.get(id.toString())); |
|
382 |
} |
|
383 |
|
|
384 |
logger.debug("Creating map for provider information"); |
|
385 |
Map<String, Set<Integer>> verbRuleMap = new HashMap<String, Set<Integer>>(); |
|
386 |
Set<Integer> old, temp = null; |
|
387 |
for (RuleStored ruleStored : rulesStored) { |
|
388 |
logger.debug("Checking for verb : " + ruleStored.getProvider_information()); |
|
389 |
if ((old = verbRuleMap.get(ruleStored.getProvider_information())) == null) { |
|
390 |
logger.debug("Verb doesn't exist"); |
|
391 |
temp = new HashSet<Integer>(); |
|
392 |
temp.add(Integer.parseInt(ruleStored.getId())); |
|
393 |
verbRuleMap.put(ruleStored.getProvider_information(), temp); |
|
394 |
} else { |
|
395 |
logger.debug("Verb exists"); |
|
396 |
old.add(Integer.parseInt(ruleStored.getId())); |
|
397 |
} |
|
398 |
} |
|
399 |
|
|
400 |
Set<Integer> rules = null; |
|
401 |
|
|
402 |
Job job = null; |
|
403 |
newJob.setUser("Workflow Service"); |
|
404 |
newJob.setValidationType("OAI Usage"); |
|
405 |
newJob.setStatus("working"); |
|
406 |
newJob.setJobType("Workflow Request"); |
|
407 |
// newJob.setRuleset("Workflow Request"); |
|
408 |
//TODO FIX |
|
409 |
newJob.setGuidelines("OpenAIRE For Literature Repositories"); |
|
410 |
newJob.setActivation_id(null); |
|
411 |
newJob.setDuration("--"); |
|
412 |
newJob.setRepo(pros.getProperty(OAIPMHSinglePageVerbProvider.BASEURL)); |
|
413 |
newJob.setRules(ruleIdsUsage); |
|
414 |
newJob.setMetadata_prefix(pros.getProperty(OAIPMHRecordProvider.METADATA_PREFIX)); |
|
415 |
newJob.setId("-1"); |
|
416 |
|
|
417 |
int jobIdStored = jobSubmittedDao.save(newJob); |
|
418 |
|
|
419 |
Map<Integer,Integer> ruleLinkingMap = new HashMap<Integer,Integer>(); |
|
420 |
|
|
421 |
ValidatorJobListener listener = createListener(); |
|
422 |
listener.setJobSubmittedId(jobIdStored); |
|
423 |
listener.setJobSubmittedUser("Workflow Service"); |
|
424 |
listener.setRuleLinkingMap(ruleLinkingMap); |
|
425 |
|
|
426 |
listener.setInternalJobsSum(verbRuleMap.size()); |
|
427 |
for (Map.Entry<String, Set<Integer>> entry : verbRuleMap.entrySet()) { |
|
428 |
pros.remove(OAIPMHSinglePageVerbProvider.VERB); |
|
429 |
pros.setProperty(OAIPMHSinglePageVerbProvider.VERB, |
|
430 |
entry.getKey()); |
|
431 |
rules = new HashSet<Integer>(); |
|
432 |
for (Integer ruleId : entry.getValue()) { |
|
433 |
RuleStored tempRule = ruleStoredDao.get(Integer |
|
434 |
.toString(ruleId)); |
|
435 |
logger.debug("prepare to add rule to registry with regexp: " + tempRule.getConfiguration().getProperty("regexp") + " and ruleIdregistry: " + ruleIdRegistry); |
|
436 |
validator.addToRegistry(ruleIdRegistry, this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), ruleIdRegistry), MemoryThreadValidator.RegistryType.rules); |
|
437 |
rules.add(ruleIdRegistry); |
|
438 |
// this.linkRules(ruleIdRegistry, ruleId); |
|
439 |
ruleLinkingMap.put(ruleIdRegistry, ruleId); |
|
440 |
ruleIdRegistry++; |
|
441 |
} |
|
442 |
|
|
443 |
job = new Job(this.jobIdRegistry, 2, rules, pros); |
|
444 |
|
|
445 |
DnetListener dnetListener = createDnetListener(); |
|
446 |
dnetListener.setJob(bJob); |
|
447 |
dnetListener.setBlackboardHandler(blackboardHandler); |
|
448 |
|
|
449 |
validator.submitJob(job, 1, listener, dnetListener); |
|
450 |
|
|
451 |
this.jobIdRegistry++; |
|
452 |
} |
|
453 |
return newJob; |
|
454 |
} catch (Exception e) { |
|
455 |
logger.error("Error Submitting usage job(s)", e); |
|
456 |
throw new ValidatorException(e); |
|
457 |
} |
|
458 |
|
|
459 |
} |
|
460 |
|
|
461 |
private Serializable getRuleClassInstanceByType(String type, |
|
462 |
Properties pros, int id) throws ValidatorException { |
|
463 |
logger.debug("getting rule object of type " + type); |
|
464 |
String classname = RuleTypes.getClassOfType(type); |
|
465 |
if (classname == null) { |
|
466 |
logger.debug("error getting rule object of type " + type |
|
467 |
+ " classname=null"); |
|
468 |
return null; |
|
469 |
} else { |
|
470 |
try { |
|
471 |
Class<?> clazz = Class.forName(classname); |
|
472 |
logger.debug("classname: " + clazz.getName()); |
|
473 |
return (Serializable) clazz.getConstructor( |
|
474 |
new Class[] { Properties.class, Integer.TYPE }) |
|
475 |
.newInstance(pros, id); |
|
476 |
|
|
477 |
} catch (ClassNotFoundException e) { |
|
478 |
logger.debug("error getting rule object: " + e); |
|
479 |
return null; |
|
480 |
} catch (NoSuchMethodException e) { |
|
481 |
logger.debug("error getting rule object: " + e); |
|
482 |
return null; |
|
483 |
} catch (InvocationTargetException e) { |
|
484 |
logger.debug("error getting rule object: " + e); |
|
485 |
return null; |
|
486 |
} catch (InstantiationException e) { |
|
487 |
logger.debug("error getting rule object: " + e); |
|
488 |
return null; |
|
489 |
} catch (IllegalAccessException e) { |
|
490 |
logger.debug("error getting rule object: " + e); |
|
491 |
return null; |
|
492 |
} |
|
493 |
} |
|
494 |
|
|
495 |
} |
|
496 |
|
|
497 |
private ChainRule<Rule> handleChain(RuleStored tempRule) throws Exception { |
|
498 |
logger.debug("chain rule found"); |
|
499 |
List<Rule> rules_chain = new ArrayList<Rule>(); |
|
500 |
RuleStored tempRuleChain1=ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_1")); |
|
501 |
if(tempRuleChain1.getType().equals("ChainRule")) { |
|
502 |
ChainRule<Rule> chainRule1 = this.handleChain(tempRuleChain1); |
|
503 |
rules_chain.add(chainRule1); |
|
504 |
ruleIdRegistry++; |
|
505 |
} else { |
|
506 |
rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain1.getType(), tempRuleChain1.getConfiguration(), ruleIdRegistry)); |
|
507 |
ruleIdRegistry++; |
|
508 |
} |
|
509 |
RuleStored tempRuleChain2=ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_2")); |
|
510 |
if(tempRuleChain2.getType().equals("ChainRule")) { |
|
511 |
ChainRule<Rule> chainRule2 = this.handleChain(tempRuleChain2); |
|
512 |
rules_chain.add(chainRule2); |
|
513 |
ruleIdRegistry++; |
|
514 |
} else { |
|
515 |
rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain2.getType(), tempRuleChain2.getConfiguration(), ruleIdRegistry)); |
|
516 |
ruleIdRegistry++; |
|
517 |
} |
|
518 |
Properties chainPros = new Properties(); |
|
519 |
chainPros.setProperty(ChainRule.TYPE,tempRule.getConfiguration().getProperty(ChainRule.TYPE)); |
|
520 |
ChainRule<Rule> chainRule = new ChainRule<Rule>(chainPros, ruleIdRegistry, rules_chain); |
|
521 |
return chainRule; |
|
522 |
} |
|
523 |
|
|
524 |
// private void linkRules(int ruleRegistry, int ruleStored) { |
|
525 |
// this.ruleLinkingMap.put(ruleRegistry, ruleStored); |
|
526 |
// } |
|
527 |
// |
|
528 |
// private int getRuleFromLink(int ruleRegistry) { |
|
529 |
// return this.ruleLinkingMap.get(ruleRegistry); |
|
530 |
// } |
|
531 |
|
|
532 |
public Validator getValidator() { |
|
533 |
return validator; |
|
534 |
} |
|
535 |
public void setValidator(Validator validator) { |
|
536 |
this.validator = validator; |
|
537 |
} |
|
538 |
public JobSubmittedDAO getJobSubmittedDao() { |
|
539 |
return jobSubmittedDao; |
|
540 |
} |
|
541 |
public void setJobSubmittedDao(JobSubmittedDAO jobSubmittedDao) { |
|
542 |
this.jobSubmittedDao = jobSubmittedDao; |
|
543 |
} |
|
544 |
public RuleSetDAO getRuleSetDao() { |
|
545 |
return ruleSetDao; |
|
546 |
} |
|
547 |
public void setRuleSetDao(RuleSetDAO ruleSetDao) { |
|
548 |
this.ruleSetDao = ruleSetDao; |
|
549 |
} |
|
550 |
public RuleStoredDAO getRuleStoredDao() { |
|
551 |
return ruleStoredDao; |
|
552 |
} |
|
553 |
public void setRuleStoredDao(RuleStoredDAO ruleStoredDao) { |
|
554 |
this.ruleStoredDao = ruleStoredDao; |
|
555 |
} |
|
556 |
// public Map<Integer, Integer> getRuleLinkingMap() { |
|
557 |
// return ruleLinkingMap; |
|
558 |
// } |
|
559 |
// public void setRuleLinkingMap(Map<Integer, Integer> ruleLinkingMap) { |
|
560 |
// this.ruleLinkingMap = ruleLinkingMap; |
|
561 |
// } |
|
562 |
} |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/service/ValidatorManager.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.service; |
|
2 |
|
|
3 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
4 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler; |
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
6 |
import gr.uoa.di.validator.ValidatorException; |
|
7 |
import gr.uoa.di.validator.dao.JobSubmitted; |
|
8 |
|
|
9 |
public interface ValidatorManager { |
|
10 |
|
|
11 |
public JobSubmitted beginDataJobForWorkflow(String datasource, String guidelines, String groupBy, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler, int workers) throws ValidatorException; |
|
12 |
|
|
13 |
public JobSubmitted beginContentJobForWorkflow(String baseUrl, String validationSet, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler) throws ValidatorException; |
|
14 |
|
|
15 |
public JobSubmitted beginUsageJobForWorkflow(String baseUrl, String validationSet, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler) throws ValidatorException; |
|
16 |
} |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/impls/rules/RegularExpressionRule.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.impls.rules; |
|
2 |
|
|
3 |
import gr.uoa.di.validator.data.Rule; |
|
4 |
|
|
5 |
import java.util.Properties; |
|
6 |
|
|
7 |
/** |
|
8 |
* Represents a rule that checks if an object has a value matching the Regular Expression {@link RegularExpressionRule#REGEXP} |
|
9 |
* @author Manos Karvounis |
|
10 |
* |
|
11 |
*/ |
|
12 |
public abstract class RegularExpressionRule extends Rule { |
|
13 |
|
|
14 |
public static final String REGEXP = "regexp"; |
|
15 |
|
|
16 |
private static final long serialVersionUID = 2159775453207438509L; |
|
17 |
|
|
18 |
public RegularExpressionRule(Properties pros, int id) { |
|
19 |
super(pros, id); |
|
20 |
} |
|
21 |
|
|
22 |
} |
|
0 | 23 |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/service/DnetProvider.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.service; |
|
2 |
|
|
3 |
import eu.dnetlib.api.data.MDStoreService; |
|
4 |
import eu.dnetlib.domain.EPR; |
|
5 |
import gr.uoa.di.driver.enabling.resultset.ResultSetFactory; |
|
6 |
import gr.uoa.di.driver.util.ServiceLocator; |
|
7 |
import gr.uoa.di.validator.data.DataException; |
|
8 |
import gr.uoa.di.validator.data.Provider; |
|
9 |
import gr.uoa.di.validator.data.ResultSet; |
|
10 |
import gr.uoa.di.validator.execution.ValidationObject; |
|
11 |
import gr.uoa.di.validator.impls.valobjs.XMLTextValidationObject; |
|
12 |
|
|
13 |
import java.io.StringReader; |
|
14 |
import java.util.ArrayList; |
|
15 |
import java.util.List; |
|
16 |
|
|
17 |
import javax.xml.parsers.DocumentBuilder; |
|
18 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
19 |
import javax.xml.parsers.ParserConfigurationException; |
|
20 |
import javax.xml.xpath.XPath; |
|
21 |
import javax.xml.xpath.XPathConstants; |
|
22 |
import javax.xml.xpath.XPathExpression; |
|
23 |
import javax.xml.xpath.XPathExpressionException; |
|
24 |
import javax.xml.xpath.XPathFactory; |
|
25 |
|
|
26 |
import org.w3c.dom.Document; |
|
27 |
import org.w3c.dom.Element; |
|
28 |
import org.w3c.dom.Node; |
|
29 |
import org.w3c.dom.ls.DOMImplementationLS; |
|
30 |
import org.w3c.dom.ls.LSSerializer; |
|
31 |
import org.xml.sax.InputSource; |
|
32 |
|
|
33 |
public class DnetProvider extends Provider{ |
|
34 |
|
|
35 |
private static final long serialVersionUID = -4280319954962194170L; |
|
36 |
|
|
37 |
private static ServiceLocator<MDStoreService> mdStoreServiceServiceLocator; |
|
38 |
|
|
39 |
private static ResultSetFactory rsFactory = null; |
|
40 |
|
|
41 |
public static final String DATASOURCE = "DATASOURCE"; |
|
42 |
|
|
43 |
public static final String BATCH_SIZE = "BATCH_SIZE"; |
|
44 |
|
|
45 |
public static final String RECORDS = "RECORDS"; |
|
46 |
|
|
47 |
public static final String MDSTORE_ID = "MDSTORE_ID"; |
|
48 |
|
|
49 |
public static final String FROM = "FROM"; |
|
50 |
|
|
51 |
public static final String BEGIN_RECORD = "BEGIN_RECORD"; |
|
52 |
|
|
53 |
public static final String UNTIL = "UNTIL"; |
|
54 |
|
|
55 |
public static final String RECORD_FILTER = "RECORD_FILTER"; |
|
56 |
|
|
57 |
public static final String WORKER_ID = "WORKER_ID"; |
|
58 |
|
|
59 |
public static final String WORKERS = "WORKERS"; |
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
public DnetProvider(Integer id) { |
|
64 |
super(id); |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public ResultSet<ValidationObject> getValidationObjects() throws ProviderException { |
|
70 |
return new DnetRecordResultSet(); |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public ResultSet<String> getValidationObjectIds() throws ProviderException, |
|
75 |
UnsupportedOperationException { |
|
76 |
// TODO Auto-generated method stub |
|
77 |
return null; |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public ValidationObject getValidationObject(String valObjId) |
|
82 |
throws ProviderException, UnsupportedOperationException { |
|
83 |
// TODO Auto-generated method stub |
|
84 |
return null; |
|
85 |
} |
|
86 |
|
|
87 |
public static void printXmlDocument(Document document) { |
|
88 |
DOMImplementationLS domImplementationLS = |
|
89 |
(DOMImplementationLS) document.getImplementation(); |
|
90 |
LSSerializer lsSerializer = |
|
91 |
domImplementationLS.createLSSerializer(); |
|
92 |
String string = lsSerializer.writeToString(document); |
|
93 |
System.out.println(string); |
|
94 |
} |
|
95 |
|
|
96 |
private class DnetResultSet { |
|
97 |
|
|
98 |
gr.uoa.di.driver.enabling.resultset.ResultSet<String> rs = null; |
|
99 |
|
|
100 |
protected DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
|
101 |
protected DocumentBuilder builder; |
|
102 |
protected XPathFactory xfactory = XPathFactory.newInstance(); |
|
103 |
protected List<Node> records = null; |
|
104 |
protected int records_sum = 0; |
|
105 |
protected int index = -1; |
|
106 |
protected int pointer = 0; |
|
107 |
protected int recordsNum = 0; |
|
108 |
protected int workers = 0; |
|
109 |
protected int workerId = 0; |
|
110 |
protected int beginRecord = 0; |
|
111 |
protected int endRecord = 0; |
|
112 |
protected String error = null; |
|
113 |
|
|
114 |
public DnetResultSet() { |
|
115 |
|
|
116 |
try { |
|
117 |
builder = factory.newDocumentBuilder(); |
|
118 |
log.debug("Retrieving the datasource.."); |
|
119 |
|
|
120 |
log.debug("RECORDS " + pros.getProperty(RECORDS)); |
|
121 |
log.debug("MDSTORE_ID " + pros.getProperty(MDSTORE_ID)); |
|
122 |
log.debug("DATASOURCE: " + pros.getProperty(DATASOURCE)); |
|
123 |
log.debug("WORKER_ID: " + pros.getProperty(WORKER_ID)); |
|
124 |
workerId = Integer.parseInt(pros.getProperty(WORKER_ID)); |
|
125 |
workers = Integer.parseInt(pros.getProperty(WORKERS)); |
|
126 |
// log.debug("BEGIN RECORD: " + pros.getProperty(BEGIN_RECORD)); |
|
127 |
// EPR epr = mdStoreServiceServiceLocator.getService().deliverMDRecords(pros.getProperty(MD_ID), pros.getProperty(FROM), pros.getProperty(UNTIL), pros.getProperty(RECORD_FILTER)); |
|
128 |
log.debug("Issuing request on mdstore: " + pros.getProperty(MDSTORE_ID)); |
|
129 |
EPR epr = mdStoreServiceServiceLocator.getService().deliverMDRecords(pros.getProperty(MDSTORE_ID), null, null, null); |
|
130 |
|
|
131 |
rs = rsFactory.createResultSet(epr); |
|
132 |
|
|
133 |
log.debug("rs created"); |
|
134 |
records_sum = rs.size(); |
|
135 |
log.debug("Number of records in ResultSet: " + records_sum); |
|
136 |
if (pros.getProperty(RECORDS).equalsIgnoreCase("all") ) { |
|
137 |
pros.setProperty(RECORDS,Integer.toString(records_sum)); |
|
138 |
} else if (Integer.parseInt(pros.getProperty(RECORDS)) > records_sum) { |
|
139 |
pros.setProperty(RECORDS,Integer.toString(records_sum)); |
|
140 |
} |
|
141 |
recordsNum = Integer.parseInt(pros.getProperty(RECORDS)); |
|
142 |
log.error("W"+ workerId + "# RECORDS TO TEST: " + recordsNum); |
|
143 |
log.error("W"+ workerId + "# WORKERS: " + workers); |
|
144 |
// pros.setProperty(DnetProvider.BEGIN_RECORD, Integer.toString(Integer.parseInt(pros.getProperty(WORKER_ID)) * (Integer.parseInt(pros.getProperty(RECORDS))/Integer.parseInt(pros.getProperty(WORKERS))))); |
|
145 |
beginRecord = workerId * (recordsNum/workers); |
|
146 |
endRecord = (recordsNum/workers) + beginRecord; |
|
147 |
// endRecord = Integer.parseInt(pros.getProperty(RECORDS))/Integer.parseInt(pros.getProperty(WORKERS)) + Integer.parseInt(pros.getProperty(BEGIN_RECORD)); |
|
148 |
if (workerId == workers-1) |
|
149 |
endRecord += recordsNum % workers; |
|
150 |
log.error("W"+ workerId + "# BEGIN RECORD: " + beginRecord); |
|
151 |
log.error("W"+ workerId + "# END RECORD: " + endRecord); |
|
152 |
pointer = beginRecord; |
|
153 |
} catch (ParserConfigurationException e) { |
|
154 |
log.error("", e); |
|
155 |
} catch (Exception e) { |
|
156 |
log.error("", e); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
protected List<Node> getRecords() throws DataException { |
|
161 |
List<Node> records = new ArrayList<Node>(); |
|
162 |
|
|
163 |
try { |
|
164 |
int to = pointer + Integer.parseInt(pros.getProperty(BATCH_SIZE)) -1 ; |
|
165 |
log.error("to : " + to + " and limit: " + endRecord); |
|
166 |
if (to < endRecord) { |
|
167 |
log.error("Issuing request for records. From : " + pointer + " to : " + to); |
|
168 |
List<String> tempRecords = rs.get(pointer, to); |
|
169 |
pointer += Integer.parseInt(pros.getProperty(BATCH_SIZE)); |
|
170 |
for (String record : tempRecords) { |
|
171 |
// log.debug("record from resultSet is : " + record); |
|
172 |
InputSource is = new InputSource(new StringReader(record)); |
|
173 |
Document doc = builder.parse(is); |
|
174 |
XPath xpath = xfactory.newXPath(); |
|
175 |
XPathExpression expr = xpath.compile("//*[local-name()='record']"); |
|
176 |
records.add((Node) expr.evaluate(doc, XPathConstants.NODE)); |
|
177 |
} |
|
178 |
} |
|
179 |
if (records.size() == 0) { |
|
180 |
log.debug("There are no records. "); |
|
181 |
error = "There are no records"; |
|
182 |
log.debug("Error: "+ error); |
|
183 |
} |
|
184 |
|
|
185 |
} catch (Exception e) { |
|
186 |
log.error("", e); |
|
187 |
throw new DataException(); |
|
188 |
} |
|
189 |
return records; |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
private class DnetRecordResultSet extends DnetResultSet implements ResultSet<ValidationObject> { |
|
194 |
|
|
195 |
@Override |
|
196 |
public String getError() { |
|
197 |
if (error != null) |
|
198 |
log.debug("An error occured "+ this.error); |
|
199 |
else |
|
200 |
log.debug("No errors on request"); |
|
201 |
return this.error; |
|
202 |
} |
|
203 |
|
|
204 |
@Override |
|
205 |
public boolean next() throws DataException { |
|
206 |
index++; |
|
207 |
log.debug("Moving cursor to result "+index); |
|
208 |
if (records == null || index >= records.size()) { |
|
209 |
if (records != null && (records.size() == 0)) |
|
210 |
return false; |
|
211 |
index = -1; |
|
212 |
records = getRecords(); |
|
213 |
return next(); |
|
214 |
} |
|
215 |
return true; |
|
216 |
} |
|
217 |
|
|
218 |
@Override |
|
219 |
public ValidationObject get() throws DataException { |
|
220 |
XMLTextValidationObject ret = null; |
|
221 |
|
|
222 |
Document newXmlDocument; |
|
223 |
try { |
|
224 |
newXmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); |
|
225 |
|
|
226 |
Element root = newXmlDocument.createElement("root"); |
|
227 |
newXmlDocument.appendChild(root); |
|
228 |
Node node = records.get(index); |
|
229 |
Node copyNode = newXmlDocument.importNode(node, true); |
|
230 |
root.appendChild(copyNode); |
|
231 |
printXmlDocument(newXmlDocument); |
|
232 |
ret = new XMLTextValidationObject(newXmlDocument); |
|
233 |
XPathFactory factory = XPathFactory.newInstance(); |
|
234 |
XPath xPath = factory.newXPath(); |
|
235 |
ret.setId(xPath.evaluate("//*[local-name()='header']/*[name()='dri:recordIdentifier']/text()", records.get(index))); |
|
236 |
ret.setStatus(xPath.evaluate("//*[local-name()='header']/@status", records.get(index))); |
|
237 |
log.debug("record id: " + ret.getId()); |
|
238 |
log.debug("record status: " + ret.getStatus()); |
|
239 |
|
|
240 |
} catch (ParserConfigurationException e) { |
|
241 |
log.error("error getting object"+ e); |
|
242 |
} catch (XPathExpressionException e) { |
|
243 |
log.error("error getting object"+ e); |
|
244 |
} |
|
245 |
return ret; |
|
246 |
} |
|
247 |
|
|
248 |
|
|
249 |
} |
|
250 |
|
|
251 |
|
|
252 |
public static ResultSetFactory getRsFactory() { |
|
253 |
return rsFactory; |
|
254 |
} |
|
255 |
|
|
256 |
public static void setRsFactory(ResultSetFactory rsFactory) { |
|
257 |
DnetProvider.rsFactory = rsFactory; |
|
258 |
} |
|
259 |
|
|
260 |
public static ServiceLocator<MDStoreService> getMdStoreServiceServiceLocator() { |
|
261 |
return mdStoreServiceServiceLocator; |
|
262 |
} |
|
263 |
|
|
264 |
public static void setMdStoreServiceServiceLocator(ServiceLocator<MDStoreService> mdStoreServiceServiceLocator) { |
|
265 |
DnetProvider.mdStoreServiceServiceLocator = mdStoreServiceServiceLocator; |
|
266 |
} |
|
267 |
} |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/service/NotificationListener.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.service; |
|
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
|
|
5 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob; |
|
6 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler; |
|
7 |
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler; |
|
8 |
import gr.uoa.di.validator.ValidatorException; |
|
9 |
|
|
10 |
public class NotificationListener extends |
|
11 |
BlackboardNotificationHandler<BlackboardServerHandler> { |
|
12 |
|
|
13 |
private static Logger logger = Logger.getLogger(NotificationListener.class); |
|
14 |
private ValidatorManager valManager; |
|
15 |
|
|
16 |
@Override |
|
17 |
protected void processJob(BlackboardJob job) { |
|
18 |
super.processJob(job); |
|
19 |
|
|
20 |
logger.debug("New Job!"); |
|
21 |
String baseUrl = job.getParameters().get("baseUrl"); |
|
22 |
String validationSet = job.getParameters().get("validationSet"); |
|
23 |
String validationType = job.getParameters().get("validationType"); |
|
24 |
String type = job.getParameters().get("type"); //OAI |
|
25 |
String mdstoreId = job.getParameters().get("mdstoreId"); |
|
26 |
String guidelines = job.getParameters().get("guidelines"); |
|
27 |
String groupBy = job.getParameters().get("groupBy"); |
|
28 |
// String workers = job.getParameters().get("workers"); |
|
29 |
String workers = "4"; |
|
30 |
logger.debug("New Job of type: " + type); |
|
31 |
|
|
32 |
try { |
|
33 |
if (type.equalsIgnoreCase("OAI")) { |
|
34 |
logger.debug("type is oai"); |
|
35 |
|
|
36 |
// if (validationType.equalsIgnoreCase("OAI Content Validation")) |
|
37 |
// valManager.beginContentJobForWorkflow(baseUrl, validationSet, job, this); |
|
38 |
// else if (validationType.equalsIgnoreCase("OAI Usage Validation")) |
|
39 |
// valManager.beginUsageJobForWorkflow(baseUrl, validationSet, job, this); |
|
40 |
// else |
|
41 |
// throw new ValidatorException("Unknown validation type " + type); |
|
42 |
|
|
43 |
} else if (type.equalsIgnoreCase("DNET")) { |
|
44 |
logger.debug("type is dnet"); |
|
45 |
logger.debug("groupBy: " + groupBy); |
|
46 |
|
|
47 |
valManager.beginDataJobForWorkflow(mdstoreId, guidelines, groupBy, job, this,Integer.parseInt(workers)); |
|
48 |
} |
|
49 |
this.getBlackboardHandler().ongoing(job); |
|
50 |
|
|
51 |
} catch (ValidatorException e) { |
|
52 |
|
|
53 |
logger.error("Failed to begin the workflow for the job received", e); |
|
54 |
getBlackboardHandler().failed(job, e); |
|
55 |
} |
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
// valManager.preRegistrationValidations(baseUrl, officialName, activationId, userMail, adminMail, validationSet, datasourceId) |
|
60 |
//TODO: kaleitai otan erxetai notification apo to DNET gia |
|
61 |
// ksekinisei douleia. Pairneis parametrous apo to job |
|
62 |
// antikeimeno: |
|
63 |
|
|
64 |
// job.getParameters().get("a param name "); |
|
65 |
// kai kapws kaleis to validator engine. |
|
66 |
|
|
67 |
// kai enimerwneis gia to status tou job: |
|
68 |
|
|
69 |
|
|
70 |
} |
|
71 |
|
|
72 |
public ValidatorManager getValManager() { |
|
73 |
return valManager; |
|
74 |
} |
|
75 |
|
|
76 |
public void setValManager(ValidatorManager valManager) { |
|
77 |
this.valManager = valManager; |
|
78 |
} |
|
79 |
} |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/impls/persistance/XMLFilePersistance.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.impls.persistance; |
|
2 |
|
|
3 |
import gr.uoa.di.validator.data.DataException; |
|
4 |
import gr.uoa.di.validator.data.ResultSet; |
|
5 |
import gr.uoa.di.validator.persistance.Persistance; |
|
6 |
|
|
7 |
import java.io.BufferedReader; |
|
8 |
import java.io.BufferedWriter; |
|
9 |
import java.io.File; |
|
10 |
import java.io.FileNotFoundException; |
|
11 |
import java.io.FileOutputStream; |
|
12 |
import java.io.FileReader; |
|
13 |
import java.io.FileWriter; |
|
14 |
import java.io.IOException; |
|
15 |
import java.io.Serializable; |
|
16 |
import java.util.HashMap; |
|
17 |
import java.util.Map; |
|
18 |
import java.util.Properties; |
|
19 |
import java.util.UUID; |
|
20 |
|
|
21 |
import org.apache.log4j.Logger; |
|
22 |
|
|
23 |
import com.thoughtworks.xstream.XStream; |
|
24 |
|
|
25 |
/** |
|
26 |
* A Persistance mechanism that stores the objects as XML files. |
|
27 |
* A path needs to be provided that points to the directory where the files will be stored. |
|
28 |
* @author Manos Karvounis |
|
29 |
* @see XMLFilePersistance#DIRECTORY |
|
30 |
*/ |
|
31 |
public class XMLFilePersistance implements Persistance { |
|
32 |
|
|
33 |
private XStream xstream = null; |
|
34 |
private Properties props = null; |
|
35 |
|
|
36 |
private String versionForRestore = null; |
|
37 |
private String versionForPersist = null; |
|
38 |
|
|
39 |
private Map<String, Integer> nums = new HashMap<String, Integer>(); |
|
40 |
|
|
41 |
private transient Logger log = Logger.getLogger(XMLFilePersistance.class); |
|
42 |
|
|
43 |
/** |
|
44 |
* A path that points to the directory where the files will be stored. |
|
45 |
* The path must exist already. |
|
46 |
*/ |
|
47 |
public final static String DIRECTORY = "directory"; |
|
48 |
|
|
49 |
public XMLFilePersistance(Properties props) { |
|
50 |
super(); |
|
51 |
this.props = props; |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public <T extends Serializable> void persist(int objid, T obj, String container) throws DataException { |
|
56 |
if (this.versionForPersist == null) |
|
57 |
try { |
|
58 |
getNextVersion(); |
|
59 |
log.debug("Persisting to version "+this.versionForPersist); |
|
60 |
} catch (IOException e1) { |
|
61 |
log.error("", e1); |
|
62 |
throw new DataException(); |
|
63 |
} |
|
64 |
if (nums.get(container) == null) |
|
65 |
nums.put(container, 0); |
|
66 |
int num = nums.get(container); |
|
67 |
nums.put(container, num + 1); |
|
68 |
FileOutputStream stream = null; |
|
69 |
try { |
|
70 |
log.debug("Writing object "+objid+" to disk"); |
|
71 |
stream = new FileOutputStream(new File(getFileName(container, num, true))); |
|
72 |
xstream.toXML(obj, stream); |
|
73 |
stream.close(); |
|
74 |
} catch (FileNotFoundException e) { |
|
75 |
log.error("", e); |
|
76 |
throw new DataException(); |
|
77 |
} catch (IOException e) { |
|
78 |
log.error("", e); |
|
79 |
throw new DataException(); |
|
80 |
} finally { |
|
81 |
if (stream != null) |
|
82 |
try { |
|
83 |
stream.close(); |
|
84 |
} catch (IOException e) { |
|
85 |
log.error("FATAL IO ERROR", e); |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public <T extends Serializable> ResultSet<T> restore(String container) throws DataException { |
|
92 |
if (this.versionForRestore == null) |
|
93 |
try { |
|
94 |
getLatestVersion(); |
|
95 |
log.debug("Restore version "+this.versionForRestore); |
|
96 |
} catch (IOException e1) { |
|
97 |
log.error("", e1); |
|
98 |
throw new DataException(); |
|
99 |
} |
|
100 |
return new XMLFilesResultSet<T>(container); |
|
101 |
} |
|
102 |
|
|
103 |
private String getFileName(String container, int num, boolean persist) { |
|
104 |
String version; |
|
105 |
if (persist) |
|
106 |
version = this.versionForPersist; |
|
107 |
else |
|
108 |
version = this.versionForRestore; |
|
109 |
return props.getProperty(DIRECTORY) + "/" + version + "/" + container + "." + num + ".xml"; |
|
110 |
} |
|
111 |
|
|
112 |
private String getNextVersion() throws IOException { |
|
113 |
log.debug("creating new persistance file on directory: "+props.getProperty(DIRECTORY)); |
|
114 |
File version = new File(props.getProperty(DIRECTORY) + "/version"); |
|
115 |
if (!version.exists()) { |
|
116 |
version.createNewFile(); |
|
117 |
this.versionForPersist = "0"; |
|
118 |
} |
|
119 |
BufferedWriter bw = new BufferedWriter(new FileWriter(version)); |
|
120 |
this.versionForPersist = UUID.randomUUID().toString(); |
|
121 |
bw.write(this.versionForPersist); |
|
122 |
bw.close(); |
|
123 |
|
|
124 |
File versionDirectory = new File(props.getProperty(DIRECTORY) + "/" + this.versionForPersist + "/"); |
|
125 |
|
|
126 |
versionDirectory.mkdir(); |
|
127 |
|
|
128 |
return this.versionForPersist; |
|
129 |
} |
|
130 |
|
|
131 |
private String getLatestVersion() throws IOException { |
|
132 |
File file = new File(props.getProperty(DIRECTORY) + "/version"); |
|
133 |
if (!file.exists()) |
|
134 |
this.versionForRestore = "0"; |
|
135 |
else { |
|
136 |
BufferedReader br = new BufferedReader(new FileReader(file)); |
|
137 |
this.versionForRestore = br.readLine(); |
|
138 |
br.close(); |
|
139 |
} |
|
140 |
return this.versionForRestore; |
|
141 |
} |
|
142 |
|
|
143 |
@Override |
|
144 |
public void open() throws DataException { |
|
145 |
xstream = new XStream(); |
|
146 |
try { |
|
147 |
getLatestVersion(); |
|
148 |
} catch (IOException e) { |
|
149 |
log.error("", e); |
|
150 |
throw new DataException(); |
|
151 |
} |
|
152 |
// if it is the first time we created a validator |
|
153 |
if(this.versionForRestore.equals("0")) { |
|
154 |
File versionDirectory = new File(props.getProperty(DIRECTORY) + "/" + this.versionForRestore + "/"); |
|
155 |
versionDirectory.mkdir(); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
@Override |
|
160 |
public void close() { |
|
161 |
xstream = null; |
|
162 |
File dir = new File(props.getProperty(DIRECTORY)); |
|
163 |
if(dir.exists() && dir.isDirectory()) { |
|
164 |
String[] dirNames = dir.list(); |
|
165 |
for(String dirName : dirNames) |
|
166 |
if(!dirName.equals(this.versionForPersist) && !dirName.equals(this.versionForRestore) && !dirName.equals("version")) { |
|
167 |
log.debug("Deleting older version "+dirName); |
|
168 |
deleteDir(new File(props.getProperty(DIRECTORY) + "/" + dirName + "/")); |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
private boolean deleteDir(File dir) { |
|
174 |
if (dir.exists() && dir.isDirectory()) { |
|
175 |
String[] children = dir.list(); |
|
176 |
for (int i = 0; i < children.length; i++) { |
|
177 |
boolean success = deleteDir(new File(dir, children[i])); |
|
178 |
if (!success) { |
|
179 |
return false; |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
return dir.delete(); |
|
184 |
} |
|
185 |
|
|
186 |
public class XMLFilesResultSet<T extends Serializable> implements ResultSet<T> { |
|
187 |
|
|
188 |
private final String container; |
|
189 |
private T current = null; |
|
190 |
private int num = 0; |
|
191 |
|
|
192 |
public XMLFilesResultSet(String container) { |
|
193 |
super(); |
|
194 |
this.container = container; |
|
195 |
} |
|
196 |
|
|
197 |
@SuppressWarnings("unchecked") |
|
198 |
@Override |
|
199 |
public boolean next() throws DataException { |
|
200 |
log.debug("Moving cursor to object from container "+container+" with num "+num); |
|
201 |
File file = new File(getFileName(container, num++, false)); |
|
202 |
if (file.exists()) { |
|
203 |
current = (T) xstream.fromXML(file); |
|
204 |
return true; |
|
205 |
} else { |
|
206 |
current = null; |
|
207 |
return false; |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
@Override |
|
212 |
public T get() throws DataException { |
|
213 |
return current; |
|
214 |
} |
|
215 |
|
|
216 |
@Override |
|
217 |
public String getError() { |
|
218 |
// TODO Auto-generated method stub |
|
219 |
return null; |
|
220 |
} |
|
221 |
|
|
222 |
} |
|
223 |
} |
|
0 | 224 |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/service/resultsetCReator.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.service; |
|
2 |
|
|
3 |
|
|
4 |
public class resultsetCReator { |
|
5 |
|
|
6 |
// public static void main(String[] args) throws URIException { |
|
7 |
// EPR epr = new EPR(); |
|
8 |
// epr.setAddress("http://node1.t.openaire.research-infrastructures.eu:8980/dnet/services/resultSet"); |
|
9 |
// epr.setParameter("ResourceIdentifier", "rs-e6a11c26-1a16-41c8-a123-288e75bcbf7b"); |
|
10 |
// |
|
11 |
// System.out.println("dnet://EPR/" + URIUtil.encodePath(EPRUtils.createW3CEPR(epr).toString())); |
|
12 |
// } |
|
13 |
|
|
14 |
} |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/impls/rules/xml/XMLCardinalityRule.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.impls.rules.xml; |
|
2 |
|
|
3 |
import gr.uoa.di.validator.data.DataException; |
|
4 |
import gr.uoa.di.validator.data.RuleException; |
|
5 |
import gr.uoa.di.validator.execution.ValidationObject; |
|
6 |
import gr.uoa.di.validator.impls.rules.CardinalityRule; |
|
7 |
import gr.uoa.di.validator.impls.valobjs.XMLTextValidationObject; |
|
8 |
|
|
9 |
import java.util.Properties; |
|
10 |
|
|
11 |
import org.w3c.dom.NodeList; |
|
12 |
|
|
13 |
public class XMLCardinalityRule extends CardinalityRule implements XMLRule { |
|
14 |
|
|
15 |
private static final long serialVersionUID = -3293960407395273309L; |
|
16 |
|
|
17 |
public XMLCardinalityRule(Properties pros, int id) { |
|
18 |
super(pros, id); |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
public boolean apply(ValidationObject obj) throws RuleException { |
|
23 |
XMLTextValidationObject tobj = (XMLTextValidationObject) obj; |
|
24 |
NodeList nodes; |
|
25 |
try { |
|
26 |
nodes = tobj.getNodes(this.pros.getProperty(XPATH)); |
|
27 |
} catch (DataException e) { |
|
28 |
log.error("", e); |
|
29 |
return false; |
|
30 |
} |
|
31 |
|
|
32 |
int number = nodes.getLength(); |
|
33 |
|
|
34 |
log.debug("XML Cardinality Rule. Count: "+number); |
|
35 |
|
|
36 |
if (number < Integer.parseInt(pros.getProperty(LESS_THAN)) && number > Integer.parseInt(pros.getProperty(GREATER_THAN))) |
|
37 |
return true; |
|
38 |
else |
|
39 |
return false; |
|
40 |
} |
|
41 |
|
|
42 |
} |
|
0 | 43 |
modules/uoa-validator/tags/uoa-validator-1.0.0/src/main/java/gr/uoa/di/validator/impls/valobjs/XMLTextValidationObject.java | ||
---|---|---|
1 |
package gr.uoa.di.validator.impls.valobjs; |
|
2 |
|
|
3 |
import gr.uoa.di.validator.data.DataException; |
|
4 |
|
|
5 |
import java.io.StringWriter; |
|
6 |
|
|
7 |
import javax.xml.transform.Result; |
|
8 |
import javax.xml.transform.Source; |
|
9 |
import javax.xml.transform.Transformer; |
|
10 |
import javax.xml.transform.TransformerConfigurationException; |
|
11 |
import javax.xml.transform.TransformerException; |
|
12 |
import javax.xml.transform.TransformerFactory; |
|
13 |
import javax.xml.transform.TransformerFactoryConfigurationError; |
|
14 |
import javax.xml.transform.dom.DOMSource; |
|
15 |
import javax.xml.transform.stream.StreamResult; |
|
16 |
import javax.xml.xpath.XPath; |
|
17 |
import javax.xml.xpath.XPathConstants; |
|
18 |
import javax.xml.xpath.XPathExpression; |
|
19 |
import javax.xml.xpath.XPathExpressionException; |
|
20 |
import javax.xml.xpath.XPathFactory; |
|
21 |
|
|
22 |
import org.apache.log4j.Logger; |
|
23 |
import org.w3c.dom.Document; |
|
24 |
import org.w3c.dom.NodeList; |
|
25 |
/** |
|
26 |
* Indicates that a Validation Object is actually an xml text. |
|
27 |
* @author Manos Karvounis |
|
28 |
*/ |
|
29 |
public class XMLTextValidationObject implements TextValidationObject { |
|
30 |
|
|
31 |
private transient Logger log = Logger.getLogger(XMLTextValidationObject.class); |
|
32 |
|
|
33 |
private String id = ""; |
|
34 |
private String status; |
|
35 |
private final Document doc; |
|
36 |
private XPathFactory factory = XPathFactory.newInstance(); |
|
37 |
|
|
38 |
public XMLTextValidationObject(Document doc) { |
|
39 |
super(); |
|
40 |
this.doc = doc; |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public String getId() { |
|
45 |
return this.id; |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public void setId(String id) { |
|
50 |
this.id = id; |
|
51 |
} |
|
52 |
|
|
53 |
public String getStatus() { |
|
54 |
return status; |
|
55 |
} |
|
56 |
|
|
57 |
public void setStatus(String status) { |
|
58 |
this.status = status; |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public Object getContentAsObject() { |
|
63 |
return this.doc; |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public String getContentAsText() { |
|
68 |
StringWriter sw = new StringWriter(); |
|
69 |
Transformer transformer = null; |
|
70 |
try { |
Also available in: Unified diff
[maven-release-plugin] copy for tag uoa-validator-1.0.0