Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.impl; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import org.onosproject.ui.RequestHandler; |
| 22 | import org.onosproject.ui.UiMessageHandler; |
| 23 | import org.onosproject.ui.UiPreferencesService; |
| 24 | |
| 25 | import java.util.Collection; |
| 26 | |
| 27 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 28 | |
| 29 | /** |
| 30 | * Message handler for intercepting user preferences messages. |
| 31 | */ |
| 32 | class UserPreferencesMessageHandler extends UiMessageHandler { |
| 33 | |
| 34 | private static final String UPDATE_PREFS_REQ = "updatePrefReq"; |
| 35 | private static final String KEY = "key"; |
| 36 | private static final String VALUE = "value"; |
| 37 | |
| 38 | @Override |
| 39 | protected Collection<RequestHandler> createRequestHandlers() { |
| 40 | return ImmutableSet.of(new UpdatePreferencesRequest()); |
| 41 | } |
| 42 | |
| 43 | private final class UpdatePreferencesRequest extends RequestHandler { |
| 44 | private UpdatePreferencesRequest() { |
| 45 | super(UPDATE_PREFS_REQ); |
| 46 | } |
| 47 | |
| 48 | @Override |
Simon Hunt | 8a0429a | 2017-01-06 16:52:47 -0800 | [diff] [blame] | 49 | public void process(ObjectNode payload) { |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 50 | if (!isNullOrEmpty(connection().userName())) { |
| 51 | UiPreferencesService service = get(UiPreferencesService.class); |
| 52 | service.setPreference(connection().userName(), |
Simon Hunt | 8a0429a | 2017-01-06 16:52:47 -0800 | [diff] [blame] | 53 | payload.get(KEY).asText(), |
| 54 | (ObjectNode) payload.get(VALUE)); |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |