Subversion Repositories SmartDukaan

Rev

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

Rev 23568 Rev 25427
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.util.HashMap;
-
 
4
import java.util.Map;
-
 
5
 
-
 
6
import javax.servlet.http.HttpServletRequest;
3
import javax.servlet.http.HttpServletRequest;
7
 
4
 
8
import org.apache.http.conn.HttpHostConnectException;
-
 
9
import org.apache.logging.log4j.Logger;
-
 
10
import org.apache.logging.log4j.LogManager;
5
import org.apache.logging.log4j.LogManager;
-
 
6
import org.apache.logging.log4j.Logger;
11
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.beans.factory.annotation.Value;
-
 
13
import org.springframework.http.MediaType;
8
import org.springframework.http.MediaType;
14
import org.springframework.http.ResponseEntity;
9
import org.springframework.http.ResponseEntity;
15
import org.springframework.stereotype.Controller;
10
import org.springframework.stereotype.Controller;
16
import org.springframework.web.bind.annotation.PathVariable;
11
import org.springframework.web.bind.annotation.PathVariable;
17
import org.springframework.web.bind.annotation.RequestMapping;
12
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestMethod;
13
import org.springframework.web.bind.annotation.RequestMethod;
19
 
14
 
20
import com.google.gson.Gson;
-
 
21
import com.spice.profitmandi.common.enumuration.SchemeType;
-
 
22
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
23
import com.spice.profitmandi.common.model.ProfitMandiConstants;
15
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24
import com.spice.profitmandi.common.web.client.RestClient;
-
 
25
import com.spice.profitmandi.common.web.util.ResponseSender;
16
import com.spice.profitmandi.common.web.util.ResponseSender;
-
 
17
import com.spice.profitmandi.dao.model.ContentPojo;
-
 
18
import com.spice.profitmandi.dao.repository.dtr.Mongo;
26
import com.spice.profitmandi.web.res.EntityResponse;
19
import com.spice.profitmandi.web.res.EntityResponse;
27
 
20
 
28
import io.swagger.annotations.ApiImplicitParam;
21
import io.swagger.annotations.ApiImplicitParam;
29
import io.swagger.annotations.ApiImplicitParams;
22
import io.swagger.annotations.ApiImplicitParams;
30
import io.swagger.annotations.ApiOperation;
23
import io.swagger.annotations.ApiOperation;
31
 
24
 
32
@Controller
25
@Controller
33
public class EntityController {
26
public class EntityController {
34
 
27
 
35
	private static final Logger logger=LogManager.getLogger(EntityController.class);
28
	private static final Logger logger = LogManager.getLogger(EntityController.class);
36
	
-
 
37
	@Value("${saholic.api.host}")
-
 
38
	private String host;
-
 
39
	
29
 
40
	@Value("${saholic.api.port}")
-
 
41
	private int port;
30
	@Autowired
42
	
-
 
43
	@Value("${saholic.api.webapp}")
-
 
44
	private String webapp;
31
	private Mongo mongo;
45
	
32
 
46
	@Autowired
33
	@Autowired
47
	private ResponseSender<?> responseSender;
34
	private ResponseSender<?> responseSender;
48
	
35
 
49
	@RequestMapping(value = ProfitMandiConstants.URL_ENTITY, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
36
	@RequestMapping(value = ProfitMandiConstants.URL_ENTITY, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
50
	@ApiImplicitParams({
37
	@ApiImplicitParams({
51
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
38
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
52
				required = true, dataType = "string", paramType = "header")
-
 
53
	})
-
 
54
	
39
 
55
	@ApiOperation(value = "Get entity content")
40
	@ApiOperation(value = "Get entity content")
56
	public ResponseEntity<?> getEntity(HttpServletRequest request, @PathVariable(value="entityId") String entityId)throws ProfitMandiBusinessException{
41
	public ResponseEntity<?> getEntity(HttpServletRequest request, @PathVariable(value = "entityId") long entityId)
-
 
42
			throws Exception {
57
		logger.info("Entity Id "+entityId);
43
		logger.info("Entity Id " + entityId);
58
		RestClient rc = new RestClient();
-
 
59
		Map<String, String> params = new HashMap<String, String>();
-
 
60
		String response = null;
-
 
61
		String uri = webapp+"/entity/"+entityId;
44
		ContentPojo cp = mongo.getEntityById(entityId);
62
		EntityResponse entityResponse=null;
45
		EntityResponse er = new EntityResponse();
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
		}
-
 
68
		
-
 
69
		Gson gson = new Gson();
46
		er.setEntity(cp);
70
		entityResponse = gson.fromJson(response, EntityResponse.class);
-
 
71
		return responseSender.ok(entityResponse);
47
		return responseSender.ok(er);
72
	}
48
	}
73
 
-
 
74
 
-
 
75
	
-
 
76
 
-
 
77
}
49
}