Project

General

Profile

« Previous | Next » 

Revision 33328

Added by Nikon Gasparis almost 10 years ago

added dao + email
renamed packages to eu.dnetlib
version changed to 2.0.0

View differences:

modules/uoa-validator-service/trunk/src/main/resources/eu/dnetlib/validator/service/dao/springContext-validator-dao-datasource.properties
1
services.validator.db.driverClassName = org.postgresql.Driver
2
services.validator.db.url = jdbc:postgresql://194.177.192.223:5432/validatornew
3
services.validator.db.username = nickonas
4
services.validator.db.password = 123456
modules/uoa-validator-service/trunk/src/main/webapp/WEB-INF/web.xml
2 2
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3 3
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
4 4
<web-app>
5
	<display-name>DNet-2.0 container web app</display-name>
5
	<display-name>Validator Web Service</display-name>
6 6
	<context-param>
7 7
		<param-name>contextConfigLocation</param-name>
8 8
		<param-value>/WEB-INF/applicationContext.xml</param-value>
modules/uoa-validator-service/trunk/src/main/java/gr/uoa/di/validator/service/impl/ValidatorManager.java
1
package gr.uoa.di.validator.service.impl;
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 eu.dnetlib.validator.service.dao.jobs.JobSubmitted;
7
import gr.uoa.di.validator.ValidatorException;
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-service/trunk/src/main/java/gr/uoa/di/validator/service/impl/ValidatorManagerImpl.java
1
package gr.uoa.di.validator.service.impl;
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 eu.dnetlib.validator.service.dao.Utilities;
7
import eu.dnetlib.validator.service.dao.jobs.JobSubmitted;
8
import eu.dnetlib.validator.service.dao.jobs.JobSubmittedDAO;
9
import eu.dnetlib.validator.service.dao.rules.RuleSet;
10
import eu.dnetlib.validator.service.dao.rules.RuleSetDAO;
11
import eu.dnetlib.validator.service.dao.rules.RuleStored;
12
import eu.dnetlib.validator.service.dao.rules.RuleStoredDAO;
13
import gr.uoa.di.validator.Validator;
14
import gr.uoa.di.validator.ValidatorException;
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.DnetProvider;
21
import gr.uoa.di.validator.impls.providers.OAIPMHRecordProvider;
22
import gr.uoa.di.validator.impls.providers.OAIPMHSinglePageVerbProvider;
23
import gr.uoa.di.validator.impls.rules.ChainRule;
24
import gr.uoa.di.validator.impls.rules.RuleTypes;
25

  
26
import java.io.Serializable;
27
import java.lang.reflect.InvocationTargetException;
28
import java.util.ArrayList;
29
import java.util.HashMap;
30
import java.util.HashSet;
31
import java.util.List;
32
import java.util.Map;
33
import java.util.Properties;
34
import java.util.Set;
35

  
36
import org.apache.log4j.Logger;
37
import org.springframework.transaction.annotation.Propagation;
38
import org.springframework.transaction.annotation.Transactional;
39

  
40
@Transactional(propagation = Propagation.REQUIRED)
41
public abstract class ValidatorManagerImpl implements ValidatorManager {
42

  
43
	private Validator validator;
44
	private JobSubmittedDAO jobSubmittedDao;
45
	private RuleSetDAO ruleSetDao;
46
	private RuleStoredDAO ruleStoredDao;
47

  
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.setStatus("working");
109
			newJob.setJobType("Workflow Request");
110
			newJob.setDuration("--");
111
			newJob.setRepo(mdstoreId);
112
			newJob.setRules(ruleIdsContent);
113
			newJob.setRecords(pros.getProperty(DnetProvider.RECORDS));
114
			newJob.setSet("dnet-workflow");
115
			newJob.setGroupBy_xpath(groupBy);
116
			newJob.setMetadata_prefix("oai_dc");
117
			newJob.setId("-1");
118
			int jobIdStored = jobSubmittedDao.save(newJob);
119
			
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, workers, listener, dnetListener);
132

  
133
			return newJob;
134
			
135
			
136
		} catch (Exception e) {
137
			logger.error("Error Submitting content job", e);
138
			throw new ValidatorException(e);
139
		}
140
	}
141

  
142
	@Override
143
	public JobSubmitted beginContentJobForWorkflow(String baseUrl, String validationSet, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler) throws ValidatorException {
144
		try {
145
			logger.debug("Submitting content job for workflow");
146
			Set<Integer> ruleIdsContent = new HashSet<Integer>();
147
			for (RuleSet ruleset : ruleSetDao.getRuleSets()) {
148
				String regRuleset;
149
				if (validationSet.equalsIgnoreCase("openaire_data")) {
150
					regRuleset = "OpenAIRE For Data Archives";
151
				} else {
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 = null;
160
			pros = new Properties();
161
			pros.setProperty(OAIPMHRecordProvider.BASEURL, baseUrl);
162
			pros.setProperty(OAIPMHRecordProvider.METADATA_PREFIX, "oai_dc");
163
			pros.setProperty(OAIPMHRecordProvider.TIMEOUT, "360000");
164
			pros.setProperty(OAIPMHRecordProvider.DELAY, "1000");
165
			pros.setProperty(OAIPMHRecordProvider.RETRY_DELAY, "60000");
166
			pros.setProperty(OAIPMHRecordProvider.RETRY_EFFORTS, "3");
167
			// pros.setProperty(OAIPMHRecordProvider.RECORDS, "20");
168
			pros.setProperty(OAIPMHRecordProvider.RECORDS, "all");
169
			pros.setProperty(OAIPMHRecordProvider.SET, validationSet);
170

  
171
			JobSubmitted newJob = new JobSubmitted();
172

  
173
			Set<Integer> rules = new HashSet<Integer>();
174
			
175
			Map<Integer,Integer> ruleLinkingMap = new HashMap<Integer,Integer>();
176

  
177
			for (Integer ruleId : ruleIdsContent) {
178
				RuleStored tempRule = ruleStoredDao.get(ruleId.toString());
179

  
180
				// special behaviour type of rule is chain
181
				if (tempRule.getType().equals("ChainRule")) {
182
					logger.debug("chain rule found");
183
					RuleStored tempRuleChain1 = ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_1"));
184
					RuleStored tempRuleChain2 = ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_2"));
185
					List<Rule> rules_chain = new ArrayList<Rule>();
186
					rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain1.getType(), tempRuleChain1.getConfiguration(), ruleIdRegistry));
187
					ruleIdRegistry++;
188
					rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain2.getType(), tempRuleChain2.getConfiguration(), ruleIdRegistry));
189
					ruleIdRegistry++;
190

  
191
					Properties chainPros = new Properties();
192
					chainPros.setProperty(ChainRule.TYPE, tempRule.getConfiguration().getProperty(ChainRule.TYPE));
193
					ChainRule<Rule> chainRule = new ChainRule<Rule>(chainPros, ruleIdRegistry, rules_chain);
194

  
195
					validator.addToRegistry(ruleIdRegistry, chainRule, MemoryThreadValidator.RegistryType.rules);
196
				} else {
197
					validator.addToRegistry(ruleIdRegistry, this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), ruleIdRegistry), MemoryThreadValidator.RegistryType.rules);
