2 * Copyright (c) 2016 Wipro Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mwtn.impl.dto;
11 import java.util.HashMap;
13 import org.json.JSONArray;
14 import org.json.JSONException;
15 import org.json.JSONObject;
16 import org.opendaylight.mwtn.impl.utils.Utils;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class UserDto {
21 private static final Logger LOG = LoggerFactory.getLogger(UserDto.class);
23 private String userId;
24 private HashMap<String, Boolean> hmScopes;
26 public String getUserId() {
30 public void setUserId(String sessionId) {
31 this.userId = sessionId;
34 public HashMap<String, Boolean> getScopes() {
38 public void setScopes(JSONArray jsonScopes) {
39 hmScopes = new HashMap<>();
40 for (int i = 0; jsonScopes != null && i < jsonScopes.length(); i++) {
42 hmScopes.put(jsonScopes.getString(i), true);
43 } catch (JSONException e) {
44 LOG.warn("Something wrong: {}", e);
49 public JSONObject getScopedResponse(JSONObject jsonAllValue) {
50 JSONObject jsonResponse = new JSONObject();
52 JSONArray jsonArrayRes = new JSONArray();
53 JSONArray jsonArray = jsonAllValue.getJSONArray(Utils.MSG_KEY_DATA);
54 for (int i = 0; jsonArray != null && i < jsonArray.length(); i++) {
55 JSONObject jsonObject = jsonArray.getJSONObject(i);
56 String msgScope = jsonObject.getString(Utils.MSG_KEY_SCOPE);
57 if (getScopes().get(msgScope) != null && getScopes().get(msgScope)) {
58 jsonArrayRes.put(jsonObject);
61 if (jsonArrayRes.length() == 0) {
64 jsonResponse.put(Utils.MSG_KEY_DATA, jsonArrayRes);
65 } catch (Exception e) {
66 LOG.warn("Something wrong: {}", e);