cancel
Showing results for 
Search instead for 
Did you mean: 

how to put catalogversionmodel inside the categoery model?

Former Member
0 Kudos

Blockquotefinal List newAttributes = new ArrayList();

System.out.println(""); System.out.println(newAttributes); final DistributionCatalogModel cat = modelService.create(DistributionCatalogModel.class); //DistributionCatalogModel c=modelService.getAll(arg0, arg1) // cat.getChannelName(); cat.setId(nextLine[2]); cat.setDefaultCatalog(new Boolean(true)); / cat.setChannelName(nextLine[3]); cat.setChannelContactName(nextLine[6]); cat.setChannelContactEmail(nextLine[7]); cat.setChannelType(ChannelTypeEnum.valueOf(nextLine[4])); cat.setChannelStatus(ChannelStatusEnum.valueOf(nextLine[5])); */ final CatalogVersionModel catver = modelService.create(CatalogVersionModel.class); catver.setCatalog(cat); catver.setVersion("Staged"); catver.setActive(new Boolean(true));
final CategoryModel categoryModel = modelService.create(CategoryModel.class); categoryModel.setCode(nextLine[0]); categoryModel.setCatalogVersion(catver); modelService.save(categoryModel); catalog is already created as Distributioncatalog type. i want to use existing catalog. i donot want create once again catalog. code has been attached. please giv e me the solution to set the catalogversion inside the categoery model...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

code is..

final List newAttributes = new ArrayList(); System.out.println(""); System.out.println(newAttributes);

                 final DistributionCatalogModel cat = modelService.create(DistributionCatalogModel.class);
                 //DistributionCatalogModel c=modelService.getAll(arg0, arg1)
                 //    cat.getChannelName();
                 cat.setId(nextLine[2]);
                 cat.setDefaultCatalog(new Boolean(true));
 
                 /*
                  * cat.setChannelName(nextLine[3]); cat.setChannelContactName(nextLine[6]);
                  * cat.setChannelContactEmail(nextLine[7]); cat.setChannelType(ChannelTypeEnum.valueOf(nextLine[4]));
                  * cat.setChannelStatus(ChannelStatusEnum.valueOf(nextLine[5]));
                  */
 
 
 
 
                 final CatalogVersionModel catver = modelService.create(CatalogVersionModel.class);
                 catver.setCatalog(cat);
                 catver.setVersion("Staged");
                 catver.setActive(new Boolean(true));
 
 
 
                 final CategoryModel categoryModel = modelService.create(CategoryModel.class);
                 categoryModel.setCode(nextLine[0]);
                 categoryModel.setCatalogVersion(catver);
 
                 modelService.save(categoryModel);

Answers (2)

Answers (2)

