Search in sources :

Example 1 with TaggedData

use of org.xel.TaggedData in project elastic-core-maven by OrdinaryDude.

the class DownloadTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest request, HttpServletResponse response) throws NxtException {
    long transactionId = ParameterParser.getUnsignedLong(request, "transaction", true);
    boolean retrieve = "true".equalsIgnoreCase(request.getParameter("retrieve"));
    TaggedData taggedData = TaggedData.getData(transactionId);
    if (taggedData == null && retrieve) {
        if (Nxt.getBlockchainProcessor().restorePrunedTransaction(transactionId) == null) {
            return PRUNED_TRANSACTION;
        }
        taggedData = TaggedData.getData(transactionId);
    }
    if (taggedData == null) {
        return JSONResponses.incorrect("transaction", "Tagged data not found");
    }
    byte[] data = taggedData.getData();
    if (!taggedData.getType().equals("")) {
        response.setContentType(taggedData.getType());
    } else {
        response.setContentType("application/octet-stream");
    }
    String filename = taggedData.getFilename();
    if (filename == null || filename.trim().isEmpty()) {
        filename = taggedData.getName().trim();
    }
    String contentDisposition = "attachment";
    try {
        URI uri = new URI(null, null, filename, null);
        contentDisposition += "; filename*=UTF-8''" + uri.toASCIIString();
    } catch (URISyntaxException ignore) {
    }
    response.setHeader("Content-Disposition", contentDisposition);
    response.setContentLength(data.length);
    try (OutputStream out = response.getOutputStream()) {
        try {
            out.write(data);
        } catch (IOException e) {
            throw new ParameterException(JSONResponses.RESPONSE_WRITE_ERROR);
        }
    } catch (IOException e) {
        throw new ParameterException(JSONResponses.RESPONSE_STREAM_ERROR);
    }
    return null;
}
Also used : OutputStream(java.io.OutputStream) TaggedData(org.xel.TaggedData) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI)

Example 2 with TaggedData

use of org.xel.TaggedData in project elastic-core-maven by OrdinaryDude.

the class GetChannelTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    String channel = Convert.emptyToNull(req.getParameter("channel"));
    if (channel == null) {
        return JSONResponses.missing("channel");
    }
    long accountId = ParameterParser.getAccountId(req, "account", false);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    boolean includeData = "true".equalsIgnoreCase(req.getParameter("includeData"));
    JSONObject response = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    response.put("data", jsonArray);
    try (DbIterator<TaggedData> data = TaggedData.getData(channel, accountId, firstIndex, lastIndex)) {
        while (data.hasNext()) {
            jsonArray.add(JSONData.taggedData(data.next(), includeData));
        }
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) TaggedData(org.xel.TaggedData)

Example 3 with TaggedData

use of org.xel.TaggedData in project elastic-core-maven by OrdinaryDude.

the class ExtendTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    Account account = ParameterParser.getSenderAccount(req);
    long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
    TaggedData taggedData = TaggedData.getData(transactionId);
    if (taggedData == null) {
        Transaction transaction = Nxt.getBlockchain().getTransaction(transactionId);
        if (transaction == null || transaction.getType() != TransactionType.Data.TAGGED_DATA_UPLOAD) {
            return UNKNOWN_TRANSACTION;
        }
        Attachment.TaggedDataUpload taggedDataUpload = ParameterParser.getTaggedData(req);
        taggedData = new TaggedData(transaction, taggedDataUpload);
    }
    Attachment.TaggedDataExtend taggedDataExtend = new Attachment.TaggedDataExtend(taggedData);
    return createTransaction(req, account, taggedDataExtend);
}
Also used : Account(org.xel.Account) Transaction(org.xel.Transaction) Attachment(org.xel.Attachment) TaggedData(org.xel.TaggedData)

Example 4 with TaggedData

use of org.xel.TaggedData in project elastic-core-maven by OrdinaryDude.

the class GetTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long transactionId = ParameterParser.getUnsignedLong(req, "transaction", true);
    boolean includeData = !"false".equalsIgnoreCase(req.getParameter("includeData"));
    boolean retrieve = "true".equalsIgnoreCase(req.getParameter("retrieve"));
    TaggedData taggedData = TaggedData.getData(transactionId);
    if (taggedData == null && retrieve) {
        if (Nxt.getBlockchainProcessor().restorePrunedTransaction(transactionId) == null) {
            return PRUNED_TRANSACTION;
        }
        taggedData = TaggedData.getData(transactionId);
    }
    if (taggedData != null) {
        return JSONData.taggedData(taggedData, includeData);
    }
    return JSON.emptyJSON;
}
Also used : TaggedData(org.xel.TaggedData)

Example 5 with TaggedData

use of org.xel.TaggedData in project elastic-core-maven by OrdinaryDude.

the class GetAccountTaggedData method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
    long accountId = ParameterParser.getAccountId(req, "account", true);
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    boolean includeData = "true".equalsIgnoreCase(req.getParameter("includeData"));
    JSONObject response = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    response.put("data", jsonArray);
    try (DbIterator<TaggedData> data = TaggedData.getData(null, accountId, firstIndex, lastIndex)) {
        while (data.hasNext()) {
            jsonArray.add(JSONData.taggedData(data.next(), includeData));
        }
    }
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) TaggedData(org.xel.TaggedData)

Aggregations

TaggedData (org.xel.TaggedData)7 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Account (org.xel.Account)1 Attachment (org.xel.Attachment)1 Transaction (org.xel.Transaction)1