Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.comakeit.strs.entites.ServiceEngineer;
import com.comakeit.strs.entites.Status;
import com.comakeit.strs.entites.User;
import com.comakeit.strs.exceptions.STRSUserNotAddedExcpetion;

@Controller
public class AdminController {
Expand All @@ -28,16 +29,18 @@ public class AdminController {

@RequestMapping("admin-Show_All_User")
public ModelAndView Show_All_User(HttpSession session) {
// get-all-users
ResponseEntity<List<User>> responseEntityUsers= restTemplate.exchange(
Constants.url + "/admin" + "/getAllUsers",
HttpMethod.GET, null,
new ParameterizedTypeReference<List<User>>() {});

List<User> listOfUsers = (List<User>) responseEntityUsers.getBody();

session.setAttribute("listOfUsers", listOfUsers);

try {
ResponseEntity<List<User>> responseEntityUsers= restTemplate.exchange(
Constants.url + "/admin" + "/getAllUsers",
HttpMethod.GET, null,
new ParameterizedTypeReference<List<User>>() {});

List<User> listOfUsers = (List<User>) responseEntityUsers.getBody();

session.setAttribute("listOfUsers", listOfUsers);
}catch(Exception e) {

}

ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("Admin.jsp?operation=Show_All_User");
Expand All @@ -48,24 +51,30 @@ public ModelAndView Show_All_User(HttpSession session) {
@RequestMapping("Add_User")
public ModelAndView addUser(User user) {

ModelAndView modelAndView = new ModelAndView();

if( user.getName().equals("") ||
user.getPassword().equals("") ||
user.getUser_name().equals("")) {
return new ModelAndView("Admin.jsp?operation=Add_user&warning=changeUserName");
}

String status = restTemplate.postForObject(
Constants.url + "/admin/addUser",
user,
String.class);

ModelAndView modelAndView = new ModelAndView();
if(status.equals("added")) {
modelAndView.setViewName("Admin.jsp?operation=addedUser");
}else if(status.equals("notAdded")) {
modelAndView.setViewName("Admin.jsp?operation=Add_user&warning=changeUserName");
try {
String status = restTemplate.postForObject(
Constants.url + "/admin/addUser",
user,
String.class);

if(status.equals("added")) {
modelAndView.setViewName("Admin.jsp?operation=addedUser");
}else if(status.equals("notAdded")) {
modelAndView.setViewName("Admin.jsp?operation=Add_user&warning=changeUserName");
}
}catch(Exception e) {

modelAndView.setViewName("Admin.jsp?operation=Add_user&warning=changeUserName");
}

return modelAndView;
}

Expand All @@ -89,11 +98,15 @@ public ModelAndView addServiceEngineer(
user.setPassword(password);
user.setUser_name(user_name);

try {
/* adding user in User Table */
user = restTemplate.postForObject(
Constants.url + "/admin/addUserServiceEngineer",
user,
User.class);
}catch(Exception e) {

}

ModelAndView modelAndView = new ModelAndView();
if(user != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,23 @@ public ModelAndView showFormRaiseTicket(HttpServletRequest request) {
public ModelAndView showAllTickets(HttpSession session) {

/* get all the tickets and put them in session and redirect to EndUser.jsp to display them */
/* listOfUsers */
ResponseEntity<List<Ticket>> responseEntityUsers= restTemplate.exchange(
Constants.url + "/ticket" + "/getAll" + "/" + session.getAttribute("user_name"),
HttpMethod.GET, null,
new ParameterizedTypeReference<List<Ticket>>() {});

List<Ticket> listOfTickets = responseEntityUsers.getBody();
session.setAttribute("listOfTickets", listOfTickets);

ModelAndView modelAndView = new ModelAndView();

try {
ResponseEntity<List<Ticket>> responseEntityUsers= restTemplate.exchange(
Constants.url + "/ticket" + "/getAll" + "/" + session.getAttribute("user_name"),
HttpMethod.GET, null,
new ParameterizedTypeReference<List<Ticket>>() {});

List<Ticket> listOfTickets = responseEntityUsers.getBody();
session.setAttribute("listOfTickets", listOfTickets);
}catch(Exception e) {

}


modelAndView.setViewName("EndUser.jsp?operation=ShowAllTickets");

return modelAndView;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.comakeit.strs.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.NO_CONTENT)
public class STRSNoContentException extends RuntimeException{

/**
*
*/
private static final long serialVersionUID = 1L;

public STRSNoContentException() {
super();
}

public STRSNoContentException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public class STRSUnAuthorizedException extends RuntimeException{

/**
*
*/
private static final long serialVersionUID = 1L;

public STRSUnAuthorizedException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.comakeit.strs.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.EXPECTATION_FAILED)
public class STRSUserNotAddedExcpetion extends RuntimeException{
private static final long serialVersionUID = 1L;

public STRSUserNotAddedExcpetion() {
super();
}

public STRSUserNotAddedExcpetion(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import com.comakeit.strs.entites.ServiceEngineer;
import com.comakeit.strs.entites.User;
import com.comakeit.strs.exceptions.STRSNoContentException;
import com.comakeit.strs.exceptions.STRSUserNotAddedExcpetion;
import com.comakeit.strs.services.AdminServices;

@RestController
Expand All @@ -23,13 +25,21 @@ public class AdminRestController {
@RequestMapping(value= "/getAllUsers",
method = RequestMethod.GET)
public List<User> getAllUses() {
return adminServices.getAllUses();
List<User> listOfUsers = adminServices.getAllUses();;
if(listOfUsers == null){
throw new STRSNoContentException("No Uses Found");
}
return listOfUsers;
}

@RequestMapping(value= "/addUser",
method = RequestMethod.POST)
public String addUser(@RequestBody User user) {
return adminServices.addUser(user);
String status = adminServices.addUser(user);
if(status == null) {
throw new STRSUserNotAddedExcpetion("User Not Added!");
}
return status;
}

@RequestMapping(value= "/addUserServiceEngineer",
Expand All @@ -44,28 +54,24 @@ public String addServiceEngineer(@RequestBody ServiceEngineer serviceEngineer) {
return adminServices.addServiceEngineer(serviceEngineer);
}

// addNewDepartment
@RequestMapping(value= "/addNewDepartment",
method = RequestMethod.POST)
public String addNewDepartment(@RequestBody HashMap<String, String> newDepartmentDetails) {
return adminServices.addNewDepartment(newDepartmentDetails);
}

// addNewStatus
@RequestMapping(value= "/addNewStatus",
method = RequestMethod.POST)
public String addNewStatus(@RequestBody HashMap<String, String> newStatusDetails) {
return adminServices.addNewStatus(newStatusDetails);
}

// addNewRole
@RequestMapping(value= "/addNewRole",
method = RequestMethod.POST)
public String addNewRole(@RequestBody HashMap<String, String> newRoleDetails) {
return adminServices.addNewRole(newRoleDetails);
}

// addNewPriority
@RequestMapping(value= "/addNewPriority",
method = RequestMethod.POST)
public String addNewPriority(@RequestBody HashMap<String, String> newPriorityDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.comakeit.strs.entites.Ticket;
import com.comakeit.strs.exceptions.STRSNoContentException;
import com.comakeit.strs.services.ServiceEngineerServices;

@RestController
Expand All @@ -26,12 +27,20 @@ public String updateTicketPriority(@RequestBody ArrayList<String> updateTicketVa

@RequestMapping(value="/getStats")
public ArrayList getAverageTimeTakenPerEngineer() {
return serviceEngineerServices.getAverageTimeTakenPerEngineer();
ArrayList averageTimeTakenPerEngineer = serviceEngineerServices.getAverageTimeTakenPerEngineer();
if(averageTimeTakenPerEngineer == null) {
throw new STRSNoContentException("No Data Found : \"Average Time Taken Per Engineer\"");
}
return averageTimeTakenPerEngineer;
}

@RequestMapping(value="/getStatsOfSeverity")
public ArrayList getAverageTimeTakenPerServerity() {
return serviceEngineerServices.getAverageTimeTakenPerServerity();
ArrayList averageTimeTakenPerServerity = serviceEngineerServices.getAverageTimeTakenPerServerity();
if(averageTimeTakenPerServerity == null) {
throw new STRSNoContentException("No Data Found : \"Average Time Taken Per Serverity\"");
}
return averageTimeTakenPerServerity;
}

@RequestMapping(value="/getAgingOfOpenTicket/{user_name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.comakeit.strs.entites.Status;
import com.comakeit.strs.exceptions.STRSNoContentException;
import com.comakeit.strs.repositories.IStatusRepository;

@RestController
Expand All @@ -18,6 +19,10 @@ public class StatusRestController {

@RequestMapping(value="/getAllStatuses")
public List<Status> getAllStatuses() {
return statusRepository.findAll();
List<Status> listOfStatus = statusRepository.findAll();
if(listOfStatus == null) {
throw new STRSNoContentException("No Statuses Found");
}
return listOfStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.comakeit.strs.entites.Ticket;
import com.comakeit.strs.exceptions.STRSNoContentException;
import com.comakeit.strs.services.TicketServices;


Expand All @@ -20,7 +21,11 @@ public class TicketRestController {

@RequestMapping(value="/getAll/{user_name}")
public List<Ticket> getAllTickets(@PathVariable(value="user_name") String user_name){
return ticketServices.getAllTickets(user_name);
List<Ticket> listOfTickets = ticketServices.getAllTickets(user_name);
if(listOfTickets == null) {
throw new STRSNoContentException("No Tickets Found");
}
return listOfTickets;
}

@RequestMapping(value="/close/{ticket_id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.comakeit.strs.entites.Role;
import com.comakeit.strs.entites.Ticket;
import com.comakeit.strs.entites.User;
import com.comakeit.strs.exceptions.STRSNoContentException;
import com.comakeit.strs.exceptions.STRSUnAuthorizedException;
//import com.comakeit.strs.entites.Priority;
//import com.comakeit.strs.entites.Role;
Expand All @@ -37,30 +38,40 @@ public Role validateAndGetRole(@RequestBody User user) {// throws STRSUnAuthoriz
System.out.println("role = in Rest = " + role);

if(role == null) {
throw new STRSUnAuthorizedException("Exception");
throw new STRSUnAuthorizedException("UnAuthorized User");
}
return role;
}

@RequestMapping(value="/getDepartments")
public List<Department> getListOfDepartment(){
return userServices.getListOfDepartment();
List<Department> listofDepartments = userServices.getListOfDepartment();
if(listofDepartments == null) {
throw new STRSNoContentException("No Content Found");
}
return listofDepartments;
}

@RequestMapping(value="/getPriorities")
public List<Priority> getListOfPriority(){
return userServices.getListOfPriority();
List<Priority> listOfPriorities = userServices.getListOfPriority();
if(listOfPriorities == null) {
throw new STRSNoContentException("No Content Found");
}
return listOfPriorities;
}

@RequestMapping(value="/getUsers")
public List<User> getListOfUsers(){
return userServices.getListOfUsers();
List<User> listOfUsers = userServices.getListOfUsers();
if(listOfUsers == null) {
throw new STRSNoContentException("No Content Found");
}
return listOfUsers;
}

// insertTicket
@RequestMapping(value="/insertTicket")
public String insertTicket(@RequestBody Ticket ticket){
return userServices.insertTicket(ticket);
}

}