Former Member
0 Kudos
 /*
  * [y] hybris Platform
  *
  * Copyright (c) 2000-2015 hybris AG
  * All rights reserved.
  *
  * This software is the confidential and proprietary information of hybris
  * ("Confidential Information"). You shall not disclose such Confidential
  * Information and shall use it only in accordance with the terms of the
  * license agreement you entered into with hybris.
  *
  *
  */
 package com.sonata.intrepid.csv;
 
 import de.hybris.platform.catalog.CatalogService;
 import de.hybris.platform.catalog.model.CatalogModel;
 import de.hybris.platform.catalog.model.CatalogVersionModel;
 import de.hybris.platform.category.CategoryService;
 import de.hybris.platform.category.model.CategoryModel;
 import de.hybris.platform.core.model.product.ProductModel;
 import de.hybris.platform.cronjob.enums.CronJobResult;
 import de.hybris.platform.cronjob.enums.CronJobStatus;
 import de.hybris.platform.cronjob.model.CronJobModel;
 import de.hybris.platform.product.daos.impl.DefaultProductDao;
 import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
 import de.hybris.platform.servicelayer.cronjob.PerformResult;
 import de.hybris.platform.servicelayer.model.ModelService;
 
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
 
 import au.com.bytecode.opencsv.CSVReader;
 
 
 /**
  *
  */
 public class TravelProduct extends AbstractJobPerformable<CronJobModel>
 {
     private ModelService modelService;
     private DefaultProductDao productDao;
     private CatalogService catalogService;
     private CategoryService categoryService;
     CSVReader reader;
 
     /**
      * @return the catalogService
      */
     public CatalogService getCatalogService()
     {
         return catalogService;
 
     }
 
     /**
      * @return the categoryService
      */
     public CategoryService getCategoryService()
     {
         return categoryService;
     }
 
     /**
      * @param categoryService
      *           the categoryService to set
      */
     public void setCategoryService(final CategoryService categoryService)
     {
         this.categoryService = categoryService;
     }
 
     /**
      * @param catalogService
      *           the catalogService to set
      */
     public void setCatalogService(final CatalogService catalogService)
     {
         this.catalogService = catalogService;
     }
 
     @Override
     @SuppressWarnings("PMD.AvoidPrintStackTrace")
     public PerformResult perform(final CronJobModel arg0)
     {
         try
         {
             //reader = new CSVReader(new FileReaderSource("C:/Users/anjani.k/Desktop/CSV/PlayingWithCSV/src/aa.csv", ',', '\'', 5)));
             reader = new CSVReader(new FileReader("C:/Users/anjani.k/Desktop/CSV/PlayingWithCSV/src/Travel_Product.csv"), ',', '\'',
                     1);
         }
         catch (final FileNotFoundException e1)
         {
             // YTODO Auto-generated catch block
             e1.printStackTrace();
         }
 
         String[] nextLine;
         try
         {
             while ((nextLine = reader.readNext()) != null)
             {
                 //    final String s1 = nextLine[0];
                 //    final String s2 = nextLine[1];
                 final String productCode = nextLine[1];
                 final String productName = nextLine[2];
                 final String packageCode = nextLine[3];
                 final String supplier = nextLine[4];
                 final String distributionChannel = nextLine[5];
 
                 final String STAGED = "Staged";
                 final Boolean setvalue = Boolean.valueOf(true);
 
 
                 final CatalogModel catalog = createCatalog(distributionChannel, setvalue);
                 // create catalogVersion
                 final CatalogVersionModel catalogVersion = createCatalogVersion(catalog, STAGED);
                 // create category
                 final CategoryModel categoryModel1 = createCategory(catalogVersion, packageCode);
 
                 // save prudoct
                 final ProductModel productModel = modelService.create(ProductModel.class);
                 productModel.setCode(productCode);
                 productModel.setName(productName);
                 productModel.setManufacturerName(supplier);
                 productModel.setCatalogVersion(catalogVersion);
 
                 if (categoryModel1 != null)
                 {
                     productModel.setSupercategories(Arrays.asList(categoryModel1));
                 }
                 //    pr.setSupercategories(categoryModel1);
 
                 modelService.save(productModel);
 
                 System.out.println(productCode + "done categoerys" + distributionChannel + "Package name:" + packageCode);
 
             }
 
         }
         catch (final IOException e)
         {
             // YTODO Auto-generated catch block
             e.printStackTrace();
         }
         return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
     }
 
     private final CatalogModel createCatalog(final String id, final Boolean setvalue)
     {
         final CatalogModel catalog = modelService.create(CatalogModel.class);
         catalog.setId(id);
         catalog.setDefaultCatalog(setvalue);
 
 
         return catalog;
     }
 
     @SuppressWarnings("deprecation")
     private CatalogVersionModel createCatalogVersion(final CatalogModel catalog, final String version)
     {
 
         if (null == catalogService.getCatalogVersion(catalog.getId(), version))
         {
             final CatalogVersionModel catalogVersion = modelService.create(CatalogVersionModel.class);
             catalogVersion.setVersion(version);
             catalogVersion.setCatalog(catalog);
             catalog.setCatalogVersions(Collections.singleton(catalogVersion));
             return catalogVersion;
 
         }
         else
         {
             @SuppressWarnings("deprecation")
             final CatalogVersionModel catalogVersion = catalogService.getCatalogVersion(catalog.getId(), version);
             return catalogVersion;
 
         }
     }
 
     @SuppressWarnings("deprecation")
     private CategoryModel createCategory(final CatalogVersionModel catalogVersionModel, final String code)
     {
         if (null == categoryService.getCategory(code))
         {
             final CategoryModel categoryModel1 = modelService.create(CategoryModel.class);
             categoryModel1.setCode(code);
             //cat.setName(name);
             categoryModel1.setCatalogVersion(catalogVersionModel);
             return categoryModel1;
         }
         else
         {
             @SuppressWarnings("deprecation")
             final CategoryModel categoryModel1 = categoryService.getCategory(code);
             return categoryModel1;
 
         }
     }
 
     /**
      * @return the modelService
      */
     public ModelService getModelService()
     {
         return modelService;
     }
 
     /**
      * @param modelService
      *           the modelService to set
      */
     @Override
     public void setModelService(final ModelService modelService)
     {
         this.modelService = modelService;
     }
 
     /**
      * @return the productDao
      */
     public DefaultProductDao getProductDao()
     {
         return productDao;
     }
 
     /**
      * @param productDao
      *           the productDao to set
      */
     public void setProductDao(final DefaultProductDao productDao)
     {
         this.productDao = productDao;
     }
 
 
 }
 i am using through the cron job. and it is working now
Former Member
0 Kudos

Hi guys, any solution for this requirement..

Regadrs anjani