/** * Builds a list with with right content types and media urls assigned of a specific Object * * @param obj the object * @return a list of entrys Media-Type, URL */ public List<Map.Entry<String, URI>> getMediaList(MCRObject obj) { List<Map.Entry<String, URI>> entryList = new ArrayList<>(); Optional<MCRObjectID> derivateIdOptional = MCRMetadataManager.getDerivateIds(obj.getId(), 1, TimeUnit.MINUTES) .stream().findFirst(); derivateIdOptional.ifPresent(derivateId -> { MCRDerivate derivate = MCRMetadataManager.retrieveMCRDerivate(derivateId); String mainDoc = derivate.getDerivate().getInternals().getMainDoc(); MCRPath mainDocumentPath = MCRPath.getPath(derivateId.toString(), mainDoc); try { String contentType = Optional.ofNullable(MCRContentTypes.probeContentType(mainDocumentPath)) .orElse("application/octet-stream"); entryList.add(new AbstractMap.SimpleEntry<>(contentType, new URI(this.registerURL + MCRXMLFunctions .encodeURIPath("/servlets/MCRFileNodeServlet/" + derivateId + "/" + mainDoc)))); } catch (IOException | URISyntaxException e) { LOGGER.error("Error while detecting the file to register!", e); } }); return entryList; }
.map(d -> { String nameOfMainFile = MCRMetadataManager.retrieveMCRDerivate(d).getDerivate().getInternals() .getMainDoc(); return nameOfMainFile.isEmpty() ? null : MCRPath.getPath(d.toString(), '/' + nameOfMainFile); })
/** * @param derivateID * ID of derivate * @return empty String or absolute path to main file of derivate if file is supported. */ public static String getSupportedMainFile(String derivateID) { try { MCRDerivate deriv = MCRMetadataManager.retrieveMCRDerivate(MCRObjectID.getInstance(derivateID)); String nameOfMainFile = deriv.getDerivate().getInternals().getMainDoc(); // verify support if (nameOfMainFile != null && !nameOfMainFile.equals("")) { MCRPath mainFile = MCRPath.getPath(derivateID, '/' + nameOfMainFile); if (isFileSupported(mainFile)) { return mainFile.getRoot().relativize(mainFile).toString(); } } } catch (Exception e) { LOGGER.warn("Could not get main file of derivate.", e); } return ""; }
/** * returns the URL of the main document of a derivate * * @param info - the Jersey UriInfo object * @param mcrObjID - the MyCoRe Object ID * @param mcrDerID - the MyCoRe Derivate ID * * @return the Resolving URL for the main document of the derivate * @throws IOException */ public static String retrieveMaindocURL(UriInfo info, String mcrObjID, String mcrDerID, Application app) throws IOException { try { MCRObjectID mcrObj = MCRObjectID.getInstance(mcrObjID); MCRDerivate derObj = retrieveMCRDerivate(mcrObj, mcrDerID); String maindoc = derObj.getDerivate().getInternals().getMainDoc(); String baseURL = MCRJerseyUtil.getBaseURL(info, app) + MCRConfiguration.instance().getString("MCR.RestAPI.v1.Files.URL.path"); baseURL = baseURL.replace("${mcrid}", mcrObj.toString()).replace("${derid}", derObj.getId().toString()); return baseURL + maindoc; } catch (MCRRestAPIException rae) { return null; } }