Search in sources :

Example 1 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)

Example 2 with UiPreferencesService

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

the class UiPreferencesWebResource method download.

/**
 * Gets user preferences for the given user.
 *
 * @param user user name
 * @return 200 OK with user preferences JSON
 */
@GET
@Path("{user}")
@Produces(MediaType.APPLICATION_JSON)
public Response download(@PathParam("user") String user) {
    UiPreferencesService service = get(UiPreferencesService.class);
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode prefs = mapper.createObjectNode();
    service.getPreferences(user).forEach(prefs::set);
    return ok(prefs).build();
}
Also used : UiPreferencesService(org.onosproject.ui.UiPreferencesService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with UiPreferencesService

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

the class UiPreferencesWebResource method upload.

/**
 * Gets the specified user preferences for the given user.
 *
 * @param user    user name
 * @param pref    preferences name
 * @param request preferences JSON
 * @return 200 OK
 * @throws IOException if given JSON is invalid
 */
@PUT
@Path("{user}/{pref}")
@Produces(MediaType.APPLICATION_JSON)
public Response upload(@PathParam("user") String user, @PathParam("pref") String pref, String request) throws IOException {
    UiPreferencesService service = get(UiPreferencesService.class);
    ObjectNode json = (ObjectNode) mapper().readTree(request);
    service.setPreference(user, pref, json);
    return Response.ok().build();
}
Also used : UiPreferencesService(org.onosproject.ui.UiPreferencesService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 4 with UiPreferencesService

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

the class UiPreferencesListCommand method doExecute.

@Override
protected void doExecute() {
    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);
    });
    print("%s", root);
}
Also used : UiPreferencesService(org.onosproject.ui.UiPreferencesService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with UiPreferencesService

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

the class UiPreferencesWebResource method remove.

/**
 * Removes the specified user preferences for the given user.
 *
 * @param user user name
 * @param pref preferences name
 * @return 204 no content
 */
@DELETE
@Path("{user}/{pref}")
@Produces(MediaType.APPLICATION_JSON)
public Response remove(@PathParam("user") String user, @PathParam("pref") String pref) {
    UiPreferencesService service = get(UiPreferencesService.class);
    service.setPreference(user, pref, null);
    return Response.noContent().build();
}
Also used : UiPreferencesService(org.onosproject.ui.UiPreferencesService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

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