Delete a business scenario
Use the AI Guardrails SDK for Java to delete a business scenario that is no longer needed.
Deleting a business scenario that is still in use makes its associated moderation policy unavailable. The service then falls back to the default moderation policy, which may produce incorrect moderation results. Before deleting, confirm that no active moderation calls reference the business scenario.
Prerequisites
Before you begin, ensure that you have:
Java dependencies installed. For details, see Installation
(Optional) The Extension.Uploader utility class downloaded and imported into your project, if you submit local images or binary image streams for image moderation
Use the Java version specified in the Installation topic. Using a different version causes subsequent operation calls to fail.
Operation
The DeleteBizType operation deletes a business scenario. The operation is supported in the following regions:
| Operation | Description | Supported regions |
|---|---|---|
| DeleteBizType | Deletes a business scenario | cn-shanghai (China (Shanghai)), cn-beijing (China (Beijing)), cn-shenzhen (China (Shenzhen)), ap-southeast-1 (Singapore) |
Sample code
The following example calls DeleteBizType to delete a business scenario.
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20170823.DeleteBizTypeRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
public class DeleteBizTypeRequestSample {
public static void main(String[] args) throws Exception {
// Use a RAM user's AccessKey pair to minimize security risks.
// Store credentials in environment variables instead of hardcoding them.
DefaultProfile profile = DefaultProfile.getProfile(
"cn-shanghai",
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
IAcsClient client = new DefaultAcsClient(profile);
DeleteBizTypeRequest deleteBizTypeRequest = new DeleteBizTypeRequest();
// Set the name of the business scenario to delete.
deleteBizTypeRequest.setBizTypeName("<your-biz-type-name>");
deleteBizTypeRequest.setAcceptFormat(FormatType.JSON);
deleteBizTypeRequest.setMethod(com.aliyuncs.http.MethodType.POST);
deleteBizTypeRequest.setEncoding("utf-8");
// Connection timeout in milliseconds.
deleteBizTypeRequest.setConnectTimeout(3000);
// Read timeout in milliseconds.
deleteBizTypeRequest.setReadTimeout(6000);
try {
HttpResponse httpResponse = client.doAction(deleteBizTypeRequest);
if (httpResponse.isSuccess()) {
JSONObject scrResponse = JSON.parseObject(
new String(httpResponse.getHttpContent(), "utf-8"));
System.out.println("delete success. detail msg:" +
JSON.toJSONString(scrResponse, true));
} else {
JSONObject scrResponse = JSON.parseObject(
new String(httpResponse.getHttpContent(), "utf-8"));
System.out.println("delete fail. detail msg: " +
JSON.toJSONString(scrResponse.get("Message"), true));
}
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}Replace <your-biz-type-name> with the name of the business scenario to delete.
Next steps
To create or manage business scenarios, see the AI Guardrails SDK for Java documentation.
To verify your active moderation policies after deletion, review your content moderation configurations in the console.