198
				}
199
				rules.add(ruleIdRegistry);
200
//				this.linkRules(ruleIdRegistry, ruleId);
201
				ruleLinkingMap.put(ruleIdRegistry, ruleId);
202
				ruleIdRegistry++;
203
			}
204
			if (pros.getProperty(OAIPMHRecordProvider.SET).equalsIgnoreCase(
205
					"openaire_data"))
206
				pros.setProperty(OAIPMHRecordProvider.METADATA_PREFIX,
207
						"oai_datacite");
208

  
209
			Job job = new Job(this.jobIdRegistry, 1, rules, pros);
210
			this.jobIdRegistry++;
211

  
212
			newJob.setUser("Workflow Service");
213
			newJob.setValidationType("OAI Content");
214
//			newJob.setType("OAI Content Validation");
215
			newJob.setStatus("working");
216
			newJob.setJobType("Workflow Request");
217
			//TODO FIX
218
			newJob.setGuidelines("OpenAIRE For Literature Repositories");
219
			newJob.setActivation_id(null);
220
			newJob.setDuration("--");
221
			newJob.setRepo(baseUrl);
222
			newJob.setRules(ruleIdsContent);
223
			newJob.setRecords(pros.getProperty(OAIPMHRecordProvider.RECORDS));
224
			newJob.setSet(pros.getProperty(OAIPMHRecordProvider.SET));
225
			newJob.setGroupBy_xpath(null);
226
			newJob.setMetadata_prefix(pros.getProperty(OAIPMHRecordProvider.METADATA_PREFIX));
227
			newJob.setId("-1");
228
			int jobIdStored = jobSubmittedDao.save(newJob);
229

  
230
			ValidatorJobListener listener = createListener();
231
			listener.setJobSubmittedId(jobIdStored);
232
			listener.setJobSubmittedUser("Workflow Service");
233
			listener.setRuleLinkingMap(ruleLinkingMap);
234
			listener.setGroupBy_xpath(null);
235
			listener.setInternalJobsSum(1);
236

  
237
			DnetListener dnetListener = createDnetListener();
238
			dnetListener.setJob(bJob);
239
			dnetListener.setBlackboardHandler(blackboardHandler);
240

  
241
			validator.submitJob(job, 1, listener, dnetListener);
242
			return newJob;
243

  
244
		} catch (Exception e) {
245
			logger.error("Error Submitting content job for workflow", e);
246
			throw new ValidatorException(e);
247
		}
248

  
249
	}
250

  
251
	@Override
