split single and plural graph inventory uris
[so.git] / common / src / main / java / org / onap / so / client / graphinventory / entities / uri / SimpleUri.java
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.so.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.so.client.graphinventory.GraphInventoryObjectPlurals;
29 import org.onap.so.client.graphinventory.GraphInventoryObjectType;
30
31 public abstract class SimpleUri<T extends GraphInventorySingleResourceUri<?, ?, ?, ?>, PT extends GraphInventoryPluralResourceUri<?, ?>, S extends GraphInventoryObjectType, P extends GraphInventoryObjectPlurals>
32         extends SimpleBaseUri<T, T, S> implements GraphInventorySingleResourceUri<T, PT, S, P> {
33
34     private static final long serialVersionUID = -337701171277616439L;
35     protected static final String relationshipAPI = "/relationship-list/relationship";
36     protected static final String relatedTo = "/related-to";
37
38     protected SimpleUri(S type, Object... values) {
39         super(type, values);
40     }
41
42     protected SimpleUri(S type, URI uri) {
43         super(type, uri);
44
45     }
46
47     protected SimpleUri(S type, UriBuilder builder, Object... values) {
48         super(type, builder, values);
49
50     }
51
52     protected SimpleUri(T parentUri, S childType, Object... childValues) {
53         super(parentUri, childType, childValues);
54     }
55
56     protected SimpleUri(SimpleBaseUri<T, T, S> copy) {
57         super(copy);
58     }
59
60     @Override
61     public T resourceVersion(String version) {
62         this.internalURI = internalURI.replaceQueryParam("resource-version", version);
63         return (T) this;
64     }
65
66     @Override
67     public T relationshipAPI() {
68         this.internalURI = internalURI.path(relationshipAPI);
69         return (T) this;
70     }
71
72     private void writeObject(ObjectOutputStream oos) throws IOException {
73         oos.defaultWriteObject();
74         oos.writeUTF(this.internalURI.toTemplate());
75     }
76
77     private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
78         ois.defaultReadObject();
79         String uri = ois.readUTF();
80         this.setInternalURI(UriBuilder.fromUri(uri));
81     }
82
83 }