2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.serialization.queryformats;
23 import javax.ws.rs.core.MultivaluedHashMap;
24 import javax.ws.rs.core.MultivaluedMap;
26 import org.openecomp.aai.exceptions.AAIException;
27 import org.openecomp.aai.introspection.Loader;
28 import org.openecomp.aai.serialization.db.DBSerializer;
29 import org.openecomp.aai.serialization.queryformats.exceptions.QueryParamInjectionException;
30 import org.openecomp.aai.serialization.queryformats.utils.QueryParamInjector;
31 import org.openecomp.aai.serialization.queryformats.utils.UrlBuilder;
33 import javax.ws.rs.core.MultivaluedHashMap;
34 import javax.ws.rs.core.MultivaluedMap;
36 public class FormatFactory {
38 private final Loader loader;
39 private final DBSerializer serializer;
40 private final UrlBuilder urlBuilder;
41 private final QueryParamInjector injector;
42 public FormatFactory (Loader loader, DBSerializer serializer) throws AAIException {
44 this.serializer = serializer;
45 this.urlBuilder = new UrlBuilder(loader.getVersion(), serializer);
46 this.injector = QueryParamInjector.getInstance();
49 public Formatter get(Format format) throws AAIException {
50 return get(format, new MultivaluedHashMap<String, String>());
53 public Formatter get(Format format, MultivaluedMap<String, String> params) throws AAIException {
55 Formatter formattter = null;
59 formattter = new Formatter(inject(new GraphSON(), params));
62 formattter = new Formatter(inject(new PathedURL(loader, urlBuilder), params));
65 formattter = new Formatter(inject(new IdURL(loader, urlBuilder), params));
68 formattter = new Formatter(inject(new Resource.Builder(loader, serializer, urlBuilder), params).build());
70 case resource_and_url :
71 formattter = new Formatter(inject(new Resource.Builder(loader, serializer, urlBuilder).includeUrl(), params).build());
74 formattter = new Formatter(inject(new RawFormat.Builder(loader, serializer, urlBuilder), params).build());
77 formattter = new Formatter(inject(new RawFormat.Builder(loader, serializer, urlBuilder).depth(0).modelDriven(), params).build());
80 formattter = new Formatter(inject(new Console(), params));
90 private <T> T inject (T obj, MultivaluedMap<String, String> params) throws QueryParamInjectionException {
92 injector.injectParams(obj, params);