blob: 3d27eebdedf9ffd603ed2fd0e3a5837499da5bea [file] [log] [blame]
Sho SHIMIZUe4efe452015-08-26 15:06:55 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUe4efe452015-08-26 15:06:55 -07003 *
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 */
16package org.onosproject.ovsdb.rfc.utils;
17
18import java.util.List;
19import java.util.Map;
20import java.util.Set;
21
22import org.onosproject.ovsdb.rfc.message.MonitorRequest;
23import org.onosproject.ovsdb.rfc.message.MonitorSelect;
24import org.onosproject.ovsdb.rfc.operations.Operation;
25import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
26import org.onosproject.ovsdb.rfc.schema.TableSchema;
27
28import com.google.common.collect.Lists;
29import com.google.common.collect.Maps;
30
31/**
32 * Params utility class. Params of the request object, refer to RFC7047's
33 * Section 4.1.
34 */
35public final class ParamUtil {
36
37 /**
38 * Constructs a ParamUtil object. Utility classes should not have a public
39 * or default constructor, otherwise IDE will compile unsuccessfully. This
40 * class should not be instantiated.
41 */
42 private ParamUtil() {
43 }
44
45 /**
46 * Returns MonitorRequest, refer to RFC7047's Section 4.1.5.
47 * @param tableSchema entity
48 * @return MonitorRequest
49 */
50 private static MonitorRequest getAllColumnsMonitorRequest(TableSchema tableSchema) {
51 String tableName = tableSchema.name();
52 Set<String> columns = tableSchema.getColumnNames();
53 MonitorSelect select = new MonitorSelect(true, true, true, true);
54 MonitorRequest monitorRequest = new MonitorRequest(tableName, columns, select);
55 return monitorRequest;
56 }
57
58 /**
59 * Returns params of monitor method, refer to RFC7047's Section 4.1.5.
60 * @param monotorId json-value, refer to RFC7047's Section 4.1.5.
61 * @param dbSchema DatabaseSchema entity
62 * @return List of Object, the params of monitor request
63 */
64 public static List<Object> getMonitorParams(String monotorId, DatabaseSchema dbSchema) {
65 Set<String> tables = dbSchema.getTableNames();
66 Map<String, MonitorRequest> mrMap = Maps.newHashMap();
67 for (String tableName : tables) {
68 TableSchema tableSchema = dbSchema.getTableSchema(tableName);
69 MonitorRequest monitorRequest = getAllColumnsMonitorRequest(tableSchema);
70 mrMap.put(tableName, monitorRequest);
71 }
72 return Lists.newArrayList(dbSchema.name(), monotorId, mrMap);
73 }
74
75 /**
76 * Returns params of transact method, refer to RFC7047's Section 4.1.3.
77 * @param dbSchema DatabaseSchema entity
78 * @param operations operation*, refer to RFC7047's Section 4.1.3.
79 * @return List of Object, the params of transact request
80 */
81 public static List<Object> getTransactParams(DatabaseSchema dbSchema, List<Operation> operations) {
82 List<Object> lists = Lists.newArrayList(dbSchema.name());
83 lists.addAll(operations);
84 return lists;
85 }
86}