use of org.mycore.datamodel.ifs.MCRDirectory in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method newDirectoryStream.
/* (non-Javadoc)
* @see java.nio.file.spi.FileSystemProvider#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter)
*/
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
MCRFilesystemNode node = resolvePath(mcrPath);
if (node instanceof MCRDirectory) {
return new MCRDirectoryStream((MCRDirectory) node, mcrPath);
}
throw new NotDirectoryException(dir.toString());
}
use of org.mycore.datamodel.ifs.MCRDirectory 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.MCRDirectory in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method doResolvePath.
private static MCRFilesystemNode doResolvePath(MCRPath path) throws IOException {
if (path.getNameCount() == 0) {
// root components
MCRDirectory rootDirectory = MCRDirectory.getRootDirectory(path.getOwner());
if (rootDirectory == null) {
throw new NoSuchFileException(path.toString());
}
// prepare cache
rootDirectory.getChildren();
return rootDirectory;
}
MCRDirectory parent = getParentDirectory(path);
MCRFilesystemNode child;
try {
child = parent.getChild(path.getFileName().toString());
} catch (RuntimeException e) {
throw new IOException(e);
}
if (child == null) {
throw new NoSuchFileException(parent.toPath().toString(), path.toString(), null);
}
return child;
}
use of org.mycore.datamodel.ifs.MCRDirectory 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.MCRDirectory 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