proj_name
stringclasses
131 values
relative_path
stringlengths
30
228
class_name
stringlengths
1
68
func_name
stringlengths
1
48
masked_class
stringlengths
78
9.82k
func_body
stringlengths
46
9.61k
len_input
int64
29
2.01k
len_output
int64
14
1.94k
total
int64
55
2.05k
relevant_context
stringlengths
0
38.4k
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableManufacturerMapper.java
ReadableManufacturerMapper
convert
class ReadableManufacturerMapper implements Mapper<Manufacturer, ReadableManufacturer> { @Override public ReadableManufacturer convert(Manufacturer source, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} private Optional<com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription> getDescription( Manufacturer source, Language language, ReadableManufacturer target) { Optional<ManufacturerDescription> description = getDescription(source.getDescriptions(), language); if (source.getDescriptions() != null && !source.getDescriptions().isEmpty() && description.isPresent()) { return Optional.of(convertDescription(description.get(), source)); } else { return Optional.empty(); } } private Optional<ManufacturerDescription> getDescription( Set<ManufacturerDescription> descriptionsLang, Language language) { Optional<ManufacturerDescription> descriptionByLang = descriptionsLang.stream() .filter(desc -> desc.getLanguage().getCode().equals(language.getCode())).findAny(); if (descriptionByLang.isPresent()) { return descriptionByLang; } else { return Optional.empty(); } } private com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription convertDescription( ManufacturerDescription description, Manufacturer source) { final com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription desc = new com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription(); desc.setFriendlyUrl(description.getUrl()); desc.setId(description.getId()); desc.setLanguage(description.getLanguage().getCode()); desc.setName(description.getName()); desc.setDescription(description.getDescription()); return desc; } @Override public ReadableManufacturer merge(Manufacturer source, ReadableManufacturer destination, MerchantStore store, Language language) { return destination; } }
if(language == null) { language = store.getDefaultLanguage(); } ReadableManufacturer target = new ReadableManufacturer(); Optional<com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription> description = getDescription(source, language, target); description.ifPresent(target::setDescription); target.setCode(source.getCode()); target.setId(source.getId()); target.setOrder(source.getOrder()); Optional<com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription> desc = this.getDescription(source, language, target); if(description.isPresent()) { target.setDescription(desc.get()); } return target;
535
201
736
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableMinimalProductMapper.java
ReadableMinimalProductMapper
convert
class ReadableMinimalProductMapper implements Mapper<Product, ReadableMinimalProduct> { @Autowired private PricingService pricingService; @Autowired @Qualifier("img") private ImageFilePath imageUtils; @Override public ReadableMinimalProduct convert(Product source, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} @Override public ReadableMinimalProduct merge(Product source, ReadableMinimalProduct destination, MerchantStore store, Language language) { Validate.notNull(source, "Product cannot be null"); Validate.notNull(destination, "ReadableMinimalProduct cannot be null"); for (ProductDescription desc : source.getDescriptions()) { if (language != null && desc.getLanguage() != null && desc.getLanguage().getId().intValue() == language.getId().intValue()) { destination.setDescription(this.description(desc)); break; } } destination.setId(source.getId()); destination.setAvailable(source.isAvailable()); destination.setProductShipeable(source.isProductShipeable()); ProductSpecification specifications = new ProductSpecification(); specifications.setHeight(source.getProductHeight()); specifications.setLength(source.getProductLength()); specifications.setWeight(source.getProductWeight()); specifications.setWidth(source.getProductWidth()); destination.setProductSpecifications(specifications); destination.setPreOrder(source.isPreOrder()); destination.setRefSku(source.getRefSku()); destination.setSortOrder(source.getSortOrder()); destination.setSku(source.getSku()); if(source.getDateAvailable() != null) { destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable())); } if(source.getProductReviewAvg()!=null) { double avg = source.getProductReviewAvg().doubleValue(); double rating = Math.round(avg * 2) / 2.0f; destination.setRating(rating); } destination.setProductVirtual(source.getProductVirtual()); if(source.getProductReviewCount()!=null) { destination.setRatingCount(source.getProductReviewCount().intValue()); } //price try { FinalPrice price = pricingService.calculateProductPrice(source); if(price != null) { destination.setFinalPrice(pricingService.getDisplayAmount(price.getFinalPrice(), store)); destination.setPrice(price.getFinalPrice()); destination.setOriginalPrice(pricingService.getDisplayAmount(price.getOriginalPrice(), store)); } } catch (ServiceException e) { throw new ConversionRuntimeException("An error occured during price calculation", e); } //image Set<ProductImage> images = source.getImages(); if(images!=null && images.size()>0) { List<ReadableImage> imageList = new ArrayList<ReadableImage>(); String contextPath = imageUtils.getContextPath(); for(ProductImage img : images) { ReadableImage prdImage = new ReadableImage(); prdImage.setImageName(img.getProductImage()); prdImage.setDefaultImage(img.isDefaultImage()); StringBuilder imgPath = new StringBuilder(); imgPath.append(contextPath).append(imageUtils.buildProductImageUtils(store, source.getSku(), img.getProductImage())); prdImage.setImageUrl(imgPath.toString()); prdImage.setId(img.getId()); prdImage.setImageType(img.getImageType()); if(img.getProductImageUrl()!=null){ prdImage.setExternalUrl(img.getProductImageUrl()); } if(img.getImageType()==1 && img.getProductImageUrl()!=null) {//video prdImage.setVideoUrl(img.getProductImageUrl()); } if(prdImage.isDefaultImage()) { destination.setImage(prdImage); } imageList.add(prdImage); } destination .setImages(imageList); } return null; } private ReadableDescription description(ProductDescription description) { ReadableDescription desc = new ReadableDescription(); desc.setDescription(description.getDescription()); desc.setName(description.getName()); desc.setId(description.getId()); desc.setLanguage(description.getLanguage().getCode()); return desc; } }
// TODO Auto-generated method stub ReadableMinimalProduct minimal = new ReadableMinimalProduct(); return this.merge(source, minimal, store, language);
1,259
44
1,303
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableProductAttributeMapper.java
ReadableProductAttributeMapper
convert
class ReadableProductAttributeMapper implements Mapper<ProductAttribute, ReadableProductAttributeEntity> { @Autowired private ReadableProductOptionMapper readableProductOptionMapper; @Autowired private ReadableProductOptionValueMapper readableProductOptionValueMapper; @Autowired private PricingService pricingService; @Override public ReadableProductAttributeEntity convert(ProductAttribute source, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} @Override public ReadableProductAttributeEntity merge(ProductAttribute source, ReadableProductAttributeEntity destination, MerchantStore store, Language language) { ReadableProductAttributeEntity attr = new ReadableProductAttributeEntity(); if(destination !=null) { attr = destination; } try { attr.setId(source.getId());//attribute of the option if(source.getProductAttributePrice()!=null && source.getProductAttributePrice().doubleValue()>0) { String formatedPrice; formatedPrice = pricingService.getDisplayAmount(source.getProductAttributePrice(), store); attr.setProductAttributePrice(formatedPrice); attr.setProductAttributeUnformattedPrice(pricingService.getStringAmount(source.getProductAttributePrice(), store)); } attr.setProductAttributeWeight(source.getAttributeAdditionalWeight()); attr.setAttributeDisplayOnly(source.getAttributeDisplayOnly()); attr.setAttributeDefault(source.getAttributeDefault()); if(!StringUtils.isBlank(source.getAttributeSortOrder())) { attr.setSortOrder(Integer.parseInt(source.getAttributeSortOrder())); } if(source.getProductOption()!=null) { ReadableProductOptionEntity option = readableProductOptionMapper.convert(source.getProductOption(), store, language); attr.setOption(option); } if(source.getProductOptionValue()!=null) { ReadableProductOptionValue optionValue = readableProductOptionValueMapper.convert(source.getProductOptionValue(), store, language); attr.setOptionValue(optionValue); } } catch (Exception e) { throw new ConversionRuntimeException("Exception while product attribute conversion",e); } return attr; } }
ReadableProductAttributeEntity productAttribute = new ReadableProductAttributeEntity(); return merge(source, productAttribute, store, language);
584
35
619
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableProductImageMapper.java
ReadableProductImageMapper
merge
class ReadableProductImageMapper implements Mapper<ProductImage, ReadableImage> { @Inject @Qualifier("img") private ImageFilePath imageUtils; @Override public ReadableImage convert(ProductImage source, MerchantStore store, Language language) { ReadableImage destination = new ReadableImage(); return merge(source, destination, store, language); } @Override public ReadableImage merge(ProductImage source, ReadableImage destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} }
String contextPath = imageUtils.getContextPath(); destination.setImageName(source.getProductImage()); destination.setDefaultImage(source.isDefaultImage()); destination.setOrder(source.getSortOrder() != null ? source.getSortOrder().intValue() : 0); if (source.getImageType() == 1 && source.getProductImageUrl()!=null) { destination.setImageUrl(source.getProductImageUrl()); } else { StringBuilder imgPath = new StringBuilder(); imgPath.append(contextPath).append(imageUtils.buildProductImageUtils(store, source.getProduct().getSku(), source.getProductImage())); destination.setImageUrl(imgPath.toString()); } destination.setId(source.getId()); destination.setImageType(source.getImageType()); if(source.getProductImageUrl()!=null){ destination.setExternalUrl(source.getProductImageUrl()); } if(source.getImageType()==1 && source.getProductImageUrl()!=null) {//video destination.setVideoUrl(source.getProductImageUrl()); } return destination;
138
317
455
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableProductOptionMapper.java
ReadableProductOptionMapper
merge
class ReadableProductOptionMapper implements Mapper<ProductOption, ReadableProductOptionEntity> { @Override public ReadableProductOptionEntity convert(ProductOption source, MerchantStore store, Language language) { ReadableProductOptionEntity destination = new ReadableProductOptionEntity(); return merge(source, destination, store, language); } @Override public ReadableProductOptionEntity merge(ProductOption source, ReadableProductOptionEntity destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription description(ProductOptionDescription description) { com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription desc = new com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription(); desc.setDescription(description.getDescription()); desc.setName(description.getName()); desc.setId(description.getId()); desc.setLanguage(description.getLanguage().getCode()); return desc; } }
ReadableProductOptionEntity readableProductOption = new ReadableProductOptionEntity(); if(language == null) { readableProductOption = new ReadableProductOptionFull(); List<com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription> descriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription>(); for(ProductOptionDescription desc : source.getDescriptions()) { com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription d = this.description(desc); descriptions.add(d); } ((ReadableProductOptionFull)readableProductOption).setDescriptions(descriptions); } else { readableProductOption = new ReadableProductOptionEntity(); if(!CollectionUtils.isEmpty(source.getDescriptions())) { for(ProductOptionDescription desc : source.getDescriptions()) { if(desc != null && desc.getLanguage()!= null && desc.getLanguage().getId() == language.getId()) { com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription d = this.description(desc); readableProductOption.setDescription(d); } } } } readableProductOption.setCode(source.getCode()); readableProductOption.setId(source.getId()); readableProductOption.setType(source.getProductOptionType()); return readableProductOption;
273
376
649
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableProductOptionSetMapper.java
ReadableProductOptionSetMapper
convert
class ReadableProductOptionSetMapper implements Mapper<ProductOptionSet, ReadableProductOptionSet> { @Autowired private ReadableProductTypeMapper readableProductTypeMapper; @Override public ReadableProductOptionSet convert(ProductOptionSet source, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} @Override public ReadableProductOptionSet merge(ProductOptionSet source, ReadableProductOptionSet destination, MerchantStore store, Language language) { Validate.notNull(source,"ProductOptionSet must not be null"); Validate.notNull(destination,"ReadableProductOptionSet must not be null"); destination.setId(source.getId()); destination.setCode(source.getCode()); destination.setReadOnly(source.isOptionDisplayOnly()); destination.setOption(this.option(source.getOption(), store, language)); List<Long> ids = new ArrayList<Long>(); if(!CollectionUtils.isEmpty(source.getValues())) { List<ReadableProductOptionValue> values = source.getValues().stream().map(val -> optionValue(ids, val, store, language)).collect(Collectors.toList()); destination.setValues(values); destination.getValues().removeAll(Collections.singleton(null)); } if(!CollectionUtils.isEmpty(source.getProductTypes())) { List<ReadableProductType> types = source.getProductTypes().stream().map( t -> this.productType(t, store, language)).collect(Collectors.toList()); destination.setProductTypes(types); } return destination; } private ReadableProductOption option (ProductOption option, MerchantStore store, Language lang) { ReadableProductOption opt = new ReadableProductOption(); opt.setCode(option.getCode()); opt.setId(option.getId()); opt.setLang(lang.getCode()); opt.setReadOnly(option.isReadOnly()); opt.setType(option.getProductOptionType()); ProductOptionDescription desc = this.optionDescription(option.getDescriptions(), lang); if(desc != null) { opt.setName(desc.getName()); } return opt; } private ReadableProductOptionValue optionValue (List<Long> ids, ProductOptionValue optionValue, MerchantStore store, Language language) { if(!ids.contains(optionValue.getId())) { ReadableProductOptionValue value = new ReadableProductOptionValue(); value.setCode(optionValue.getCode()); value.setId(optionValue.getId()); ProductOptionValueDescription desc = optionValueDescription(optionValue.getDescriptions(), language); if(desc!=null) { value.setName(desc.getName()); } ids.add(optionValue.getId()); return value; } else { return null; } } private ProductOptionDescription optionDescription(Set<ProductOptionDescription> descriptions, Language lang) { return descriptions.stream().filter(desc-> desc.getLanguage().getCode().equals(lang.getCode())).findAny().orElse(null); } private ProductOptionValueDescription optionValueDescription(Set<ProductOptionValueDescription> descriptions, Language lang) { return descriptions.stream().filter(desc-> desc.getLanguage().getCode().equals(lang.getCode())).findAny().orElse(null); } private ReadableProductType productType(ProductType type, MerchantStore store, Language language) { return readableProductTypeMapper.convert(type, store, language); } }
ReadableProductOptionSet optionSource = new ReadableProductOptionSet(); return merge(source, optionSource, store, language);
942
35
977
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableProductOptionValueMapper.java
ReadableProductOptionValueMapper
merge
class ReadableProductOptionValueMapper implements Mapper<ProductOptionValue, ReadableProductOptionValue> { @Autowired @Qualifier("img") private ImageFilePath imageUtils; @Override public ReadableProductOptionValue merge(ProductOptionValue source, ReadableProductOptionValue destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription description(ProductOptionValueDescription description) { com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription desc = new com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription(); desc.setDescription(description.getDescription()); desc.setName(description.getName()); desc.setId(description.getId()); desc.setLanguage(description.getLanguage().getCode()); return desc; } @Override public ReadableProductOptionValue convert(ProductOptionValue source, MerchantStore store, Language language) { ReadableProductOptionValue destination = new ReadableProductOptionValue(); return merge(source, destination, store, language); } }
ReadableProductOptionValue readableProductOptionValue = new ReadableProductOptionValue(); if(language == null) { readableProductOptionValue = new ReadableProductOptionValueFull(); List<com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription> descriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription>(); for(ProductOptionValueDescription desc : source.getDescriptions()) { com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription d = this.description(desc); descriptions.add(d); } ((ReadableProductOptionValueFull)readableProductOptionValue).setDescriptions(descriptions); } else { readableProductOptionValue = new ReadableProductOptionValue(); if(!CollectionUtils.isEmpty(source.getDescriptions())) { for(ProductOptionValueDescription desc : source.getDescriptions()) { if(desc != null && desc.getLanguage()!= null && desc.getLanguage().getId() == language.getId()) { com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription d = this.description(desc); readableProductOptionValue.setDescription(d); } } } } readableProductOptionValue.setCode(source.getCode()); if(source.getId()!=null) { readableProductOptionValue.setId(source.getId().longValue()); } if(source.getProductOptionValueSortOrder()!=null) { readableProductOptionValue.setOrder(source.getProductOptionValueSortOrder().intValue()); } if(!StringUtils.isBlank(source.getProductOptionValueImage())) { readableProductOptionValue.setImage(imageUtils.buildProductPropertyImageUtils(store, source.getProductOptionValueImage())); } return readableProductOptionValue;
300
494
794
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableProductTypeMapper.java
ReadableProductTypeMapper
merge
class ReadableProductTypeMapper implements Mapper<ProductType, ReadableProductType> { @Override public ReadableProductType convert(ProductType source, MerchantStore store, Language language) { ReadableProductType type = new ReadableProductType(); return this.merge(source, type, store, language); } @Override public ReadableProductType merge(ProductType source, ReadableProductType destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} private ReadableProductType type (ProductType type, Language language) { ReadableProductType readableType = null; if(language != null) { readableType = new ReadableProductType(); if(!CollectionUtils.isEmpty(type.getDescriptions())) { Optional<ProductTypeDescription> desc = type.getDescriptions().stream().filter(t -> t.getLanguage().getCode().equals(language.getCode())) .map(d -> typeDescription(d)).findFirst(); if(desc.isPresent()) { readableType.setDescription(desc.get()); } } } else { readableType = new ReadableProductTypeFull(); List<ProductTypeDescription> descriptions = type.getDescriptions().stream().map(t -> this.typeDescription(t)).collect(Collectors.toList()); ((ReadableProductTypeFull)readableType).setDescriptions(descriptions); } readableType.setCode(type.getCode()); readableType.setId(type.getId()); readableType.setVisible(type.getVisible() != null && type.getVisible().booleanValue() ? true:false); readableType.setAllowAddToCart(type.getAllowAddToCart() != null && type.getAllowAddToCart().booleanValue() ? true:false); return readableType; } private ProductTypeDescription typeDescription(com.salesmanager.core.model.catalog.product.type.ProductTypeDescription description) { ProductTypeDescription desc = new ProductTypeDescription(); desc.setId(description.getId()); desc.setName(description.getName()); desc.setDescription(description.getDescription()); desc.setLanguage(description.getLanguage().getCode()); return desc; } }
Validate.notNull(source, "ProductType cannot be null"); Validate.notNull(destination, "ReadableProductType cannot be null"); return type(source, language);
595
51
646
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableProductVariationMapper.java
ReadableProductVariationMapper
optionValue
class ReadableProductVariationMapper implements Mapper<ProductVariation, ReadableProductVariation> { @Override public ReadableProductVariation convert(ProductVariation source, MerchantStore store, Language language) { ReadableProductVariation variation = new ReadableProductVariation(); return merge(source, variation, store, language); } @Override public ReadableProductVariation merge(ProductVariation source, ReadableProductVariation destination, MerchantStore store, Language language) { Validate.notNull(source,"ProductVariation must not be null"); Validate.notNull(destination,"ReadableProductVariation must not be null"); destination.setId(source.getId()); destination.setCode(source.getCode()); destination.setOption(this.option(source.getProductOption(), language)); destination.setOptionValue(this.optionValue(source.getProductOptionValue(), store, language)); return destination; } private ReadableProductOption option (ProductOption option, Language lang) { ReadableProductOption opt = new ReadableProductOption(); opt.setCode(option.getCode()); opt.setId(option.getId()); opt.setLang(lang.getCode()); opt.setReadOnly(option.isReadOnly()); opt.setType(option.getProductOptionType()); ProductOptionDescription desc = this.optionDescription(option.getDescriptions(), lang); if(desc != null) { opt.setName(desc.getName()); } return opt; } private ReadableProductOptionValue optionValue (ProductOptionValue val, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} private ProductOptionDescription optionDescription(Set<ProductOptionDescription> descriptions, Language lang) { return descriptions.stream().filter(desc-> desc.getLanguage().getCode().equals(lang.getCode())).findAny().orElse(null); } private ProductOptionValueDescription optionValueDescription(Set<ProductOptionValueDescription> descriptions, Language lang) { return descriptions.stream().filter(desc-> desc.getLanguage().getCode().equals(lang.getCode())).findAny().orElse(null); } }
ReadableProductOptionValue value = new ReadableProductOptionValue(); value.setCode(val.getCode()); value.setId(val.getId()); ProductOptionValueDescription desc = optionValueDescription(val.getDescriptions(), language); if(desc!=null) { value.setName(desc.getName()); } return value;
578
99
677
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/product/PersistableProductAvailabilityMapper.java
PersistableProductAvailabilityMapper
merge
class PersistableProductAvailabilityMapper implements Mapper<PersistableProductInventory, ProductAvailability> { @Override public ProductAvailability convert(PersistableProductInventory source, MerchantStore store, Language language) { return this.merge(source, new ProductAvailability(), store, language); } @Override public ProductAvailability merge(PersistableProductInventory source, ProductAvailability destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} }
try { destination.setRegion(Constants.ALL_REGIONS); destination.setProductQuantity(source.getQuantity()); destination.setProductQuantityOrderMin(1); destination.setProductQuantityOrderMax(1); if (source.getPrice() != null) { ProductPrice price = new ProductPrice(); price.setProductAvailability(destination); price.setDefaultPrice(source.getPrice().isDefaultPrice()); price.setProductPriceAmount(source.getPrice().getPrice()); price.setCode(source.getPrice().getCode()); price.setProductPriceSpecialAmount(source.getPrice().getDiscountedPrice()); if (source.getPrice().getDiscountStartDate() != null) { Date startDate; startDate = DateUtil.getDate(source.getPrice().getDiscountStartDate()); price.setProductPriceSpecialStartDate(startDate); } if (source.getPrice().getDiscountEndDate() != null) { Date endDate = DateUtil.getDate(source.getPrice().getDiscountEndDate()); price.setProductPriceSpecialEndDate(endDate); } destination.getPrices().add(price); for (Language lang : store.getLanguages()) { ProductPriceDescription ppd = new ProductPriceDescription(); ppd.setProductPrice(price); ppd.setLanguage(lang); ppd.setName(ProductPriceDescription.DEFAULT_PRICE_DESCRIPTION); // price appender Optional<com.salesmanager.shop.model.catalog.product.ProductPriceDescription> description = source .getPrice().getDescriptions().stream() .filter(d -> d.getLanguage() != null && d.getLanguage().equals(lang.getCode())).findFirst(); if (description.isPresent()) { ppd.setPriceAppender(description.get().getPriceAppender()); } price.getDescriptions().add(ppd); } } } catch (Exception e) { throw new ServiceRuntimeException("An error occured while mapping product availability", e); } return destination;
124
585
709
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/product/PersistableProductVariantGroupMapper.java
PersistableProductVariantGroupMapper
merge
class PersistableProductVariantGroupMapper implements Mapper<PersistableProductVariantGroup, ProductVariantGroup>{ @Autowired private ProductVariantService productVariantService; @Autowired private ProductVariantImageService productVariantImageService; @Override public ProductVariantGroup convert(PersistableProductVariantGroup source, MerchantStore store, Language language) { Validate.notNull(source, "PersistableproductVariantGroup cannot be null"); Validate.notNull(store, "MerchantStore cannot be null"); Validate.notNull(language, "Language cannot be null"); return this.merge(source, new ProductVariantGroup(), store, language); } @Override public ProductVariantGroup merge(PersistableProductVariantGroup source, ProductVariantGroup destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} private ProductVariant instance(ProductVariant instance, ProductVariantGroup group, MerchantStore store) { instance.setProductVariantGroup(group); return instance; } }
Validate.notNull(source, "PersistableproductVariantGroup cannot be null"); Validate.notNull(store, "MerchantStore cannot be null"); Validate.notNull(language, "Language cannot be null"); Validate.notNull(source.getproductVariants(), "Product instances cannot be null"); if(destination == null) { destination = new ProductVariantGroup(); } destination.setId(source.getId()); List<ProductVariant> productVariants = productVariantService.getByIds(source.getproductVariants(), store); for(ProductVariant p : productVariants) { p.setProductVariantGroup(destination); } //images are not managed from this object if(source.getId() != null) { List<ProductVariantImage> images = productVariantImageService.listByProductVariantGroup(source.getId(), store); destination.setImages(images); } destination.setMerchantStore(store); destination.setProductVariants(new HashSet<ProductVariant>(productVariants)); return destination;
284
308
592
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/product/PersistableProductVariantMapper.java
PersistableProductVariantMapper
merge
class PersistableProductVariantMapper implements Mapper<PersistableProductVariant, ProductVariant> { @Autowired private ProductVariationService productVariationService; @Autowired private PersistableProductAvailabilityMapper persistableProductAvailabilityMapper; @Autowired private ProductService productService; @Override public ProductVariant convert(PersistableProductVariant source, MerchantStore store, Language language) { ProductVariant productVariantModel = new ProductVariant(); return this.merge(source, productVariantModel, store, language); } @Override public ProductVariant merge(PersistableProductVariant source, ProductVariant destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} }
// Long productVariation = source.getVariation(); Long productVariationValue = source.getVariationValue(); String productVariationCode = source.getVariationCode(); String productVariationValueCode = source.getVariationValueCode(); Optional<ProductVariation> variation = null; Optional<ProductVariation> variationValue = null; if(StringUtils.isEmpty(productVariationCode)) { variation = productVariationService.getById(store, productVariation); if(productVariationValue != null) { variationValue = productVariationService.getById(store, productVariationValue); if(variationValue.isEmpty()) { throw new ResourceNotFoundException("ProductVaritionValue [" + productVariationValue + "] + not found for store [" + store.getCode() + "]"); } } } else { variation = productVariationService.getByCode(store, productVariationCode); if(productVariationValueCode != null) { variationValue = productVariationService.getByCode(store, productVariationValueCode); if(variationValue.isEmpty()) { throw new ResourceNotFoundException("ProductVaritionValue [" + productVariationValue + "] + not found for store [" + store.getCode() + "]"); } } } if(variation.isEmpty()) { throw new ResourceNotFoundException("ProductVarition [" + productVariation + "] + not found for store [" + store.getCode() + "]"); } destination.setVariation(variation.get()); if(productVariationValue != null) { destination.setVariationValue(variationValue.get()); } StringBuilder instanceCode = new StringBuilder(); instanceCode.append(variation.get().getCode()); if(productVariationValue != null && variationValue.get()!=null) { instanceCode.append(":").append(variationValue.get().getCode()); } destination.setCode(instanceCode.toString()); destination.setAvailable(source.isAvailable()); destination.setDefaultSelection(source.isDefaultSelection()); destination.setSku(source.getSku()); if(StringUtils.isBlank(source.getDateAvailable())) { source.setDateAvailable(DateUtil.formatDate(new Date())); } if(source.getDateAvailable()!=null) { try { destination.setDateAvailable(DateUtil.getDate(source.getDateAvailable())); } catch (Exception e) { throw new ServiceRuntimeException("Cant format date [" + source.getDateAvailable() + "]"); } } destination.setSortOrder(source.getSortOrder()); /** * Inventory */ if(source.getInventory() != null) { ProductAvailability availability = persistableProductAvailabilityMapper.convert(source.getInventory(), store, language); availability.setProductVariant(destination); destination.getAvailabilities().add(availability); } Product product = null; if(source.getProductId() != null && source.getProductId().longValue() > 0) { product = productService.findOne(source.getProductId(), store); if(product == null) { throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]"); } if(product.getMerchantStore().getId() != store.getId()) { throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]"); } if(product.getSku() != null && product.getSku().equals(source.getSku())) { throw new OperationNotAllowedException("Product variant sku [" + source.getSku() + "] + must be different than product instance sku [" + product.getSku() + "]"); } destination.setProduct(product); } return destination;
195
1,114
1,309
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/product/ReadableProductVariantGroupMapper.java
ReadableProductVariantGroupMapper
convert
class ReadableProductVariantGroupMapper implements Mapper<ProductVariantGroup, ReadableProductVariantGroup> { @Autowired private ReadableProductVariantMapper readableProductVariantMapper; @Inject @Qualifier("img") private ImageFilePath imageUtils; @Override public ReadableProductVariantGroup convert(ProductVariantGroup source, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} @Override public ReadableProductVariantGroup merge(ProductVariantGroup source, ReadableProductVariantGroup destination, MerchantStore store, Language language) { Validate.notNull(source, "productVariantGroup cannot be null"); Validate.notNull(store, "MerchantStore cannot be null"); Validate.notNull(language, "Language cannot be null"); if(destination == null) { destination = new ReadableProductVariantGroup(); } destination.setId(source.getId()); Set<ProductVariant> instances = source.getProductVariants(); destination.setproductVariants(instances.stream().map(i -> this.instance(i, store, language)).collect(Collectors.toList())); //image id should be unique in the list Map<Long,ReadableImage> finalList = new HashMap<Long, ReadableImage>(); List<ReadableImage> originalList = source.getImages().stream() .map(i -> this.image(finalList, i, store, language)) .collect(Collectors.toList()); destination.setImages(new ArrayList<ReadableImage>(finalList.values())); return destination; } private ReadableProductVariant instance(ProductVariant instance, MerchantStore store, Language language) { return readableProductVariantMapper.convert(instance, store, language); } private ReadableImage image(Map<Long,ReadableImage> finalList , ProductVariantImage img, MerchantStore store, Language language) { ReadableImage readable = null; if(!finalList.containsKey(img.getId())) { readable = new ReadableImage(); readable.setId(img.getId()); readable.setImageName(img.getProductImage()); readable.setImageUrl(imageUtils.buildCustomTypeImageUtils(store, img.getProductImage(), FileContentType.VARIANT)); readable.setDefaultImage(img.isDefaultImage()); finalList.put(img.getId(), readable); } return readable; } }
Validate.notNull(source, "productVariantGroup cannot be null"); Validate.notNull(store, "MerchantStore cannot be null"); Validate.notNull(language, "Language cannot be null"); return this.merge(source, new ReadableProductVariantGroup(), store, language);
668
80
748
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/product/ReadableProductVariantMapper.java
ReadableProductVariantMapper
merge
class ReadableProductVariantMapper implements Mapper<ProductVariant, ReadableProductVariant> { @Autowired private ReadableProductVariationMapper readableProductVariationMapper; @Autowired private ReadableInventoryMapper readableInventoryMapper; @Inject @Qualifier("img") private ImageFilePath imagUtils; @Override public ReadableProductVariant convert(ProductVariant source, MerchantStore store, Language language) { ReadableProductVariant readableproductVariant = new ReadableProductVariant(); return this.merge(source, readableproductVariant, store, language); } @Override public ReadableProductVariant merge(ProductVariant source, ReadableProductVariant destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} private ReadableImage image(ProductVariantImage instanceImage, MerchantStore store, Language language) { ReadableImage img = new ReadableImage(); img.setDefaultImage(instanceImage.isDefaultImage()); img.setId(instanceImage.getId()); img.setImageName(instanceImage.getProductImage()); img.setImageUrl(imagUtils.buildCustomTypeImageUtils(store, img.getImageName(), FileContentType.VARIANT)); return img; } }
Validate.notNull(source, "Product instance cannot be null"); Validate.notNull(source.getProduct(), "Product cannot be null"); if(destination == null) { destination = new ReadableProductVariant(); } destination.setSortOrder(source.getSortOrder() != null ? source.getSortOrder().intValue():0); destination.setAvailable(source.isAvailable()); destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable())); destination.setId(source.getId()); destination.setDefaultSelection(source.isDefaultSelection()); destination.setProductId(source.getProduct().getId()); destination.setSku(source.getSku()); destination.setSortOrder(source.getSortOrder()); destination.setCode(source.getCode()); //get product Product baseProduct = source.getProduct(); if(baseProduct == null) { throw new ResourceNotFoundException("Product instances do not include the parent product [" + destination.getSku() + "]"); } destination.setProductShipeable(baseProduct.isProductShipeable()); //destination.setStore(null); destination.setStore(store.getCode()); destination.setVariation(readableProductVariationMapper.convert(source.getVariation(), store, language)); if(source.getVariationValue() != null) { destination.setVariationValue(readableProductVariationMapper.convert(source.getVariationValue(), store, language)); } if(source.getProductVariantGroup() != null) { Set<String> nameSet = new HashSet<>(); List<ReadableImage> instanceImages = source.getProductVariantGroup().getImages().stream().map(i -> this.image(i, store, language)) .filter(e -> nameSet.add(e.getImageUrl())) .collect(Collectors.toList()); destination.setImages(instanceImages); } if(!CollectionUtils.isEmpty(source.getAvailabilities())) { List<ReadableInventory> inventories = source.getAvailabilities().stream().map(i -> readableInventoryMapper.convert(i, store, language)).collect(Collectors.toList()); destination.setInventory(inventories); } return destination;
334
632
966
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/customer/ReadableCustomerMapper.java
ReadableCustomerMapper
merge
class ReadableCustomerMapper implements Mapper<Customer, ReadableCustomer> { @Override public ReadableCustomer convert(Customer source, MerchantStore store, Language language) { ReadableCustomer destination = new ReadableCustomer(); return this.merge(source, destination, store, language); } @Override public ReadableCustomer merge(Customer source, ReadableCustomer target, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} }
if(source.getId()!=null && source.getId()>0) { target.setId(source.getId()); } target.setEmailAddress(source.getEmailAddress()); if (StringUtils.isNotEmpty(source.getNick())) { target.setUserName(source.getNick()); } if (source.getDefaultLanguage()!= null) { target.setLanguage(source.getDefaultLanguage().getCode()); } if (source.getGender()!= null) { target.setGender(source.getGender().name()); } if (StringUtils.isNotEmpty(source.getProvider())) { target.setProvider(source.getProvider()); } if(source.getBilling()!=null) { Address address = new Address(); address.setAddress(source.getBilling().getAddress()); address.setCity(source.getBilling().getCity()); address.setCompany(source.getBilling().getCompany()); address.setFirstName(source.getBilling().getFirstName()); address.setLastName(source.getBilling().getLastName()); address.setPostalCode(source.getBilling().getPostalCode()); address.setPhone(source.getBilling().getTelephone()); if(source.getBilling().getCountry()!=null) { address.setCountry(source.getBilling().getCountry().getIsoCode()); } if(source.getBilling().getZone()!=null) { address.setZone(source.getBilling().getZone().getCode()); } if(source.getBilling().getState()!=null) { address.setStateProvince(source.getBilling().getState()); } target.setFirstName(address.getFirstName()); target.setLastName(address.getLastName()); target.setBilling(address); } if(source.getCustomerReviewAvg() != null) { target.setRating(source.getCustomerReviewAvg().doubleValue()); } if(source.getCustomerReviewCount() != null) { target.setRatingCount(source.getCustomerReviewCount().intValue()); } if(source.getDelivery()!=null) { Address address = new Address(); address.setCity(source.getDelivery().getCity()); address.setAddress(source.getDelivery().getAddress()); address.setCompany(source.getDelivery().getCompany()); address.setFirstName(source.getDelivery().getFirstName()); address.setLastName(source.getDelivery().getLastName()); address.setPostalCode(source.getDelivery().getPostalCode()); address.setPhone(source.getDelivery().getTelephone()); if(source.getDelivery().getCountry()!=null) { address.setCountry(source.getDelivery().getCountry().getIsoCode()); } if(source.getDelivery().getZone()!=null) { address.setZone(source.getDelivery().getZone().getCode()); } if(source.getDelivery().getState()!=null) { address.setStateProvince(source.getDelivery().getState()); } target.setDelivery(address); } else { target.setDelivery(target.getBilling()); } if(source.getAttributes()!=null) { for(CustomerAttribute attribute : source.getAttributes()) { ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute(); readableAttribute.setId(attribute.getId()); readableAttribute.setTextValue(attribute.getTextValue()); ReadableCustomerOption option = new ReadableCustomerOption(); option.setId(attribute.getCustomerOption().getId()); option.setCode(attribute.getCustomerOption().getCode()); CustomerOptionDescription d = new CustomerOptionDescription(); d.setDescription(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getDescription()); d.setName(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getName()); option.setDescription(d); readableAttribute.setCustomerOption(option); ReadableCustomerOptionValue optionValue = new ReadableCustomerOptionValue(); optionValue.setId(attribute.getCustomerOptionValue().getId()); CustomerOptionValueDescription vd = new CustomerOptionValueDescription(); vd.setDescription(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getDescription()); vd.setName(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getName()); optionValue.setCode(attribute.getCustomerOptionValue().getCode()); optionValue.setDescription(vd); readableAttribute.setCustomerOptionValue(optionValue); target.getAttributes().add(readableAttribute); } if(source.getGroups() != null) { for(Group group : source.getGroups()) { ReadableGroup readableGroup = new ReadableGroup(); readableGroup.setId(group.getId().longValue()); readableGroup.setName(group.getGroupName()); readableGroup.setType(group.getGroupType().name()); target.getGroups().add( readableGroup ); } } } return target;
117
1,436
1,553
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/inventory/PersistableProductPriceMapper.java
PersistableProductPriceMapper
merge
class PersistableProductPriceMapper implements Mapper<PersistableProductPrice, ProductPrice> { @Autowired private LanguageService languageService; @Autowired private ProductService productService; @Autowired private ProductAvailabilityService productAvailabilityService; @Override public ProductPrice convert(PersistableProductPrice source, MerchantStore store, Language language) { return merge(source, new ProductPrice(), store, language); } @Override public ProductPrice merge(PersistableProductPrice source, ProductPrice destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} private Set<ProductPriceDescription> getProductPriceDescriptions(ProductPrice price, List<com.salesmanager.shop.model.catalog.product.ProductPriceDescription> descriptions, MerchantStore store) { if (CollectionUtils.isEmpty(descriptions)) { return Collections.emptySet(); } Set<ProductPriceDescription> descs = new HashSet<ProductPriceDescription>(); for (com.salesmanager.shop.model.catalog.product.ProductPriceDescription desc : descriptions) { ProductPriceDescription description = null; if (CollectionUtils.isNotEmpty(price.getDescriptions())) { for (ProductPriceDescription d : price.getDescriptions()) { if (isPositive(desc.getId()) && desc.getId().equals(d.getId())) { desc.setId(d.getId()); } } } description = getDescription(desc); description.setProductPrice(price); descs.add(description); } return descs; } private ProductPriceDescription getDescription( com.salesmanager.shop.model.catalog.product.ProductPriceDescription desc) { ProductPriceDescription target = new ProductPriceDescription(); target.setDescription(desc.getDescription()); target.setName(desc.getName()); target.setTitle(desc.getTitle()); target.setId(null); if (isPositive(desc.getId())) { target.setId(desc.getId()); } Language lang = getLanguage(desc); target.setLanguage(lang); return target; } private Language getLanguage(com.salesmanager.shop.model.catalog.product.ProductPriceDescription desc) { try { return Optional.ofNullable(languageService.getByCode(desc.getLanguage())) .orElseThrow(() -> new ConversionRuntimeException( "Language is null for code " + desc.getLanguage() + " use language ISO code [en, fr ...]")); } catch (ServiceException e) { throw new ConversionRuntimeException(e); } } }
Validate.notNull(source, "PersistableProductPrice cannot be null"); Validate.notNull(source.getSku(), "Product sku cannot be null"); try { if (destination == null) { destination = new ProductPrice(); } destination.setId(source.getId()); /** * Get product availability and verify the existing br-pa-1.0.0 * * Cannot have multiple default price for the same product availability Default * price can be edited but cannot create new default price */ ProductAvailability availability = null; if (isPositive(source.getProductAvailabilityId())) { Optional<ProductAvailability> avail = productAvailabilityService .getById(source.getProductAvailabilityId(), store); if (avail.isEmpty()) { throw new ConversionRuntimeException( "Product availability with id [" + source.getProductAvailabilityId() + "] was not found"); } availability = avail.get(); } else { // get an existing product availability List<ProductAvailability> existing = productAvailabilityService.getBySku(source.getSku(), store); if (!CollectionUtils.isEmpty(existing)) { // find default availability Optional<ProductAvailability> avail = existing.stream() .filter(a -> a.getRegion() != null && a.getRegion().equals(Constants.ALL_REGIONS)) .findAny(); if (avail.isPresent()) { availability = avail.get(); // if default price exist for sku exit if (source.isDefaultPrice()) { Optional<ProductPrice> defaultPrice = availability.getPrices().stream() .filter(p -> p.isDefaultPrice()).findAny(); if (defaultPrice.isPresent()) { //throw new ConversionRuntimeException( // "Default Price already exist for product with sku [" + source.getSku() + "]"); destination = defaultPrice.get(); } } } } } if (availability == null) { com.salesmanager.core.model.catalog.product.Product product = productService.getBySku(source.getSku(), store, language); if (product == null) { throw new ConversionRuntimeException("Product with sku [" + source.getSku() + "] not found for MerchantStore [" + store.getCode() + "]"); } availability = new ProductAvailability(); availability.setProduct(product); availability.setRegion(Constants.ALL_REGIONS); } destination.setProductAvailability(availability); destination.setDefaultPrice(source.isDefaultPrice()); destination.setProductPriceAmount(source.getPrice()); destination.setCode(source.getCode()); destination.setProductPriceSpecialAmount(source.getDiscountedPrice()); if (source.getDiscountStartDate() != null) { Date startDate = DateUtil.getDate(source.getDiscountStartDate()); destination.setProductPriceSpecialStartDate(startDate); } if (source.getDiscountEndDate() != null) { Date endDate = DateUtil.getDate(source.getDiscountEndDate()); destination.setProductPriceSpecialEndDate(endDate); } availability.getPrices().add(destination); destination.setProductAvailability(availability); destination.setDescriptions(this.getProductPriceDescriptions(destination, source.getDescriptions(), store)); destination.setDefaultPrice(source.isDefaultPrice()); } catch (Exception e) { throw new ConversionRuntimeException(e); } return destination;
693
996
1,689
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/inventory/ReadableInventoryMapper.java
ReadableInventoryMapper
store
class ReadableInventoryMapper implements Mapper<ProductAvailability, ReadableInventory> { @Autowired private PricingService pricingService; @Autowired private ReadableMerchantStorePopulator readableMerchantStorePopulator; @Override public ReadableInventory convert(ProductAvailability source, MerchantStore store, Language language) { ReadableInventory availability = new ReadableInventory(); return merge(source, availability, store, language); } @Override public ReadableInventory merge(ProductAvailability source, ReadableInventory destination, MerchantStore store, Language language) { Validate.notNull(destination, "Destination Product availability cannot be null"); Validate.notNull(source, "Source Product availability cannot be null"); try { destination.setQuantity(source.getProductQuantity() != null ? source.getProductQuantity().intValue() : 0); destination.setProductQuantityOrderMax( source.getProductQuantityOrderMax() != null ? source.getProductQuantityOrderMax().intValue() : 0); destination.setProductQuantityOrderMin( source.getProductQuantityOrderMin() != null ? source.getProductQuantityOrderMin().intValue() : 0); destination.setOwner(source.getOwner()); destination.setId(source.getId()); destination.setRegion(source.getRegion()); destination.setRegionVariant(source.getRegionVariant()); destination.setStore(store(store, language)); if (source.getAvailable() != null) { if (source.getProductDateAvailable() != null) { boolean isAfter = LocalDate.parse(DateUtil.getPresentDate()) .isAfter(LocalDate.parse(DateUtil.formatDate(source.getProductDateAvailable()))); if (isAfter && source.getAvailable().booleanValue()) { destination.setAvailable(true); } destination.setDateAvailable(DateUtil.formatDate(source.getProductDateAvailable())); } else { destination.setAvailable(source.getAvailable().booleanValue()); } } if (source.getAuditSection() != null) { if (source.getAuditSection().getDateCreated() != null) { destination.setCreationDate(DateUtil.formatDate(source.getAuditSection().getDateCreated())); } } List<ReadableProductPrice> prices = prices(source, store, language); destination.setPrices(prices); if(!StringUtils.isEmpty(source.getSku())) { destination.setSku(source.getSku()); } else { destination.setSku(source.getProduct().getSku()); } FinalPrice price = null; //try { price = pricingService.calculateProductPrice(source); destination.setPrice(price.getStringPrice()); //} catch (ServiceException e) { // throw new ConversionRuntimeException("Unable to get product price", e); //} } catch (Exception e) { throw new ConversionRuntimeException("Error while converting Inventory", e); } return destination; } private ReadableMerchantStore store(MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} private List<ReadableProductPrice> prices(ProductAvailability source, MerchantStore store, Language language) throws ConversionException { ReadableProductPricePopulator populator = null; List<ReadableProductPrice> prices = new ArrayList<ReadableProductPrice>(); for (ProductPrice price : source.getPrices()) { populator = new ReadableProductPricePopulator(); populator.setPricingService(pricingService); ReadableProductPrice p = populator.populate(price, new ReadableProductPrice(), store, language); prices.add(p); } return prices; } }
if (language == null) { language = store.getDefaultLanguage(); } /* * ReadableMerchantStorePopulator populator = new * ReadableMerchantStorePopulator(); * populator.setCountryService(countryService); * populator.setZoneService(zoneService); */ return readableMerchantStorePopulator.populate(store, new ReadableMerchantStore(), store, language);
1,039
110
1,149
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/optin/PersistableOptinMapper.java
PersistableOptinMapper
convert
class PersistableOptinMapper implements Mapper<PersistableOptin, Optin> { @Override public Optin convert(PersistableOptin source, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} @Override public Optin merge(PersistableOptin source, Optin destination, MerchantStore store, Language language) { return destination; } }
Optin optinEntity = new Optin(); optinEntity.setCode(source.getCode()); optinEntity.setDescription(source.getDescription()); optinEntity.setOptinType(OptinType.valueOf(source.getOptinType())); optinEntity.setMerchant(store); return optinEntity;
118
94
212
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/optin/ReadableOptinMapper.java
ReadableOptinMapper
convert
class ReadableOptinMapper implements Mapper<Optin, ReadableOptin> { @Override public ReadableOptin convert(Optin source, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} @Override public ReadableOptin merge(Optin source, ReadableOptin destination, MerchantStore store, Language language) { return destination; } }
ReadableOptin optinEntity = new ReadableOptin(); optinEntity.setCode(source.getCode()); optinEntity.setDescription(source.getDescription()); optinEntity.setOptinType(source.getOptinType().name()); return optinEntity;
116
80
196
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/order/ReadableOrderProductMapper.java
ReadableOrderProductMapper
merge
class ReadableOrderProductMapper implements Mapper<OrderProduct, ReadableOrderProduct> { @Autowired PricingService pricingService; @Autowired ProductService productService; @Autowired ReadableProductMapper readableProductMapper; @Inject @Qualifier("img") private ImageFilePath imageUtils; @Override public ReadableOrderProduct convert(OrderProduct source, MerchantStore store, Language language) { ReadableOrderProduct orderProduct = new ReadableOrderProduct(); return this.merge(source, orderProduct, store, language); } @Override public ReadableOrderProduct merge(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} }
Validate.notNull(source, "OrderProduct cannot be null"); Validate.notNull(target, "ReadableOrderProduct cannot be null"); Validate.notNull(store, "MerchantStore cannot be null"); Validate.notNull(language, "Language cannot be null"); target.setId(source.getId()); target.setOrderedQuantity(source.getProductQuantity()); try { target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store)); } catch (Exception e) { throw new ConversionRuntimeException("Cannot convert price", e); } target.setProductName(source.getProductName()); target.setSku(source.getSku()); // subtotal = price * quantity BigDecimal subTotal = source.getOneTimeCharge(); subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity())); try { String subTotalPrice = pricingService.getDisplayAmount(subTotal, store); target.setSubTotal(subTotalPrice); } catch (Exception e) { throw new ConversionRuntimeException("Cannot format price", e); } if (source.getOrderAttributes() != null) { List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>(); for (OrderProductAttribute attr : source.getOrderAttributes()) { ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute(); try { String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store); readableAttribute.setAttributePrice(price); } catch (ServiceException e) { throw new ConversionRuntimeException("Cannot format price", e); } readableAttribute.setAttributeName(attr.getProductAttributeName()); readableAttribute.setAttributeValue(attr.getProductAttributeValueName()); attributes.add(readableAttribute); } target.setAttributes(attributes); } String productSku = source.getSku(); if (!StringUtils.isBlank(productSku)) { Product product = null; try { product = productService.getBySku(productSku, store, language); } catch (ServiceException e) { throw new ServiceRuntimeException(e); } if (product != null) { ReadableProduct productProxy = readableProductMapper.convert(product, store, language); target.setProduct(productProxy); /** // TODO autowired ReadableProductPopulator populator = new ReadableProductPopulator(); populator.setPricingService(pricingService); populator.setimageUtils(imageUtils); ReadableProduct productProxy; try { productProxy = populator.populate(product, new ReadableProduct(), store, language); target.setProduct(productProxy); } catch (ConversionException e) { throw new ConversionRuntimeException("Cannot convert product", e); } Set<ProductImage> images = product.getImages(); ProductImage defaultImage = null; if (images != null) { for (ProductImage image : images) { if (defaultImage == null) { defaultImage = image; } if (image.isDefaultImage()) { defaultImage = image; } } } if (defaultImage != null) { target.setImage(defaultImage.getProductImage()); } **/ } } return target;
195
941
1,136
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/order/ReadableOrderTotalMapper.java
ReadableOrderTotalMapper
merge
class ReadableOrderTotalMapper implements Mapper<OrderTotal, ReadableOrderTotal> { @Autowired private PricingService pricingService; @Autowired private LabelUtils messages; @Override public ReadableOrderTotal convert(OrderTotal source, MerchantStore store, Language language) { ReadableOrderTotal destination = new ReadableOrderTotal(); return this.merge(source, destination, store, language); } @Override public ReadableOrderTotal merge(OrderTotal source, ReadableOrderTotal target, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} }
Validate.notNull(source, "OrderTotal must not be null"); Validate.notNull(target, "ReadableTotal must not be null"); Validate.notNull(store, "MerchantStore must not be null"); Validate.notNull(language, "Language must not be null"); Locale locale = LocaleUtils.getLocale(language); try { target.setCode(source.getOrderTotalCode()); target.setId(source.getId()); target.setModule(source.getModule()); target.setOrder(source.getSortOrder()); target.setTitle(messages.getMessage(source.getOrderTotalCode(), locale, source.getOrderTotalCode())); target.setText(source.getText()); target.setValue(source.getValue()); target.setTotal(pricingService.getDisplayAmount(source.getValue(), store)); if (!StringUtils.isBlank(source.getOrderTotalCode())) { if (Constants.OT_DISCOUNT_TITLE.equals(source.getOrderTotalCode())) { target.setDiscounted(true); } } } catch (Exception e) { throw new ConversionRuntimeException(e); } return target;
153
330
483
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/tax/PersistableTaxClassMapper.java
PersistableTaxClassMapper
merge
class PersistableTaxClassMapper implements Mapper<PersistableTaxClass, TaxClass> { @Override public TaxClass convert(PersistableTaxClass source, MerchantStore store, Language language) { Validate.notNull(source, "PersistableTaxClass cannot be null"); Validate.notNull(store, "MerchantStore cannot be null"); TaxClass taxClass = new TaxClass(); taxClass.setMerchantStore(store); taxClass.setTitle(source.getName()); taxClass.setId(source.getId()); return this.merge(source, taxClass, store, language); } @Override public TaxClass merge(PersistableTaxClass source, TaxClass destination, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} }
Validate.notNull(source, "PersistableTaxClass cannot be null"); Validate.notNull(destination, "TaxClass cannot be null"); Validate.notNull(store, "MerchantStore cannot be null"); destination.setCode(source.getCode()); if(source.getId()!=null && source.getId().longValue() > 0) { destination.setId(source.getId()); } destination.setMerchantStore(store); destination.setTitle(source.getName()); return destination;
202
150
352
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/tax/PersistableTaxRateMapper.java
PersistableTaxRateMapper
taxRate
class PersistableTaxRateMapper implements Mapper<PersistableTaxRate, TaxRate> { @Autowired private CountryService countryService; @Autowired private ZoneService zoneService; @Autowired private LanguageService languageService; @Autowired private TaxClassService taxClassService; @Override public TaxRate convert(PersistableTaxRate source, MerchantStore store, Language language) { TaxRate rate = new TaxRate(); return this.merge(source, rate, store, language); } @Override public TaxRate merge(PersistableTaxRate source, TaxRate destination, MerchantStore store, Language language) { Validate.notNull(destination, "destination TaxRate cannot be null"); Validate.notNull(source, "source TaxRate cannot be null"); try { destination.setId(source.getId()); destination.setCode(source.getCode()); destination.setTaxPriority(source.getPriority()); destination.setCountry(countryService.getByCode(source.getCountry())); destination.setZone(zoneService.getByCode(source.getZone())); destination.setStateProvince(source.getZone()); destination.setMerchantStore(store); destination.setTaxClass(taxClassService.getByCode(source.getTaxClass(), store)); destination.setTaxRate(source.getRate()); this.taxRate(destination, source); return destination; } catch (Exception e) { throw new ServiceRuntimeException("An error occured withe creating tax rate",e); } } private com.salesmanager.core.model.tax.taxrate.TaxRate taxRate(com.salesmanager.core.model.tax.taxrate.TaxRate destination, PersistableTaxRate source) throws Exception {<FILL_FUNCTION_BODY>} private com.salesmanager.core.model.tax.taxrate.TaxRateDescription description(TaxRateDescription source) throws Exception { Validate.notNull(source.getLanguage(),"description.language should not be null"); com.salesmanager.core.model.tax.taxrate.TaxRateDescription desc = new com.salesmanager.core.model.tax.taxrate.TaxRateDescription(); desc.setId(null); desc.setDescription(source.getDescription()); desc.setName(source.getName()); if(source.getId() != null && source.getId().longValue()>0) { desc.setId(source.getId()); } Language lang = languageService.getByCode(source.getLanguage()); desc.setLanguage(lang); return desc; } }
//List<com.salesmanager.core.model.tax.taxrate.TaxRateDescription> descriptions = new ArrayList<com.salesmanager.core.model.tax.taxrate.TaxRateDescription>(); if(!CollectionUtils.isEmpty(source.getDescriptions())) { for(TaxRateDescription desc : source.getDescriptions()) { com.salesmanager.core.model.tax.taxrate.TaxRateDescription description = null; if(!CollectionUtils.isEmpty(destination.getDescriptions())) { for(com.salesmanager.core.model.tax.taxrate.TaxRateDescription d : destination.getDescriptions()) { if(!StringUtils.isBlank(desc.getLanguage()) && desc.getLanguage().equals(d.getLanguage().getCode())) { d.setDescription(desc.getDescription()); d.setName(desc.getName()); d.setTitle(desc.getTitle()); description = d; break; } } } if(description == null) { description = description(desc); description.setTaxRate(destination); destination.getDescriptions().add(description); } } } return destination;
707
339
1,046
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/tax/ReadableTaxClassMapper.java
ReadableTaxClassMapper
convert
class ReadableTaxClassMapper implements Mapper<TaxClass, ReadableTaxClass> { @Override public ReadableTaxClass convert(TaxClass source, MerchantStore store, Language language) {<FILL_FUNCTION_BODY>} @Override public ReadableTaxClass merge(TaxClass source, ReadableTaxClass destination, MerchantStore store, Language language) { destination.setId(source.getId()); destination.setCode(source.getCode()); destination.setName(source.getTitle()); destination.setStore(store.getCode()); return destination; } }
ReadableTaxClass taxClass = new ReadableTaxClass(); taxClass.setId(source.getId()); taxClass.setCode(source.getCode()); taxClass.setName(source.getTitle()); taxClass.setStore(store.getCode()); return taxClass;
156
80
236
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/mapper/tax/ReadableTaxRateMapper.java
ReadableTaxRateMapper
convertDescription
class ReadableTaxRateMapper implements Mapper<TaxRate, ReadableTaxRate> { @Override public ReadableTaxRate convert(TaxRate source, MerchantStore store, Language language) { ReadableTaxRate taxRate = new ReadableTaxRate(); return this.merge(source, taxRate, store, language); } @Override public ReadableTaxRate merge(TaxRate source, ReadableTaxRate destination, MerchantStore store, Language language) { Validate.notNull(destination, "destination TaxRate cannot be null"); Validate.notNull(source, "source TaxRate cannot be null"); destination.setId(source.getId()); destination.setCountry(source.getCountry().getIsoCode()); destination.setZone(source.getZone().getCode()); destination.setRate(source.getTaxRate().toString()); destination.setCode(source.getCode()); destination.setPriority(source.getTaxPriority()); Optional<ReadableTaxRateDescription> description = this.convertDescription(source.getDescriptions(), language); if(description.isPresent()) { destination.setDescription(description.get()); } return destination; } private Optional<ReadableTaxRateDescription> convertDescription(List<TaxRateDescription> descriptions, Language language) { Validate.notEmpty(descriptions,"List of TaxRateDescriptions should not be empty"); Optional<TaxRateDescription> description = descriptions.stream() .filter(desc -> desc.getLanguage().getCode().equals(language.getCode())).findAny(); if (description.isPresent()) { return Optional.of(convertDescription(description.get())); } else { return Optional.empty(); } } private ReadableTaxRateDescription convertDescription(TaxRateDescription desc) {<FILL_FUNCTION_BODY>} }
ReadableTaxRateDescription d = new ReadableTaxRateDescription(); d.setDescription(desc.getDescription()); d.setName(desc.getName()); d.setLanguage(desc.getLanguage().getCode()); d.setDescription(desc.getDescription()); d.setId(desc.getId()); d.setTitle(desc.getTitle()); return d;
486
104
590
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/PersistableAuditAspect.java
PersistableAuditAspect
afterReturning
class PersistableAuditAspect { private static final Logger LOGGER = LoggerFactory.getLogger(PersistableAuditAspect.class); @AfterReturning(value = "execution(* populate(..))", returning = "result") public void afterReturning(JoinPoint joinPoint, Object result) {<FILL_FUNCTION_BODY>} }
try { if(result instanceof Auditable) { Auditable entity = (Auditable)result; AuditSection audit = entity.getAuditSection(); if(entity.getAuditSection()==null) { audit = new AuditSection(); } audit.setDateModified(new Date()); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if(auth!=null) { if(auth instanceof UsernamePasswordAuthenticationToken) {//api only is captured com.salesmanager.shop.store.security.user.JWTUser user = (com.salesmanager.shop.store.security.user.JWTUser)auth.getPrincipal(); audit.setModifiedBy(user.getUsername()); } } //TODO put in log audit log trail entity.setAuditSection(audit); } } catch (Throwable e) { LOGGER.error("Error while setting audit values" + e.getMessage()); }
101
276
377
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/PersistableCategoryPopulator.java
PersistableCategoryPopulator
populate
class PersistableCategoryPopulator extends AbstractDataPopulator<PersistableCategory, Category> { @Inject private CategoryService categoryService; @Inject private LanguageService languageService; public void setCategoryService(CategoryService categoryService) { this.categoryService = categoryService; } public CategoryService getCategoryService() { return categoryService; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } public LanguageService getLanguageService() { return languageService; } @Override public Category populate(PersistableCategory source, Category target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} private com.salesmanager.core.model.catalog.category.CategoryDescription buildDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription source, com.salesmanager.core.model.catalog.category.CategoryDescription target) throws Exception { //com.salesmanager.core.model.catalog.category.CategoryDescription desc = new com.salesmanager.core.model.catalog.category.CategoryDescription(); target.setCategoryHighlight(source.getHighlights()); target.setDescription(source.getDescription()); target.setName(source.getName()); target.setMetatagDescription(source.getMetaDescription()); target.setMetatagTitle(source.getTitle()); target.setSeUrl(source.getFriendlyUrl()); Language lang = languageService.getByCode(source.getLanguage()); if(lang==null) { throw new ConversionException("Language is null for code " + source.getLanguage() + " use language ISO code [en, fr ...]"); } //description.setId(description.getId()); target.setLanguage(lang); return target; } @Override protected Category createTarget() { // TODO Auto-generated method stub return null; } }
try { Validate.notNull(target, "Category target cannot be null"); /* Validate.notNull(categoryService, "Requires to set CategoryService"); Validate.notNull(languageService, "Requires to set LanguageService");*/ target.setMerchantStore(store); target.setCode(source.getCode()); target.setSortOrder(source.getSortOrder()); target.setVisible(source.isVisible()); target.setFeatured(source.isFeatured()); //children if(!CollectionUtils.isEmpty(source.getChildren())) { //no modifications to children category } else { target.getCategories().clear(); } //get parent if(source.getParent()==null || (StringUtils.isBlank(source.getParent().getCode())) || source.getParent().getId()==null) { target.setParent(null); target.setDepth(0); target.setLineage(new StringBuilder().append("/").append(source.getId()).append("/").toString()); } else { Category parent = null; if(!StringUtils.isBlank(source.getParent().getCode())) { parent = categoryService.getByCode(store.getCode(), source.getParent().getCode()); } else if(source.getParent().getId()!=null) { parent = categoryService.getById(source.getParent().getId(), store.getId()); } else { throw new ConversionException("Category parent needs at least an id or a code for reference"); } if(parent !=null && parent.getMerchantStore().getId().intValue()!=store.getId().intValue()) { throw new ConversionException("Store id does not belong to specified parent id"); } if(parent!=null) { target.setParent(parent); String lineage = parent.getLineage(); int depth = parent.getDepth(); target.setDepth(depth+1); target.setLineage(new StringBuilder().append(lineage).append(target.getId()).append("/").toString()); } } if(!CollectionUtils.isEmpty(source.getChildren())) { for(PersistableCategory cat : source.getChildren()) { Category persistCategory = this.populate(cat, new Category(), store, language); target.getCategories().add(persistCategory); } } if(!CollectionUtils.isEmpty(source.getDescriptions())) { Set<com.salesmanager.core.model.catalog.category.CategoryDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.category.CategoryDescription>(); if(CollectionUtils.isNotEmpty(target.getDescriptions())) { for(com.salesmanager.core.model.catalog.category.CategoryDescription description : target.getDescriptions()) { for(CategoryDescription d : source.getDescriptions()) { if(StringUtils.isBlank(d.getLanguage())) { throw new ConversionException("Source category description has no language"); } if(d.getLanguage().equals(description.getLanguage().getCode())) { description.setCategory(target); description = buildDescription(d, description); descriptions.add(description); } } } } else { for(CategoryDescription d : source.getDescriptions()) { com.salesmanager.core.model.catalog.category.CategoryDescription t = new com.salesmanager.core.model.catalog.category.CategoryDescription(); this.buildDescription(d, t); t.setCategory(target); descriptions.add(t); } } target.setDescriptions(descriptions); } return target; } catch(Exception e) { throw new ConversionException(e); }
499
1,037
1,536
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.catalog.category.Category populate(com.salesmanager.shop.model.catalog.category.PersistableCategory, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/PersistableProductImagePopulator.java
PersistableProductImagePopulator
populate
class PersistableProductImagePopulator extends AbstractDataPopulator<PersistableImage, ProductImage> { private Product product; @Override public ProductImage populate(PersistableImage source, ProductImage target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ProductImage createTarget() { // TODO Auto-generated method stub return null; } public Product getProduct() { return product; } public void setProduct(Product product) { this.product = product; } }
Validate.notNull(product,"Must set a product setProduct(Product)"); Validate.notNull(product.getId(),"Product must have an id not null"); Validate.notNull(source.getContentType(),"Content type must be set on persistable image"); target.setDefaultImage(source.isDefaultImage()); target.setImageType(source.getImageType()); target.setProductImage(source.getName()); if(source.getImageUrl() != null) { target.setProductImageUrl(source.getImageUrl()); } target.setProduct(product); return target;
150
171
321
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.catalog.product.image.ProductImage populate(com.salesmanager.shop.model.catalog.product.PersistableImage, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/PersistableProductOptionPopulator.java
PersistableProductOptionPopulator
populate
class PersistableProductOptionPopulator extends AbstractDataPopulator<PersistableProductOption, ProductOption> { private LanguageService languageService; public LanguageService getLanguageService() { return languageService; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } @Override public ProductOption populate(PersistableProductOption source, ProductOption target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ProductOption createTarget() { return null; } }
Validate.notNull(languageService, "Requires to set LanguageService"); try { target.setMerchantStore(store); target.setProductOptionSortOrder(source.getOrder()); target.setCode(source.getCode()); if(!CollectionUtils.isEmpty(source.getDescriptions())) { Set<com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription>(); for(ProductOptionDescription desc : source.getDescriptions()) { com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription description = new com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription(); Language lang = languageService.getByCode(desc.getLanguage()); if(lang==null) { throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]"); } description.setLanguage(lang); description.setName(desc.getName()); description.setTitle(desc.getTitle()); description.setProductOption(target); descriptions.add(description); } target.setDescriptions(descriptions); } } catch (Exception e) { throw new ConversionException(e); } return target;
157
389
546
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.catalog.product.attribute.ProductOption populate(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOption, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/PersistableProductOptionValuePopulator.java
PersistableProductOptionValuePopulator
populate
class PersistableProductOptionValuePopulator extends AbstractDataPopulator<PersistableProductOptionValue, ProductOptionValue> { private LanguageService languageService; public LanguageService getLanguageService() { return languageService; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } @Override public ProductOptionValue populate(PersistableProductOptionValue source, ProductOptionValue target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ProductOptionValue createTarget() { return null; } }
Validate.notNull(languageService, "Requires to set LanguageService"); try { target.setMerchantStore(store); target.setProductOptionValueSortOrder(source.getOrder()); target.setCode(source.getCode()); if(!CollectionUtils.isEmpty(source.getDescriptions())) { Set<com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription>(); for(ProductOptionValueDescription desc : source.getDescriptions()) { com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription description = new com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription(); Language lang = languageService.getByCode(desc.getLanguage()); if(lang==null) { throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]"); } description.setLanguage(lang); description.setName(desc.getName()); description.setTitle(desc.getTitle()); description.setProductOptionValue(target); descriptions.add(description); } target.setDescriptions(descriptions); } } catch (Exception e) { throw new ConversionException(e); } return target;
166
398
564
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue populate(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/PersistableProductReviewPopulator.java
PersistableProductReviewPopulator
populate
class PersistableProductReviewPopulator extends AbstractDataPopulator<PersistableProductReview, ProductReview> { private CustomerService customerService; private ProductService productService; private LanguageService languageService; public LanguageService getLanguageService() { return languageService; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } @Override public ProductReview populate(PersistableProductReview source, ProductReview target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ProductReview createTarget() { return null; } public CustomerService getCustomerService() { return customerService; } public void setCustomerService(CustomerService customerService) { this.customerService = customerService; } public ProductService getProductService() { return productService; } public void setProductService(ProductService productService) { this.productService = productService; } }
Validate.notNull(customerService,"customerService cannot be null"); Validate.notNull(productService,"productService cannot be null"); Validate.notNull(languageService,"languageService cannot be null"); Validate.notNull(source.getRating(),"Rating cannot bot be null"); try { if(target==null) { target = new ProductReview(); } Customer customer = customerService.getById(source.getCustomerId()); //check if customer belongs to store if(customer ==null || customer.getMerchantStore().getId().intValue()!=store.getId().intValue()) { throw new ConversionException("Invalid customer id for the given store"); } if(source.getDate() == null) { String date = DateUtil.formatDate(new Date()); source.setDate(date); } target.setReviewDate(DateUtil.getDate(source.getDate())); target.setCustomer(customer); target.setReviewRating(source.getRating()); Product product = productService.getById(source.getProductId()); //check if product belongs to store if(product ==null || product.getMerchantStore().getId().intValue()!=store.getId().intValue()) { throw new ConversionException("Invalid product id for the given store"); } target.setProduct(product); Language lang = languageService.getByCode(language.getCode()); if(lang ==null) { throw new ConversionException("Invalid language code, use iso codes (en, fr ...)"); } ProductReviewDescription description = new ProductReviewDescription(); description.setDescription(source.getDescription()); description.setLanguage(lang); description.setName("-"); description.setProductReview(target); Set<ProductReviewDescription> descriptions = new HashSet<ProductReviewDescription>(); descriptions.add(description); target.setDescriptions(descriptions); return target; } catch (Exception e) { throw new ConversionException("Cannot populate ProductReview", e); }
276
587
863
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.catalog.product.review.ProductReview populate(com.salesmanager.shop.model.catalog.product.PersistableProductReview, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/ReadableCategoryPopulator.java
ReadableCategoryPopulator
populate
class ReadableCategoryPopulator extends AbstractDataPopulator<Category, ReadableCategory> { @Override public ReadableCategory populate(final Category source, final ReadableCategory target, final MerchantStore store, final Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableCategory createTarget() { return null; } }
Validate.notNull(source, "Category must not be null"); target.setLineage(source.getLineage()); if (source.getDescriptions() != null && source.getDescriptions().size() > 0) { CategoryDescription description = source.getDescription(); if (source.getDescriptions().size() > 1) { for (final CategoryDescription desc : source.getDescriptions()) { if (desc.getLanguage().getCode().equals(language.getCode())) { description = desc; break; } } } if (description != null) { final com.salesmanager.shop.model.catalog.category.CategoryDescription desc = new com.salesmanager.shop.model.catalog.category.CategoryDescription(); desc.setFriendlyUrl(description.getSeUrl()); desc.setName(description.getName()); desc.setId(source.getId()); desc.setDescription(description.getDescription()); desc.setKeyWords(description.getMetatagKeywords()); desc.setHighlights(description.getCategoryHighlight()); desc.setTitle(description.getMetatagTitle()); desc.setMetaDescription(description.getMetatagDescription()); target.setDescription(desc); } } if (source.getParent() != null) { final com.salesmanager.shop.model.catalog.category.Category parent = new com.salesmanager.shop.model.catalog.category.Category(); parent.setCode(source.getParent().getCode()); parent.setId(source.getParent().getId()); target.setParent(parent); } target.setCode(source.getCode()); target.setId(source.getId()); if (source.getDepth() != null) { target.setDepth(source.getDepth()); } target.setSortOrder(source.getSortOrder()); target.setVisible(source.isVisible()); target.setFeatured(source.isFeatured()); return target;
105
526
631
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.catalog.category.ReadableCategory populate(com.salesmanager.core.model.catalog.category.Category, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/ReadableFinalPricePopulator.java
ReadableFinalPricePopulator
populate
class ReadableFinalPricePopulator extends AbstractDataPopulator<FinalPrice, ReadableProductPrice> { private PricingService pricingService; public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } @Override public ReadableProductPrice populate(FinalPrice source, ReadableProductPrice target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableProductPrice createTarget() { // TODO Auto-generated method stub return null; } }
Validate.notNull(pricingService,"pricingService must be set"); try { target.setOriginalPrice(pricingService.getDisplayAmount(source.getOriginalPrice(), store)); if(source.isDiscounted()) { target.setDiscounted(true); target.setFinalPrice(pricingService.getDisplayAmount(source.getDiscountedPrice(), store)); } else { target.setFinalPrice(pricingService.getDisplayAmount(source.getFinalPrice(), store)); } } catch(Exception e) { throw new ConversionException("Exception while converting to ReadableProductPrice",e); } return target;
180
186
366
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.catalog.product.ReadableProductPrice populate(com.salesmanager.core.model.catalog.product.price.FinalPrice, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/ReadableProductPricePopulator.java
ReadableProductPricePopulator
populate
class ReadableProductPricePopulator extends AbstractDataPopulator<ProductPrice, ReadableProductPrice> { private PricingService pricingService; public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } @Override public ReadableProductPrice populate(ProductPrice source, ReadableProductPrice target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableProductPrice createTarget() { // TODO Auto-generated method stub return null; } com.salesmanager.shop.model.catalog.product.ProductPriceDescription populateDescription( ProductPriceDescription description) { if (description == null) { return null; } com.salesmanager.shop.model.catalog.product.ProductPriceDescription d = new com.salesmanager.shop.model.catalog.product.ProductPriceDescription(); d.setName(description.getName()); d.setDescription(description.getDescription()); d.setId(description.getId()); d.setTitle(description.getTitle()); if (description.getLanguage() != null) { d.setLanguage(description.getLanguage().getCode()); } return d; } }
Validate.notNull(pricingService,"pricingService must be set"); Validate.notNull(source.getProductAvailability(),"productPrice.availability cannot be null"); Validate.notNull(source.getProductAvailability().getProduct(),"productPrice.availability.product cannot be null"); try { if(language == null) { target = new ReadableProductPriceFull(); } if(source.getId() != null && source.getId() > 0) { target.setId(source.getId()); } target.setDefaultPrice(source.isDefaultPrice()); FinalPrice finalPrice = pricingService.calculateProductPrice(source.getProductAvailability().getProduct()); target.setOriginalPrice(pricingService.getDisplayAmount(source.getProductPriceAmount(), store)); if(finalPrice.isDiscounted()) { target.setDiscounted(true); target.setFinalPrice(pricingService.getDisplayAmount(source.getProductPriceSpecialAmount(), store)); } else { target.setFinalPrice(pricingService.getDisplayAmount(finalPrice.getOriginalPrice(), store)); } if(source.getDescriptions()!=null && source.getDescriptions().size()>0) { List<com.salesmanager.shop.model.catalog.product.ProductPriceDescription> fulldescriptions = new ArrayList<com.salesmanager.shop.model.catalog.product.ProductPriceDescription>(); Set<ProductPriceDescription> descriptions = source.getDescriptions(); ProductPriceDescription description = null; for(ProductPriceDescription desc : descriptions) { if(language != null && desc.getLanguage().getCode().equals(language.getCode())) { description = desc; break; } else { fulldescriptions.add(populateDescription(desc)); } } if (description != null) { com.salesmanager.shop.model.catalog.product.ProductPriceDescription d = populateDescription(description); target.setDescription(d); } if(target instanceof ReadableProductPriceFull) { ((ReadableProductPriceFull)target).setDescriptions(fulldescriptions); } } } catch(Exception e) { throw new ConversionException("Exception while converting to ReadableProductPrice",e); } return target;
361
642
1,003
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.catalog.product.ReadableProductPrice populate(com.salesmanager.core.model.catalog.product.price.ProductPrice, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/ReadableProductReviewPopulator.java
ReadableProductReviewPopulator
populate
class ReadableProductReviewPopulator extends AbstractDataPopulator<ProductReview, ReadableProductReview> { @Override public ReadableProductReview populate(ProductReview source, ReadableProductReview target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableProductReview createTarget() { return null; } }
try { ReadableCustomerPopulator populator = new ReadableCustomerPopulator(); ReadableCustomer customer = new ReadableCustomer(); populator.populate(source.getCustomer(), customer, store, language); target.setId(source.getId()); target.setDate(DateUtil.formatDate(source.getReviewDate())); target.setCustomer(customer); target.setRating(source.getReviewRating()); target.setProductId(source.getProduct().getId()); Set<ProductReviewDescription> descriptions = source.getDescriptions(); if(descriptions!=null) { for(ProductReviewDescription description : descriptions) { target.setDescription(description.getDescription()); target.setLanguage(description.getLanguage().getCode()); break; } } return target; } catch (Exception e) { throw new ConversionException("Cannot populate ProductReview", e); }
105
263
368
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.catalog.product.ReadableProductReview populate(com.salesmanager.core.model.catalog.product.review.ProductReview, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/CustomerBillingAddressPopulator.java
CustomerBillingAddressPopulator
populate
class CustomerBillingAddressPopulator extends AbstractDataPopulator<Customer, Address> { @Override public Address populate( Customer source, Address target, MerchantStore store, Language language ) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Address createTarget() { return new Address(); } }
target.setCity(source.getBilling().getCity()); target.setCompany(source.getBilling().getCompany()); target.setFirstName(source.getBilling().getFirstName()); target.setLastName(source.getBilling().getLastName()); target.setPostalCode(source.getBilling().getPostalCode()); target.setPhone(source.getBilling().getTelephone()); if(source.getBilling().getTelephone()==null) { target.setPhone(source.getBilling().getTelephone()); } target.setAddress(source.getBilling().getAddress()); if(source.getBilling().getCountry()!=null) { target.setCountry(source.getBilling().getCountry().getIsoCode()); } if(source.getBilling().getZone()!=null) { target.setZone(source.getBilling().getZone().getCode()); } target.setStateProvince(source.getBilling().getState()); return target;
94
271
365
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.customer.address.Address populate(com.salesmanager.core.model.customer.Customer, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/CustomerDeliveryAddressPopulator.java
CustomerDeliveryAddressPopulator
populate
class CustomerDeliveryAddressPopulator extends AbstractDataPopulator<Customer, Address> { @Override public Address populate( Customer source, Address target, MerchantStore store, Language language ) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Address createTarget() { return new Address(); } }
if(source.getDelivery()!=null){ if(StringUtils.isNotBlank( source.getDelivery().getCity() )){ target.setCity(source.getDelivery().getCity()); } if(StringUtils.isNotBlank( source.getDelivery().getCompany() )){ target.setCompany(source.getDelivery().getCompany()); } if(StringUtils.isNotBlank( source.getDelivery().getAddress() )){ target.setAddress(source.getDelivery().getAddress()); } if(StringUtils.isNotBlank( source.getDelivery().getFirstName() )){ target.setFirstName(source.getDelivery().getFirstName()); } if(StringUtils.isNotBlank( source.getDelivery().getLastName() )){ target.setLastName(source.getDelivery().getLastName()); } if(StringUtils.isNotBlank( source.getDelivery().getPostalCode() )){ target.setPostalCode(source.getDelivery().getPostalCode()); } if(StringUtils.isNotBlank( source.getDelivery().getTelephone() )){ target.setPhone(source.getDelivery().getTelephone()); } target.setStateProvince(source.getDelivery().getState()); if(source.getDelivery().getTelephone()==null) { target.setPhone(source.getDelivery().getTelephone()); } target.setAddress(source.getDelivery().getAddress()); if(source.getDelivery().getCountry()!=null) { target.setCountry(source.getDelivery().getCountry().getIsoCode()); } if(source.getDelivery().getZone()!=null) { target.setZone(source.getDelivery().getZone().getCode()); } } return target;
94
505
599
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.customer.address.Address populate(com.salesmanager.core.model.customer.Customer, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/CustomerEntityPopulator.java
CustomerEntityPopulator
populate
class CustomerEntityPopulator extends AbstractDataPopulator<Customer, CustomerEntity> { @Override public CustomerEntity populate( final Customer source, final CustomerEntity target, final MerchantStore merchantStore, final Language language ) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected CustomerEntity createTarget() { return new CustomerEntity(); } }
try { target.setId( source.getId() ); if(StringUtils.isNotBlank( source.getEmailAddress() )){ target.setEmailAddress( source.getEmailAddress() ); } if ( source.getBilling() != null ) { Address address = new Address(); address.setCity( source.getBilling().getCity() ); address.setAddress(source.getBilling().getAddress()); address.setCompany( source.getBilling().getCompany() ); address.setFirstName( source.getBilling().getFirstName() ); address.setLastName( source.getBilling().getLastName() ); address.setPostalCode( source.getBilling().getPostalCode() ); address.setPhone( source.getBilling().getTelephone() ); if ( source.getBilling().getCountry() != null ) { address.setCountry( source.getBilling().getCountry().getIsoCode() ); } if ( source.getBilling().getZone() != null ) { address.setZone( source.getBilling().getZone().getCode() ); } address.setStateProvince(source.getBilling().getState()); target.setBilling( address ); } if(source.getCustomerReviewAvg() != null) { target.setRating(source.getCustomerReviewAvg().doubleValue()); } if(source.getCustomerReviewCount() != null) { target.setRatingCount(source.getCustomerReviewCount().intValue()); } if ( source.getDelivery() != null ) { Address address = new Address(); address.setCity( source.getDelivery().getCity() ); address.setAddress(source.getDelivery().getAddress()); address.setCompany( source.getDelivery().getCompany() ); address.setFirstName( source.getDelivery().getFirstName() ); address.setLastName( source.getDelivery().getLastName() ); address.setPostalCode( source.getDelivery().getPostalCode() ); address.setPhone( source.getDelivery().getTelephone() ); if ( source.getDelivery().getCountry() != null ) { address.setCountry( source.getDelivery().getCountry().getIsoCode() ); } if ( source.getDelivery().getZone() != null ) { address.setZone( source.getDelivery().getZone().getCode() ); } address.setStateProvince(source.getDelivery().getState()); target.setDelivery( address ); } } catch ( Exception e ) { throw new ConversionException( e ); } return target;
106
739
845
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.customer.CustomerEntity populate(com.salesmanager.core.model.customer.Customer, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/PersistableCustomerBillingAddressPopulator.java
PersistableCustomerBillingAddressPopulator
populate
class PersistableCustomerBillingAddressPopulator extends AbstractDataPopulator<Address, Customer> { @Override public Customer populate( Address source, Customer target, MerchantStore store, Language language ) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Customer createTarget() { return null; } }
target.getBilling().setFirstName( source.getFirstName() ); target.getBilling().setLastName( source.getLastName() ); // lets fill optional data now if(StringUtils.isNotBlank( source.getAddress())){ target.getBilling().setAddress( source.getAddress() ); } if(StringUtils.isNotBlank( source.getCity())){ target.getBilling().setCity( source.getCity() ); } if(StringUtils.isNotBlank( source.getCompany())){ target.getBilling().setCompany( source.getCompany() ); } if(StringUtils.isNotBlank( source.getPhone())){ target.getBilling().setTelephone( source.getPhone()); } if(StringUtils.isNotBlank( source.getPostalCode())){ target.getBilling().setPostalCode( source.getPostalCode()); } if(StringUtils.isNotBlank( source.getStateProvince())){ target.getBilling().setState(source.getStateProvince()); } return target;
99
313
412
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.customer.Customer populate(com.salesmanager.shop.model.customer.address.Address, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/PersistableCustomerOptionPopulator.java
PersistableCustomerOptionPopulator
populate
class PersistableCustomerOptionPopulator extends AbstractDataPopulator<PersistableCustomerOption, CustomerOption> { private LanguageService languageService; @Override public CustomerOption populate(PersistableCustomerOption source, CustomerOption target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected CustomerOption createTarget() { return null; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } public LanguageService getLanguageService() { return languageService; } }
Validate.notNull(languageService, "Requires to set LanguageService"); try { target.setCode(source.getCode()); target.setMerchantStore(store); target.setSortOrder(source.getOrder()); if(!StringUtils.isBlank(source.getType())) { target.setCustomerOptionType(source.getType()); } else { target.setCustomerOptionType("TEXT"); } target.setPublicOption(true); if(!CollectionUtils.isEmpty(source.getDescriptions())) { Set<com.salesmanager.core.model.customer.attribute.CustomerOptionDescription> descriptions = new HashSet<com.salesmanager.core.model.customer.attribute.CustomerOptionDescription>(); for(CustomerOptionDescription desc : source.getDescriptions()) { com.salesmanager.core.model.customer.attribute.CustomerOptionDescription description = new com.salesmanager.core.model.customer.attribute.CustomerOptionDescription(); Language lang = languageService.getByCode(desc.getLanguage()); if(lang==null) { throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]"); } description.setLanguage(lang); description.setName(desc.getName()); description.setTitle(desc.getTitle()); description.setCustomerOption(target); descriptions.add(description); } target.setDescriptions(descriptions); } } catch (Exception e) { throw new ConversionException(e); } return target;
159
437
596
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.customer.attribute.CustomerOption populate(com.salesmanager.shop.model.customer.attribute.PersistableCustomerOption, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/PersistableCustomerOptionValuePopulator.java
PersistableCustomerOptionValuePopulator
populate
class PersistableCustomerOptionValuePopulator extends AbstractDataPopulator<PersistableCustomerOptionValue, CustomerOptionValue> { private LanguageService languageService; @Override public CustomerOptionValue populate(PersistableCustomerOptionValue source, CustomerOptionValue target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected CustomerOptionValue createTarget() { return null; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } public LanguageService getLanguageService() { return languageService; } }
Validate.notNull(languageService, "Requires to set LanguageService"); try { target.setCode(source.getCode()); target.setMerchantStore(store); target.setSortOrder(source.getOrder()); if(!CollectionUtils.isEmpty(source.getDescriptions())) { Set<com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription> descriptions = new HashSet<com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription>(); for(CustomerOptionValueDescription desc : source.getDescriptions()) { com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription description = new com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription(); Language lang = languageService.getByCode(desc.getLanguage()); if(lang==null) { throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]"); } description.setLanguage(lang); description.setName(desc.getName()); description.setTitle(desc.getTitle()); description.setCustomerOptionValue(target); descriptions.add(description); } target.setDescriptions(descriptions); } } catch (Exception e) { throw new ConversionException(e); } return target;
166
380
546
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.customer.attribute.CustomerOptionValue populate(com.salesmanager.shop.model.customer.attribute.PersistableCustomerOptionValue, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/PersistableCustomerPopulator.java
PersistableCustomerPopulator
populate
class PersistableCustomerPopulator extends AbstractDataPopulator<Customer, PersistableCustomer> { @Override public PersistableCustomer populate(Customer source, PersistableCustomer target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected PersistableCustomer createTarget() { // TODO Auto-generated method stub return null; } }
try { if(source.getBilling()!=null) { Address address = new Address(); address.setCity(source.getBilling().getCity()); address.setCompany(source.getBilling().getCompany()); address.setFirstName(source.getBilling().getFirstName()); address.setLastName(source.getBilling().getLastName()); address.setPostalCode(source.getBilling().getPostalCode()); address.setPhone(source.getBilling().getTelephone()); if(source.getBilling().getTelephone()==null) { address.setPhone(source.getBilling().getTelephone()); } address.setAddress(source.getBilling().getAddress()); if(source.getBilling().getCountry()!=null) { address.setCountry(source.getBilling().getCountry().getIsoCode()); } if(source.getBilling().getZone()!=null) { address.setZone(source.getBilling().getZone().getCode()); } if(source.getBilling().getState()!=null) { address.setStateProvince(source.getBilling().getState()); } target.setBilling(address); } target.setProvider(source.getProvider()); if(source.getCustomerReviewAvg() != null) { target.setRating(source.getCustomerReviewAvg().doubleValue()); } if(source.getCustomerReviewCount() != null) { target.setRatingCount(source.getCustomerReviewCount().intValue()); } if(source.getDelivery()!=null) { Address address = new Address(); address.setAddress(source.getDelivery().getAddress()); address.setCity(source.getDelivery().getCity()); address.setCompany(source.getDelivery().getCompany()); address.setFirstName(source.getDelivery().getFirstName()); address.setLastName(source.getDelivery().getLastName()); address.setPostalCode(source.getDelivery().getPostalCode()); address.setPhone(source.getDelivery().getTelephone()); if(source.getDelivery().getCountry()!=null) { address.setCountry(source.getDelivery().getCountry().getIsoCode()); } if(source.getDelivery().getZone()!=null) { address.setZone(source.getDelivery().getZone().getCode()); } if(source.getDelivery().getState()!=null) { address.setStateProvince(source.getDelivery().getState()); } target.setDelivery(address); } target.setId(source.getId()); target.setEmailAddress(source.getEmailAddress()); if(source.getGender()!=null) { target.setGender(source.getGender().name()); } if(source.getDefaultLanguage()!=null) { target.setLanguage(source.getDefaultLanguage().getCode()); } target.setUserName(source.getNick()); target.setStoreCode(store.getCode()); if(source.getDefaultLanguage()!=null) { target.setLanguage(source.getDefaultLanguage().getCode()); } else { target.setLanguage(store.getDefaultLanguage().getCode()); } } catch (Exception e) { throw new ConversionException(e); } return target;
112
960
1,072
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.customer.PersistableCustomer populate(com.salesmanager.core.model.customer.Customer, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/PersistableCustomerReviewPopulator.java
PersistableCustomerReviewPopulator
populate
class PersistableCustomerReviewPopulator extends AbstractDataPopulator<PersistableCustomerReview, CustomerReview> { private CustomerService customerService; private LanguageService languageService; public LanguageService getLanguageService() { return languageService; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } @Override public CustomerReview populate(PersistableCustomerReview source, CustomerReview target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected CustomerReview createTarget() { // TODO Auto-generated method stub return null; } public CustomerService getCustomerService() { return customerService; } public void setCustomerService(CustomerService customerService) { this.customerService = customerService; } }
Validate.notNull(customerService,"customerService cannot be null"); Validate.notNull(languageService,"languageService cannot be null"); Validate.notNull(source.getRating(),"Rating cannot bot be null"); try { if(target==null) { target = new CustomerReview(); } if(source.getDate() == null) { String date = DateUtil.formatDate(new Date()); source.setDate(date); } target.setReviewDate(DateUtil.getDate(source.getDate())); if(source.getId() != null && source.getId().longValue()==0) { source.setId(null); } else { target.setId(source.getId()); } Customer reviewer = customerService.getById(source.getCustomerId()); Customer reviewed = customerService.getById(source.getReviewedCustomer()); target.setReviewRating(source.getRating()); target.setCustomer(reviewer); target.setReviewedCustomer(reviewed); Language lang = languageService.getByCode(language.getCode()); if(lang ==null) { throw new ConversionException("Invalid language code, use iso codes (en, fr ...)"); } CustomerReviewDescription description = new CustomerReviewDescription(); description.setDescription(source.getDescription()); description.setLanguage(lang); description.setName("-"); description.setCustomerReview(target); Set<CustomerReviewDescription> descriptions = new HashSet<CustomerReviewDescription>(); descriptions.add(description); target.setDescriptions(descriptions); } catch (Exception e) { throw new ConversionException("Cannot populate CustomerReview", e); } return target;
213
501
714
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.customer.review.CustomerReview populate(com.salesmanager.shop.model.customer.PersistableCustomerReview, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/PersistableCustomerShippingAddressPopulator.java
PersistableCustomerShippingAddressPopulator
populate
class PersistableCustomerShippingAddressPopulator extends AbstractDataPopulator<Address, Customer> { @Override public Customer populate( Address source, Customer target, MerchantStore store, Language language ) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Customer createTarget() { return null; } }
if( target.getDelivery() == null){ Delivery delivery=new Delivery(); delivery.setFirstName( source.getFirstName()) ; delivery.setLastName( source.getLastName() ); if(StringUtils.isNotBlank( source.getAddress())){ delivery.setAddress( source.getAddress() ); } if(StringUtils.isNotBlank( source.getCity())){ delivery.setCity( source.getCity() ); } if(StringUtils.isNotBlank( source.getCompany())){ delivery.setCompany( source.getCompany() ); } if(StringUtils.isNotBlank( source.getPhone())){ delivery.setTelephone( source.getPhone()); } if(StringUtils.isNotBlank( source.getPostalCode())){ delivery.setPostalCode( source.getPostalCode()); } if(StringUtils.isNotBlank( source.getStateProvince())){ delivery.setPostalCode( source.getStateProvince()); } target.setDelivery( delivery ); } else{ target.getDelivery().setFirstName( source.getFirstName() ); target.getDelivery().setLastName( source.getLastName() ); // lets fill optional data now if(StringUtils.isNotBlank( source.getAddress())){ target.getDelivery().setAddress( source.getAddress() ); } if(StringUtils.isNotBlank( source.getCity())){ target.getDelivery().setCity( source.getCity() ); } if(StringUtils.isNotBlank( source.getCompany())){ target.getDelivery().setCompany( source.getCompany() ); } if(StringUtils.isNotBlank( source.getPhone())){ target.getDelivery().setTelephone( source.getPhone()); } if(StringUtils.isNotBlank( source.getPostalCode())){ target.getDelivery().setPostalCode( source.getPostalCode()); } if(StringUtils.isNotBlank( source.getStateProvince())){ target.getDelivery().setPostalCode( source.getStateProvince()); } } return target;
100
619
719
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.customer.Customer populate(com.salesmanager.shop.model.customer.address.Address, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/ReadableCustomerDeliveryAddressPopulator.java
ReadableCustomerDeliveryAddressPopulator
populate
class ReadableCustomerDeliveryAddressPopulator extends AbstractDataPopulator<Delivery, ReadableDelivery> { private CountryService countryService; private ZoneService zoneService; @Override public ReadableDelivery populate( Delivery source, ReadableDelivery target, MerchantStore store, Language language ) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableDelivery createTarget() { // TODO Auto-generated method stub return null; } public CountryService getCountryService() { return countryService; } public void setCountryService(CountryService countryService) { this.countryService = countryService; } public ZoneService getZoneService() { return zoneService; } public void setZoneService(ZoneService zoneService) { this.zoneService = zoneService; } }
if(countryService==null) { throw new ConversionException("countryService must be set"); } if(zoneService==null) { throw new ConversionException("zoneService must be set"); } target.setLatitude(source.getLatitude()); target.setLongitude(source.getLongitude()); if(StringUtils.isNotBlank( source.getCity() )){ target.setCity(source.getCity()); } if(StringUtils.isNotBlank( source.getCompany() )){ target.setCompany(source.getCompany()); } if(StringUtils.isNotBlank( source.getAddress() )){ target.setAddress(source.getAddress()); } if(StringUtils.isNotBlank( source.getFirstName() )){ target.setFirstName(source.getFirstName()); } if(StringUtils.isNotBlank( source.getLastName() )){ target.setLastName(source.getLastName()); } if(StringUtils.isNotBlank( source.getPostalCode() )){ target.setPostalCode(source.getPostalCode()); } if(StringUtils.isNotBlank( source.getTelephone() )){ target.setPhone(source.getTelephone()); } target.setStateProvince(source.getState()); if(source.getTelephone()==null) { target.setPhone(source.getTelephone()); } target.setAddress(source.getAddress()); if(source.getCountry()!=null) { target.setCountry(source.getCountry().getIsoCode()); //resolve country name try { Map<String,Country> countries = countryService.getCountriesMap(language); Country c =countries.get(source.getCountry().getIsoCode()); if(c!=null) { target.setCountryName(c.getName()); } } catch (ServiceException e) { // TODO Auto-generated catch block throw new ConversionException(e); } } if(source.getZone()!=null) { target.setZone(source.getZone().getCode()); //resolve zone name try { Map<String,Zone> zones = zoneService.getZones(language); Zone z = zones.get(source.getZone().getCode()); if(z!=null) { target.setProvinceName(z.getName()); } } catch (ServiceException e) { // TODO Auto-generated catch block throw new ConversionException(e); } } return target;
220
723
943
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.customer.ReadableDelivery populate(com.salesmanager.core.model.common.Delivery, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/ReadableCustomerPopulator.java
ReadableCustomerPopulator
populate
class ReadableCustomerPopulator extends AbstractDataPopulator<Customer, ReadableCustomer> { @Override public ReadableCustomer populate(Customer source, ReadableCustomer target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableCustomer createTarget() { return null; } }
try { if(target == null) { target = new ReadableCustomer(); } if(source.getId()!=null && source.getId()>0) { target.setId(source.getId()); } target.setEmailAddress(source.getEmailAddress()); if (StringUtils.isNotEmpty(source.getNick())) { target.setUserName(source.getNick()); } if (source.getDefaultLanguage()!= null) { target.setLanguage(source.getDefaultLanguage().getCode()); } if (source.getGender()!= null) { target.setGender(source.getGender().name()); } if (StringUtils.isNotEmpty(source.getProvider())) { target.setProvider(source.getProvider()); } if(source.getBilling()!=null) { Address address = new Address(); address.setAddress(source.getBilling().getAddress()); address.setCity(source.getBilling().getCity()); address.setCompany(source.getBilling().getCompany()); address.setFirstName(source.getBilling().getFirstName()); address.setLastName(source.getBilling().getLastName()); address.setPostalCode(source.getBilling().getPostalCode()); address.setPhone(source.getBilling().getTelephone()); if(source.getBilling().getCountry()!=null) { address.setCountry(source.getBilling().getCountry().getIsoCode()); } if(source.getBilling().getZone()!=null) { address.setZone(source.getBilling().getZone().getCode()); } if(source.getBilling().getState()!=null) { address.setStateProvince(source.getBilling().getState()); } target.setFirstName(address.getFirstName()); target.setLastName(address.getLastName()); target.setBilling(address); } if(source.getCustomerReviewAvg() != null) { target.setRating(source.getCustomerReviewAvg().doubleValue()); } if(source.getCustomerReviewCount() != null) { target.setRatingCount(source.getCustomerReviewCount().intValue()); } if(source.getDelivery()!=null) { Address address = new Address(); address.setCity(source.getDelivery().getCity()); address.setAddress(source.getDelivery().getAddress()); address.setCompany(source.getDelivery().getCompany()); address.setFirstName(source.getDelivery().getFirstName()); address.setLastName(source.getDelivery().getLastName()); address.setPostalCode(source.getDelivery().getPostalCode()); address.setPhone(source.getDelivery().getTelephone()); if(source.getDelivery().getCountry()!=null) { address.setCountry(source.getDelivery().getCountry().getIsoCode()); } if(source.getDelivery().getZone()!=null) { address.setZone(source.getDelivery().getZone().getCode()); } if(source.getDelivery().getState()!=null) { address.setStateProvince(source.getDelivery().getState()); } target.setDelivery(address); } if(source.getAttributes()!=null) { for(CustomerAttribute attribute : source.getAttributes()) { ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute(); readableAttribute.setId(attribute.getId()); readableAttribute.setTextValue(attribute.getTextValue()); ReadableCustomerOption option = new ReadableCustomerOption(); option.setId(attribute.getCustomerOption().getId()); option.setCode(attribute.getCustomerOption().getCode()); CustomerOptionDescription d = new CustomerOptionDescription(); d.setDescription(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getDescription()); d.setName(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getName()); option.setDescription(d); readableAttribute.setCustomerOption(option); ReadableCustomerOptionValue optionValue = new ReadableCustomerOptionValue(); optionValue.setId(attribute.getCustomerOptionValue().getId()); CustomerOptionValueDescription vd = new CustomerOptionValueDescription(); vd.setDescription(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getDescription()); vd.setName(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getName()); optionValue.setCode(attribute.getCustomerOptionValue().getCode()); optionValue.setDescription(vd); readableAttribute.setCustomerOptionValue(optionValue); target.getAttributes().add(readableAttribute); } if(source.getGroups() != null) { for(Group group : source.getGroups()) { ReadableGroup readableGroup = new ReadableGroup(); readableGroup.setId(group.getId().longValue()); readableGroup.setName(group.getGroupName()); readableGroup.setType(group.getGroupType().name()); target.getGroups().add( readableGroup ); } } } } catch (Exception e) { throw new ConversionException(e); } return target;
98
1,472
1,570
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.customer.ReadableCustomer populate(com.salesmanager.core.model.customer.Customer, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/customer/ReadableCustomerReviewPopulator.java
ReadableCustomerReviewPopulator
populate
class ReadableCustomerReviewPopulator extends AbstractDataPopulator<CustomerReview, ReadableCustomerReview> { @Override public ReadableCustomerReview populate(CustomerReview source, ReadableCustomerReview target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableCustomerReview createTarget() { // TODO Auto-generated method stub return null; } }
try { if(target==null) { target = new ReadableCustomerReview(); } if(source.getReviewDate() != null) { target.setDate(DateUtil.formatDate(source.getReviewDate())); } ReadableCustomer reviewed = new ReadableCustomer(); reviewed.setId(source.getReviewedCustomer().getId()); reviewed.setFirstName(source.getReviewedCustomer().getBilling().getFirstName()); reviewed.setLastName(source.getReviewedCustomer().getBilling().getLastName()); target.setId(source.getId()); target.setCustomerId(source.getCustomer().getId()); target.setReviewedCustomer(reviewed); target.setRating(source.getReviewRating()); target.setReviewedCustomer(reviewed); target.setCustomerId(source.getCustomer().getId()); Set<CustomerReviewDescription> descriptions = source.getDescriptions(); if(CollectionUtils.isNotEmpty(descriptions)) { CustomerReviewDescription description = null; if(descriptions.size()>1) { for(CustomerReviewDescription desc : descriptions) { if(desc.getLanguage().getCode().equals(language.getCode())) { description = desc; break; } } } else { description = descriptions.iterator().next(); } if(description != null) { target.setDescription(description.getDescription()); target.setLanguage(description.getLanguage().getCode()); } } } catch (Exception e) { throw new ConversionException("Cannot populate ReadableCustomerReview", e); } return target;
108
470
578
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.customer.ReadableCustomerReview populate(com.salesmanager.core.model.customer.review.CustomerReview, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/manufacturer/PersistableManufacturerPopulator.java
PersistableManufacturerPopulator
populate
class PersistableManufacturerPopulator extends AbstractDataPopulator<PersistableManufacturer, Manufacturer> { private LanguageService languageService; @Override public Manufacturer populate(PersistableManufacturer source, Manufacturer target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Manufacturer createTarget() { // TODO Auto-generated method stub return null; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } public LanguageService getLanguageService() { return languageService; } }
Validate.notNull(languageService, "Requires to set LanguageService"); try { target.setMerchantStore(store); target.setCode(source.getCode()); if(!CollectionUtils.isEmpty(source.getDescriptions())) { Set<com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription>(); for(ManufacturerDescription description : source.getDescriptions()) { com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription desc = new com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription(); if(desc.getId() != null && desc.getId().longValue()>0) { desc.setId(description.getId()); } if(target.getDescriptions() != null) { for(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription d : target.getDescriptions()) { if(d.getLanguage().getCode().equals(description.getLanguage()) || desc.getId() != null && d.getId().longValue() == desc.getId().longValue()) { desc = d; } } } desc.setManufacturer(target); desc.setDescription(description.getDescription()); desc.setName(description.getName()); Language lang = languageService.getByCode(description.getLanguage()); if(lang==null) { throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]"); } desc.setLanguage(lang); descriptions.add(desc); } target.setDescriptions(descriptions); } } catch (Exception e) { throw new ConversionException(e); } return target;
171
539
710
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer populate(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/manufacturer/ReadableManufacturerPopulator.java
ReadableManufacturerPopulator
populateDescription
class ReadableManufacturerPopulator extends AbstractDataPopulator<com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer, ReadableManufacturer> { @Override public ReadableManufacturer populate( com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer source, ReadableManufacturer target, MerchantStore store, Language language) throws ConversionException { if (language == null) { target = new ReadableManufacturerFull(); } target.setOrder(source.getOrder()); target.setId(source.getId()); target.setCode(source.getCode()); if (source.getDescriptions() != null && source.getDescriptions().size() > 0) { List<com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription> fulldescriptions = new ArrayList<com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription>(); Set<ManufacturerDescription> descriptions = source.getDescriptions(); ManufacturerDescription description = null; for (ManufacturerDescription desc : descriptions) { if (language != null && desc.getLanguage().getCode().equals(language.getCode())) { description = desc; break; } else { fulldescriptions.add(populateDescription(desc)); } } if (description != null) { com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription d = populateDescription(description); target.setDescription(d); } if (target instanceof ReadableManufacturerFull) { ((ReadableManufacturerFull) target).setDescriptions(fulldescriptions); } } return target; } @Override protected ReadableManufacturer createTarget() { return null; } com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription populateDescription( ManufacturerDescription description) {<FILL_FUNCTION_BODY>} }
if (description == null) { return null; } com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription d = new com.salesmanager.shop.model.catalog.manufacturer.ManufacturerDescription(); d.setName(description.getName()); d.setDescription(description.getDescription()); d.setId(description.getId()); d.setTitle(description.getTitle()); if (description.getLanguage() != null) { d.setLanguage(description.getLanguage().getCode()); } return d;
555
153
708
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer populate(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/OrderProductPopulator.java
OrderProductPopulator
populate
class OrderProductPopulator extends AbstractDataPopulator<ShoppingCartItem, OrderProduct> { private ProductService productService; private DigitalProductService digitalProductService; private ProductAttributeService productAttributeService; public ProductAttributeService getProductAttributeService() { return productAttributeService; } public void setProductAttributeService( ProductAttributeService productAttributeService) { this.productAttributeService = productAttributeService; } public DigitalProductService getDigitalProductService() { return digitalProductService; } public void setDigitalProductService(DigitalProductService digitalProductService) { this.digitalProductService = digitalProductService; } /** * Converts a ShoppingCartItem carried in the ShoppingCart to an OrderProduct * that will be saved in the system */ @Override public OrderProduct populate(ShoppingCartItem source, OrderProduct target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected OrderProduct createTarget() { return null; } public void setProductService(ProductService productService) { this.productService = productService; } public ProductService getProductService() { return productService; } private OrderProductPrice orderProductPrice(FinalPrice price) { OrderProductPrice orderProductPrice = new OrderProductPrice(); ProductPrice productPrice = price.getProductPrice(); orderProductPrice.setDefaultPrice(productPrice.isDefaultPrice()); orderProductPrice.setProductPrice(price.getFinalPrice()); orderProductPrice.setProductPriceCode(productPrice.getCode()); if(productPrice.getDescriptions()!=null && productPrice.getDescriptions().size()>0) { orderProductPrice.setProductPriceName(productPrice.getDescriptions().iterator().next().getName()); } if(price.isDiscounted()) { orderProductPrice.setProductPriceSpecial(productPrice.getProductPriceSpecialAmount()); orderProductPrice.setProductPriceSpecialStartDate(productPrice.getProductPriceSpecialStartDate()); orderProductPrice.setProductPriceSpecialEndDate(productPrice.getProductPriceSpecialEndDate()); } return orderProductPrice; } }
Validate.notNull(productService,"productService must be set"); Validate.notNull(digitalProductService,"digitalProductService must be set"); Validate.notNull(productAttributeService,"productAttributeService must be set"); try { Product modelProduct = productService.getBySku(source.getSku(), store, language); if(modelProduct==null) { throw new ConversionException("Cannot get product with sku " + source.getSku()); } if(modelProduct.getMerchantStore().getId().intValue()!=store.getId().intValue()) { throw new ConversionException("Invalid product with sku " + source.getSku()); } DigitalProduct digitalProduct = digitalProductService.getByProduct(store, modelProduct); if(digitalProduct!=null) { OrderProductDownload orderProductDownload = new OrderProductDownload(); orderProductDownload.setOrderProductFilename(digitalProduct.getProductFileName()); orderProductDownload.setOrderProduct(target); orderProductDownload.setDownloadCount(0); orderProductDownload.setMaxdays(ApplicationConstants.MAX_DOWNLOAD_DAYS); target.getDownloads().add(orderProductDownload); } target.setOneTimeCharge(source.getItemPrice()); target.setProductName(source.getProduct().getDescriptions().iterator().next().getName()); target.setProductQuantity(source.getQuantity()); target.setSku(source.getProduct().getSku()); FinalPrice finalPrice = source.getFinalPrice(); if(finalPrice==null) { throw new ConversionException("Object final price not populated in shoppingCartItem (source)"); } //Default price OrderProductPrice orderProductPrice = orderProductPrice(finalPrice); orderProductPrice.setOrderProduct(target); Set<OrderProductPrice> prices = new HashSet<OrderProductPrice>(); prices.add(orderProductPrice); //Other prices List<FinalPrice> otherPrices = finalPrice.getAdditionalPrices(); if(otherPrices!=null) { for(FinalPrice otherPrice : otherPrices) { OrderProductPrice other = orderProductPrice(otherPrice); other.setOrderProduct(target); prices.add(other); } } target.setPrices(prices); //OrderProductAttribute Set<ShoppingCartAttributeItem> attributeItems = source.getAttributes(); if(!CollectionUtils.isEmpty(attributeItems)) { Set<OrderProductAttribute> attributes = new HashSet<OrderProductAttribute>(); for(ShoppingCartAttributeItem attribute : attributeItems) { OrderProductAttribute orderProductAttribute = new OrderProductAttribute(); orderProductAttribute.setOrderProduct(target); Long id = attribute.getProductAttributeId(); ProductAttribute attr = productAttributeService.getById(id); if(attr==null) { throw new ConversionException("Attribute id " + id + " does not exists"); } if(attr.getProduct().getMerchantStore().getId().intValue()!=store.getId().intValue()) { throw new ConversionException("Attribute id " + id + " invalid for this store"); } orderProductAttribute.setProductAttributeIsFree(attr.getProductAttributeIsFree()); orderProductAttribute.setProductAttributeName(attr.getProductOption().getDescriptionsSettoList().get(0).getName()); orderProductAttribute.setProductAttributeValueName(attr.getProductOptionValue().getDescriptionsSettoList().get(0).getName()); orderProductAttribute.setProductAttributePrice(attr.getProductAttributePrice()); orderProductAttribute.setProductAttributeWeight(attr.getProductAttributeWeight()); orderProductAttribute.setProductOptionId(attr.getProductOption().getId()); orderProductAttribute.setProductOptionValueId(attr.getProductOptionValue().getId()); attributes.add(orderProductAttribute); } target.setOrderAttributes(attributes); } } catch (Exception e) { throw new ConversionException(e); } return target;
575
1,087
1,662
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.order.orderproduct.OrderProduct populate(com.salesmanager.core.model.shoppingcart.ShoppingCartItem, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/PersistableOrderApiPopulator.java
PersistableOrderApiPopulator
populate
class PersistableOrderApiPopulator extends AbstractDataPopulator<PersistableOrder, Order> { @Autowired private CurrencyService currencyService; @Autowired private CustomerService customerService; /* @Autowired private ShoppingCartService shoppingCartService; @Autowired private ProductService productService; @Autowired private ProductAttributeService productAttributeService; @Autowired private DigitalProductService digitalProductService;*/ @Autowired private CustomerPopulator customerPopulator; @Override public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Order createTarget() { // TODO Auto-generated method stub return null; } /* public CurrencyService getCurrencyService() { return currencyService; } public void setCurrencyService(CurrencyService currencyService) { this.currencyService = currencyService; } public CustomerService getCustomerService() { return customerService; } public void setCustomerService(CustomerService customerService) { this.customerService = customerService; } public ShoppingCartService getShoppingCartService() { return shoppingCartService; } public void setShoppingCartService(ShoppingCartService shoppingCartService) { this.shoppingCartService = shoppingCartService; } public ProductService getProductService() { return productService; } public void setProductService(ProductService productService) { this.productService = productService; } public ProductAttributeService getProductAttributeService() { return productAttributeService; } public void setProductAttributeService(ProductAttributeService productAttributeService) { this.productAttributeService = productAttributeService; } public DigitalProductService getDigitalProductService() { return digitalProductService; } public void setDigitalProductService(DigitalProductService digitalProductService) { this.digitalProductService = digitalProductService; }*/ }
/* Validate.notNull(currencyService,"currencyService must be set"); Validate.notNull(customerService,"customerService must be set"); Validate.notNull(shoppingCartService,"shoppingCartService must be set"); Validate.notNull(productService,"productService must be set"); Validate.notNull(productAttributeService,"productAttributeService must be set"); Validate.notNull(digitalProductService,"digitalProductService must be set");*/ Validate.notNull(source.getPayment(),"Payment cannot be null"); try { if(target == null) { target = new Order(); } //target.setLocale(LocaleUtils.getLocale(store)); target.setLocale(LocaleUtils.getLocale(store)); Currency currency = null; try { currency = currencyService.getByCode(source.getCurrency()); } catch(Exception e) { throw new ConversionException("Currency not found for code " + source.getCurrency()); } if(currency==null) { throw new ConversionException("Currency not found for code " + source.getCurrency()); } //Customer Customer customer = null; if(source.getCustomerId() != null && source.getCustomerId().longValue() >0) { Long customerId = source.getCustomerId(); customer = customerService.getById(customerId); if(customer == null) { throw new ConversionException("Curstomer with id " + source.getCustomerId() + " does not exist"); } target.setCustomerId(customerId); } else { if(source instanceof PersistableAnonymousOrder) { PersistableCustomer persistableCustomer = ((PersistableAnonymousOrder)source).getCustomer(); customer = new Customer(); customer = customerPopulator.populate(persistableCustomer, customer, store, language); } else { throw new ConversionException("Curstomer details or id not set in request"); } } target.setCustomerEmailAddress(customer.getEmailAddress()); Delivery delivery = customer.getDelivery(); target.setDelivery(delivery); Billing billing = customer.getBilling(); target.setBilling(billing); if(source.getAttributes() != null && source.getAttributes().size() > 0) { Set<OrderAttribute> attrs = new HashSet<OrderAttribute>(); for(com.salesmanager.shop.model.order.OrderAttribute attribute : source.getAttributes()) { OrderAttribute attr = new OrderAttribute(); attr.setKey(attribute.getKey()); attr.setValue(attribute.getValue()); attr.setOrder(target); attrs.add(attr); } target.setOrderAttributes(attrs); } target.setDatePurchased(new Date()); target.setCurrency(currency); target.setCurrencyValue(new BigDecimal(0)); target.setMerchant(store); target.setChannel(OrderChannel.API); //need this target.setStatus(OrderStatus.ORDERED); target.setPaymentModuleCode(source.getPayment().getPaymentModule()); target.setPaymentType(PaymentType.valueOf(source.getPayment().getPaymentType())); target.setCustomerAgreement(source.isCustomerAgreement()); target.setConfirmedAddress(true);//force this to true, cannot perform this activity from the API if(!StringUtils.isBlank(source.getComments())) { OrderStatusHistory statusHistory = new OrderStatusHistory(); statusHistory.setStatus(null); statusHistory.setOrder(target); statusHistory.setComments(source.getComments()); target.getOrderHistory().add(statusHistory); } return target; } catch(Exception e) { throw new ConversionException(e); }
512
1,082
1,594
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.order.Order populate(com.salesmanager.shop.model.order.v1.PersistableOrder, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/PersistableOrderPopulator.java
PersistableOrderPopulator
populate
class PersistableOrderPopulator extends AbstractDataPopulator<PersistableOrder, Order> { private CustomerService customerService; private CountryService countryService; private CurrencyService currencyService; private ZoneService zoneService; private ProductService productService; private DigitalProductService digitalProductService; private ProductAttributeService productAttributeService; @Override public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Order createTarget() { return null; } public void setProductService(ProductService productService) { this.productService = productService; } public ProductService getProductService() { return productService; } public void setDigitalProductService(DigitalProductService digitalProductService) { this.digitalProductService = digitalProductService; } public DigitalProductService getDigitalProductService() { return digitalProductService; } public void setProductAttributeService(ProductAttributeService productAttributeService) { this.productAttributeService = productAttributeService; } public ProductAttributeService getProductAttributeService() { return productAttributeService; } public CustomerService getCustomerService() { return customerService; } public void setCustomerService(CustomerService customerService) { this.customerService = customerService; } public CountryService getCountryService() { return countryService; } public void setCountryService(CountryService countryService) { this.countryService = countryService; } public CurrencyService getCurrencyService() { return currencyService; } public void setCurrencyService(CurrencyService currencyService) { this.currencyService = currencyService; } public ZoneService getZoneService() { return zoneService; } public void setZoneService(ZoneService zoneService) { this.zoneService = zoneService; } }
Validate.notNull(productService,"productService must be set"); Validate.notNull(digitalProductService,"digitalProductService must be set"); Validate.notNull(productAttributeService,"productAttributeService must be set"); Validate.notNull(customerService,"customerService must be set"); Validate.notNull(countryService,"countryService must be set"); Validate.notNull(zoneService,"zoneService must be set"); Validate.notNull(currencyService,"currencyService must be set"); try { Map<String,Country> countriesMap = countryService.getCountriesMap(language); Map<String,Zone> zonesMap = zoneService.getZones(language); /** customer **/ PersistableCustomer customer = source.getCustomer(); if(customer!=null) { if(customer.getId()!=null && customer.getId()>0) { Customer modelCustomer = customerService.getById(customer.getId()); if(modelCustomer==null) { throw new ConversionException("Customer id " + customer.getId() + " does not exists"); } if(modelCustomer.getMerchantStore().getId().intValue()!=store.getId().intValue()) { throw new ConversionException("Customer id " + customer.getId() + " does not exists for store " + store.getCode()); } target.setCustomerId(modelCustomer.getId()); target.setBilling(modelCustomer.getBilling()); target.setDelivery(modelCustomer.getDelivery()); target.setCustomerEmailAddress(source.getCustomer().getEmailAddress()); } } target.setLocale(LocaleUtils.getLocale(store)); CreditCard creditCard = source.getCreditCard(); if(creditCard!=null) { String maskedNumber = CreditCardUtils.maskCardNumber(creditCard.getCcNumber()); creditCard.setCcNumber(maskedNumber); target.setCreditCard(creditCard); } Currency currency = null; try { currency = currencyService.getByCode(source.getCurrency()); } catch(Exception e) { throw new ConversionException("Currency not found for code " + source.getCurrency()); } if(currency==null) { throw new ConversionException("Currency not found for code " + source.getCurrency()); } target.setCurrency(currency); target.setDatePurchased(source.getDatePurchased()); //target.setCurrency(store.getCurrency()); target.setCurrencyValue(new BigDecimal(0)); target.setMerchant(store); target.setStatus(source.getOrderStatus()); target.setPaymentModuleCode(source.getPaymentModule()); target.setPaymentType(source.getPaymentType()); target.setShippingModuleCode(source.getShippingModule()); target.setCustomerAgreement(source.isCustomerAgreed()); target.setConfirmedAddress(source.isConfirmedAddress()); if(source.getPreviousOrderStatus()!=null) { List<OrderStatus> orderStatusList = source.getPreviousOrderStatus(); for(OrderStatus status : orderStatusList) { OrderStatusHistory statusHistory = new OrderStatusHistory(); statusHistory.setStatus(status); statusHistory.setOrder(target); target.getOrderHistory().add(statusHistory); } } if(!StringUtils.isBlank(source.getComments())) { OrderStatusHistory statusHistory = new OrderStatusHistory(); statusHistory.setStatus(null); statusHistory.setOrder(target); statusHistory.setComments(source.getComments()); target.getOrderHistory().add(statusHistory); } List<PersistableOrderProduct> products = source.getOrderProductItems(); if(CollectionUtils.isEmpty(products)) { throw new ConversionException("Requires at least 1 PersistableOrderProduct"); } com.salesmanager.shop.populator.order.PersistableOrderProductPopulator orderProductPopulator = new PersistableOrderProductPopulator(); orderProductPopulator.setProductAttributeService(productAttributeService); orderProductPopulator.setProductService(productService); orderProductPopulator.setDigitalProductService(digitalProductService); for(PersistableOrderProduct orderProduct : products) { OrderProduct modelOrderProduct = new OrderProduct(); orderProductPopulator.populate(orderProduct, modelOrderProduct, store, language); target.getOrderProducts().add(modelOrderProduct); } List<OrderTotal> orderTotals = source.getTotals(); if(CollectionUtils.isNotEmpty(orderTotals)) { for(OrderTotal total : orderTotals) { com.salesmanager.core.model.order.OrderTotal totalModel = new com.salesmanager.core.model.order.OrderTotal(); totalModel.setModule(total.getModule()); totalModel.setOrder(target); totalModel.setOrderTotalCode(total.getCode()); totalModel.setTitle(total.getTitle()); totalModel.setValue(total.getValue()); target.getOrderTotal().add(totalModel); } } } catch (Exception e) { throw new ConversionException(e); } return target;
485
1,440
1,925
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.order.Order populate(com.salesmanager.shop.model.order.v0.PersistableOrder, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/PersistableOrderProductPopulator.java
PersistableOrderProductPopulator
populate
class PersistableOrderProductPopulator extends AbstractDataPopulator<PersistableOrderProduct, OrderProduct> { private ProductService productService; private DigitalProductService digitalProductService; private ProductAttributeService productAttributeService; public ProductAttributeService getProductAttributeService() { return productAttributeService; } public void setProductAttributeService( ProductAttributeService productAttributeService) { this.productAttributeService = productAttributeService; } public DigitalProductService getDigitalProductService() { return digitalProductService; } public void setDigitalProductService(DigitalProductService digitalProductService) { this.digitalProductService = digitalProductService; } /** * Converts a ShoppingCartItem carried in the ShoppingCart to an OrderProduct * that will be saved in the system */ @Override public OrderProduct populate(PersistableOrderProduct source, OrderProduct target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected OrderProduct createTarget() { return null; } public void setProductService(ProductService productService) { this.productService = productService; } public ProductService getProductService() { return productService; } }
Validate.notNull(productService,"productService must be set"); Validate.notNull(digitalProductService,"digitalProductService must be set"); Validate.notNull(productAttributeService,"productAttributeService must be set"); try { Product modelProduct = productService.getById(source.getProduct().getId()); if(modelProduct==null) { throw new ConversionException("Cannot get product with id (productId) " + source.getProduct().getId()); } if(modelProduct.getMerchantStore().getId().intValue()!=store.getId().intValue()) { throw new ConversionException("Invalid product id " + source.getProduct().getId()); } DigitalProduct digitalProduct = digitalProductService.getByProduct(store, modelProduct); if(digitalProduct!=null) { OrderProductDownload orderProductDownload = new OrderProductDownload(); orderProductDownload.setOrderProductFilename(digitalProduct.getProductFileName()); orderProductDownload.setOrderProduct(target); orderProductDownload.setDownloadCount(0); orderProductDownload.setMaxdays(ApplicationConstants.MAX_DOWNLOAD_DAYS); target.getDownloads().add(orderProductDownload); } target.setOneTimeCharge(source.getPrice()); target.setProductName(source.getProduct().getDescription().getName()); target.setProductQuantity(source.getOrderedQuantity()); target.setSku(source.getProduct().getSku()); OrderProductPrice orderProductPrice = new OrderProductPrice(); orderProductPrice.setDefaultPrice(true); orderProductPrice.setProductPrice(source.getPrice()); orderProductPrice.setOrderProduct(target); Set<OrderProductPrice> prices = new HashSet<OrderProductPrice>(); prices.add(orderProductPrice); /** DO NOT SUPPORT MUTIPLE PRICES **/ /* //Other prices List<FinalPrice> otherPrices = finalPrice.getAdditionalPrices(); if(otherPrices!=null) { for(FinalPrice otherPrice : otherPrices) { OrderProductPrice other = orderProductPrice(otherPrice); other.setOrderProduct(target); prices.add(other); } }*/ target.setPrices(prices); //OrderProductAttribute List<ProductAttribute> attributeItems = source.getAttributes(); if(!CollectionUtils.isEmpty(attributeItems)) { Set<OrderProductAttribute> attributes = new HashSet<OrderProductAttribute>(); for(ProductAttribute attribute : attributeItems) { OrderProductAttribute orderProductAttribute = new OrderProductAttribute(); orderProductAttribute.setOrderProduct(target); Long id = attribute.getId(); com.salesmanager.core.model.catalog.product.attribute.ProductAttribute attr = productAttributeService.getById(id); if(attr==null) { throw new ConversionException("Attribute id " + id + " does not exists"); } if(attr.getProduct().getMerchantStore().getId().intValue()!=store.getId().intValue()) { throw new ConversionException("Attribute id " + id + " invalid for this store"); } orderProductAttribute.setProductAttributeIsFree(attr.getProductAttributeIsFree()); orderProductAttribute.setProductAttributeName(attr.getProductOption().getDescriptionsSettoList().get(0).getName()); orderProductAttribute.setProductAttributeValueName(attr.getProductOptionValue().getDescriptionsSettoList().get(0).getName()); orderProductAttribute.setProductAttributePrice(attr.getProductAttributePrice()); orderProductAttribute.setProductAttributeWeight(attr.getProductAttributeWeight()); orderProductAttribute.setProductOptionId(attr.getProductOption().getId()); orderProductAttribute.setProductOptionValueId(attr.getProductOptionValue().getId()); attributes.add(orderProductAttribute); } target.setOrderAttributes(attributes); } } catch (Exception e) { throw new ConversionException(e); } return target;
323
1,082
1,405
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.order.orderproduct.OrderProduct populate(com.salesmanager.shop.model.order.PersistableOrderProduct, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/ReadableOrderProductDownloadPopulator.java
ReadableOrderProductDownloadPopulator
populate
class ReadableOrderProductDownloadPopulator extends AbstractDataPopulator<OrderProductDownload, ReadableOrderProductDownload> { @Override public ReadableOrderProductDownload populate(OrderProductDownload source, ReadableOrderProductDownload target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableOrderProductDownload createTarget() { return new ReadableOrderProductDownload(); } }
try { target.setProductName(source.getOrderProduct().getProductName()); target.setDownloadCount(source.getDownloadCount()); target.setDownloadExpiryDays(source.getMaxdays()); target.setId(source.getId()); target.setFileName(source.getOrderProductFilename()); target.setOrderId(source.getOrderProduct().getOrder().getId()); return target; } catch(Exception e) { throw new ConversionException(e); }
119
142
261
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.order.ReadableOrderProductDownload populate(com.salesmanager.core.model.order.orderproduct.OrderProductDownload, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/ReadableOrderProductPopulator.java
ReadableOrderProductPopulator
populate
class ReadableOrderProductPopulator extends AbstractDataPopulator<OrderProduct, ReadableOrderProduct> { private ProductService productService; private PricingService pricingService; private ImageFilePath imageUtils; public ImageFilePath getimageUtils() { return imageUtils; } public void setimageUtils(ImageFilePath imageUtils) { this.imageUtils = imageUtils; } @Override public ReadableOrderProduct populate(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableOrderProduct createTarget() { return null; } public ProductService getProductService() { return productService; } public void setProductService(ProductService productService) { this.productService = productService; } public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } }
Validate.notNull(productService,"Requires ProductService"); Validate.notNull(pricingService,"Requires PricingService"); Validate.notNull(imageUtils,"Requires imageUtils"); target.setId(source.getId()); target.setOrderedQuantity(source.getProductQuantity()); try { target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store)); } catch(Exception e) { throw new ConversionException("Cannot convert price",e); } target.setProductName(source.getProductName()); target.setSku(source.getSku()); //subtotal = price * quantity BigDecimal subTotal = source.getOneTimeCharge(); subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity())); try { String subTotalPrice = pricingService.getDisplayAmount(subTotal, store); target.setSubTotal(subTotalPrice); } catch(Exception e) { throw new ConversionException("Cannot format price",e); } if(source.getOrderAttributes()!=null) { List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>(); for(OrderProductAttribute attr : source.getOrderAttributes()) { ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute(); try { String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store); readableAttribute.setAttributePrice(price); } catch (ServiceException e) { throw new ConversionException("Cannot format price",e); } readableAttribute.setAttributeName(attr.getProductAttributeName()); readableAttribute.setAttributeValue(attr.getProductAttributeValueName()); attributes.add(readableAttribute); } target.setAttributes(attributes); } String productSku = source.getSku(); if(!StringUtils.isBlank(productSku)) { Product product = null; try { product = productService.getBySku(productSku, store, language); } catch (ServiceException e) { throw new ServiceRuntimeException(e); } if(product!=null) { ReadableProductPopulator populator = new ReadableProductPopulator(); populator.setPricingService(pricingService); populator.setimageUtils(imageUtils); ReadableProduct productProxy = populator.populate(product, new ReadableProduct(), store, language); target.setProduct(productProxy); Set<ProductImage> images = product.getImages(); ProductImage defaultImage = null; if(images!=null) { for(ProductImage image : images) { if(defaultImage==null) { defaultImage = image; } if(image.isDefaultImage()) { defaultImage = image; } } } if(defaultImage!=null) { target.setImage(defaultImage.getProductImage()); } } } return target;
278
837
1,115
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.order.ReadableOrderProduct populate(com.salesmanager.core.model.order.orderproduct.OrderProduct, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/ReadableOrderSummaryPopulator.java
ReadableOrderSummaryPopulator
populate
class ReadableOrderSummaryPopulator extends AbstractDataPopulator<OrderTotalSummary, ReadableOrderTotalSummary> { private static final Logger LOGGER = LoggerFactory .getLogger(ReadableOrderSummaryPopulator.class); private PricingService pricingService; private LabelUtils messages; @Override public ReadableOrderTotalSummary populate(OrderTotalSummary source, ReadableOrderTotalSummary target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableOrderTotalSummary createTarget() { // TODO Auto-generated method stub return null; } public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } public LabelUtils getMessages() { return messages; } public void setMessages(LabelUtils messages) { this.messages = messages; } }
Validate.notNull(pricingService,"PricingService must be set"); Validate.notNull(messages,"LabelUtils must be set"); if(target==null) { target = new ReadableOrderTotalSummary(); } try { if(source.getSubTotal() != null) { target.setSubTotal(pricingService.getDisplayAmount(source.getSubTotal(), store)); } if(source.getTaxTotal()!=null) { target.setTaxTotal(pricingService.getDisplayAmount(source.getTaxTotal(), store)); } if(source.getTotal() != null) { target.setTotal(pricingService.getDisplayAmount(source.getTotal(), store)); } if(!CollectionUtils.isEmpty(source.getTotals())) { ReadableOrderTotalPopulator orderTotalPopulator = new ReadableOrderTotalPopulator(); orderTotalPopulator.setMessages(messages); orderTotalPopulator.setPricingService(pricingService); for(OrderTotal orderTotal : source.getTotals()) { ReadableOrderTotal t = new ReadableOrderTotal(); orderTotalPopulator.populate(orderTotal, t, store, language); target.getTotals().add(t); } } } catch(Exception e) { LOGGER.error("Error during amount formatting " + e.getMessage()); throw new ConversionException(e); } return target;
259
400
659
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.order.ReadableOrderTotalSummary populate(com.salesmanager.core.model.order.OrderTotalSummary, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/ReadableOrderTotalPopulator.java
ReadableOrderTotalPopulator
populate
class ReadableOrderTotalPopulator extends AbstractDataPopulator<OrderTotal, ReadableOrderTotal> { private PricingService pricingService; private LabelUtils messages; @Override public ReadableOrderTotal populate(OrderTotal source, ReadableOrderTotal target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableOrderTotal createTarget() { return new ReadableOrderTotal(); } public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } public LabelUtils getMessages() { return messages; } public void setMessages(LabelUtils messages) { this.messages = messages; } }
Validate.notNull(pricingService,"PricingService must be set"); Validate.notNull(messages,"LabelUtils must be set"); Locale locale = LocaleUtils.getLocale(language); try { target.setCode(source.getOrderTotalCode()); target.setId(source.getId()); target.setModule(source.getModule()); target.setOrder(source.getSortOrder()); target.setTitle(messages.getMessage(source.getOrderTotalCode(), locale, source.getOrderTotalCode())); target.setText(source.getText()); target.setValue(source.getValue()); target.setTotal(pricingService.getDisplayAmount(source.getValue(), store)); if(!StringUtils.isBlank(source.getOrderTotalCode())) { if(Constants.OT_DISCOUNT_TITLE.equals(source.getOrderTotalCode())) { target.setDiscounted(true); } } } catch(Exception e) { throw new ConversionException(e); } return target;
226
301
527
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.order.total.ReadableOrderTotal populate(com.salesmanager.core.model.order.OrderTotal, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/ReadableShippingSummaryPopulator.java
ReadableShippingSummaryPopulator
populate
class ReadableShippingSummaryPopulator extends AbstractDataPopulator<ShippingSummary, ReadableShippingSummary> { private PricingService pricingService; @Override public ReadableShippingSummary populate(ShippingSummary source, ReadableShippingSummary target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableShippingSummary createTarget() { return new ReadableShippingSummary(); } public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } }
Validate.notNull(pricingService,"PricingService must be set"); Validate.notNull(source,"ShippingSummary cannot be null"); try { target.setShippingQuote(source.isShippingQuote()); target.setFreeShipping(source.isFreeShipping()); target.setHandling(source.getHandling()); target.setShipping(source.getShipping()); target.setShippingModule(source.getShippingModule()); target.setShippingOption(source.getShippingOption()); target.setTaxOnShipping(source.isTaxOnShipping()); target.setHandlingText(pricingService.getDisplayAmount(source.getHandling(), store)); target.setShippingText(pricingService.getDisplayAmount(source.getShipping(), store)); if(source.getDeliveryAddress()!=null) { ReadableDelivery deliveryAddress = new ReadableDelivery(); deliveryAddress.setAddress(source.getDeliveryAddress().getAddress()); deliveryAddress.setPostalCode(source.getDeliveryAddress().getPostalCode()); deliveryAddress.setCity(source.getDeliveryAddress().getCity()); if(source.getDeliveryAddress().getZone()!=null) { deliveryAddress.setZone(source.getDeliveryAddress().getZone().getCode()); } if(source.getDeliveryAddress().getCountry()!=null) { deliveryAddress.setCountry(source.getDeliveryAddress().getCountry().getIsoCode()); } deliveryAddress.setLatitude(source.getDeliveryAddress().getLatitude()); deliveryAddress.setLongitude(source.getDeliveryAddress().getLongitude()); deliveryAddress.setStateProvince(source.getDeliveryAddress().getState()); target.setDelivery(deliveryAddress); } } catch(Exception e) { throw new ConversionException(e); } return target;
193
552
745
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.order.shipping.ReadableShippingSummary populate(com.salesmanager.core.model.shipping.ShippingSummary, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/ReadableShopOrderPopulator.java
ReadableShopOrderPopulator
populate
class ReadableShopOrderPopulator extends AbstractDataPopulator<ShopOrder, ReadableShopOrder> { @Override public ReadableShopOrder populate(ShopOrder source, ReadableShopOrder target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableShopOrder createTarget() { return null; } }
//not that much is required //customer try { ReadableCustomer customer = new ReadableCustomer(); PersistableCustomer persistableCustomer = source.getCustomer(); customer.setEmailAddress(persistableCustomer.getEmailAddress()); if(persistableCustomer.getBilling()!=null) { Address address = new Address(); address.setCity(persistableCustomer.getBilling().getCity()); address.setCompany(persistableCustomer.getBilling().getCompany()); address.setFirstName(persistableCustomer.getBilling().getFirstName()); address.setLastName(persistableCustomer.getBilling().getLastName()); address.setPostalCode(persistableCustomer.getBilling().getPostalCode()); address.setPhone(persistableCustomer.getBilling().getPhone()); if(persistableCustomer.getBilling().getCountry()!=null) { address.setCountry(persistableCustomer.getBilling().getCountry()); } if(persistableCustomer.getBilling().getZone()!=null) { address.setZone(persistableCustomer.getBilling().getZone()); } customer.setBilling(address); } if(persistableCustomer.getDelivery()!=null) { Address address = new Address(); address.setCity(persistableCustomer.getDelivery().getCity()); address.setCompany(persistableCustomer.getDelivery().getCompany()); address.setFirstName(persistableCustomer.getDelivery().getFirstName()); address.setLastName(persistableCustomer.getDelivery().getLastName()); address.setPostalCode(persistableCustomer.getDelivery().getPostalCode()); address.setPhone(persistableCustomer.getDelivery().getPhone()); if(persistableCustomer.getDelivery().getCountry()!=null) { address.setCountry(persistableCustomer.getDelivery().getCountry()); } if(persistableCustomer.getDelivery().getZone()!=null) { address.setZone(persistableCustomer.getDelivery().getZone()); } customer.setDelivery(address); } //TODO if ship to billing enabled, set delivery = billing /* if(persistableCustomer.getAttributes()!=null) { for(PersistableCustomerAttribute attribute : persistableCustomer.getAttributes()) { ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute(); readableAttribute.setId(attribute.getId()); ReadableCustomerOption option = new ReadableCustomerOption(); option.setId(attribute.getCustomerOption().getId()); option.setCode(attribute.getCustomerOption()); CustomerOptionDescription d = new CustomerOptionDescription(); d.setDescription(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getDescription()); d.setName(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getName()); option.setDescription(d); readableAttribute.setCustomerOption(option); ReadableCustomerOptionValue optionValue = new ReadableCustomerOptionValue(); optionValue.setId(attribute.getCustomerOptionValue().getId()); CustomerOptionValueDescription vd = new CustomerOptionValueDescription(); vd.setDescription(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getDescription()); vd.setName(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getName()); optionValue.setCode(attribute.getCustomerOptionValue().getCode()); optionValue.setDescription(vd); readableAttribute.setCustomerOptionValue(optionValue); customer.getAttributes().add(readableAttribute); } }*/ target.setCustomer(customer); } catch (Exception e) { throw new ConversionException(e); } return target;
105
1,063
1,168
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.order.ReadableShopOrder populate(com.salesmanager.shop.model.order.ShopOrder, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/ShoppingCartItemPopulator.java
ShoppingCartItemPopulator
populate
class ShoppingCartItemPopulator extends AbstractDataPopulator<PersistableOrderProduct, ShoppingCartItem> { private ProductService productService; private ProductAttributeService productAttributeService; private ShoppingCartService shoppingCartService; @Override public ShoppingCartItem populate(PersistableOrderProduct source, /** TODO: Fix, target not used possible future bug ! **/ShoppingCartItem target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ShoppingCartItem createTarget() { // TODO Auto-generated method stub return null; } public void setProductAttributeService(ProductAttributeService productAttributeService) { this.productAttributeService = productAttributeService; } public ProductAttributeService getProductAttributeService() { return productAttributeService; } public void setProductService(ProductService productService) { this.productService = productService; } public ProductService getProductService() { return productService; } public void setShoppingCartService(ShoppingCartService shoppingCartService) { this.shoppingCartService = shoppingCartService; } public ShoppingCartService getShoppingCartService() { return shoppingCartService; } }
Validate.notNull(productService, "Requires to set productService"); Validate.notNull(productAttributeService, "Requires to set productAttributeService"); Validate.notNull(shoppingCartService, "Requires to set shoppingCartService"); Product product = null; try { product = productService.getBySku(source.getSku(), store, language); } catch (ServiceException e) { throw new ServiceRuntimeException(e); } if(product==null ) { throw new ResourceNotFoundException("No product found for sku [" + source.getSku() +"]"); } if(source.getAttributes()!=null) { for(com.salesmanager.shop.model.catalog.product.attribute.ProductAttribute attr : source.getAttributes()) { ProductAttribute attribute = productAttributeService.getById(attr.getId()); if(attribute==null) { throw new ConversionException("ProductAttribute with id " + attr.getId() + " is null"); } if(attribute.getProduct().getId().longValue()!=source.getProduct().getId().longValue()) { throw new ConversionException("ProductAttribute with id " + attr.getId() + " is not assigned to Product id " + source.getProduct().getId()); } product.getAttributes().add(attribute); } } try { return shoppingCartService.populateShoppingCartItem(product, store); } catch (ServiceException e) { throw new ConversionException(e); }
315
401
716
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.shoppingcart.ShoppingCartItem populate(com.salesmanager.shop.model.order.PersistableOrderProduct, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/transaction/PersistablePaymentPopulator.java
PersistablePaymentPopulator
populate
class PersistablePaymentPopulator extends AbstractDataPopulator<PersistablePayment, Payment> { PricingService pricingService; @Override public Payment populate(PersistablePayment source, Payment target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Payment createTarget() { // TODO Auto-generated method stub return null; } public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } }
Validate.notNull(source,"PersistablePayment cannot be null"); Validate.notNull(pricingService,"pricingService must be set"); if(target == null) { target = new Payment(); } try { target.setAmount(pricingService.getAmount(source.getAmount())); target.setModuleName(source.getPaymentModule()); target.setPaymentType(PaymentType.valueOf(source.getPaymentType())); target.setTransactionType(TransactionType.valueOf(source.getTransactionType())); Map<String,String> metadata = new HashMap<String,String>(); metadata.put("paymentToken", source.getPaymentToken()); target.setPaymentMetaData(metadata); return target; } catch(Exception e) { throw new ConversionException(e); }
176
241
417
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.payments.Payment populate(com.salesmanager.shop.model.order.transaction.PersistablePayment, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/transaction/PersistableTransactionPopulator.java
PersistableTransactionPopulator
populate
class PersistableTransactionPopulator extends AbstractDataPopulator<PersistableTransaction, Transaction> { private OrderService orderService; private PricingService pricingService; @Override public Transaction populate(PersistableTransaction source, Transaction target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected Transaction createTarget() { // TODO Auto-generated method stub return null; } public OrderService getOrderService() { return orderService; } public void setOrderService(OrderService orderService) { this.orderService = orderService; } public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } }
Validate.notNull(source,"PersistableTransaction must not be null"); Validate.notNull(orderService,"OrderService must not be null"); Validate.notNull(pricingService,"OrderService must not be null"); if(target == null) { target = new Transaction(); } try { target.setAmount(pricingService.getAmount(source.getAmount())); target.setDetails(source.getDetails()); target.setPaymentType(PaymentType.valueOf(source.getPaymentType())); target.setTransactionType(TransactionType.valueOf(source.getTransactionType())); target.setTransactionDate(DateUtil.getDate(source.getTransactionDate())); if(source.getOrderId()!=null && source.getOrderId().longValue() > 0) { Order order = orderService.getById(source.getOrderId()); /* if(source.getCustomerId() == null) { throw new ConversionException("Cannot add a transaction for an Order without specyfing the customer"); }*/ if(order == null) { throw new ConversionException("Order with id " + source.getOrderId() + "does not exist"); } target.setOrder(order); } return target; } catch(Exception e) { throw new ConversionException(e); }
220
378
598
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.payments.Transaction populate(com.salesmanager.shop.model.order.transaction.PersistableTransaction, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/order/transaction/ReadableTransactionPopulator.java
ReadableTransactionPopulator
populate
class ReadableTransactionPopulator extends AbstractDataPopulator<Transaction, ReadableTransaction> { private OrderService orderService; private PricingService pricingService; @Override public ReadableTransaction populate(Transaction source, ReadableTransaction target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableTransaction createTarget() { // TODO Auto-generated method stub return null; } public OrderService getOrderService() { return orderService; } public void setOrderService(OrderService orderService) { this.orderService = orderService; } public PricingService getPricingService() { return pricingService; } public void setPricingService(PricingService pricingService) { this.pricingService = pricingService; } }
Validate.notNull(source,"PersistableTransaction must not be null"); Validate.notNull(orderService,"OrderService must not be null"); Validate.notNull(pricingService,"OrderService must not be null"); if(target == null) { target = new ReadableTransaction(); } try { target.setAmount(pricingService.getDisplayAmount(source.getAmount(), store)); target.setDetails(source.getDetails()); target.setPaymentType(source.getPaymentType()); target.setTransactionType(source.getTransactionType()); target.setTransactionDate(DateUtil.formatDate(source.getTransactionDate())); target.setId(source.getId()); if(source.getOrder() != null) { target.setOrderId(source.getOrder().getId()); } return target; } catch(Exception e) { throw new ConversionException(e); }
219
276
495
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.order.transaction.ReadableTransaction populate(com.salesmanager.core.model.payments.Transaction, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/references/ReadableCountryPopulator.java
ReadableCountryPopulator
populate
class ReadableCountryPopulator extends AbstractDataPopulator<Country, ReadableCountry> { @Override public ReadableCountry populate(Country source, ReadableCountry target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableCountry createTarget() { // TODO Auto-generated method stub return null; } }
if(target==null) { target = new ReadableCountry(); } target.setId(new Long(source.getId())); target.setCode(source.getIsoCode()); target.setSupported(source.getSupported()); if(!CollectionUtils.isEmpty(source.getDescriptions())) { target.setName(source.getDescriptions().iterator().next().getName()); } if(!CollectionUtils.isEmpty(source.getZones())) { for(Zone z : source.getZones()) { ReadableZone readableZone = new ReadableZone(); readableZone.setCountryCode(target.getCode()); readableZone.setId(z.getId()); if(!CollectionUtils.isEmpty(z.getDescriptions())) { for(ZoneDescription d : z.getDescriptions()) { if(d.getLanguage().getId() == language.getId()) { readableZone.setName(d.getName()); continue; } } } target.getZones().add(readableZone); } } return target;
101
298
399
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.references.ReadableCountry populate(com.salesmanager.core.model.reference.country.Country, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/references/ReadableZonePopulator.java
ReadableZonePopulator
populate
class ReadableZonePopulator extends AbstractDataPopulator<Zone, ReadableZone> { @Override public ReadableZone populate(Zone source, ReadableZone target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableZone createTarget() { // TODO Auto-generated method stub return null; } }
if(target==null) { target = new ReadableZone(); } target.setId(source.getId()); target.setCode(source.getCode()); target.setCountryCode(source.getCountry().getIsoCode()); if(!CollectionUtils.isEmpty(source.getDescriptions())) { for(ZoneDescription d : source.getDescriptions()) { if(d.getLanguage().getId() == language.getId()) { target.setName(d.getName()); continue; } } } return target;
101
158
259
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.references.ReadableZone populate(com.salesmanager.core.model.reference.zone.Zone, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/shoppingCart/ShoppingCartDataPopulator.java
ShoppingCartDataPopulator
populate
class ShoppingCartDataPopulator extends AbstractDataPopulator<ShoppingCart,ShoppingCartData> { private static final Logger LOG = LoggerFactory.getLogger(ShoppingCartDataPopulator.class); private PricingService pricingService; private ShoppingCartCalculationService shoppingCartCalculationService; private ImageFilePath imageUtils; public ImageFilePath getimageUtils() { return imageUtils; } public void setimageUtils(ImageFilePath imageUtils) { this.imageUtils = imageUtils; } @Override public ShoppingCartData createTarget() { return new ShoppingCartData(); } public ShoppingCartCalculationService getOrderService() { return shoppingCartCalculationService; } public PricingService getPricingService() { return pricingService; } @Override public ShoppingCartData populate(final ShoppingCart shoppingCart, final ShoppingCartData cart, final MerchantStore store, final Language language) {<FILL_FUNCTION_BODY>}; public void setPricingService(final PricingService pricingService) { this.pricingService = pricingService; } public void setShoppingCartCalculationService(final ShoppingCartCalculationService shoppingCartCalculationService) { this.shoppingCartCalculationService = shoppingCartCalculationService; } }
Validate.notNull(shoppingCart, "Requires ShoppingCart"); Validate.notNull(language, "Requires Language not null"); int cartQuantity = 0; cart.setCode(shoppingCart.getShoppingCartCode()); Set<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> items = shoppingCart.getLineItems(); List<ShoppingCartItem> shoppingCartItemsList=Collections.emptyList(); try{ if(items!=null) { shoppingCartItemsList=new ArrayList<ShoppingCartItem>(); for(com.salesmanager.core.model.shoppingcart.ShoppingCartItem item : items) { ShoppingCartItem shoppingCartItem = new ShoppingCartItem(); shoppingCartItem.setCode(cart.getCode()); shoppingCartItem.setSku(item.getProduct().getSku()); shoppingCartItem.setProductVirtual(item.isProductVirtual()); shoppingCartItem.setId(item.getId()); String itemName = item.getProduct().getProductDescription().getName(); if(!CollectionUtils.isEmpty(item.getProduct().getDescriptions())) { for(ProductDescription productDescription : item.getProduct().getDescriptions()) { if(language != null && language.getId().intValue() == productDescription.getLanguage().getId().intValue()) { itemName = productDescription.getName(); break; } } } shoppingCartItem.setName(itemName); shoppingCartItem.setPrice(pricingService.getDisplayAmount(item.getItemPrice(),store)); shoppingCartItem.setQuantity(item.getQuantity()); cartQuantity = cartQuantity + item.getQuantity(); shoppingCartItem.setProductPrice(item.getItemPrice()); shoppingCartItem.setSubTotal(pricingService.getDisplayAmount(item.getSubTotal(), store)); ProductImage image = item.getProduct().getProductImage(); if(image!=null && imageUtils!=null) { String imagePath = imageUtils.buildProductImageUtils(store, item.getProduct().getSku(), image.getProductImage()); shoppingCartItem.setImage(imagePath); } Set<com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem> attributes = item.getAttributes(); if(attributes!=null) { List<ShoppingCartAttribute> cartAttributes = new ArrayList<ShoppingCartAttribute>(); for(com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem attribute : attributes) { ShoppingCartAttribute cartAttribute = new ShoppingCartAttribute(); cartAttribute.setId(attribute.getId()); cartAttribute.setAttributeId(attribute.getProductAttributeId()); cartAttribute.setOptionId(attribute.getProductAttribute().getProductOption().getId()); cartAttribute.setOptionValueId(attribute.getProductAttribute().getProductOptionValue().getId()); List<ProductOptionDescription> optionDescriptions = attribute.getProductAttribute().getProductOption().getDescriptionsSettoList(); List<ProductOptionValueDescription> optionValueDescriptions = attribute.getProductAttribute().getProductOptionValue().getDescriptionsSettoList(); if(!CollectionUtils.isEmpty(optionDescriptions) && !CollectionUtils.isEmpty(optionValueDescriptions)) { String optionName = optionDescriptions.get(0).getName(); String optionValue = optionValueDescriptions.get(0).getName(); for(ProductOptionDescription optionDescription : optionDescriptions) { if(optionDescription.getLanguage() != null && optionDescription.getLanguage().getId().intValue() == language.getId().intValue()) { optionName = optionDescription.getName(); break; } } for(ProductOptionValueDescription optionValueDescription : optionValueDescriptions) { if(optionValueDescription.getLanguage() != null && optionValueDescription.getLanguage().getId().intValue() == language.getId().intValue()) { optionValue = optionValueDescription.getName(); break; } } cartAttribute.setOptionName(optionName); cartAttribute.setOptionValue(optionValue); cartAttributes.add(cartAttribute); } } shoppingCartItem.setShoppingCartAttributes(cartAttributes); } shoppingCartItemsList.add(shoppingCartItem); } } if(CollectionUtils.isNotEmpty(shoppingCartItemsList)){ cart.setShoppingCartItems(shoppingCartItemsList); } if(shoppingCart.getOrderId() != null) { cart.setOrderId(shoppingCart.getOrderId()); } OrderSummary summary = new OrderSummary(); List<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> productsList = new ArrayList<com.salesmanager.core.model.shoppingcart.ShoppingCartItem>(); productsList.addAll(shoppingCart.getLineItems()); summary.setProducts(productsList.stream().filter(p -> p.getProduct().isAvailable()).collect(Collectors.toList())); OrderTotalSummary orderSummary = shoppingCartCalculationService.calculate(shoppingCart,store, language ); if(CollectionUtils.isNotEmpty(orderSummary.getTotals())) { List<OrderTotal> totals = new ArrayList<OrderTotal>(); for(com.salesmanager.core.model.order.OrderTotal t : orderSummary.getTotals()) { OrderTotal total = new OrderTotal(); total.setCode(t.getOrderTotalCode()); total.setText(t.getText()); total.setValue(t.getValue()); totals.add(total); } cart.setTotals(totals); } cart.setSubTotal(pricingService.getDisplayAmount(orderSummary.getSubTotal(), store)); cart.setTotal(pricingService.getDisplayAmount(orderSummary.getTotal(), store)); cart.setQuantity(cartQuantity); cart.setId(shoppingCart.getId()); } catch(ServiceException ex){ LOG.error( "Error while converting cart Model to cart Data.."+ex ); throw new ConversionException( "Unable to create cart data", ex ); } return cart;
386
1,614
2,000
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.shoppingcart.ShoppingCartData populate(com.salesmanager.core.model.shoppingcart.ShoppingCart, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/store/PersistableMerchantStorePopulator.java
PersistableMerchantStorePopulator
populate
class PersistableMerchantStorePopulator extends AbstractDataPopulator<PersistableMerchantStore, MerchantStore> { @Inject private CountryService countryService; @Inject private ZoneService zoneService; @Inject private LanguageService languageService; @Inject private CurrencyService currencyService; @Inject private MerchantStoreService merchantStoreService; @Override public MerchantStore populate(PersistableMerchantStore source, MerchantStore target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected MerchantStore createTarget() { // TODO Auto-generated method stub return null; } public ZoneService getZoneService() { return zoneService; } public void setZoneService(ZoneService zoneService) { this.zoneService = zoneService; } public CountryService getCountryService() { return countryService; } public void setCountryService(CountryService countryService) { this.countryService = countryService; } public LanguageService getLanguageService() { return languageService; } public void setLanguageService(LanguageService languageService) { this.languageService = languageService; } public CurrencyService getCurrencyService() { return currencyService; } public void setCurrencyService(CurrencyService currencyService) { this.currencyService = currencyService; } }
Validate.notNull(source, "PersistableMerchantStore mst not be null"); if(target == null) { target = new MerchantStore(); } target.setCode(source.getCode()); if(source.getId()!=0) { target.setId(source.getId()); } if(store.getStoreLogo()!=null) { target.setStoreLogo(store.getStoreLogo()); } if(!StringUtils.isEmpty(source.getInBusinessSince())) { try { Date dt = DateUtil.getDate(source.getInBusinessSince()); target.setInBusinessSince(dt); } catch(Exception e) { throw new ConversionException("Cannot parse date [" + source.getInBusinessSince() + "]",e); } } if(source.getDimension()!=null) { target.setSeizeunitcode(source.getDimension().name()); } if(source.getWeight()!=null) { target.setWeightunitcode(source.getWeight().name()); } target.setCurrencyFormatNational(source.isCurrencyFormatNational()); target.setStorename(source.getName()); target.setStorephone(source.getPhone()); target.setStoreEmailAddress(source.getEmail()); target.setUseCache(source.isUseCache()); target.setRetailer(source.isRetailer()); //get parent store if(!StringUtils.isBlank(source.getRetailerStore())) { if(source.getRetailerStore().equals(source.getCode())) { throw new ConversionException("Parent store [" + source.getRetailerStore() + "] cannot be parent of current store"); } try { MerchantStore parent = merchantStoreService.getByCode(source.getRetailerStore()); if(parent == null) { throw new ConversionException("Parent store [" + source.getRetailerStore() + "] does not exist"); } target.setParent(parent); } catch (ServiceException e) { throw new ConversionException(e); } } try { if(!StringUtils.isEmpty(source.getDefaultLanguage())) { Language l = languageService.getByCode(source.getDefaultLanguage()); target.setDefaultLanguage(l); } if(!StringUtils.isEmpty(source.getCurrency())) { Currency c = currencyService.getByCode(source.getCurrency()); target.setCurrency(c); } else { target.setCurrency(currencyService.getByCode(Constants.DEFAULT_CURRENCY.getCurrencyCode())); } List<String> languages = source.getSupportedLanguages(); if(!CollectionUtils.isEmpty(languages)) { for(String lang : languages) { Language ll = languageService.getByCode(lang); target.getLanguages().add(ll); } } } catch(Exception e) { throw new ConversionException(e); } //address population PersistableAddress address = source.getAddress(); if(address != null) { Country country; try { country = countryService.getByCode(address.getCountry()); Zone zone = zoneService.getByCode(address.getStateProvince()); if(zone != null) { target.setZone(zone); } else { target.setStorestateprovince(address.getStateProvince()); } target.setStoreaddress(address.getAddress()); target.setStorecity(address.getCity()); target.setCountry(country); target.setStorepostalcode(address.getPostalCode()); } catch (ServiceException e) { throw new ConversionException(e); } } if (StringUtils.isNotEmpty(source.getTemplate())) target.setStoreTemplate(source.getTemplate()); return target;
357
1,080
1,437
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.merchant.MerchantStore populate(com.salesmanager.shop.model.store.PersistableMerchantStore, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/store/ReadableMerchantStorePopulator.java
ReadableMerchantStorePopulator
populate
class ReadableMerchantStorePopulator extends AbstractDataPopulator<MerchantStore, ReadableMerchantStore> { protected final Log logger = LogFactory.getLog(getClass()); @Autowired private CountryService countryService; @Autowired private ZoneService zoneService; @Autowired @Qualifier("img") private ImageFilePath filePath; @Autowired private LanguageService languageService; @Override public ReadableMerchantStore populate(MerchantStore source, ReadableMerchantStore target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableMerchantStore createTarget() { // TODO Auto-generated method stub return null; } }
Validate.notNull(countryService,"Must use setter for countryService"); Validate.notNull(zoneService,"Must use setter for zoneService"); if(target == null) { target = new ReadableMerchantStore(); } target.setId(source.getId()); target.setCode(source.getCode()); if(source.getDefaultLanguage() != null) { target.setDefaultLanguage(source.getDefaultLanguage().getCode()); } target.setCurrency(source.getCurrency().getCode()); target.setPhone(source.getStorephone()); ReadableAddress address = new ReadableAddress(); address.setAddress(source.getStoreaddress()); address.setCity(source.getStorecity()); if(source.getCountry()!=null) { try { address.setCountry(source.getCountry().getIsoCode()); Country c =countryService.getCountriesMap(language).get(source.getCountry().getIsoCode()); if(c!=null) { address.setCountry(c.getIsoCode()); } } catch (ServiceException e) { logger.error("Cannot get Country", e); } } if(source.getParent() != null) { ReadableMerchantStore parent = populate(source.getParent(), new ReadableMerchantStore(), source, language); target.setParent(parent); } if(target.getParent() == null) { target.setRetailer(true); } else { target.setRetailer(source.isRetailer()!=null?source.isRetailer().booleanValue():false); } target.setDimension(MeasureUnit.valueOf(source.getSeizeunitcode())); target.setWeight(WeightUnit.valueOf(source.getWeightunitcode())); if(source.getZone()!=null) { address.setStateProvince(source.getZone().getCode()); try { Zone z = zoneService.getZones(language).get(source.getZone().getCode()); address.setStateProvince(z.getCode()); } catch (ServiceException e) { logger.error("Cannot get Zone", e); } } if(!StringUtils.isBlank(source.getStorestateprovince())) { address.setStateProvince(source.getStorestateprovince()); } if(!StringUtils.isBlank(source.getStoreLogo())) { ReadableImage image = new ReadableImage(); image.setName(source.getStoreLogo()); if(filePath!=null) { image.setPath(filePath.buildStoreLogoFilePath(source)); } target.setLogo(image); } address.setPostalCode(source.getStorepostalcode()); target.setAddress(address); target.setCurrencyFormatNational(source.isCurrencyFormatNational()); target.setEmail(source.getStoreEmailAddress()); target.setName(source.getStorename()); target.setId(source.getId()); target.setInBusinessSince(DateUtil.formatDate(source.getInBusinessSince())); target.setUseCache(source.isUseCache()); if(!CollectionUtils.isEmpty(source.getLanguages())) { List<ReadableLanguage> supported = new ArrayList<ReadableLanguage>(); for(Language lang : source.getLanguages()) { try { Language langObject = languageService.getLanguagesMap().get(lang.getCode()); if(langObject != null) { ReadableLanguage l = new ReadableLanguage(); l.setId(langObject.getId()); l.setCode(langObject.getCode()); supported.add(l); } } catch (ServiceException e) { logger.error("Cannot get Language [" + lang.getId() + "]"); } } target.setSupportedLanguages(supported); } if(source.getAuditSection()!=null) { ReadableAudit audit = new ReadableAudit(); if(source.getAuditSection().getDateCreated()!=null) { audit.setCreated(DateUtil.formatDate(source.getAuditSection().getDateCreated())); } if(source.getAuditSection().getDateModified()!=null) { audit.setModified(DateUtil.formatDate(source.getAuditSection().getDateCreated())); } audit.setUser(source.getAuditSection().getModifiedBy()); target.setReadableAudit(audit); } return target;
201
1,270
1,471
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.store.ReadableMerchantStore populate(com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/store/ReadableMerchantStorePopulatorWithDetails.java
ReadableMerchantStorePopulatorWithDetails
populate
class ReadableMerchantStorePopulatorWithDetails extends ReadableMerchantStorePopulator { protected final Log logger = LogFactory.getLog(getClass()); @Override public ReadableMerchantStore populate(MerchantStore source, ReadableMerchantStore target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableMerchantStore createTarget() { // TODO Auto-generated method stub return null; } }
target = super.populate(source, target, store, language); target.setTemplate(source.getStoreTemplate()); // TODO Add more as needed return target;
132
52
184
<methods>public non-sealed void <init>() ,public com.salesmanager.shop.model.store.ReadableMerchantStore populate(com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.shop.model.store.ReadableMerchantStore, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException<variables>private com.salesmanager.core.business.services.reference.country.CountryService countryService,private com.salesmanager.shop.utils.ImageFilePath filePath,private com.salesmanager.core.business.services.reference.language.LanguageService languageService,protected final org.apache.commons.logging.Log logger,private com.salesmanager.core.business.services.reference.zone.ZoneService zoneService
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/system/ReadableOptinPopulator.java
ReadableOptinPopulator
populate
class ReadableOptinPopulator extends AbstractDataPopulator<Optin, ReadableOptin> { @Override public ReadableOptin populate(Optin source, ReadableOptin target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableOptin createTarget() { // TODO Auto-generated method stub return null; } }
Validate.notNull(store,"MerchantStore cannot be null"); Validate.notNull(source,"Optin cannot be null"); if(target==null) { target = new ReadableOptin(); } target.setCode(source.getCode()); target.setDescription(source.getDescription()); target.setEndDate(source.getEndDate()); target.setId(source.getId()); target.setOptinType(source.getOptinType().name()); target.setStartDate(source.getStartDate()); target.setStore(store.getCode()); return target;
108
171
279
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.system.ReadableOptin populate(com.salesmanager.core.model.system.optin.Optin, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/user/PersistableUserPopulator.java
PersistableUserPopulator
populate
class PersistableUserPopulator extends AbstractDataPopulator<PersistableUser, User> { @Inject private LanguageService languageService; @Inject private GroupService groupService; @Inject private MerchantStoreService merchantStoreService; @Inject @Named("passwordEncoder") private PasswordEncoder passwordEncoder; @Override public User populate(PersistableUser source, User target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected User createTarget() { // TODO Auto-generated method stub return null; } }
Validate.notNull(source, "PersistableUser cannot be null"); Validate.notNull(store, "MerchantStore cannot be null"); if (target == null) { target = new User(); } target.setFirstName(source.getFirstName()); target.setLastName(source.getLastName()); target.setAdminEmail(source.getEmailAddress()); target.setAdminName(source.getUserName()); if(!StringUtils.isBlank(source.getPassword())) { target.setAdminPassword(passwordEncoder.encode(source.getPassword())); } if(!StringUtils.isBlank(source.getStore())) { try { MerchantStore userStore = merchantStoreService.getByCode(source.getStore()); target.setMerchantStore(userStore); } catch (ServiceException e) { throw new ConversionException("Error while reading MerchantStore store [" + source.getStore() + "]",e); } } else { target.setMerchantStore(store); } target.setActive(source.isActive()); Language lang = null; try { lang = languageService.getByCode(source.getDefaultLanguage()); } catch(Exception e) { throw new ConversionException("Cannot get language [" + source.getDefaultLanguage() + "]",e); } // set default language target.setDefaultLanguage(lang); List<Group> userGroups = new ArrayList<Group>(); List<String> names = new ArrayList<String>(); for (PersistableGroup group : source.getGroups()) { names.add(group.getName()); } try { List<Group> groups = groupService.listGroupByNames(names); for(Group g: groups) { userGroups.add(g); } } catch (Exception e1) { throw new ConversionException("Error while getting user groups",e1); } target.setGroups(userGroups); return target;
178
527
705
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.core.model.user.User populate(com.salesmanager.shop.model.user.PersistableUser, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/populator/user/ReadableUserPopulator.java
ReadableUserPopulator
populate
class ReadableUserPopulator extends AbstractDataPopulator<User, ReadableUser> { @Override public ReadableUser populate(User source, ReadableUser target, MerchantStore store, Language language) throws ConversionException {<FILL_FUNCTION_BODY>} @Override protected ReadableUser createTarget() { // TODO Auto-generated method stub return null; } }
Validate.notNull(source, "User cannot be null"); if (target == null) { target = new ReadableUser(); } target.setFirstName(source.getFirstName()); target.setLastName(source.getLastName()); target.setEmailAddress(source.getAdminEmail()); target.setUserName(source.getAdminName()); target.setActive(source.isActive()); if (source.getLastAccess() != null) { target.setLastAccess(DateUtil.formatLongDate(source.getLastAccess())); } // set default language target.setDefaultLanguage(Constants.DEFAULT_LANGUAGE); if (source.getDefaultLanguage() != null) target.setDefaultLanguage(source.getDefaultLanguage().getCode()); target.setMerchant(store.getCode()); target.setId(source.getId()); for (Group group : source.getGroups()) { ReadableGroup g = new ReadableGroup(); g.setName(group.getGroupName()); g.setId(group.getId().longValue()); target.getGroups().add(g); } /** * dates DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm a z"); * myObjectMapper.setDateFormat(df); */ return target;
104
351
455
<methods>public non-sealed void <init>() ,public java.util.Locale getLocale() ,public com.salesmanager.shop.model.user.ReadableUser populate(com.salesmanager.core.model.user.User, com.salesmanager.core.model.merchant.MerchantStore, com.salesmanager.core.model.reference.language.Language) throws com.salesmanager.core.business.exception.ConversionException,public void setLocale(java.util.Locale) <variables>private java.util.Locale locale
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/DefaultController.java
DefaultController
version
class DefaultController { @Autowired private Environment env; @GetMapping(value = "/") public @ResponseBody String version(Model model) {<FILL_FUNCTION_BODY>} }
return "{\"version\":\""+ env.getProperty("application-version") +"\", \"build\":\"" + env.getProperty("build.timestamp") + "\"}";
56
50
106
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/exception/FileUploadExceptionAdvice.java
FileUploadExceptionAdvice
handleFileException
class FileUploadExceptionAdvice { private static final Logger log = LoggerFactory.getLogger(FileUploadExceptionAdvice.class); @ExceptionHandler(MaxUploadSizeExceededException.class) @ResponseStatus(HttpStatus.PAYLOAD_TOO_LARGE) public @ResponseBody ErrorEntity handleFileException(Exception exception) {<FILL_FUNCTION_BODY>} }
log.error(exception.getMessage(), exception); ErrorEntity errorEntity = new ErrorEntity(); String resultMessage = exception.getLocalizedMessage() != null ? exception.getLocalizedMessage() : exception.getMessage(); Optional.ofNullable(resultMessage) .ifPresent(errorEntity::setMessage); return errorEntity;
103
84
187
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/exception/RestErrorHandler.java
RestErrorHandler
handleServiceException
class RestErrorHandler { private static final Logger log = LoggerFactory.getLogger(RestErrorHandler.class); @RequestMapping(produces = "application/json") @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public @ResponseBody ErrorEntity handleServiceException(Exception exception) {<FILL_FUNCTION_BODY>} /** * Generic exception serviceException handler */ @RequestMapping(produces = "application/json") @ExceptionHandler(ServiceRuntimeException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody ErrorEntity handleServiceException(ServiceRuntimeException exception) { log.error(exception.getErrorMessage(), exception); Throwable rootCause = exception.getCause(); while (rootCause.getCause() != null && rootCause.getCause() != rootCause) { rootCause = rootCause.getCause(); } ErrorEntity errorEntity = createErrorEntity(exception.getErrorCode()!=null?exception.getErrorCode():"500", exception.getErrorMessage(), rootCause.getMessage()); return errorEntity; } @RequestMapping(produces = "application/json") @ExceptionHandler(ConversionRuntimeException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody ErrorEntity handleServiceException(ConversionRuntimeException exception) { log.error(exception.getErrorMessage(), exception); ErrorEntity errorEntity = createErrorEntity(exception.getErrorCode(), exception.getErrorMessage(), exception.getLocalizedMessage()); return errorEntity; } @RequestMapping(produces = "application/json") @ExceptionHandler(ResourceNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) public @ResponseBody ErrorEntity handleServiceException(ResourceNotFoundException exception) { log.error(exception.getErrorMessage(), exception); ErrorEntity errorEntity = createErrorEntity(exception.getErrorCode(), exception.getErrorMessage(), exception.getLocalizedMessage()); return errorEntity; } @RequestMapping(produces = "application/json") @ExceptionHandler(UnauthorizedException.class) @ResponseStatus(HttpStatus.UNAUTHORIZED) public @ResponseBody ErrorEntity handleServiceException(UnauthorizedException exception) { log.error(exception.getErrorMessage(), exception); ErrorEntity errorEntity = createErrorEntity(exception.getErrorCode(), exception.getErrorMessage(), exception.getLocalizedMessage()); return errorEntity; } @RequestMapping(produces = "application/json") @ExceptionHandler(RestApiException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public @ResponseBody ErrorEntity handleRestApiException(RestApiException exception) { log.error(exception.getErrorMessage(), exception); ErrorEntity errorEntity = createErrorEntity(exception.getErrorCode(), exception.getErrorMessage(), exception.getLocalizedMessage()); return errorEntity; } private ErrorEntity createErrorEntity(String errorCode, String message, String detailMessage) { ErrorEntity errorEntity = new ErrorEntity(); Optional.ofNullable(errorCode) .ifPresent(errorEntity::setErrorCode); String resultMessage = (message != null && detailMessage !=null) ? new StringBuilder().append(message).append(", ").append(detailMessage).toString() : detailMessage; if(StringUtils.isBlank(resultMessage)) { resultMessage = message; } Optional.ofNullable(resultMessage) .ifPresent(errorEntity::setMessage); return errorEntity; } }
log.error(exception.getMessage(), exception); Objects.requireNonNull(exception.getCause()); Throwable rootCause = exception.getCause(); while (rootCause.getCause() != null && rootCause.getCause() != rootCause) { rootCause = rootCause.getCause(); } ErrorEntity errorEntity = createErrorEntity("500", exception.getMessage(), rootCause.getMessage()); return errorEntity;
1,019
138
1,157
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v0/store/StoreContactRESTController.java
StoreContactRESTController
contact
class StoreContactRESTController { @Inject private LanguageService languageService; @Inject private MerchantStoreService merchantStoreService; @Inject private EmailTemplatesUtils emailTemplatesUtils; private static final Logger LOGGER = LoggerFactory.getLogger(StoreContactRESTController.class); @RequestMapping( value="/public/{store}", method=RequestMethod.GET) @ResponseStatus(HttpStatus.ACCEPTED) @ResponseBody public AjaxResponse store(@PathVariable final String store, HttpServletRequest request, HttpServletResponse response) { AjaxResponse ajaxResponse = new AjaxResponse(); try { /** default routine **/ MerchantStore merchantStore = (MerchantStore)request.getAttribute(Constants.MERCHANT_STORE); if(merchantStore!=null) { if(!merchantStore.getCode().equals(store)) { merchantStore = null; } } if(merchantStore== null) { merchantStore = merchantStoreService.getByCode(store); } if(merchantStore==null) { LOGGER.error("Merchant store is null for code " + store); response.sendError(503, "Merchant store is null for code " + store); return null; } Language language = merchantStore.getDefaultLanguage(); Map<String,Language> langs = languageService.getLanguagesMap(); return null; } catch (Exception e) { LOGGER.error("Error while saving category",e); try { response.sendError(503, "Error while saving category " + e.getMessage()); } catch (Exception ignore) { } return null; } } @RequestMapping( value="/public/{store}/contact", method=RequestMethod.POST) @ResponseStatus(HttpStatus.ACCEPTED) @ResponseBody public AjaxResponse contact(@PathVariable final String store, @Valid @RequestBody ContactForm contact, HttpServletRequest request, HttpServletResponse response) {<FILL_FUNCTION_BODY>} }
AjaxResponse ajaxResponse = new AjaxResponse(); try { /** default routine **/ MerchantStore merchantStore = (MerchantStore)request.getAttribute(Constants.MERCHANT_STORE); if(merchantStore!=null) { if(!merchantStore.getCode().equals(store)) { merchantStore = null; } } if(merchantStore== null) { merchantStore = merchantStoreService.getByCode(store); } if(merchantStore==null) { LOGGER.error("Merchant store is null for code " + store); response.sendError(503, "Merchant store is null for code " + store); return null; } Language language = merchantStore.getDefaultLanguage(); Map<String,Language> langs = languageService.getLanguagesMap(); if(!StringUtils.isBlank(request.getParameter(Constants.LANG))) { String lang = request.getParameter(Constants.LANG); if(lang!=null) { language = langs.get(language); } } if(language==null) { language = merchantStore.getDefaultLanguage(); } Locale l = LocaleUtils.getLocale(language); /** end default routine **/ emailTemplatesUtils.sendContactEmail(contact, merchantStore, l, request.getContextPath()); ajaxResponse.setStatus(AjaxResponse.RESPONSE_STATUS_SUCCESS); return ajaxResponse; } catch (Exception e) { LOGGER.error("Error while saving category",e); try { response.sendError(503, "Error while saving category " + e.getMessage()); } catch (Exception ignore) { } return null; }
562
505
1,067
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v0/system/SystemRESTController.java
SystemRESTController
deleteOptin
class SystemRESTController { private static final Logger LOGGER = LoggerFactory.getLogger(SystemRESTController.class); @Inject private ModuleConfigurationService moduleConfigurationService; /** * Creates or updates a configuration module. A JSON has to be created on the client side which represents * an object that will create a new module (payment, shipping ...) which can be used and configured from * the administration tool. Here is an example of configuration accepted * * { "module": "PAYMENT", "code": "paypal-express-checkout", "type":"paypal", "version":"104.0", "regions": ["*"], "image":"icon-paypal.png", "configuration":[{"env":"TEST","scheme":"","host":"","port":"","uri":"","config1":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token="},{"env":"PROD","scheme":"","host":"","port":"","uri":"","config1":"https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token="}] } * * see : shopizer/sm-core/src/main/resources/reference/integrationmodules.json for more samples * @param json * @param request * @param response * @throws Exception */ @RequestMapping( value="/private/system/module", method=RequestMethod.POST, consumes = "text/plain;charset=UTF-8") @ResponseBody public AjaxResponse createOrUpdateModule(@RequestBody final String json, HttpServletRequest request, HttpServletResponse response) throws Exception { AjaxResponse resp = new AjaxResponse(); try { LOGGER.debug("Creating or updating an integration module : " + json); moduleConfigurationService.createOrUpdateModule(json); response.setStatus(200); resp.setStatus(200); } catch(Exception e) { resp.setStatus(500); resp.setErrorMessage(e); response.sendError(503, "Exception while creating or updating the module " + e.getMessage()); } return resp; } @RequestMapping( value="/private/system/optin", method=RequestMethod.POST) @ResponseBody public AjaxResponse createOptin(@RequestBody final String json, HttpServletRequest request, HttpServletResponse response) throws Exception { AjaxResponse resp = new AjaxResponse(); try { LOGGER.debug("Creating an optin : " + json); //moduleConfigurationService.createOrUpdateModule(json); response.setStatus(200); resp.setStatus(200); } catch(Exception e) { resp.setStatus(500); resp.setErrorMessage(e); response.sendError(503, "Exception while creating optin " + e.getMessage()); } return resp; } @RequestMapping( value="/private/system/optin/{code}", method=RequestMethod.DELETE) @ResponseBody public AjaxResponse deleteOptin(@RequestBody final String code, HttpServletRequest request, HttpServletResponse response) throws Exception {<FILL_FUNCTION_BODY>} @RequestMapping( value="/private/system/optin/{code}/customer", method=RequestMethod.POST, consumes = "application/json") @ResponseBody public AjaxResponse createOptinCustomer(@RequestBody final String code, HttpServletRequest request, HttpServletResponse response) throws Exception { AjaxResponse resp = new AjaxResponse(); try { LOGGER.debug("Adding a customer optin : " + code); //moduleConfigurationService.createOrUpdateModule(json); response.setStatus(200); resp.setStatus(200); } catch(Exception e) { resp.setStatus(500); resp.setErrorMessage(e); response.sendError(503, "Exception while creating uptin " + e.getMessage()); } return resp; } }
AjaxResponse resp = new AjaxResponse(); try { LOGGER.debug("Delete optin : " + code); //moduleConfigurationService.createOrUpdateModule(json); response.setStatus(200); resp.setStatus(200); } catch(Exception e) { resp.setStatus(500); resp.setErrorMessage(e); response.sendError(503, "Exception while deleting optin " + e.getMessage()); } return resp;
1,096
149
1,245
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/configurations/CacheApi.java
CacheApi
clearCache
class CacheApi { private static final Logger LOGGER = LoggerFactory.getLogger(CacheApi.class); @Inject private StoreFacade storeFacade; @Inject private CacheUtils cache; @DeleteMapping(value = "/auth/cache/store/{storeId}/clear") public @ResponseBody ResponseEntity<String> clearCache(@PathVariable("storeId") String storeCode, @RequestParam(name = "cacheKey", required = false) String cacheKey) {<FILL_FUNCTION_BODY>} }
try { MerchantStore merchantStore = storeFacade.get(storeCode); StringBuilder key = new StringBuilder().append(merchantStore.getId()).append("_").append(cacheKey); if (StringUtils.isNotEmpty(cacheKey)) { cache.removeFromCache(key.toString()); } else { cache.removeAllFromCache(merchantStore); } } catch (Exception e) { LOGGER.error("Error while clearning cache {}", e.getCause()); throw new ServiceRuntimeException("Error while clearing cache"); } return new ResponseEntity<>(HttpStatus.OK);
138
162
300
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/customer/AuthenticateCustomerApi.java
AuthenticateCustomerApi
authenticate
class AuthenticateCustomerApi { private static final Logger LOGGER = LoggerFactory.getLogger(AuthenticateCustomerApi.class); @Value("${authToken.header}") private String tokenHeader; @Inject private AuthenticationManager jwtCustomerAuthenticationManager; @Inject private JWTTokenUtil jwtTokenUtil; @Inject private UserDetailsService jwtCustomerDetailsService; @Inject private CustomerFacade customerFacade; @Inject private StoreFacade storeFacade; @Autowired AuthorizationUtils authorizationUtils; @Autowired private UserFacade userFacade; /** * Create new customer for a given MerchantStore, then authenticate that customer */ @RequestMapping( value={"/customer/register"}, method=RequestMethod.POST, produces ={ "application/json" }) @ResponseStatus(HttpStatus.CREATED) @ApiOperation(httpMethod = "POST", value = "Registers a customer to the application", notes = "Used as self-served operation",response = AuthenticationResponse.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") }) @ResponseBody public ResponseEntity<?> register( @Valid @RequestBody PersistableCustomer customer, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws Exception { customer.setUserName(customer.getEmailAddress()); if(customerFacade.checkIfUserExists(customer.getUserName(), merchantStore)) { //409 Conflict throw new GenericRuntimeException("409", "Customer with email [" + customer.getEmailAddress() + "] is already registered"); } Validate.notNull(customer.getUserName(),"Username cannot be null"); Validate.notNull(customer.getBilling(),"Requires customer Country code"); Validate.notNull(customer.getBilling().getCountry(),"Requires customer Country code"); customerFacade.registerCustomer(customer, merchantStore, language); // Perform the security Authentication authentication = null; try { authentication = jwtCustomerAuthenticationManager.authenticate( new UsernamePasswordAuthenticationToken( customer.getUserName(), customer.getPassword() ) ); } catch(Exception e) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } if(authentication == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } SecurityContextHolder.getContext().setAuthentication(authentication); // Reload password post-security so we can generate token final JWTUser userDetails = (JWTUser)jwtCustomerDetailsService.loadUserByUsername(customer.getUserName()); final String token = jwtTokenUtil.generateToken(userDetails); // Return the token return ResponseEntity.ok(new AuthenticationResponse(customer.getId(),token)); } /** * Authenticate a customer using username & password * @param authenticationRequest * @param device * @return * @throws AuthenticationException */ @RequestMapping(value = "/customer/login", method = RequestMethod.POST, produces ={ "application/json" }) @ApiOperation(httpMethod = "POST", value = "Authenticates a customer to the application", notes = "Customer can authenticate after registration, request is {\"username\":\"admin\",\"password\":\"password\"}",response = ResponseEntity.class) @ResponseBody public ResponseEntity<?> authenticate(@RequestBody @Valid AuthenticationRequest authenticationRequest) throws AuthenticationException {<FILL_FUNCTION_BODY>} @RequestMapping(value = "/auth/customer/refresh", method = RequestMethod.GET, produces ={ "application/json" }) public ResponseEntity<?> refreshToken(HttpServletRequest request) { String token = request.getHeader(tokenHeader); String username = jwtTokenUtil.getUsernameFromToken(token); JWTUser user = (JWTUser) jwtCustomerDetailsService.loadUserByUsername(username); if (jwtTokenUtil.canTokenBeRefreshed(token, user.getLastPasswordResetDate())) { String refreshedToken = jwtTokenUtil.refreshToken(token); return ResponseEntity.ok(new AuthenticationResponse(user.getId(),refreshedToken)); } else { return ResponseEntity.badRequest().body(null); } } @RequestMapping(value = "/auth/customer/password", method = RequestMethod.POST, produces ={ "application/json" }) @ApiOperation(httpMethod = "POST", value = "Sends a request to reset password", notes = "Password reset request is {\"username\":\"test@email.com\"}",response = ResponseEntity.class) public ResponseEntity<?> changePassword(@RequestBody @Valid PasswordRequest passwordRequest, HttpServletRequest request) { try { MerchantStore merchantStore = storeFacade.getByCode(request); Customer customer = customerFacade.getCustomerByUserName(passwordRequest.getUsername(), merchantStore); if(customer == null){ return ResponseEntity.notFound().build(); } //need to validate if password matches if(!customerFacade.passwordMatch(passwordRequest.getCurrent(), customer)) { throw new ResourceNotFoundException("Username or password does not match"); } if(!passwordRequest.getPassword().equals(passwordRequest.getRepeatPassword())) { throw new ResourceNotFoundException("Both passwords do not match"); } customerFacade.changePassword(customer, passwordRequest.getPassword()); return ResponseEntity.ok(Void.class); } catch(Exception e) { return ResponseEntity.badRequest().body("Exception when reseting password "+e.getMessage()); } } }
//TODO SET STORE in flow // Perform the security Authentication authentication = null; try { //to be used when username and password are set authentication = jwtCustomerAuthenticationManager.authenticate( new UsernamePasswordAuthenticationToken( authenticationRequest.getUsername(), authenticationRequest.getPassword() ) ); } catch(BadCredentialsException unn) { return new ResponseEntity<>("{\"message\":\"Bad credentials\"}",HttpStatus.UNAUTHORIZED); } catch(Exception e) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } if(authentication == null) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } SecurityContextHolder.getContext().setAuthentication(authentication); // Reload password post-security so we can generate token // todo create one for social final JWTUser userDetails = (JWTUser)jwtCustomerDetailsService.loadUserByUsername(authenticationRequest.getUsername()); final String token = jwtTokenUtil.generateToken(userDetails); // Return the token return ResponseEntity.ok(new AuthenticationResponse(userDetails.getId(),token));
1,545
325
1,870
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/customer/CustomerApi.java
CustomerApi
updateAuthUserAddress
class CustomerApi { private static final Logger LOGGER = LoggerFactory.getLogger(CustomerApi.class); @Inject private CustomerFacade customerFacade; @Autowired private UserFacade userFacade; /** Create new customer for a given MerchantStore */ @PostMapping("/private/customer") @ApiOperation(httpMethod = "POST", value = "Creates a customer", notes = "Requires administration access", produces = "application/json", response = ReadableCustomer.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public ReadableCustomer create(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @Valid @RequestBody PersistableCustomer customer) { return customerFacade.create(customer, merchantStore, language); } @PutMapping("/private/customer/{id}") @ApiOperation(httpMethod = "PUT", value = "Updates a customer", notes = "Requires administration access", produces = "application/json", response = PersistableCustomer.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public PersistableCustomer update(@PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @Valid @RequestBody PersistableCustomer customer) { customer.setId(id); return customerFacade.update(customer, merchantStore); } @PatchMapping("/private/customer/{id}/address") @ApiOperation(httpMethod = "PATCH", value = "Updates a customer", notes = "Requires administration access", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public void updateAddress(@PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @RequestBody PersistableCustomer customer) { customer.setId(id); customerFacade.updateAddress(customer, merchantStore); } @DeleteMapping("/private/customer/{id}") @ApiOperation(httpMethod = "DELETE", value = "Deletes a customer", notes = "Requires administration access") @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public void delete(@PathVariable Long id, @ApiIgnore MerchantStore merchantStore) { String authenticatedUser = userFacade.authenticatedUser(); if (authenticatedUser == null) { throw new UnauthorizedException(); } userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList())); customerFacade.deleteById(id); } /** * Get all customers * * @param start * @param count * @param request * @return * @throws Exception */ @GetMapping("/private/customers") @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") }) public ReadableCustomerList list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "count", required = false) Integer count, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { CustomerCriteria customerCriteria = createCustomerCriteria(page, count); return customerFacade.getListByStore(merchantStore, customerCriteria, language); } private CustomerCriteria createCustomerCriteria(Integer start, Integer count) { CustomerCriteria customerCriteria = new CustomerCriteria(); Optional.ofNullable(start).ifPresent(customerCriteria::setStartIndex); Optional.ofNullable(count).ifPresent(customerCriteria::setMaxCount); return customerCriteria; } @GetMapping("/private/customer/{id}") @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") }) public ReadableCustomer get(@PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return customerFacade.getCustomerById(id, merchantStore, language); } /** * Get logged in customer profile * * @param merchantStore * @param language * @param request * @return */ @GetMapping({ "/private/customer/profile", "/auth/customer/profile" }) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") }) public ReadableCustomer getAuthUser(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) { Principal principal = request.getUserPrincipal(); String userName = principal.getName(); return customerFacade.getCustomerByNick(userName, merchantStore, language); } @PatchMapping("/auth/customer/address") @ApiOperation(httpMethod = "PATCH", value = "Updates a loged in customer address", notes = "Requires authentication", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public void updateAuthUserAddress(@ApiIgnore MerchantStore merchantStore, @RequestBody PersistableCustomer customer, HttpServletRequest request) {<FILL_FUNCTION_BODY>} @PatchMapping("/auth/customer/") @ApiOperation(httpMethod = "PATCH", value = "Updates a loged in customer profile", notes = "Requires authentication", produces = "application/json", response = PersistableCustomer.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public PersistableCustomer update(@ApiIgnore MerchantStore merchantStore, @Valid @RequestBody PersistableCustomer customer, HttpServletRequest request) { Principal principal = request.getUserPrincipal(); String userName = principal.getName(); return customerFacade.update(userName, customer, merchantStore); } @DeleteMapping("/auth/customer/") @ApiOperation(httpMethod = "DELETE", value = "Deletes a loged in customer profile", notes = "Requires authentication", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public void delete(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) { Principal principal = request.getUserPrincipal(); String userName = principal.getName(); Customer customer; try { customer = customerFacade.getCustomerByUserName(userName, merchantStore); if(customer == null) { throw new ResourceNotFoundException("Customer [" + userName + "] not found"); } customerFacade.delete(customer); } catch (Exception e) { throw new ServiceRuntimeException("An error occured while deleting customer ["+userName+"]"); } } }
Principal principal = request.getUserPrincipal(); String userName = principal.getName(); customerFacade.updateAddress(userName, customer, merchantStore);
1,897
47
1,944
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/customer/ResetCustomerPasswordApi.java
ResetCustomerPasswordApi
passwordResetVerify
class ResetCustomerPasswordApi { private static final Logger LOGGER = LoggerFactory.getLogger(ResetCustomerPasswordApi.class); @Inject private com.salesmanager.shop.store.controller.customer.facade.v1.CustomerFacade customerFacade; /** * Request a reset password token * * @param merchantStore * @param language * @param user * @param request */ @ResponseStatus(HttpStatus.OK) @PostMapping(value = { "/customer/password/reset/request" }, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "POST", value = "Launch customer password reset flow", notes = "", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void passwordResetRequest(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @Valid @RequestBody ResetPasswordRequest customer) { customerFacade.requestPasswordReset(customer.getUsername(), customer.getReturnUrl(), merchantStore, language); } /** * Verify a password token * @param store * @param token * @param merchantStore * @param language * @param request */ @ResponseStatus(HttpStatus.OK) @GetMapping(value = { "/customer/{store}/reset/{token}" }, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "Validate customer password reset token", notes = "", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void passwordResetVerify( @PathVariable String store, @PathVariable String token, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {<FILL_FUNCTION_BODY>} /** * Change password * @param passwordRequest * @param store * @param token * @param merchantStore * @param language * @param request */ @RequestMapping(value = "/customer/{store}/password/{token}", method = RequestMethod.POST, produces = { "application/json" }) @ApiOperation(httpMethod = "POST", value = "Change customer password", response = Void.class) public void changePassword( @RequestBody @Valid PasswordRequest passwordRequest, @PathVariable String store, @PathVariable String token, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) { // validate password if (StringUtils.isBlank(passwordRequest.getPassword()) || StringUtils.isBlank(passwordRequest.getRepeatPassword())) { throw new RestApiException("400", "Password don't match"); } if (!passwordRequest.getPassword().equals(passwordRequest.getRepeatPassword())) { throw new RestApiException("400", "Password don't match"); } customerFacade.resetPassword(passwordRequest.getPassword(), token, store); } }
/** * Receives reset token Needs to validate if user found from token Needs * to validate if token has expired * * If no problem void is returned otherwise throw OperationNotAllowed * All of this in UserFacade */ customerFacade.verifyPasswordRequestToken(token, store);
834
87
921
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/marketplace/MarketPlaceApi.java
MarketPlaceApi
signup
class MarketPlaceApi { @Autowired private MarketPlaceFacade marketPlaceFacade; @Autowired private UserFacade userFacade; @Inject private StoreFacade storeFacade; @Inject private LanguageUtils languageUtils; /** * Get a marketplace from storeCode returns market place details and * merchant store */ @GetMapping("/private/marketplace/{store}") @ApiOperation(httpMethod = "GET", value = "Get market place meta-data", notes = "", produces = "application/json", response = ReadableMarketPlace.class) public ReadableMarketPlace marketPlace(@PathVariable String store, @RequestParam(value = "lang", required = false) String lang) { Language language = languageUtils.getServiceLanguage(lang); return marketPlaceFacade.get(store, language); } // signup new merchant @PostMapping("/store/signup") @ApiOperation(httpMethod = "POST", value = "Signup store", notes = "", produces = "application/json", response = Void.class) public void signup(@RequestBody SignupStore store, @ApiIgnore Language language) {<FILL_FUNCTION_BODY>} @ResponseStatus(HttpStatus.OK) @GetMapping(value = { "/store/{store}/signup/{token}" }, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "Validate store signup token", notes = "", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void storeSignupVerify(@PathVariable String store, @PathVariable String token, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { /** * Receives signup token. Needs to validate if a store * to validate if token has expired * * If no problem void is returned otherwise throw OperationNotAllowed */ //TBD } }
ReadableUser user = null; try { // check if user exists user = userFacade.findByUserName(store.getEmail()); } catch (ResourceNotFoundException ignore) {//that is what will happen if user does not exists } if (user != null) { throw new OperationNotAllowedException( "User [" + store.getEmail() + "] already exist and cannot be registered"); } // check if store exists if (storeFacade.existByCode(store.getCode())) { throw new OperationNotAllowedException( "Store [" + store.getCode() + "] already exist and cannot be registered"); } // create user // create store // send notification
529
197
726
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/order/OrderStatusHistoryApi.java
OrderStatusHistoryApi
list
class OrderStatusHistoryApi { @Inject private OrderFacade orderFacade; @Inject private AuthorizationUtils authorizationUtils; @RequestMapping(value = { "private/orders/{id}/history" }, method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ResponseBody public List<ReadableOrderStatusHistory> list(@PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {<FILL_FUNCTION_BODY>} @RequestMapping(value = { "private/orders/{id}/history" }, method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) @ApiOperation(httpMethod = "POST", value = "Add order history", notes = "Adds a new status to an order", produces = "application/json", response = Void.class) @ResponseBody public void create(@PathVariable final Long id, @RequestBody PersistableOrderStatusHistory history, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { String user = authorizationUtils.authenticatedUser(); authorizationUtils.authorizeUser(user, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_ORDER, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()), merchantStore); // TODO validate date format orderFacade.createOrderStatus(history, id, merchantStore); } }
String user = authorizationUtils.authenticatedUser(); authorizationUtils.authorizeUser(user, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_ORDER, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()), merchantStore); return orderFacade.getReadableOrderHistory(id, merchantStore, language);
366
110
476
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/order/OrderTotalApi.java
OrderTotalApi
calculateTotal
class OrderTotalApi { @Inject private ShoppingCartFacade shoppingCartFacade; @Inject private LabelUtils messages; @Inject private PricingService pricingService; @Inject private CustomerService customerService; @Inject private ShippingQuoteService shippingQuoteService; @Inject private OrderService orderService; private static final Logger LOGGER = LoggerFactory.getLogger(OrderTotalApi.class); /** * This service calculates order total for a given shopping cart This method takes in * consideration any applicable sales tax An optional request parameter accepts a quote id that * was received using shipping api * * @param quote * @param request * @param response * @return * @throws Exception */ @RequestMapping( value = {"/auth/cart/{id}/total"}, method = RequestMethod.GET) @ResponseBody @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ReadableOrderTotalSummary payment( @PathVariable final Long id, @RequestParam(value = "quote", required = false) Long quote, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) { try { Principal principal = request.getUserPrincipal(); String userName = principal.getName(); Customer customer = customerService.getByNick(userName); if (customer == null) { response.sendError(503, "Error while getting user details to calculate shipping quote"); } ShoppingCart shoppingCart = shoppingCartFacade.getShoppingCartModel(id, merchantStore); if (shoppingCart == null) { response.sendError(404, "Cart id " + id + " does not exist"); return null; } if (shoppingCart.getCustomerId() == null) { response.sendError( 404, "Cart id " + id + " does not exist for exist for user " + userName); return null; } if (shoppingCart.getCustomerId().longValue() != customer.getId().longValue()) { response.sendError( 404, "Cart id " + id + " does not exist for exist for user " + userName); return null; } ShippingSummary shippingSummary = null; // get shipping quote if asked for if (quote != null) { shippingSummary = shippingQuoteService.getShippingSummary(quote, merchantStore); } OrderTotalSummary orderTotalSummary = null; OrderSummary orderSummary = new OrderSummary(); orderSummary.setShippingSummary(shippingSummary); List<ShoppingCartItem> itemsSet = new ArrayList<ShoppingCartItem>(shoppingCart.getLineItems()); orderSummary.setProducts(itemsSet); orderTotalSummary = orderService.caculateOrderTotal(orderSummary, customer, merchantStore, language); ReadableOrderTotalSummary returnSummary = new ReadableOrderTotalSummary(); ReadableOrderSummaryPopulator populator = new ReadableOrderSummaryPopulator(); populator.setMessages(messages); populator.setPricingService(pricingService); populator.populate(orderTotalSummary, returnSummary, merchantStore, language); return returnSummary; } catch (Exception e) { LOGGER.error("Error while calculating order summary", e); try { response.sendError(503, "Error while calculating order summary " + e.getMessage()); } catch (Exception ignore) { } return null; } } /** * Public api * @param id * @param quote * @param merchantStore * @param language * @param response * @return */ @RequestMapping( value = {"/cart/{code}/total"}, method = RequestMethod.GET) @ResponseBody @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ReadableOrderTotalSummary calculateTotal( @PathVariable final String code, @RequestParam(value = "quote", required = false) Long quote, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language,//possible postal code, province and country HttpServletResponse response) {<FILL_FUNCTION_BODY>} }
try { ShoppingCart shoppingCart = shoppingCartFacade.getShoppingCartModel(code, merchantStore); if (shoppingCart == null) { response.sendError(404, "Cart code " + code + " does not exist"); return null; } ShippingSummary shippingSummary = null; // get shipping quote if asked for if (quote != null) { shippingSummary = shippingQuoteService.getShippingSummary(quote, merchantStore); } OrderTotalSummary orderTotalSummary = null; OrderSummary orderSummary = new OrderSummary(); orderSummary.setShippingSummary(shippingSummary); List<ShoppingCartItem> itemsSet = new ArrayList<ShoppingCartItem>(shoppingCart.getLineItems()); orderSummary.setProducts(itemsSet); orderTotalSummary = orderService.caculateOrderTotal(orderSummary, merchantStore, language); ReadableOrderTotalSummary returnSummary = new ReadableOrderTotalSummary(); ReadableOrderSummaryPopulator populator = new ReadableOrderSummaryPopulator(); populator.setMessages(messages); populator.setPricingService(pricingService); populator.populate(orderTotalSummary, returnSummary, merchantStore, language); return returnSummary; } catch (Exception e) { LOGGER.error("Error while calculating order summary", e); try { response.sendError(503, "Error while calculating order summary " + e.getMessage()); } catch (Exception ignore) { } return null; }
1,190
398
1,588
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/payment/PaymentApi.java
PaymentApi
configure
class PaymentApi { private static final Logger LOGGER = LoggerFactory.getLogger(PaymentApi.class); @Autowired private PaymentService paymentService; /** * Get available payment modules * * @param merchantStore * @param language * @return */ @GetMapping("/private/modules/payment") @ApiOperation(httpMethod = "GET", value = "List list of payment modules", notes = "Requires administration access", produces = "application/json", response = List.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public List<IntegrationModuleSummaryEntity> paymentModules( @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { try { List<IntegrationModule> modules = paymentService.getPaymentMethods(merchantStore); // configured modules Map<String, IntegrationConfiguration> configuredModules = paymentService .getPaymentModulesConfigured(merchantStore); return modules.stream().map(m -> integrationModule(m, configuredModules)).collect(Collectors.toList()); } catch (ServiceException e) { LOGGER.error("Error getting payment modules", e); throw new ServiceRuntimeException("Error getting payment modules", e); } } @PostMapping(value = "/private/modules/payment") public void configure( @RequestBody IntegrationModuleConfiguration configuration, @ApiIgnore MerchantStore merchantStore) {<FILL_FUNCTION_BODY>} /** * Get merchant payment module details * * @param code * @param merchantStore * @param language * @return */ @GetMapping("/private/modules/payment/{code}") @ApiOperation(httpMethod = "GET", value = "Payment module by code", produces = "application/json", response = List.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public IntegrationModuleConfiguration paymentModule(@PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { try { // get module IntegrationModule integrationModule = paymentService.getPaymentMethodByCode(merchantStore, code); if (integrationModule == null) { throw new ResourceNotFoundException("Payment module [" + code + "] not found"); } IntegrationModuleConfiguration returnConfig = new IntegrationModuleConfiguration(); returnConfig.setConfigurable(integrationModule.getConfigurable()); returnConfig.setActive(false); returnConfig.setDefaultSelected(false); returnConfig.setCode(code); // configured modules IntegrationConfiguration config = paymentService.getPaymentConfiguration(code, merchantStore); if(config == null) { return returnConfig; } /** * Build return object for now this is a read copy */ returnConfig.setActive(config.isActive()); returnConfig.setDefaultSelected(config.isDefaultSelected()); returnConfig.setCode(code); returnConfig.setIntegrationKeys(config.getIntegrationKeys()); returnConfig.setIntegrationOptions(config.getIntegrationOptions()); return returnConfig; } catch (ServiceException e) { LOGGER.error("Error getting payment module [" + code + "]", e); throw new ServiceRuntimeException("Error getting payment module [" + code + "]", e); } } private IntegrationModuleSummaryEntity integrationModule(IntegrationModule module, Map<String, IntegrationConfiguration> configuredModules) { IntegrationModuleSummaryEntity readable = null; readable = new IntegrationModuleSummaryEntity(); readable.setCode(module.getCode()); readable.setImage(module.getImage()); readable.setBinaryImage(module.getBinaryImage()); //readable.setRequiredKeys(module.getConfigurables()); readable.setConfigurable(module.getConfigurable()); if (configuredModules.containsKey(module.getCode())) { readable.setConfigured(true); if(configuredModules.get(module.getCode()).isActive()) { readable.setActive(true); } } return readable; } }
try { List<IntegrationModule> modules = paymentService.getPaymentMethods(merchantStore); Map<String, IntegrationModule> map = modules.stream() .collect(Collectors.toMap(IntegrationModule::getCode, module -> module)); IntegrationModule config = map.get(configuration.getCode()); if (config == null) { throw new ResourceNotFoundException("Payment module [" + configuration.getCode() + "] not found"); } Map<String, IntegrationConfiguration> configuredModules = paymentService .getPaymentModulesConfigured(merchantStore); IntegrationConfiguration integrationConfiguration = configuredModules.get(configuration.getCode()); if(integrationConfiguration == null) { integrationConfiguration = new IntegrationConfiguration(); integrationConfiguration.setModuleCode(configuration.getCode()); } integrationConfiguration.setActive(configuration.isActive()); integrationConfiguration.setDefaultSelected(configuration.isDefaultSelected()); integrationConfiguration.setIntegrationKeys(configuration.getIntegrationKeys()); integrationConfiguration.setIntegrationOptions(configuration.getIntegrationOptions()); paymentService.savePaymentModuleConfiguration(integrationConfiguration, merchantStore); } catch (ServiceException e) { LOGGER.error("Error getting payment modules", e); throw new ServiceRuntimeException("Error saving payment module", e); }
1,120
378
1,498
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductGroupApi.java
ProductGroupApi
addProductToGroup
class ProductGroupApi { @Inject private ProductService productService; @Inject private ProductItemsFacade productItemsFacade; private static final Logger LOGGER = LoggerFactory.getLogger(ProductGroupApi.class); @ResponseStatus(HttpStatus.OK) @PostMapping("/private/products/group") @ApiOperation(httpMethod = "POST", value = "Create product group", notes = "", response = ProductGroup.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody ProductGroup creteGroup( @RequestBody ProductGroup group, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception { return productItemsFacade.createProductGroup(group, merchantStore); } @ResponseStatus(HttpStatus.OK) @PatchMapping("/private/products/group/{code}") @ApiOperation(httpMethod = "PATCH", value = "Update product group visible flag", notes = "", response = ProductGroup.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void updateGroup( @RequestBody ProductGroup group, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception { productItemsFacade.updateProductGroup(code, group, merchantStore); } @GetMapping("/private/product/groups") @ApiOperation(httpMethod = "GET", value = "Get products groups for a given merchant", notes = "", response = List.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody java.util.List<ProductGroup> list( @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception { return productItemsFacade.listProductGroups(merchantStore, language); } /** * Query for a product group public/product/group/{code}?lang=fr|en no lang it will take session * lang or default store lang code can be any code used while creating product group, defeult * being FEATURED * * @param store * @param language * @param groupCode * @param request * @param response * @return * @throws Exception */ @ResponseStatus(HttpStatus.OK) @GetMapping("/products/group/{code}") @ApiOperation(httpMethod = "GET", value = "Get products by group code", notes = "", response = ReadableProductList.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody ReadableProductList getProductItemsByGroup( @PathVariable final String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception { try { ReadableProductList list = productItemsFacade.listItemsByGroup(code, merchantStore, language); if (list == null) { response.sendError(404, "Group not fount for code " + code); return null; } return list; } catch (Exception e) { LOGGER.error("Error while getting products", e); response.sendError(503, "An error occured while retrieving products " + e.getMessage()); } return null; } @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/private/products/{productId}/group/{code}", method = RequestMethod.POST) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody ReadableProductList addProductToGroup( @PathVariable Long productId, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {<FILL_FUNCTION_BODY>} @ResponseStatus(HttpStatus.OK) @RequestMapping( value = "/private/products/{productId}/group/{code}", method = RequestMethod.DELETE) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody ReadableProductList removeProductFromGroup( @PathVariable Long productId, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) { try { // get the product Product product = productService.getById(productId); if (product == null) { response.sendError(404, "Product not fount for id " + productId); return null; } ReadableProductList list = productItemsFacade.removeItemFromGroup(product, code, merchantStore, language); return list; } catch (Exception e) { LOGGER.error("Error while removing product from category", e); try { response.sendError(503, "Error while removing product from category " + e.getMessage()); } catch (Exception ignore) { } return null; } } @ResponseStatus(HttpStatus.OK) @DeleteMapping("/products/group/{code}") @ApiOperation(httpMethod = "DELETE", value = "Delete product group by group code", notes = "", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void deleteGroup( @PathVariable final String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) { productItemsFacade.deleteGroup(code, merchantStore); } }
Product product = null; try { // get the product product = productService.findOne(productId, merchantStore); if (product == null) { response.sendError(404, "Product not fount for id " + productId); return null; } } catch (Exception e) { LOGGER.error("Error while adding product to group", e); try { response.sendError(503, "Error while adding product to group " + e.getMessage()); } catch (Exception ignore) { } return null; } ReadableProductList list = productItemsFacade.addItemToGroup(product, code, merchantStore, language); return list;
1,764
196
1,960
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductInventoryApi.java
ProductInventoryApi
getByProductId
class ProductInventoryApi { @Autowired private ProductInventoryFacade productInventoryFacade; private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryApi.class); @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = { "/private/product/{productId}/inventory" }, method = RequestMethod.POST) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody ReadableInventory create(@PathVariable Long productId, @Valid @RequestBody PersistableInventory inventory, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { inventory.setProductId(productId); return productInventoryFacade.add(inventory, merchantStore, language); } @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/{productId}/inventory/{id}" }, method = RequestMethod.PUT) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void update( @PathVariable Long productId, @PathVariable Long id, @Valid @RequestBody PersistableInventory inventory, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { inventory.setId(id); inventory.setProductId(inventory.getProductId()); inventory.setVariant(inventory.getVariant()); inventory.setProductId(productId); productInventoryFacade.update(inventory, merchantStore, language); } @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/{productId}/inventory/{id}" }, method = RequestMethod.DELETE) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void delete( @PathVariable Long productId, @PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { productInventoryFacade.delete(productId, id, merchantStore); } @ResponseStatus(HttpStatus.OK) @GetMapping(value = { "/private/product/{sku}/inventory" }) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody ReadableEntityList<ReadableInventory> getBySku( @PathVariable String sku, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) { return productInventoryFacade.get(sku, merchantStore, language, page, count); } @ResponseStatus(HttpStatus.OK) @GetMapping(value = { "/private/product/inventory" }) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody ReadableEntityList<ReadableInventory> getByProductId( @RequestParam Long productId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) {<FILL_FUNCTION_BODY>} }
if(productId == null) { throw new RestApiException("Requires request parameter product id [/product/inventoty?productId"); } return productInventoryFacade.get(productId, merchantStore, language, page, count);
1,050
70
1,120
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductPriceApi.java
ProductPriceApi
save
class ProductPriceApi { @Autowired private ProductPriceFacade productPriceFacade;; private static final Logger LOGGER = LoggerFactory.getLogger(ProductApi.class); @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/{sku}/inventory/{inventoryId}/price"}, method = RequestMethod.POST) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody Entity save( @PathVariable String sku, @PathVariable Long inventoryId, @Valid @RequestBody PersistableProductPrice price, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { price.setSku(sku); price.setProductAvailabilityId(inventoryId); Long id = productPriceFacade.save(price, merchantStore); return new Entity(id); } @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = { "/private/product/{sku}/price"}, method = RequestMethod.POST) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody Entity save( @PathVariable String sku, @Valid @RequestBody PersistableProductPrice price, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {<FILL_FUNCTION_BODY>} @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/{sku}/inventory/{inventoryId}/price/{priceId}"}, method = RequestMethod.PUT) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void edit( @PathVariable String sku, @PathVariable Long inventoryId, @PathVariable Long priceId, @Valid @RequestBody PersistableProductPrice price, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { price.setSku(sku); price.setProductAvailabilityId(inventoryId); price.setId(priceId); productPriceFacade.save(price, merchantStore); } @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/{sku}/price/{priceId}"}, method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ReadableProductPrice get( @PathVariable String sku, @PathVariable Long priceId, @Valid @RequestBody PersistableProductPrice price, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { price.setSku(sku); price.setId(priceId); return productPriceFacade.get(sku, priceId, merchantStore, language); } @RequestMapping(value = { "/private/product/{sku}/inventory/{inventoryId}/price"}, method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public List<ReadableProductPrice> list( @PathVariable String sku, @PathVariable Long inventoryId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return productPriceFacade.list(sku, inventoryId, merchantStore, language); } @RequestMapping(value = { "/private/product/{sku}/prices"}, method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public List<ReadableProductPrice> list( @PathVariable String sku, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return productPriceFacade.list(sku, merchantStore, language); } @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/{sku}/price/{priceId}"}, method = RequestMethod.DELETE) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void delete( @PathVariable String sku, @PathVariable Long priceId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { productPriceFacade.delete(priceId, sku, merchantStore); } }
price.setSku(sku); Long id = productPriceFacade.save(price, merchantStore); return new Entity(id);
1,401
49
1,450
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductPropertySetApi.java
ProductPropertySetApi
list
class ProductPropertySetApi { @Autowired private ProductOptionSetFacade productOptionSetFacade; @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = { "/private/product/property/set" }, method = RequestMethod.POST) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void create( @Valid @RequestBody PersistableProductOptionSet optionSet, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { productOptionSetFacade.create(optionSet, merchantStore, language); } @ResponseStatus(HttpStatus.OK) @GetMapping(value = { "/private/product/property/set/unique" }, produces = MediaType.APPLICATION_JSON_VALUE) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") }) @ApiOperation(httpMethod = "GET", value = "Check if option set code already exists", notes = "", response = EntityExists.class) public ResponseEntity<EntityExists> exists( @RequestParam(value = "code") String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { boolean isOptionExist = productOptionSetFacade.exists(code, merchantStore); return new ResponseEntity<EntityExists>(new EntityExists(isOptionExist), HttpStatus.OK); } @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/property/set/{id}" }, method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) @ResponseBody public ReadableProductOptionSet get( @PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return productOptionSetFacade.get(id, merchantStore, language); } @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/property/set/{id}" }, method = RequestMethod.PUT) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void update( @Valid @RequestBody PersistableProductOptionSet option, @PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { option.setId(id); productOptionSetFacade.update(id, option, merchantStore, language); } @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/property/set/{id}" }, method = RequestMethod.DELETE) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void delete( @PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { productOptionSetFacade.delete(id, merchantStore); } /** * Get property set by store * filter by product type * @param merchantStore * @param language * @return */ @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/private/product/property/set" }, method = RequestMethod.GET) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public @ResponseBody List<ReadableProductOptionSet> list( @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "productType", required = false) String type) {<FILL_FUNCTION_BODY>} }
if(!StringUtils.isBlank(type)) { return productOptionSetFacade.list(merchantStore, language, type); } else { return productOptionSetFacade.list(merchantStore, language); }
1,108
66
1,174
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductRelationshipApi.java
ProductRelationshipApi
getAll
class ProductRelationshipApi { @Inject private ProductFacade productFacade; @Inject private StoreFacade storeFacade; @Inject private LanguageUtils languageUtils; @Inject private ProductService productService; @Inject private ProductReviewService productReviewService; private static final Logger LOGGER = LoggerFactory.getLogger(ProductRelationshipApi.class); /* @RequestMapping( value={"/private/products/{id}/related","/auth/products/{id}/related"}, method=RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) @ResponseBody public PersistableProductReview create(@PathVariable final Long id, @Valid @RequestBody PersistableProductReview review, HttpServletRequest request, HttpServletResponse response) throws Exception { try { MerchantStore merchantStore = storeFacade.getByCode(request); Language language = languageUtils.getRESTLanguage(request, merchantStore); //rating already exist ProductReview prodReview = productReviewService.getByProductAndCustomer(review.getProductId(), review.getCustomerId()); if(prodReview!=null) { response.sendError(500, "A review already exist for this customer and product"); return null; } //rating maximum 5 if(review.getRating()>Constants.MAX_REVIEW_RATING_SCORE) { response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE); return null; } review.setProductId(id); productFacade.saveOrUpdateReview(review, merchantStore, language); return review; } catch (Exception e) { LOGGER.error("Error while saving product review",e); try { response.sendError(503, "Error while saving product review" + e.getMessage()); } catch (Exception ignore) { } return null; } }*/ @RequestMapping(value = "/product/{id}/related", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ApiOperation( httpMethod = "GET", value = "Get product related items. This is used for doing cross-sell and up-sell functionality on a product details page", notes = "", produces = "application/json", response = List.class) @ResponseBody @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public List<ReadableProduct> getAll( @PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) throws Exception {<FILL_FUNCTION_BODY>} /* @RequestMapping( value={"/private/products/{id}/reviews/{reviewid}","/auth/products/{id}/reviews/{reviewid}"}, method=RequestMethod.PUT) @ResponseStatus(HttpStatus.OK) @ResponseBody public PersistableProductReview update(@PathVariable final Long id, @PathVariable final Long reviewId, @Valid @RequestBody PersistableProductReview review, HttpServletRequest request, HttpServletResponse response) throws Exception { try { MerchantStore merchantStore = storeFacade.getByCode(request); Language language = languageUtils.getRESTLanguage(request, merchantStore); ProductReview prodReview = productReviewService.getById(reviewId); if(prodReview==null) { response.sendError(404, "Product review with id " + reviewId + " does not exist"); return null; } if(prodReview.getCustomer().getId().longValue() != review.getCustomerId().longValue()) { response.sendError(404, "Product review with id " + reviewId + " does not exist"); return null; } //rating maximum 5 if(review.getRating()>Constants.MAX_REVIEW_RATING_SCORE) { response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE); return null; } review.setProductId(id); productFacade.saveOrUpdateReview(review, merchantStore, language); return review; } catch (Exception e) { LOGGER.error("Error while saving product review",e); try { response.sendError(503, "Error while saving product review" + e.getMessage()); } catch (Exception ignore) { } return null; } } @RequestMapping( value={"/private/products/{id}/reviews/{reviewid}","/auth/products/{id}/reviews/{reviewid}"}, method=RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) @ResponseBody public void delete(@PathVariable final Long id, @PathVariable final Long reviewId, HttpServletRequest request, HttpServletResponse response) throws Exception { try { MerchantStore merchantStore = storeFacade.getByCode(request); Language language = languageUtils.getRESTLanguage(request, merchantStore); ProductReview prodReview = productReviewService.getById(reviewId); if(prodReview==null) { response.sendError(404, "Product review with id " + reviewId + " does not exist"); return; } if(prodReview.getProduct().getId().longValue() != id.longValue()) { response.sendError(404, "Product review with id " + reviewId + " does not exist"); return; } productFacade.deleteReview(prodReview, merchantStore, language); } catch (Exception e) { LOGGER.error("Error while deleting product review",e); try { response.sendError(503, "Error while deleting product review" + e.getMessage()); } catch (Exception ignore) { } return; } }*/ }
try { // product exist Product product = productService.getById(id); if (product == null) { response.sendError(404, "Product id " + id + " does not exists"); return null; } List<ReadableProduct> relatedItems = productFacade.relatedItems(merchantStore, product, language); return relatedItems; } catch (Exception e) { LOGGER.error("Error while getting product reviews", e); try { response.sendError(503, "Error while getting product reviews" + e.getMessage()); } catch (Exception ignore) { } return null; }
1,669
176
1,845
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductReviewApi.java
ProductReviewApi
delete
class ProductReviewApi { @Inject private ProductCommonFacade productCommonFacade; @Inject private ProductService productService; @Inject private ProductReviewService productReviewService; private static final Logger LOGGER = LoggerFactory.getLogger(ProductReviewApi.class); @RequestMapping( value = { "/private/products/{id}/reviews", "/auth/products/{id}/reviews", "/auth/products/{id}/reviews", "/auth/products/{id}/reviews" }, method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) @ResponseBody @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public PersistableProductReview create( @PathVariable final Long id, @Valid @RequestBody PersistableProductReview review, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) { try { // rating already exist ProductReview prodReview = productReviewService.getByProductAndCustomer( review.getProductId(), review.getCustomerId()); if (prodReview != null) { response.sendError(500, "A review already exist for this customer and product"); return null; } // rating maximum 5 if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) { response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE); return null; } review.setProductId(id); productCommonFacade.saveOrUpdateReview(review, merchantStore, language); return review; } catch (Exception e) { LOGGER.error("Error while saving product review", e); try { response.sendError(503, "Error while saving product review" + e.getMessage()); } catch (Exception ignore) { } return null; } } @RequestMapping(value = "/product/{id}/reviews", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ResponseBody @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public List<ReadableProductReview> getAll( @PathVariable final Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) { try { // product exist Product product = productService.getById(id); if (product == null) { response.sendError(404, "Product id " + id + " does not exists"); return null; } List<ReadableProductReview> reviews = productCommonFacade.getProductReviews(product, merchantStore, language); return reviews; } catch (Exception e) { LOGGER.error("Error while getting product reviews", e); try { response.sendError(503, "Error while getting product reviews" + e.getMessage()); } catch (Exception ignore) { } return null; } } @RequestMapping( value = { "/private/products/{id}/reviews/{reviewid}", "/auth/products/{id}/reviews/{reviewid}" }, method = RequestMethod.PUT) @ResponseStatus(HttpStatus.OK) @ResponseBody @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public PersistableProductReview update( @PathVariable final Long id, @PathVariable final Long reviewId, @Valid @RequestBody PersistableProductReview review, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) { try { ProductReview prodReview = productReviewService.getById(reviewId); if (prodReview == null) { response.sendError(404, "Product review with id " + reviewId + " does not exist"); return null; } if (prodReview.getCustomer().getId().longValue() != review.getCustomerId().longValue()) { response.sendError(404, "Product review with id " + reviewId + " does not exist"); return null; } // rating maximum 5 if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) { response.sendError(503, "Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE); return null; } review.setProductId(id); productCommonFacade.saveOrUpdateReview(review, merchantStore, language); return review; } catch (Exception e) { LOGGER.error("Error while saving product review", e); try { response.sendError(503, "Error while saving product review" + e.getMessage()); } catch (Exception ignore) { } return null; } } @RequestMapping( value = { "/private/products/{id}/reviews/{reviewid}", "/auth/products/{id}/reviews/{reviewid}" }, method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) @ResponseBody @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void delete( @PathVariable final Long id, @PathVariable final Long reviewId, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletResponse response) {<FILL_FUNCTION_BODY>} }
try { ProductReview prodReview = productReviewService.getById(reviewId); if (prodReview == null) { response.sendError(404, "Product review with id " + reviewId + " does not exist"); return; } if (prodReview.getProduct().getId().longValue() != id.longValue()) { response.sendError(404, "Product review with id " + reviewId + " does not exist"); return; } productCommonFacade.deleteReview(prodReview, merchantStore, language); } catch (Exception e) { LOGGER.error("Error while deleting product review", e); try { response.sendError(503, "Error while deleting product review" + e.getMessage()); } catch (Exception ignore) { } return; }
1,627
216
1,843
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductTypeApi.java
ProductTypeApi
create
class ProductTypeApi { @Inject private ProductTypeFacade productTypeFacade; private static final Logger LOGGER = LoggerFactory.getLogger(ProductTypeApi.class); @GetMapping(value = "/private/product/types", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "Get product types list", notes = "", produces = "application/json", response = List.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ReadableProductTypeList list(@RequestParam(name = "count", defaultValue = "10") int count, @RequestParam(name = "page", defaultValue = "0") int page, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return productTypeFacade.getByMerchant(merchantStore, language, count, page); } @GetMapping(value = "/private/product/type/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "Get product type", notes = "", produces = "application/json", response = ReadableProductType.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ReadableProductType get(@PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return productTypeFacade.get(merchantStore, id, language); } @GetMapping(value = "/private/product/type/unique", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "Verify if product type is unique", notes = "", produces = "application/json", response = ResponseEntity.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ResponseEntity<EntityExists> exists(@RequestParam String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { boolean exists = productTypeFacade.exists(code, merchantStore, language); return new ResponseEntity<EntityExists>(new EntityExists(exists), HttpStatus.OK); } @PostMapping(value = "/private/product/type", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "POST", value = "Create product type", notes = "", produces = "application/json", response = Entity.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public Entity create(@RequestBody PersistableProductType type, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {<FILL_FUNCTION_BODY>} @PutMapping(value = "/private/product/type/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "PUT", value = "Update product type", notes = "", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void update(@RequestBody PersistableProductType type, @PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { productTypeFacade.update(type, id, merchantStore, language); } @DeleteMapping(value = "/private/product/type/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "DELETE", value = "Delete product type", notes = "", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void delete(@PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { productTypeFacade.delete(id, merchantStore, language); } }
Long id = productTypeFacade.save(type, merchantStore, language); Entity entity = new Entity(); entity.setId(id); return entity;
1,157
50
1,207
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/references/ReferencesApi.java
ReferencesApi
measures
class ReferencesApi { private static final Logger LOGGER = LoggerFactory.getLogger(ReferencesApi.class); @Inject private StoreFacade storeFacade; @Inject private LanguageUtils languageUtils; @Inject private LanguageFacade languageFacade; @Inject private CountryFacade countryFacade; @Inject private ZoneFacade zoneFacade; @Inject private CurrencyFacade currencyFacade; /** * Search languages by language code private/languages returns everything * * @return */ @GetMapping("/languages") public List<Language> getLanguages() { return languageFacade.getLanguages(); } /** * Returns a country with zones (provinces, states) supports language set in parameter * ?lang=en|fr|ru... * * @param request * @return */ @GetMapping("/country") public List<ReadableCountry> getCountry(@ApiIgnore Language language, HttpServletRequest request) { MerchantStore merchantStore = storeFacade.getByCode(request); return countryFacade.getListCountryZones(language, merchantStore); } @GetMapping("/zones") public List<ReadableZone> getZones( @RequestParam("code") String code, @ApiIgnore Language language, HttpServletRequest request) { MerchantStore merchantStore = storeFacade.getByCode(request); return zoneFacade.getZones(code, language, merchantStore); } /** * Currency * * @return */ @GetMapping("/currency") public List<Currency> getCurrency() { return currencyFacade.getList(); } @GetMapping("/measures") public SizeReferences measures() {<FILL_FUNCTION_BODY>} }
SizeReferences sizeReferences = new SizeReferences(); sizeReferences.setMeasures(Arrays.asList(MeasureUnit.values())); sizeReferences.setWeights(Arrays.asList(WeightUnit.values())); return sizeReferences;
472
66
538
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/security/SecurityApi.java
SecurityApi
listPermissions
class SecurityApi { private static final Logger LOGGER = LoggerFactory.getLogger(SecurityApi.class); @Inject private PermissionService permissionService; @Inject private GroupService groupService; @ResponseStatus(HttpStatus.OK) @GetMapping({ "/private/{group}/permissions" }) @ApiOperation(httpMethod = "GET", value = "Get permissions by group", notes = "", produces = MediaType.APPLICATION_JSON_VALUE, response = List.class) public List<ReadablePermission> listPermissions(@PathVariable String group) {<FILL_FUNCTION_BODY>} /** * Permissions Requires service user authentication * * @return */ @GetMapping("/private/permissions") public List<ReadablePermission> permissions() { List<Permission> permissions = permissionService.list(); List<ReadablePermission> readablePermissions = new ArrayList<ReadablePermission>(); for (Permission permission : permissions) { ReadablePermission readablePermission = new ReadablePermission(); readablePermission.setName(permission.getPermissionName()); readablePermission.setId(permission.getId()); readablePermissions.add(readablePermission); } return readablePermissions; } /** * Load groups Requires service user authentication * * @return */ @GetMapping("/private/groups") public List<ReadableGroup> groups() { List<Group> groups = groupService.list(); List<ReadableGroup> readableGroups = new ArrayList<ReadableGroup>(); for (Group group : groups) { ReadableGroup readableGroup = new ReadableGroup(); readableGroup.setName(group.getGroupName()); readableGroup.setId(group.getId().longValue()); readableGroup.setType(group.getGroupType().name()); readableGroups.add(readableGroup); } return readableGroups; } }
Group g = null; try { g = groupService.findByName(group); if(g == null) { throw new ResourceNotFoundException("Group [" + group + "] does not exist"); } } catch (Exception e) { LOGGER.error("An error occured while getting group [" + group + "]",e); throw new ServiceRuntimeException("An error occured while getting group [" + group + "]"); } Set<Permission> permissions = g.getPermissions(); List<ReadablePermission> readablePermissions = new ArrayList<ReadablePermission>(); for (Permission permission : permissions) { ReadablePermission readablePermission = new ReadablePermission(); readablePermission.setName(permission.getPermissionName()); readablePermission.setId(permission.getId()); readablePermissions.add(readablePermission); } return readablePermissions;
495
242
737
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/shipping/ShippingExpeditionApi.java
ShippingExpeditionApi
saveExpedition
class ShippingExpeditionApi { private static final Logger LOGGER = LoggerFactory.getLogger(ShippingExpeditionApi.class); @Autowired private AuthorizationUtils authorizationUtils; @Autowired private ShippingFacade shippingFacade; @RequestMapping(value = { "/private/shipping/expedition" }, method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) @ResponseBody public ExpeditionConfiguration expedition( @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { String user = authorizationUtils.authenticatedUser(); authorizationUtils.authorizeUser(user, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_SHIPPING, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()), merchantStore); return shippingFacade.getExpeditionConfiguration(merchantStore, language); } @GetMapping("/shipping/country") public List<ReadableCountry> getCountry( @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return shippingFacade.shipToCountry(merchantStore, language); } @RequestMapping(value = { "/private/shipping/expedition" }, method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) @ResponseBody public void saveExpedition( @RequestBody ExpeditionConfiguration expedition, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {<FILL_FUNCTION_BODY>} }
String user = authorizationUtils.authenticatedUser(); authorizationUtils.authorizeUser(user, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_SHIPPING, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()), merchantStore); shippingFacade.saveExpeditionConfiguration(expedition, merchantStore);
411
112
523
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/system/ContactApi.java
ContactApi
contact
class ContactApi { @Inject private LanguageService languageService; @Inject private EmailTemplatesUtils emailTemplatesUtils; @PostMapping("/contact") @ApiOperation( httpMethod = "POST", value = "Sends an email contact us to store owner", notes = "", produces = "application/json") @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ResponseEntity<Void> contact( @Valid @RequestBody ContactForm contact, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) {<FILL_FUNCTION_BODY>} }
Locale locale = languageService.toLocale(language, merchantStore); emailTemplatesUtils.sendContactEmail(contact, merchantStore, locale, request.getContextPath()); return new ResponseEntity<Void>(HttpStatus.OK);
210
61
271
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/system/OptinApi.java
OptinApi
create
class OptinApi { private static final Logger LOGGER = LoggerFactory.getLogger(OptinApi.class); @Inject private OptinFacade optinFacade; /** Create new optin */ @PostMapping("/private/optin") @ApiOperation( httpMethod = "POST", value = "Creates an optin event type definition", notes = "", produces = "application/json") @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ReadableOptin create( @Valid @RequestBody PersistableOptin optin, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) {<FILL_FUNCTION_BODY>} }
LOGGER.debug("[" + request.getUserPrincipal().getName() + "] creating optin [" + optin.getCode() + "]"); return optinFacade.create(optin, merchantStore, language);
236
57
293
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/system/SearchToolsApi.java
SearchToolsApi
contact
class SearchToolsApi { private static final Logger LOGGER = LoggerFactory.getLogger(SearchToolsApi.class); @Inject private SearchFacade searchFacade; @Inject private UserFacade userFacade; @PostMapping("/private/system/search/index") @ApiOperation(httpMethod = "POST", value = "Indexes all products", notes = "", produces = "application/json") @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ResponseEntity<Void> contact(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request) {<FILL_FUNCTION_BODY>} }
// superadmin, admin and admin_catalogue String authenticatedUser = userFacade.authenticatedUser(); if (authenticatedUser == null) { throw new UnauthorizedException(); } Principal principal = request.getUserPrincipal(); String userName = principal.getName(); ReadableUser user = userFacade.findByUserName(userName, null, language); if(user== null) { throw new UnauthorizedException(); } userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_CATALOGUE, Constants.GROUP_ADMIN_RETAIL) .collect(Collectors.toList())); if(!user.getMerchant().equals(merchantStore.getCode())) { throw new UnauthorizedException(); } try { searchFacade.indexAllData(merchantStore); } catch (Exception e) { throw new RestApiException("Exception while indexing store data", e); } return new ResponseEntity<Void>(HttpStatus.CREATED);
201
311
512
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/tax/TaxClassApi.java
TaxClassApi
exists
class TaxClassApi { private static final Logger LOGGER = LoggerFactory.getLogger(TaxClassApi.class); @Autowired private TaxFacade taxFacade; /** Create new tax class for a given MerchantStore */ @PostMapping("/private/tax/class") @ApiOperation(httpMethod = "POST", value = "Creates a taxClass", notes = "Requires administration access", produces = "application/json", response = Entity.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public Entity create(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @Valid @RequestBody PersistableTaxClass taxClass) { return taxFacade.createTaxClass(taxClass, merchantStore, language); } @GetMapping(value = "/private/tax/class/unique", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "Verify if taxClass is unique", notes = "", produces = "application/json", response = ResponseEntity.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ResponseEntity<EntityExists> exists(@RequestParam String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {<FILL_FUNCTION_BODY>} /** Update tax class for a given MerchantStore */ @PutMapping("/private/tax/class/{id}") @ApiOperation(httpMethod = "PUT", value = "Updates a taxClass", notes = "Requires administration access", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public void update(@ApiIgnore MerchantStore merchantStore, @PathVariable Long id, @ApiIgnore Language language, @Valid @RequestBody PersistableTaxClass taxClass) { taxClass.setId(id); taxFacade.updateTaxClass(id, taxClass, merchantStore, language); } @GetMapping(value = "/private/tax/class", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "List taxClasses by store", notes = "", produces = "application/json", response = ReadableEntityList.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ReadableEntityList<ReadableTaxClass> list(@RequestParam(name = "count", defaultValue = "10") int count, @RequestParam(name = "page", defaultValue = "0") int page, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return taxFacade.taxClasses(merchantStore, language); } @GetMapping("/private/tax/class/{code}") @ApiOperation(httpMethod = "GET", value = "Get a taxClass by code", notes = "Requires administration access", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public ReadableTaxClass get(@ApiIgnore MerchantStore merchantStore, @PathVariable String code, @ApiIgnore Language language) { return taxFacade.taxClass(code, merchantStore, language); } @DeleteMapping(value = "/private/tax/class/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "DELETE", value = "Delete tax class", notes = "", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void delete(@PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { taxFacade.deleteTaxClass(id, merchantStore, language); } }
boolean exists = taxFacade.existsTaxClass(code, merchantStore, language); return new ResponseEntity<EntityExists>(new EntityExists(exists), HttpStatus.OK);
1,074
49
1,123
<no_super_class>
shopizer-ecommerce_shopizer
shopizer/sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/tax/TaxRatesApi.java
TaxRatesApi
exists
class TaxRatesApi { private static final Logger LOGGER = LoggerFactory.getLogger(TaxRatesApi.class); @Autowired private TaxFacade taxFacade; /** Create new tax rate for a given MerchantStore */ @PostMapping("/private/tax/rate") @ApiOperation(httpMethod = "POST", value = "Creates a taxRate", notes = "Requires administration access", produces = "application/json", response = Entity.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public Entity create(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @Valid @RequestBody PersistableTaxRate taxRate) { return taxFacade.createTaxRate(taxRate, merchantStore, language); } @GetMapping(value = "/private/tax/rate/unique", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "Verify if taxRate is unique", notes = "", produces = "application/json", response = ResponseEntity.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ResponseEntity<EntityExists> exists(@RequestParam String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {<FILL_FUNCTION_BODY>} /** Update tax rate for a given MerchantStore */ @PutMapping("/private/tax/rate/{id}") @ApiOperation(httpMethod = "PUT", value = "Updates a taxRate", notes = "Requires administration access", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public void update(@ApiIgnore MerchantStore merchantStore, @PathVariable Long id, @ApiIgnore Language language, @Valid @RequestBody PersistableTaxRate taxRate) { taxRate.setId(id); taxFacade.updateTaxRate(id, taxRate, merchantStore, language); } @GetMapping(value = "/private/tax/rates", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "GET", value = "List taxRates by store", notes = "", produces = "application/json", response = ReadableEntityList.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public ReadableEntityList<ReadableTaxRate> list(@RequestParam(name = "count", defaultValue = "10") int count, @RequestParam(name = "page", defaultValue = "0") int page, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { return taxFacade.taxRates(merchantStore, language); } @GetMapping("/private/tax/rate/{id}") @ApiOperation(httpMethod = "GET", value = "Get a taxRate by code", notes = "Requires administration access", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") }) public ReadableTaxRate get(@ApiIgnore MerchantStore merchantStore, @PathVariable Long id, @ApiIgnore Language language) { return taxFacade.taxRate(id, merchantStore, language); } @DeleteMapping(value = "/private/tax/rate/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(httpMethod = "DELETE", value = "Delete tax rate", notes = "", produces = "application/json", response = Void.class) @ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") }) public void delete(@PathVariable Long id, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) { taxFacade.deleteTaxRate(id, merchantStore, language); } }
boolean exists = taxFacade.existsTaxRate(code, merchantStore, language); return new ResponseEntity<EntityExists>(new EntityExists(exists), HttpStatus.OK);
1,078
49
1,127
<no_super_class>