@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; }
@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); }
/** * 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())); } }
/** * 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<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); } }