Example usage for com.amazonaws.services.iot.model PolicyVersion getVersionId

List of usage examples for com.amazonaws.services.iot.model PolicyVersion getVersionId

Introduction

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

Prototype


public String getVersionId() 

Source Link

Document

The policy version ID.

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;/*w ww. ja  va  2s.c  om*/
    }
    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) {
    }
}