Skip to content

Commit e262a3b

Browse files
Trello issues
1 parent f57a27f commit e262a3b

File tree

17 files changed

+113
-26
lines changed

17 files changed

+113
-26
lines changed

sm-core-model/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<artifactId>spring-boot-starter-parent</artifactId>
1111
<version>1.5.18.RELEASE</version>
1212
</parent>
13-
<version>2.7.0</version>
13+
<version>2.8.0</version>
1414
<groupId>com.shopizer</groupId> -->
1515

1616
<parent>
0 Bytes
Binary file not shown.

sm-core/src/main/java/com/salesmanager/core/business/repositories/catalog/product/attribute/PageableProductOptionRepository.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
public interface PageableProductOptionRepository extends PagingAndSortingRepository<ProductOption, Long> {
1010

11-
@Query(value = "select distinct p from ProductOption p join fetch p.merchantStore pm left join fetch p.descriptions pd where pm.id = ?1 and pd.language.id = ?2 and (?3 is null or pd.name like %?3%)",
12-
countQuery = "select count(p) from ProductOption p join p.merchantStore pm left join p.descriptions pd where pm.id = ?1 and pd.language.id = ?2 and (?3 is null or pd.name like %?3%)")
13-
Page<ProductOption> listOptions(int merchantStoreId, int languageId, String name, Pageable pageable);
11+
@Query(value = "select distinct p from ProductOption p join fetch p.merchantStore pm left join fetch p.descriptions pd where pm.id = ?1 and (?2 is null or pd.name like %?2%)",
12+
countQuery = "select count(p) from ProductOption p join p.merchantStore pm left join p.descriptions pd where pm.id = ?1 and (?2 is null or pd.name like %?2%)")
13+
Page<ProductOption> listOptions(int merchantStoreId, String name, Pageable pageable);
1414

1515

1616
}

sm-core/src/main/java/com/salesmanager/core/business/repositories/catalog/product/attribute/PageableProductOptionValueRepository.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
public interface PageableProductOptionValueRepository extends PagingAndSortingRepository<ProductOptionValue, Long> {
1111

12-
@Query(value = "select distinct p from ProductOptionValue p join fetch p.merchantStore pm left join fetch p.descriptions pd where pm.id = ?1 and pd.language.id = ?2 and (?3 is null or pd.name like %?3%)",
13-
countQuery = "select count(p) from ProductOptionValue p join p.merchantStore pm left join p.descriptions pd where pm.id = ?1 and pd.language.id = ?2 and (?3 is null or pd.name like %?3%)")
14-
Page<ProductOptionValue> listOptions(int merchantStoreId, int languageId, String name, Pageable pageable);
12+
@Query(value = "select distinct p from ProductOptionValue p join fetch p.merchantStore pm left join fetch p.descriptions pd where pm.id = ?1 and (?2 is null or pd.name like %?2%)",
13+
countQuery = "select count(p) from ProductOptionValue p join p.merchantStore pm left join p.descriptions pd where pm.id = ?1 and (?2 is null or pd.name like %?2%)")
14+
Page<ProductOptionValue> listOptionValues(int merchantStoreId, String name, Pageable pageable);
1515

1616

1717
}

