/** * Copy constructor for a DcsFile. The state of <code>toCopy</code> is copied * to this. * * @param toCopy the dcs file to copy */ public DcsFile(DcsFile toCopy) { super(toCopy); this.name = toCopy.getName(); this.extant = toCopy.isExtant(); this.sizeBytes = toCopy.getSizeBytes(); this.fixity = toCopy.getFixity(); this.formats = toCopy.getFormats(); this.source = toCopy.getSource(); this.valid = toCopy.getValid(); this.metadata = toCopy.getMetadata(); this.metadataRef = toCopy.getMetadataRef(); }
public DcsFile createFile() { DcsFile file = new DcsFile(); file.setExtant(rand.nextBoolean()); file.setId(nextid()); file.setFixity(createFixitySet(rand.nextInt(3))); file.setFormats(createFormatSet(rand.nextInt(2))); file.setName(randomString(8, false)); file.setSizeBytes(Math.abs(rand.nextLong())); file.setSource(randomString(10, false)); if (rand.nextBoolean()) { file.setValid(rand.nextBoolean()); } file.setMetadata(createMetadataSet(rand.nextInt(2))); file.setMetadataRef(createMetadataRefSet(rand.nextInt(2))); return file; }
private void updateFileAncestry(Map<String, List<String>> ancestrymap, Collection<DcsFile> set) throws IOException, SolrServerException { for (DcsFile file : set) { for (DcsMetadataRef ref : file.getMetadataRef()) { updateAncestry(ancestrymap, ref, file.getId()); } } }
DcsManifestation man = new DcsManifestation(); DcsManifestationFile mf = new DcsManifestationFile(); DcsFile file = new DcsFile(); file.setId("file"); mf.setRef(new DcsFileRef(file.getId())); man.addManifestationFile(mf); man.addTechnicalEnvironment(XSTREAM_TECHNICAL_ENV); File xmlfile = File.createTempFile("metadata", null); xmlfile.deleteOnExit(); file.setSource(xmlfile.toURI().toURL().toExternalForm()); file.setExtant(true); file.setName("metadata.xml");
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { final DcsFile file = new DcsFile(); final String src = reader.getAttribute(A_SRC); if (!isEmptyOrNull(id)) { file.setId(id); file.setSource(src); file.setName(value); file.setExtant(Boolean.parseBoolean(value)); } catch (Exception e) { final String msg = "Unable to parse boolean value '" + value + "' for element '" + E_EXTANT + "': " + e.getMessage(); file.setValid(Boolean.parseBoolean(value)); } catch (Exception e) { final String msg = "Unable to parse boolean value '" + value + "' for element '" + E_VALID + "': " + e.getMessage(); file.setSizeBytes(Long.parseLong(value)); }catch (Exception e) { final String msg = "Unable to parse long value '" + value + "' for element '" + E_SIZE + "': " + e.getMessage(); final DcsFixity fixity = (DcsFixity) context.convertAnother(file, DcsFixity.class); if (fixity != null) { file.addFixity(fixity); final DcsFormat format = (DcsFormat) context.convertAnother(file, DcsFormat.class); if (format != null) {
DcsFile dataSetMd = new DcsFile(); dataSetMd.setId(UUID.randomUUID().toString()); java.io.File tmp = null; try { dataSetMd.setSizeBytes(tmp.length()); dataSetMd.setExtant(true); try { dataSetMd.addFixity(calculateFixity(new FileInputStream(tmp), MessageDigest.getInstance("MD5"))); dataSetMd.addFixity(calculateFixity(new FileInputStream(tmp), MessageDigest.getInstance("SHA1"))); } catch (Exception e) { throw new DcpMappingException("Error calculating file length or fixity: " + e.getMessage(), e); dataSetMd.setName(tmp.getName()); dataSetMd.setSource(tmp.toURI().toString()); return dataSetMd;
if (f.getId().equals(dataSetMetadataFileRef.getRef())) { dataSetMetadataFile = f; InputStream fis = new URL(dataSetMetadataFile.getSource()).openStream(); ds = (DataItem)xstream.fromXML(fis); final String msg = "Error retrieving stream '" + dataSetMetadataFile.getSource() + "' from the archive: " + e.getMessage(); log.error(msg, e); throw new RuntimeException(msg, e);
file.setName(physicalFile.getName()); fixity.setAlgorithm(checksumAlgorithm); fixity.setValue(new String(Hex.encodeHex(digest))); file.addFixity(fixity); format.setSchemeUri("http://www.iana.org/assignments/media-types/"); format.setFormat(mime); file.addFormat(format); file.setSource(doUpload(path, mime, digest, length)); file.setSizeBytes(length); file.setExtant(true);
if (df.getId() != null && df.getId().equals(file_id)) { file = df; break; metadataFile.setSize(file.getSizeBytes()); metadataFile.setPath(dcs_mf.getPath()); for (DcsFormat format : file.getFormats()) { for (DcsResourceIdentifier id : file.getAlternateIds()) { if (id.getAuthorityId() != null && id.getAuthorityId().equals(Id.getAuthority()) metadataFile.setSource(file.getSource());
String pid = mapper.getPID(entity.getId()); fdo.setObjectPid(pid); String title = "File: " + entity.getId(); if (entity.getId() != null) { DublinCoreElement dceIdentifier = new DublinCoreElement(); dceIdentifier.setName(DublinCoreConverter.IDENTIFIER); dceIdentifier.setValue(entity.getId()); dc.getElementList().add(dceIdentifier); erdfeid.setLiteral(entity.getId()); String ianaURI = "http://www.iana.org/assignments/media-types/"; String registryURI = "http://www.nationalarchives.gov.uk/PRONOM/"; for (DcsFormat formatEntry : entity.getFormats()) { dcfdsv.setVersionID(dcfds.getId() + DatastreamVersionConverter.BASE_VERSION); dcfdsv.setLabel(entity.getName()); location.setLocationURL(entity.getSource()); location.setType(ContentLocationConverter.LOCATION_TYPE_URL); dcfdsv.setContent(location);
@Override public String getId() { return fileDelegate.getId(); }
@Override public String getSource() { return fileDelegate.getSource(); }
@Override public DataFile fromDcp(Dcp dcp) throws DcpMappingException { DataFile df = super.fromDcp(dcp); if (df == null) { throw new DcpMappingException("Unable to map DataFile from DCP: " + dcp); } DcsFile source = boSearcher.findDataFile(df.getId()); if (source != null) { df.setSource(source.getSource()); df.setSize(source.getSizeBytes()); df.setPath(source.getSource()); } return df; }
@Override public String getName() { return fileDelegate.getName(); }
if (f.getId().equals(target)) { f.addMetadataRef(mdref); found = true;
public Set<DcsFile> getFiles() { final Set<DcsFile> files = new HashSet<DcsFile>(this.files.size()); for (DcsFile f : this.files) { files.add(new DcsFile(f)); } return files; }