2
2
3
3
import de .filefighter .rest .domain .filesystem .data .persistence .FileSystemEntity ;
4
4
import de .filefighter .rest .domain .filesystem .data .persistence .FileSystemRepository ;
5
- import de .filefighter .rest .domain .filesystem .type .FileSystemType ;
6
5
import de .filefighter .rest .domain .token .business .AccessTokenBusinessService ;
7
6
import de .filefighter .rest .domain .token .data .persistence .AccessTokenEntity ;
8
7
import de .filefighter .rest .domain .token .data .persistence .AccessTokenRepository ;
17
16
18
17
import java .time .Instant ;
19
18
19
+ import static de .filefighter .rest .domain .filesystem .type .FileSystemType .FOLDER ;
20
+ import static de .filefighter .rest .domain .filesystem .type .FileSystemType .TEXT ;
21
+ import static de .filefighter .rest .domain .user .group .Groups .*;
22
+
20
23
@ Log4j2
21
24
@ Configuration
22
25
public class PrepareDataBase {
@@ -70,18 +73,31 @@ CommandLineRunner cleanDataBase(UserRepository userRepository, FileSystemReposit
70
73
};
71
74
}
72
75
76
+ @ Bean
77
+ CommandLineRunner createRuntimeUser (UserRepository userRepository ) {
78
+ return args -> log .info ("Preloading system runtime user. {}" , userRepository .save (UserEntity
79
+ .builder ()
80
+ .userId (0L )
81
+ .username ("FileFighter" )
82
+ .lowercaseUsername ("filefighter" )
83
+ .password (null )
84
+ .refreshToken (null )
85
+ .groupIds (new long []{SYSTEM .getGroupId ()})
86
+ .build ()));
87
+ }
88
+
73
89
@ Bean
74
90
@ Profile ("prod" )
75
91
CommandLineRunner initDataBaseProd (UserRepository userRepository , FileSystemRepository fileSystemRepository ) {
76
92
return args -> {
77
93
log .info ("Preloading default admin user: {}." , userRepository .save (UserEntity
78
94
.builder ()
79
- .userId (0L )
95
+ .userId (1L )
80
96
.username ("Admin" )
81
97
.lowercaseUsername ("admin" )
82
98
.password ("admin" )
83
99
.refreshToken ("refreshToken1234" )
84
- .groupIds (new long []{0 , 1 })
100
+ .groupIds (new long []{FAMILY . getGroupId (), ADMIN . getGroupId () })
85
101
.build ()));
86
102
87
103
log .info ("Preloading default fsStructure: {} {}." , fileSystemRepository .save (FileSystemEntity
@@ -92,22 +108,22 @@ CommandLineRunner initDataBaseProd(UserRepository userRepository, FileSystemRepo
92
108
.path ("/" )
93
109
.itemIds (new long [0 ])
94
110
.lastUpdated (Instant .now ().getEpochSecond ())
95
- .name ("root " )
111
+ .name ("HOME_Admin " )
96
112
.size (0 )
97
- .typeId (FileSystemType . FOLDER .getId ())
98
- .visibleForGroupIds (new long []{- 1 , 0 , 1 })
113
+ .typeId (FOLDER .getId ())
114
+ .visibleForGroupIds (new long []{UNDEFINED . getGroupId (), FAMILY . getGroupId (), ADMIN . getGroupId () })
99
115
.itemIds (new long []{1 })
100
116
.build ()),
101
117
fileSystemRepository .save (FileSystemEntity .builder ()
102
- .createdByUserId (0 )
118
+ .createdByUserId (1 )
103
119
.fileSystemId (1 )
104
120
.isFile (true )
105
121
.lastUpdated (Instant .now ().getEpochSecond ())
106
122
.name ("dummyFile.txt" )
107
123
.size (420 )
108
- .typeId (FileSystemType . TEXT .getId ())
109
- .editableFoGroupIds (new long []{0 })
110
- .visibleForGroupIds (new long []{0 })
124
+ .typeId (TEXT .getId ())
125
+ .editableFoGroupIds (new long []{FAMILY . getGroupId () })
126
+ .visibleForGroupIds (new long []{FAMILY . getGroupId () })
111
127
.build ()));
112
128
113
129
log .info ("Inserting Users {}" , (userRepository .findAll ().size () == 1 ? MESSAGE_ON_SUCCESS : MESSAGE_ON_FAILURE ));
@@ -122,33 +138,33 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
122
138
log .info ("Preloading default users: {} {}." ,
123
139
userRepository .save (UserEntity
124
140
.builder ()
125
- .userId (0 )
141
+ .userId (1 )
126
142
.username ("user" )
127
143
.lowercaseUsername ("user" )
128
144
.password ("1234" )
129
145
.refreshToken ("rft1234" )
130
- .groupIds (new long []{1 })
146
+ .groupIds (new long []{ADMIN . getGroupId () })
131
147
.build ()),
132
148
userRepository .save (UserEntity
133
149
.builder ()
134
- .userId (1 )
150
+ .userId (2 )
135
151
.username ("user1" )
136
152
.lowercaseUsername ("user1" )
137
153
.password ("12345" )
138
154
.refreshToken ("rft" )
139
- .groupIds (new long []{0 })
155
+ .groupIds (new long []{FAMILY . getGroupId () })
140
156
.build ()));
141
157
142
158
log .info ("Preloading default tokens: {} {}" ,
143
159
accessTokenRepository .save (AccessTokenEntity
144
160
.builder ()
145
- .userId (0 )
161
+ .userId (1 )
146
162
.value ("token" )
147
163
.validUntil (Instant .now ().getEpochSecond () + AccessTokenBusinessService .ACCESS_TOKEN_DURATION_IN_SECONDS )
148
164
.build ()),
149
165
accessTokenRepository .save (AccessTokenEntity
150
166
.builder ()
151
- .userId (1 )
167
+ .userId (2 )
152
168
.value ("token1234" )
153
169
.validUntil (Instant .now ().getEpochSecond () + AccessTokenBusinessService .ACCESS_TOKEN_DURATION_IN_SECONDS )
154
170
.build ()));
@@ -163,30 +179,30 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
163
179
.lastUpdated (Instant .now ().getEpochSecond ())
164
180
.name ("HOME_User" )
165
181
.size (420 )
166
- .typeId (FileSystemType . FOLDER .getId ())
167
- .visibleForGroupIds (new long []{0 , 1 })
182
+ .typeId (FOLDER .getId ())
183
+ .visibleForGroupIds (new long []{FAMILY . getGroupId (), ADMIN . getGroupId () })
168
184
.build ()),
169
185
fileSystemRepository .save (FileSystemEntity .builder ()
170
- .createdByUserId (1 )
186
+ .createdByUserId (0 )
171
187
.fileSystemId (1 )
172
188
.isFile (false )
173
189
.path ("/" )
174
190
.lastUpdated (Instant .now ().getEpochSecond ())
175
191
.name ("HOME_User1" )
176
192
.size (420 )
177
- .typeId (FileSystemType . FOLDER .getId ())
178
- .visibleForGroupIds (new long []{- 1 , 0 , 1 })
193
+ .typeId (FOLDER .getId ())
194
+ .visibleForGroupIds (new long []{UNDEFINED . getGroupId (), FAMILY . getGroupId (), ADMIN . getGroupId () })
179
195
.build ()),
180
196
fileSystemRepository .save (FileSystemEntity .builder ()
181
- .createdByUserId (0 )
197
+ .createdByUserId (1 )
182
198
.fileSystemId (2 )
183
199
.isFile (true )
184
200
.lastUpdated (Instant .now ().getEpochSecond ())
185
201
.name ("dummyFile.txt" )
186
202
.size (420 )
187
- .typeId (FileSystemType . TEXT .getId ())
188
- .editableFoGroupIds (new long []{0 })
189
- .visibleForGroupIds (new long []{0 })
203
+ .typeId (TEXT .getId ())
204
+ .editableFoGroupIds (new long []{FAMILY . getGroupId () })
205
+ .visibleForGroupIds (new long []{FAMILY . getGroupId () })
190
206
.build ()));
191
207
192
208
log .info ("Inserting FileSystemItems {}" , (fileSystemRepository .findAll ().size () == 3 ? MESSAGE_ON_SUCCESS : MESSAGE_ON_FAILURE ));
0 commit comments