sm-core/src/main/java/com/salesmanager/core/business/services/catalog/product/attribute/ProductOptionServiceImpl.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ public ProductOption getById(MerchantStore store, Long optionId) {
112112
public Page<ProductOption> getByMerchant(MerchantStore store, Language language, String name,
113113
int page, int count) {
114114
Validate.notNull(store, "MerchantStore cannot be null");
115-
Validate.notNull(language, "Language cannot be null");
116115
Pageable p = new PageRequest(page, count);
117-
return pageableProductOptionRepository.listOptions(store.getId(), language.getId(), name, p);
116+
return pageableProductOptionRepository.listOptions(store.getId(), name, p);
118117
}
119118

120119

sm-core/src/main/java/com/salesmanager/core/business/services/catalog/product/attribute/ProductOptionValueServiceImpl.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ public ProductOptionValue getById(MerchantStore store, Long optionValueId) {
115115
public Page<ProductOptionValue> getByMerchant(MerchantStore store, Language language, String name, int page,
116116
int count) {
117117
Validate.notNull(store, "MerchantStore cannot be null");
118-
Validate.notNull(language, "Language cannot be null");
119118
Pageable p = new PageRequest(page, count);
120-
return pageableProductOptionValueRepository.listOptions(store.getId(), language.getId(), name, p);
119+
return pageableProductOptionValueRepository.listOptionValues(store.getId(), name, p);
121120
}
122121

123122

sm-shop-model/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<version>1.5.18.RELEASE</version>
2020
</parent>
2121
<groupId>com.shopizer</groupId>
22-
<version>2.7.0</version> -->
22+
<version>2.8.0</version> -->
2323

2424

2525
<licenses>

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/filter/StoreFilter.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import javax.servlet.http.HttpServletResponse;
5151
import java.util.*;
5252
import java.util.concurrent.ConcurrentHashMap;
53+
import java.util.stream.Collectors;
5354

5455
/**
5556
* Servlet Filter implementation class StoreFilter
@@ -559,7 +560,10 @@ private void setTopCategories(MerchantStore store, Language language, HttpServle
559560
// load categories
560561
ReadableCategoryList categoryList = categoryFacade.getCategoryHierarchy(store, null, 0, language, null, 0, 200);// null
561562
loadedCategories = categoryList.getCategories();
562-
// filter
563+
564+
//filter out invisible category
565+
loadedCategories.stream().filter(cat -> cat.isVisible()==true).collect(Collectors.toList());
566+
563567
objects = new ConcurrentHashMap<String, List<ReadableCategory>>();
564568
objects.put(language.getCode(), loadedCategories);
565569
webApplicationCache.putInCache(categoriesKey.toString(), objects);

sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/category/CategoryApi.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import static org.springframework.http.HttpStatus.OK;
44
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
5+
56
import java.util.List;
67
import java.util.stream.Collectors;
78
import java.util.stream.Stream;
89

910
import javax.inject.Inject;
10-
import javax.servlet.http.HttpServletRequest;
1111
import javax.validation.Valid;
12+
1213
import org.springframework.http.HttpStatus;
1314
import org.springframework.http.MediaType;
1415
import org.springframework.http.ResponseEntity;
@@ -23,6 +24,7 @@
2324
import org.springframework.web.bind.annotation.RequestParam;
2425
import org.springframework.web.bind.annotation.ResponseStatus;
2526
import org.springframework.web.bind.annotation.RestController;
27+
2628
import com.salesmanager.core.model.merchant.MerchantStore;
2729
import com.salesmanager.core.model.reference.language.Language;
2830
import com.salesmanager.shop.constants.Constants;
@@ -36,6 +38,7 @@
3638
import com.salesmanager.shop.store.controller.store.facade.StoreFacade;
3739
import com.salesmanager.shop.store.controller.user.facade.UserFacade;
3840
import com.salesmanager.shop.utils.LanguageUtils;
41+
3942
import io.swagger.annotations.Api;
4043
import io.swagger.annotations.ApiImplicitParam;
4144
import io.swagger.annotations.ApiImplicitParams;

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

+41-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import com.salesmanager.shop.model.catalog.product.ReadableProduct;
3737
import com.salesmanager.shop.model.catalog.product.ReadableProductList;
3838
import com.salesmanager.shop.model.entity.EntityExists;
39+
import com.salesmanager.shop.store.api.exception.ResourceNotFoundException;
40+
import com.salesmanager.shop.store.api.exception.UnauthorizedException;
3941
import com.salesmanager.shop.store.controller.product.facade.ProductFacade;
4042
import com.salesmanager.shop.utils.ImageFilePath;
4143
import io.swagger.annotations.Api;
@@ -504,7 +506,26 @@ public ResponseEntity<EntityExists> exists(
504506
try {
505507
// get the product
506508
Product product = productService.getById(productId);
509+
510+
if(product == null) {
511+
throw new ResourceNotFoundException("Product id [" + productId + "] is not found");
512+
}
513+
514+
if(product.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
515+
throw new UnauthorizedException("Product id [" + productId + "] does not belong to store [" + merchantStore.getCode() + "]");
516+
}
517+
507518
Category category = categoryService.getById(categoryId);
519+
520+
if(category == null) {
521+
throw new ResourceNotFoundException("Category id [" + categoryId + "] is not found");
522+
}
523+
524+
if(category.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
525+
throw new UnauthorizedException("Category id [" + categoryId + "] does not belong to store [" + merchantStore.getCode() + "]");
526+
}
527+
528+
508529
return productFacade.addProductToCategory(category, product, language);
509530

510531
} catch (Exception e) {
@@ -537,9 +558,26 @@ public ResponseEntity<EntityExists> exists(
537558
HttpServletResponse response) {
538559

539560
try {
540-
// get the product
541-
Product product = productService.getById(productId);
542-
Category category = categoryService.getById(categoryId);
561+
Product product = productService.getById(productId);
562+
563+
if(product == null) {
564+
throw new ResourceNotFoundException("Product id [" + productId + "] is not found");
565+
}
566+
567+
if(product.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
568+
throw new UnauthorizedException("Product id [" + productId + "] does not belong to store [" + merchantStore.getCode() + "]");
569+
}
570+
571+
Category category = categoryService.getById(categoryId);
572+
573+
if(category == null) {
574+
throw new ResourceNotFoundException("Category id [" + categoryId + "] is not found");
575+
}
576+
577+
if(category.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
578+
throw new UnauthorizedException("Category id [" + categoryId + "] does not belong to store [" + merchantStore.getCode() + "]");
579+
}
580+
543581
return productFacade.removeProductFromCategory(category, product, language);
544582

545583
} catch (Exception e) {

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

+19
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ public void deleteOptionValue(
245245
@RequestMapping(value = { "/private/product/{id}/attributes" }, method = RequestMethod.GET)
246246
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
247247
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
248+
@ApiOperation(httpMethod = "GET", value = "Get product attributes", notes = "",
249+
response = ReadableProductAttributeList.class)
248250
public @ResponseBody ReadableProductAttributeList attributes(
249251
@PathVariable Long id,
250252
@ApiIgnore MerchantStore merchantStore,
@@ -254,6 +256,23 @@ public void deleteOptionValue(
254256

255257
}
256258

259+
@ResponseStatus(HttpStatus.OK)
260+
@RequestMapping(value = { "/private/product/{id}/attribute/{attributeId}" }, method = RequestMethod.GET)
261+
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
262+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
263+
@ApiOperation(httpMethod = "GET", value = "Get product attributes", notes = "",
264+
response = EntityExists.class)
265+
public @ResponseBody ReadableProductAttributeEntity getAttribute(
266+
@PathVariable Long id,
267+
@PathVariable Long attributeId,
268+
@ApiIgnore MerchantStore merchantStore,
269+
@ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
270+
271+
ReadableProductAttributeEntity entity = productOptionFacade.getAttribute(id, attributeId, merchantStore, language);
272+
return entity;
273+
274+
}
275+
257276
@ResponseStatus(HttpStatus.CREATED)
258277
@RequestMapping(value = { "/private/product/{id}/attribute" }, method = RequestMethod.POST)
259278
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@
4444
import com.salesmanager.shop.store.controller.user.facade.UserFacade;
4545
import com.salesmanager.shop.utils.ServiceRequestCriteriaBuilderUtils;
4646

47+
import io.swagger.annotations.Api;
4748
import io.swagger.annotations.ApiImplicitParam;
4849
import io.swagger.annotations.ApiImplicitParams;
4950
import io.swagger.annotations.ApiOperation;
5051
import io.swagger.annotations.ApiResponse;
5152
import io.swagger.annotations.ApiResponses;
53+
import io.swagger.annotations.SwaggerDefinition;
54+
import io.swagger.annotations.Tag;
5255
import springfox.documentation.annotations.ApiIgnore;
5356

5457
/** Api for managing admin users */
5558
@RestController
5659
@RequestMapping(value = "/api/v1")
60+
@Api(tags = { "User management resource (User Management Api)" })
61+
@SwaggerDefinition(tags = {
62+
@Tag(name = "User management resource", description = "Manage administration users") })
5763
public class UserApi {
5864

5965
private static final Logger LOGGER = LoggerFactory.getLogger(UserApi.class);
@@ -291,8 +297,13 @@ public ReadableUser getAuthUser(
291297
HttpServletRequest request) {
292298
Principal principal = request.getUserPrincipal();
293299
String userName = principal.getName();
294-
return userFacade.findByUserName(userName, null, language);
300+
ReadableUser user = userFacade.findByUserName(userName, null, language);
295301

302+
if(!user.isActive()) {
303+
throw new UnauthorizedException("User " + userName + " not not active");
304+
}
305+
306+
return user;
296307

297308
}
298309
}

sm-shop/src/main/java/com/salesmanager/shop/store/controller/user/facade/UserFacadeImpl.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,16 @@ public ReadableUser findById(Long id, String storeCode, Language lang) {
375375
}
376376

377377
boolean isActive = user.isActive();
378+
379+
//user must be superadmin or admin
378380

379381
List<Group> originalGroups = user.getGroups();
380-
Group superadmin = originalGroups.stream()
381-
.filter(group -> Constants.GROUP_SUPERADMIN.equals(group.getGroupName())).findAny().orElse(null);
382+
Group admin = originalGroups.stream()
383+
.filter(
384+
group -> Constants.GROUP_SUPERADMIN.equals(group.getGroupName()) || Constants.GROUP_ADMIN.equals(group.getGroupName())
385+
).findAny().orElse(null);
382386

383-
if (superadmin == null) {
387+
if (admin == null) {
384388
if (user.getMerchantStore().getCode().equals(storeCode)) {
385389
throw new UnauthorizedException("User [" + user.getAdminEmail() + " Not authorized");
386390
}

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.ArrayList;
44
import java.util.Date;
55
import java.util.List;
6+
import java.util.stream.Collectors;
7+
68
import javax.inject.Inject;
79
import org.apache.commons.collections4.CollectionUtils;
810
import org.apache.commons.lang.Validate;
@@ -42,6 +44,7 @@
4244
import com.salesmanager.shop.populator.catalog.PersistableProductReviewPopulator;
4345
import com.salesmanager.shop.populator.catalog.ReadableProductPopulator;
4446
import com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator;
47+
import com.salesmanager.shop.store.api.exception.OperationNotAllowedException;
4548
import com.salesmanager.shop.store.api.exception.ResourceNotFoundException;
4649
import com.salesmanager.shop.store.api.exception.ServiceRuntimeException;
4750
import com.salesmanager.shop.store.controller.product.facade.ProductFacade;
@@ -348,7 +351,14 @@ public ReadableProduct addProductToCategory(Category category, Product product,
348351

349352
Validate.notNull(category, "Category cannot be null");
350353
Validate.notNull(product, "Product cannot be null");
351-
354+
355+
//not alloweed if category already attached
356+
List<Category> assigned = product.getCategories().stream().filter(cat -> cat.getId().longValue() == category.getId().longValue()).collect(Collectors.toList());
357+
358+
if(assigned.size() >0) {
359+
throw new OperationNotAllowedException("Category with id [" + category.getId() + "] already attached to product [" + product.getId() + "]");
360+
}
361+
352362
product.getCategories().add(category);
353363

354364
productService.update(product);

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ public ReadableProductOptionValueList optionValues(MerchantStore store, Language
143143
int count) {
144144
Validate.notNull(store, "MerchantStore should not be null");
145145

146-
Page<ProductOptionValue> options = productOptionValueService.getByMerchant(store, language, name, page, count);
146+
Page<ProductOptionValue> options = productOptionValueService.getByMerchant(store, null, name, page, count);
147147
ReadableProductOptionValueList valueList = new ReadableProductOptionValueList();
148148
valueList.setTotalPages(options.getTotalPages());
149149
valueList.setRecordsTotal(options.getTotalElements());
150150
valueList.setNumber(options.getNumber());
151151

152152
List<ReadableProductOptionValueEntity> values = options.getContent().stream()
153-
.map(option -> readableOptionValueMapper.convert(option, store, language)).collect(Collectors.toList());
153+
.map(option -> readableOptionValueMapper.convert(option, store, null)).collect(Collectors.toList());
154154

155155
valueList.setOptionValues(values);
156156

@@ -161,14 +161,14 @@ public ReadableProductOptionValueList optionValues(MerchantStore store, Language
161161
public ReadableProductOptionList options(MerchantStore store, Language language, String name, int page, int count) {
162162
Validate.notNull(store, "MerchantStore should not be null");
163163

164-
Page<ProductOption> options = productOptionService.getByMerchant(store, language, name, page, count);
164+
Page<ProductOption> options = productOptionService.getByMerchant(store, null, name, page, count);
165165
ReadableProductOptionList valueList = new ReadableProductOptionList();
166166
valueList.setTotalPages(options.getTotalPages());
167167
valueList.setRecordsTotal(options.getTotalElements());
168168
valueList.setNumber(options.getNumber());
169169

170170
List<ReadableProductOptionEntity> values = options.getContent().stream()
171-
.map(option -> readableMapper.convert(option, store, language)).collect(Collectors.toList());
171+
.map(option -> readableMapper.convert(option, store, null)).collect(Collectors.toList());
172172

173173
valueList.setOptions(values);
174174

0 commit comments

Comments
 (0)