Subversion Repositories SmartDukaan

Rev

Rev 21236 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21236 Rev 21248
Line 13... Line 13...
13
import org.springframework.web.bind.annotation.RequestMapping;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestMethod;
14
import org.springframework.web.bind.annotation.RequestMethod;
15
import org.springframework.web.bind.annotation.RequestParam;
15
import org.springframework.web.bind.annotation.RequestParam;
16
 
16
 
17
import com.spice.profitmandi.common.ResponseCodeHolder;
17
import com.spice.profitmandi.common.ResponseCodeHolder;
-
 
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.dao.entity.Api;
20
import com.spice.profitmandi.dao.entity.Api;
20
import com.spice.profitmandi.dao.enumuration.Method;
21
import com.spice.profitmandi.dao.enumuration.Method;
21
import com.spice.profitmandi.dao.exception.EntityAlreadyExistException;
-
 
22
import com.spice.profitmandi.dao.exception.EntityNotFoundException;
-
 
23
import com.spice.profitmandi.dao.repository.ApiRepository;
22
import com.spice.profitmandi.dao.repository.ApiRepository;
24
import com.spice.profitmandi.dao.repository.ApiRepositoryImpl;
23
import com.spice.profitmandi.dao.repository.ApiRepositoryImpl;
25
import com.spice.profitmandi.web.model.ProfitMandiResponse;
24
import com.spice.profitmandi.web.model.ProfitMandiResponse;
26
import com.spice.profitmandi.web.model.Response;
25
import com.spice.profitmandi.web.model.Response;
27
import com.spice.profitmandi.web.model.ResponseStatus;
26
import com.spice.profitmandi.web.model.ResponseStatus;
Line 42... Line 41...
42
			api.setCreateTimestamp(LocalDateTime.now());
41
			api.setCreateTimestamp(LocalDateTime.now());
43
			api.setUpdateTimestamp(LocalDateTime.now());
42
			api.setUpdateTimestamp(LocalDateTime.now());
44
			apiRepository.persist(api);
43
			apiRepository.persist(api);
