complete dependency inject CRUD implementations
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronNorthboundRSApplication.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation 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 package org.opendaylight.neutron.northbound.api;
9
10 import static java.util.Collections.emptySet;
11
12 import com.google.common.collect.ImmutableSet;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Set;
16 import javax.inject.Inject;
17 import javax.inject.Singleton;
18 import javax.ws.rs.core.Application;
19 import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
20
21 /**
22  * This class is an instance of javax.ws.rs.core.Application and is used to return the classes
23  * that will be instantiated for JAXRS processing. This is necessary
24  * because package scanning in jersey doesn't yet work in OSGi environment.
25  */
26 @Singleton
27 public final class NeutronNorthboundRSApplication extends Application {
28     private static final int HASHMAP_SIZE = 3;
29
30     private final NeutronNetworksNorthbound neutronNetworksNorthbound;
31     private final NeutronSubnetsNorthbound neutronSubnetsNorthbound;
32     private final NeutronPortsNorthbound neutronPortsNorthbound;
33     private final NeutronRoutersNorthbound neutronRoutersNorthbound;
34     private final NeutronFloatingIpsNorthbound neutronFloatingIpsNorthbound;
35     private final NeutronSecurityGroupsNorthbound neutronSecurityGroupsNorthbound;
36     private final NeutronSecurityRulesNorthbound neutronSecurityRulesNorthbound;
37     private final NeutronFirewallNorthbound neutronFirewallNorthbound;
38     private final NeutronFirewallPolicyNorthbound neutronFirewallPolicyNorthbound;
39     private final NeutronFirewallRulesNorthbound neutronFirewallRulesNorthbound;
40     private final NeutronLoadBalancerNorthbound neutronLoadBalancerNorthbound;
41     private final NeutronLoadBalancerListenerNorthbound neutronLoadBalancerListenerNorthbound;
42     private final NeutronLoadBalancerPoolNorthbound neutronLoadBalancerPoolNorthbound;
43     private final NeutronBgpvpnsNorthbound neutronBgpvpnsNorthbound;
44     private final NeutronL2gatewayNorthbound neutronL2gatewayNorthbound;
45     private final NeutronL2gatewayConnectionNorthbound neutronL2gatewayConnectionNorthbound;
46     private final NeutronLoadBalancerHealthMonitorNorthbound neutronLoadBalancerHealthMonitorNorthbound;
47     private final NeutronMeteringLabelsNorthbound neutronMeteringLabelsNorthbound;
48     private final NeutronMeteringLabelRulesNorthbound neutronMeteringLabelRulesNorthbound;
49     private final NeutronVpnServicesNorthbound neutronVpnServicesNorthbound;
50     private final NeutronVpnIkePoliciesNorthbound neutronVpnIkePoliciesNorthbound;
51     private final NeutronVpnIpSecPoliciesNorthbound neutronVpnIpSecPoliciesNorthbound;
52     private final NeutronVpnIpSecSiteConnectionsNorthbound neutronVpnIpSecSiteConnectionsNorthbound;
53     private final NeutronSFCFlowClassifiersNorthbound neutronSFCFlowClassifiersNorthbound;
54     private final NeutronSFCPortChainsNorthbound neutronSFCPortChainsNorthbound;
55     private final NeutronSFCPortPairGroupsNorthbound neutronSFCPortPairGroupsNorthbound;
56     private final NeutronSFCPortPairsNorthbound neutronSFCPortPairsNorthbound;
57     private final NeutronQosPolicyNorthbound neutronQosPolicyNorthbound;
58     private final NeutronTrunksNorthbound neutronTrunksNorthbound;
59     private final NeutronTapServiceNorthbound neutronTapServiceNorthbound;
60     private final NeutronTapFlowNorthbound neutronTapFlowNorthbound;
61
62     @Inject
63     public NeutronNorthboundRSApplication(
64             NeutronNetworksNorthbound neutronNetworksNorthbound,
65             NeutronSubnetsNorthbound neutronSubnetsNorthbound,
66             NeutronPortsNorthbound neutronPortsNorthbound,
67             NeutronRoutersNorthbound neutronRoutersNorthbound,
68             NeutronFloatingIpsNorthbound neutronFloatingIpsNorthbound,
69             NeutronSecurityGroupsNorthbound neutronSecurityGroupsNorthbound,
70             NeutronSecurityRulesNorthbound neutronSecurityRulesNorthbound,
71             NeutronFirewallNorthbound neutronFirewallNorthbound,
72             NeutronFirewallPolicyNorthbound neutronFirewallPolicyNorthbound,
73             NeutronFirewallRulesNorthbound neutronFirewallRulesNorthbound,
74             NeutronLoadBalancerListenerNorthbound neutronLoadBalancerListenerNorthbound,
75             NeutronLoadBalancerNorthbound neutronLoadBalancerNorthbound,
76             NeutronLoadBalancerPoolNorthbound neutronLoadBalancerPoolNorthbound,
77             NeutronBgpvpnsNorthbound neutronBgpvpnsNorthbound,
78             NeutronL2gatewayNorthbound neutronL2gatewayNorthbound,
79             NeutronL2gatewayConnectionNorthbound neutronL2gatewayConnectionNorthbound,
80             NeutronLoadBalancerHealthMonitorNorthbound neutronLoadBalancerHealthMonitorNorthbound,
81             NeutronMeteringLabelsNorthbound neutronMeteringLabelsNorthbound,
82             NeutronMeteringLabelRulesNorthbound neutronMeteringLabelRulesNorthbound,
83             NeutronVpnServicesNorthbound neutronVpnServicesNorthbound,
84             NeutronVpnIkePoliciesNorthbound neutronVpnIkePoliciesNorthbound,
85             NeutronVpnIpSecSiteConnectionsNorthbound neutronVpnIpSecSiteConnectionsNorthbound,
86             NeutronVpnIpSecPoliciesNorthbound neutronVpnIpSecPoliciesNorthbound,
87             NeutronSFCFlowClassifiersNorthbound neutronSFCFlowClassifiersNorthbound,
88             NeutronSFCPortChainsNorthbound neutronSFCPortChainsNorthbound,
89             NeutronSFCPortPairGroupsNorthbound neutronSFCPortPairGroupsNorthbound,
90             NeutronSFCPortPairsNorthbound neutronSFCPortPairsNorthbound,
91             NeutronQosPolicyNorthbound neutronQosPolicyNorthbound,
92             NeutronTrunksNorthbound neutronTrunksNorthbound,
93             NeutronTapServiceNorthbound neutronTapServiceNorthbound,
94             NeutronTapFlowNorthbound neutronTapFlowNorthbound) {
95
96         this.neutronNetworksNorthbound = neutronNetworksNorthbound;
97         this.neutronSubnetsNorthbound = neutronSubnetsNorthbound;
98         this.neutronPortsNorthbound = neutronPortsNorthbound;
99         this.neutronRoutersNorthbound = neutronRoutersNorthbound;
100         this.neutronFloatingIpsNorthbound = neutronFloatingIpsNorthbound;
101         this.neutronSecurityGroupsNorthbound = neutronSecurityGroupsNorthbound;
102         this.neutronSecurityRulesNorthbound = neutronSecurityRulesNorthbound;
103         this.neutronFirewallNorthbound = neutronFirewallNorthbound;
104         this.neutronFirewallRulesNorthbound = neutronFirewallRulesNorthbound;
105         this.neutronLoadBalancerListenerNorthbound = neutronLoadBalancerListenerNorthbound;
106         this.neutronLoadBalancerNorthbound = neutronLoadBalancerNorthbound;
107         this.neutronFirewallPolicyNorthbound = neutronFirewallPolicyNorthbound;
108         this.neutronLoadBalancerPoolNorthbound = neutronLoadBalancerPoolNorthbound;
109         this.neutronBgpvpnsNorthbound = neutronBgpvpnsNorthbound;
110         this.neutronL2gatewayNorthbound = neutronL2gatewayNorthbound;
111         this.neutronL2gatewayConnectionNorthbound = neutronL2gatewayConnectionNorthbound;
112         this.neutronLoadBalancerHealthMonitorNorthbound = neutronLoadBalancerHealthMonitorNorthbound;
113         this.neutronMeteringLabelsNorthbound = neutronMeteringLabelsNorthbound;
114         this.neutronMeteringLabelRulesNorthbound = neutronMeteringLabelRulesNorthbound;
115         this.neutronVpnServicesNorthbound = neutronVpnServicesNorthbound;
116         this.neutronVpnIkePoliciesNorthbound = neutronVpnIkePoliciesNorthbound;
117         this.neutronVpnIpSecSiteConnectionsNorthbound = neutronVpnIpSecSiteConnectionsNorthbound;
118         this.neutronVpnIpSecPoliciesNorthbound = neutronVpnIpSecPoliciesNorthbound;
119         this.neutronSFCFlowClassifiersNorthbound = neutronSFCFlowClassifiersNorthbound;
120         this.neutronSFCPortChainsNorthbound = neutronSFCPortChainsNorthbound;
121         this.neutronSFCPortPairGroupsNorthbound = neutronSFCPortPairGroupsNorthbound;
122         this.neutronSFCPortPairsNorthbound = neutronSFCPortPairsNorthbound;
123         this.neutronQosPolicyNorthbound = neutronQosPolicyNorthbound;
124         this.neutronTrunksNorthbound = neutronTrunksNorthbound;
125         this.neutronTapServiceNorthbound = neutronTapServiceNorthbound;
126         this.neutronTapFlowNorthbound = neutronTapFlowNorthbound;
127     }
128
129     @Override
130     public Set<Class<?>> getClasses() {
131         return emptySet();
132     }
133
134     @Override
135     public Set<Object> getSingletons() {
136         return ImmutableSet.builderWithExpectedSize(32)
137                 .add(getMOXyJsonProvider())
138                 // Northbound URIs JAX RS Resources:
139                 .add(neutronNetworksNorthbound)
140                 .add(neutronSubnetsNorthbound)
141                 .add(neutronPortsNorthbound)
142                 .add(neutronRoutersNorthbound)
143                 .add(neutronFloatingIpsNorthbound)
144                 .add(neutronSecurityGroupsNorthbound)
145                 .add(neutronSecurityRulesNorthbound)
146                 .add(neutronFirewallNorthbound)
147                 .add(neutronFirewallPolicyNorthbound)
148                 .add(neutronFirewallRulesNorthbound)
149                 .add(neutronLoadBalancerNorthbound)
150                 .add(neutronLoadBalancerListenerNorthbound)
151                 .add(neutronLoadBalancerPoolNorthbound)
152                 .add(neutronLoadBalancerHealthMonitorNorthbound)
153                 .add(neutronMeteringLabelsNorthbound)
154                 .add(neutronMeteringLabelRulesNorthbound)
155                 .add(neutronVpnServicesNorthbound)
156                 .add(neutronVpnIkePoliciesNorthbound)
157                 .add(neutronVpnIpSecPoliciesNorthbound)
158                 .add(neutronVpnIpSecSiteConnectionsNorthbound)
159                 .add(neutronBgpvpnsNorthbound)
160                 .add(neutronL2gatewayNorthbound)
161                 .add(neutronL2gatewayConnectionNorthbound)
162                 .add(neutronSFCFlowClassifiersNorthbound)
163                 .add(neutronSFCPortPairsNorthbound)
164                 .add(neutronSFCPortPairGroupsNorthbound)
165                 .add(neutronSFCPortChainsNorthbound)
166                 .add(neutronQosPolicyNorthbound)
167                 .add(neutronTrunksNorthbound)
168                 .add(neutronTapServiceNorthbound)
169                 .add(neutronTapFlowNorthbound)
170                 .build();
171     }
172
173     private MOXyJsonProvider getMOXyJsonProvider() {
174         MOXyJsonProvider moxyJsonProvider = new MOXyJsonProvider();
175
176         moxyJsonProvider.setAttributePrefix("@");
177         moxyJsonProvider.setFormattedOutput(true);
178         moxyJsonProvider.setIncludeRoot(false);
179         moxyJsonProvider.setMarshalEmptyCollections(true);
180         moxyJsonProvider.setValueWrapper("$");
181
182         Map<String, String> namespacePrefixMapper = new HashMap<>(HASHMAP_SIZE);
183         // FIXME: fill in next two with XSD
184         namespacePrefixMapper.put("router", "router");
185         namespacePrefixMapper.put("provider", "provider");
186         namespacePrefixMapper.put("binding", "binding");
187         moxyJsonProvider.setNamespacePrefixMapper(namespacePrefixMapper);
188         moxyJsonProvider.setNamespaceSeparator(':');
189
190         return moxyJsonProvider;
191     }
192 }