use of org.mycore.access.MCRAccessException 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.access.MCRAccessException in project mycore by MyCoRe-Org.
the class MCRSwordContainerHandler method deleteObject.
public void deleteObject(MCRObject object) throws SwordServerException {
try {
object.getStructure().getDerivates().stream().map(MCRMetaLinkID::getXLinkHrefID).forEach(id -> {
try {
MCRMetadataManager.deleteMCRDerivate(id);
} catch (Exception e) {
throw new MCRException(e);
}
});
MCRMetadataManager.delete(object);
} catch (MCRActiveLinkException | MCRAccessException | MCRException e) {
Throwable ex = e;
if (e instanceof MCRException && Optional.ofNullable(e.getCause()).map(Object::getClass).filter(MCRAccessException.class::isAssignableFrom).isPresent()) {
// unwrapp
ex = e.getCause();
}
throw new SwordServerException("Error while deleting Object.", ex);
}
}
use of org.mycore.access.MCRAccessException in project mycore by MyCoRe-Org.
the class MCRPackerServlet method doGetPost.
@Override
protected void doGetPost(MCRServletJob job) throws IOException {
String packer = job.getRequest().getParameter("packer");
if (packer == null || packer.isEmpty()) {
try {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "No or invalid 'packer' parameter!");
} catch (IOException e) {
LOGGER.error("Error while sending request error to client!", e);
return;
}
}
Map<String, String> jobParameters = resolveJobParameters(job);
try {
MCRJob mcrJob = MCRPackerManager.startPacking(jobParameters);
if (mcrJob == null) {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "No packer parameter!");
}
} catch (MCRAccessException e) {
job.getResponse().sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
} catch (MCRUsageException e) {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Parameters: " + e.getMessage());
}
if (jobParameters.containsKey("redirect")) {
String redirect = jobParameters.get("redirect");
job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(redirect));
}
}
use of org.mycore.access.MCRAccessException in project mycore by MyCoRe-Org.
the class MCRMetadataManager method update.
/**
* Updates the derivate or creates it if it does not exist yet.
*
* @throws MCRPersistenceException
* if a persistence problem is occurred
* @throws MCRAccessException
* if write permission to object or derivate is missing
*/
public static void update(final MCRDerivate mcrDerivate) throws MCRPersistenceException, MCRAccessException {
MCRObjectID id = mcrDerivate.getId();
// check deletion mark
if (MCRMarkManager.instance().isMarkedForDeletion(id)) {
return;
}
if (!MCRMetadataManager.exists(id)) {
MCRMetadataManager.create(mcrDerivate);
return;
}
if (!MCRAccessManager.checkPermission(id, PERMISSION_WRITE)) {
throw MCRAccessException.missingPermission("Update derivate", id.toString(), PERMISSION_WRITE);
}
File fileSourceDirectory = null;
if (mcrDerivate.getDerivate().getInternals() != null && mcrDerivate.getDerivate().getInternals().getSourcePath() != null) {
fileSourceDirectory = new File(mcrDerivate.getDerivate().getInternals().getSourcePath());
if (!fileSourceDirectory.exists()) {
LOGGER.warn("{}: the directory {} was not found.", id, fileSourceDirectory);
fileSourceDirectory = null;
}
}
// get the old Item
MCRDerivate old = MCRMetadataManager.retrieveMCRDerivate(id);
// remove the old link to metadata
MCRMetaLinkID oldLink = old.getDerivate().getMetaLink();
MCRMetaLinkID newLink = mcrDerivate.getDerivate().getMetaLink();
if (!oldLink.equals(newLink)) {
MCRObjectID oldMetadataObjectID = oldLink.getXLinkHrefID();
MCRObjectID newMetadataObjectID = newLink.getXLinkHrefID();
if (!oldMetadataObjectID.equals(newLink.getXLinkHrefID())) {
try {
MCRMetadataManager.removeDerivateFromObject(oldMetadataObjectID, id);
} catch (final MCRException e) {
LOGGER.warn(e.getMessage(), e);
}
}
// add the link to metadata
final MCRMetaLinkID der = new MCRMetaLinkID("derobject", id, null, mcrDerivate.getLabel(), newLink.getXLinkRole());
addOrUpdateDerivateToObject(newMetadataObjectID, der);
}
// update the derivate
mcrDerivate.getService().setDate("createdate", old.getService().getDate("createdate"));
if (!mcrDerivate.getService().isFlagTypeSet(MCRObjectService.FLAG_TYPE_CREATEDBY)) {
for (String flagCreatedBy : old.getService().getFlags(MCRObjectService.FLAG_TYPE_CREATEDBY)) {
mcrDerivate.getService().addFlag(MCRObjectService.FLAG_TYPE_CREATEDBY, flagCreatedBy);
}
}
MCRMetadataManager.updateMCRDerivateXML(mcrDerivate);
// update to IFS
if (fileSourceDirectory != null) {
Path sourcePath = fileSourceDirectory.toPath();
MCRPath targetPath = MCRPath.getPath(id.toString(), "/");
try {
Files.walkFileTree(sourcePath, new MCRTreeCopier(sourcePath, targetPath));
} catch (Exception exc) {
throw new MCRPersistenceException("Unable to update IFS. Copy failed from " + sourcePath.toAbsolutePath() + " to target " + targetPath.toAbsolutePath(), exc);
}
}
}
use of org.mycore.access.MCRAccessException in project mycore by MyCoRe-Org.
the class MCRRoleResolver method resolve.
/* (non-Javadoc)
* @see javax.xml.transform.URIResolver#resolve(java.lang.String, java.lang.String)
*/
@Override
public Source resolve(final String href, final String base) throws TransformerException {
final String target = href.substring(href.indexOf(":") + 1);
final String[] part = target.split(":");
final String method = part[0];
try {
if ("getAssignableGroupsForUser".equals(method)) {
return new JDOMSource(getAssignableGroupsForUser());
}
} catch (final MCRAccessException exc) {
throw new TransformerException(exc);
}
throw new TransformerException(new IllegalArgumentException("Unknown method " + method + " in uri " + href));
}
Aggregations