Skip to content

Commit 8b1707b

Browse files
authored
Standalone vertex for User Role (#26)
* Janusgraph Schema changes for User Role Vertex * SNAPSHOT version changes * UserRole renamed to SecurityRole * Reverting pom versions
1 parent 451445b commit 8b1707b

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

strongbox-db-schema/src/main/java/org/carlspring/strongbox/db/schema/Edges.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface Edges
77
String ARTIFACT_HAS_TAGS = "ArtifactHasTags";
88
String ARTIFACT_GROUP_HAS_ARTIFACTS = "ArtifactGroupHasArtifacts";
99
String ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS = "ArtifactGroupHasTaggedArtifacts";
10-
1110
String EXTENDS = "Extends";
12-
11+
String USER_HAS_SECURITY_ROLES = "UserHasSecurityRoles";
12+
1313
}

strongbox-db-schema/src/main/java/org/carlspring/strongbox/db/schema/Properties.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public interface Properties
2121
String USERNAME = "username";
2222
String PASSWORD = "password";
2323
String ENABLED = "enabled";
24-
String ROLES = "roles";
2524
String SECURITY_TOKEN_KEY = "securityTokenKey";
2625
String SOURCE_ID = "sourceId";
2726
String FILE_NAMES = "filenames";

strongbox-db-schema/src/main/java/org/carlspring/strongbox/db/schema/StrongboxSchema.java

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.carlspring.strongbox.db.schema.Edges.ARTIFACT_HAS_ARTIFACT_COORDINATES;
66
import static org.carlspring.strongbox.db.schema.Edges.ARTIFACT_HAS_TAGS;
77
import static org.carlspring.strongbox.db.schema.Edges.EXTENDS;
8+
import static org.carlspring.strongbox.db.schema.Edges.USER_HAS_SECURITY_ROLES;
89
import static org.carlspring.strongbox.db.schema.Properties.ARTIFACT_FILE_EXISTS;
910
import static org.carlspring.strongbox.db.schema.Properties.CHECKSUMS;
1011
import static org.carlspring.strongbox.db.schema.Properties.COORDINATES_ABI;
@@ -35,7 +36,6 @@
3536
import static org.carlspring.strongbox.db.schema.Properties.NAME;
3637
import static org.carlspring.strongbox.db.schema.Properties.PASSWORD;
3738
import static org.carlspring.strongbox.db.schema.Properties.REPOSITORY_ID;
38-
import static org.carlspring.strongbox.db.schema.Properties.ROLES;
3939
import static org.carlspring.strongbox.db.schema.Properties.SECURITY_TOKEN_KEY;
4040
import static org.carlspring.strongbox.db.schema.Properties.SIZE_IN_BYTES;
4141
import static org.carlspring.strongbox.db.schema.Properties.SOURCE_ID;
@@ -53,9 +53,10 @@
5353
import static org.carlspring.strongbox.db.schema.Vertices.PYPI_ARTIFACT_COORDINATES;
5454
import static org.carlspring.strongbox.db.schema.Vertices.RAW_ARTIFACT_COORDINATES;
5555
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;
5757
import static org.janusgraph.core.Multiplicity.MANY2ONE;
5858
import static org.janusgraph.core.Multiplicity.MULTI;
59+
import static org.janusgraph.core.Multiplicity.ONE2MANY;
5960
import static org.janusgraph.core.Multiplicity.ONE2ONE;
6061

