Java Controller and Service - Implement Getter and Setter in Service [closed]











up vote
0
down vote

favorite












I have the following code :



UserController.java :



@RequestMapping(value = "/user/getUser")
@ResponseBody
public Map<String, Object> getUser(@ModelAttribute UserRequestModel userRequest, HttpServletRequest request)
throws Exception {
final IContext context = contextFactory.getContext(request);
Map<String, Object> responseMap = new HashMap<>();

String UserID = userService.getUserID(context, userRequest.getName());

if (UserID != null) {
UserDetails userDetails = userService.getUserDetails(context, userID);
if (userDetails != null) {
responseMap = userService.mapResponse(
context, userID, userDetails);
}
}

return responseMap;
}

------
@RequestMapping(value = "/user/Booking")
@ResponseBody
public Map<String, Object> Booking(@RequestParam("bookingRequest") String RequestAsJSON,HttpServletRequest request) throws Exception {
Map<String, Object> responseMap = new HashMap<>();

final IContext context = contextFactory.getContext(request);
UserList userList = userService.getUserList(context, RequestAsJSON);
IUserResponse userresponse = userService.createBooking(RequestAsJSON, context, userList);
return responseMap;
}


Also following Service class:
UserService.java :



  @Override
public String getUserID(IContext requestContext, String userName) {
String userID = null;
List<User> users = createUser(context, userName);
userID = <API>.getID(context, userList);
return userID;
}


@Override
public UserDetails getUserDetails(IContext context, String userID) {
UserDetails userDetails = null;
userDetails = <API>.getUserDetails(userID, context);
return userDetails;
}


@Override


public UserList getUserList(IContext context, String requestAsJSON) {
JsonObject requestObj = new JsonParser().parse(requestAsJSON).getAsJsonObject();
String userName = requestObj.get("Name").getAsString();
UserCard userCard = createCard(userName);
List<User> users = new ArrayList<>();
users.add(userCard);
UserList userList = new UserList();
userList.setUsers(users);
..

return userList;
}
....
private List<User> createUser(IContext context, String userName) {
List<User> users = new ArrayList<>();
UserCard userCard = createCard(userName);
users.add(userCard);
return users;
}
private UserCard createCard(String userName) {
UserCard userCard = new UserCard();
userCard.setOfficeID(12345);
userCard.setAddress("Addr1");
userCard.setOffice(“Test”);
return userCard;
}


I would like to get get help in this code implementation.
Currently createCard method is calling twice when getting user ("/user/getUser") and booking ("/user/Booking"). I would like to createCard while "/user/getUser" and get this card while "/user/Booking".










share|improve this question













