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;
}
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);
}
}
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);
}
}
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());
}
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);
}
Aggregations