private InputStream getDeliverableContent(Deliverable deliverable) { URL url = null; try { String uriStart = getHostForLaunch(deliverable.getJobId()); url = new URL(uriStart + "/ws/simple/file?id=" + deliverable.getRandomId()); jqmlogger.trace("URL: " + url.toString()); } catch (MalformedURLException e) { throw new JqmClientException("URL is not valid " + url, e); } return getFile(url.toString()); }
@Override public List<com.enioka.jqm.api.Deliverable> getJobDeliverables(int idJob) { DbConn cnx = null; try { cnx = getDbSession(); // TODO: no intermediate entity here: directly SQL => API object. List<Deliverable> deliverables = Deliverable.select(cnx, "deliverable_select_all_for_ji", idJob); List<com.enioka.jqm.api.Deliverable> res = new ArrayList<>(); for (Deliverable d : deliverables) { res.add(new com.enioka.jqm.api.Deliverable(d.getFilePath(), d.getFileFamily(), d.getId(), d.getOriginalFileName())); } return res; } catch (Exception e) { throw new JqmClientException("Could not query files for job instance " + idJob, e); } finally { closeQuietly(cnx); } }
public static List<Deliverable> select(DbConn cnx, String query_key, Object... args) { List<Deliverable> res = new ArrayList<Deliverable>(); try { ResultSet rs = cnx.runSelect(query_key, args); while (rs.next()) { Deliverable tmp = new Deliverable(); tmp.id = rs.getInt(1); tmp.fileFamily = rs.getString(2); tmp.filePath = rs.getString(3); tmp.jobId = rs.getInt(4); tmp.originalFileName = rs.getString(5); tmp.randomId = rs.getString(6); res.add(tmp); } } catch (SQLException e) { throw new DatabaseException(e); } return res; } }
/** * Version of {@link JqmClient#getDeliverableContent(Deliverable)} which does not require the web service APIs to be enabled to work. * Also, returned files do not self-destruct on stream close.<br> * See the javadoc of the original method for details. * * @throws FileNotFoundException */ public InputStream getDeliverableContent(Deliverable file) throws FileNotFoundException { List<com.enioka.jqm.model.Deliverable> dd = com.enioka.jqm.model.Deliverable.select(cnx, "deliverable_select_by_id", file.getId()); if (dd.isEmpty()) { throw new JqmInvalidRequestException("no deliverable with this ID"); } com.enioka.jqm.model.Deliverable d = dd.get(0); JobInstance ji = Query.create().setJobInstanceId(d.getJobId()).run().get(0); String nodeName = ji.getNodeName(); Node n = nodes.get(nodeName); return new FileInputStream(FilenameUtils.concat(n.getDlRepo(), file.getFilePath())); } }
@Override public List<InputStream> getJobDeliverablesContent(int idJob) { DbConn cnx = null; ArrayList<InputStream> streams = new ArrayList<>(); try { cnx = getDbSession(); for (Deliverable del : Deliverable.select(cnx, "deliverable_select_all_for_ji", idJob)) { streams.add(getDeliverableContent(del)); } } catch (Exception e) { throw new JqmClientException("could not retrieve file streams", e); } finally { closeQuietly(cnx); } return streams; }
/** * Version of {@link JqmClient#getDeliverableContent(Deliverable)} which does not require the web service APIs to be enabled to work. * Also, returned files do not self-destruct on stream close.<br> * See the javadoc of the original method for details. * * @throws FileNotFoundException */ public InputStream getDeliverableContent(Deliverable file) throws FileNotFoundException { List<com.enioka.jqm.model.Deliverable> dd = com.enioka.jqm.model.Deliverable.select(cnx, "deliverable_select_by_id", file.getId()); if (dd.isEmpty()) { throw new JqmInvalidRequestException("no deliverable with this ID"); } com.enioka.jqm.model.Deliverable d = dd.get(0); JobInstance ji = Query.create().setJobInstanceId(d.getJobId()).run().get(0); String nodeName = ji.getNodeName(); Node n = nodes.get(nodeName); return new FileInputStream(FilenameUtils.concat(n.getDlRepo(), file.getFilePath())); } }
@Override public InputStream getDeliverableContent(int delId) { DbConn cnx = null; Deliverable deliverable = null; try { cnx = getDbSession(); List<Deliverable> dd = Deliverable.select(cnx, "deliverable_select_by_id", delId); if (dd.size() == 0) { throw new JqmClientException("There is no deliverable with the given ID - check your ID"); } deliverable = dd.get(0); } catch (Exception e) { throw new JqmInvalidRequestException("Could not get find deliverable description inside DB - your ID may be wrong", e); } finally { closeQuietly(cnx); } return getDeliverableContent(deliverable); }
public static List<Deliverable> select(DbConn cnx, String query_key, Object... args) { List<Deliverable> res = new ArrayList<>(); try { ResultSet rs = cnx.runSelect(query_key, args); while (rs.next()) { Deliverable tmp = new Deliverable(); tmp.id = rs.getInt(1); tmp.fileFamily = rs.getString(2); tmp.filePath = rs.getString(3); tmp.jobId = rs.getInt(4); tmp.originalFileName = rs.getString(5); tmp.randomId = rs.getString(6); res.add(tmp); } } catch (SQLException e) { throw new DatabaseException(e); } return res; } }