use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRTransferPackageCommands method importTransferPackagesFromDirectory.
@MCRCommand(help = "Imports all transfer packages located in the directory {0}.", syntax = "import transfer packages from directory {0}")
public static List<String> importTransferPackagesFromDirectory(String directory) throws Exception {
Path dir = Paths.get(directory);
if (!(Files.exists(dir) || Files.isDirectory(dir))) {
throw new FileNotFoundException(directory + " does not exist or is not a directory.");
}
List<String> importStatements = new LinkedList<>();
try (Stream<Path> stream = Files.find(dir, 0, (path, attr) -> String.valueOf(path).endsWith(".tar") && Files.isRegularFile(path))) {
stream.map(Path::toAbsolutePath).map(Path::toString).forEach(path -> {
String subCommand = MessageFormat.format("import transfer package from tar {0}", path);
importStatements.add(subCommand);
});
}
return importStatements;
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRIView2Commands method deleteImageTiles.
/**
* Deletes all image tiles of this derivate.
* @param derivate derivate ID
* @param absoluteImagePath absolute path to image file
*/
@MCRCommand(syntax = "delete tiles of image {0} {1}", help = "removes tiles of a specific file identified by its derivate ID {0} and absolute path {1}", order = 110)
public static void deleteImageTiles(String derivate, String absoluteImagePath) throws IOException {
Path tileFile = MCRImage.getTiledFile(MCRIView2Tools.getTileDir(), derivate, absoluteImagePath);
deleteFileAndEmptyDirectories(tileFile);
int removed = MCRTilingQueue.getInstance().remove(derivate, absoluteImagePath);
LOGGER.info("removed tiles from {} images", removed);
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRIView2Commands method deleteAllTiles.
/**
* Deletes all image tiles.
*/
@MCRCommand(syntax = "delete all tiles", help = "removes all tiles of all derivates", order = 80)
public static void deleteAllTiles() throws IOException {
Path storeDir = MCRIView2Tools.getTileDir();
Files.walkFileTree(storeDir, MCRRecursiveDeleter.instance());
MCRTilingQueue.getInstance().clear();
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRIView2Commands method checkImage.
/**
* checks and repairs tile of this derivate.
* @param derivate derivate ID
* @param absoluteImagePath absolute path to image file
*/
@MCRCommand(syntax = CHECK_TILES_OF_IMAGE_COMMAND_SYNTAX, help = "checks if tiles a specific file identified by its derivate {0} and absolute path {1} are valid or generates new one", order = 30)
public static void checkImage(String derivate, String absoluteImagePath) throws IOException {
Path iviewFile = MCRImage.getTiledFile(MCRIView2Tools.getTileDir(), derivate, absoluteImagePath);
// file checks
if (!Files.exists(iviewFile)) {
LOGGER.warn("IView2 file does not exist: {}", iviewFile);
tileImage(derivate, absoluteImagePath);
return;
}
MCRTiledPictureProps props;
try {
props = MCRTiledPictureProps.getInstanceFromFile(iviewFile);
} catch (Exception e) {
LOGGER.warn("Error while reading image metadata. Recreating tiles.", e);
tileImage(derivate, absoluteImagePath);
return;
}
if (props == null) {
LOGGER.warn("Could not get tile metadata");
tileImage(derivate, absoluteImagePath);
return;
}
ZipFile iviewImage;
try {
iviewImage = new ZipFile(iviewFile.toFile());
validateZipFile(iviewImage);
} catch (Exception e) {
LOGGER.warn("Error while reading Iview2 file: {}", iviewFile, e);
tileImage(derivate, absoluteImagePath);
return;
}
try (FileSystem fs = MCRIView2Tools.getFileSystem(iviewFile)) {
Path iviewFileRoot = fs.getRootDirectories().iterator().next();
// structure and metadata checks
// one for metadata
int tilesCount = iviewImage.size() - 1;
if (props.getTilesCount() != tilesCount) {
LOGGER.warn("Metadata tile count does not match stored tile count: {}", iviewFile);
tileImage(derivate, absoluteImagePath);
return;
}
int x = props.getWidth();
int y = props.getHeight();
if (MCRImage.getTileCount(x, y) != tilesCount) {
LOGGER.warn("Calculated tile count does not match stored tile count: {}", iviewFile);
tileImage(derivate, absoluteImagePath);
return;
}
try {
ImageReader imageReader = MCRIView2Tools.getTileImageReader();
@SuppressWarnings("unused") BufferedImage thumbnail = MCRIView2Tools.getZoomLevel(iviewFileRoot, props, imageReader, 0);
int maxX = (int) Math.ceil((double) props.getWidth() / MCRImage.getTileSize());
int maxY = (int) Math.ceil((double) props.getHeight() / MCRImage.getTileSize());
LOGGER.debug(MessageFormat.format("Image size:{0}x{1}, tiles:{2}x{3}", props.getWidth(), props.getHeight(), maxX, maxY));
try {
@SuppressWarnings("unused") BufferedImage sampleTile = MCRIView2Tools.readTile(iviewFileRoot, imageReader, props.getZoomlevel(), maxX - 1, 0);
} finally {
imageReader.dispose();
}
} catch (IOException | JDOMException e) {
LOGGER.warn("Could not read thumbnail of {}", iviewFile, e);
tileImage(derivate, absoluteImagePath);
}
}
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRIFS2Commands method repairMcrdataXmlForDerivate.
@MCRCommand(syntax = "repair mcrdata.xml for derivate {0} in content store {1}", help = "repair the entries in mcrdata.xml with data from content store {1} for MCRDerivate {0}")
public static void repairMcrdataXmlForDerivate(String derivate_id, String content_store) {
LOGGER.info("Start repair of mcrdata.xml for derivate {} in store {}", derivate_id, content_store);
// check input;
MCRObjectID mcr_derivate_id;
try {
mcr_derivate_id = MCRObjectID.getInstance(derivate_id);
} catch (MCRException e) {
LOGGER.error("Wrong derivate parameter, it is not a MCRObjectID");
return;
}
if (content_store == null || content_store.length() == 0) {
LOGGER.error("Empty content store parameter");
return;
}
MCRContentStore store = MCRContentStoreFactory.getStore(content_store);
if (!(store instanceof MCRCStoreIFS2)) {
LOGGER.error("The content store is not a IFS2 type");
return;
}
// repair
try {
MCRFileCollection file_collection = ((MCRCStoreIFS2) store).getIFS2FileCollection(mcr_derivate_id);
file_collection.repairMetadata();
} catch (IOException e) {
LOGGER.error("Erroe while repair derivate with ID {}", mcr_derivate_id);
}
}
Aggregations