2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.serialization.queryformats;
24 import javax.ws.rs.core.MultivaluedHashMap;
25 import javax.ws.rs.core.MultivaluedMap;
27 import org.onap.aai.exceptions.AAIException;
28 import org.onap.aai.introspection.Loader;
29 import org.onap.aai.serialization.db.DBSerializer;
30 import org.onap.aai.serialization.queryformats.exceptions.QueryParamInjectionException;
31 import org.onap.aai.serialization.queryformats.utils.QueryParamInjector;
32 import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
34 import javax.ws.rs.core.MultivaluedHashMap;
35 import javax.ws.rs.core.MultivaluedMap;
37 public class FormatFactory {
39 private final Loader loader;
40 private final DBSerializer serializer;
41 private final UrlBuilder urlBuilder;
42 private final QueryParamInjector injector;
43 public FormatFactory (Loader loader, DBSerializer serializer) throws AAIException {
45 this.serializer = serializer;
46 this.urlBuilder = new UrlBuilder(loader.getVersion(), serializer);
47 this.injector = QueryParamInjector.getInstance();
50 public Formatter get(Format format) throws AAIException {
51 return get(format, new MultivaluedHashMap<String, String>());
54 public Formatter get(Format format, MultivaluedMap<String, String> params) throws AAIException {
56 Formatter formatter = null;
60 formatter = new Formatter(inject(new GraphSON(), params));
63 formatter = new Formatter(inject(new PathedURL(loader, urlBuilder), params));
66 formatter = new Formatter(inject(new IdURL(loader, urlBuilder), params));
69 formatter = new Formatter(inject(new Resource.Builder(loader, serializer, urlBuilder), params).build());
71 case resource_and_url :
72 formatter = new Formatter(inject(new Resource.Builder(loader, serializer, urlBuilder).includeUrl(), params).build());
75 formatter = new Formatter(inject(new RawFormat.Builder(loader, serializer, urlBuilder), params).build());
78 formatter = new Formatter(inject(new RawFormat.Builder(loader, serializer, urlBuilder).depth(0).modelDriven(), params).build());
81 formatter = new Formatter(inject(new Console(), params));
84 formatter = new Formatter(inject(new Count(), params));
94 private <T> T inject (T obj, MultivaluedMap<String, String> params) throws QueryParamInjectionException {
96 injector.injectParams(obj, params);