use of net.sf.json.JSONArray in project jaffa-framework by jaffa-projects.
the class TreeNode method toJson.
public JSONObject toJson() {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("text", text);
json.put("leaf", leaf);
json.put("isClass", isClass);
if (iconCls != null) {
json.put("iconCls", iconCls);
}
if (className != null) {
json.put("className", className);
}
if (serviceName != null) {
json.put("serviceName", serviceName);
}
if (dbTableName != null) {
json.put("dbTableName", dbTableName);
}
if (soaEventName != null) {
json.put("soaEventName", soaEventName);
}
if (label != null) {
json.put("label", label);
}
if (description != null) {
json.put("description", description);
}
if (soaEventParams != null && (leaf || isSelectable)) {
json.put("soaEventParams", soaEventParams);
}
if (uniqueName != null) {
json.put("uniqueName", uniqueName);
}
json.put("isEnabled", isEnabled);
json.put("isSelectable", isSelectable);
if (children.isEmpty()) {
return json;
}
JSONArray jsonArray = new JSONArray();
for (TreeNode child : children) {
jsonArray.add(child.toJson());
}
json.put("children", jsonArray);
return json;
}
use of net.sf.json.JSONArray in project jaffa-framework by jaffa-projects.
the class SOAEventMetaDataService method createTree.
/**
* @return JSONArray.
*/
private JSONArray createTree() throws JAXBException, MalformedURLException {
JSONArray array = new JSONArray();
// get all of the SOA events
List<SoaEventInfo> soaEvents = getSoaEventInfo();
// create a root node for the tree
TreeNode globalRoot = new TreeNode("SOA Events");
globalRoot.setLeaf(false);
globalRoot.setUniqueName("SOA_EVENTS");
// get the default event state and the list of all events that are not in the default state
final boolean areEventsEnabledByDefault = SOAEventEnabledConfigurationFactory.instance().areEventsEnabledByDefault();
final List<String> eventsInNonDefaultState = SOAEventEnabledConfigurationFactory.instance().getEventsInNonDefaultState();
// create a tree node for each SOA event
for (SoaEventInfo soaEvent : soaEvents) {
String[] chain = null;
if (soaEvent.getName().indexOf("_") > 0) {
chain = soaEvent.getName().split("_");
} else {
chain = soaEvent.getName().split("\\.");
}
TreeNode currentNode = null;
// create a tree node for each level of chaining in the event's name
for (int j = 0; j < chain.length; j++) {
TreeNode wantedNode = new TreeNode(chain[j]);
wantedNode.setSoaEventName(soaEvent.getName());
wantedNode.setLabel(soaEvent.getLabel());
wantedNode.setDescription(soaEvent.getDescription());
wantedNode.setSoaEventParams(getParams(soaEvent));
// set the unique name of this tree node, this is the chain of parent node names and this node's name
StringBuilder sb = new StringBuilder();
for (int k = 0; k <= j; k++) {
// add an underscore after the first node name in the chain
if (k > 0) {
sb.append("_");
}
// append the node name from the chain of node names
sb.append(chain[k]);
}
wantedNode.setUniqueName(sb.toString());
// set the isEnabled value on the tree node so we can use it to filter visibility
if (areEventsEnabledByDefault && eventsInNonDefaultState.contains(soaEvent.getName())) {
wantedNode.setIsEnabled(false);
} else if (!areEventsEnabledByDefault && !eventsInNonDefaultState.contains(soaEvent.getName())) {
wantedNode.setIsEnabled(false);
} else {
wantedNode.setIsEnabled(true);
}
// else, set the icon based on the isEnabled flag of the event
if (j < (chain.length - 1)) {
wantedNode.setIconCls("copy");
wantedNode.setIsSelectable(false);
} else if (wantedNode.getIsEnabled()) {
wantedNode.setIconCls("icon-filter-enabled");
wantedNode.setIsSelectable(true);
} else {
wantedNode.setIconCls("icon-filter-disabled");
wantedNode.setIsSelectable(true);
}
if (j == 0) {
for (int k = 0; k < globalRoot.getChild().size(); k++) {
if (wantedNode.getText().equals(globalRoot.getChild().get(k).getText())) {
currentNode = globalRoot.getChild().get(k);
break;
} else {
if (k == globalRoot.getChild().size() - 1) {
globalRoot.addChild(wantedNode);
currentNode = wantedNode;
}
}
}
if (globalRoot.getChild().isEmpty()) {
globalRoot.addChild(wantedNode);
currentNode = wantedNode;
}
} else {
if (currentNode.getChild() == null || currentNode.getChild().isEmpty()) {
currentNode.addChild(wantedNode);
currentNode = wantedNode;
}
for (int k = 0; k < currentNode.getChild().size(); k++) {
if (wantedNode.getText().equals(currentNode.getChild().get(k).getText())) {
currentNode = currentNode.getChild().get(k);
break;
} else {
if (k == currentNode.getChild().size() - 1) {
currentNode.addChild(wantedNode);
currentNode = wantedNode;
}
}
}
}
}
}
array.add(globalRoot.toJson());
return array;
}
use of net.sf.json.JSONArray in project jaffa-framework by jaffa-projects.
the class ExcelExportService method jsonArrayToBeanArray.
/**
* Converts the input array JSON structure into an array of instances of the
* beanClassName. If the beanClassName is null, then an arrays of instances
* of org.apache.commons.beanutils.DynaBean will be returned.
*
* @param input
* input array as a JSON structure.
* @param beanClassName
* the name of the bean class.
* @return the input array JSON structure as an array of instances of the beanClassName.
* @throws ClassNotFoundException if the beanClassName is invalid.
*/
public static Object[] jsonArrayToBeanArray(String input, String beanClassName) throws ClassNotFoundException {
if (log.isDebugEnabled())
log.debug("Converting JSON '" + input + "' into an array of instances of " + beanClassName);
registerCustomMorphers();
Class beanClass = beanClassName != null ? Class.forName(beanClassName) : null;
JSONArray jsonArray = JSONArray.fromObject(input);
Object[] beans = beanClass != null ? (Object[]) JSONArray.toArray(jsonArray, beanClass) : (Object[]) JSONArray.toArray(jsonArray);
if (log.isDebugEnabled())
log.debug("Converted to: " + Arrays.toString(beans));
return beans;
}
use of net.sf.json.JSONArray in project hudson-2.x by hudson.
the class ParametersDefinitionProperty method _doBuild.
/**
* Interprets the form submission and schedules a build for a parameterized job.
*
* <p>
* This method is supposed to be invoked from {@link AbstractProject#doBuild(StaplerRequest, StaplerResponse)}.
*/
public void _doBuild(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
if (!req.getMethod().equals("POST")) {
// show the parameter entry form.
req.getView(this, "index.jelly").forward(req, rsp);
return;
}
List<ParameterValue> values = new ArrayList<ParameterValue>();
JSONObject formData = req.getSubmittedForm();
JSONArray a = JSONArray.fromObject(formData.get("parameter"));
for (Object o : a) {
JSONObject jo = (JSONObject) o;
String name = jo.getString("name");
ParameterDefinition d = getParameterDefinition(name);
if (d == null)
throw new IllegalArgumentException("No such parameter definition: " + name);
ParameterValue parameterValue = d.createValue(req, jo);
values.add(parameterValue);
}
Hudson.getInstance().getQueue().schedule(owner, owner.getDelay(req), new ParametersAction(values), new CauseAction(new Cause.UserCause()));
// send the user back to the job top page.
rsp.sendRedirect(".");
}
use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.
the class FavoritesStatePreloader method getFetchData.
@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
User jenkinsUser = User.current();
if (jenkinsUser != null) {
BlueOrganization organization = IterableUtils.getFirst(OrganizationFactory.getInstance().list(), null);
if (organization != null) {
String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
// don't need this list when at pipeline pages
if (pipelineFullName != null) {
return null;
}
UserImpl blueUser = new UserImpl(organization, jenkinsUser, organization.getUsers());
BlueFavoriteContainer favoritesContainer = blueUser.getFavorites();
if (favoritesContainer != null) {
JSONArray favorites = new JSONArray();
// Limit the number of favorites to return to a sane amount
Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator(0, DEFAULT_LIMIT);
while (favoritesIterator.hasNext()) {
Reachable favorite = favoritesIterator.next();
try {
favorites.add(JSONObject.fromObject(Export.toJson(favorite)));
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Unable to preload favorites for User '%s'. Serialization error.", jenkinsUser.getFullName()), e);
return null;
}
}
return new FetchData(favoritesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, favorites.toString());
}
}
}
// Don't preload any data on the page.
return null;
}
Aggregations