Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes creation details for multi-valued custom metadata attributes #1197

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,19 @@ void createCustomMetadataIPR() throws AtlanException {

@Test(groups = {"cm.create.cm.raci"})
void createCustomMetadataRACI() throws AtlanException {
AttributeDef informed =
AttributeDef.of(client, CM_ATTR_RACI_INFORMED, AtlanCustomAttributePrimitiveType.GROUPS, null, false)
.toBuilder()
.multiValued(true)
.build();
CustomMetadataDef customMetadataDef = CustomMetadataDef.creator(CM_RACI)
.attributeDef(AttributeDef.of(
client, CM_ATTR_RACI_RESPONSIBLE, AtlanCustomAttributePrimitiveType.USERS, null, true))
.attributeDef(AttributeDef.of(
client, CM_ATTR_RACI_ACCOUNTABLE, AtlanCustomAttributePrimitiveType.USERS, null, false))
.attributeDef(AttributeDef.of(
client, CM_ATTR_RACI_CONSULTED, AtlanCustomAttributePrimitiveType.GROUPS, null, true))
.attributeDef(AttributeDef.of(
client, CM_ATTR_RACI_INFORMED, AtlanCustomAttributePrimitiveType.GROUPS, null, true))
.attributeDef(informed)
.attributeDef(AttributeDef.of(
client, CM_ATTR_RACI_EXTRA, AtlanCustomAttributePrimitiveType.STRING, null, false))
.options(CustomMetadataOptions.withIcon(AtlanIcon.USERS_THREE, AtlanTagColor.GRAY))
Expand All @@ -171,6 +175,7 @@ void createCustomMetadataRACI() throws AtlanException {
assertNotNull(one.getName());
assertNotEquals(one.getName(), CM_ATTR_RACI_RESPONSIBLE);
assertEquals(one.getTypeName(), "array<" + AtlanCustomAttributePrimitiveType.STRING.getValue() + ">");
assertEquals(one.getCardinality(), AtlanCustomAttributeCardinality.SET);
assertNotNull(one.getOptions());
assertTrue(one.getOptions().getMultiValueSelect());
assertEquals(one.getOptions().getCustomType(), AtlanCustomAttributePrimitiveType.USERS.getValue());
Expand All @@ -179,6 +184,7 @@ void createCustomMetadataRACI() throws AtlanException {
assertNotNull(one.getName());
assertNotEquals(one.getName(), CM_ATTR_RACI_ACCOUNTABLE);
assertEquals(one.getTypeName(), AtlanCustomAttributePrimitiveType.STRING.getValue());
assertEquals(one.getCardinality(), AtlanCustomAttributeCardinality.SINGLE);
assertNotNull(one.getOptions());
assertFalse(one.getOptions().getMultiValueSelect());
assertEquals(one.getOptions().getCustomType(), AtlanCustomAttributePrimitiveType.USERS.getValue());
Expand All @@ -187,6 +193,7 @@ void createCustomMetadataRACI() throws AtlanException {
assertNotNull(one.getName());
assertNotEquals(one.getName(), CM_ATTR_RACI_CONSULTED);
assertEquals(one.getTypeName(), "array<" + AtlanCustomAttributePrimitiveType.STRING.getValue() + ">");
assertEquals(one.getCardinality(), AtlanCustomAttributeCardinality.SET);
assertNotNull(one.getOptions());
assertTrue(one.getOptions().getMultiValueSelect());
assertEquals(one.getOptions().getCustomType(), AtlanCustomAttributePrimitiveType.GROUPS.getValue());
Expand All @@ -195,6 +202,7 @@ void createCustomMetadataRACI() throws AtlanException {
assertNotNull(one.getName());
assertNotEquals(one.getName(), CM_ATTR_RACI_INFORMED);
assertEquals(one.getTypeName(), "array<" + AtlanCustomAttributePrimitiveType.STRING.getValue() + ">");
assertEquals(one.getCardinality(), AtlanCustomAttributeCardinality.SET);
assertNotNull(one.getOptions());
assertTrue(one.getOptions().getMultiValueSelect());
assertEquals(one.getOptions().getCustomType(), AtlanCustomAttributePrimitiveType.GROUPS.getValue());
Expand Down Expand Up @@ -1017,6 +1025,7 @@ private AttributeDef validateRACIStructure(List<AttributeDef> list, int totalExp
assertEquals(one.getDisplayName(), CM_ATTR_RACI_RESPONSIBLE);
assertNotEquals(one.getName(), CM_ATTR_RACI_RESPONSIBLE);
assertEquals(one.getTypeName(), "array<" + AtlanCustomAttributePrimitiveType.STRING.getValue() + ">");
assertEquals(one.getCardinality(), AtlanCustomAttributeCardinality.SET);
assertTrue(one.getOptions().getApplicableAssetTypes().contains(Database.TYPE_NAME));
assertFalse(one.isArchived());
assertTrue(one.getOptions().getMultiValueSelect());
Expand All @@ -1025,6 +1034,7 @@ private AttributeDef validateRACIStructure(List<AttributeDef> list, int totalExp
assertEquals(one.getDisplayName(), CM_ATTR_RACI_ACCOUNTABLE);
assertNotEquals(one.getName(), CM_ATTR_RACI_ACCOUNTABLE);
assertEquals(one.getTypeName(), AtlanCustomAttributePrimitiveType.STRING.getValue());
assertEquals(one.getCardinality(), AtlanCustomAttributeCardinality.SINGLE);
assertTrue(one.getOptions().getApplicableAssetTypes().contains(Table.TYPE_NAME));
assertFalse(one.isArchived());
assertFalse(one.getOptions().getMultiValueSelect());
Expand All @@ -1033,6 +1043,7 @@ private AttributeDef validateRACIStructure(List<AttributeDef> list, int totalExp
assertEquals(one.getDisplayName(), CM_ATTR_RACI_CONSULTED);
assertNotEquals(one.getName(), CM_ATTR_RACI_CONSULTED);
assertEquals(one.getTypeName(), "array<" + AtlanCustomAttributePrimitiveType.STRING.getValue() + ">");
assertEquals(one.getCardinality(), AtlanCustomAttributeCardinality.SET);
assertTrue(one.getOptions().getApplicableAssetTypes().contains(Column.TYPE_NAME));
assertFalse(one.isArchived());
assertTrue(one.getOptions().getMultiValueSelect());
Expand All @@ -1041,6 +1052,7 @@ private AttributeDef validateRACIStructure(List<AttributeDef> list, int totalExp
assertEquals(one.getDisplayName(), CM_ATTR_RACI_INFORMED);
assertNotEquals(one.getName(), CM_ATTR_RACI_INFORMED);
assertEquals(one.getTypeName(), "array<" + AtlanCustomAttributePrimitiveType.STRING.getValue() + ">");
assertEquals(one.getCardinality(), AtlanCustomAttributeCardinality.SET);
assertTrue(one.getOptions().getApplicableAssetTypes().contains(MaterializedView.TYPE_NAME));
assertFalse(one.isArchived());
assertTrue(one.getOptions().getMultiValueSelect());
Expand Down
32 changes: 32 additions & 0 deletions sdk/src/main/java/com/atlan/model/typedefs/AttributeDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public static AttributeDef of(
}
if (multiValued) {
builder.typeName("array<" + baseType + ">")
.cardinality(AtlanCustomAttributeCardinality.SET)
.options(AttributeDefOptions.of(client, type, optionsName, otherOptions).toBuilder()
.multiValueSelect(true)
.build());
Expand Down Expand Up @@ -382,6 +383,7 @@ public abstract static class AttributeDefBuilder<
* nothing to the attribute definition.
*
* @param by name of the user who is archiving the attribute definition
* @return the builder for archiving this attribute definition
*/
public B archive(String by) {
if (options != null) {
Expand All @@ -395,5 +397,35 @@ public B archive(String by) {
}
return self();
}

/**
* Configure this attribute definition to allow multiple values. Note that you MUST
* first have defined a type for the attribute definition, or this will likely not work
* as expected.
*
* @param multiValued true if multiple values are allowed for the attribute, otherwise false
* @return the builder configured for the multiple or singular values for this attribute definition
*/
public B multiValued(boolean multiValued) {
if (options != null) {
options = options.toBuilder().multiValueSelect(multiValued).build();
} else {
options = AttributeDefOptions.builder()
.multiValueSelect(multiValued)
.build();
}
if (multiValued) {
if (typeName != null && !typeName.startsWith("array<")) {
typeName("array<" + typeName + ">");
}
cardinality(AtlanCustomAttributeCardinality.SET);
} else {
if (typeName != null && typeName.startsWith("array<")) {
typeName(typeName.substring("array<".length(), typeName.length() - 1));
}
cardinality(AtlanCustomAttributeCardinality.SINGLE);
}
return self();
}
}
}
Loading