2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 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====================================================
22 package org.onap.aaf.auth.dao.cass;
24 import java.io.ByteArrayOutputStream;
25 import java.io.DataInputStream;
26 import java.io.DataOutputStream;
27 import java.io.IOException;
28 import java.nio.ByteBuffer;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map.Entry;
33 import org.onap.aaf.auth.dao.Bytification;
34 import org.onap.aaf.auth.dao.CassDAOImpl;
35 import org.onap.aaf.auth.dao.Loader;
36 import org.onap.aaf.auth.rserv.Pair;
39 public class Namespace implements Bytification {
40 public static final int MAGIC=250935515;
41 public static final int VERSION=1;
42 public static final int BUFF_SIZE=48;
45 public List<String> owner;
46 public List<String> admin;
47 public List<Pair<String,String>> attrib;
48 public String description;
53 public Namespace(NsDAO.Data ndd) {
55 description = ndd.description;
58 if (ndd.attrib!=null && !ndd.attrib.isEmpty()) {
59 attrib = new ArrayList<>();
60 for ( Entry<String, String> entry : ndd.attrib.entrySet()) {
61 attrib.add(new Pair<String,String>(entry.getKey(),entry.getValue()));
66 public Namespace(NsDAO.Data ndd,List<String> owner, List<String> admin) {
70 description = ndd.description;
73 if (ndd.attrib!=null && !ndd.attrib.isEmpty()) {
74 attrib = new ArrayList<>();
75 for ( Entry<String, String> entry : ndd.attrib.entrySet()) {
76 attrib.add(new Pair<String,String>(entry.getKey(),entry.getValue()));
81 public NsDAO.Data data() {
82 NsDAO.Data ndd = new NsDAO.Data();
84 ndd.description = description;
91 public ByteBuffer bytify() throws IOException {
92 ByteArrayOutputStream baos = new ByteArrayOutputStream();
93 DataOutputStream os = new DataOutputStream(baos);
95 Loader.writeHeader(os,MAGIC,VERSION);
96 Loader.writeString(os, name);
98 Loader.writeStringSet(os,admin);
99 Loader.writeStringSet(os,owner);
100 Loader.writeString(os,description);
101 Loader.writeString(os,parent);
103 return ByteBuffer.wrap(baos.toByteArray());
107 public void reconstitute(ByteBuffer bb) throws IOException {
108 DataInputStream is = CassDAOImpl.toDIS(bb);
109 /*int version = */Loader.readHeader(is,MAGIC,VERSION);
110 // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields
112 byte[] buff = new byte[BUFF_SIZE];
113 name = Loader.readString(is, buff);
115 admin = Loader.readStringList(is,buff);
116 owner = Loader.readStringList(is,buff);
117 description = Loader.readString(is,buff);
118 parent = Loader.readString(is,buff);
123 * @see java.lang.Object#hashCode()
126 public int hashCode() {
127 return name.hashCode();
132 * @see java.lang.Object#toString()
135 public String toString() {
136 return name.toString();
140 * @see java.lang.Object#equals(java.lang.Object)
143 public boolean equals(Object arg0) {
144 if (arg0==null || !(arg0 instanceof Namespace)) {
147 return name.equals(((Namespace)arg0).name);