| 37213 |
amit |
1 |
package com.spice.profitmandi.service.catalog;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.dao.entity.catalog.CategorySpecDefinition;
|
|
|
5 |
import com.spice.profitmandi.dao.model.CategorySpecPojo;
|
|
|
6 |
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
* Pairs positional SpecValue<N> upload columns with a category's active
|
|
|
12 |
* spec definitions (external catalogMaster categorySpecs). Pure logic, no
|
|
|
13 |
* Spring wiring — the fofo content upload flow calls it per CSV row.
|
|
|
14 |
*/
|
|
|
15 |
public final class CategorySpecUtil {
|
|
|
16 |
|
|
|
17 |
private CategorySpecUtil() {
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public static List<CategorySpecPojo> pairValues(List<CategorySpecDefinition> defs, List<String> values)
|
|
|
21 |
throws ProfitMandiBusinessException {
|
|
|
22 |
List<CategorySpecPojo> specs = new ArrayList<>();
|
|
|
23 |
for (int idx = 0; idx < values.size(); idx++) {
|
|
|
24 |
String value = values.get(idx) == null ? "" : values.get(idx).trim();
|
|
|
25 |
if (value.isEmpty()) {
|
|
|
26 |
continue;
|
|
|
27 |
}
|
|
|
28 |
int position = idx + 1;
|
|
|
29 |
CategorySpecDefinition def = defAt(defs, position);
|
|
|
30 |
if (def == null) {
|
|
|
31 |
throw new ProfitMandiBusinessException("SpecValue" + position, value,
|
|
|
32 |
"No spec defined at position " + position + " for this category");
|
|
|
33 |
}
|
|
|
34 |
specs.add(new CategorySpecPojo(def.getSpecKey(), def.getDisplayLabel(), value));
|
|
|
35 |
}
|
|
|
36 |
return specs;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
private static CategorySpecDefinition defAt(List<CategorySpecDefinition> defs, int position) {
|
|
|
40 |
for (CategorySpecDefinition def : defs) {
|
|
|
41 |
if (def.getPosition() == position) {
|
|
|
42 |
return def;
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
return null;
|
|
|
46 |
}
|
|
|
47 |
}
|