Search in sources :

Example 26 with ObjectNode

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;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode)

Example 27 with ObjectNode

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();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode)

Example 28 with ObjectNode

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();
}
Also used : PrintStream(java.io.PrintStream) ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) File(java.io.File)

Example 29 with ObjectNode

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;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode)

Example 30 with ObjectNode

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('\"', '\''));
}
Also used : PatientDomainWrapper(org.openmrs.module.emrapi.patient.PatientDomainWrapper) ObjectNode(org.codehaus.jackson.node.ObjectNode) Patient(org.openmrs.Patient) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)28 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)17 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)7 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3