Search in sources :

Example 56 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRMetsMods2IIIFConverter method convert.

public MCRIIIFManifest convert() {
    MCRIIIFManifest manifest = new MCRIIIFManifest();
    // root chapter ^= manifest metadata
    LogicalStructMap logicalStructMap = (LogicalStructMap) mets.getStructMap("LOGICAL");
    LogicalDiv divContainer = logicalStructMap.getDivContainer();
    List<MCRIIIFMetadata> metadata = extractMedataFromLogicalDiv(mets, divContainer);
    manifest.metadata = metadata;
    manifest.setId(this.identifier);
    PhysicalStructMap physicalStructMap = (PhysicalStructMap) mets.getStructMap("PHYSICAL");
    PhysicalDiv physicalDivContainer = physicalStructMap.getDivContainer();
    String id = physicalDivContainer.getId();
    MCRIIIFSequence sequence = new MCRIIIFSequence(id);
    List<PhysicalSubDiv> children = physicalDivContainer.getChildren();
    MCRIIIFImageImpl imageImpl = MCRIIIFImageImpl.getInstance(getImageImplName());
    MCRIIIFImageProfile profile = imageImpl.getProfile();
    profile.setId(MCRIIIFImageUtil.getProfileLink(imageImpl));
    sequence.canvases = children.stream().map(physicalSubDiv -> {
        String order = physicalSubDiv.asElement().getAttributeValue("ORDER");
        String orderLabel = physicalSubDiv.getOrderLabel();
        String contentids = physicalSubDiv.getContentids();
        String label = Stream.of(order, orderLabel, contentids).filter(o -> o != null && !o.isEmpty()).collect(Collectors.joining(" - "));
        String identifier = this.physicalIdentifierMap.get(physicalSubDiv);
        try {
            MCRIIIFImageInformation information = imageImpl.getInformation(identifier);
            MCRIIIFCanvas canvas = new MCRIIIFCanvas(identifier, label, information.width, information.height);
            MCRIIIFAnnotation annotation = new MCRIIIFAnnotation(identifier, canvas);
            canvas.images.add(annotation);
            MCRIIIFResource resource = new MCRIIIFResource(information.getId(), MCRDCMIType.Image);
            resource.setWidth(information.width);
            resource.setHeight(information.height);
            MCRIIIFService service = new MCRIIIFService(information.getId(), profile.getContext());
            service.profile = MCRIIIFImageProfile.IIIF_PROFILE_2_0;
            resource.setService(service);
            annotation.setResource(resource);
            return canvas;
        } catch (MCRIIIFImageNotFoundException | MCRIIIFImageProvidingException e) {
            throw new MCRException("Error while providing ImageInfo for " + identifier, e);
        } catch (MCRAccessException e) {
            LOGGER.warn("User has no access to {}", identifier);
            return null;
        }
    }).filter(Objects::nonNull).collect(Collectors.toList());
    manifest.sequences.add(sequence);
    List<MCRIIIFRange> complete = new ArrayList<>();
    processDivContainer(complete, divContainer);
    manifest.structures.addAll(complete);
    manifest.setLabel(metadata.stream().filter(m -> m.getLabel().equals("title")).findFirst().get().getStringValue().get());
    return manifest;
}
Also used : PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRIIIFCanvas(org.mycore.iiif.presentation.model.basic.MCRIIIFCanvas) MCRIIIFImageUtil(org.mycore.iiif.image.MCRIIIFImageUtil) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) MCRConstants(org.mycore.common.MCRConstants) MCRIIIFImageProvidingException(org.mycore.iiif.image.impl.MCRIIIFImageProvidingException) MCRIIIFImageProfile(org.mycore.iiif.image.model.MCRIIIFImageProfile) HashMap(java.util.HashMap) MCRIIIFSequence(org.mycore.iiif.presentation.model.basic.MCRIIIFSequence) MCRException(org.mycore.common.MCRException) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) MCRIIIFService(org.mycore.iiif.presentation.model.attributes.MCRIIIFService) FileGrp(org.mycore.mets.model.files.FileGrp) Map(java.util.Map) MCRDCMIType(org.mycore.iiif.presentation.model.attributes.MCRDCMIType) MCRIIIFResource(org.mycore.iiif.presentation.model.attributes.MCRIIIFResource) MCRAccessException(org.mycore.access.MCRAccessException) File(org.mycore.mets.model.files.File) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) MCRIIIFAnnotation(org.mycore.iiif.presentation.model.additional.MCRIIIFAnnotation) MCRIIIFViewingHint(org.mycore.iiif.presentation.model.attributes.MCRIIIFViewingHint) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MCRIIIFManifest(org.mycore.iiif.presentation.model.basic.MCRIIIFManifest) Mets(org.mycore.mets.model.Mets) Collectors(java.util.stream.Collectors) MCRIIIFRange(org.mycore.iiif.presentation.model.basic.MCRIIIFRange) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MDTYPE(org.mycore.mets.model.struct.MDTYPE) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) DmdSec(org.mycore.mets.model.sections.DmdSec) MdWrap(org.mycore.mets.model.struct.MdWrap) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) MCRIIIFMetadata(org.mycore.iiif.presentation.model.attributes.MCRIIIFMetadata) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) ArrayList(java.util.ArrayList) MCRIIIFSequence(org.mycore.iiif.presentation.model.basic.MCRIIIFSequence) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv) MCRIIIFRange(org.mycore.iiif.presentation.model.basic.MCRIIIFRange) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MCRIIIFCanvas(org.mycore.iiif.presentation.model.basic.MCRIIIFCanvas) MCRIIIFMetadata(org.mycore.iiif.presentation.model.attributes.MCRIIIFMetadata) MCRIIIFService(org.mycore.iiif.presentation.model.attributes.MCRIIIFService) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) MCRException(org.mycore.common.MCRException) MCRIIIFManifest(org.mycore.iiif.presentation.model.basic.MCRIIIFManifest) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) MCRIIIFResource(org.mycore.iiif.presentation.model.attributes.MCRIIIFResource) MCRAccessException(org.mycore.access.MCRAccessException) PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRIIIFImageProfile(org.mycore.iiif.image.model.MCRIIIFImageProfile) MCRIIIFAnnotation(org.mycore.iiif.presentation.model.additional.MCRIIIFAnnotation) Objects(java.util.Objects)

