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