use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.
the class PluginData method mergeConfiguration.
/**
* Applies custom (user-defined) configuration on top of default (descriptor-defined) configuration, and returns the
* resulting JSON object.
*/
public ObjectNode mergeConfiguration() {
JsonNode descriptorConfigNode = descriptorNode.path(ATT_CONFIG);
ObjectNode result = nodeFactory.objectNode();
// Apply default configuration, if any
if (!descriptorConfigNode.isMissingNode() && descriptorConfigNode.isObject()) {
result.putAll((ObjectNode) descriptorConfigNode);
}
// Apply custom configuration, if any
JsonNode customConfigNode = configurationNode.path(ATT_CONFIG);
if (customConfigNode != null && !customConfigNode.isMissingNode() && customConfigNode.isObject()) {
result.putAll((ObjectNode) customConfigNode);
}
return result;
}
use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.
the class GwtDynamicHostPageServlet method getValueObject.
/**
* Create a Javascript value object with the value being the passed in value.
* @param value The {@code String} value to use as the value of the object.
* @return A String representation of the Javascript object.
*/
protected String getValueObject(final String value) {
ObjectNode node = mapper.createObjectNode();
// $NON-NLS-1$
node.put("value", value);
return node.toString();
}
use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.
the class ContextSensitiveHelpMappingServlet method doGet.
/**
* Respond to a GET request for the CSH mapping file. See class Javadoc for the algorithm.
*
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String manualPath = getManualDir(getServletConfig());
List<String> locales = getLocales(new File(manualPath));
ObjectNode appCsh = mapper.createObjectNode();
for (String locale : locales) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
File cshConfigDir = new File(manualPath + "/" + locale + "/" + CSH_MAPPING_DIR + "/" + APPLICATION);
if (cshConfigDir.exists() && cshConfigDir.canRead()) {
List<JsonNode> configData = readJsonFiles(cshConfigDir);
// merge the data from all the files
if (configData.size() > 0) {
JsonNode destination = configData.get(0);
for (int i = 1; i < configData.size(); i++) {
destination = merge(destination, configData.get(i));
}
appCsh.put(locale, destination);
}
} else {
// $NON-NLS-1$
log.error("couldn't get csh directory: " + cshConfigDir);
}
}
// $NON-NLS-1$
response.setContentType("application/json");
PrintStream printStream = new PrintStream(response.getOutputStream());
printStream.print(appCsh.toString());
printStream.flush();
}
use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.
the class ContextSensitiveHelpMappingServlet method merge.
/**
* Merge json objects. This is used to put json mappings from multiple config files into one object.
*
* Note that this method is recursive.
*
* @param destination destination json node
* @param source source json node.
* @return merged json object
*/
protected static JsonNode merge(JsonNode destination, JsonNode source) {
Iterator<String> fieldNames = source.getFieldNames();
while (fieldNames.hasNext()) {
String fieldName = fieldNames.next();
JsonNode jsonNode = destination.get(fieldName);
// if field is an embedded object, recurse
if (jsonNode != null && jsonNode.isObject()) {
merge(jsonNode, source.get(fieldName));
} else // else it's a plain field
if (destination instanceof ObjectNode) {
// overwrite field
JsonNode value = source.get(fieldName);
((ObjectNode) destination).put(fieldName, value);
}
}
return destination;
}
use of org.codehaus.jackson.node.ObjectNode in project openmrs-module-coreapps by openmrs.
the class DashboardWidgetFragmentController method controller.
public void controller(FragmentConfiguration config, @FragmentParam("app") AppDescriptor app, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("adminService") AdministrationService adminService) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Object patient = null;
patient = config.get("patient");
if (patient == null) {
patient = config.get("patientId");
}
ObjectNode appConfig = app.getConfig();
if (patient != null) {
if (patient instanceof Patient) {
patientWrapper.setPatient((Patient) patient);
} else if (patient instanceof PatientDomainWrapper) {
patientWrapper = (PatientDomainWrapper) patient;
} else if (patient instanceof Integer) {
// assume we have patientId
patientWrapper.setPatient(Context.getPatientService().getPatient((Integer) patient));
} else {
throw new IllegalArgumentException("Patient must be of type Patient or PatientDomainWrapper");
}
appConfig.put("patientUuid", patientWrapper.getPatient().getUuid());
}
if (appConfig.get("dateFormat") == null) {
appConfig.put("dateFormat", adminService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATE_FORMAT, "yyyy-MM-dd"));
}
appConfig.put("locale", Context.getLocale().toString());
appConfig.put("language", Context.getLocale().getLanguage().toString());
Map<String, Object> appConfigMap = mapper.convertValue(appConfig, Map.class);
config.merge(appConfigMap);
config.addAttribute("json", appConfig.toString().replace('\"', '\''));
}
Aggregations