@Override public boolean equals(Object obj) { if ((obj == null) || (!(obj instanceof DistributionFile))) { return false; } DistributionFile other = (DistributionFile) obj; if (getDistribution() == null) { if (other.getDistribution() != null) { return false; } } else if (!getDistribution().equals(other.getDistribution())) { return false; } return true; }
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @TransactionTimeout(45 * 60) public long outputDistributionFileBits(DistributionFile distFile, OutputStream outputStream) { long numBytes = 0L; InputStream bitStream = null; try { Distribution dist = distFile.getDistribution(); log.info("Distribution has a basePath of " + dist.getBasePath()); String distFilePath = dist.getBasePath() + "/" + distFile.getRelativeFilename(); File f = getDistributionFileBitsLocalFilesystemFile(dist.getLabel(), distFilePath); log.info("Fetching: " + distFilePath + " on local file store from: " + f.getAbsolutePath()); bitStream = new FileInputStream(f); numBytes = StreamUtil.copy(bitStream, outputStream); } catch (Exception e) { log.info(e); } finally { // close our stream but leave the output stream open try { bitStream.close(); } catch (Exception closeError) { log.warn("Failed to close the bits stream", closeError); } } log.debug("Retrieved and sent [" + numBytes + "] bytes for [" + distFile.getRelativeFilename() + "]"); return numBytes; }
private void translateDomainToDto(List<Distribution> dists, List<DistributionDetails> distDetails) { DistributionManagerLocal distManager = LookupUtil.getDistributionManagerLocal(); for (Distribution d : dists) { DistributionDetails detail = new DistributionDetails(d.getLabel(), d.getDistributionType().getName()); detail.setLabel(d.getLabel()); detail.setDistributionPath(d.getBasePath()); detail.setDescription(d.getDistributionType().getDescription()); List<DistributionFile> files = distManager.getDistributionFilesByDistId(d.getId()); for (DistributionFile f : files) { DistributionFileDetails dfd = new DistributionFileDetails(f.getRelativeFilename(), f.getLastModified(), f.getMd5sum()); detail.addFile(dfd); } distDetails.add(detail); } }
log.debug("Found " + distFiles.size() + " DistributionFiles"); for (DistributionFile dFile : distFiles) { String relPath = dist.getBasePath() + "/" + dFile.getRelativeFilename(); File outputFile = getDistLocalFileAndCreateParentDir(dist.getLabel(), relPath); log.debug("Checking if file exists at: " + outputFile.getAbsolutePath()); if (outputFile.exists()) { log.debug("File " + outputFile.getAbsolutePath() + " exists, checking md5sum"); String expectedMD5 = (dFile.getMd5sum() != null) ? dFile.getMd5sum() : "<unspecified MD5>"; String actualMD5 = MessageDigestGenerator.getDigestString(outputFile); if (!expectedMD5.trim().toLowerCase().equals(actualMD5.toLowerCase())) { log.debug("Attempting download of " + dFile.getRelativeFilename() + " from contentSourceId " + contentSourceId); String remoteFetchLoc = distSource.getDistFileRemoteLocation(repo.getName(), dist.getLabel(), dFile.getRelativeFilename()); InputStream bitsStream = pc.getAdapterManager().loadDistributionFileBits(contentSourceId, remoteFetchLoc);
for (DistributionFileDetails f : files) { log.debug("Creating DistributionFile for: " + f); DistributionFile df = new DistributionFile(newDist, f.getRelativeFilename(), f.getMd5sum()); df.setLastModified(f.getLastModified()); entityManager.persist(df); entityManager.flush();
@Override public int hashCode() { int result = 1; result = (31 * result) + ((getDistribution() == null) ? 0 : getDistribution().hashCode()); return result; }