5
5
import static org .carlspring .strongbox .db .schema .Edges .ARTIFACT_HAS_ARTIFACT_COORDINATES ;
6
6
import static org .carlspring .strongbox .db .schema .Edges .ARTIFACT_HAS_TAGS ;
7
7
import static org .carlspring .strongbox .db .schema .Edges .EXTENDS ;
8
+ import static org .carlspring .strongbox .db .schema .Edges .USER_HAS_SECURITY_ROLES ;
8
9
import static org .carlspring .strongbox .db .schema .Properties .ARTIFACT_FILE_EXISTS ;
9
10
import static org .carlspring .strongbox .db .schema .Properties .CHECKSUMS ;
10
11
import static org .carlspring .strongbox .db .schema .Properties .COORDINATES_ABI ;
35
36
import static org .carlspring .strongbox .db .schema .Properties .NAME ;
36
37
import static org .carlspring .strongbox .db .schema .Properties .PASSWORD ;
37
38
import static org .carlspring .strongbox .db .schema .Properties .REPOSITORY_ID ;
38
- import static org .carlspring .strongbox .db .schema .Properties .ROLES ;
39
39
import static org .carlspring .strongbox .db .schema .Properties .SECURITY_TOKEN_KEY ;
40
40
import static org .carlspring .strongbox .db .schema .Properties .SIZE_IN_BYTES ;
41
41
import static org .carlspring .strongbox .db .schema .Properties .SOURCE_ID ;
53
53
import static org .carlspring .strongbox .db .schema .Vertices .PYPI_ARTIFACT_COORDINATES ;
54
54
import static org .carlspring .strongbox .db .schema .Vertices .RAW_ARTIFACT_COORDINATES ;
55
55
import static org .carlspring .strongbox .db .schema .Vertices .USER ;
56
- import static org .janusgraph . core . Multiplicity . ONE2MANY ;
56
+ import static org .carlspring . strongbox . db . schema . Vertices . SECURITY_ROLE ;
57
57
import static org .janusgraph .core .Multiplicity .MANY2ONE ;
58
58
import static org .janusgraph .core .Multiplicity .MULTI ;
59
+ import static org .janusgraph .core .Multiplicity .ONE2MANY ;
59
60
import static org .janusgraph .core .Multiplicity .ONE2ONE ;
60
61
61
62
import java .util .Arrays ;
@@ -135,9 +136,9 @@ public void createSchema(JanusGraph jg)
135
136
for (Entry <String , String > relationIndex : relationIndexes .entrySet ())
136
137
{
137
138
logger .info (String .format ("Wait index [%s] to be registered." , relationIndex .getKey ()));
138
- ManagementSystem .awaitRelationIndexStatus (jg , relationIndex .getKey (), relationIndex .getValue ()).call ();
139
+ ManagementSystem .awaitRelationIndexStatus (jg , relationIndex .getKey (), relationIndex .getValue ()).call ();
139
140
}
140
-
141
+
141
142
jgm = jg .openManagement ();
142
143
try
143
144
{
@@ -151,13 +152,12 @@ public void createSchema(JanusGraph jg)
151
152
jgm .rollback ();
152
153
throw new RuntimeException ("Failed to enable indexes." , e );
153
154
}
154
-
155
+
155
156
jgm = jg .openManagement ();
156
157
try
157
158
{
158
159
logger .info (String .format ("Schema: %n%s" , jgm .printSchema ()));
159
- }
160
- finally
160
+ } finally
161
161
{
162
162
jgm .rollback ();
163
163
}
@@ -174,7 +174,7 @@ protected void enableIndexes(JanusGraphManagement jgm,
174
174
jgm .updateIndex (jgm .getGraphIndex (janusGraphIndex ), SchemaAction .ENABLE_INDEX ).get ();
175
175
}
176
176
}
177
-
177
+
178
178
protected void enableRelationIndexes (JanusGraphManagement jgm ,
179
179
Map <String , String > indexes )
180
180
throws InterruptedException ,
@@ -184,15 +184,17 @@ protected void enableRelationIndexes(JanusGraphManagement jgm,
184
184
for (Entry <String , String > e : entrySet )
185
185
{
186
186
logger .info (String .format ("Enabling index [%s]." , e .getKey ()));
187
- jgm .updateIndex (jgm .getRelationIndex (jgm .getRelationType (e .getValue ()), e .getKey ()), SchemaAction .ENABLE_INDEX ).get ();
187
+ jgm .updateIndex (jgm .getRelationIndex (jgm .getRelationType (e .getValue ()), e .getKey ()),
188
+ SchemaAction .ENABLE_INDEX )
189
+ .get ();
188
190
}
189
191
}
190
192
191
193
protected Map <String , String > createRelationIndexes (JanusGraph jg ,
192
- JanusGraphManagement jgm )
194
+ JanusGraphManagement jgm )
193
195
{
194
196
Map <String , String > result = new HashMap <>();
195
-
197
+
196
198
String name = ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS + "By" + StringUtils .capitalize (TAG_NAME );
197
199
if (!jgm .containsGraphIndex (name ))
198
200
{
@@ -202,10 +204,10 @@ protected Map<String, String> createRelationIndexes(JanusGraph jg,
202
204
jgm .getPropertyKey (TAG_NAME ));
203
205
result .put (name , ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS );
204
206
}
205
-
207
+
206
208
return result ;
207
209
}
208
-
210
+
209
211
protected Set <String > createIndexes (JanusGraph jg ,
210
212
JanusGraphManagement jgm )
211
213
throws InterruptedException
@@ -244,7 +246,12 @@ protected Set<String> createIndexes(JanusGraph jg,
244
246
Vertex .class ,
245
247
jgm .getVertexLabel (USER ),
246
248
true ,
247
- jgm .getPropertyKey (UUID )).ifPresent (result ::add );
249
+ jgm .getPropertyKey (UUID )).ifPresent (result ::add );
250
+ buildIndexIfNecessary (jgm ,
251
+ Vertex .class ,
252
+ jgm .getVertexLabel (SECURITY_ROLE ),
253
+ true ,
254
+ jgm .getPropertyKey (UUID )).ifPresent (result ::add );
248
255
249
256
return result ;
250
257
}
@@ -265,13 +272,15 @@ private void applySchemaChanges(JanusGraphManagement jgm)
265
272
makeVertexLabelIfDoesNotExist (jgm , ARTIFACT_TAG );
266
273
makeVertexLabelIfDoesNotExist (jgm , ARTIFACT_ID_GROUP );
267
274
makeVertexLabelIfDoesNotExist (jgm , USER );
275
+ makeVertexLabelIfDoesNotExist (jgm , SECURITY_ROLE );
268
276
269
277
// Edges
270
278
makeEdgeLabelIfDoesNotExist (jgm , ARTIFACT_HAS_ARTIFACT_COORDINATES , MANY2ONE );
271
279
makeEdgeLabelIfDoesNotExist (jgm , ARTIFACT_HAS_TAGS , MULTI );
272
280
makeEdgeLabelIfDoesNotExist (jgm , EXTENDS , ONE2ONE );
273
281
makeEdgeLabelIfDoesNotExist (jgm , ARTIFACT_GROUP_HAS_ARTIFACTS , ONE2MANY );
274
282
makeEdgeLabelIfDoesNotExist (jgm , ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS , MULTI );
283
+ makeEdgeLabelIfDoesNotExist (jgm , USER_HAS_SECURITY_ROLES , MULTI );
275
284
276
285
// Add property constraints
277
286
applyPropertyConstraints (jgm );
@@ -293,7 +302,7 @@ private void applyConnectionConstraints(JanusGraphManagement jgm)
293
302
jgm .addConnection (jgm .getEdgeLabel (ARTIFACT_GROUP_HAS_ARTIFACTS ),
294
303
jgm .getVertexLabel (ARTIFACT_ID_GROUP ),
295
304
jgm .getVertexLabel (ARTIFACT ));
296
-
305
+
297
306
jgm .addConnection (jgm .getEdgeLabel (ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS ),
298
307
jgm .getVertexLabel (ARTIFACT_ID_GROUP ),
299
308
jgm .getVertexLabel (ARTIFACT ));
@@ -318,6 +327,10 @@ private void applyConnectionConstraints(JanusGraphManagement jgm)
318
327
jgm .getVertexLabel (PYPI_ARTIFACT_COORDINATES ),
319
328
jgm .getVertexLabel (GENERIC_ARTIFACT_COORDINATES ));
320
329
330
+ jgm .addConnection (jgm .getEdgeLabel (USER_HAS_SECURITY_ROLES ),
331
+ jgm .getVertexLabel (USER ),
332
+ jgm .getVertexLabel (SECURITY_ROLE ));
333
+
321
334
}
322
335
323
336
private void applyPropertyConstraints (JanusGraphManagement jgm )
@@ -427,14 +440,18 @@ private void applyPropertyConstraints(JanusGraphManagement jgm)
427
440
UUID ,
428
441
PASSWORD ,
429
442
ENABLED ,
430
- ROLES ,
431
443
SECURITY_TOKEN_KEY ,
432
444
SOURCE_ID ,
433
445
CREATED ,
434
446
LAST_UPDATED );
435
-
436
- addEdgePropertyConstraints (jgm ,
437
- ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS ,
447
+
448
+ addVertexPropertyConstraints (jgm ,
449
+ SECURITY_ROLE ,
450
+ UUID ,
451
+ CREATED );
452
+
453
+ addEdgePropertyConstraints (jgm ,
454
+ ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS ,
438
455
TAG_NAME );
439
456
}
440
457
@@ -448,7 +465,7 @@ private void addVertexPropertyConstraints(JanusGraphManagement jgm,
448
465
jgm .addProperties (vertexLabel , jgm .getPropertyKey (propertyKey ));
449
466
}
450
467
}
451
-
468
+
452
469
private void addEdgePropertyConstraints (JanusGraphManagement jgm ,
453
470
String label ,
454
471
String ... propertykeys )
@@ -521,7 +538,6 @@ private void createProperties(JanusGraphManagement jgm)
521
538
// User
522
539
makePropertyKeyIfDoesNotExist (jgm , PASSWORD , String .class , Cardinality .SINGLE );
523
540
makePropertyKeyIfDoesNotExist (jgm , ENABLED , Boolean .class , Cardinality .SINGLE );
524
- makePropertyKeyIfDoesNotExist (jgm , ROLES , String .class , Cardinality .SET );
525
541
makePropertyKeyIfDoesNotExist (jgm , SECURITY_TOKEN_KEY , String .class , Cardinality .SINGLE );
526
542
makePropertyKeyIfDoesNotExist (jgm , SOURCE_ID , String .class , Cardinality .SINGLE );
527
543
}
@@ -530,10 +546,11 @@ private Optional<String> buildIndexIfNecessary(final JanusGraphManagement jgm,
530
546
final Class <? extends Element > elementType ,
531
547
final JanusGraphSchemaType schemaType ,
532
548
final boolean unique ,
533
- final PropertyKey ... properties ){
549
+ final PropertyKey ... properties )
550
+ {
534
551
return buildIndexIfNecessary (jgm , elementType , schemaType , unique , true , properties );
535
552
}
536
-
553
+
537
554
private Optional <String > buildIndexIfNecessary (final JanusGraphManagement jgm ,
538
555
final Class <? extends Element > elementType ,
539
556
final JanusGraphSchemaType schemaType ,
@@ -598,16 +615,16 @@ private void makeVertexLabelIfDoesNotExist(final JanusGraphManagement jgm,
598
615
}
599
616
600
617
private Optional <PropertyKey > makePropertyKeyIfDoesNotExist (final JanusGraphManagement jgm ,
601
- final String name ,
602
- final Class <?> dataType )
618
+ final String name ,
619
+ final Class <?> dataType )
603
620
{
604
621
return makePropertyKeyIfDoesNotExist (jgm , name , dataType , null );
605
622
}
606
623
607
624
private Optional <PropertyKey > makePropertyKeyIfDoesNotExist (final JanusGraphManagement jgm ,
608
- final String name ,
609
- final Class <?> dataType ,
610
- final Cardinality cardinality )
625
+ final String name ,
626
+ final Class <?> dataType ,
627
+ final Cardinality cardinality )
611
628
{
612
629
if (jgm .containsPropertyKey (name ))
613
630
{
0 commit comments