rlangenfeld
Contributor
Contributor

Renaming a Vapp template in a catalog using JAVA SDK 5.1

Hello,

I'm trying to rename a vApp template in that is stored in a Catalog. It ran fine but when I went to the VCloud director UI, the catalog name did not properly reflect that. Am I missing something here? Here is the code that I am using:

Catalog catalog = manager.searchForCatalog(vCloudClient, org, "CatalogA");

ReferenceType catalogRef = catalog.getCatalogItemRefByName("VApp Template to be renamed");

try {

     CatalogItem catalogItem = CatalogItem.getCatalogItemByReference(vCloudClient, catalogRef);

     CatalogItemType type = catalogItem.getResource();

     type.setName("Name to change to");

     catalogItem.updateCatalogItem(type);

} catch (VCloudException e) {

     // TODO Auto-generated catch block

     e.printStackTrace();

}

0 Kudos
6 Replies
rkamal
VMware Employee
VMware Employee

HI,

The code above will definitely try to rename the vapp template name to the new name. Unless it is a bug.

But you are saying that the catalog name did not properly reflect that. The code will change the vapp template name and not the catalog name.

Regards,

Rajesh Kamal.

0 Kudos
rlangenfeld
Contributor
Contributor

How do I get the catalog name to change then?

0 Kudos
rkamal
VMware Employee
VMware Employee

Hi,

You can use the AdminCatalog to change the catalog name.

AdminCatalog adminCatalog = AdminCatalog.getCatalogById(vcloudClient, catalogId);
AdminCatalogType adminCatalogResource = adminCatalog.getResource();
adminCatalogResource.setName("new name");
adminCatalog.updateAdminCatalog(adminCatalogResource);

Regards,

Rajesh Kamal.

0 Kudos
rlangenfeld
Contributor
Contributor

Sorry for the confusion. I meant how do I get the name of VAppTemplate in the catalog to change and have it correctly displayed with that new name in the UI?

0 Kudos
rkamal
VMware Employee
VMware Employee

Hi,

The code that you posted in the initial thread should work(find the catalog, find the catalog item with that name and change it).

Or you can also try this(find the catalog, find the catalog item, get the vapp template and change its name) and see.

Catalog catalog = Catalog.getCatalogByReference(vcloudClient, catalogRef);
ReferenceType catalogItemRef = catalog.getCatalogItemRefByName("vapp template name");

CatalogItem catalogItem = CatalogItem.getCatalogItemByReference(vcloudClient, catalogItemRef);
ReferenceType vappTemplateRef = catalogItem.getEntityReference();

VappTemplate vappTemplate = VappTemplate.getVappTemplateByReference(vcloudClient, vappTemplateRef);
VAppTemplateType vappTemplateRes = vappTemplate.getResource();
vappTemplateRes.setName("new vapp template name");
vappTemplate.updateVappTemplate(vappTemplateRes);

Regards,

Rajesh Kamal.

0 Kudos
rlangenfeld
Contributor
Contributor

Thanks Rajesh! This provided me exactly with what I needed! Kind of strange that changing the name of the CatalogItem doesn't change the name of the front end device as well!

0 Kudos