Search in sources :

Example 16 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode 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;
}
Also used : MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Example 17 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode 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;
}
Also used : MCRPath(org.mycore.datamodel.niofs.MCRPath) Path(java.nio.file.Path) MCRFile(org.mycore.datamodel.ifs.MCRFile) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) NoSuchFileException(java.nio.file.NoSuchFileException)

Example 18 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.

the class MCROAIObjectManager method formatURI.

protected String formatURI(String uri, String id, String metadataPrefix) {
    MCRObjectID mcrID = MCRObjectID.isValid(id) ? MCRObjectID.getInstance(id) : null;
    boolean exists;
    String objectType;
    if (mcrID != null) {
        exists = MCRMetadataManager.exists(mcrID);
        objectType = mcrID.getTypeId();
    } else {
        MCRFilesystemNode node = MCRFilesystemNode.getNode(id);
        exists = node != null;
        objectType = "data_file";
    }
    return uri.replace("{id}", id).replace("{format}", metadataPrefix).replace("{objectType}", objectType).replace(":{flag}", !exists ? ":deletedMcrObject" : "");
}
Also used : MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 19 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.

the class MCRIFSCommands method deleteIFSNode.

@MCRCommand(syntax = "delete ifs node {0}", help = "deletes ifs node {0} recursivly")
public static void deleteIFSNode(String nodeID) {
    MCRFilesystemNode node = MCRFilesystemNode.getNode(nodeID);
    if (node == null) {
        LOGGER.warn("IFS Node {} does not exist.", nodeID);
        return;
    }
    LOGGER.info(MessageFormat.format("Deleting IFS Node {0}: {1}{2}", nodeID, node.getOwnerID(), node.getAbsolutePath()));
    node.delete();
}
Also used : MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Aggregations

MCRFilesystemNode (org.mycore.datamodel.ifs.MCRFilesystemNode)19 MCRDirectory (org.mycore.datamodel.ifs.MCRDirectory)12 MCRPath (org.mycore.datamodel.niofs.MCRPath)11 MCRFile (org.mycore.datamodel.ifs.MCRFile)10 NoSuchFileException (java.nio.file.NoSuchFileException)9 IOException (java.io.IOException)5 NotDirectoryException (java.nio.file.NotDirectoryException)5 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)2 Path (java.nio.file.Path)2 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 CopyOption (java.nio.file.CopyOption)1 InvalidPathException (java.nio.file.InvalidPathException)1 LinkOption (java.nio.file.LinkOption)1