252
	public JobSubmitted beginUsageJobForWorkflow(String baseUrl, String validationSet, BlackboardJob bJob, BlackboardNotificationHandler<BlackboardServerHandler> blackboardHandler) throws ValidatorException {
253
		try {
254

  
255
			logger.debug("Submitting Usage job(s) for workflow");
256

  
257
			Set<Integer> ruleIdsUsage = new HashSet<Integer>();
258
			for (RuleSet ruleset : ruleSetDao.getRuleSets()) {
259
				String regRuleset;
260
				if (validationSet.equalsIgnoreCase("openaire_data")) {
261
					regRuleset = "OpenAIRE For Data Archives";
262
				} else {
263
					regRuleset = "OpenAIRE For Literature Repositories";
264
				}
265
				if (ruleset.getName().equals(regRuleset)) {
266
					ruleIdsUsage = Utilities.convertListToSet(ruleset
267
							.getRuleIdsUsage());
268
				}
269
			}
270

  
271
			Properties pros = new Properties();
272
			pros.setProperty(OAIPMHSinglePageVerbProvider.BASEURL, baseUrl);
273
			pros.setProperty(OAIPMHSinglePageVerbProvider.TIMEOUT, "360000");
274
			pros.setProperty(OAIPMHSinglePageVerbProvider.DELAY, "1000");
275
			pros.setProperty(OAIPMHSinglePageVerbProvider.RETRY_DELAY, "60000");
276
			pros.setProperty(OAIPMHSinglePageVerbProvider.RETRY_EFFORTS, "3");
277

  
278
			JobSubmitted newJob = new JobSubmitted();
279

  
280
			List<RuleStored> rulesStored = new ArrayList<RuleStored>();
281
			for (Integer id : ruleIdsUsage) {
282
				logger.debug("Rule with id: " + id + " added");
283
				rulesStored.add(ruleStoredDao.get(id.toString()));
284
			}
285

  
286
			logger.debug("Creating map for provider information");
287
			Map<String, Set<Integer>> verbRuleMap = new HashMap<String, Set<Integer>>();
288
			Set<Integer> old, temp = null;
289
			for (RuleStored ruleStored : rulesStored) {
290
				logger.debug("Checking for verb : " + ruleStored.getProvider_information());
291
				if ((old = verbRuleMap.get(ruleStored.getProvider_information())) == null) {
292
					logger.debug("Verb doesn't exist");
293
					temp = new HashSet<Integer>();
294
					temp.add(Integer.parseInt(ruleStored.getId()));
295
					verbRuleMap.put(ruleStored.getProvider_information(), temp);
296
				} else {
297
					logger.debug("Verb exists");
298
					old.add(Integer.parseInt(ruleStored.getId()));
299
				}
300
			}
301

  
302
			Set<Integer> rules = null;
303

  
304
			Job job = null;
305
			newJob.setUser("Workflow Service");
306
			newJob.setValidationType("OAI Usage");
307
			newJob.setStatus("working");
308
			newJob.setJobType("Workflow Request");
309
			//TODO FIX
310
			newJob.setGuidelines("OpenAIRE For Literature Repositories");
311
			newJob.setActivation_id(null);
312
			newJob.setDuration("--");
313
			newJob.setRepo(pros.getProperty(OAIPMHSinglePageVerbProvider.BASEURL));
314
			newJob.setRules(ruleIdsUsage);
315
			newJob.setMetadata_prefix(pros.getProperty(OAIPMHRecordProvider.METADATA_PREFIX));
316
			newJob.setId("-1");
317

  
318
			int jobIdStored = jobSubmittedDao.save(newJob);
319

  
320
			Map<Integer,Integer> ruleLinkingMap = new HashMap<Integer,Integer>();
321
			
322
			ValidatorJobListener listener = createListener();
323
			listener.setJobSubmittedId(jobIdStored);
324
			listener.setJobSubmittedUser("Workflow Service");
325
			listener.setRuleLinkingMap(ruleLinkingMap);
326

  
327
			listener.setInternalJobsSum(verbRuleMap.size());
328
			for (Map.Entry<String, Set<Integer>> entry : verbRuleMap.entrySet()) {
329
				pros.remove(OAIPMHSinglePageVerbProvider.VERB);
330
				pros.setProperty(OAIPMHSinglePageVerbProvider.VERB,
331
						entry.getKey());
332
				rules = new HashSet<Integer>();
333
				for (Integer ruleId : entry.getValue()) {
334
					RuleStored tempRule = ruleStoredDao.get(Integer
335
							.toString(ruleId));
336
					logger.debug("prepare to add rule to registry with regexp: " + tempRule.getConfiguration().getProperty("regexp") + " and ruleIdregistry: " + ruleIdRegistry);
337
					validator.addToRegistry(ruleIdRegistry, this.getRuleClassInstanceByType(tempRule.getType(), tempRule.getConfiguration(), ruleIdRegistry), MemoryThreadValidator.RegistryType.rules);
338
					rules.add(ruleIdRegistry);
339
//					this.linkRules(ruleIdRegistry, ruleId);
340
					ruleLinkingMap.put(ruleIdRegistry, ruleId);
341
					ruleIdRegistry++;
342
				}
343

  
344
				job = new Job(this.jobIdRegistry, 2, rules, pros);
345

  
346
				DnetListener dnetListener = createDnetListener();
347
				dnetListener.setJob(bJob);
348
				dnetListener.setBlackboardHandler(blackboardHandler);
349

  
350
				validator.submitJob(job, 1, listener, dnetListener);
351

  
352
				this.jobIdRegistry++;
353
			}
354
			return newJob;
355
		} catch (Exception e) {
356
			logger.error("Error Submitting usage job(s)", e);
357
			throw new ValidatorException(e);
358
		}
359

  
360
	}
361

  
362
	private Serializable getRuleClassInstanceByType(String type,
363
			Properties pros, int id) throws ValidatorException {
364
		logger.debug("getting rule object of type " + type);
365
		String classname = RuleTypes.getClassOfType(type);
366
		if (classname == null) {
367
			logger.debug("error getting rule object of type " + type
368
					+ " classname=null");
369
			return null;
370
		} else {
371
			try {
372
				Class<?> clazz = Class.forName(classname);
373
				logger.debug("classname: " + clazz.getName());
374
				return (Serializable) clazz.getConstructor(
375
						new Class[] { Properties.class, Integer.TYPE })
376
						.newInstance(pros, id);
377

  
378
			} catch (ClassNotFoundException e) {
379
				logger.debug("error getting rule object: " + e);
380
				return null;
381
			} catch (NoSuchMethodException e) {
382
				logger.debug("error getting rule object: " + e);
383
				return null;
384
			} catch (InvocationTargetException e) {
385
				logger.debug("error getting rule object: " + e);
386
				return null;
387
			} catch (InstantiationException e) {
388
				logger.debug("error getting rule object: " + e);
389
				return null;
390
			} catch (IllegalAccessException e) {
391
				logger.debug("error getting rule object: " + e);
392
				return null;
393
			}
394
		}
395

  
396
	}
397
	
398
	private ChainRule<Rule> handleChain(RuleStored tempRule) throws Exception {
399
		logger.debug("chain rule found");
400
		List<Rule> rules_chain = new ArrayList<Rule>();
401
		RuleStored tempRuleChain1=ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_1"));
402
		if(tempRuleChain1.getType().equals("ChainRule")) {
403
			ChainRule<Rule> chainRule1 = this.handleChain(tempRuleChain1);
404
			rules_chain.add(chainRule1);
405
			ruleIdRegistry++;
406
		} else {
407
			rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain1.getType(), tempRuleChain1.getConfiguration(), ruleIdRegistry));
408
			ruleIdRegistry++;
409
		}
410
		RuleStored tempRuleChain2=ruleStoredDao.get(tempRule.getConfiguration().getProperty("rule_2"));
411
		if(tempRuleChain2.getType().equals("ChainRule")) {
412
			ChainRule<Rule> chainRule2 = this.handleChain(tempRuleChain2);
413
			rules_chain.add(chainRule2);
414
			ruleIdRegistry++;
415
		} else {
416
			rules_chain.add((Rule) this.getRuleClassInstanceByType(tempRuleChain2.getType(), tempRuleChain2.getConfiguration(), ruleIdRegistry));
417
			ruleIdRegistry++;
418
		}
419
		Properties chainPros = new Properties();
