use of annis.service.objects.AnnisBinaryMetaData in project ANNIS by korpling.
the class VideoVisualizer method createComponent.
@Override
public MediaElementPlayer createComponent(VisualizerInput input, VisualizationToggle visToggle) {
List<String> corpusPath = CommonHelper.getCorpusPath(input.getDocument().getGraph(), input.getDocument());
String binaryServletPath = "";
String corpusName = corpusPath.get(corpusPath.size() - 1);
String documentName = corpusPath.get(0);
corpusName = urlPathEscape.escape(corpusName);
documentName = urlPathEscape.escape(documentName);
WebResource resMeta = Helper.getAnnisWebResource().path("meta/binary").path(corpusName).path(documentName);
List<AnnisBinaryMetaData> meta = resMeta.get(new GenericType<List<AnnisBinaryMetaData>>() {
});
// if there is no document at all don't fail
String mimeType = meta.size() > 0 ? null : "video/webm";
for (AnnisBinaryMetaData m : meta) {
if (m.getMimeType().startsWith("video/")) {
mimeType = m.getMimeType();
break;
}
}
Validate.notNull(mimeType, "There must be at least one binary file for the document with a video mime type");
String mimeTypeEncoded = mimeType;
mimeTypeEncoded = urlParamEscape.escape(mimeType);
binaryServletPath = input.getContextPath() + "/Binary?" + "documentName=" + documentName + "&toplevelCorpusName=" + corpusName + "&mime=" + mimeTypeEncoded;
MediaElementPlayer player = new MediaElementPlayer(MediaElement.video, binaryServletPath, mimeType);
if (VaadinSession.getCurrent().getAttribute(MediaController.class) != null) {
VaadinSession.getCurrent().getAttribute(MediaController.class).addMediaPlayer(player, input.getId(), visToggle);
}
return player;
}
use of annis.service.objects.AnnisBinaryMetaData in project ANNIS by korpling.
the class AudioVisualizer method createComponent.
@Override
public MediaElementPlayer createComponent(VisualizerInput input, VisualizationToggle visToggle) {
List<String> corpusPath = CommonHelper.getCorpusPath(input.getDocument().getGraph(), input.getDocument());
String binaryServletPath = "";
String corpusName = corpusPath.get(corpusPath.size() - 1);
String documentName = corpusPath.get(0);
corpusName = urlPathEscape.escape(corpusName);
documentName = urlPathEscape.escape(documentName);
WebResource resMeta = Helper.getAnnisWebResource().path("meta/binary").path(corpusName).path(documentName);
List<AnnisBinaryMetaData> meta = resMeta.get(new GenericType<List<AnnisBinaryMetaData>>() {
});
// if there is no document at all don't fail
String mimeType = meta.size() > 0 ? null : "audio/ogg";
for (AnnisBinaryMetaData m : meta) {
if (m.getMimeType().startsWith("audio/")) {
mimeType = m.getMimeType();
break;
}
}
Validate.notNull(mimeType, "There must be at least one binary file for the document with a audio mime type");
String mimeTypeEncoded = mimeType;
mimeTypeEncoded = urlParamEscape.escape(mimeType);
binaryServletPath = input.getContextPath() + "/Binary?" + "documentName=" + documentName + "&toplevelCorpusName=" + corpusName + "&mime=" + mimeTypeEncoded;
MediaElementPlayer player = new MediaElementPlayer(MediaElement.audio, binaryServletPath, mimeType);
if (VaadinSession.getCurrent().getAttribute(MediaController.class) != null) {
VaadinSession.getCurrent().getAttribute(MediaController.class).addMediaPlayer(player, input.getId(), visToggle);
}
return player;
}
use of annis.service.objects.AnnisBinaryMetaData in project ANNIS by korpling.
the class MetaByteHelper method extractData.
@Override
public List<AnnisBinaryMetaData> extractData(ResultSet rs) throws DataAccessException {
List<AnnisBinaryMetaData> result = new LinkedList<>();
try {
while (rs.next()) {
AnnisBinaryMetaData ab = new AnnisBinaryMetaData();
ab.setLocalFileName(rs.getString("filename"));
ab.setFileName(rs.getString("title"));
ab.setCorpusName(rs.getString("corpus_name"));
ab.setMimeType(rs.getString("mime_type"));
result.add(ab);
}
} catch (SQLException ex) {
log.error(null, ex);
}
return result;
}
use of annis.service.objects.AnnisBinaryMetaData in project ANNIS by korpling.
the class QueryServiceImpl method binary.
/**
* Get an Annis Binary object identified by its id.
*
* @param id
* @param rawOffset the part we want to start from, we start from 0
* @param rawLength how many bytes we take
* @return AnnisBinary
*/
@Override
public Response binary(String toplevelCorpusName, String corpusName, String rawOffset, String rawLength, String fileName) {
Subject user = SecurityUtils.getSubject();
user.checkPermission("query:binary:" + toplevelCorpusName);
String acceptHeader = request.getHeader(HttpHeaders.ACCEPT);
if (acceptHeader == null || acceptHeader.trim().isEmpty()) {
acceptHeader = "*/*";
}
List<AnnisBinaryMetaData> meta = queryDao.getBinaryMeta(toplevelCorpusName, corpusName);
HashMap<String, AnnisBinaryMetaData> matchedMetaByType = new LinkedHashMap<>();
for (AnnisBinaryMetaData m : meta) {
if (fileName == null) {
// just add all available media types
if (!matchedMetaByType.containsKey(m.getMimeType())) {
matchedMetaByType.put(m.getMimeType(), m);
}
} else {
// check if this binary has the right title/file name
if (fileName.equals(m.getFileName())) {
matchedMetaByType.put(m.getMimeType(), m);
}
}
}
if (matchedMetaByType.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity("Requested binary not found").build();
}
// find the best matching mime type
String bestMediaTypeMatch = MIMEParse.bestMatch(matchedMetaByType.keySet(), acceptHeader);
if (bestMediaTypeMatch.isEmpty()) {
return Response.status(Response.Status.NOT_ACCEPTABLE).entity("Client must accept one of the following media types: " + StringUtils.join(matchedMetaByType.keySet(), ", ")).build();
}
MediaType mediaType = MediaType.valueOf(bestMediaTypeMatch);
int offset = 0;
int length = 0;
if (rawLength == null || rawOffset == null) {
// use matched binary meta data to get the complete file size
AnnisBinaryMetaData matchedBinary = matchedMetaByType.get(mediaType.toString());
if (matchedBinary != null) {
length = matchedBinary.getLength();
}
} else {
// use the provided information
offset = Integer.parseInt(rawOffset);
length = Integer.parseInt(rawLength);
}
log.debug("fetching " + (length / 1024) + "kb (" + offset + "-" + (offset + length) + ") from binary " + toplevelCorpusName + "/" + corpusName + (fileName == null ? "" : fileName) + " " + mediaType.toString());
final InputStream stream = queryDao.getBinary(toplevelCorpusName, corpusName, mediaType.toString(), fileName, offset, length);
log.debug("fetch successfully");
StreamingOutput result = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
try {
ByteStreams.copy(stream, output);
output.close();
} finally {
stream.close();
}
}
};
return Response.ok(result, mediaType).build();
}
use of annis.service.objects.AnnisBinaryMetaData in project ANNIS by korpling.
the class QueryDaoImpl method getBinaryComplete.
@Override
public InputStream getBinaryComplete(String toplevelCorpusName, String mimeType, String title) {
List<AnnisBinaryMetaData> binaryMetas = getBinaryMeta(toplevelCorpusName);
InputStream input = null;
if (binaryMetas != null) {
for (AnnisBinaryMetaData metaData : binaryMetas) {
if (mimeType.equals(metaData.getMimeType()) && title.equals(metaData.getFileName())) {
String filePath = getRealDataDir().getPath() + "/" + metaData.getLocalFileName();
try {
input = new FileInputStream(filePath);
return input;
} catch (FileNotFoundException ex) {
log.error("could not found binary file {}", filePath, ex);
}
}
}
}
return input;
}
Aggregations