String galleryTabTemplateStringId = (String) fields.get(GALLERYTABTEMPLATE_ID_KEY);
Long galleryTabTemplateId = StringUtils.isNotEmpty(galleryTabTemplateStringId) ? Long
.parseLong(galleryTabTemplateStringId) : null;
// find/create the GalleryTabTemplate.
GalleryTabTemplate gtt = getGalleryTabTemplateByIdMapper.execute(galleryTabTemplateId == null ? null
: new FindByIdRequest("GalleryTabTemplate", galleryTabTemplateId));
// if required set the tab template.
if (tabId != null)
{
// look up source tab by id.
Tab tab = findTabByIdMapper.execute(new FindByIdRequest("Tab", tabId));
// create new tabTemplate from source.
TabTemplate newTabTemplate = new TabTemplate(tab.getTemplate());
gtt.setTabTemplate(newTabTemplate);
gtt.setTitle(newTabTemplate.getTabName());
}
// get/create the category and set it.
GalleryItemCategory galleryItemCategory = galleryItemCategoryMapper.findByName(GalleryItemType.TAB, category);
gtt.setCategory(galleryItemCategory);
// set the description
gtt.setDescription(description);
// persist the new GalleryTabTemplate to datastore.
return persistMapper.execute(new PersistenceRequest<GalleryTabTemplate>(gtt));
}