Search in sources :

Example 6 with UiPreferencesService

use of org.onosproject.ui.UiPreferencesService in project onos by opennetworkinglab.

the class UiPreferencesWebResource method download.

/**
 * Gets all user preferences.
 *
 * @return 200 OK with user preferences JSON
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response download() {
    UiPreferencesService service = get(UiPreferencesService.class);
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode root = mapper.createObjectNode();
    service.getUserNames().forEach(user -> {
        ObjectNode prefs = mapper.createObjectNode();
        root.set(user, prefs);
        service.getPreferences(user).forEach(prefs::set);
    });
    return ok(root).build();
}
Also used : UiPreferencesService(org.onosproject.ui.UiPreferencesService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with UiPreferencesService

use of org.onosproject.ui.UiPreferencesService in project onos by opennetworkinglab.

the class MainIndexResource method userPreferences.

// Produces an input stream including user preferences.
private InputStream userPreferences(String userName) {
    UiPreferencesService service = get(UiPreferencesService.class);
    ObjectNode prefs = mapper().createObjectNode();
    service.getPreferences(userName).forEach(prefs::set);
    String string = "var userPrefs = " + prefs.toString() + ";\n";
    return new ByteArrayInputStream(string.getBytes());
}
Also used : UiPreferencesService(org.onosproject.ui.UiPreferencesService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

UiPreferencesService (org.onosproject.ui.UiPreferencesService)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Produces (javax.ws.rs.Produces)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Path (javax.ws.rs.Path)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 GET (javax.ws.rs.GET)2 DELETE (javax.ws.rs.DELETE)1 PUT (javax.ws.rs.PUT)1