use of org.xel.NxtException in project elastic-core-maven by OrdinaryDude.
the class GetWork method processRequest.
@Override
protected JSONStreamAware processRequest(final HttpServletRequest req) throws NxtException {
long just_account;
try {
final String readParam = ParameterParser.getParameterMultipart(req, "account");
final BigInteger b = new BigInteger(readParam);
just_account = b.longValue();
} catch (final Exception e) {
just_account = 0;
}
long wid_filter;
try {
final String readParam = ParameterParser.getParameterMultipart(req, "work_id");
final BigInteger b = new BigInteger(readParam);
wid_filter = b.longValue();
} catch (final Exception e) {
wid_filter = 0;
}
long storage_slot = -1;
try {
final String readParam = ParameterParser.getParameterMultipart(req, "storage_id");
final BigInteger b = new BigInteger(readParam);
storage_slot = b.longValue();
} catch (final Exception e) {
storage_slot = -1;
}
boolean include_finished = false;
try {
final String readParam = ParameterParser.getParameterMultipart(req, "with_finished");
final BigInteger b = new BigInteger(readParam);
int res = b.intValue();
if (res != 0) {
include_finished = true;
}
} catch (final Exception e) {
include_finished = false;
}
boolean with_source = false;
try {
final String readParam = ParameterParser.getParameterMultipart(req, "with_source");
final BigInteger b = new BigInteger(readParam);
int res = b.intValue();
if (res != 0) {
with_source = true;
}
} catch (final Exception e) {
with_source = false;
}
final int firstIndex = ParameterParser.getFirstIndex(req);
final int lastIndex = ParameterParser.getLastIndex(req);
final List<Work> work = Work.getWork(just_account, include_finished, firstIndex, lastIndex, wid_filter);
JSONArray work_packages = null;
if (wid_filter == 0) {
JSONArray jsonArray = new JSONArray();
for (Work work1 : work) {
JSONObject jsonObject = Work.toJson(work1);
jsonArray.add(jsonObject);
}
work_packages = jsonArray;
} else {
{
int finalStorage_slot = (int) storage_slot;
boolean finalWith_source1 = with_source;
JSONArray jsonArray = new JSONArray();
for (Work work1 : work) {
int gostor = finalStorage_slot;
if (storage_slot == -1 && work1.getStorage_size() > 0) {
gostor = ThreadLocalRandom.current().nextInt(0, work1.getStorage_size());
}
JSONObject jsonObject = Work.toJsonWithStorage(work1, gostor, finalWith_source1);
jsonArray.add(jsonObject);
}
work_packages = jsonArray;
}
}
final JSONObject response = new JSONObject();
response.put("work_packages", work_packages);
return response;
}
Aggregations