Project

General

Profile

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

    
3
import eu.dnetlib.api.functionality.ValidatorService;
4
import eu.dnetlib.api.functionality.ValidatorServiceException;
5
import eu.dnetlib.domain.ActionType;
6
import eu.dnetlib.domain.ResourceType;
7
import eu.dnetlib.domain.enabling.Notification;
8
import eu.dnetlib.domain.functionality.validator.JobForValidation;
9
import eu.dnetlib.domain.functionality.validator.JobResultEntry;
10
import eu.dnetlib.domain.functionality.validator.RuleSet;
11
import eu.dnetlib.domain.functionality.validator.StoredJob;
12
import eu.dnetlib.enabling.tools.blackboard.BlackboardNotificationHandler;
13
import eu.dnetlib.enabling.tools.blackboard.BlackboardServerHandler;
14
import eu.dnetlib.validator.commons.dao.DaoException;
15
import eu.dnetlib.validator.engine.ValidatorException;
16
import gr.uoa.di.driver.app.DriverServiceImpl;
17
import gr.uoa.di.driver.enabling.issn.NotificationListener;
18

    
19
import java.util.List;
20

    
21
import org.apache.log4j.Logger;
22

    
23
public class ValidatorServiceImpl extends DriverServiceImpl implements
24
		ValidatorService {
25

    
26
	private BlackboardNotificationHandler<BlackboardServerHandler> blackboardNotificationHandler = null;
27
	private Logger logger = Logger.getLogger(ValidatorServiceImpl.class);
28

    
29
	private ValidatorManager valManager;
30

    
31
	// do NOT call directly. It will be called by the
32
	// InitializingServiceRegistrationManager
33
	// after it sets the service EPR and id.
34
	@Override
35
	public void init() {
36
		super.init();
37
		if (this.blackboardNotificationHandler != null) { 
38
			this.subscribe(ActionType.UPDATE,
39
				ResourceType.VALIDATORSERVICERESOURCETYPE, this.getServiceEPR()
40
						.getParameter("serviceId"),
41
				"RESOURCE_PROFILE/BODY/BLACKBOARD/LAST_REQUEST",
42
				new NotificationListener() {
43
					@Override
44
					public void processNotification(Notification notification) {
45
						blackboardNotificationHandler.notified(
46
								notification.getSubscriptionId(),
47
								notification.getTopic(),
48
								notification.getIsId(),
49
								notification.getMessage());
50
						logger.debug(notification.getSubscriptionId());
51
						logger.debug(notification.getTopic());
52
						logger.debug(notification.getIsId());
53
						logger.debug(notification.getMessage());
54
					}
55
				});
56
		}
57
	}
58

    
59
	@Override
60
	public StoredJob getStoredJob(int jobId, String groupBy)
61
			throws ValidatorServiceException {
62
		try {
63
			logger.info("received request for job " + jobId);
64
			return valManager.getStoredJob(jobId, groupBy);
65
		} catch (ValidatorException e) {
66
			throw new ValidatorServiceException(e);
67
		}
68

    
69
	}
70

    
71
	@Override
72
	public List<StoredJob> getJobSummary(List<String> baseUrl, int size) throws ValidatorServiceException {
73
		try {
74
			return valManager.getJobSummary(baseUrl,size);
75
		} catch (DaoException e) {
76
			throw new ValidatorServiceException(e);
77
		}
78
	}
79

    
80

    
81
	@Override
82
	public List<StoredJob> getStoredJobs(String userMail, String jobType,
83
										 Integer offset, Integer limit, String dateFrom, String dateTo)
84
			throws ValidatorServiceException {
85
		try {
86
			logger.debug("received request for jobs of user " + userMail);
87
			return valManager.getStoredJobs(userMail, jobType, offset, limit, dateFrom, dateTo);
88
		} catch (ValidatorException e) {
89
			throw new ValidatorServiceException(e);
90
		}
91
	}
92

    
93
	@Override
94
	public List<StoredJob> getStoredJobsNew(String userMail, String jobType,
95
										 Integer offset, Integer limit, String dateFrom, String dateTo, String jobStatus)
96
			throws ValidatorServiceException {
97
		try {
98
			logger.debug("received request for jobs of user " + userMail);
99
			return valManager.getStoredJobs(userMail, jobType, offset, limit, dateFrom, dateTo, jobStatus);
100
		} catch (ValidatorException e) {
101
			throw new ValidatorServiceException(e);
102
		}
103
	}
104

    
105
	@Override
106
	public int getStoredJobsTotalNumber(String userMail, String jobType)
107
			throws ValidatorServiceException {
108
		try {
109
			logger.debug("received request for total number of jobs of user " + userMail);
110
			return valManager.getStoredJobsTotalNumber(userMail, jobType);
111
		} catch (ValidatorException e) {
112
			throw new ValidatorServiceException(e);
113
		}
114
	}
115

    
116
	@Override
117
	public int getStoredJobsTotalNumberNew(String userMail, String jobType, String jobStatus)
118
			throws ValidatorServiceException {
119
		try {
120
			logger.debug("received request for total number of jobs of user " + userMail);
121
			return valManager.getStoredJobsTotalNumber(userMail, jobType, jobStatus);
122
		} catch (ValidatorException e) {
123
			throw new ValidatorServiceException(e);
124
		}
125
	}
126

    
127
	@Override
128
	public List<RuleSet> getRuleSets() throws ValidatorServiceException {
129
		try {
130
			logger.info("received request for rulesets ");
131
			return valManager.getRuleSets();
132
		} catch (ValidatorException e) {
133
			throw new ValidatorServiceException(e);
134
		}
135
	}
136

    
137
	@Override
138
	public void submitValidationJob(JobForValidation job)
139
			throws ValidatorServiceException {
140
		try {
141
			logger.info("received request to submit job");
142
			this.valManager.submitJob(job);
143
		} catch (ValidatorException e) {
144
			throw new ValidatorServiceException(e);
145
		}
146
	}
147

    
148
	public BlackboardNotificationHandler<BlackboardServerHandler> getBlackboardNotificationHandler() {
149
		return blackboardNotificationHandler;
150
	}
151

    
152
	public ValidatorManager getValManager() {
153
		return valManager;
154
	}
155

    
156
	public void setValManager(ValidatorManager valManager) {
157
		this.valManager = valManager;
158
	}
159

    
160
	public void setBlackboardNotificationHandler(
161
			BlackboardNotificationHandler<BlackboardServerHandler> blackboardNotificationHandler) {
162
		this.blackboardNotificationHandler = blackboardNotificationHandler;
163
	}
164

    
165
}
(4-4/4)