/** * Generates a filename using the base name of a source element and the extension of a derived element. * * @param source * the source media package element * @param derived * the derived media package element * @return the filename */ protected String getFileNameFromElements(MediaPackageElement source, MediaPackageElement derived) { String fileName = FilenameUtils.getBaseName(source.getURI().getPath()); String fileExtension = FilenameUtils.getExtension(derived.getURI().getPath()); return fileName + "." + fileExtension; }
/** * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo(MediaPackageElement o) { return uri.toString().compareTo(o.getURI().toString()); }
/** * Extract the file name from a media package elements URI. * * @return the file name or none if it could not be determined */ public static Opt<String> getFileName(MediaPackageElement mpe) { final URI uri = mpe.getURI(); if (uri != null) { return Opt.nul(FilenameUtils.getName(uri.toString())).bind(Strings.blankToNone); } else { return Opt.none(); } }
/** * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (!(obj instanceof MediaPackageElement)) return false; MediaPackageElement e = (MediaPackageElement) obj; if (mediaPackage != null && e.getMediaPackage() != null && !mediaPackage.equals(e.getMediaPackage())) return false; if (id != null && !id.equals(e.getIdentifier())) return false; if (uri != null && !uri.equals(e.getURI())) return false; return true; }
/** * Load the DublinCore catalog identified by <code>mpe</code>. Throws an exception if it does not exist or cannot be * loaded by any reason. * * @return the catalog */ public static DublinCoreCatalog loadDublinCore(Workspace workspace, MediaPackageElement mpe) { URI uri = mpe.getURI(); logger.debug("Loading DC catalog from {}", uri); try (InputStream in = workspace.read(uri)) { return DublinCores.read(in); } catch (Exception e) { logger.error("Unable to load metadata from catalog '{}'", mpe, e); return chuck(e); } }
/** * Remove all files created by the given jobs * @param jobs */ private void cleanupWorkspace(List<Job> jobs) { for (Job job : jobs) { String jobPayload = job.getPayload(); if (StringUtils.isNotEmpty(jobPayload)) { try { MediaPackageElement timelinepreviewsMpe = MediaPackageElementParser.getFromXml(jobPayload); URI timelinepreviewsUri = timelinepreviewsMpe.getURI(); workspace.delete(timelinepreviewsUri); } catch (MediaPackageException ex) { // unexpected job payload logger.error("Can't parse timeline previews attachment from job {}", job.getId()); } catch (NotFoundException ex) { // this is ok, because we want delete the file } catch (IOException ex) { logger.warn("Deleting timeline previews image file from workspace failed: {}", ex.getMessage()); // this is ok, because workspace cleaner will remove old files if they exist } } } }
Job receipt = JobParser.parseJob(response.getEntity().getContent()); logger.info("Completing inspection of media file at {} using a remote media inspection service", original.getURI()); return receipt;
File file; try { file = workspace.get(element.getURI()); } catch (NotFoundException e) { throw new MediaInspectionException("Unable to find " + element.getURI() + " in the workspace", e); } catch (IOException e) { throw new MediaInspectionException("Error accessing " + element.getURI() + " in the workspace", e); element.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, file)); } catch (IOException e) { throw new MediaInspectionException("Error generating checksum for " + element.getURI(), e);
try { timelinePreviewsMpe = MediaPackageElementParser.getFromXml(jobPayload); timelinePreviewsFile = workspace.get(timelinePreviewsMpe.getURI()); } catch (MediaPackageException ex) { throw new WorkflowOperationException("Timeline preview images file '" + timelinePreviewsMpe.getURI() + "' not found", ex); } catch (IOException ex) { throw new WorkflowOperationException("Can't get workflow image file '" + timelinePreviewsMpe.getURI() + "' from workspace"); timelinePreviewsMpe.getURI(), mediaPackage.getIdentifier().compact()); String fileName = FilenameUtils.getName(timelinePreviewsMpe.getURI().getPath()); URI timelinePreviewsWfrUri = workspace.put(mediaPackage.getIdentifier().compact(), timelinePreviewsMpe.getIdentifier(), fileName, timelinePreviewsInputStream);
try { waveformMpe = MediaPackageElementParser.getFromXml(jobPayload); URI newURI = workspace.moveTo(waveformMpe.getURI(), mediaPackage.getIdentifier().toString(), waveformMpe.getIdentifier(), "waveform.png"); waveformMpe.setURI(newURI); throw new WorkflowOperationException("Waveform image file '" + waveformMpe.getURI() + "' not found", ex); } catch (IOException ex) { throw new WorkflowOperationException("Can't get workflow image file '" + waveformMpe.getURI() + "' from workspace");