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