420
		chainPros.setProperty(ChainRule.TYPE,tempRule.getConfiguration().getProperty(ChainRule.TYPE));
421
		ChainRule<Rule> chainRule = new ChainRule<Rule>(chainPros, ruleIdRegistry, rules_chain);
422
		return chainRule;
423
	}
424

  
425
//	private void linkRules(int ruleRegistry, int ruleStored) {
426
//		this.ruleLinkingMap.put(ruleRegistry, ruleStored);
427
//	}
428
//
429
//	private int getRuleFromLink(int ruleRegistry) {
430
//		return this.ruleLinkingMap.get(ruleRegistry);
431
//	}
432

  
433
	public Validator getValidator() {
434
		return validator;
435
	}
436
	public void setValidator(Validator validator) {
437
		this.validator = validator;
438
	}
439
	public JobSubmittedDAO getJobSubmittedDao() {
440
		return jobSubmittedDao;
441
	}
442
	public void setJobSubmittedDao(JobSubmittedDAO jobSubmittedDao) {
443
		this.jobSubmittedDao = jobSubmittedDao;
444
	}
445
	public RuleSetDAO getRuleSetDao() {
446
		return ruleSetDao;
447
	}
448
	public void setRuleSetDao(RuleSetDAO ruleSetDao) {
449
		this.ruleSetDao = ruleSetDao;
450
	}
451
	public RuleStoredDAO getRuleStoredDao() {
452
		return ruleStoredDao;
453
	}
454
	public void setRuleStoredDao(RuleStoredDAO ruleStoredDao) {
455
		this.ruleStoredDao = ruleStoredDao;
456
	}
