Subversion Repositories SmartDukaan

Rev

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

Rev 21390 Rev 21426
Line 37... Line 37...
37
	public ResponseEntity<?> createApi(HttpServletRequest request){
37
	public ResponseEntity<?> createApi(HttpServletRequest request){
38
		LOGGER.info("requested url : "+request.getRequestURL().toString());
38
		LOGGER.info("requested url : "+request.getRequestURL().toString());
39
		final Api api = (Api)request.getAttribute(ProfitMandiConstants.API);
39
		final Api api = (Api)request.getAttribute(ProfitMandiConstants.API);
40
		request.removeAttribute(ProfitMandiConstants.API);
40
		request.removeAttribute(ProfitMandiConstants.API);
41
		try {
41
		try {
42
			api.setCreateTimestamp(LocalDateTime.now());
-
 
43
			api.setUpdateTimestamp(LocalDateTime.now());
-
 
44
			apiRepository.persist(api);
42
			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"));
43
			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);
44
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
47
		}catch (ProfitMandiBusinessException pmbe) {
45
		}catch (ProfitMandiBusinessException pmbe) {
48
			LOGGER.error("ProfitMandi error: ", pmbe);
46
			LOGGER.error("ProfitMandi error: ", pmbe);
49
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
47
			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);
48
			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);
49
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
52
		}catch (Exception e) {
-
 
53
			LOGGER.error("Internal Server Error : ",e);
-
 
54
			final Response response=new Response("","","", e.getMessage());
-
 
55
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
-
 
56
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
57
		}
50
		}
58
	}
51
	}
59
	
52
	
60
	@RequestMapping(value = ProfitMandiConstants.URL_API_ALL,method=RequestMethod.GET)
53
	@RequestMapping(value = ProfitMandiConstants.URL_API_ALL,method=RequestMethod.GET)
61
	public ResponseEntity<?> getAll(HttpServletRequest request){
54
	public ResponseEntity<?> getAll(HttpServletRequest request){
62
		LOGGER.info("requested url : "+request.getRequestURL().toString());
55
		LOGGER.info("requested url : "+request.getRequestURL().toString());
63
		try {
-
 
64
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectAll());
56
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectAll());
65
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
57
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
66
		}catch (Exception e) {
-
 
67
			LOGGER.error("Internal Server Error : ",e);
-
 
68
			final Response response=new Response("","","", e.getMessage());
-
 
69
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
58
		
70
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
71
		}
-
 
72
	}
59
	}
73
	@RequestMapping(value = ProfitMandiConstants.URL_API_ID,method=RequestMethod.GET)
60
	@RequestMapping(value = ProfitMandiConstants.URL_API_ID,method=RequestMethod.GET)
74
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
61
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
75
		LOGGER.info("requested url : "+request.getRequestURL().toString());
62
		LOGGER.info("requested url : "+request.getRequestURL().toString());
76
		try {
63
		try {
77
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectById(id));
64
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectById(id));
78
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
65
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
79
		}catch (ProfitMandiBusinessException pmbe) {
66
		}catch (ProfitMandiBusinessException pmbe) {
80
			LOGGER.error("ProfitMandi error: ", pmbe);
67
			LOGGER.error("ProfitMandi error: ", pmbe);
81
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
68
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
82
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
69
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
83
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
70
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
84
		}catch (Exception e) {
-
 
85
			LOGGER.error("Internal Server Error : ",e);
-
 
86
			final Response response=new Response("","","", e.getMessage());
-
 
87
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
-
 
88
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
89
		}
71
		}
90
	}
72
	}
91
	
73
	
92
	@RequestMapping(value = ProfitMandiConstants.URL_API_NAME,method=RequestMethod.GET)
74
	@RequestMapping(value = ProfitMandiConstants.URL_API_NAME,method=RequestMethod.GET)
