| Line 30... |
Line 30... |
| 30 |
import com.spice.profitmandi.service.catalog.CategorySpecDerivationService;
|
30 |
import com.spice.profitmandi.service.catalog.CategorySpecDerivationService;
|
| 31 |
import com.spice.profitmandi.service.catalog.CategorySpecUtil;
|
31 |
import com.spice.profitmandi.service.catalog.CategorySpecUtil;
|
| 32 |
import com.spice.profitmandi.service.catalog.ItemLoaderService;
|
32 |
import com.spice.profitmandi.service.catalog.ItemLoaderService;
|
| 33 |
import com.spice.profitmandi.web.model.EntityMediaPojo;
|
33 |
import com.spice.profitmandi.web.model.EntityMediaPojo;
|
| 34 |
import com.spice.profitmandi.web.model.LoginDetails;
|
34 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| - |
|
35 |
import com.spice.profitmandi.web.service.BrandIdentifierUploadService;
|
| - |
|
36 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| - |
|
37 |
import java.nio.charset.StandardCharsets;
|
| 35 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
38 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 36 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
39 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 37 |
import org.apache.commons.csv.CSVFormat;
|
40 |
import org.apache.commons.csv.CSVFormat;
|
| 38 |
import org.apache.commons.csv.CSVParser;
|
41 |
import org.apache.commons.csv.CSVParser;
|
| 39 |
import org.apache.commons.csv.CSVRecord;
|
42 |
import org.apache.commons.csv.CSVRecord;
|
| Line 168... |
Line 171... |
| 168 |
itemLoaderService.parse(file);
|
171 |
itemLoaderService.parse(file);
|
| 169 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
172 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 170 |
return "response";
|
173 |
return "response";
|
| 171 |
}
|
174 |
}
|
| 172 |
|
175 |
|
| - |
|
176 |
@Autowired
|
| - |
|
177 |
BrandIdentifierUploadService brandIdentifierUploadService;
|
| - |
|
178 |
|
| - |
|
179 |
@Autowired
|
| - |
|
180 |
ObjectMapper objectMapper;
|
| - |
|
181 |
|
| - |
|
182 |
/**
|
| - |
|
183 |
* CSV itemId,brandIdentifier -> catalog.item.brand_identifier, replacing existing values.
|
| - |
|
184 |
* apply=false only previews; apply=true writes, and only when no row has an error.
|
| - |
|
185 |
*/
|
| - |
|
186 |
@PostMapping(value = "/catalog/brandIdentifier/upload")
|
| - |
|
187 |
public String uploadBrandIdentifiers(HttpServletRequest request, @RequestPart("file") MultipartFile file,
|
| - |
|
188 |
@RequestParam(defaultValue = "false") boolean apply, Model model) throws Exception {
|
| - |
|
189 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
190 |
Map<String, Object> result;
|
| - |
|
191 |
try {
|
| - |
|
192 |
result = brandIdentifierUploadService.process(file.getInputStream(), apply, loginDetails.getEmailId());
|
| - |
|
193 |
} catch (IllegalArgumentException e) {
|
| - |
|
194 |
result = new HashMap<>();
|
| - |
|
195 |
result.put("message", e.getMessage());
|
| - |
|
196 |
}
|
| - |
|
197 |
model.addAttribute("response1", objectMapper.writeValueAsString(result));
|
| - |
|
198 |
return "response";
|
| - |
|
199 |
}
|
| - |
|
200 |
|
| - |
|
201 |
@GetMapping(value = "/catalog/brandIdentifier/template.csv")
|
| - |
|
202 |
public ResponseEntity<byte[]> downloadBrandIdentifierTemplate() {
|
| - |
|
203 |
HttpHeaders headers = new HttpHeaders();
|
| - |
|
204 |
headers.setContentType(MediaType.parseMediaType("text/csv"));
|
| - |
|
205 |
headers.setContentDispositionFormData("brand-identifier-template.csv", "brand-identifier-template.csv");
|
| - |
|
206 |
return new ResponseEntity<>("itemId,brandIdentifier\n".getBytes(StandardCharsets.UTF_8), headers, HttpStatus.OK);
|
| - |
|
207 |
}
|
| - |
|
208 |
|
| 173 |
// column order must match ItemLoaderService.createLoaderModel
|
209 |
// column order must match ItemLoaderService.createLoaderModel
|
| 174 |
private static final List<String> CATALOG_TEMPLATE_HEADERS = Arrays.asList("Product Group",
|
210 |
private static final List<String> CATALOG_TEMPLATE_HEADERS = Arrays.asList("Product Group",
|
| 175 |
"Category Id As per System", "Category", "HSNCode(Ensure that hsncode exists)", "Brand", "Model Number",
|
211 |
"Category Id As per System", "Category", "HSNCode(Ensure that hsncode exists)", "Brand", "Model Number",
|
| 176 |
"Model Name", "Color", "MRP", "SP", "MOP", "DP", "TP", "NLC", "Startdate", "Preferred Vendor", "Risky",
|
212 |
"Model Name", "Color", "MRP", "SP", "MOP", "DP", "TP", "NLC", "Startdate", "Preferred Vendor", "Risky",
|
| 177 |
"Weight in Kg", "Item type(1 for Serialized and 2 for non-serialized)", "TaxRate",
|
213 |
"Weight in Kg", "Item type(1 for Serialized and 2 for non-serialized)", "TaxRate",
|