Revision 57213
Added by Ioannis Diplas over 4 years ago
JobsDAOImpl.java | ||
---|---|---|
16 | 16 |
import java.util.Map; |
17 | 17 |
import java.util.Map.Entry; |
18 | 18 |
import java.util.Set; |
19 |
import java.util.stream.Collectors; |
|
19 | 20 |
|
20 | 21 |
import eu.dnetlib.domain.functionality.validator.JobForValidation; |
21 | 22 |
import eu.dnetlib.domain.functionality.validator.JobResultEntry; |
... | ... | |
971 | 972 |
return retJob; |
972 | 973 |
} |
973 | 974 |
|
975 |
@Override |
|
976 |
public List<StoredJob> getJobSummary(List<String> baseUrls, int size) throws DaoException { |
|
977 |
ResultSet rs = null; |
|
978 |
Connection con = null; |
|
979 |
PreparedStatement stmt = null; |
|
980 |
List<JobResultEntry> resultEntries = new ArrayList<JobResultEntry>(); |
|
981 |
StringBuilder builder = new StringBuilder(); |
|
982 |
List<StoredJob> storedJobs = new ArrayList<>(); |
|
983 |
for(int i = 0; i < baseUrls.size(); i++ ) { |
|
984 |
builder.append("?,"); |
|
985 |
} |
|
986 |
Map<Integer, List<JobResultEntry>> results = new HashMap<>(); |
|
987 |
try { |
|
988 |
con = getConnection(); |
|
989 |
String query="select rules.name, rules.description, rules.weight, rules.mandatory, total, successes, rules.id, rules.job_type, job_results.job_id from job_results join rules on job_results.rule_id = rules.id join jobs on jobs.id = job_results.job_id where jobs.repo in ("+ builder.deleteCharAt( builder.length() -1 ).toString() +") order by job_results.job_id limit " + size; |
|
990 |
stmt = con.prepareStatement(query); |
|
991 |
int index = 1; |
|
992 |
for( String o : baseUrls) { |
|
993 |
stmt.setString( index++, o ); // or whatever it applies |
|
994 |
} |
|
995 |
rs = stmt.executeQuery(); |
|
996 |
JobResultEntry retEntry = new JobResultEntry(); |
|
997 |
if (rs!=null){ |
|
998 |
int oldId = 0; |
|
999 |
while (rs.next()) { |
|
1000 |
if(oldId!=rs.getInt("job_id")){ |
|
1001 |
results.put(oldId,resultEntries); |
|
1002 |
logger.debug("Old id:"+oldId + " new id:"+rs.getInt("job_id") + " size:"+resultEntries.size()); |
|
1003 |
System.out.println("Old id:"+oldId + " new id:"+rs.getInt("job_id") + " size:"+resultEntries.size()); |
|
1004 |
oldId=rs.getInt("job_id"); |
|
1005 |
resultEntries = new ArrayList<>(); |
|
1006 |
} |
|
1007 |
retEntry.setName(rs.getString(1)); |
|
1008 |
retEntry.setDescription(rs.getString(2)); |
|
1009 |
retEntry.setWeight(rs.getInt(3)); |
|
1010 |
retEntry.setMandatory(rs.getBoolean(4)); |
|
1011 |
retEntry.setRuleId(rs.getInt(7)); |
|
1012 |
retEntry.setType(rs.getString("job_type")); |
|
1013 |
retEntry.setErrors(this.getValidationErrors(rs.getInt("job_id"), retEntry.getRuleId())); |
|
1014 |
int total = rs.getInt(5); |
|
1015 |
int successes = rs.getInt(6); |
|
1016 |
if (rs.getInt(5) > 0) |
|
1017 |
retEntry.setSuccesses(successes + "/" + total); |
|
1018 |
else |
|
1019 |
retEntry.setSuccesses("--"); |
|
1020 |
if (successes < total) |
|
1021 |
retEntry.setHasErrors(true); |
|
1022 |
else |
|
1023 |
retEntry.setHasErrors(false); |
|
1024 |
|
|
1025 |
resultEntries.add(retEntry); |
|
1026 |
} |
|
1027 |
if(oldId!=0) |
|
1028 |
results.put(oldId,resultEntries); |
|
1029 |
|
|
1030 |
|
|
1031 |
if(results.get(0)!=null) |
|
1032 |
results.remove(0); |
|
1033 |
for(Map.Entry<Integer,List<JobResultEntry>> entry : results.entrySet()){ |
|
1034 |
StoredJob storedJob = this.get(entry.getKey()); |
|
1035 |
storedJob.setResultEntries(entry.getValue()); |
|
1036 |
storedJob.setFilteredScores(this.getScoresPerGroupBy(entry.getKey())); |
|
1037 |
storedJob.getFilteredScores().put("all", storedJob.getContentJobScore()); |
|
1038 |
storedJobs.add(storedJob); |
|
1039 |
} |
|
1040 |
} |
|
1041 |
} catch (Exception e) { |
|
1042 |
logger.error("Error while Accessing DB to get all Jobs entries.", e); |
|
1043 |
throw new DaoException(e); |
|
1044 |
} finally { |
|
1045 |
if (stmt != null) { |
|
1046 |
try { |
|
1047 |
stmt.close(); |
|
1048 |
} catch (SQLException e) { |
|
1049 |
logger.error("Error while Accessing DB to get all Jobs entries.", e); |
|
1050 |
throw new DaoException(e); |
|
1051 |
} |
|
1052 |
} |
|
1053 |
closeConnection(con); |
|
1054 |
} |
|
1055 |
return storedJobs; |
|
1056 |
} |
|
1057 |
|
|
974 | 1058 |
public List<String> getValidationErrors(int jobId, int ruleId) throws DaoException { |
975 | 1059 |
ResultSet rs = null; |
976 | 1060 |
Connection con = null; |
Also available in: Unified diff
Added method for getting StoredJobs by base url