6162
import java.util.Arrays;
@@ -135,9 +136,9 @@ public void createSchema(JanusGraph jg)
135136
for (Entry<String, String> relationIndex : relationIndexes.entrySet())
136137
{
137138
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();
139140
}
140-
141+
141142
jgm = jg.openManagement();
142143
try
143144
{
@@ -151,13 +152,12 @@ public void createSchema(JanusGraph jg)
151152
jgm.rollback();
152153
throw new RuntimeException("Failed to enable indexes.", e);
153154
}
154-
155+
155156
jgm = jg.openManagement();
156157
try
157158
{
158159
logger.info(String.format("Schema: %n%s", jgm.printSchema()));
159-
}
160-
finally
160+
} finally
161161
{
162162
jgm.rollback();
163163
}
@@ -174,7 +174,7 @@ protected void enableIndexes(JanusGraphManagement jgm,
174174
jgm.updateIndex(jgm.getGraphIndex(janusGraphIndex), SchemaAction.ENABLE_INDEX).get();
175175
}
176176
}
177-
177+
178178
protected void enableRelationIndexes(JanusGraphManagement jgm,
179179
Map<String, String> indexes)
180180
throws InterruptedException,
@@ -184,15 +184,17 @@ protected void enableRelationIndexes(JanusGraphManagement jgm,
184184
for (Entry<String, String> e : entrySet)
185185
{
186186
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();
188190
}
189191
}
190192

191193
protected Map<String, String> createRelationIndexes(JanusGraph jg,
192-
JanusGraphManagement jgm)
194+
JanusGraphManagement jgm)
193195
{
194196
Map<String, String> result = new HashMap<>();
195-
197+
196198
String name = ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS + "By" + StringUtils.capitalize(TAG_NAME);
197199
if (!jgm.containsGraphIndex(name))
198200
{
@@ -202,10 +204,10 @@ protected Map<String, String> createRelationIndexes(JanusGraph jg,
202204
jgm.getPropertyKey(TAG_NAME));
203205
result.put(name, ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS);
204206
}
205-
207+
206208
return result;
207209
}
208-
210+
209211
protected Set<String> createIndexes(JanusGraph jg,
210212
JanusGraphManagement jgm)
211213
throws InterruptedException
@@ -244,7 +246,12 @@ protected Set<String> createIndexes(JanusGraph jg,
244246
Vertex.class,
245247
jgm.getVertexLabel(USER),
246248
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);
248255

249256
return result;
250257
}
@@ -265,13 +272,15 @@ private void applySchemaChanges(JanusGraphManagement jgm)
265272
makeVertexLabelIfDoesNotExist(jgm, ARTIFACT_TAG);
266273
makeVertexLabelIfDoesNotExist(jgm, ARTIFACT_ID_GROUP);
267274
makeVertexLabelIfDoesNotExist(jgm, USER);
275+
makeVertexLabelIfDoesNotExist(jgm, SECURITY_ROLE);
268276

269277
// Edges
270278
makeEdgeLabelIfDoesNotExist(jgm, ARTIFACT_HAS_ARTIFACT_COORDINATES, MANY2ONE);
271279
makeEdgeLabelIfDoesNotExist(jgm, ARTIFACT_HAS_TAGS, MULTI);
272280
makeEdgeLabelIfDoesNotExist(jgm, EXTENDS, ONE2ONE);
273281
makeEdgeLabelIfDoesNotExist(jgm, ARTIFACT_GROUP_HAS_ARTIFACTS, ONE2MANY);
274282
makeEdgeLabelIfDoesNotExist(jgm, ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS, MULTI);
283+
makeEdgeLabelIfDoesNotExist(jgm, USER_HAS_SECURITY_ROLES, MULTI);
275284

276285
// Add property constraints
277286
applyPropertyConstraints(jgm);
@@ -293,7 +302,7 @@ private void applyConnectionConstraints(JanusGraphManagement jgm)
293302
jgm.addConnection(jgm.getEdgeLabel(ARTIFACT_GROUP_HAS_ARTIFACTS),
294303
jgm.getVertexLabel(ARTIFACT_ID_GROUP),
295304
jgm.getVertexLabel(ARTIFACT));
296-
305+
297306
jgm.addConnection(jgm.getEdgeLabel(ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS),
298307
jgm.getVertexLabel(ARTIFACT_ID_GROUP),
299308
jgm.getVertexLabel(ARTIFACT));
@@ -318,6 +327,10 @@ private void applyConnectionConstraints(JanusGraphManagement jgm)
318327
jgm.getVertexLabel(PYPI_ARTIFACT_COORDINATES),
319328
jgm.getVertexLabel(GENERIC_ARTIFACT_COORDINATES));
320329

