This example shows how to find an item by using the item name and then how to change the name and description of the retrieved item.
This example uses the steps that are described in the Edit the Settings of a Library Item procedure.
Note: For related code samples, see the
vsphere-automation-sdk-java VMware repository at GitHub.
... // List the items in a published library Item libItemService = this.vapiAuthHelper.getStubFactory().createStub(Item.class, sessionStubconfig); List<String> itemIds = libItemService.list(libraryId.getId()); for (String itemId : itemIds) { ItemModel singleItem = libItemService.get(itemId); // List the files uploaded to each library item and print their names and size com.vmware.content.library.item.File itemFilesService = this.vapiAuthHelper.getStubFactory().createStub(com.vmware.content.library.item.File.class, sessionStubconfig); List<com.vmware.content.library.item.FileTypes.Info> fileInfos = itemFilesService.list(itemId); for (com.vmware.content.library.item.FileTypes.Info singleFile : fileInfos) { System.out.println("Library item with name "+ singleFile.getName() + " has size " + singleFile.getSize()); } // Change the name and description of the library item with the specified name if (singleItem.getName().equals("simpleVmTemplate")) { ItemModel libItemUpdated = new ItemModel(); libItemUpdated.setName("newItemName"); libItemUpdated.setDescription("Description of the newItemName"); libItemService.update(singleItem.getId(), libItemUpdated); } }