Search in sources :

Example 16 with MCRFile

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

the class MCRTransferPackage method getContent.

/**
 * Returns the content for this transfer package. You have to call {@link #build()}
 * before you can retrieve this data.
 *
 * @return a map where key = filename; value = MCRContent
 */
public Map<String, MCRContent> getContent() throws IOException {
    Map<String, MCRContent> content = new HashMap<>();
    // config
    content.put(IMPORT_CONFIG_FILENAME, new MCRJDOMContent(buildImportConfiguration()));
    // objects
    for (MCRObject object : this.objects) {
        String fileName = CONTENT_PATH + object.getId() + ".xml";
        Document xml = object.createXML();
        content.put(fileName, new MCRJDOMContent(xml));
    }
    // file containers
    for (MCRTransferPackageFileContainer fc : this.fileContainers) {
        // derivate
        MCRObjectID derivateId = fc.getDerivateId();
        MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derivateId);
        Document derivateXML = derivate.createXML();
        String folder = CONTENT_PATH + fc.getName();
        String derivateFileName = folder + "/" + fc.getName() + ".xml";
        content.put(derivateFileName, new MCRJDOMContent(derivateXML));
        // files of derivate
        for (MCRFile file : fc.getFiles()) {
            content.put(folder + file.getAbsolutePath(), file.getContent());
        }
    }
    // classifications
    for (String classId : this.classifications) {
        Document classification = MCRClassificationUtils.asDocument(classId);
        String path = CLASS_PATH + classId + ".xml";
        content.put(path, new MCRJDOMContent(classification));
    }
    return content;
}
Also used : MCRFile(org.mycore.datamodel.ifs.MCRFile) MCRObject(org.mycore.datamodel.metadata.MCRObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent)

Aggregations

MCRFile (org.mycore.datamodel.ifs.MCRFile)16 MCRDirectory (org.mycore.datamodel.ifs.MCRDirectory)11 MCRFilesystemNode (org.mycore.datamodel.ifs.MCRFilesystemNode)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)9 NoSuchFileException (java.nio.file.NoSuchFileException)7 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)5 NotDirectoryException (java.nio.file.NotDirectoryException)4 IOException (java.io.IOException)3 InvalidPathException (java.nio.file.InvalidPathException)3 Path (java.nio.file.Path)3 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)3 File (java.io.File)2 CopyOption (java.nio.file.CopyOption)2 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)2 LinkOption (java.nio.file.LinkOption)2 ProviderMismatchException (java.nio.file.ProviderMismatchException)2 StandardCopyOption (java.nio.file.StandardCopyOption)2 FileTime (java.nio.file.attribute.FileTime)2 HashMap (java.util.HashMap)2 CacheBuilder (com.google.common.cache.CacheBuilder)1