Example 57 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRMETSDefaultGenerator method generate.

@Override
public Mets generate() throws MCRException {
    try {
        Mets mets = createMets();
        MCRDerivate owner = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(getOwner()));
        mets.getLogicalStructMap().getDivContainer().setLabel(MCRTranslation.exists("MCR.Mets.LogicalStructMap.Default.Label") ? MCRTranslation.translate("MCR.Mets.LogicalStructMap.Default.Label") : owner.getId().toString());
        Map<String, String> urnFileMap = owner.getUrnMap();
        if (urnFileMap.size() > 0) {
            try {
                MCRMetsSave.updateURNsInMetsDocument(mets, urnFileMap);
            } catch (Exception e) {
                LOGGER.error("error while adding urnĀ“s to new Mets file", e);
            }
        }
        return mets;
    } catch (Exception ioExc) {
        throw new MCRException("Unable to create mets.xml of " + getOwner(), ioExc);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate) URISyntaxException(java.net.URISyntaxException) MCRException(org.mycore.common.MCRException) IOException(java.io.IOException)

Example 58 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRMETSHierarchyGenerator method generate.

@Override
public synchronized Mets generate() throws MCRException {
    long startTime = System.currentTimeMillis();
    String derivateId = getOwner();
    setup(derivateId);
    try {
        Mets mets = createMets();
        LOGGER.info("mets creation for derivate {} took {}ms!", derivateId, System.currentTimeMillis() - startTime);
        return mets;
    } catch (Exception exc) {
        throw new MCRException("Unable to create mets.xml of " + derivateId, exc);
    }
}
Also used : MCRException(org.mycore.common.MCRException) URISyntaxException(java.net.URISyntaxException) MCRException(org.mycore.common.MCRException) IOException(java.io.IOException)

Example 59 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRIView2Commands method forAllImages.

