use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class SectionDaoImpl method getSectionList.
@Override
public List<Section> getSectionList() throws SectionException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
List<Section> sectionList = new ArrayList<>();
Query query = session.createQuery("from Section");
for (Object sectionObj : query.list()) sectionList.add((Section) sectionObj);
session.getTransaction().commit();
session.close();
return sectionList;
} catch (SectionDaoException e) {
session.close();
throw new SectionException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class SectionDaoImpl method deleteSectionById.
@Override
public Section deleteSectionById(long id) throws SectionException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Section section = session.get(Section.class, id);
if (section == null)
throw new SectionDaoException("Section with id : " + id + " does not exist");
// to avoid the constraints restriction we meed to remove section from the student that having the section
Query studentQuery = session.createQuery("from Student");
for (Object studentObj : studentQuery.list()) {
Student student = (Student) studentObj;
if (student.getSection() == null)
continue;
if (student.getSection().equals(section) || (student.getSection() != null ? student.getSection().getId() : 0) == section.getId()) {
student.setSection(null);
}
}
// to avoid the constraints restriction we meed to remove section from the class that having the section
Query classQuery = session.createQuery("from Class");
for (Object classObj : classQuery.list()) {
Class _class = (Class) classObj;
if (_class.getSection() == null)
continue;
if (_class.getSection().equals(section) || (_class.getSection() != null ? _class.getSection().getId() : 0) == section.getId()) {
_class.setSection(null);
}
}
section.setDepartment(null);
session.delete(section);
session.getTransaction().commit();
session.close();
return section;
} catch (SectionDaoException e) {
session.close();
throw new SectionException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class SectionController method getSection.
@RequestMapping(value = "get", method = RequestMethod.POST)
public String getSection(@RequestParam("query") String query, ModelMap modelMap) {
try {
List<Department> departmentList = departmentService.getDepartmentList();
List<Section> sectionList = new ArrayList<>();
Section section = null;
if (!query.trim().isEmpty()) {
try {
long id = Long.parseLong(query.trim());
section = sectionService.getSectionById(id);
} catch (NumberFormatException e) {
e.printStackTrace();
section = null;
} catch (SectionException e) {
e.printStackTrace();
section = null;
}
if (section != null)
sectionList.add(section);
else {
for (Section t : sectionService.getSectionList()) {
if (t.getName().equals(query.trim())) {
sectionList.add(t);
continue;
}
}
}
}
if (sectionList.size() < 1) {
sectionList = sectionService.getSectionList();
modelMap.put("responseMessage", "No result found.");
} else {
modelMap.put("responseMessage", sectionList.size() + " Result found.");
}
modelMap.put("sectionList", sectionList);
modelMap.put("departmentList", departmentList);
return "section-table";
} catch (SectionException | DepartmentException e) {
e.printStackTrace();
return "error";
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class StudentController method updateStudentById.
@RequestMapping(value = "update", method = RequestMethod.POST)
public String updateStudentById(@RequestParam("id") long id, @RequestParam("studentNumber") long studentNumber, @RequestParam("firstName") String firstName, @RequestParam("middleName") String middleName, @RequestParam("lastName") String lastName, @RequestParam("gender") String gender, @RequestParam("age") int age, @RequestParam("sectionId") long sectionId, ModelMap modelMap) {
try {
Student newStudent = new Student(studentNumber, firstName, lastName, middleName, gender, age, "");
try {
studentService.updateStudentById(id, newStudent, sectionId);
} catch (StudentException e) {
try {
e.printStackTrace();
sectionId = 0;
studentService.updateStudentById(id, newStudent, sectionId);
} catch (StudentException e2) {
e2.printStackTrace();
}
}
List<Student> studentList = studentService.getStudentList();
List<Section> sectionList = sectionService.getSectionList();
modelMap.put("studentList", studentList);
modelMap.put("sectionList", sectionList);
return "student";
} catch (StudentException | SectionException e) {
e.printStackTrace();
return "error";
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class SectionServiceImpl method deleteSectionById.
@Override
public Section deleteSectionById(long id) throws SectionException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(id);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.delete();
if (response.getStatus() == 200) {
return (Section) response.readEntity(Section.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new SectionServiceException(message.getMessage());
} else
throw new SectionServiceException("The request might invalid or server is down");
} catch (SectionServiceException e) {
throw new SectionException(e.getMessage());
}
}
Aggregations