1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.dao.aaf.cass;
\r
25 import java.io.ByteArrayOutputStream;
\r
26 import java.io.DataInputStream;
\r
27 import java.io.DataOutputStream;
\r
28 import java.io.IOException;
\r
29 import java.nio.ByteBuffer;
\r
30 import java.util.ArrayList;
\r
31 import java.util.List;
\r
32 import java.util.Map.Entry;
\r
34 import org.onap.aaf.cssa.rserv.Pair;
\r
35 import org.onap.aaf.dao.Bytification;
\r
36 import org.onap.aaf.dao.CassDAOImpl;
\r
37 import org.onap.aaf.dao.Loader;
\r
40 public class Namespace implements Bytification {
\r
41 public static final int MAGIC=250935515;
\r
42 public static final int VERSION=1;
\r
43 public static final int BUFF_SIZE=48;
\r
46 public List<String> owner;
\r
47 public List<String> admin;
\r
48 public List<Pair<String,String>> attrib;
\r
49 public String description;
\r
50 public Integer type;
\r
51 public String parent;
\r
52 public Namespace() {}
\r
54 public Namespace(NsDAO.Data ndd) {
\r
56 description = ndd.description;
\r
58 parent = ndd.parent;
\r
59 if(ndd.attrib!=null && !ndd.attrib.isEmpty()) {
\r
60 attrib = new ArrayList<Pair<String,String>>();
\r
61 for( Entry<String, String> entry : ndd.attrib.entrySet()) {
\r
62 attrib.add(new Pair<String,String>(entry.getKey(),entry.getValue()));
\r
67 public Namespace(NsDAO.Data ndd,List<String> owner, List<String> admin) {
\r
71 description = ndd.description;
\r
73 parent = ndd.parent;
\r
74 if(ndd.attrib!=null && !ndd.attrib.isEmpty()) {
\r
75 attrib = new ArrayList<Pair<String,String>>();
\r
76 for( Entry<String, String> entry : ndd.attrib.entrySet()) {
\r
77 attrib.add(new Pair<String,String>(entry.getKey(),entry.getValue()));
\r
82 public NsDAO.Data data() {
\r
83 NsDAO.Data ndd = new NsDAO.Data();
\r
85 ndd.description = description;
\r
86 ndd.parent = parent;
\r
92 public ByteBuffer bytify() throws IOException {
\r
93 ByteArrayOutputStream baos = new ByteArrayOutputStream();
\r
94 DataOutputStream os = new DataOutputStream(baos);
\r
96 Loader.writeHeader(os,MAGIC,VERSION);
\r
97 Loader.writeString(os, name);
\r
99 Loader.writeStringSet(os,admin);
\r
100 Loader.writeStringSet(os,owner);
\r
101 Loader.writeString(os,description);
\r
102 Loader.writeString(os,parent);
\r
104 return ByteBuffer.wrap(baos.toByteArray());
\r
108 public void reconstitute(ByteBuffer bb) throws IOException {
\r
109 DataInputStream is = CassDAOImpl.toDIS(bb);
\r
110 /*int version = */Loader.readHeader(is,MAGIC,VERSION);
\r
111 // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields
\r
113 byte[] buff = new byte[BUFF_SIZE];
\r
114 name = Loader.readString(is, buff);
\r
115 type = is.readInt();
\r
116 admin = Loader.readStringList(is,buff);
\r
117 owner = Loader.readStringList(is,buff);
\r
118 description = Loader.readString(is,buff);
\r
119 parent = Loader.readString(is,buff);
\r
124 * @see java.lang.Object#hashCode()
\r
127 public int hashCode() {
\r
128 return name.hashCode();
\r
133 * @see java.lang.Object#toString()
\r
136 public String toString() {
\r
137 return name.toString();
\r
141 * @see java.lang.Object#equals(java.lang.Object)
\r
144 public boolean equals(Object arg0) {
\r
145 if(arg0==null || !(arg0 instanceof Namespace)) {
\r
148 return name.equals(((Namespace)arg0).name);
\r