Subversion Repositories SmartDukaan

Rev

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

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