2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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=========================================================
21 package org.onap.aai.serialization.queryformats;
23 import org.onap.aai.exceptions.AAIException;
24 import org.onap.aai.introspection.Loader;
25 import org.onap.aai.serialization.db.DBSerializer;
26 import org.onap.aai.serialization.queryformats.exceptions.QueryParamInjectionException;
27 import org.onap.aai.serialization.queryformats.utils.QueryParamInjector;
28 import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
29 import org.onap.aai.setup.SchemaVersions;
31 import javax.ws.rs.core.MultivaluedHashMap;
32 import javax.ws.rs.core.MultivaluedMap;
34 public class FormatFactory {
36 private final Loader loader;
37 private final DBSerializer serializer;
38 private final UrlBuilder urlBuilder;
39 private final QueryParamInjector injector;
41 public FormatFactory(Loader loader, DBSerializer serializer, SchemaVersions schemaVersions, String basePath)
44 this.serializer = serializer;
45 this.urlBuilder = new UrlBuilder(loader.getVersion(), serializer, schemaVersions, basePath);
46 this.injector = QueryParamInjector.getInstance();
49 public FormatFactory(Loader loader, DBSerializer serializer, SchemaVersions schemaVersions, String basePath, String serverBase)
52 this.serializer = serializer;
53 this.urlBuilder = new UrlBuilder(loader.getVersion(), serializer, serverBase, schemaVersions, basePath);
54 this.injector = QueryParamInjector.getInstance();
57 public Formatter get(Format format) throws AAIException {
58 return get(format, new MultivaluedHashMap<>());
61 public Formatter get(Format format, MultivaluedMap<String, String> params) throws AAIException {
63 Formatter formatter = null;
67 formatter = new Formatter(inject(new GraphSON(), params));
70 formatter = new Formatter(inject(new PathedURL.Builder(loader, serializer, urlBuilder), params).build(), params);
72 case pathed_resourceversion:
73 formatter = new Formatter(inject(new PathedURL.Builder(loader, serializer, urlBuilder).includeUrl(), params).build(), params);
76 formatter = new Formatter(inject(new IdURL.Builder(loader, serializer, urlBuilder), params).build(), params);
79 formatter = new Formatter(inject(new Resource.Builder(loader, serializer, urlBuilder, params), params).build(), params);
81 case resource_and_url:
82 formatter = new Formatter(
83 inject(new Resource.Builder(loader, serializer, urlBuilder, params).includeUrl(), params).build(), params);
87 new Formatter(inject(new RawFormat.Builder(loader, serializer, urlBuilder), params).build(), params);
90 formatter = new Formatter(
91 inject(new RawFormat.Builder(loader, serializer, urlBuilder).depth(0).modelDriven(), params)
95 formatter = new Formatter(
96 inject(new Aggregate.Builder(loader, serializer, urlBuilder).depth(0).modelDriven(), params)
100 formatter = new Formatter(inject(new Console(), params));
103 formatter = new Formatter(inject(new Count(), params));
105 case resource_with_sot:
106 formatter = new Formatter(
107 inject(new ResourceWithSoT.Builder(loader, serializer, urlBuilder), params).build(), params);
111 new Formatter(inject(new ChangesFormat(), params));
115 new Formatter(inject(new StateFormat.Builder(loader, serializer, urlBuilder), params).build(format));
119 new Formatter(inject(new LifecycleFormat.Builder(loader, serializer, urlBuilder), params).build(format));
122 formatter = new Formatter(
123 inject(new TreeFormat.Builder(loader, serializer, urlBuilder), params).build());
133 private <T> T inject(T obj, MultivaluedMap<String, String> params) throws QueryParamInjectionException {
135 injector.injectParams(obj, params);