Project

General

Profile

« Previous | Next » 

Revision 36209

Added by Nikon Gasparis over 9 years ago

  • usage jobs do not update number of tested records
  • new method to save a job

View differences:

modules/uoa-validator-commons/trunk/src/main/java/eu/dnetlib/validator/commons/dao/jobs/JobsDAO.java
3 3
import java.util.List;
4 4
import java.util.Map;
5 5

  
6
import eu.dnetlib.domain.functionality.validator.JobForValidation;
7 6
import eu.dnetlib.domain.functionality.validator.StoredJob;
8 7
import eu.dnetlib.validator.commons.dao.DAO;
9 8
import eu.dnetlib.validator.commons.dao.rules.RuleStatus;
......
21 20

  
22 21
	public void setStatus(int jobId, String status, int recordsTested, String validationType);
23 22
	
24
	public void storeJobForCris(JobForValidation job, int jobId);
25
	
26
	public void storeJobForRegistration(JobForValidation job, int jobIdStored);
27

  
28 23
	public List<StoredJob> getUncompletedJobs();
29 24
	
30 25
	public List<StoredJob> getJobs(String userName, String jobType, Integer offset, Integer limit, String dateFrom, String dateTo);
modules/uoa-validator-commons/trunk/src/main/java/eu/dnetlib/validator/commons/dao/jobs/JobsDAOImpl.java
28 28
public class JobsDAOImpl extends AbstractDAO<StoredJob> implements JobsDAO{
29 29

  
30 30
	@Override
31
	protected PreparedStatement getUpdateStatement(StoredJob t,
32
			Connection con) throws SQLException {
33
		logger.debug("getting submittedjob updateStatement");
34
		String query="UPDATE jobs SET validation_type=?, started=to_timestamp(?, 'YYYY-MM-DD HH24:MI:SS'), guidelines=?, content_job_status=?, repo=?, duration=? WHERE id=?";
31
	public Integer save(StoredJob job) {
32
		Connection con = null;
33
		PreparedStatement stmt = null;
34
		Integer retId = -1;
35
		logger.debug("Accessing DB to save/update Job");
36
		try {
37
			logger.debug("Accessing DB to update Job");
38
			Calendar cal = Calendar.getInstance();
39
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
35 40

  
36
		PreparedStatement stmt = con.prepareStatement(query);
37
		Calendar cal = Calendar.getInstance();
38
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
39
		stmt.setString(1, t.getValidationType());
40
		stmt.setString(2, sdf.format(cal.getTime()));
41
//		stmt.setTimestamp(2, getCurrentTimeStamp());
42
		stmt.setString(3, t.getDesiredCompatibilityLevel());
43
		stmt.setString(4, t.getContentJobStatus());
44
		stmt.setString(5, t.getBaseUrl());
45
		stmt.setString(6, t.getDuration());
46
		stmt.setInt(7, t.getId());
41
			con = getConnection();
42
			logger.debug("getting submittedjob updateStatement");
43
			String query="UPDATE jobs SET validation_type=?, started=to_timestamp(?, 'YYYY-MM-DD HH24:MI:SS'), guidelines=?, content_job_status=?, repo=?, duration=? WHERE id=?";
47 44

  
48
		return stmt;
45
			stmt = con.prepareStatement(query);
46
			stmt.setString(1, job.getValidationType());
47
			stmt.setString(2, sdf.format(cal.getTime()));
48
			stmt.setString(3, job.getDesiredCompatibilityLevel());
49
			stmt.setString(4, job.getContentJobStatus());
50
			stmt.setString(5, job.getBaseUrl());
51
			stmt.setString(6, job.getDuration());
52
			stmt.setInt(7, job.getId());
53
			
54
			if (stmt.executeUpdate() == 0) {
55
				stmt.close();
56
				logger.debug("Accessing DB to save Job");
57
				query="INSERT INTO jobs(validation_type,started,guidelines,user_email,content_job_status, usage_job_status, repo, duration, rules, records, set, groupby_xpath, metadata_prefix, job_type) VALUES(?,to_timestamp(?, 'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?,?,?,?,?,?,?)";
58
				stmt = con.prepareStatement(query);
59
				stmt.setString(1, job.getValidationType());
60
				stmt.setString(2, sdf.format(cal.getTime()));
61
//				stmt.setTimestamp(2, getCurrentTimeStamp());
62
				stmt.setString(3, job.getDesiredCompatibilityLevel());
63
				stmt.setString(4, job.getUserEmail());
64
				stmt.setString(5, job.getContentJobStatus());
65
				stmt.setString(6, job.getUsageJobStatus());
66
				stmt.setString(7, job.getBaseUrl());
67
				stmt.setString(8, job.getDuration());
68
				stmt.setString(9, Utilities.convertSetToString(job.getRules()));
69
				stmt.setString(10, Integer.toString(job.getRecords()));
70
				stmt.setString(11, job.getValidationSet());
71
				stmt.setString(12, job.getGroupByXpath());
72
				stmt.setString(13, job.getMetadataPrefix());
73
				stmt.setString(14, job.getJobType());
74
				stmt.executeUpdate();
75
				retId = this.getLastId();
76
			} else {
77
				logger.debug("Accessing DB to update job-done");
78
				retId=job.getId();
79
			}
80
			
81
			if (job.isRegistration()) {
82
				this.storeJobForRegistration(job, retId);
83
			}
84
			if (job.isCris()) {
85
				this.storeJobForCris(job, retId);
86
			}
87
			stmt.close();
88
		    
89
		} catch (SQLException e) {
90
			logger.error("Error accessing DB to get save/update Rule.", e);
91
		} finally {
92
			if (stmt != null) {
93
				try {
94
					stmt.close();
95
				} catch (SQLException e) {
96
					logger.error("Error accessing DB to get save/update Rule.", e);
97
				}
98
			}
99
		}
100
		return retId;
49 101
	}
50 102

  
51 103
	@Override
52
	protected PreparedStatement getInsertStatement(StoredJob t,
53
			Connection con) throws SQLException {
54
		logger.debug("getting submittedjob insertStatement");
55
		Calendar cal = Calendar.getInstance();
56
		
57
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
58
		
59
		String query="INSERT INTO jobs(validation_type,started,guidelines,user_email,content_job_status, usage_job_status, repo, duration, rules, records, set, groupby_xpath, metadata_prefix, job_type) VALUES(?,to_timestamp(?, 'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?,?,?,?,?,?,?)";
60
		PreparedStatement stmt = con.prepareStatement(query);
61
		stmt.setString(1, t.getValidationType());
62
		stmt.setString(2, sdf.format(cal.getTime()));
63
//		stmt.setTimestamp(2, getCurrentTimeStamp());
64
		stmt.setString(3, t.getDesiredCompatibilityLevel());
65
		stmt.setString(4, t.getUserEmail());
66
		stmt.setString(5, t.getContentJobStatus());
67
		stmt.setString(6, t.getUsageJobStatus());
68
		stmt.setString(7, t.getBaseUrl());
69
		stmt.setString(8, t.getDuration());
70
		stmt.setString(9, Utilities.convertSetToString(t.getRules()));
71
		stmt.setString(10, Integer.toString(t.getRecords()));
72
		stmt.setString(11, t.getValidationSet());
73
		stmt.setString(12, t.getGroupByXpath());
74
		stmt.setString(13, t.getMetadataPrefix());
75
		stmt.setString(14, t.getJobType());
76
		
77
		return stmt;
78
	}
79

  
80
	@Override
81 104
	protected PreparedStatement getDeleteStatement(int id, Connection con) throws SQLException {
82 105
		String query="DELETE FROM jobs " + " WHERE id=?";
83 106
		PreparedStatement stmt = con.prepareStatement(query);
84 107
		stmt.setInt(1, id);
85 108
		return stmt;
86 109
	}
87

  
110
	
88 111
	@Override
89 112
	public StoredJob get(int id) {
90 113
		ResultSet rs = null;
......
661 684
			if (failed) 
662 685
				error = "Server responded with error while issuing the request to retrieve the records.";
663 686
			con = getConnection();
664
			String query="UPDATE jobs SET " + validationType + "_job_status=? , records_tested=? WHERE id=?";
665
			stmt = con.prepareStatement(query);
666
			stmt.setString(1, "finished");
667
			stmt.setInt(2, objsValidated);
668
			stmt.setInt(3, jobId);
687
			String query = null;
688
			if (validationType.equalsIgnoreCase("content"))	{
689
				query="UPDATE jobs SET " + validationType + "_job_status=? , records_tested=? WHERE id=?";
690
				stmt = con.prepareStatement(query);
691
				stmt.setString(1, "finished");
692
				stmt.setInt(2, objsValidated);
693
				stmt.setInt(3, jobId);
694
			}
695
			else if (validationType.equalsIgnoreCase("usage")) {	
696
				query="UPDATE jobs SET " + validationType + "_job_status=? WHERE id=?";
697
				stmt = con.prepareStatement(query);
698
				stmt.setString(1, "finished");
699
				stmt.setInt(2, jobId);
700
			}
669 701

  
670 702
			int res = stmt.executeUpdate();
671 703
			stmt.close();
......
1154 1186

  
1155 1187
	}	
1156 1188
	
1157
	@Override
1158
	public void storeJobForRegistration(JobForValidation job, int jobId) {
1189
	private void storeJobForRegistration(JobForValidation job, int jobId) {
1159 1190
		
1160 1191
		Connection con = null;
1161 1192
		PreparedStatement stmt = null;
......
1192 1223
		
1193 1224
	}
1194 1225
	
1195
	@Override
1196
	public void storeJobForCris(JobForValidation job, int jobId) {
1226
	private void storeJobForCris(JobForValidation job, int jobId) {
1197 1227
		
1198 1228
		Connection con = null;
1199 1229
		PreparedStatement stmt = null;
......
1301 1331
		}
1302 1332
	}
1303 1333
	
1334
	@Override
1335
	protected PreparedStatement getUpdateStatement(StoredJob t,
1336
			Connection con) throws SQLException {
1337
		logger.debug("getting submittedjob updateStatement");
1338
		String query="UPDATE jobs SET validation_type=?, started=to_timestamp(?, 'YYYY-MM-DD HH24:MI:SS'), guidelines=?, content_job_status=?, repo=?, duration=? WHERE id=?";
1339

  
1340
		PreparedStatement stmt = con.prepareStatement(query);
1341
		Calendar cal = Calendar.getInstance();
1342
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1343
		stmt.setString(1, t.getValidationType());
1344
		stmt.setString(2, sdf.format(cal.getTime()));
1345
//		stmt.setTimestamp(2, getCurrentTimeStamp());
1346
		stmt.setString(3, t.getDesiredCompatibilityLevel());
1347
		stmt.setString(4, t.getContentJobStatus());
1348
		stmt.setString(5, t.getBaseUrl());
1349
		stmt.setString(6, t.getDuration());
1350
		stmt.setInt(7, t.getId());
1351

  
1352
		return stmt;
1353
	}
1354

  
1355
	@Override
1356
	protected PreparedStatement getInsertStatement(StoredJob t,
1357
			Connection con) throws SQLException {
1358
		logger.debug("getting submittedjob insertStatement");
1359
		Calendar cal = Calendar.getInstance();
1360
		
1361
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1362
		
1363
		String query="INSERT INTO jobs(validation_type,started,guidelines,user_email,content_job_status, usage_job_status, repo, duration, rules, records, set, groupby_xpath, metadata_prefix, job_type) VALUES(?,to_timestamp(?, 'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?,?,?,?,?,?,?)";
1364
		PreparedStatement stmt = con.prepareStatement(query);
1365
		stmt.setString(1, t.getValidationType());
1366
		stmt.setString(2, sdf.format(cal.getTime()));
1367
//		stmt.setTimestamp(2, getCurrentTimeStamp());
1368
		stmt.setString(3, t.getDesiredCompatibilityLevel());
1369
		stmt.setString(4, t.getUserEmail());
1370
		stmt.setString(5, t.getContentJobStatus());
1371
		stmt.setString(6, t.getUsageJobStatus());
1372
		stmt.setString(7, t.getBaseUrl());
1373
		stmt.setString(8, t.getDuration());
1374
		stmt.setString(9, Utilities.convertSetToString(t.getRules()));
1375
		stmt.setString(10, Integer.toString(t.getRecords()));
1376
		stmt.setString(11, t.getValidationSet());
1377
		stmt.setString(12, t.getGroupByXpath());
1378
		stmt.setString(13, t.getMetadataPrefix());
1379
		stmt.setString(14, t.getJobType());
1380
		
1381
		return stmt;
1382
	}
1383

  
1384
	
1304 1385
	private static java.sql.Timestamp getCurrentTimeStamp() {
1305 1386
		 
1306 1387
		java.util.Date today = new java.util.Date();

Also available in: Unified diff