93
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
75
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
Line 98... Line 80...
98
		}catch (ProfitMandiBusinessException pmbe) {
80
		}catch (ProfitMandiBusinessException pmbe) {
99
			LOGGER.error("ProfitMandi error: ", pmbe);
81
			LOGGER.error("ProfitMandi error: ", pmbe);
100
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
82
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
101
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
83
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
102
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
84
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
103
		}catch (Exception e) {
-
 
104
			LOGGER.error("Internal Server Error : ",e);
-
 
105
			final Response response=new Response("","","", e.getMessage());
-
 
106
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
-
 
107
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
108
		}
85
		}
109
	}
86
	}
110
	
87
	
111
	@RequestMapping(value = ProfitMandiConstants.URL_API_URI,method=RequestMethod.GET)
88
	@RequestMapping(value = ProfitMandiConstants.URL_API_URI,method=RequestMethod.GET)
112
	public ResponseEntity<?> getByUri(HttpServletRequest request, @RequestParam(name = "uri") String uri){
89
	public ResponseEntity<?> getByUri(HttpServletRequest request, @RequestParam(name = "uri") String uri){
113
		LOGGER.info("requested url : "+request.getRequestURL().toString());
90
		LOGGER.info("requested url : "+request.getRequestURL().toString());
114
		try {
-
 
115
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectByUri(uri));
91
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, apiRepository.selectByUri(uri));
116
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
92
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
117
		}catch (Exception e) {
-
 
118
			LOGGER.error("Internal Server error : ",e);
-
 
119
			final Response response=new Response("","","", e.getMessage());
-
 
120
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
93
		
121
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
122
		}
-
 
123
	}
94
	}
124
	
95
	
125
	@RequestMapping(value = ProfitMandiConstants.URL_API_ID,method=RequestMethod.DELETE)
96
	@RequestMapping(value = ProfitMandiConstants.URL_API_ID,method=RequestMethod.DELETE)
126
	public ResponseEntity<?> deleteById(HttpServletRequest request, @RequestParam(name = "id") int id){
97
	public ResponseEntity<?> deleteById(HttpServletRequest request, @RequestParam(name = "id") long id){
127
		LOGGER.info("requested url : "+request.getRequestURL().toString());
98
		LOGGER.info("requested url : "+request.getRequestURL().toString());
128
		try {
99
		try {
129
			apiRepository.deleteById(id);
100
			apiRepository.deleteById(id);
130
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
101
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
131
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
102
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
132
		}catch (ProfitMandiBusinessException pmbe) {
103
		}catch (ProfitMandiBusinessException pmbe) {
133
			LOGGER.error("ProfitMandi error: ", pmbe);
104
			LOGGER.error("ProfitMandi error: ", pmbe);
134
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
105
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
135
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
106
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
136
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
107
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
137
		}catch (Exception e) {
-
 
138
			LOGGER.error("Internal Server error : ",e);
-
 
139
			final Response response=new Response("","","", e.getMessage());
-
 
140
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
-
 
141
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
142
		}
108
		}
143
	}
109
	}
144
	
110
	
145
	@SuppressWarnings("unchecked")
111
	@SuppressWarnings("unchecked")
146
	@RequestMapping(value = ProfitMandiConstants.URL_API,method=RequestMethod.PUT)
112
	@RequestMapping(value = ProfitMandiConstants.URL_API,method=RequestMethod.PUT)
Line 155... Line 121...
155
		}catch (ProfitMandiBusinessException pmbe) {
121
		}catch (ProfitMandiBusinessException pmbe) {
156
			LOGGER.error("ProfitMandi error: ", pmbe);
122
			LOGGER.error("ProfitMandi error: ", pmbe);
157
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
123
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
158
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
124
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
159
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
125
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
160
		}catch (Exception e) {
-
 
161
			LOGGER.error("Internal Server Error : ",e);
-
 
162
			final Response response=new Response("","","", e.getMessage());
-
 
163
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
-
 
164
			return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
165
		}
126
		}
166
	}
127
	}
167
		
128
		
168
}
129
}