This topic describes how to use Content Moderation SDK for Java to delete a business scenario. If you need to delete a business scenario, make sure that the business scenario is not in use. If you use a deleted business scenario, the moderation policy that is customized based on the business scenario becomes unavailable and the default moderation policy is used. This may lead to errors in the moderation of business data.

Before you begin

Before you call operations, make the following preparations:
  • Create an AccessKey pair for your Alibaba Cloud account. For more information, see Create an AccessKey pair.
  • Install Java dependencies. For more information, see Installation.
  • Optional:Download and import the Extension.Uploader utility class into your project if you submit an on-premises image or a binary image stream for image moderation.

Delete a business scenario

Operation Description Supported region
DeleteBizType Deletes a business scenario.
  • cn-shanghai: China (Shanghai)
  • cn-beijing: China (Beijing)
  • cn-shenzhen: China (Shenzhen)
  • ap-southeast-1: Singapore (Singapore)

Sample code

// Import the required classes. 
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;

/**
 * Use the following code to delete a business scenario. 
 */
public class DeleteBizTypeRequestSample extends BaseSample {

    public static void main(String[] args) throws Exception {
        // Use the AccessKey ID and AccessKey secret of your Alibaba Cloud account. 
        IClientProfile profile = DefaultProfile
            .getProfile("cn-shanghai", "Your AccessKey ID", "Your AccessKey secret");
        DefaultProfile
            .addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
        IAcsClient client = new DefaultAcsClient(profile);

        DeleteBizTypeRequest deleteBizTypeRequest = new DeleteBizTypeRequest();
        // Specify the name of the business scenario that you want to delete. 
        deleteBizTypeRequest.setBizTypeName("The name of the business scenario");
        // Specify the response format of the operation. 
        deleteBizTypeRequest.setAcceptFormat(FormatType.JSON); 
        // Specify the request method. 
        deleteBizTypeRequest.setSysMethod(com.aliyuncs.http.MethodType.POST);
        deleteBizTypeRequest.setSysEncoding("utf-8");
        // Specify the connection timeout. You can modify the timeout period as needed. Unit: milliseconds. 
        deleteBizTypeRequest.setSysConnectTimeout(3000);
        // Specify the read timeout. You can modify the timeout period as needed. Unit: milliseconds. 
        deleteBizTypeRequest.setSysReadTimeout(6000);

        // Send the HTTP request to delete a business scenario. 
        try {
            HttpResponse httpResponse = client.doAction(deleteBizTypeRequest);
            // Check whether the HTTP request is successful. 
            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"));
                // Check the error message. 
                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();
        }
    }
}