457
//	public Map<Integer, Integer> getRuleLinkingMap() {
458
//		return ruleLinkingMap;
459
//	}
460
//	public void setRuleLinkingMap(Map<Integer, Integer> ruleLinkingMap) {
461
//		this.ruleLinkingMap = ruleLinkingMap;
462
//	}
463
}
modules/uoa-validator-service/trunk/src/main/java/gr/uoa/di/validator/service/impl/ValidatorServiceImpl.java
1
package gr.uoa.di.validator.service.impl;
2

  
3
import eu.dnetlib.api.functionality.ValidatorService;
4
import eu.dnetlib.domain.ActionType;
5
import eu.dnetlib.domain.EPR;
6
import eu.dnetlib.domain.ResourceType;
7
import eu.dnetlib.domain.enabling.Notification;
8
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler;
9
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
10
import gr.uoa.di.driver.app.DriverServiceImpl;
11
import gr.uoa.di.driver.enabling.issn.NotificationListener;
12

  
13
import org.apache.log4j.Logger;
14

  
15
public class ValidatorServiceImpl extends DriverServiceImpl implements
16
		ValidatorService {
17

  
18
	private BlackboardNotificationHandler<BlackboardServerHandler> blackboardNotificationHandler = null;
19
	private Logger logger = Logger.getLogger(ValidatorServiceImpl.class);
20

  
21
	
22
	// do NOT call directly. It will be called by the
23
	// InitializingServiceRegistrationManager
24
	// after it sets the service EPR and id.
25
	@Override
26
	public void init() {
27
		super.init();
28
		this.subscribe(ActionType.UPDATE,
29
				ResourceType.VALIDATORSERVICERESOURCETYPE, this
30
						.getServiceEPR().getParameter("serviceId"),
31
				"RESOURCE_PROFILE/BODY/BLACKBOARD/LAST_REQUEST",
32
				new NotificationListener() {
33
					@Override
34
					public void processNotification(Notification notification) {
35
						blackboardNotificationHandler.notified(
36
								notification.getSubscriptionId(),
37
								notification.getTopic(),
38
								notification.getIsId(),
39
								notification.getMessage());
40
						logger.debug(notification.getSubscriptionId());
41
						logger.debug(notification.getTopic());
42
						logger.debug(notification.getIsId());
43
						logger.debug(notification.getMessage());
44
					}
45
				});
46
	}
47

  
48
	public BlackboardNotificationHandler<BlackboardServerHandler> getBlackboardNotificationHandler() {
49
		return blackboardNotificationHandler;
50
	}
51

  
52
	public void setBlackboardNotificationHandler(
53
			BlackboardNotificationHandler<BlackboardServerHandler> blackboardNotificationHandler) {
54
		this.blackboardNotificationHandler = blackboardNotificationHandler;
55
	}
56

  
57
	@Override
58
	public EPR validate(EPR datasource) {
59
		throw new UnsupportedOperationException();
60
	}
61
}
modules/uoa-validator-service/trunk/src/main/java/gr/uoa/di/validator/service/impl/NotificationListener.java
1
package gr.uoa.di.validator.service.impl;
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-service/trunk/src/main/java/eu/dnetlib/validator/service/dao/jobs/Entry.java
1
package eu.dnetlib.validator.service.dao.jobs;
2

  
3
import java.util.List;
4

  
5
public class Entry {
6

  
7
	private String name, description;
8
	private String successes;
9
	private int weight;
10
	private List<String> errors;
11
	private int ruleId;
12
	private boolean hasErrors, mandatory;
13
	
14
	public String getName() {
15
		return name;
16
	}
17
	public void setName(String name) {
18
		this.name = name;
19
	}
20
	public String getDescription() {
21
		return description;
22
	}
23
	public void setDescription(String description) {
24
		this.description = description;
25
	}
26
	public String getSuccesses() {
27
		return successes;
28
	}
29
	public void setSuccesses(String successes) {
30
		this.successes = successes;
31
	}
32
	public List<String> getErrors() {
33
		return errors;
34
	}
35
	public void setErrors(List<String> errors) {
36
		this.errors = errors;
37
	}
38
	public void setRuleId(int ruleId) {
39
		this.ruleId = ruleId;
40
	}
41
	public int getRuleId() {
42
		return ruleId;
43
	}
44
	public void setHasErrors(boolean hasErrors) {
45
		this.hasErrors = hasErrors;
46
	}
47
	public boolean isHasErrors() {
48
		return hasErrors;
49
	}
50
	public void setWeight(int weight) {
51
		this.weight = weight;
52
	}
53
	public int getWeight() {
54
		return weight;
55
	}
56
	public boolean isMandatory() {
57
		return mandatory;
58
	}
59
	public void setMandatory(boolean mandatory) {
60
		this.mandatory = mandatory;
61
	}
62

  
63
	
64
}
modules/uoa-validator-service/trunk/src/main/java/eu/dnetlib/validator/service/dao/jobs/JobSubmitted.java
1
package eu.dnetlib.validator.service.dao.jobs;
2

  
3
import java.util.Set;
4

  
5
public class JobSubmitted {
6
	private String status, started, ended, score, id, user, repo, duration, error , records, set, groupBy_xpath, metadata_prefix, activation_id;
7
	private String validationType, jobType, guidelines;
8
	private Set<Integer> rules;
9

  
10
	public String getDuration() {
11
		return duration;
12
	}
13

  
14
	public void setDuration(String duration) {
15
		this.duration = duration;
16
	}
17

  
18
	public String getRepo() {
19
		return repo;
20
	}
21

  
22
	public void setRepo(String repo) {
23
		this.repo = repo;
24
	}
25

  
26
	public String getUser() {
27
		return user;
28
	}
29

  
30
	public void setUser(String user) {
31
		this.user = user;
32
	}
33

  
34
	public String getId() {
35
		return id;
36
	}
37

  
38
	public void setId(String id) {
39
		this.id = id;
40
	}
41

  
42
	public String getStatus() {
43
		return status;
44
	}
45

  
46
	public void setStatus(String status) {
47
		this.status = status;
48
	}
49

  
50
	public String getStarted() {
51
		return started;
52
	}
53

  
54
	public void setStarted(String started) {
55
		this.started = started;
56
	}
57

  
58
	public String getEnded() {
59
		return ended;
60
	}
61

  
62
	public void setEnded(String ended) {
63
		this.ended = ended;
64
	}
65

  
66
	public String getScore() {
67
		return score;
68
	}
69

  
70
	public void setScore(String score) {
71
		this.score = score;
72
	}
73

  
74
	public String getError() {
75
		return error;
76
	}
77

  
78
	public void setError(String error) {
79
		this.error = error;
80
	}
81

  
82
	public Set<Integer> getRules() {
83
		return rules;
84
	}
85

  
86
	public void setRules(Set<Integer> rules) {
87
		this.rules = rules;
88
	}
89

  
90
	public String getRecords() {
91
		return records;
92
	}
93

  
94
	public void setRecords(String records) {
95
		this.records = records;
96
	}
97

  
98
	public String getSet() {
99
		return set;
100
	}
101

  
102
	public void setSet(String set) {
103
		this.set = set;
104
	}
105

  
106
	public String getGroupBy_xpath() {
107
		return groupBy_xpath;
108
	}
109

  
110
	public void setGroupBy_xpath(String groupBy_xpath) {
111
		this.groupBy_xpath = groupBy_xpath;
112
	}
113

  
114
	public String getMetadata_prefix() {
115
		return metadata_prefix;
116
	}
117

  
118
	public void setMetadata_prefix(String metadata_prefix) {
119
		this.metadata_prefix = metadata_prefix;
120
	}
121

  
122
	public String getActivation_id() {
123
		return activation_id;
124
	}
125

  
126
	public void setActivation_id(String activation_id) {
127
		this.activation_id = activation_id;
128
	}
129

  
130
	public String getGuidelines() {
131
		return guidelines;
132
	}
133

  
134
	public void setGuidelines(String guidelines) {
135
		this.guidelines = guidelines;
136
	}
137

  
138
	public String getValidationType() {
139
		return validationType;
140
	}
141

  
142
	public void setValidationType(String validationType) {
143
		this.validationType = validationType;
144
	}
145

  
146
	public String getJobType() {
147
		return jobType;
148
	}
149

  
150
	public void setJobType(String jobType) {
151
		this.jobType = jobType;
152
	}
153
}
modules/uoa-validator-service/trunk/src/main/java/eu/dnetlib/validator/service/email/BugReporter.java
1
package eu.dnetlib.validator.service.email;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.apache.log4j.Logger;
7

  
8

  
9
public class BugReporter {
10

  
11
	private transient Logger logger = Logger.getLogger(BugReporter.class);
12
	
13
	private String ex = null;
14

  
15
	public void report() {
16
		List<String> recipients = new ArrayList<String>();
17
		try {
18
			recipients.add("nikonas@di.uoa.gr");
19
			String message = "An exception has occurred:\n"+ex;
20
			String subject = "Automatic Bug Report";
21
//			this.getEmailer().sendMail(recipients, subject, message, false, null);
22
		} catch (Exception e) {
23
			logger.error("error sending error report", e);
24
		}
25
	}
26

  
27
	public void setEx(String ex) {
28
		this.ex = ex;
29
	}
30

  
31
	public String getEx() {
32
		return ex;
33
	}
34
	
35
	
36

  
37
}
modules/uoa-validator-service/trunk/src/main/resources/gr/uoa/di/validator/service/springContext-validator-service.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4
	xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
5
	xmlns:p="http://http://www.springframework.org/schema/p"
6
	xmlns:template="http://dnetlib.eu/springbeans/template" xmlns:t="http://dnetlib.eu/springbeans/t"
7
	xmlns:tx="http://www.springframework.org/schema/tx"
8

  
9
	xsi:schemaLocation="
10
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
11
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
12
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
13
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
14
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
15
        http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"
16
	default-autowire="no">
17

  
18
	<bean id="blackboardHandler"
19
		class="eu.dnetlib.enabling.tools.blackboard.BlackboardHandlerImpl">
20
		<property name="registryLocator" ref="cnr.registryLocator" />
21
		<property name="messageFactory">
22
			<bean class="eu.dnetlib.miscutils.jaxb.JaxbFactory">
23
				<constructor-arg
24
					value="eu.dnetlib.enabling.tools.blackboard.BlackboardMessageImpl" />
25
			</bean>