closed as off-topic by Hosch250, 200_success, Jamal Dec 2 at 8:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Hosch250, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.













  • I['d like help in] implementation and Currently [a does b]. I would like [c] does not read I'd appreciate insights, opinions and advice on this working code: your post looks off topic on Code Review@SE.
    – greybeard
    Dec 1 at 15:32















up vote
0
down vote

favorite












I have the following code :



UserController.java :



@RequestMapping(value = "/user/getUser")
@ResponseBody
public Map<String, Object> getUser(@ModelAttribute UserRequestModel userRequest, HttpServletRequest request)
throws Exception {
final IContext context = contextFactory.getContext(request);
Map<String, Object> responseMap = new HashMap<>();

String UserID = userService.getUserID(context, userRequest.getName());

if (UserID != null) {
UserDetails userDetails = userService.getUserDetails(context, userID);
if (userDetails != null) {
responseMap = userService.mapResponse(
context, userID, userDetails);
}
}

return responseMap;
}

------
@RequestMapping(value = "/user/Booking")
@ResponseBody
public Map<String, Object> Booking(@RequestParam("bookingRequest") String RequestAsJSON,HttpServletRequest request) throws Exception {
Map<String, Object> responseMap = new HashMap<>();

final IContext context = contextFactory.getContext(request);
UserList userList = userService.getUserList(context, RequestAsJSON);
IUserResponse userresponse = userService.createBooking(RequestAsJSON, context, userList);
return responseMap;
}


Also following Service class:
UserService.java :



  @Override
public String getUserID(IContext requestContext, String userName) {
String userID = null;
List<User> users = createUser(context, userName);
userID = <API>.getID(context, userList);
return userID;
}


@Override
public UserDetails getUserDetails(IContext context, String userID) {
UserDetails userDetails = null;
userDetails = <API>.getUserDetails(userID, context);
return userDetails;
}


@Override


public UserList getUserList(IContext context, String requestAsJSON) {
JsonObject requestObj = new JsonParser().parse(requestAsJSON).getAsJsonObject();
String userName = requestObj.get("Name").getAsString();
UserCard userCard = createCard(userName);
List<User> users = new ArrayList<>();
users.add(userCard);
UserList userList = new UserList();
userList.setUsers(users);
..

return userList;
}
....
private List<User> createUser(IContext context, String userName) {
List<User> users = new ArrayList<>();
UserCard userCard = createCard(userName);
users.add(userCard);
return users;
}
private UserCard createCard(String userName) {
UserCard userCard = new UserCard();
userCard.setOfficeID(12345);
userCard.setAddress("Addr1");
userCard.setOffice(“Test”);
return userCard;
}


I would like to get get help in this code implementation.
Currently createCard method is calling twice when getting user ("/user/getUser") and booking ("/user/Booking"). I would like to createCard while "/user/getUser" and get this card while "/user/Booking".










share|improve this question













closed as off-topic by Hosch250, 200_success, Jamal Dec 2 at 8:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Hosch250, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.













  • I['d like help in] implementation and Currently [a does b]. I would like [c] does not read I'd appreciate insights, opinions and advice on this working code: your post looks off topic on Code Review@SE.
    – greybeard
    Dec 1 at 15:32













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have the following code :



UserController.java :



@RequestMapping(value = "/user/getUser")
@ResponseBody
public Map<String, Object> getUser(@ModelAttribute UserRequestModel userRequest, HttpServletRequest request)
throws Exception {
final IContext context = contextFactory.getContext(request);
Map<String, Object> responseMap = new HashMap<>();

String UserID = userService.getUserID(context, userRequest.getName());

if (UserID != null) {
UserDetails userDetails = userService.getUserDetails(context, userID);
if (userDetails != null) {
responseMap = userService.mapResponse(
context, userID, userDetails);
}
}

return responseMap;
}

------
@RequestMapping(value = "/user/Booking")
@ResponseBody
public Map<String, Object> Booking(@RequestParam("bookingRequest") String RequestAsJSON,HttpServletRequest request) throws Exception {
Map<String, Object> responseMap = new HashMap<>();

final IContext context = contextFactory.getContext(request);
UserList userList = userService.getUserList(context, RequestAsJSON);
IUserResponse userresponse = userService.createBooking(RequestAsJSON, context, userList);
return responseMap;
}


Also following Service class:
UserService.java :



  @Override
public String getUserID(IContext requestContext, String userName) {
String userID = null;
List<User> users = createUser(context, userName);
userID = <API>.getID(context, userList);
return userID;
}


@Override
public UserDetails getUserDetails(IContext context, String userID) {
UserDetails userDetails = null;
userDetails = <API>.getUserDetails(userID, context);
return userDetails;
}


@Override


public UserList getUserList(IContext context, String requestAsJSON) {
JsonObject requestObj = new JsonParser().parse(requestAsJSON).getAsJsonObject();
String userName = requestObj.get("Name").getAsString();
UserCard userCard = createCard(userName);
List<User> users = new ArrayList<>();
users.add(userCard);
UserList userList = new UserList();
userList.setUsers(users);
..

return userList;
}
....
private List<User> createUser(IContext context, String userName) {
List<User> users = new ArrayList<>();
UserCard userCard = createCard(userName);
users.add(userCard);
return users;
}
private UserCard createCard(String userName) {
UserCard userCard = new UserCard();
userCard.setOfficeID(12345);
userCard.setAddress("Addr1");
userCard.setOffice(“Test”);
return userCard;
}


I would like to get get help in this code implementation.
Currently createCard method is calling twice when getting user ("/user/getUser") and booking ("/user/Booking"). I would like to createCard while "/user/getUser" and get this card while "/user/Booking".










share|improve this question













I have the following code :



UserController.java :



@RequestMapping(value = "/user/getUser")
@ResponseBody
public Map<String, Object> getUser(@ModelAttribute UserRequestModel userRequest, HttpServletRequest request)
throws Exception {
final IContext context = contextFactory.getContext(request);
Map<String, Object> responseMap = new HashMap<>();

String UserID = userService.getUserID(context, userRequest.getName());

if (UserID != null) {
UserDetails userDetails = userService.getUserDetails(context, userID);
if (userDetails != null) {
responseMap = userService.mapResponse(
context, userID, userDetails);
}
}

return responseMap;
}

------
@RequestMapping(value = "/user/Booking")
@ResponseBody
public Map<String, Object> Booking(@RequestParam("bookingRequest") String RequestAsJSON,HttpServletRequest request) throws Exception {
Map<String, Object> responseMap = new HashMap<>();

final IContext context = contextFactory.getContext(request);
UserList userList = userService.getUserList(context, RequestAsJSON);
IUserResponse userresponse = userService.createBooking(RequestAsJSON, context, userList);
return responseMap;
}


Also following Service class:
UserService.java :



  @Override
public String getUserID(IContext requestContext, String userName) {
String userID = null;
List<User> users = createUser(context, userName);
userID = <API>.getID(context, userList);
return userID;
}


@Override
public UserDetails getUserDetails(IContext context, String userID) {
UserDetails userDetails = null;
userDetails = <API>.getUserDetails(userID, context);
return userDetails;
}


@Override


public UserList getUserList(IContext context, String requestAsJSON) {
JsonObject requestObj = new JsonParser().parse(requestAsJSON).getAsJsonObject();
String userName = requestObj.get("Name").getAsString();
UserCard userCard = createCard(userName);
List<User> users = new ArrayList<>();
users.add(userCard);
UserList userList = new UserList();
userList.setUsers(users);
..

return userList;
}
....
private List<User> createUser(IContext context, String userName) {
List<User> users = new ArrayList<>();
UserCard userCard = createCard(userName);
users.add(userCard);
return users;
}
private UserCard createCard(String userName) {
UserCard userCard = new UserCard();
userCard.setOfficeID(12345);
userCard.setAddress("Addr1");
userCard.setOffice(“Test”);
return userCard;
}


I would like to get get help in this code implementation.
Currently createCard method is calling twice when getting user ("/user/getUser") and booking ("/user/Booking"). I would like to createCard while "/user/getUser" and get this card while "/user/Booking".







java spring






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 1 at 13:31









Futuregeek

1011




1011




closed as off-topic by Hosch250, 200_success, Jamal Dec 2 at 8:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Hosch250, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Hosch250, 200_success, Jamal Dec 2 at 8:07


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Hosch250, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.












  • I['d like help in] implementation and Currently [a does b]. I would like [c] does not read I'd appreciate insights, opinions and advice on this working code: your post looks off topic on Code Review@SE.
    – greybeard
    Dec 1 at 15:32


















  • I['d like help in] implementation and Currently [a does b]. I would like [c] does not read I'd appreciate insights, opinions and advice on this working code: your post looks off topic on Code Review@SE.
    – greybeard
    Dec 1 at 15:32
















I['d like help in] implementation and Currently [a does b]. I would like [c] does not read I'd appreciate insights, opinions and advice on this working code: your post looks off topic on Code Review@SE.
– greybeard
Dec 1 at 15:32




I['d like help in] implementation and Currently [a does b]. I would like [c] does not read I'd appreciate insights, opinions and advice on this working code: your post looks off topic on Code Review@SE.
– greybeard
Dec 1 at 15:32















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Сан-Квентин

8-я гвардейская общевойсковая армия

Алькесар