Search in sources :

Example 76 with JSONArray

use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.

the class PipelineActivityStatePreloader method getFetchData.

@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
    BluePipeline pipeline = getPipeline(blueUrl);
    if (pipeline != null) {
        // It's a pipeline page. Let's prefetch the pipeline activity and add them to the page,
        // saving the frontend the overhead of requesting them.
        Container<BlueRun> activitiesContainer = pipeline.getRuns();
        if (activitiesContainer == null) {
            return null;
        }
        Iterator<BlueRun> activitiesIterator = activitiesContainer.iterator(0, DEFAULT_LIMIT);
        JSONArray activities = new JSONArray();
        while (activitiesIterator.hasNext()) {
            Resource blueActivity = activitiesIterator.next();
            try {
                activities.add(JSONObject.fromObject(Export.toJson(blueActivity)));
            } catch (IOException e) {
                LOGGER.log(Level.FINE, String.format("Unable to preload runs for Job '%s'. Activity serialization error.", pipeline.getFullName()), e);
                return null;
            }
        }
        return new FetchData(activitiesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, activities.toString());
    }
    // Don't preload any data on the page.
    return null;
}
Also used : BlueRun(io.jenkins.blueocean.rest.model.BlueRun) JSONArray(net.sf.json.JSONArray) Resource(io.jenkins.blueocean.rest.model.Resource) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) IOException(java.io.IOException)

Example 77 with JSONArray

use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.

the class JwtAuthenticationServiceImpl method getJwkSet.

@Override
public JSONObject getJwkSet() {
    JSONObject jwks = new JSONObject();
    JSONArray keys = new JSONArray();
    // Get a year of potential signing keys
    for (int i = 0; i <= 12; i++) {
        String keyId = SigningKeyProviderImpl.DATE_FORMAT.format(Instant.now().minus(ChronoUnit.MONTHS.getDuration().multipliedBy(i)));
        try {
            SigningPublicKey signingKey = getJwks(keyId);
            if (signingKey != null) {
                keys.add(signingKey.asJSON());
            }
        } catch (ServiceException e) {
            LOGGER.log(WARNING, String.format("Error reading RSA key for id %s: %s", keyId, e.getMessage()), e);
        }
    }
    jwks.put("keys", keys);
    return jwks;
}
Also used : SigningPublicKey(io.jenkins.blueocean.auth.jwt.SigningPublicKey) JSONObject(net.sf.json.JSONObject) ServiceException(io.jenkins.blueocean.commons.ServiceException) JSONArray(net.sf.json.JSONArray)

Example 78 with JSONArray

use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.

the class GraphDumpAction method doIndex.

public HttpResponse doIndex() throws IOException {
    JSONArray response = new JSONArray();
    FlowGraphWalker walker = new FlowGraphWalker(run.getExecution());
    for (FlowNode node : walker) {
        JSONObject outputNode = new JSONObject();
        outputNode.put("id", node.getId());
        outputNode.put("name", node.getDisplayName());
        outputNode.put("functionName", node.getDisplayFunctionName());
        outputNode.put("className", node.getClass().getName());
        outputNode.put("enclosingId", node.getEnclosingId());
        outputNode.put("isBegin", node instanceof BlockStartNode);
        outputNode.put("isEnd", node instanceof BlockEndNode);
        outputNode.put("isStepNode", node instanceof StepNode);
        if (node instanceof StepNode) {
            StepNode sn = (StepNode) node;
            StepDescriptor descriptor = sn.getDescriptor();
            if (descriptor != null) {
                JSONObject outputDescriptor = new JSONObject();
                outputDescriptor.put("getDisplayName", descriptor.getDisplayName());
                outputDescriptor.put("getFunctionName", descriptor.getFunctionName());
                outputNode.put("stepDescriptor", outputDescriptor);
            }
        }
        JSONArray parents = new JSONArray();
        for (FlowNode parent : node.getParents()) {
            parents.add(parent.getId());
        }
        outputNode.put("parents", parents);
        if (node instanceof BlockStartNode) {
            BlockStartNode startNode = (BlockStartNode) node;
            final BlockEndNode endNode = startNode.getEndNode();
            outputNode.put("endNodeId", endNode == null ? null : endNode.getId());
        } else if (node instanceof BlockEndNode) {
            BlockEndNode endNode = (BlockEndNode) node;
            outputNode.put("startNodeId", endNode.getStartNode().getId());
        }
        JSONArray actions = new JSONArray();
        for (Action action : node.getAllActions()) {
            JSONObject outputAction = new JSONObject();
            outputAction.put("className", action.getClass().getName());
            outputAction.put("displayName", action.getDisplayName());
            actions.add(outputAction);
        }
        outputNode.put("actions", actions);
        response.add(outputNode);
    }
    return HttpResponses.okJSON(response);
}
Also used : Action(hudson.model.Action) StepNode(org.jenkinsci.plugins.workflow.graph.StepNode) JSONObject(net.sf.json.JSONObject) BlockStartNode(org.jenkinsci.plugins.workflow.graph.BlockStartNode) JSONArray(net.sf.json.JSONArray) FlowGraphWalker(org.jenkinsci.plugins.workflow.graph.FlowGraphWalker) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) BlockEndNode(org.jenkinsci.plugins.workflow.graph.BlockEndNode) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 79 with JSONArray

use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.

the class RunContainerImpl method getParameterValue.

