Subversion Repositories SmartDukaan

Rev

Rev 36482 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36482 Rev 37143
Line 11... Line 11...
11
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
11
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
12
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
12
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
13
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
13
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
14
import com.spice.profitmandi.dao.repository.dtr.PartnerDealerRepository;
14
import com.spice.profitmandi.dao.repository.dtr.PartnerDealerRepository;
15
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
15
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
16
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
-
 
17
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
16
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
-
 
17
import com.spice.profitmandi.common.solr.SolrService;
18
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.stereotype.Component;
19
import org.springframework.stereotype.Component;
20
 
20
 
21
import java.util.ArrayList;
21
import java.util.ArrayList;
-
 
22
import java.util.Collection;
22
import java.util.List;
23
import java.util.List;
23
import java.util.Map;
24
import java.util.Map;
24
import java.util.stream.Collectors;
25
import java.util.stream.Collectors;
25
 
26
 
26
@Component
27
@Component
Line 31... Line 32...
31
 
32
 
32
    @Autowired
33
    @Autowired
33
    private BrandsRepository brandCatalogRepository;
34
    private BrandsRepository brandCatalogRepository;
34
 
35
 
35
    @Autowired
36
    @Autowired
36
    private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
37
    private BlockedBrandService blockedBrandService;
37
 
38
 
38
    @Autowired
39
    @Autowired
39
    private FofoStoreRepository fofoStoreRepository;
40
    private FofoStoreRepository fofoStoreRepository;
40
 
41
 
41
    @Autowired
42
    @Autowired
Line 86... Line 87...
86
        ineligibleBrands.removeAll(wodCompleteBrands);
87
        ineligibleBrands.removeAll(wodCompleteBrands);
87
        return ineligibleBrands;
88
        return ineligibleBrands;
88
    }
89
    }
89
 
90
 
90
    @Override
91
    @Override
-
 
92
    public List<String> restrictedBrands(int fofoId) throws ProfitMandiBusinessException {
-
 
93
        List<String> restricted = new ArrayList<>(blockedBrandService.getBlockedBrands(fofoId));
-
 
94
        this.loiIneligibleBrands(fofoId).stream().filter(x -> !restricted.contains(x)).forEach(restricted::add);
-
 
95
        return restricted;
-
 
96
    }
-
 
97
 
-
 
98
    @Override
-
 
99
    public void applyRestrictedSolrExclusion(Map<String, String> params, int fofoId)
-
 
100
            throws ProfitMandiBusinessException {
-
 
101
        String exclusionFq = SolrService.brandExclusionFq(this.restrictedBrands(fofoId));
-
 
102
        if (exclusionFq == null) {
-
 
103
            return;
-
 
104
        }
-
 
105
        String existingFq = params.get("fq");
-
 
106
        params.put("fq", existingFq == null ? exclusionFq : existingFq + " AND " + exclusionFq);
-
 
107
    }
-
 
108
 
-
 
109
    @Override
-
 
110
    public void validateOrderableBrands(int fofoId, Collection<String> brands) throws ProfitMandiBusinessException {
-
 
111
        List<String> ineligibleBrands = this.loiIneligibleBrands(fofoId);
-
 
112
        List<String> offendingBrands = brands.stream().filter(ineligibleBrands::contains).distinct()
-
 
113
                .collect(Collectors.toList());
-
 
114
        if (!offendingBrands.isEmpty()) {
-
 
115
            String message = "Brand ( " + String.join(", ", offendingBrands) + ") is not allowed for this partner";
-
 
116
            throw new ProfitMandiBusinessException("Brand is not allowed", offendingBrands, message);
-
 
117
        }
-
 
118
        blockedBrandService.validateBrandsAllowed(fofoId, brands);
-
 
119
    }
-
 
120
 
-
 
121
    // LOI eligibility only applies to real, non-internal partner stores; identities
-
 
122
    // without a fofo_store row degrade to blocked-only restriction.
-
 
123
    private List<String> loiIneligibleBrands(int fofoId) throws ProfitMandiBusinessException {
-
 
124
        if (fofoId == Utils.SYSTEM_PARTNER_ID) {
-
 
125
            return new ArrayList<>();
-
 
126
        }
-
 
127
        FofoStore fofoStore;
-
 
128
        try {
-
 
129
            fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
130
        } catch (ProfitMandiBusinessException e) {
-
 
131
            return new ArrayList<>();
-
 
132
        }
-
 
133
        if (fofoStore == null || fofoStore.isInternal()) {
-
 
134
            return new ArrayList<>();
-
 
135
        }
-
 
136
        return this.partnerIneligibleBrands(fofoId);
-
 
137
    }
-
 
138
 
-
 
139
    @Override
91
    public List<BrandCatalog> getAllActiveBrands() throws ProfitMandiBusinessException {
140
    public List<BrandCatalog> getAllActiveBrands() throws ProfitMandiBusinessException {
92
        List<BrandCategory> brandCategories = brandCategoryRepository.selectAllActive();
141
        List<BrandCategory> brandCategories = brandCategoryRepository.selectAllActive();
93
 
142
 
94
        Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
143
        Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
95
                .collect(Collectors.toMap(BrandCategory::getBrandId, x -> x, (a, b) -> a));
144
                .collect(Collectors.toMap(BrandCategory::getBrandId, x -> x, (a, b) -> a));