use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRMetsLock method isLocked.
/**
* Checks if a Derivate is locked
* @param derivateIdString the derivate id
* @return true if the derivate is locked
*/
public static synchronized boolean isLocked(String derivateIdString) {
MCRObjectID derivateId = MCRObjectID.getInstance(derivateIdString);
if (MCRMetsLock.metsAccessSessionTable.containsKey(derivateId)) {
String lastAccessID = MCRMetsLock.metsAccessSessionTable.get(derivateId);
MCRSession lastSession = MCRSessionMgr.getSession(lastAccessID);
LOGGER.debug(MessageFormat.format("{0} is locked : {1}", derivateIdString, lastSession != null));
return lastSession != null;
} else {
LOGGER.debug(MessageFormat.format("{0} is not locked", derivateIdString));
return false;
}
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRIView2Commands method forAllDerivatesOfObject.
private static List<String> forAllDerivatesOfObject(String objectID, String batchCommandSyntax) {
MCRObjectID mcrobjid;
try {
mcrobjid = MCRObjectID.getInstance(objectID);
} catch (Exception e) {
LOGGER.error("The object ID {} is wrong", objectID);
return null;
}
List<MCRObjectID> derivateIds = MCRMetadataManager.getDerivateIds(mcrobjid, 0, TimeUnit.MILLISECONDS);
if (derivateIds == null) {
LOGGER.error("Object does not exist: {}", mcrobjid);
}
ArrayList<String> cmds = new ArrayList<>(derivateIds.size());
for (MCRObjectID derId : derivateIds) {
cmds.add(MessageFormat.format(batchCommandSyntax, derId));
}
return cmds;
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRJWPlayerResource method getSources.
@GET
@Path("{derivateId}/{path: .+}/sources.json")
@Produces({ "application/javascript" })
public String getSources(@PathParam("derivateId") String derivateId, @PathParam("path") String path) throws URISyntaxException, IOException {
MCRObjectID derivate = MCRJerseyUtil.getID(derivateId);
MCRJerseyUtil.checkDerivateReadPermission(derivate);
try {
MCRMediaSourceProvider formatter = new MCRMediaSourceProvider(derivateId, path, Optional.ofNullable(request.getHeader("User-Agent")), () -> Arrays.stream(Optional.ofNullable(request.getQueryString()).orElse("").split("&")).filter(p -> !p.startsWith("callback=")).toArray(String[]::new));
return toJson(formatter.getSources());
} catch (NoSuchFileException e) {
LogManager.getLogger().warn("Could not find video file.", e);
throw new WebApplicationException(Status.NOT_FOUND);
}
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRThumbnailResource method getThumbnail.
private Response getThumbnail(String documentId, int size, String ext) {
List<MCRObjectID> derivateIds = MCRMetadataManager.getDerivateIds(MCRJerseyUtil.getID(documentId), 1, TimeUnit.MINUTES);
for (MCRObjectID derivateId : derivateIds) {
if (MCRAccessManager.checkPermissionForReadingDerivate(derivateId.toString())) {
String nameOfMainFile = MCRMetadataManager.retrieveMCRDerivate(derivateId).getDerivate().getInternals().getMainDoc();
if (nameOfMainFile != null && !nameOfMainFile.equals("")) {
MCRPath mainFile = MCRPath.getPath(derivateId.toString(), '/' + nameOfMainFile);
try {
String mimeType = Files.probeContentType(mainFile);
String generators = MCRConfiguration.instance().getString("MCR.Media.Thumbnail.Generators");
for (String generator : generators.split(",")) {
Class<MCRThumbnailGenerator> classObject = (Class<MCRThumbnailGenerator>) Class.forName(generator);
Constructor<MCRThumbnailGenerator> constructor = classObject.getConstructor();
MCRThumbnailGenerator thumbnailGenerator = constructor.newInstance();
if (thumbnailGenerator.matchesFileType(mimeType, mainFile)) {
FileTime lastModified = Files.getLastModifiedTime(mainFile);
Date lastModifiedDate = new Date(lastModified.toMillis());
Response.ResponseBuilder resp = request.evaluatePreconditions(lastModifiedDate);
if (resp == null) {
Optional<BufferedImage> thumbnail = thumbnailGenerator.getThumbnail(mainFile, size);
if (thumbnail.isPresent()) {
CacheControl cc = new CacheControl();
cc.setMaxAge((int) TimeUnit.DAYS.toSeconds(1));
String type = "image/png";
if ("jpg".equals(ext) || "jpeg".equals(ext)) {
type = "image/jpeg";
}
return Response.ok(thumbnail.get()).cacheControl(cc).lastModified(lastModifiedDate).type(type).build();
}
return Response.status(Response.Status.NOT_FOUND).build();
}
return resp.build();
}
}
} catch (IOException | ReflectiveOperationException e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
}
}
return Response.status(Response.Status.NOT_FOUND).build();
}
use of org.mycore.datamodel.metadata.MCRObjectID in project mycore by MyCoRe-Org.
the class MCRUpdateMetsOnDerivateChangeEventHandler method checkUpdateMets.
/**
* Checks if the mets.xml should be updated.
*
* @param evt the mcr event
* @param file the file which was changed
* @param attrs the file attributes
* @return true if the mets shoud be updated, otherwise false
*/
protected boolean checkUpdateMets(MCREvent evt, Path file, BasicFileAttributes attrs) {
// don't update if no MCRPath
if (!(file instanceof MCRPath)) {
return false;
}
// don't update if mets.xml is deleted
Path fileName = file.getFileName();
if (fileName != null && fileName.toString().equals(mets)) {
return false;
}
MCRPath mcrPath = MCRPath.toMCRPath(file);
String derivateId = mcrPath.getOwner();
// don't update if mets.xml does not exist
if (Files.notExists(MCRPath.getPath(derivateId, '/' + mets))) {
return false;
}
// don't update if derivate or mycore object is marked for deletion
MCRObjectID mcrDerivateId = MCRObjectID.getInstance(derivateId);
MCRDerivate mcrDerivate = MCRMetadataManager.retrieveMCRDerivate(mcrDerivateId);
return !MCRMarkManager.instance().isMarkedForDeletion(mcrDerivate);
}
Aggregations