Skip to content

Commit f4bc49e

Browse files
ProductGroups
1 parent 806aa80 commit f4bc49e

File tree

16 files changed

+186
-52
lines changed

16 files changed

+186
-52
lines changed
0 Bytes
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.salesmanager.shop.model.catalog.product.group;
2+
3+
public class ProductGroup {
4+
5+
private String code;
6+
private boolean active;
7+
public String getCode() {
8+
return code;
9+
}
10+
public void setCode(String code) {
11+
this.code = code;
12+
}
13+
public boolean isActive() {
14+
return active;
15+
}
16+
public void setActive(boolean active) {
17+
this.active = active;
18+
}
19+
20+
}

sm-shop-model/src/main/java/com/salesmanager/shop/store/controller/items/facade/ProductItemsFacade.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.salesmanager.core.model.merchant.MerchantStore;
77
import com.salesmanager.core.model.reference.language.Language;
88
import com.salesmanager.shop.model.catalog.product.ReadableProductList;
9+
import com.salesmanager.shop.model.catalog.product.group.ProductGroup;
910

1011
public interface ProductItemsFacade {
1112

@@ -17,6 +18,8 @@ public interface ProductItemsFacade {
1718
*/
1819
ReadableProductList listItemsByManufacturer(MerchantStore store, Language language, Long manufacturerId, int startCount, int maxCount) throws Exception;
1920

21+
ProductGroup createProductGroup(ProductGroup group, MerchantStore store);
22+
2023
/**
2124
* List product items by id
2225
* @param store

sm-shop-model/src/main/java/com/salesmanager/shop/store/controller/product/facade/ProductOptionFacade.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ public interface ProductOptionFacade {
2929

3030
ReadableProductOptionEntity saveOption(PersistableProductOptionEntity option, MerchantStore store, Language language);
3131

32-
ReadableProductOptionValueEntity saveOptionValue(Optional<MultipartFile> image, PersistableProductOptionValueEntity optionValue, MerchantStore store, Language language);
32+
ReadableProductOptionValueEntity saveOptionValue(PersistableProductOptionValueEntity optionValue, MerchantStore store, Language language);
3333

34+
void addOptionValueImage(MultipartFile image, Long optionValueId, MerchantStore store, Language language);
35+
36+
void removeOptionValueImage(Long optionValueId, MerchantStore store, Language language);
37+
3438
boolean optionExists(String code, MerchantStore store);
3539

3640
boolean optionValueExists(String code, MerchantStore store);

sm-shop/SALESMANAGER-TEST.h2.db

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableCategoryMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private com.salesmanager.shop.model.catalog.category.CategoryDescription convert
7272
desc.setFriendlyUrl(description.getSeUrl());
7373
desc.setName(description.getName());
7474
desc.setId(description.getId());
75-
desc.setDescription(description.getName());
75+
desc.setDescription(description.getDescription());
7676
desc.setKeyWords(description.getMetatagKeywords());
7777
desc.setHighlights(description.getCategoryHighlight());
7878
desc.setLanguage(description.getLanguage().getCode());

sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableProductOptionValueMapper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ public ReadableProductOptionValueEntity convert(ProductOptionValue source, Reada
4444
}
4545

4646
readableProductOptionValue.setCode(source.getCode());
47-
readableProductOptionValue.setId(source.getId());
48-
readableProductOptionValue.setOrder(source.getProductOptionValueSortOrder());
47+
if(source.getId()!=null) {
48+
readableProductOptionValue.setId(source.getId().longValue());
49+
}
50+
if(source.getProductOptionValueSortOrder()!=null) {
51+
readableProductOptionValue.setOrder(source.getProductOptionValueSortOrder().intValue());
52+
}
4953
readableProductOptionValue.setImage(source.getProductOptionValueImage());
5054

5155

sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/PersistableCategoryPopulator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public Category populate(PersistableCategory source, Category target,
124124
}
125125
if(d.getLanguage().equals(description.getLanguage().getCode())) {
126126
description.setCategory(target);
127-
description = this.buildDescription(d, description);
127+
description = buildDescription(d, description);
128128
descriptions.add(description);
129129
}
130130
}

sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/ReadableCategoryPopulator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public ReadableCategory populate(final Category source,
3939
desc.setFriendlyUrl(description.getSeUrl());
4040
desc.setName(description.getName());
4141
desc.setId(source.getId());
42-
desc.setDescription(description.getName());
42+
desc.setDescription(description.getDescription());
4343
desc.setKeyWords(description.getMetatagKeywords());
4444
desc.setHighlights(description.getCategoryHighlight());
4545
desc.setTitle(description.getMetatagTitle());

sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductGroupApi.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.web.bind.annotation.DeleteMapping;
1212
import org.springframework.web.bind.annotation.GetMapping;
1313
import org.springframework.web.bind.annotation.PathVariable;
14+
import org.springframework.web.bind.annotation.RequestBody;
1415
import org.springframework.web.bind.annotation.RequestMapping;
1516
import org.springframework.web.bind.annotation.RequestMethod;
1617
import org.springframework.web.bind.annotation.ResponseBody;
@@ -21,6 +22,7 @@
2122
import com.salesmanager.core.model.merchant.MerchantStore;
2223
import com.salesmanager.core.model.reference.language.Language;
2324
import com.salesmanager.shop.model.catalog.product.ReadableProductList;
25+
import com.salesmanager.shop.model.catalog.product.group.ProductGroup;
2426
import com.salesmanager.shop.store.controller.items.facade.ProductItemsFacade;
2527

2628
import io.swagger.annotations.Api;
@@ -49,6 +51,26 @@ public class ProductGroupApi {
4951

5052
private static final Logger LOGGER = LoggerFactory.getLogger(ProductGroupApi.class);
5153

54+
@ResponseStatus(HttpStatus.OK)
55+
@GetMapping("/private/products/group")
56+
@ApiOperation(httpMethod = "POST", value = "Get products by group code", notes = "", response = ProductGroup.class)
57+
@ApiImplicitParams({
58+
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
59+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")
60+
})
61+
public @ResponseBody ProductGroup creteGroup(
62+
@RequestBody ProductGroup group,
63+
@ApiIgnore MerchantStore merchantStore,
64+
@ApiIgnore Language language,
65+
HttpServletResponse response)
66+
throws Exception {
67+
68+
productItemsFacade.createProductGroup(group, merchantStore);
69+
70+
return group;
71+
}
72+
73+
5274
/**
5375
* Query for a product group public/products/group/{code}?lang=fr|en no lang it will take session
5476
* lang or default store lang code can be any code used while creating product group, defeult
@@ -139,7 +161,7 @@ public class ProductGroupApi {
139161
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
140162
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")
141163
})
142-
public @ResponseBody ReadableProductList removeProductFromCategory(
164+
public @ResponseBody ReadableProductList removeProductFromGroup(
143165
@PathVariable Long productId,
144166
@PathVariable String code,
145167
@ApiIgnore MerchantStore merchantStore,
@@ -179,7 +201,7 @@ public class ProductGroupApi {
179201
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
180202
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")
181203
})
182-
public void delete(
204+
public void deleteGroup(
183205
@PathVariable final String code,
184206
@ApiIgnore MerchantStore merchantStore,
185207
@ApiIgnore Language language,

sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductOptionApi.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,46 @@ public ResponseEntity<EntityExists> optionValueExists(@RequestParam(value = "cod
9494
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
9595
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
9696
public @ResponseBody ReadableProductOptionValueEntity createOptionValue(
97-
@Valid @RequestBody PersistableProductOptionValueEntity optionValie,
98-
@RequestParam(name = "file", required = false) MultipartFile file, @ApiIgnore MerchantStore merchantStore,
97+
@Valid @RequestBody PersistableProductOptionValueEntity optionValue,
98+
//@RequestParam(name = "file", required = false) MultipartFile file,
99+
@ApiIgnore MerchantStore merchantStore,
99100
@ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
100101

101-
Optional<MultipartFile> imageFile = Optional.empty();
102-
if (file != null) {
103-
imageFile = Optional.of(file);
104-
}
105-
106-
ReadableProductOptionValueEntity entity = productOptionFacade.saveOptionValue(imageFile, optionValie,
102+
ReadableProductOptionValueEntity entity = productOptionFacade.saveOptionValue( optionValue,
107103
merchantStore, language);
108104
return entity;
109105

110106
}
107+
108+
@ResponseStatus(HttpStatus.CREATED)
109+
@RequestMapping(value = { "/private/product/option/value/{id}/image" }, method = RequestMethod.POST)
110+
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
111+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
112+
public void addOptionValueImage(
113+
@PathVariable Long id,
114+
@RequestParam(name = "file", required = true) MultipartFile file,
115+
@ApiIgnore MerchantStore merchantStore,
116+
@ApiIgnore Language language,
117+
HttpServletRequest request, HttpServletResponse response) {
118+
119+
productOptionFacade.addOptionValueImage(file, id, merchantStore, language);
120+
121+
122+
}
123+
124+
@ResponseStatus(HttpStatus.OK)
125+
@RequestMapping(value = { "/private/product/option/value/{id}/image" }, method = RequestMethod.DELETE)
126+
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
127+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
128+
public void removeOptionValueImage(
129+
@PathVariable Long id,
130+
@ApiIgnore MerchantStore merchantStore,
131+
@ApiIgnore Language language,
132+
HttpServletRequest request, HttpServletResponse response) {
133+
134+
productOptionFacade.removeOptionValueImage(id, merchantStore, language);
135+
136+
}
111137

112138
@ResponseStatus(HttpStatus.OK)
113139
@RequestMapping(value = { "/private/product/option/{id}" }, method = RequestMethod.GET)
@@ -165,16 +191,11 @@ public void deleteOption(@PathVariable Long optionId, @ApiIgnore MerchantStore m
165191
public void updateOptionValue(
166192
@PathVariable Long id,
167193
@Valid @RequestBody PersistableProductOptionValueEntity optionValue,
168-
@RequestParam(name = "file", required = false) MultipartFile file, @ApiIgnore MerchantStore merchantStore,
194+
@ApiIgnore MerchantStore merchantStore,
169195
@ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
170196

171197
optionValue.setId(id);
172-
Optional<MultipartFile> imageFile = Optional.empty();
173-
if (file != null) {
174-
imageFile = Optional.of(file);
175-
}
176-
177-
productOptionFacade.saveOptionValue(imageFile, optionValue, merchantStore, language);
198+
productOptionFacade.saveOptionValue(optionValue, merchantStore, language);
178199
return;
179200

180201
}

sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/user/UserApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public ResponseEntity<EntityExists> exists(@ApiIgnore MerchantStore merchantStor
235235
boolean isUserExist = true;// default user exist
236236
try {
237237
// will throw an exception if not fount
238-
userFacade.findByUserName(userName.getUnique(), merchantStore.getCode(), language);
238+
userFacade.findByUserName(userName.getUnique(), userName.getMerchant(), language);
239239

240240
} catch (ResourceNotFoundException e) {
241241
isUserExist = false;
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.salesmanager.shop.store.controller.items.facade;
1+
package com.salesmanager.shop.store.facade.items;
22

33
import java.util.ArrayList;
44
import java.util.List;
@@ -21,8 +21,10 @@
2121
import com.salesmanager.core.model.reference.language.Language;
2222
import com.salesmanager.shop.model.catalog.product.ReadableProduct;
2323
import com.salesmanager.shop.model.catalog.product.ReadableProductList;
24+
import com.salesmanager.shop.model.catalog.product.group.ProductGroup;
2425
import com.salesmanager.shop.populator.catalog.ReadableProductPopulator;
2526
import com.salesmanager.shop.store.api.exception.ServiceRuntimeException;
27+
import com.salesmanager.shop.store.controller.items.facade.ProductItemsFacade;
2628
import com.salesmanager.shop.utils.ImageFilePath;
2729

2830
@Component
@@ -187,4 +189,16 @@ public void deleteGroup(String group, MerchantStore store) {
187189

188190
}
189191

192+
@Override
193+
public ProductGroup createProductGroup(ProductGroup group, MerchantStore store) {
194+
Validate.notNull(group,"ProductGroup cannot be null");
195+
Validate.notNull(store,"MerchantStore cannot be null");
196+
try {
197+
productRelationshipService.addGroup(store, group.getCode());
198+
} catch (ServiceException e) {
199+
throw new ServiceRuntimeException("Cannor delete product group",e);
200+
}
201+
return group;
202+
}
203+
190204
}

sm-shop/src/main/java/com/salesmanager/shop/store/facade/product/ProductOptionFacadeImpl.java

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.salesmanager.core.model.catalog.product.attribute.ProductAttribute;
2222
import com.salesmanager.core.model.catalog.product.attribute.ProductOption;
2323
import com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue;
24+
import com.salesmanager.core.model.content.FileContentType;
2425
import com.salesmanager.core.model.content.InputContentFile;
2526
import com.salesmanager.core.model.merchant.MerchantStore;
2627
import com.salesmanager.core.model.reference.language.Language;
@@ -213,8 +214,8 @@ public boolean optionValueExists(String code, MerchantStore store) {
213214
}
214215

215216
@Override
216-
public ReadableProductOptionValueEntity saveOptionValue(Optional<MultipartFile> image,
217-
PersistableProductOptionValueEntity optionValue, MerchantStore store, Language language) {
217+
public ReadableProductOptionValueEntity saveOptionValue(PersistableProductOptionValueEntity optionValue,
218+
MerchantStore store, Language language) {
218219
Validate.notNull(optionValue, "Option value code must not be null");
219220
Validate.notNull(store, "Store code must not be null");
220221

@@ -228,22 +229,7 @@ public ReadableProductOptionValueEntity saveOptionValue(Optional<MultipartFile>
228229
}
229230

230231
value = persistableOptionValueMapper.convert(optionValue, value, store, language);
231-
if (image.isPresent()) {
232-
try {
233-
String imageName = image.get().getOriginalFilename();
234-
InputStream inputStream = image.get().getInputStream();
235-
InputContentFile cmsContentImage = new InputContentFile();
236-
cmsContentImage.setFileName(imageName);
237-
cmsContentImage.setMimeType(image.get().getContentType());
238-
cmsContentImage.setFile(inputStream);
239-
240-
contentService.addOptionImage(store.getCode(), cmsContentImage);
241-
value.setProductOptionValueImage(imageName);
242-
} catch (Exception e) {
243-
throw new ServiceRuntimeException("Exception while saving option value image", e);
244-
}
245232

246-
}
247233

248234
try {
249235
productOptionValueService.saveOrUpdate(value);
@@ -400,4 +386,64 @@ public void deleteAttribute(Long productId, Long attributeId, MerchantStore stor
400386

401387
}
402388

389+
390+
391+
@Override
392+
public void addOptionValueImage(MultipartFile image, Long optionValueId,
393+
MerchantStore store, Language language) {
394+
395+
396+
Validate.notNull(optionValueId,"OptionValueId must not be null");
397+
Validate.notNull(image,"Image must not be null");
398+
//get option value
399+
ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
400+
if(value == null) {
401+
throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
402+
}
403+
404+
try {
405+
String imageName = image.getOriginalFilename();
406+
InputStream inputStream = image.getInputStream();
407+
InputContentFile cmsContentImage = new InputContentFile();
408+
cmsContentImage.setFileName(imageName);
409+
cmsContentImage.setMimeType(image.getContentType());
410+
cmsContentImage.setFile(inputStream);
411+
412+
contentService.addOptionImage(store.getCode(), cmsContentImage);
413+
value.setProductOptionValueImage(imageName);
414+
productOptionValueService.saveOrUpdate(value);
415+
} catch (Exception e) {
416+
throw new ServiceRuntimeException("Exception while adding option value image", e);
417+
}
418+
419+
420+
421+
422+
return;
423+
}
424+
425+
@Override
426+
public void removeOptionValueImage(Long optionValueId, MerchantStore store,
427+
Language language) {
428+
Validate.notNull(optionValueId,"OptionValueId must not be null");
429+
ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
430+
if(value == null) {
431+
throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
432+
}
433+
434+
try {
435+
436+
contentService.removeFile(store.getCode(), FileContentType.PROPERTY, value.getProductOptionValueImage());
437+
value.setProductOptionValueImage(null);
438+
productOptionValueService.saveOrUpdate(value);
439+
} catch (Exception e) {
440+
throw new ServiceRuntimeException("Exception while removing option value image", e);
441+
}
442+
443+
444+
445+
446+
return;
447+
}
448+
403449
}

0 commit comments

Comments
 (0)