Project

General

Profile

1
package eu.dnetlib.validator.service.impl;
2

    
3
import org.apache.log4j.Logger;
4
import org.hibernate.hql.ast.tree.UpdateStatement;
5

    
6
import eu.dnetlib.enabling.tools.blackboard.BlackboardJob;
7
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler;
8
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
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 validationSet = job.getParameters().get("validationSet");
22
//		String validationType = job.getParameters().get("validationType");
23
		String type = job.getParameters().get("type"); //OAI
24
		String mdstoreId = job.getParameters().get("mdstoreId");
25
		String guidelines = job.getParameters().get("guidelines");
26
		String groupBy = job.getParameters().get("groupBy");
27
		String records = job.getParameters().get("records");
28
		String submissionDate = job.getParameters().get("submissionDate");
29
		
30
		String jobStatusUpdateInterval = job.getParameters().get("jobStatusUpdateInterval");
31
		
32
		//the datasource id
33
	    String datasourceId = job.getParameters().get("datasourceId");
34
		
35
	    //the datasource baseUrl, optional for type=OAI, mandatory for type=DNET
36
	    String baseUrl = job.getParameters().get("baseUrl");
37
	    
38
	    //the namespace prefix of the datasource, optional
39
	    String datasourceNamespacePrefix = job.getParameters().get("datasourceNamespacePrefix");
40
	    
41
	    //the datasource name, optional
42
	    String datasourceName = job.getParameters().get("datasourceName");
43
	    
44
	    //json map of other parameters that may be of interest, optional
45
	    String extra_param = job.getParameters().get("extra_param");
46
		
47
	    try {
48
			int workers = 1;
49
			int recordsInt = 0;
50
			int jobStatusUpdateIntervalInt = 100;
51
			if (records == null || records.equalsIgnoreCase("all")) 
52
				recordsInt = -1;
53
			else
54
				recordsInt = Integer.parseInt(records);
55
			if (recordsInt > -1 && recordsInt < 100)
56
				workers = 1;
57
			else
58
				workers = 4;
59
			if (jobStatusUpdateInterval != null)
60
				jobStatusUpdateIntervalInt = Integer.parseInt(jobStatusUpdateInterval);
61
			
62
			if (recordsInt != 0) {
63
				logger.debug("New Job of type: " + type + " - workers: " + workers + " - recordsInt: " + recordsInt);
64
				logger.debug("workers: " + workers);
65
				logger.debug("recordsInt: " + recordsInt);
66
				logger.debug("jobStatusUpdateInterval: " + jobStatusUpdateIntervalInt);
67
				if (job.getAction().equalsIgnoreCase("VALIDATE")) {
68
					if (type.equalsIgnoreCase("OAI")) {
69
						logger.debug("type is oai");
70
						
71
					} else if (type.equalsIgnoreCase("DNET")) {
72
						logger.debug("type is dnet");
73
						logger.debug("groupBy: " + groupBy);
74
						this.getBlackboardHandler().ongoing(job);
75
						valManager.beginDataJobForWorkflow(mdstoreId, guidelines, groupBy, recordsInt, workers, job, this, jobStatusUpdateIntervalInt);
76
					}
77
				} else {
78
					throw new Exception("Unknown action");
79
				}
80
			} else {
81
				throw new Exception("There are no records in the MDStore.");
82
			}
83
		} catch (Exception e) {
84
			logger.error("Failed to begin the workflow for the job received", e);
85
			getBlackboardHandler().failed(job, e);
86
		}
87
	}
88

    
89
	public ValidatorManager getValManager() {
90
		return valManager;
91
	}
92

    
93
	public void setValManager(ValidatorManager valManager) {
94
		this.valManager = valManager;
95
	}
96
}
(1-1/4)