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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations