Java Code Examples for net.sf.json.JSONObject#isNullObject()

The following examples show how to use net.sf.json.JSONObject#isNullObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JiraConverter.java    From benten with MIT License 6 votes vote down vote up
public static Meta getFieldMetadata(String name, JSONObject editmeta)
        throws BentenJiraException {

    if (editmeta.isNullObject() || !editmeta.containsKey(name))
        throw new BentenJiraException("Field '" + name + "' does not exist or read-only");

    Map f = (Map)editmeta.get(name);
    Meta m = new Meta();

    m.required = (boolean)f.get("required");
    m.name = (String)f.get("name");

    if (!f.containsKey("schema"))
        throw new BentenJiraException("Field '" + name + "' is missing schema metadata");

    Map schema = (Map)f.get("schema");

    m.type = getString(schema.get("type"));
    m.items = getString(schema.get("items"));
    m.system = getString(schema.get("system"));
    m.custom = getString(schema.get("custom"));
    m.customId = getInteger(schema.get("customId"));

    return m;
}
 
Example 2
Source File: WebhookJobPropertyDescriptor.java    From office-365-connector-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public WebhookJobProperty newInstance(StaplerRequest req, JSONObject formData) {

    List<Webhook> webhooks = new ArrayList<>();
    if (formData != null && !formData.isNullObject()) {
        JSON webhooksData = (JSON) formData.get("webhooks");
        if (webhooksData != null && !webhooksData.isEmpty()) {
            if (webhooksData.isArray()) {
                JSONArray webhooksArrayData = (JSONArray) webhooksData;
                webhooks.addAll(req.bindJSONToList(Webhook.class, webhooksArrayData));
            } else {
                JSONObject webhooksObjectData = (JSONObject) webhooksData;
                webhooks.add(req.bindJSON(Webhook.class, webhooksObjectData));
            }
        }
    }
    return new WebhookJobProperty(webhooks);
}
 
Example 3
Source File: AggregatedTestResultPublisher.java    From junit-plugin with MIT License 5 votes vote down vote up
@Override
public AggregatedTestResultPublisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
    // Starting in 1.640, Descriptor#newInstance is
    // newInstance(@CheckForNull StaplerRequest req, @Nonnull JSONObject formData)
    if (formData == null) {
        // Should not happen. See above
        throw new AssertionError("Null parameters to Descriptor#newInstance");
    }
    JSONObject s = formData.getJSONObject("specify");
    if(s.isNullObject())
        return new AggregatedTestResultPublisher(null, req != null && req.getParameter("includeFailedBuilds") != null);
    else
        return new AggregatedTestResultPublisher(s.getString("jobs"), req != null && req.getParameter("includeFailedBuilds") != null);
}
 
Example 4
Source File: PushAndPullRequestPayload.java    From DotCi with MIT License 5 votes vote down vote up
private boolean isBranchChange() {
    if (!isEditedAction()) {
        return false;
    }
    JSONObject changes = this.payloadJson.getJSONObject("changes");
    return !changes.isNullObject() && changes.containsKey("base");
}
 
Example 5
Source File: Wikidata.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Fetch only the name and description of the object.
 */
@SuppressWarnings("rawtypes")
public Vertex fetchDescription(JSONObject json, int cascade, Network network, Map<String, Vertex> processed) {
	if (json.isNullObject()) {
		return null;
	}
	// Get the object's name.
	Object id = json.get("id");		
	Vertex object = processed.get(id);
	if (object != null) {
		return object;
	}
	List names = extractText(json.get("labels"));
	Object name = null;
	if (names.size() > 0) {
		name = names.get(0);
	}
	List descriptions = extractText(json.get("descriptions"));
	log("Processing object:", Bot.FINE, id, names);
	
	try {
		if ((name instanceof String) && (((String)name).length() > 0)) {
			// Add names.
			object = network.createObject((String)name);
			if (object.hasRelationship(getPrimitive())) {
				return object;
			}
			object.addRelationship(getPrimitive(), network.createVertex(id));
			processed.put((String)id, object);
			object.addRelationship(Primitive.INSTANTIATION, Primitive.THING);
			for (Object eachName : names) {
				if (eachName instanceof String) {
					Vertex word = network.createWord((String)eachName);
					word.addRelationship(Primitive.MEANING, object);
					object.addRelationship(Primitive.WORD, word);
					network.associateCaseInsensitivity((String)eachName, object);
				}
			}
			for (Object description : descriptions) {
				// Add descriptions.
				if (description instanceof String) {
					Vertex paragraph = network.createParagraph((String)description);
					if (paragraph.instanceOf(Primitive.PARAGRAPH)) {
						object.addRelationship(Primitive.PARAGRAPH, paragraph);
						Vertex sentence = paragraph.orderedRelations(Primitive.SENTENCE).get(0);
						object.addRelationship(Primitive.SENTENCE, sentence);
					} else {
						object.addRelationship(Primitive.SENTENCE, paragraph);
					}
				}
			}
		} else {
			object = network.createVertex();
		}

		network.save();
	} catch (Exception ioException) {
		log(ioException);
	}
	return object;
}
 
Example 6
Source File: Freebase.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Fetch only the name and description of the object.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public Vertex fetchDescription(JSONObject json, int cascade, Network network, Map<String, Vertex> processed) {
	if (json.isNullObject()) {
		return null;
	}
	// Get the object's name.
	Object id = json.get("id");		
	Vertex object = processed.get(id);
	if (object != null) {
		return object;
	}
	JSONObject properties = (JSONObject)json.get("property");
	if (properties == null) {
		return null;
	}
	List names = extractPropertyValues(properties.get("/type/object/name"), Collections.EMPTY_LIST, cascade, network, processed);
	Object name = null;
	if (names.size() > 0) {
		name = names.get(0);
	}
	List descriptions = extractPropertyValues(properties.get("/common/topic/description"), Collections.EMPTY_LIST, cascade, network, processed);
	log("Processing object:", Bot.FINE, id, names);
	
	try {
		if ((name instanceof String) && (((String)name).length() > 0)) {
			// Add names.
			object = network.createObject((String)name);
			if (object.hasRelationship(getPrimitive())) {
				return object;
			}
			object.addRelationship(getPrimitive(), network.createVertex(id));
			processed.put((String)id, object);
			object.addRelationship(Primitive.INSTANTIATION, Primitive.THING);
			for (Object eachName : names) {
				if (eachName instanceof String) {
					Vertex word = network.createWord((String)eachName);
					word.addRelationship(Primitive.MEANING, object);
					object.addRelationship(Primitive.WORD, word);
					network.associateCaseInsensitivity((String)eachName, object);
				}
			}
			for (Object description : descriptions) {
				// Add descriptions.
				if (description instanceof String) {
					Vertex paragraph = network.createParagraph((String)description);
					if (paragraph.instanceOf(Primitive.PARAGRAPH)) {
						object.addRelationship(Primitive.PARAGRAPH, paragraph);
						Vertex sentence = paragraph.orderedRelations(Primitive.SENTENCE).get(0);
						object.addRelationship(Primitive.SENTENCE, sentence);							
					} else {
						object.addRelationship(Primitive.SENTENCE, paragraph);
					}
				}
			}
		} else {
			object = network.createVertex();
		}

		network.save();
	} catch (Exception ioException) {
		log(ioException);
	}
	return object;
}
 
Example 7
Source File: RemoteService.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Invoke the Pannous service.
 */
public String requestPannous(String message, String botid, String server, String apikey, int limit) throws Exception {
	try {
		if (server != null && !server.isEmpty()) {
			server = server.toLowerCase();
			if (!server.startsWith("http")) {
				server = "http://" + server;
			}
		} else {
			server = PANNOUS;
		}
		String url = server + "/api?input=" + Utils.encodeURL(message);
		log("PANNOUS", Level.INFO, url);
		InputStream stream = Utils.openStream(Utils.safeURL(url));
		String result = Utils.loadTextFile(stream, "UTF-8", 1000000);
		log("Response", Level.INFO, result);
		JSONObject json = (JSONObject)JSONSerializer.toJSON(result);
		if (json == null || json.isNullObject()) {
			return null;
		}
		JSONArray outputs = json.getJSONArray("output");
		if (outputs == null || outputs.isEmpty()) {
			return null;
		}
		JSONObject output = (JSONObject)outputs.get(0);
		if (output == null || output.isNullObject()) {
			return null;
		}
		JSONObject actions = output.getJSONObject("actions");
		if (actions == null || actions.isNullObject()) {
			return null;
		}
		JSONObject value = actions.getJSONObject("say");
		if (value == null || value.isNullObject()) {
			return null;
		}
		String text = value.getString("text");
		if (text == null) {
			return null;
		}
		if (limit > 0) {
			StringWriter writer = new StringWriter();
			TextStream textStream = new TextStream(text);
			for (int index = 0; index < limit; index++) {
				if (textStream.atEnd()) {
					break;
				}
				writer.write(textStream.nextSentence());
			}
			text = writer.toString();
		}
		return text;
	} catch (Exception exception) {
		log(exception);
		return null;
	}
}