AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-deforg / src / main / java / org / onap / aaf / org / Identities.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 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  ******************************************************************************/
22 package org.onap.aaf.org;
23
24 import java.io.File;
25 import java.io.IOException;
26
27 import org.onap.aaf.auth.local.AbsData;
28 import org.onap.aaf.auth.local.DataFile.Token.Field;
29
30 /*
31  * Example User Data file, which can be modified for many different kinds of Data Feeds.
32  * 
33  * Note: This has shown to be extremely effective in AT&T, an acknowledged very large organizations, 
34  *           because there is no need to synchronize records.  AAF simply receives a Data Feed in Organization
35  *               defined intervals.  (You might want to check for validity, such as size, etc), then is copied into
36  *               Data Directory.  You will want to do so first creating a "lock" file.  Assuming the File name is "users.dat",
37  *               the Lock File is "users.lock".  
38  * 
39  *               After the movement of the Datafile into place, it is best to remove the Index File, then remove the lock file.
40  * 
41  *               Note, Any AAF Programs needing this data WILL wait on the Lock file, so you should get fresh Data files
42  *       in a "stage" directory, from WEB, or wherever, and then, after it is correct, do the following as fast as feasible.
43  *       
44  *              a) lock
45  *          b) copy from stage
46  *          c) remove idx
47  *          d) unlock
48  * 
49  *           If the Index File is either non-existent or out of date from the Data File, it will be reindexed, which
50  *               has proven to be a very quick function, even with large numbers of entries.
51  * 
52  * This Sample Feed is set for a file with delimiter of "|".  512 is maximum expected line length. The "0" is the
53  *       field offset for the "key" to the record,  which, for user, should be the unique Organization Identity.
54  *       
55  */
56 public class Identities extends AbsData {
57         public final static Data NO_DATA = new Data();
58         
59         public Identities(File users) {
60                 super(users,'|',512,0);
61         }
62
63         /*
64          * Example Field Layout.  note, in this example, Application IDs and People IDs are mixed.  You may want to split
65          *   out AppIDs, choose your own status indicators, or whatever you use.
66          * 0 - unique ID
67          * 1 - full name
68          * 2 - first name
69          * 3 - last name
70          * 4 - phone
71          * 5 - official email
72          * 6 - employment status e=employee, c=contractor, a=application, n=no longer with company
73          * 7 - responsible to (i.e Supervisor for People, or AppOwner, if it's an App ID)
74          */
75         public static class Data {
76                 public final String id;
77                 public final String name;
78                 public final String fname;
79                 public final String lname;
80                 public final String phone;
81                 public final String email;
82                 public final String status;
83                 public final String responsibleTo;
84                 
85                 private Data(Field f) {
86                         f.reset();
87                         id=f.next();
88                         name=f.next();
89                         fname=f.next();
90                         lname=f.next();
91                         phone=f.next();
92                         email=f.next();
93                         status=f.next();
94                         responsibleTo =f.next();
95                 }
96                 
97                 private Data() {
98                         id = name = fname = lname =
99                         phone = email = status = responsibleTo 
100                         = "";
101                 }
102
103                 public String toString() {
104                         return  id + '|' +
105                                         name + '|' +
106                                         lname + '|' +
107                                         fname + '|' +
108                                         phone + '|' +
109                                         email + '|' +
110                                         status + '|' +
111                                         responsibleTo;
112                 }
113                 
114                 // Here, make up your own Methods which help you easily determine your Organization's structure
115                 // in your Organization Object
116         public boolean hasStatus(String possible) {
117             return possible.contains(status);
118             }
119
120             public boolean isEmployee() {
121                     return "e".equals(status);
122             }
123         
124             public boolean isContractor() {
125                     return "c".equals(status);
126             }
127         
128             public boolean isApplication() {
129                     return "a".equals(status);
130             }
131         }
132         
133     public Data find(Object key,Reuse r) throws IOException {
134         r.reset();
135         // These are new, to allow for Thread Safety
136         int rec = ti.find(key,r,0);
137         if(rec<0) {
138             return null;
139         }
140         r.pos(rec);
141                 return new Data(r.getFieldData());
142     }
143 }