Network topology and inventory init
[transportpce.git] / inventory / src / main / java / org / opendaylight / transportpce / inventory / query / Queries.java
1 /*
2  * Copyright © 2017 AT&T and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.inventory.query;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.base.Strings;
13
14 public class Queries {
15
16     private static final String DEVICE_INFO_INSERT =
17         "INSERT INTO %sinv_dev_info "
18         + "(node_id, node_number, node_type, clli, vendor, model, serial_id, ipAddress, prefix_length, "
19         + "default_gateway, source, current_ipAddress, current_prefix_length, current_default_gateway, macAddress, "
20         + "software_version, template, current_datetime, latitude, longitude, max_degrees, max_srgs, sw_version, "
21         + "sw_validation_timer, activation_date_time, create_date, update_date) "
22         + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
23
24     private static final String DEVICE_SHELF_INSERT =
25         "INSERT INTO %sinv_dev_shelf "
26         + "(node_id, shelf_name, shelf_type, rack, shelf_position, administrative_state, vendor, model, serial_id, "
27         + "type, product_code, manufacture_date, clei, hardware_version, operational_state, equipment_state, due_date, "
28         + "create_date, update_date) "
29         + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
30
31     private static final String DEVICE_SHELF_SLOT_INSERT =
32         "INSERT INTO %sinv_dev_shelf_slot "
33         + "(node_id, shelf_name, slot_name, label, provisioned_circuit_pack, create_date, update_date) "
34         + "VALUES (?, ?, ?, ?, ?, ?, ?)";
35
36     private static final String DEVICE_CP_INSERT =
37         "INSERT INTO %sinv_dev_circuit_pack "
38         + "(node_id, circuitPackName, circuitPackType, circuitPackProductCode, administrative_state, vendor, model, "
39         + "serial_id, type, product_code, manufacture_date, clei, hardware_version, operational_state, "
40         + "equipment_state, shelf, slot, subSlo, cpCatType, extension, due_date, parentCpName, parentCpSlotName) "
41         + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
42
43     private static final String SERVICE_INSERT =
44         "INSERT INTO %sinv_ser_main "
45         + "(service_name, common_id, sdnc_req_header_request_id, sdnc_req_header_rpc_action, "
46         + "sdnc_req_header_notification_url, sdnc_req_header_request_system_id, connection_type, lifecycle_state, "
47         + "administrative_state, operational_state, serv_condition, a_end_service_format, a_end_service_rate, "
48         + "a_end_clli, a_end_node_id, a_end_tx_port_device_name, a_end_tx_port_type, a_end_tx_port_name, "
49         + "a_end_tx_port_rack, a_end_tx_port_shelf, a_end_tx_port_slot, a_end_tx_port_sub_slot, "
50         + "a_end_tx_lgx_device_name, a_end_tx_lgx_port_name, a_end_tx_lgx_port_rack, a_end_tx_lgx_port_shelf, "
51         + "a_end_tx_tail_rnode_id, a_end_tx_xport_cp_name, a_end_tx_xport_port_name, a_end_tx_tail_roadm_port_aid, "
52         + "a_end_tx_tail_roadm_port_rack_loc, a_end_rx_port_device_name, a_end_rx_port_type, a_end_rx_port_name, "
53         + "a_end_rx_port_rack, a_end_rx_port_shelf, a_end_rx_port_slot, a_end_rx_port_sub_slot, "
54         + "a_end_rx_lgx_device_name, a_end_rx_lgx_port_name, a_end_rx_lgx_port_rack, a_end_rx_lgx_port_shelf, "
55         + "a_end_rx_tail_rnode_id, a_end_rx_xport_cp_name, a_end_rx_xport_port_name, a_end_rx_tail_roadm_port_aid, "
56         + "a_end_rx_tail_roadm_port_rack_loc, a_end_optic_type, a_end_router_node_id, a_end_router_ip_address, "
57         + "a_end_router_url, a_end_user_label, z_end_service_format, z_end_service_rate, z_end_clli, z_end_node_id, "
58         + "z_end_tx_port_device_name, z_end_tx_port_type, z_end_tx_port_name, z_end_tx_port_rack, z_end_tx_port_shelf, "
59         + "z_end_tx_port_slot, z_end_tx_port_sub_slot, z_end_tx_lgx_device_name, z_end_tx_lgx_port_name, "
60         + "z_end_tx_lgx_port_rack, z_end_tx_lgx_port_shelf, z_end_tx_tail_rnode_id, z_end_tx_xport_cp_name, "
61         + "z_end_tx_xport_port_name, z_end_tx_tail_roadm_port_aid, z_end_tx_tail_roadm_port_rack_loc, "
62         + "z_end_rx_port_device_name, z_end_rx_port_type, z_end_rx_port_name, z_end_rx_port_rack, z_end_rx_port_shelf, "
63         + "z_end_rx_port_slot, z_end_rx_port_sub_slot, z_end_rx_lgx_device_name, z_end_rx_lgx_port_name, "
64         + "z_end_rx_lgx_port_rack, z_end_rx_lgx_port_shelf, z_end_rx_tail_rnode_id, z_end_rx_xport_cp_name, "
65         + "z_end_rx_xport_port_name, z_end_rx_tail_roadm_port_aid, z_end_rx_tail_roadm_port_rack_loc, "
66         + "z_end_optic_type, z_end_router_node_id, z_end_router_ip_address, z_end_router_url, z_end_user_label, "
67         + "due_date, end_date, nc_code, nci_code, secondary_nci_code, customer, customer_contact, operator_contact, "
68         + "latency, fiber_span_srlgs, supp_serv_name, create_date, update_date) "
69         + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
70         + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
71         + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
72
73     private static final String SERVICE_DELETE =
74         "DELETE FROM %sinv_ser_main WHERE service_name = ?";
75
76     private Queries() {
77         // util class
78     }
79
80     public static Query getQuery() {
81         return new Query();
82     }
83
84     public static class Query {
85         private String sql;
86         private String schema;
87
88         private Query() {
89             this.schema = "";
90         }
91
92         public Query withSchema(String schema) {
93             this.schema = schema;
94             return this;
95         }
96
97         public Query deviceInfoInsert() {
98             this.sql = DEVICE_INFO_INSERT;
99             return this;
100         }
101
102         public Query deviceShelfInsert() {
103             this.sql = DEVICE_SHELF_INSERT;
104             return this;
105         }
106
107         public Query deviceShelfSlotInsert() {
108             this.sql = DEVICE_SHELF_SLOT_INSERT;
109             return this;
110         }
111
112         public Query deviceCircuitPackInsert() {
113             this.sql = DEVICE_CP_INSERT;
114             return this;
115         }
116
117         public Query serviceCreate() {
118             this.sql = SERVICE_INSERT;
119             return this;
120         }
121
122         public Query serviceDelete() {
123             this.sql = SERVICE_DELETE;
124             return this;
125         }
126
127         public String get() {
128             Preconditions.checkArgument(!Strings.isNullOrEmpty(this.sql), "No query selected");
129             return String.format(this.sql, this.schema.concat("."));
130         }
131     }
132 }