private List<ParameterValue> getParameterValue(@NonNull StaplerRequest request) {
    List<ParameterValue> values = new ArrayList<>();
    List<ParameterDefinition> pdsInRequest = new ArrayList<>();
    ParametersDefinitionProperty pp = (ParametersDefinitionProperty) job.getProperty(ParametersDefinitionProperty.class);
    if (pp == null) {
        return values;
    }
    try {
        JSONObject body = JSONObject.fromObject(IOUtils.toString(request.getReader()));
        if (body.get("parameters") == null && pp.getParameterDefinitions().size() > 0) {
            throw new ServiceException.BadRequestException("This is parameterized job, requires parameters");
        }
        if (body.get("parameters") != null) {
            JSONArray pds = JSONArray.fromObject(body.get("parameters"));
            for (Object o : pds) {
                JSONObject p = (JSONObject) o;
                String name = (String) p.get("name");
                if (name == null) {
                    throw new ServiceException.BadRequestException("parameters.name is required element");
                }
                ParameterDefinition pd = pp.getParameterDefinition(name);
                if (pd == null) {
                    throw new ServiceException.BadRequestException("No such parameter definition: " + name);
                }
                ParameterValue parameterValue = pd.createValue(request, p);
                if (parameterValue != null) {
                    values.add(parameterValue);
                    pdsInRequest.add(pd);
                } else {
                    throw new ServiceException.BadRequestException("Invalid value. Cannot retrieve the parameter value: " + name);
                }
            }
            // now check for missing parameters without default values
            if (pdsInRequest.size() != pp.getParameterDefinitions().size()) {
                for (ParameterDefinition pd : pp.getParameterDefinitions()) {
                    if (!pdsInRequest.contains(pd)) {
                        ParameterValue v = pd.getDefaultParameterValue();
                        if (v == null || v.getValue() == null) {
                            throw new ServiceException.BadRequestException("Missing parameter: " + pd.getName());
                        }
                        values.add(v);
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
    }
    return values;
}
Also used : ParameterValue(hudson.model.ParameterValue) ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) IOException(java.io.IOException) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) JSONObject(net.sf.json.JSONObject) ServiceException(io.jenkins.blueocean.commons.ServiceException) JSONObject(net.sf.json.JSONObject) ParameterDefinition(hudson.model.ParameterDefinition)

Example 80 with JSONArray

use of net.sf.json.JSONArray in project pmph by BCSquad.

the class BookServiceImpl method AbuttingJoint.

@Override
public String AbuttingJoint(String[] vns, Integer type, String materialName) throws CheckedServiceException {
    String result = "SUCCESS";
    Const.AllSYNCHRONIZATION = 1;
    int num = vns.length / 100;
    for (int i = 0; i < vns.length; i++) {
        Book oldBook = bookDao.getBookByBookVn(vns[i]);
        JSONObject ot = new JSONObject();
        if (type == 0) {
            // 商城发送修改的请求
            if (ObjectUtil.isNull(oldBook)) {
                continue;
            }
        }
        try {
            // System.out.println("第"+(i+1)+"条数据,本版号为"+vns[i]+" 共"+vns.length+"条");
            ot = PostBusyAPI(vns[i]);
            if (null != ot && "1".equals(ot.getJSONObject("RESP").getString("CODE"))) {
                JSONArray array = ot.getJSONObject("RESP").getJSONObject("responseData").getJSONArray("results");
                if (array.size() > 0) {
                    Book book = BusyResJSONToModel(array.getJSONObject(0), null);
                    // 获取到图书详情将其存入到图书详情表中
                    String content = book.getContent();
                    if (ObjectUtil.isNull(oldBook)) {
                        book.setScore(10.0);
                        book.setType(1L);
                        bookDao.addBook(book);
                        BookDetail bookDetail = new BookDetail(book.getId(), content);
                        bookDetailDao.addBookDetail(bookDetail);
                    } else {
                        Book newBook = new Book(book.getBookname(), book.getIsbn(), book.getSn(), book.getAuthor(), book.getPublisher(), book.getLang(), book.getRevision(), book.getType(), book.getPublishDate(), book.getReader(), book.getPrice(), book.getScore(), book.getBuyUrl(), book.getImageUrl(), book.getPdfUrl(), book.getClicks(), book.getComments(), book.getLikes(), book.getBookmarks(), book.getIsStick(), book.getSort(), book.getDeadlineStick(), book.getIsNew(), book.getSortNew(), book.getDeadlineNew(), book.getIsPromote(), book.getSortPromote(), book.getDeadlinePromote(), book.getIsKey(), book.getSortKey(), book.getSales(), book.getIsOnSale(), book.getGmtCreate(), book.getGmtUpdate());
                        newBook.setId(oldBook.getId());
                        bookDao.updateBook(newBook);
                        BookDetail bookDetail = new BookDetail(oldBook.getId(), content);
                        bookDetailDao.updateBookDetailByBookId(bookDetail);
                    }
                }
                if ((i + 1) >= num * (Const.AllSYNCHRONIZATION + 1)) {
                    Const.AllSYNCHRONIZATION++;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "FAIL";
        }
    }
    return result;
}
Also used : JSONObject(net.sf.json.JSONObject) Book(com.bc.pmpheep.back.po.Book) JSONArray(net.sf.json.JSONArray) BookDetail(com.bc.pmpheep.back.po.BookDetail) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

JSONArray (net.sf.json.JSONArray)144 JSONObject (net.sf.json.JSONObject)109 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)22 HashMap (java.util.HashMap)20 File (java.io.File)16 Test (org.junit.Test)15 JSON (net.sf.json.JSON)14 Map (java.util.Map)12 JsonConfig (net.sf.json.JsonConfig)10 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 URI (java.net.URI)8 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)6 Date (java.util.Date)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 OutputStream (java.io.OutputStream)5 List (java.util.List)5 CAFunctorFactory (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory)4 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)4