330+
jgm.addConnection(jgm.getEdgeLabel(USER_HAS_SECURITY_ROLES),
331+
jgm.getVertexLabel(USER),
332+
jgm.getVertexLabel(SECURITY_ROLE));
333+
321334
}
322335

323336
private void applyPropertyConstraints(JanusGraphManagement jgm)
@@ -427,14 +440,18 @@ private void applyPropertyConstraints(JanusGraphManagement jgm)
427440
UUID,
428441
PASSWORD,
429442
ENABLED,
430-
ROLES,
431443
SECURITY_TOKEN_KEY,
432444
SOURCE_ID,
433445
CREATED,
434446
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,
438455
TAG_NAME);
439456
}
440457

@@ -448,7 +465,7 @@ private void addVertexPropertyConstraints(JanusGraphManagement jgm,
448465
jgm.addProperties(vertexLabel, jgm.getPropertyKey(propertyKey));
449466
}
450467
}
451-
468+
452469
private void addEdgePropertyConstraints(JanusGraphManagement jgm,
453470
String label,
454471
String... propertykeys)
@@ -521,7 +538,6 @@ private void createProperties(JanusGraphManagement jgm)
521538
// User
522539
makePropertyKeyIfDoesNotExist(jgm, PASSWORD, String.class, Cardinality.SINGLE);
523540
makePropertyKeyIfDoesNotExist(jgm, ENABLED, Boolean.class, Cardinality.SINGLE);
524-
makePropertyKeyIfDoesNotExist(jgm, ROLES, String.class, Cardinality.SET);
525541
makePropertyKeyIfDoesNotExist(jgm, SECURITY_TOKEN_KEY, String.class, Cardinality.SINGLE);
526542
makePropertyKeyIfDoesNotExist(jgm, SOURCE_ID, String.class, Cardinality.SINGLE);
527543
}
@@ -530,10 +546,11 @@ private Optional<String> buildIndexIfNecessary(final JanusGraphManagement jgm,
530546
final Class<? extends Element> elementType,
531547
final JanusGraphSchemaType schemaType,
532548
final boolean unique,
533-
final PropertyKey... properties){
549+
final PropertyKey... properties)
550+
{
534551
return buildIndexIfNecessary(jgm, elementType, schemaType, unique, true, properties);
535552
}
536-
553+
537554
private Optional<String> buildIndexIfNecessary(final JanusGraphManagement jgm,
538555
final Class<? extends Element> elementType,
539556
final JanusGraphSchemaType schemaType,
@@ -598,16 +615,16 @@ private void makeVertexLabelIfDoesNotExist(final JanusGraphManagement jgm,
598615
}
599616

600617
private Optional<PropertyKey> makePropertyKeyIfDoesNotExist(final JanusGraphManagement jgm,
601-
final String name,
602-
final Class<?> dataType)
618+
final String name,
619+
final Class<?> dataType)
603620
{
604621
return makePropertyKeyIfDoesNotExist(jgm, name, dataType, null);
605622
}
606623

607624
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)
611628
{
612629
if (jgm.containsPropertyKey(name))
613630
{

strongbox-db-schema/src/main/java/org/carlspring/strongbox/db/schema/Vertices.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ public interface Vertices
1414
String ARTIFACT_TAG = "ArtifactTag";
1515
String ARTIFACT_ID_GROUP = "ArtifactIdGroup";
1616
String USER = "User";
17+
String SECURITY_ROLE = "SecurityRole";
1718
}

0 commit comments

Comments
 (0)