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

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

Introduction

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

Prototype

Boolean isDefaultVersion

To view the source code for com.amazonaws.services.iot.model PolicyVersion isDefaultVersion.

Click Source Link

Document

Specifies whether the policy version is the default.

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 a  v a2 s  . com*/
    }
    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) {
    }
}