Copilot commented on code in PR #401:
URL: https://github.com/apache/atlas/pull/401#discussion_r2208356380
##########
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEnumDefStoreV2.java:
##########
@@ -299,4 +306,34 @@ private static AtlasEnumDef toEnumDef(AtlasVertex vertex,
AtlasEnumDef enumDef,
return ret;
}
+
+ private void createPropertyKeys(AtlasEnumDef enumDef) throws
AtlasBaseException {
+ AtlasGraphManagement management =
typeDefStore.atlasGraph.getManagementSystem();
+
+ // create property keys first
+ for (AtlasEnumElementDef element : enumDef.getElementDefs()) {
+ // Validate the enum element
+ if (StringUtils.isEmpty(element.getValue()) || null ==
element.getOrdinal()) {
+ throw new
AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE,
enumDef.getName(), "elementValue");
+ }
+
+ String elemKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef,
element.getValue());
+
+ createPropertyKey(encodePropertyKey(elemKey), Integer.class,
AtlasCardinality.SINGLE, management);
+ }
+
+ String typeDefKey =
AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef);
+ String defaultValueKey =
AtlasGraphUtilsV2.getTypeDefPropertyKey(enumDef, "defaultValue");
+
+ createPropertyKey(encodePropertyKey(typeDefKey), Object.class,
AtlasCardinality.SINGLE, management);
+ createPropertyKey(encodePropertyKey(defaultValueKey), String.class,
AtlasCardinality.SINGLE, management);
+
+ try {
+ management.commit();
+ } catch (Exception e) {
+ LOG.error("PropertyKey creation failed", e);
+
+ throw new AtlasBaseException(new IndexException("Index commit
failed ", e));
Review Comment:
There's an extra space in the error message "Index commit failed ". It
should be "Index commit failed" without the trailing space.
```suggestion
throw new AtlasBaseException(new IndexException("Index commit
failed", e));
```
##########
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEnumDefStoreV2.java:
##########
@@ -239,14 +244,11 @@ private void toVertex(AtlasEnumDef enumDef, AtlasVertex
vertex) throws AtlasBase
throw new
AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE,
enumDef.getName(), "values");
}
+ createPropertyKeys(enumDef);
+
List<String> values = new ArrayList<>(enumDef.getElementDefs().size());
for (AtlasEnumElementDef element : enumDef.getElementDefs()) {
Review Comment:
The validation logic for enum elements was moved from toVertex() to
createPropertyKeys(), but the validation is now performed twice - once in
createPropertyKeys() and once when iterating through elements in toVertex().
Consider removing the duplicate validation or clearly documenting why it's
needed in both places.
##########
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java:
##########
@@ -638,4 +653,35 @@ private static void addReferencesForAttribute(AtlasVertex
vertex, AtlasAttribute
}
}
}
+
+ private static void createPropertyKeys(AtlasStructDef structDef,
AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException {
+ AtlasGraphManagement management =
typeDefStore.atlasGraph.getManagementSystem();
+
+ for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
+ // Validate the mandatory features of an attribute (compatibility
with legacy type system)
+ if (StringUtils.isEmpty(attributeDef.getName())) {
+ throw new
AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE,
structDef.getName(), "name");
+ }
+
+ if (StringUtils.isEmpty(attributeDef.getTypeName())) {
+ throw new
AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE,
structDef.getName(), "typeName");
+ }
+
+ String propertyKey =
AtlasGraphUtilsV2.getTypeDefPropertyKey(structDef, attributeDef.getName());
+
+
createPropertyKey(AtlasGraphUtilsV2.encodePropertyKey(propertyKey),
String.class, AtlasCardinality.SINGLE, management);
+ }
+
+ String typeNamePropertyKey =
AtlasGraphUtilsV2.getTypeDefPropertyKey(structDef);
+
+
createPropertyKey(AtlasGraphUtilsV2.encodePropertyKey(typeNamePropertyKey),
Object.class, AtlasCardinality.SINGLE, management);
+
+ try {
+ management.commit();
+ } catch (Exception e) {
+ LOG.error("PropertyKey creation failed", e);
+
+ throw new AtlasBaseException(new IndexException("Index commit
failed ", e));
Review Comment:
There's an extra space in the error message "Index commit failed ". It
should be "Index commit failed" without the trailing space.
```suggestion
throw new AtlasBaseException(new IndexException("Index commit
failed", e));
```
##########
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java:
##########
@@ -638,4 +653,35 @@ private static void addReferencesForAttribute(AtlasVertex
vertex, AtlasAttribute
}
}
}
+
+ private static void createPropertyKeys(AtlasStructDef structDef,
AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException {
Review Comment:
The validation logic in createPropertyKeys() duplicates the validation in
updateVertexPreCreate(). Consider extracting the validation into a separate
method to avoid code duplication.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]