Search in sources :

Example 6 with NxtException

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;
}
Also used : JSONObject(org.json.simple.JSONObject) Work(org.xel.Work) JSONArray(org.json.simple.JSONArray) BigInteger(java.math.BigInteger) NxtException(org.xel.NxtException)

Aggregations

NxtException (org.xel.NxtException)6 JSONObject (org.json.simple.JSONObject)5 JSONStreamAware (org.json.simple.JSONStreamAware)3 IOException (java.io.IOException)2 JSONArray (org.json.simple.JSONArray)2 Work (org.xel.Work)2 Writer (java.io.Writer)1 BigInteger (java.math.BigInteger)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Appendix (org.xel.Appendix)1 Attachment (org.xel.Attachment)1 Block (org.xel.Block)1 Blockchain (org.xel.Blockchain)1 Nxt (org.xel.Nxt)1 TaggedData (org.xel.TaggedData)1 CommandCancelWork (org.xel.computation.CommandCancelWork)1 CommandPowBty (org.xel.computation.CommandPowBty)1 Filter (org.xel.util.Filter)1