use of org.mycore.datamodel.ifs.MCRFile in project mycore by MyCoRe-Org.
the class MCRTransferPackageFileContainer method processNode.
/**
* @param node the node to process
*/
private void processNode(MCRFilesystemNode node) {
MCRDirectory dir = (MCRDirectory) node;
MCRFilesystemNode[] children = dir.getChildren();
for (MCRFilesystemNode child : children) {
if (child instanceof MCRDirectory) {
processNode(child);
}
if (child instanceof MCRFile) {
this.fileList.add((MCRFile) child);
}
}
}
use of org.mycore.datamodel.ifs.MCRFile in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method newByteChannel.
/* (non-Javadoc)
* @see java.nio.file.spi.FileSystemProvider#newByteChannel(java.nio.file.Path, java.util.Set, java.nio.file.attribute.FileAttribute[])
*/
@Override
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
if (attrs.length > 0) {
throw new UnsupportedOperationException("Atomically setting of file attributes is not supported.");
}
MCRPath ifsPath = MCRFileSystemUtils.checkPathAbsolute(path);
Set<? extends OpenOption> fileOpenOptions = options.stream().filter(option -> !(option == StandardOpenOption.CREATE || option == StandardOpenOption.CREATE_NEW)).collect(Collectors.toSet());
boolean create = options.contains(StandardOpenOption.CREATE);
boolean createNew = options.contains(StandardOpenOption.CREATE_NEW);
if (create || createNew) {
for (OpenOption option : fileOpenOptions) {
// check before we create any file instance
MCRFile.checkOpenOption(option);
}
}
MCRFile mcrFile = MCRFileSystemUtils.getMCRFile(ifsPath, create, createNew);
if (mcrFile == null) {
throw new NoSuchFileException(path.toString());
}
return mcrFile.getFileChannel(fileOpenOptions);
}
use of org.mycore.datamodel.ifs.MCRFile in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method createDirectory.
/* (non-Javadoc)
* @see java.nio.file.spi.FileSystemProvider#createDirectory(java.nio.file.Path, java.nio.file.attribute.FileAttribute[])
*/
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
if (attrs.length > 0) {
throw new UnsupportedOperationException("Setting 'attrs' atomically is unsupported.");
}
MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
MCRDirectory rootDirectory;
if (mcrPath.isAbsolute() && mcrPath.getNameCount() == 0) {
rootDirectory = MCRDirectory.getDirectory(mcrPath.getOwner());
if (rootDirectory != null) {
throw new FileAlreadyExistsException(mcrPath.toString());
}
rootDirectory = new MCRDirectory(mcrPath.getOwner());
return;
}
rootDirectory = getRootDirectory(mcrPath);
MCRPath parentPath = mcrPath.getParent();
MCRPath absolutePath = getAbsolutePathFromRootComponent(parentPath);
MCRFilesystemNode childByPath = rootDirectory.getChildByPath(absolutePath.toString());
if (childByPath == null) {
throw new NoSuchFileException(parentPath.toString(), dir.getFileName().toString(), "parent directory does not exist");
}
if (childByPath instanceof MCRFile) {
throw new NotDirectoryException(parentPath.toString());
}
MCRDirectory parentDir = (MCRDirectory) childByPath;
String dirName = mcrPath.getFileName().toString();
if (parentDir.getChild(dirName) != null) {
throw new FileAlreadyExistsException(mcrPath.toString());
}
new MCRDirectory(dirName, parentDir);
}
use of org.mycore.datamodel.ifs.MCRFile in project mycore by MyCoRe-Org.
the class MCRFileTypeDetector method probeContentType.
/* (non-Javadoc)
* @see java.nio.file.spi.FileTypeDetector#probeContentType(java.nio.file.Path)
*/
@Override
public String probeContentType(Path path) throws IOException {
LOGGER.debug(() -> "Probing content type of: " + path);
if (!(path.getFileSystem() instanceof MCRIFSFileSystem)) {
return null;
}
MCRFilesystemNode resolvePath = MCRFileSystemProvider.resolvePath(MCRPath.toMCRPath(path));
if (resolvePath == null) {
throw new NoSuchFileException(path.toString());
}
if (resolvePath instanceof MCRDirectory) {
throw new NoSuchFileException(path.toString());
}
MCRFile file = (MCRFile) resolvePath;
String mimeType = file.getContentType().getMimeType();
LOGGER.debug(() -> "IFS mime-type: " + mimeType);
if (defaultMimeType.equals(mimeType)) {
Path dummy = Paths.get(path.getFileName().toString());
String dummyType = Files.probeContentType(dummy);
if (dummyType != null) {
LOGGER.debug(() -> "System mime-type #1: " + dummyType);
return dummyType;
}
String systemMimeType = Files.probeContentType(file.getLocalFile().toPath());
if (systemMimeType != null) {
LOGGER.debug(() -> "System mime-type #2: " + systemMimeType);
return systemMimeType;
}
}
return mimeType;
}
use of org.mycore.datamodel.ifs.MCRFile in project mycore by MyCoRe-Org.
the class MCRHIBFileMetadataStore method storeNode.
@Override
public void storeNode(MCRFilesystemNode node) throws MCRPersistenceException {
String ID = node.getID();
String PID = node.getParentID();
String OWNER = node.getOwnerID();
String NAME = node.getName();
String LABEL = node.getLabel();
long SIZE = node.getSize();
GregorianCalendar DATE = node.getLastModified();
String TYPE = null;
String STOREID = null;
String STORAGEID = null;
String FCTID = null;
String MD5 = null;
int NUMCHDD = 0;
int NUMCHDF = 0;
int NUMCHTD = 0;
int NUMCHTF = 0;
if (node instanceof MCRFile) {
MCRFile file = (MCRFile) node;
TYPE = "F";
STOREID = file.getStoreID();
STORAGEID = file.getStorageID();
FCTID = file.getContentTypeID();
MD5 = file.getMD5();
} else if (node instanceof MCRDirectory) {
MCRDirectory dir = (MCRDirectory) node;
TYPE = "D";
NUMCHDD = dir.getNumChildren(MCRDirectory.DIRECTORIES, MCRDirectory.HERE);
NUMCHDF = dir.getNumChildren(MCRDirectory.FILES, MCRDirectory.HERE);
NUMCHTD = dir.getNumChildren(MCRDirectory.DIRECTORIES, MCRDirectory.TOTAL);
NUMCHTF = dir.getNumChildren(MCRDirectory.FILES, MCRDirectory.TOTAL);
} else {
throw new MCRPersistenceException("MCRFilesystemNode must be either MCRFile or MCRDirectory");
}
Session session = getSession();
MCRFSNODES fs = session.get(MCRFSNODES.class, ID);
if (fs == null) {
fs = new MCRFSNODES();
fs.setId(ID);
}
fs.setPid(PID);
fs.setType(TYPE);
fs.setOwner(OWNER);
fs.setName(NAME);
fs.setLabel(LABEL);
fs.setSize(SIZE);
fs.setDate(new Timestamp(DATE.getTime().getTime()));
fs.setStoreid(STOREID);
fs.setStorageid(STORAGEID);
fs.setFctid(FCTID);
fs.setMd5(MD5);
fs.setNumchdd(NUMCHDD);
fs.setNumchdf(NUMCHDF);
fs.setNumchtd(NUMCHTD);
fs.setNumchtf(NUMCHTF);
if (!session.contains(fs)) {
session.saveOrUpdate(fs);
}
}
Aggregations