Subversion Repositories SmartDukaan

Rev

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