26
		</property>
27
	</bean>
28

  
29
	<bean id="notificationListener" class="gr.uoa.di.validator.service.NotificationListener"
30
		scope="singleton">
31
		<property name="valManager" ref="validatorManager" />
32
		<property name="blackboardHandler" ref="blackboardHandler" />
33
	</bean>
34

  
35
	<bean id="validatorManager" class="gr.uoa.di.validator.service.ValidatorManagerImpl"
36
		scope="singleton" init-method="start">
37
		<property name="validator" ref="validator" />
38
		<property name="jobSubmittedDao" ref="jobSubmittedDao" />
39
		<property name="ruleSetDao" ref="ruleSetDao" />
40
		<property name="ruleStoredDao" ref="ruleStoredDao" />
41
		<lookup-method name="createListener" bean="openaireValListener" />
42
		<lookup-method name="createDnetListener" bean="openaireDnetListener" />
43
	</bean>
44

  
45
	<bean id="validatorService" class="gr.uoa.di.validator.service.ValidatorServiceImpl"
46
		scope="singleton">
47
		<property name="snManager" ref="snManager" />
48
		<property name="blackboardNotificationHandler" ref="notificationListener" />
49
	</bean>
50

  
51
<!-- 	<bean id="dnetProvider" class="gr.uoa.di.validator.service.DnetProvider" factory-method="getInstance"> -->
52
<!-- 		<property name="dataSourceResolver" ref="extendedDataSourceResolver" /> -->
53
<!-- 		<property name="rsFactory" ref="resultSetFactory" /> -->
54
<!-- 	</bean> -->
55

  
56

  
57
	<!-- The web service bean -->
58
	<bean id="validatorWebServiceImpl"
59
		class="eu.dnetlib.clients.functionality.validator.ws.ValidatorWebServiceImpl">
60
		<property name="service" ref="validatorService" />
61
	</bean>
62

  
63
	<!-- Service endpoint -->
64
	<jaxws:endpoint 
65
		id="validatorWebService" 
66
		implementor="#validatorWebServiceImpl"
67
		implementorClass="eu.dnetlib.clients.functionality.validator.ws.ValidatorWebService"
68
		address="/validatorWebService"/>
69

  
70
	<template:instance name="nkua.serviceRegistrationManager"
71
		t:name="validatorServiceRegistrationManager"
72
		t:service="validatorService"
73
		t:endpoint="validatorWebService"/>
74
</beans>
modules/uoa-validator-service/trunk/src/main/java/eu/dnetlib/validator/service/dao/users/UserStored.java
1
package eu.dnetlib.validator.service.dao.users;
2

  
3
public class UserStored {
4

  
5
	private String email;
6
	private String password;
7
	private String activationId;
8
	
9
	public String getEmail() {
10
		return email;
11
	}
12
	public void setEmail(String email) {
13
		this.email = email;
14
	}
15
	public String getPassword() {
16
		return password;
17
	}
18
	public void setPassword(String password) {
19
		this.password = password;
20
	}
21
	public String getActivationId() {
22
		return activationId;
23
	}
24
	public void setActivationId(String activationId) {
25
		this.activationId = activationId;
26
	}
27
	
28
}
modules/uoa-validator-service/trunk/src/main/resources/eu/dnetlib/validator/service/dao/springContext-validator-dao.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4
	xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
5
	xmlns:p="http://http://www.springframework.org/schema/p"
6
	xmlns:template="http://dnetlib.eu/springbeans/template" xmlns:t="http://dnetlib.eu/springbeans/t"
7
	xmlns:tx="http://www.springframework.org/schema/tx"
8

  
9
	xsi:schemaLocation="
10
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
11
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
12
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
13
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
14
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
15
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
16
        http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"
17
	default-autowire="no">
18

  
19
	<bean id="jobSubmittedDao" class="gr.uoa.di.validator.dao.jobs.JobSubmittedDAOImpl">
20
		<property name="datasource" ref="validator.dataSource" />
21
	</bean>
22
	
23
	<bean id="repositoryStoredDao" class="gr.uoa.di.validator.dao.repositories.RepositoryStoredDAOImpl">
24
		<property name="datasource" ref="validator.dataSource" />
25
	</bean>
26

  
27
	<bean id="ruleSetDao" class="gr.uoa.di.validator.dao.rules.RuleSetDAOimpl">
28
		<property name="datasource" ref="validator.dataSource" />
29
	</bean>	
30

  
31
	<bean id="ruleStoredDao" class="gr.uoa.di.validator.dao.rules.RuleStoredDAOimpl">
32
		<property name="datasource" ref="validator.dataSource" />
33
	</bean>		
34
	
35
	<bean id="taskStoredDao" class="gr.uoa.di.validator.dao.tasks.TaskStoredDAOimpl">
36
		<property name="datasource" ref="validator.dataSource" />
37
	</bean>		
38
	
39
	<bean id="userStoredDao" class="gr.uoa.di.validator.dao.users.UserStoredDAOimpl">
40
		<property name="datasource" ref="validator.dataSource" />
41
	</bean>				
42
	
