Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
Freshpass Poc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Giridhari Sahoo
Freshpass Poc
Commits
2f5528af
Commit
2f5528af
authored
Nov 21, 2024
by
Giridhari Sahoo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement validation logic
parent
38f70dba
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
198 additions
and
0 deletions
+198
-0
EmployeeServiceException.java
...m/nisum/Employeeinfo/advice/EmployeeServiceException.java
+53
-0
ApiError.java
src/main/java/com/nisum/Employeeinfo/errorcode/ApiError.java
+45
-0
ApiErrorCode.java
...n/java/com/nisum/Employeeinfo/errorcode/ApiErrorCode.java
+29
-0
EmployeeNotFoundException.java
...sum/Employeeinfo/exception/EmployeeNotFoundException.java
+22
-0
ExceptionResponse.java
...a/com/nisum/Employeeinfo/exception/ExceptionResponse.java
+26
-0
InvalidEmployeeDataException.java
.../Employeeinfo/exception/InvalidEmployeeDataException.java
+19
-0
CommonServiceValidator.java
.../nisum/Employeeinfo/validator/CommonServiceValidator.java
+4
-0
No files found.
src/main/java/com/nisum/Employeeinfo/advice/EmployeeServiceException.java
0 → 100644
View file @
2f5528af
package
com
.
nisum
.
Employeeinfo
.
advice
;
import
com.nisum.Employeeinfo.errorcode.ApiError
;
import
com.nisum.Employeeinfo.errorcode.ApiErrorCode
;
import
com.nisum.Employeeinfo.exception.EmployeeNotFoundException
;
import
com.nisum.Employeeinfo.exception.ExceptionResponse
;
import
com.nisum.Employeeinfo.exception.InvalidEmployeeDataException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.RestControllerAdvice
;
@RestControllerAdvice
public
class
EmployeeServiceException
{
@ExceptionHandler
(
EmployeeNotFoundException
.
class
)
public
ResponseEntity
<
Object
>
handleEmployeeNotFoundException
(
EmployeeNotFoundException
ex
,
ServerHttpRequest
serverHttpRequest
){
ApiError
apiError
=
new
ApiError
(
ex
.
getErrorCode
(),
ex
.
getMessage
(),
serverHttpRequest
.
getURI
().
getPath
()
);
ExceptionResponse
response
=
new
ExceptionResponse
(
apiError
);
return
new
ResponseEntity
<>(
response
,
HttpStatus
.
NOT_FOUND
);
}
@ExceptionHandler
(
InvalidEmployeeDataException
.
class
)
public
ResponseEntity
<
Object
>
handleInvalidEmployeeData
(
InvalidEmployeeDataException
ex
,
ServerHttpRequest
serverHttpRequest
){
ApiError
apiError
=
new
ApiError
(
ex
.
getErrorCode
(),
ex
.
getMessage
(),
serverHttpRequest
.
getURI
().
getPath
()
);
ExceptionResponse
response
=
new
ExceptionResponse
(
apiError
);
return
new
ResponseEntity
<>(
response
,
HttpStatus
.
BAD_REQUEST
);
}
@ExceptionHandler
(
Exception
.
class
)
public
ResponseEntity
<
Object
>
handleGeneralException
(
Exception
ex
,
ServerHttpRequest
serverHttpRequest
){
ApiError
apiError
=
new
ApiError
(
ApiErrorCode
.
GENERAL_ERROR
.
getString
(),
ex
.
getMessage
(),
serverHttpRequest
.
getURI
().
getPath
()
);
ExceptionResponse
response
=
new
ExceptionResponse
(
apiError
);
return
new
ResponseEntity
<>(
response
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
}
src/main/java/com/nisum/Employeeinfo/errorcode/ApiError.java
0 → 100644
View file @
2f5528af
package
com
.
nisum
.
Employeeinfo
.
errorcode
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
public
class
ApiError
{
@JsonProperty
(
"errorCode"
)
private
String
errorCode
;
@JsonProperty
(
"errorMessage"
)
private
String
errorMessage
;
@JsonProperty
(
"uri"
)
private
String
uri
;
public
ApiError
(
String
errorCode
,
String
errorMessage
,
String
uri
)
{
this
.
errorCode
=
errorCode
;
this
.
errorMessage
=
errorMessage
;
this
.
uri
=
uri
;
}
public
String
getErrorCode
()
{
return
errorCode
;
}
public
void
setErrorCode
(
String
errorCode
)
{
this
.
errorCode
=
errorCode
;
}
public
String
getErrorMessage
()
{
return
errorMessage
;
}
public
void
setErrorMessage
(
String
errorMessage
)
{
this
.
errorMessage
=
errorMessage
;
}
public
String
getUri
()
{
return
uri
;
}
public
void
setUri
(
String
uri
)
{
this
.
uri
=
uri
;
}
}
src/main/java/com/nisum/Employeeinfo/errorcode/ApiErrorCode.java
0 → 100644
View file @
2f5528af
package
com
.
nisum
.
Employeeinfo
.
errorcode
;
import
com.fasterxml.jackson.annotation.JsonValue
;
public
enum
ApiErrorCode
{
EMPLOYEE_NOT_FOUND
(
"EMPLOYEE_404"
),
INVALID_EMPLOYEE_DATA
(
"EMPLOYEE_400"
),
EMPLOYEE_CREATION_FAILED
(
"EMPLOYEE_500"
),
EMPLOYEE_UPDATE_FAILED
(
"EMPLOYEE_500"
),
EMPLOYEE_DELETION_FAILED
(
"EMPLOYEE_500"
),
GENERAL_ERROR
(
"GENERAL_500"
);
private
final
String
errorCode
;
// Constructor
private
ApiErrorCode
(
String
errorCode
)
{
this
.
errorCode
=
errorCode
;
}
// Method to return the error code as a string
@JsonValue
public
String
getString
()
{
return
this
.
errorCode
;
}
}
src/main/java/com/nisum/Employeeinfo/exception/EmployeeNotFoundException.java
0 → 100644
View file @
2f5528af
package
com
.
nisum
.
Employeeinfo
.
exception
;
import
com.nisum.Employeeinfo.errorcode.ApiErrorCode
;
public
class
EmployeeNotFoundException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
-
4918194282229127629L
;
private
final
String
errorCode
;
// Constructor that accepts ApiErrorCode and message
public
EmployeeNotFoundException
(
ApiErrorCode
apiErrorCode
,
String
message
)
{
super
(
message
);
// Pass message to RuntimeException constructor
this
.
errorCode
=
apiErrorCode
.
getString
();
// Store the error code from ApiErrorCode
}
// Getter for errorCode
public
String
getErrorCode
()
{
return
errorCode
;
}
}
src/main/java/com/nisum/Employeeinfo/exception/ExceptionResponse.java
0 → 100644
View file @
2f5528af
package
com
.
nisum
.
Employeeinfo
.
exception
;
import
com.nisum.Employeeinfo.errorcode.ApiError
;
public
class
ExceptionResponse
{
private
ApiError
apiError
;
public
ExceptionResponse
(
ApiError
error
)
{
apiError
=
new
ApiError
(
error
.
getErrorCode
(),
error
.
getErrorMessage
(),
error
.
getUri
()
);
}
public
ApiError
getApiError
()
{
return
apiError
;
}
public
void
setApiError
(
ApiError
apiError
)
{
this
.
apiError
=
apiError
;
}
}
src/main/java/com/nisum/Employeeinfo/exception/InvalidEmployeeDataException.java
0 → 100644
View file @
2f5528af
package
com
.
nisum
.
Employeeinfo
.
exception
;
import
com.nisum.Employeeinfo.errorcode.ApiErrorCode
;
public
class
InvalidEmployeeDataException
extends
RuntimeException
{
private
final
String
errorCode
;
public
InvalidEmployeeDataException
(
ApiErrorCode
errorCode
,
String
message
){
super
(
message
);
this
.
errorCode
=
errorCode
.
getString
();
}
public
String
getErrorCode
()
{
return
errorCode
;
}
}
src/main/java/com/nisum/Employeeinfo/validator/CommonServiceValidator.java
0 → 100644
View file @
2f5528af
package
com
.
nisum
.
Employeeinfo
.
validator
;
public
class
CommonServiceValidator
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment