use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRIFSFileSystem method removeRoot.
@Override
public void removeRoot(String owner) throws FileSystemException {
MCRPath rootPath = getPath(owner, "", this);
MCRDirectory rootDirectory = MCRDirectory.getRootDirectory(owner);
if (rootDirectory == null) {
throw new NoSuchFileException(rootPath.toString());
}
if (rootDirectory.isDeleted()) {
return;
}
if (rootDirectory.hasChildren()) {
throw new DirectoryNotEmptyException(rootPath.toString());
}
try {
rootDirectory.delete();
} catch (RuntimeException e) {
LogManager.getLogger(getClass()).warn("Catched run time exception while removing root directory.", e);
throw new FileSystemException(rootPath.toString(), null, e.getMessage());
}
LogManager.getLogger(getClass()).info("Removed root directory: {}", rootPath);
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRDirectory method delete.
/**
* Deletes this directory and its content stored in the system
*/
@Override
public void delete() throws MCRPersistenceException {
ensureNotDeleted();
Stream.of(getChildren()).forEach(MCRFilesystemNode::delete);
BasicFileAttributes attrs = getBasicFileAttributes();
MCRPath path = toPath();
super.delete();
MCREvent evt = new MCREvent(MCREvent.PATH_TYPE, MCREvent.DELETE_EVENT);
evt.put(MCREvent.PATH_KEY, path);
evt.put(MCREvent.FILEATTR_KEY, attrs);
MCREventManager.instance().handleEvent(evt);
children = null;
numChildDirsHere = 0;
numChildDirsTotal = 0;
numChildFilesHere = 0;
numChildFilesTotal = 0;
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRDerivateContentTransformerServlet method getContent.
@Override
public MCRContent getContent(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String pathInfo = req.getPathInfo();
if (pathInfo.startsWith("/")) {
pathInfo = pathInfo.substring(1);
}
String[] pathTokens = pathInfo.split("/");
String derivate = pathTokens[0];
String path = pathInfo.substring(derivate.length());
LOGGER.debug("Derivate : {}", derivate);
LOGGER.debug("Path : {}", path);
MCRPath mcrPath = MCRPath.getPath(derivate, path);
MCRContent pc = new MCRPathContent(mcrPath);
FileTime lastModifiedTime = Files.getLastModifiedTime(mcrPath);
MCRFrontendUtil.writeCacheHeaders(resp, (long) CACHE_TIME, lastModifiedTime.toMillis(), true);
try {
return getLayoutService().getTransformedContent(req, resp, pc);
} catch (TransformerException | SAXException e) {
throw new IOException("could not transform content", e);
}
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRURNGranularOAIRegistrationService method registerURNsDerivate.
private MCRDNBURN registerURNsDerivate(MCRBase obj, String additional, MCRObjectDerivate derivate) throws MCRPersistentIdentifierException {
LOGGER.info("Add URNs to all files of {}", obj.getId());
Session session = MCRHIBConnection.instance().getSession();
Path path = MCRPath.getPath(obj.getId().toString(), "/");
MCRFileCollectingFileVisitor<Path> collectingFileVisitor = new MCRFileCollectingFileVisitor<>();
try {
Files.walkFileTree(path, collectingFileVisitor);
} catch (IOException e) {
throw new MCRPersistentIdentifierException("Could not walk derivate file tree!", e);
}
List<String> ignoreFileNamesList = getIgnoreFileList();
List<Predicate<String>> predicateList = ignoreFileNamesList.stream().map(Pattern::compile).map(Pattern::asPredicate).collect(Collectors.toList());
List<MCRPath> pathList = collectingFileVisitor.getPaths().stream().filter(file -> predicateList.stream().noneMatch(p -> p.test(file.toString().split(":")[1]))).map(p -> (MCRPath) p).sorted().collect(Collectors.toList());
MCRDNBURN newURN = getNewIdentifier(obj.getId(), additional);
String setID = obj.getId().getNumberAsString();
for (int pathListIndex = 0; pathListIndex < pathList.size(); pathListIndex++) {
MCRDNBURN subURN = newURN.toGranular(setID, pathListIndex + 1, pathList.size());
derivate.getOrCreateFileMetadata(pathList.get(pathListIndex), subURN.asString()).setUrn(subURN.asString());
MCRPI databaseEntry = new MCRPI(subURN.asString(), getType(), obj.getId().toString(), pathList.get(pathListIndex).getOwnerRelativePath(), this.getRegistrationServiceID(), null);
session.save(databaseEntry);
}
derivate.setURN(newURN.asString());
MCRPI databaseEntry = new MCRPI(newURN.asString(), getType(), obj.getId().toString(), "", this.getRegistrationServiceID(), new Date());
session.save(databaseEntry);
return newURN;
}
use of org.mycore.datamodel.niofs.MCRPath in project mycore by MyCoRe-Org.
the class MCRDefaultAltoChangeApplier method applyChange.
@Override
public void applyChange(MCRAltoChangeSet changeSet) {
String derivateID = changeSet.getDerivateID();
changeSet.getWordChanges().stream().forEach(change -> {
List<MCRAltoWordChange> list = fileChangeMap.computeIfAbsent(change.getFile(), (k) -> new ArrayList<>());
list.add(change);
});
fileChangeMap.keySet().forEach(file -> {
LOGGER.info("Open file {} to apply changes!", file);
MCRPath altoFilePath = MCRPath.getPath(derivateID, file);
if (!Files.exists(altoFilePath)) {
LOGGER.warn("Could not find file {} which was referenced by alto change!", altoFilePath);
throw new MCRException(new IOException("Alto-File " + altoFilePath + " does not exist"));
}
Document altoDocument = readALTO(altoFilePath);
List<MCRAltoWordChange> wordChangesInThisFile = fileChangeMap.get(file);
wordChangesInThisFile.stream().forEach(wordChange -> {
String xpath = String.format(Locale.ROOT, "//alto:String[number(@HPOS)=number('%d') and number(@VPOS)=number('%d')]", wordChange.getHpos(), wordChange.getVpos());
List<Element> wordToChange = XPathFactory.instance().compile(xpath, Filters.element(), null, MCRConstants.ALTO_NAMESPACE).evaluate(altoDocument);
if (wordToChange.size() != 1) {
LOGGER.warn("Found {} words to change.", wordToChange.size());
}
wordToChange.forEach(word -> {
word.setAttribute("CONTENT", wordChange.getTo());
word.setAttribute("WC", "1");
});
});
storeALTO(altoFilePath, altoDocument);
});
}
Aggregations