Search in sources :

Example 1 with PostFileResponse

use of com.pogeyan.cmis.api.messages.PostFileResponse in project copper-cms by PogeyanOSS.

the class ObjectActor method getContent.

private PostFileResponse getContent(QueryGetRequest request) throws CmisObjectNotFoundException, CmisInvalidArgumentException, CmisRuntimeException {
    String permission = request.getUserObject().getPermission();
    if (!Helpers.checkingUserPremission(permission, "get")) {
        throw new CmisRuntimeException(request.getUserName() + " is not authorized to applyAcl.");
    }
    String objectId = request.getObjectId();
    String streamId = request.getParameter(QueryGetRequest.PARAM_STREAM_ID);
    boolean download = false;
    String downloadParam = request.getParameter(QueryGetRequest.PARAM_DOWNLOAD);
    if (downloadParam != null && downloadParam.length() > 0) {
        String downloadParamLower = downloadParam.trim().toLowerCase(Locale.ENGLISH);
        if ("attachment".equals(downloadParamLower)) {
            download = true;
        } else if ("inline".equals(downloadParamLower)) {
            download = false;
        } else {
            throw new CmisInvalidArgumentException("Invalid download parameter value!");
        }
    }
    BigInteger offset = request.getOffset();
    BigInteger length = request.getLength();
    ContentStream content = CmisObjectService.Impl.getContentStream(request.getRepositoryId(), objectId, streamId, offset, length);
    PostFileResponse fileResponse = new PostFileResponse();
    fileResponse.setDownload(download);
    fileResponse.setOffset(offset);
    fileResponse.setContent(content);
    if (Helpers.isPerfMode()) {
        MetricsInputs.get().getCounter("Count_Downloads_" + request.getObjectId()).inc();
    }
    return fileResponse;
/*
		 * if (content == null || content.getStream() == null) { throw new
		 * CmisRuntimeException("Content stream is null!"); }
		 * 
		 * String contentType = content.getMimeType(); if (contentType == null) {
		 * contentType = QueryGetRequest.MEDIATYPE_OCTETSTREAM; }
		 * 
		 * String contentFilename = content.getFileName(); if (contentFilename == null)
		 * { contentFilename = "content"; }
		 * 
		 * // send content InputStream in = content.getStream(); OutputStream out =
		 * null; try { out = new FileOutputStream(content.getFileName());
		 * IOUtils.copy(in, out, QueryGetRequest.BUFFER_SIZE); out.flush(); } catch
		 * (Exception e) { LOG.error("writeContent exception: {}, {}", e.getMessage(),
		 * ExceptionUtils.getStackTrace(e)); throw new
		 * IllegalArgumentException("Could not write content: " + e.getMessage(), e); }
		 * finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } return null;
		 */
}
Also used : ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisInvalidArgumentException(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException) BigInteger(java.math.BigInteger) PostFileResponse(com.pogeyan.cmis.api.messages.PostFileResponse)

Aggregations

PostFileResponse (com.pogeyan.cmis.api.messages.PostFileResponse)1 BigInteger (java.math.BigInteger)1 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)1 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)1 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)1