Skip to content

Commit

Permalink
Merge pull request #346 from atlanhq/DVX-72
Browse files Browse the repository at this point in the history
Removes ability to soft-delete categories (can only be purged)
  • Loading branch information
cmgrote authored Nov 23, 2023
2 parents 90fcb08 + 3212421 commit 2c6fc7e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
12 changes: 12 additions & 0 deletions sdk/src/main/java/com/atlan/api/AssetEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.atlan.exception.InvalidRequestException;
import com.atlan.model.assets.Asset;
import com.atlan.model.assets.Connection;
import com.atlan.model.assets.GlossaryCategory;
import com.atlan.model.assets.IReferenceable;
import com.atlan.model.core.*;
import com.atlan.model.enums.AtlanDeleteType;
Expand Down Expand Up @@ -373,10 +374,21 @@ public AssetDeletionResponse delete(List<String> guids, AtlanDeleteType deleteTy
* @param options to override default client settings
* @return the results of the deletion
* @throws AtlanException on any API interaction problems
* @throws InvalidRequestException if you attempt to archive a category, as categories can only be purged
*/
public AssetDeletionResponse delete(List<String> guids, AtlanDeleteType deleteType, RequestOptions options)
throws AtlanException {
if (guids != null) {
if (deleteType == AtlanDeleteType.SOFT) {
List<String> categoryGuids = new ArrayList<>();
client.assets.select().where(Asset.GUID.in(guids)).stream()
.filter(a -> a instanceof GlossaryCategory)
.forEach(c -> categoryGuids.add(c.getGuid()));
if (!categoryGuids.isEmpty()) {
throw new InvalidRequestException(
ErrorCode.CATEGORIES_CANNOT_BE_ARCHIVED, String.join(",", categoryGuids));
}
}
StringBuilder guidList = new StringBuilder();
for (String guid : guids) {
if (guid != null) {
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/main/java/com/atlan/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ public enum ErrorCode implements ExceptionMessageSet {
"ATLAN-JAVA-400-041",
"Objects of type {0} should only be updated in full.",
"For objects of this type you should not use trimToRequired but instead update the object in full."),
CATEGORIES_CANNOT_BE_ARCHIVED(
400,
"ATLAN-JAVA-400-042",
"Categories cannot be archived (soft-deleted): {0}.",
"Please use the purge operation if you wish to remove a category."),

AUTHENTICATION_PASSTHROUGH(
401,
Expand Down
23 changes: 0 additions & 23 deletions sdk/src/main/java/com/atlan/model/assets/GlossaryCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,29 +364,6 @@ public static GlossaryCategory retrieveByQualifiedName(AtlanClient client, Strin
return get(client, qualifiedName);
}

/**
* Restore the archived (soft-deleted) GlossaryCategory to active.
*
* @param qualifiedName for the GlossaryCategory
* @return true if the GlossaryCategory is now active, and false otherwise
* @throws AtlanException on any API problems
*/
public static boolean restore(String qualifiedName) throws AtlanException {
return restore(Atlan.getDefaultClient(), qualifiedName);
}

/**
* Restore the archived (soft-deleted) GlossaryCategory to active.
*
* @param client connectivity to the Atlan tenant on which to restore the asset
* @param qualifiedName for the GlossaryCategory
* @return true if the GlossaryCategory is now active, and false otherwise
* @throws AtlanException on any API problems
*/
public static boolean restore(AtlanClient client, String qualifiedName) throws AtlanException {
return Asset.restore(client, TYPE_NAME, qualifiedName);
}

/**
* Builds the minimal object necessary for creating a category.
*
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/resources/templates/entity.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ public <#if abstract>abstract</#if> class ${className} extends ${parentClassName
return get(client, qualifiedName);
}

<#if className != "GlossaryCategory">
/**
* Restore the archived (soft-deleted) ${className} to active.
*
Expand All @@ -472,6 +473,7 @@ public <#if abstract>abstract</#if> class ${className} extends ${parentClassName
return Asset.restore(client, TYPE_NAME, qualifiedName);
}

</#if>
</#if>
<#if classTemplateFile??>
<#import classTemplateFile as methods>
Expand Down

0 comments on commit 2c6fc7e

Please sign in to comment.