45
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1000"));
44
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1000"));
46
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
45
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
47
		}catch (EntityAlreadyExistException eaee) {
46
		}catch (ProfitMandiBusinessException pmbe) {
48
			LOGGER.error("API already exist : ",eaee);
47
			LOGGER.error("ProfitMandi error: ", pmbe);
49
			final Response response=new Response(eaee.getRejectedType(), eaee.getRejectedValue(),eaee.getCode(), eaee.getMessage());
48
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
50
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
49
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
51
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
50
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
52
		}catch (Exception e) {
51
		}catch (Exception e) {
53
			LOGGER.error("Internal Server Error : ",e);
52
			LOGGER.error("Internal Server Error : ",e);
54
			final Response response=new Response("","","", e.getMessage());
53
			final Response response=new Response("","","", e.getMessage());
Line 73... Line 72...
73
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
72
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
74
		LOGGER.info("requested url : "+request.getRequestURL().toString());
73
		LOGGER.info("requested url : "+request.getRequestURL().toString());
75
		try {
74
		try {
76
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectById(id));
75
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectById(id));
77
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
76
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
78
		}catch (EntityNotFoundException enfe) {
77
		}catch (ProfitMandiBusinessException pmbe) {
79
			LOGGER.error("API not found : ",enfe);
78
			LOGGER.error("ProfitMandi error: ", pmbe);
80
			final Response response=new Response(enfe.getRejectedType(), enfe.getRejectedValue(),enfe.getCode(), enfe.getMessage());
79
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
81
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
80
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
82
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
81
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
83
		}catch (Exception e) {
82
		}catch (Exception e) {
84
			LOGGER.error("Internal Server Error : ",e);
83
			LOGGER.error("Internal Server Error : ",e);
85
			final Response response=new Response("","","", e.getMessage());
84
			final Response response=new Response("","","", e.getMessage());
Line 92... Line 91...
92
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
91
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
93
		LOGGER.info("requested url : "+request.getRequestURL().toString());
92
		LOGGER.info("requested url : "+request.getRequestURL().toString());
94
		try {
93
		try {
95
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectByName(name));
94
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectByName(name));
96
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
95
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
-
 
96
		}catch (ProfitMandiBusinessException pmbe) {
-
 
97
			LOGGER.error("ProfitMandi error: ", pmbe);
-
 
98
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
-
 
99
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
-
 
100
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
97
		}catch (Exception e) {
101
		}catch (Exception e) {
98
			LOGGER.error("Internal Server Error : ",e);
102
			LOGGER.error("Internal Server Error : ",e);
99
			final Response response=new Response("","","", e.getMessage());
103
			final Response response=new Response("","","", e.getMessage());
100
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
104
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
101
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
105
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
Line 121... Line 125...
121
		LOGGER.info("requested url : "+request.getRequestURL().toString());
125
		LOGGER.info("requested url : "+request.getRequestURL().toString());
122
		try {
126
		try {
123
			apiRepository.deleteById(id);
127
			apiRepository.deleteById(id);
124
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
128
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
125
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
129
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
126
		}catch (EntityNotFoundException enfe) {
130
		}catch (ProfitMandiBusinessException pmbe) {
127
			LOGGER.error("API not found : ",enfe);
131
			LOGGER.error("ProfitMandi error: ", pmbe);
128
			final Response response=new Response(enfe.getRejectedType(), enfe.getRejectedValue(),enfe.getCode(), enfe.getMessage());
132
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
129
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
133
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
130
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
134
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
131
		}catch (Exception e) {
135
		}catch (Exception e) {
132
			LOGGER.error("Internal Server error : ",e);
136
			LOGGER.error("Internal Server error : ",e);
133
			final Response response=new Response("","","", e.getMessage());
137
			final Response response=new Response("","","", e.getMessage());
Line 144... Line 148...
144
		request.removeAttribute(ProfitMandiConstants.UPDATE_API_MAP);
148
		request.removeAttribute(ProfitMandiConstants.UPDATE_API_MAP);
145
		try {
149
		try {
146
			apiRepository.updateNameById(updateApiMap.get(ProfitMandiConstants.NAME).toString(), updateApiMap.get(ProfitMandiConstants.URI).toString(),(Method)updateApiMap.get(ProfitMandiConstants.METHOD), (Long)updateApiMap.get(ProfitMandiConstants.ID));
150
			apiRepository.updateNameById(updateApiMap.get(ProfitMandiConstants.NAME).toString(), updateApiMap.get(ProfitMandiConstants.URI).toString(),(Method)updateApiMap.get(ProfitMandiConstants.METHOD), (Long)updateApiMap.get(ProfitMandiConstants.ID));
147
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1002"));
151
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1002"));
148
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
152
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
149
		}catch (EntityAlreadyExistException eaee) {
153
		}catch (ProfitMandiBusinessException pmbe) {
150
			LOGGER.error("API already exist : ",eaee);
154
			LOGGER.error("ProfitMandi error: ", pmbe);
151
			final Response response=new Response(eaee.getRejectedType(), eaee.getRejectedValue(),eaee.getCode(), eaee.getMessage());
-
 
152
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
-
 
153
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
-
 
154
		}catch (EntityNotFoundException enfe) {
-
 
155
			LOGGER.error("API not found : ",enfe);
-
 
156
			final Response response=new Response(enfe.getRejectedType(), enfe.getRejectedValue(),enfe.getCode(), enfe.getMessage());
155
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
157
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
156
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
158
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
157
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
159
		}catch (Exception e) {
158
		}catch (Exception e) {
160
			LOGGER.error("Internal Server Error : ",e);
159
			LOGGER.error("Internal Server Error : ",e);
161
			final Response response=new Response("","","", e.getMessage());
160
			final Response response=new Response("","","", e.getMessage());