570856d7f4402ea28ea46498e4ca8749dc780b63
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.aaiclient.client.graphinventory.entities.uri;
22
23 import java.io.IOException;
24 import java.io.ObjectInputStream;
25 import java.io.ObjectOutputStream;
26 import java.net.URI;
27 import javax.ws.rs.core.UriBuilder;
28 import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectPlurals;
29 import org.onap.aaiclient.client.graphinventory.GraphInventoryObjectType;
30 import org.onap.aaiclient.client.graphinventory.GraphInventoryPluralFragment;
31 import org.onap.aaiclient.client.graphinventory.GraphInventorySingleFragment;
32
33 public abstract class SimpleUri<T extends GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?>, PT extends GraphInventoryPluralResourceUri<?, ?>, S extends GraphInventoryObjectType, P extends GraphInventoryObjectPlurals, SF extends GraphInventorySingleFragment<?>, PF extends GraphInventoryPluralFragment<?>>
34         extends SimpleBaseUri<T, T, S> implements GraphInventorySingleResourceUri<T, PT, S, P, SF, PF> {
35
36     private static final long serialVersionUID = -337701171277616439L;
37     protected static final String relationshipAPI = "/relationship-list/relationship";
38     protected static final String relatedTo = "/related-to";
39
40     protected SimpleUri(S type, Object... values) {
41         super(type, values);
42     }
43
44     protected SimpleUri(S type, URI uri) {
45         super(type, uri);
46
47     }
48
49     protected SimpleUri(S type, UriBuilder builder, Object... values) {
50         super(type, builder, values);
51
52     }
53
54     protected SimpleUri(T parentUri, S childType, Object... childValues) {
55         super(parentUri, childType, childValues);
56     }
57
58     protected SimpleUri(SimpleBaseUri<T, T, S> copy) {
59         super(copy);
60     }
61
62     @Override
63     public T resourceVersion(String version) {
64         this.internalURI = internalURI.replaceQueryParam("resource-version", version);
65         return (T) this;
66     }
67
68     @Override
69     public T relationshipAPI() {
70         this.internalURI = internalURI.path(relationshipAPI);
71         return (T) this;
72     }
73
74     private void writeObject(ObjectOutputStream oos) throws IOException {
75         oos.defaultWriteObject();
76         oos.writeUTF(this.internalURI.toTemplate());
77     }
78
79     private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
80         ois.defaultReadObject();
81         String uri = ois.readUTF();
82         this.setInternalURI(UriBuilder.fromUri(uri));
83     }
84
85 }