43
</beans>
modules/uoa-validator-service/trunk/src/main/webapp/WEB-INF/log4j.properties
8 8

  
9 9
log4j.additivity.eu.dnetlib = false
10 10
log4j.additivity.gr.uoa = false
11

  
12 11
log4j.additivity.org.springframework = false
13 12
log4j.additivity.org.hsqld = false
14 13

  
15 14
log4j.appender.R = org.apache.log4j.RollingFileAppender
16
log4j.appender.R.File = /tmp/log/validator.log
15
log4j.appender.R.File = /tmp/log/validator-service.log
17 16
log4j.appender.R.MaxFileSize = 10MB
18 17
log4j.appender.R.MaxBackupIndex = 10
19 18
log4j.appender.R.layout = org.apache.log4j.PatternLayout
20 19
log4j.appender.R.layout.ConversionPattern = %d %p %t [%c] - %m%n
21 20

  
22 21
log4j.appender.S = org.apache.log4j.RollingFileAppender
23
log4j.appender.S.File = /tmp/log/validator-spring.log
22
log4j.appender.S.File = /tmp/log/validator-service-spring.log
24 23
log4j.appender.S.MaxFileSize = 10MB
25 24
log4j.appender.S.MaxBackupIndex = 10
26 25
log4j.appender.S.layout = org.apache.log4j.PatternLayout
modules/uoa-validator-service/trunk/src/main/java/eu/dnetlib/validator/service/dao/users/UserStoredDAO.java
1
package eu.dnetlib.validator.service.dao.users;
2

  
3
import eu.dnetlib.validator.service.dao.DAO;
4

  
5

  
6
public interface UserStoredDAO extends DAO<UserStored> {
7

  
8
	public boolean checkCorrectCreds(UserStored newUser);
9

  
10
	public boolean isAdmin(String email);
11

  
12
	public boolean isRepoAdmin(String email);
13
	
14
	public boolean isActivated(String email);
15

  
16
	public boolean userExists(String email);
17

  
18
	public void prepareResetPassword(String uuid, String email);
19

  
20
	public void ResetPassword(String uuid, String password);
21

  
22
}
modules/uoa-validator-service/trunk/src/main/java/eu/dnetlib/validator/service/dao/users/UserStoredDAOimpl.java
1
package eu.dnetlib.validator.service.dao.users;
2

  
3
import eu.dnetlib.validator.service.dao.AbstractDAO;
4

  
5
import java.sql.Connection;
6
import java.sql.PreparedStatement;
7
import java.sql.ResultSet;
8
import java.sql.SQLException;
9

  
10
public class UserStoredDAOimpl extends AbstractDAO<UserStored> implements UserStoredDAO {
11

  
12

  
13
	@Override
14
	protected PreparedStatement getUpdateStatement(UserStored t, Connection con)
15
			throws SQLException {
16
		String query="UPDATE users SET activation_id=? WHERE activation_id=?";
17
		PreparedStatement stmt = con.prepareStatement(query);
18
		stmt.setString(1, null);
19
		stmt.setString(2, t.getActivationId());
20
		return stmt;
21
	}
22

  
23
	
24
	@Override
25
	protected PreparedStatement getInsertStatement(UserStored t, Connection con)
26
			throws SQLException {
27
		String query="INSERT INTO users(email,password,activation_id) VALUES(?,?,?)";
28
		PreparedStatement stmt = con.prepareStatement(query);
29
		stmt.setString(1, t.getEmail());
30
		stmt.setString(2, t.getPassword());
31
		stmt.setString(3, t.getActivationId());		
32
		return stmt;
33
	}
34

  
35
	@Override
36
	protected PreparedStatement getDeleteStatement(String id, Connection con)
37
			throws SQLException {
38
		// TODO Auto-generated method stub
39
		return null;
40
	}
41

  
42
	@Override
43
	protected int getLastId() throws SQLException {
44
		// TODO Auto-generated method stub
45
		return 0;
46
	}
47

  
48
	@Override
49
	public UserStored get(String id) {
50
		// TODO Auto-generated method stub
51
		return null;
52
	}
53

  
54

  
55
	@Override
56
	public boolean checkCorrectCreds(UserStored newUser) {
57
		ResultSet rs = null;
58
		Connection con = null;
59
		PreparedStatement stmt = null;
60
		logger.debug("Accessing DB to check correct credentials");
61
		try {
62
			con = getConnection();
63
			String query="SELECT * FROM users WHERE email=? AND password=?";
64
			stmt = con.prepareStatement(query);
65
			stmt.setString(1,newUser.getEmail());
66
			stmt.setString(2,newUser.getPassword());
67
			rs = stmt.executeQuery();
68
			if (rs.next()){
69
				return true;
70
			}
71
		} catch (SQLException e) {
72
			logger.error("Error while accessing DB to check correct credentials: "+e);
73
		} finally {
74
			if (stmt != null) {
75
				try {
76
					stmt.close();
77
				} catch (SQLException e) {
78
					logger.error("Error while accessing DB to check correct credentials: "+e);
79
				}
80
			}
81
		}
82
		return false;
83
	}
84

  
85

  
86
	@Override
87
	public boolean isAdmin(String email) {
88
		ResultSet rs = null;
89
		Connection con = null;
90
		PreparedStatement stmt = null;
91
		logger.debug("Accessing DB to check if user is admin");
92
		try {
93
			con = getConnection();
94
			String query="SELECT * FROM admins WHERE username=? AND level=?";
95
			stmt = con.prepareStatement(query);
96
			stmt.setString(1,email);
97
			stmt.setString(2,"secondary");
98
			rs = stmt.executeQuery();
99
			if (rs.next()){
100
				return true;
101
			}
102
		} catch (SQLException e) {
103
			logger.error("Error while accessing DB to check if user is admin: "+e);
104
		} finally {
105
			if (stmt != null) {
106
				try {
107
					stmt.close();
108
				} catch (SQLException e) {
109
					logger.error("Error while accessing DB to check if user is admin: "+e);
110
				}
111
			}
112
		}
113
		return false;
114
	}
115

  
116
	@Override
117
	public boolean isRepoAdmin(String email) {
118
		ResultSet rs = null;
119
		Connection con = null;
120
		PreparedStatement stmt = null;
121
		logger.debug("Accessing DB to check if user is repoAdmin");
122
		try {
123
			con = getConnection();
124
			String query="SELECT * FROM admins WHERE username=? AND level=?";
125
			stmt = con.prepareStatement(query);
126
			stmt.setString(1,email);
127
			stmt.setString(2,"secondary");
128
			rs = stmt.executeQuery();
129
			if (rs.next()){
130
				return true;
131
			}
132
		} catch (SQLException e) {
133
			logger.error("Error while accessing DB to check if user is repoAdmin: "+e);
134
		} finally {
135
			if (stmt != null) {
136
				try {
137
					stmt.close();
138
				} catch (SQLException e) {
139
					logger.error("Error while accessing DB to check if user is repoAdmin: "+e);
140
				}
141
			}
142
		}
143
		return false;
144
	}
145

  
146
	@Override
147
	public boolean isActivated(String email) {
148
		ResultSet rs = null;
149
		Connection con = null;
150
		PreparedStatement stmt = null;
151
		logger.debug("Accessing DB to check if user is activated");
152
		try {
153
			con = getConnection();
154
			String query="SELECT * FROM users WHERE email=? AND activation_id is null";
155
			stmt = con.prepareStatement(query);
156
			stmt.setString(1,email);
157
//			stmt.setString(2,"NULL");
158
			rs = stmt.executeQuery();
159
			if (rs.next()){
160
				return true;
161
			}
162
		} catch (SQLException e) {
163
			logger.error("Error while accessing DB to check if user is activated "+e);
164
		} finally {
165
			if (stmt != null) {
166
				try {
167
					stmt.close();
168
				} catch (SQLException e) {
169
					logger.error("Error while accessing DB to check if user is activated "+e);
170
				}
171
			}
172
		}
173
		return false;
174
	}
175

  
176

  
177
	@Override
178
	public boolean userExists(String email) {
179
		ResultSet rs = null;
180
		Connection con = null;
181
		PreparedStatement stmt = null;
182
		logger.debug("Accessing DB to check if user "+email+" exists");
183
		try {
184
			con = getConnection();
185
//			con.setAutoCommit(false); 
186
//			con.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
187
			String query="SELECT * FROM users WHERE email=?";
188
			stmt = con.prepareStatement(query);
189
			stmt.setString(1,email);
190
			rs = stmt.executeQuery();
191
			if (rs.next()){
192
				logger.debug("user exists");
193
				return true;
194
			}
195
		} catch (SQLException e) {
196
			logger.error("Error while accessing DB to check if user exists: "+e);
197
		} finally {
198
			if (stmt != null) {
199
				try {
200
					stmt.close();
201
				} catch (SQLException e) {
202
					logger.error("Error while accessing DB to check if user exists: "+e);
203
				}
204
			}
205
		}
206
		return false;
207
	}
208

  
209

  
210
	@Override
211
	public void prepareResetPassword(String uuid, String email) {
212
		Connection con = null;
213
		PreparedStatement stmt = null;
214
		logger.debug("Accessing DB to prepare reset password");
215
		try {
216
			con = getConnection();
217
			String query="UPDATE users SET activation_id=? WHERE email=?";;
218
			stmt = con.prepareStatement(query);
219
			stmt.setString(1,uuid);
220
			stmt.setString(2,email);
221
			stmt.executeUpdate();
222
		} catch (SQLException e) {
223
			logger.error("Error while accessing DB to prepare reset password: "+e);
224
		} finally {
225
			if (stmt != null) {
226
				try {
227
					stmt.close();
228
				} catch (SQLException e) {
229
					logger.error("Error while accessing DB to prepare reset password: "+e);
230
				}
231
			}
232
		}
233
	}
234

  
235

  
236
	@Override
237
	public void ResetPassword(String uuid, String password) {
238
		Connection con = null;
239
		PreparedStatement stmt = null;
240
		logger.debug("Accessing DB to reset password");
241
		try {
242
			con = getConnection();
243
			String query="UPDATE users SET password=? WHERE activation_id=?";;
244
			stmt = con.prepareStatement(query);
245
			stmt.setString(1,password);
246
			stmt.setString(2,uuid);
247
			stmt.executeUpdate();
248
		} catch (SQLException e) {
249
			logger.error("Error while accessing DB to reset password: "+e);
250
		} finally {
251
			if (stmt != null) {
252
				try {
253
					stmt.close();
254
				} catch (SQLException e) {
255
					logger.error("Error while accessing DB to reset password: "+e);
256
				}
257
			}
258
		}
259
	}
260

  
261
}
modules/uoa-validator-service/trunk/src/main/java/eu/dnetlib/validator/service/dao/DAO.java
1
package eu.dnetlib.validator.service.dao;
2

  
3
public interface DAO<T> {
4

  
5
	public Integer save (T t);
6
//	public String delete (T t);
7
	public String delete (String id);
8
	public T get (String id);
9
}
modules/uoa-validator-service/trunk/src/main/java/eu/dnetlib/validator/service/dao/tasks/TaskStored.java
1
package eu.dnetlib.validator.service.dao.tasks;
2

  
3

  
4
public class TaskStored {
5

  
6
	private String status, started, ended, jobId, ruleId, valObjId, recordIdentifier, recordUrl;
7
	private boolean success;
8
//	private RuleD rule;
9
	
10
	public String getRecordUrl() {
11
		return recordUrl;
12
	}
13
	public void setRecordUrl(String recordUrl) {
14
		this.recordUrl = recordUrl;
15
	}
16
	public String getStatus() { 
17
		return status;
18
	}
19
	public void setStatus(String status) {
20
		this.status = status;
21
	}
22
	public boolean getSuccess() {
23
		return success;
24
	}
25
	public void setSuccess(boolean success) {
26
		this.success = success;
27
	}
28
	public String getStarted() {
29
		return started;
30
	}
31
	public void setStarted(String started) {
32
		this.started = started;
33
	}
34
	public String getEnded() {
35
		return ended;
36
	}
37
	public void setEnded(String ended) {
38
		this.ended = ended;
39
	}
40
	public String getJobId() {
41
		return jobId;
42
	}
43
	public void setJobId(String jobId) {
44
		this.jobId = jobId;
45
	}
46
	public String getRuleId() {
47
		return ruleId;
48
	}
49
	public void setRuleId(String ruleId) {
50
		this.ruleId = ruleId;
51
	}
52
	
53
	public String getValObjId() {
54
		return valObjId;
55
	}
56
	public void setValObjId(String valObjId) {
57
		this.valObjId = valObjId;
58
	}
59
	public String getRecordIdentifier() {
60
		return recordIdentifier;
61
	}
62
	public void setRecordIdentifier(String recordIdentifier) {
63
		this.recordIdentifier = recordIdentifier;
64
	}
65
//	public RuleD getRule() {
66
//		return rule;
67
//	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff