Example usage for com.amazonaws.services.iot.model CertificateStatus INACTIVE

List of usage examples for com.amazonaws.services.iot.model CertificateStatus INACTIVE

Introduction

In this page you can find the example usage for com.amazonaws.services.iot.model CertificateStatus INACTIVE.

Prototype

CertificateStatus INACTIVE

To view the source code for com.amazonaws.services.iot.model CertificateStatus INACTIVE.

Click Source Link

Usage

From source file:com.erudika.para.iot.AWSIoTService.java

License:Apache License

@Override
public void deleteThing(Thing thing) {
    if (thing == null || StringUtils.isBlank(thing.getId())) {
        return;/*from   w w  w.  j  av a 2  s. c  o m*/
    }
    String id = cloudIDForThing(thing);
    String cARN = (String) thing.getDeviceMetadata().get("clientCertARN");
    String certId = (String) thing.getDeviceMetadata().get("clientCertId");
    String policy = id + "-Policy";
    for (PolicyVersion p : getClient()
            .listPolicyVersions(new ListPolicyVersionsRequest().withPolicyName(policy)).getPolicyVersions()) {
        if (!p.isDefaultVersion()) {
            getClient().deletePolicyVersion(new DeletePolicyVersionRequest().withPolicyName(policy)
                    .withPolicyVersionId(p.getVersionId()));
        }
    }
    try {
        getClient()
                .detachThingPrincipal(new DetachThingPrincipalRequest().withPrincipal(cARN).withThingName(id));
    } catch (Exception e) {
    }
    try {
        getClient().detachPrincipalPolicy(
                new DetachPrincipalPolicyRequest().withPrincipal(cARN).withPolicyName(policy));
    } catch (Exception e) {
    }
    try {
        getClient().deletePolicy(new DeletePolicyRequest().withPolicyName(policy));
    } catch (Exception e) {
    }
    try {
        getClient().updateCertificate(new UpdateCertificateRequest().withCertificateId(certId)
                .withNewStatus(CertificateStatus.INACTIVE));
    } catch (Exception e) {
    }
    try {
        getClient().deleteCertificate(new DeleteCertificateRequest().withCertificateId(certId));
    } catch (Exception e) {
    }
    getClient().deleteThing(new DeleteThingRequest().withThingName(id));
    try {
        getDataClient().deleteThingShadow(new DeleteThingShadowRequest().withThingName(id));
    } catch (Exception e) {
    }
}