When deleting a vApp, the resulting task contains a reference to the vApp as the Owner. This reference only includes the href and type. From that, how can I get the ID (URN) of the vApp? Normally I would fetch the href but that doesn't work after the vApp has been deleted.
I know that I could parse the href but the documentation advises against doing that as the href formats may change. I'm looking for something official.
Hi,
1. Just before the vapp delete operation you can very well get the id from the vapp object itself.
Ex: Vapp vapp = Vapp.getVappByReference(client, vappRef);
String vAppId = vapp.getResource().getId();
Task task = vapp.delete();
2. If you just have the task, then you can use the queryservice to get the task and also its associated properties in the id format.
Ex: Task task = vapp.delete();
String taskId = task.getResource().getId();
QueryParams<QueryAdminTaskField> queryParams = new QueryParams<QueryAdminTaskField>();
queryParams.setFilter(new Filter(new Expression(QueryAdminTaskField.ID, taskId, ExpressionType.EQUALS)));
RecordResult<QueryResultAdminTaskRecordType> taskResult = client.getQueryService().queryIdRecords(QueryRecordType.ADMINTASK,
queryParams);
// some checks
System.out.println(taskResult.getRecords().get(0).getObject());
System.out.println(taskResult.getRecords().get(0).getObjectName());
System.out.println(taskResult.getRecords().get(0).getObjectType());
API
Regards,
Rajesh Kamal.
Thanks Rajesh. I like the query idea but I'm getting an error when
trying to filter by id.
"Bad request: Unknown property name id."
I should have mentioned that I am still on v1.5. Do you think that might
be the problem?
I just wish all references included the id up front. Would avoid a lot
of extra requests.
I believe the ability to query for an object by its ID is new to the 5.1 API.