/** * Handle the request primitive delete ... TODO: Strategy for error handling ... TS0004 7.1.1.2 * * @param onem2mResponse response */ public void handleOperationDelete(ResponsePrimitive onem2mResponse) { // Use table TS0004: 7.1.1.1-1 to validate DELETE specific parameters that were not handled in // the calling routine String cf = getPrimitive(RequestPrimitive.CONTENT); if (cf != null) { onem2mResponse.setRSC( Onem2m.ResponseStatusCode.INVALID_ARGUMENTS, "CONTENT(" + RequestPrimitive.CONTENT + ") not permitted"); return; } // validate result content options for delete String rc = getPrimitive(RequestPrimitive.RESULT_CONTENT); if (rc != null) { if (!(rc.contentEquals(Onem2m.ResultContent.ATTRIBUTES) || rc.contentEquals(Onem2m.ResultContent.NOTHING) || rc.contentEquals(Onem2m.ResultContent.CHILD_RESOURCE_REFS) || rc.contentEquals(Onem2m.ResultContent.ATTRIBUTES_CHILD_RESOURCE_REFS))) { onem2mResponse.setRSC( Onem2m.ResponseStatusCode.CONTENTS_UNACCEPTABLE, "RESULT_CONTENT(" + RequestPrimitive.RESULT_CONTENT + ") not accepted (" + rc + ")"); return; } } /** Find the resource, fill in the response based on result content */ String to = this.getPrimitive(RequestPrimitive.TO); if (Onem2mDb.getInstance().findResourceUsingURI(to, this, onem2mResponse) == false) { // TODO: is it idempotent or not ... fail or succeed??? onem2mResponse.setRSC( Onem2m.ResponseStatusCode.NOT_FOUND, "Resource target URI not found: " + to); return; } String protocol = getPrimitive(RequestPrimitive.PROTOCOL); String rt = this.getOnem2mResource().getResourceType(); if (rt != null && rt.contentEquals(Onem2m.ResourceType.CSE_BASE) && !protocol.contentEquals(Onem2m.Protocol.NATIVEAPP)) { onem2mResponse.setRSC( Onem2m.ResponseStatusCode.OPERATION_NOT_ALLOWED, "Not permitted to delete this resource: " + this.getPrimitive(RequestPrimitive.TO)); return; } ResourceContentProcessor.handleDelete(this, onem2mResponse); if (onem2mResponse.getPrimitive(ResponsePrimitive.RESPONSE_STATUS_CODE) != null) { return; } ResultContentProcessor.handleDelete(this, onem2mResponse); if (onem2mResponse.getPrimitive(ResponsePrimitive.RESPONSE_STATUS_CODE) != null) { return; } NotificationProcessor.handleDelete(this); // now delete the resource from the database // TODO: idempotent so who cares if cannot find the resource ... is this true? if (Onem2mDb.getInstance().deleteResourceUsingURI(this, onem2mResponse) == false) { onem2mResponse.setRSC( Onem2m.ResponseStatusCode.INTERNAL_SERVER_ERROR, "Resource target URI data store delete error: " + this.getPrimitive(RequestPrimitive.TO)); return; } // TODO: see TS0004 6.8 // if FOUND, and all went well, send back OK if (onem2mResponse.getPrimitive(ResponsePrimitive.RESPONSE_STATUS_CODE) == null) { onem2mResponse.setPrimitive( ResponsePrimitive.RESPONSE_STATUS_CODE, Onem2m.ResponseStatusCode.DELETED); } }