Subversion Repositories SmartDukaan

Rev

Rev 32959 | Rev 32963 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32959 Rev 32962
Line 158... Line 158...
158
    private void addItem(ItemLoaderModel itemLoaderModel) throws ProfitMandiBusinessException {
158
    private void addItem(ItemLoaderModel itemLoaderModel) throws ProfitMandiBusinessException {
159
        this.validateItemLoaderModel(itemLoaderModel);
159
        this.validateItemLoaderModel(itemLoaderModel);
160
        List<Item> items = itemRepository.selectAll(itemLoaderModel.getBrand(), itemLoaderModel.getModelName(), itemLoaderModel.getModelNumber());
160
        List<Item> items = itemRepository.selectAll(itemLoaderModel.getBrand(), itemLoaderModel.getModelName(), itemLoaderModel.getModelNumber());
161
        int catalogId = 0;
161
        int catalogId = 0;
162
        if (items.size() > 0) {
162
        if (items.size() > 0) {
-
 
163
            //Check if color already exist
-
 
164
            long similarColorCount = items.stream().filter(x-> itemLoaderModel.getColor().equals(x.getColorNatural())).count();
-
 
165
            if(similarColorCount > 0) {
-
 
166
                throw new ProfitMandiBusinessException("Color alerady exist", "Pls check", itemLoaderModel.getColor());
-
 
167
            }
-
 
168
 
163
            List<Integer> categoryIds = items.stream().map(x -> x.getCategoryId()).distinct().collect(Collectors.toList());
169
            List<Integer> categoryIds = items.stream().map(x -> x.getCategoryId()).distinct().collect(Collectors.toList());
164
            if (categoryIds.size() > 1) {
170
            if (categoryIds.size() > 1) {
165
                throw new ProfitMandiBusinessException("Model Wrongly Mapped to different categories", "Pls check", categoryIds.toString());
171
                throw new ProfitMandiBusinessException("Model Wrongly Mapped to different categories", "Pls check", categoryIds.toString());
166
            } else if (categoryIds.get(0) != itemLoaderModel.getCategoryId()) {
172
            } else if (categoryIds.get(0) != itemLoaderModel.getCategoryId()) {
167
                throw new ProfitMandiBusinessException("Model already Mapped to different category", "Pls check", categoryIds.toString());
173
                throw new ProfitMandiBusinessException("Model already Mapped to different category", "Pls check", categoryIds.toString());
168
            }
174
            }
169
            List<Integer> catalogIds = items.stream().map(x -> x.getCategoryId()).distinct().collect(Collectors.toList());
175
            List<Integer> catalogIds = items.stream().map(x -> x.getCategoryId()).distinct().collect(Collectors.toList());
170
            if (catalogIds.size() > 1) {
176
            if (catalogIds.size() > 1) {
171
                throw new ProfitMandiBusinessException("Model Wrongly Mapped to different CatalogIds", "Pls check", catalogIds.toString());
177
                throw new ProfitMandiBusinessException("Model Wrongly Mapped to different CatalogIds", "Pls check", catalogIds.toString());
172
            }
178
            }
173
            Map<String, Long> colorsCount = items.stream().collect(Collectors.groupingBy(x -> x.getColor(), Collectors.counting()));
179
            Map<String, Long> colorsCount = items.stream().collect(Collectors.groupingBy(x -> x.getColorNatural(), Collectors.counting()));
174
            for (Map.Entry<String, Long> colorCountEntrySet : colorsCount.entrySet()) {
180
            for (Map.Entry<String, Long> colorCountEntrySet : colorsCount.entrySet()) {
175
                if (colorCountEntrySet.getValue() > 1) {
181
                if (colorCountEntrySet.getValue() > 1) {
176
                    throw new ProfitMandiBusinessException("Model repeats the same color", "Pls check", colorCountEntrySet.getKey());
182
                    throw new ProfitMandiBusinessException("Model repeats the same color", "Pls check", colorCountEntrySet.getKey());
177
                }
183
                }
178
            }
184
            }