private static List<String> forAllImages(String derivateID, String batchCommandSyntax) throws IOException {
    if (!MCRIView2Tools.isDerivateSupported(derivateID)) {
        LOGGER.info("Skipping tiling of derivate {} as it's main file is not supported by IView2.", derivateID);
        return null;
    }
    MCRPath derivateRoot = MCRPath.getPath(derivateID, "/");
    if (!Files.exists(derivateRoot)) {
        throw new MCRException("Derivate " + derivateID + " does not exist or is not a directory!");
    }
    List<MCRPath> supportedFiles = getSupportedFiles(derivateRoot);
    return supportedFiles.stream().map(image -> MessageFormat.format(batchCommandSyntax, derivateID, image.getOwnerRelativePath())).collect(Collectors.toList());
}
Also used : MCRIView2Tools(org.mycore.iview2.services.MCRIView2Tools) Enumeration(java.util.Enumeration) TypedQuery(javax.persistence.TypedQuery) MCRException(org.mycore.common.MCRException) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) MCRRecursiveDeleter(org.mycore.datamodel.niofs.utils.MCRRecursiveDeleter) DirectoryStream(java.nio.file.DirectoryStream) JDOMException(org.jdom2.JDOMException) MCRImage(org.mycore.imagetiler.MCRImage) MCRTileJob(org.mycore.iview2.services.MCRTileJob) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) MCRTiledPictureProps(org.mycore.imagetiler.MCRTiledPictureProps) ZipFile(java.util.zip.ZipFile) MCRCommandGroup(org.mycore.frontend.cli.annotation.MCRCommandGroup) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) MCRMetadataManager(org.mycore.datamodel.metadata.MCRMetadataManager) MCRTilingQueue(org.mycore.iview2.services.MCRTilingQueue) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage) Files(java.nio.file.Files) MCRAbstractCommands(org.mycore.frontend.cli.MCRAbstractCommands) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRImageTiler(org.mycore.iview2.services.MCRImageTiler) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) FileSystem(java.nio.file.FileSystem) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) MCREntityManagerProvider(org.mycore.backend.jpa.MCREntityManagerProvider) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Logger(org.apache.logging.log4j.Logger) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) CRC32(java.util.zip.CRC32) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) MCRException(org.mycore.common.MCRException) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 60 with MCRException

use of org.mycore.common.MCRException in project mycore by MyCoRe-Org.

the class MCRUserCommands method initSuperuser.

/**
 * This method initializes the user and role system an creates a superuser with values set in
 * mycore.properties.private As 'super' default, if no properties were set, mcradmin with password mycore will be
 * used.
 */
@MCRCommand(syntax = "init superuser", help = "Initializes the user system. This command runs only if the user database does not exist.", order = 30)
public static List<String> initSuperuser() {
    final String suser = CONFIG.getString("MCR.Users.Superuser.UserName");
    final String spasswd = CONFIG.getString("MCR.Users.Superuser.UserPasswd");
    final String srole = CONFIG.getString("MCR.Users.Superuser.GroupName");
    if (MCRUserManager.exists(suser)) {
        LOGGER.error("The superuser already exists!");
        return null;
    }
    // the superuser role
    try {
        Set<MCRLabel> labels = new HashSet<>();
        labels.add(new MCRLabel("en", "The superuser role", null));
        MCRRole mcrRole = new MCRRole(srole, labels);
        MCRRoleManager.addRole(mcrRole);
    } catch (Exception e) {
        throw new MCRException("Can't create the superuser role.", e);
    }
    LOGGER.info("The role {} is installed.", srole);
    // the superuser
    try {
        MCRUser mcrUser = new MCRUser(suser);
        mcrUser.setRealName("Superuser");
        mcrUser.assignRole(srole);
        MCRUserManager.updatePasswordHashToSHA256(mcrUser, spasswd);
        MCRUserManager.createUser(mcrUser);
    } catch (Exception e) {
        throw new MCRException("Can't create the superuser.", e);
    }
    LOGGER.info(MessageFormat.format("The user {0} with password {1} is installed.", suser, spasswd));
    return Collections.singletonList("change to user " + suser + " with " + spasswd);
}
Also used : MCRException(org.mycore.common.MCRException) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) MCRException(org.mycore.common.MCRException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXParseException(org.xml.sax.SAXParseException) HashSet(java.util.HashSet) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Aggregations

MCRException (org.mycore.common.MCRException)131 IOException (java.io.IOException)39 Element (org.jdom2.Element)26 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)19 Document (org.jdom2.Document)18 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)18 File (java.io.File)15 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)12 MCRObject (org.mycore.datamodel.metadata.MCRObject)12 ArrayList (java.util.ArrayList)11 JDOMException (org.jdom2.JDOMException)11 MCRAccessException (org.mycore.access.MCRAccessException)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 SAXException (org.xml.sax.SAXException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 List (java.util.List)7 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)7 SAXParseException (org.xml.sax.SAXParseException)7 URI (java.net.URI)6 Path (java.nio.file.Path)6