Subversion Repositories SmartDukaan

Rev

Rev 22906 | Rev 23532 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21339 kshitij.so 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.util.HashMap;
4
import java.util.Map;
5
 
6
import javax.servlet.http.HttpServletRequest;
7
 
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
22319 amit.gupta 10
import org.springframework.beans.factory.annotation.Autowired;
21339 kshitij.so 11
import org.springframework.beans.factory.annotation.Value;
12
import org.springframework.http.MediaType;
13
import org.springframework.http.ResponseEntity;
14
import org.springframework.stereotype.Controller;
15
import org.springframework.web.bind.annotation.PathVariable;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestMethod;
18
 
19
import com.google.gson.Gson;
21643 ashik.ali 20
import com.spice.profitmandi.common.enumuration.SchemeType;
21339 kshitij.so 21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21643 ashik.ali 23
import com.spice.profitmandi.common.web.client.RestClient;
22319 amit.gupta 24
import com.spice.profitmandi.common.web.util.ResponseSender;
21339 kshitij.so 25
import com.spice.profitmandi.web.res.EntityResponse;
26
 
27
import io.swagger.annotations.ApiImplicitParam;
28
import io.swagger.annotations.ApiImplicitParams;
29
import io.swagger.annotations.ApiOperation;
30
 
31
@Controller
32
public class EntityController {
33
 
34
	private static final Logger logger=LoggerFactory.getLogger(EntityController.class);
35
 
36
	@Value("${saholic.api.host}")
37
	private String host;
22931 ashik.ali 38
 
21339 kshitij.so 39
	@Value("${saholic.api.port}")
40
	private int port;
22931 ashik.ali 41
 
21339 kshitij.so 42
	@Value("${saholic.api.webapp}")
43
	private String webapp;
44
 
22319 amit.gupta 45
	@Autowired
22931 ashik.ali 46
	private ResponseSender<?> responseSender;
22319 amit.gupta 47
 
21339 kshitij.so 48
	@RequestMapping(value = ProfitMandiConstants.URL_ENTITY, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
49
	@ApiImplicitParams({
50
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
51
				required = true, dataType = "string", paramType = "header")
52
	})
22931 ashik.ali 53
 
21339 kshitij.so 54
	@ApiOperation(value = "Get entity content")
22931 ashik.ali 55
	public ResponseEntity<?> getEntity(HttpServletRequest request, @PathVariable(value="entityId") String entityId)throws ProfitMandiBusinessException{
21339 kshitij.so 56
		logger.info("Entity Id "+entityId);
57
		RestClient rc = new RestClient(SchemeType.HTTP, host , port);
58
		Map<String, String> params = new HashMap<String, String>();
59
		String response = null;
60
		String uri = webapp+"/entity/"+entityId;
21359 kshitij.so 61
		EntityResponse entityResponse=null;
22931 ashik.ali 62
		response = rc.get(uri, params);
63
 
21339 kshitij.so 64
		Gson gson = new Gson();
21359 kshitij.so 65
		entityResponse = gson.fromJson(response, EntityResponse.class);
22319 amit.gupta 66
		return responseSender.ok(entityResponse);
21339 kshitij.so 67
	}
68
 
69
 
70
 
71
 
72
}