Subversion Repositories SmartDukaan

Rev

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

Rev 21581 Rev 21612
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import java.util.HashSet;
3
import java.util.List;
4
import java.util.List;
-
 
5
import java.util.Set;
4
 
6
 
5
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletRequest;
6
 
8
 
7
import org.slf4j.Logger;
9
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
10
import org.slf4j.LoggerFactory;
Line 13... Line 15...
13
import org.springframework.web.bind.annotation.ModelAttribute;
15
import org.springframework.web.bind.annotation.ModelAttribute;
14
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestParam;
17
import org.springframework.web.bind.annotation.RequestParam;
16
 
18
 
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
20
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
18
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.dao.entity.CurrentInventorySnapshot;
-
 
20
import com.spice.profitmandi.dao.entity.FofoItemId;
22
import com.spice.profitmandi.dao.entity.FofoItemId;
21
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
23
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
22
import com.spice.profitmandi.web.model.FofoDetails;
24
import com.spice.profitmandi.web.model.FofoDetails;
23
import com.spice.profitmandi.web.util.CookiesFetcher;
25
import com.spice.profitmandi.web.util.CookiesFetcher;
24
import com.spice.profitmandi.web.util.MVCResponseSender;
26
import com.spice.profitmandi.web.util.MVCResponseSender;
Line 44... Line 46...
44
			fofoDetails = cookiesFetcher.getCookiesObject(request);
46
			fofoDetails = cookiesFetcher.getCookiesObject(request);
45
		} catch (ProfitMandiBusinessException e) {
47
		} catch (ProfitMandiBusinessException e) {
46
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
48
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
47
			return "response";
49
			return "response";
48
		}
50
		}
49
		try{
-
 
50
			List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.getByFofoId(fofoDetails.getFofoId());
51
		List<Object[]> rows = currentInventorySnapshotRepository.selectCustomByFofoId(fofoDetails.getFofoId());
-
 
52
		
51
			model.addAttribute("currentInventorySnapshots", currentInventorySnapshots);
53
		model.addAttribute("currentInventorySnapshots", this.getCustomCurrentInventorySnapshots(rows));
52
			return "dashboard";
54
		return "dashboard";
-
 
55
	}
-
 
56
	
53
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
57
	private Set<CustomCurrentInventorySnapshot> getCustomCurrentInventorySnapshots(List<Object[]> rows){
54
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
58
		Set<CustomCurrentInventorySnapshot> currentInventorySnapshots = new HashSet<>();
55
			return "response";
59
		for(Object[] row : rows){
-
 
60
			currentInventorySnapshots.add(this.createCustomCurrentInventorySnapshop(row));
56
		}
61
		}
-
 
62
		return currentInventorySnapshots;
57
	}
63
	}
58
	
64
	
-
 
65
	private CustomCurrentInventorySnapshot createCustomCurrentInventorySnapshop(Object[] row)
-
 
66
	{
-
 
67
		CustomCurrentInventorySnapshot currentInventorySnapshot = new CustomCurrentInventorySnapshot();
-
 
68
		currentInventorySnapshot.setItemId((Integer)row[0]);
-
 
69
		currentInventorySnapshot.setAvailability((Integer)row[1]);
-
 
70
		currentInventorySnapshot.setBrand((String)row[2]);
-
 
71
		currentInventorySnapshot.setModelName((String)row[3]);
-
 
72
		currentInventorySnapshot.setModelNumber((String)row[4]);
-
 
73
		currentInventorySnapshot.setColor((String)row[5]);
-
 
74
		return currentInventorySnapshot;
-
 
75
	}
59
	@RequestMapping(value = "/checkItemAvailability")
76
	@RequestMapping(value = "/checkItemAvailability")
60
	public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, @ModelAttribute Model model) throws Exception{
77
	public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, @ModelAttribute Model model) throws Exception{
61
		FofoDetails fofoDetails;
78
		FofoDetails fofoDetails;
62
		try {
79
		try {
63
			fofoDetails = cookiesFetcher.getCookiesObject(request);
80
			fofoDetails = cookiesFetcher.getCookiesObject(request);
Line 67... Line 84...
67
		}
84
		}
68
		try{
85
		try{
69
			FofoItemId fofoItemId = new FofoItemId();
86
			FofoItemId fofoItemId = new FofoItemId();
70
			fofoItemId.setFofoId(fofoDetails.getFofoId());
87
			fofoItemId.setFofoId(fofoDetails.getFofoId());
71
			fofoItemId.setItemId(itemId);
88
			fofoItemId.setItemId(itemId);
72
			CurrentInventorySnapshot currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoItemId(fofoItemId);
89
			Object[] row = currentInventorySnapshotRepository.selectCustomByFofoItemId(fofoItemId);
73
			model.addAttribute("currentInventorySnapshots", currentInventorySnapshot);
90
			model.addAttribute("currentInventorySnapshots", this.createCustomCurrentInventorySnapshop(row));
74
			return "dashboard";
91
			return "dashboard";
75
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
92
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
76
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
93
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
77
			return "response";
94
			return "response";
78
		}
95
		}