use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class StudentResource method updateStudentById.
@PUT
@Path("{studentId}")
public Response updateStudentById(@PathParam("studentId") long id, Student newStudent) {
try {
StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
Student student = studentService.updateStudentById(id, newStudent, sectionId);
student.addLink(resourceLinks.self(id));
if (student.getSection() != null) {
Section section = student.getSection();
section.addLink(sectionResourceLinks.self(section.getId()));
if (section.getDepartment() != null)
section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
}
return Response.status(Response.Status.OK).entity(student).build();
} catch (StudentException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class StudentResource method getStudentById.
@GET
@Path("{studentId}")
public Response getStudentById(@PathParam("studentId") long id) {
try {
StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
Student student = studentService.getStudentById(id);
student.addLink(resourceLinks.self(id));
if (student.getSection() != null) {
Section section = student.getSection();
section.addLink(sectionResourceLinks.self(section.getId()));
if (section.getDepartment() != null)
section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
}
return Response.status(Response.Status.OK).entity(student).build();
} catch (StudentException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class StudentResource method deleteStudentById.
@DELETE
@Path("{studentId}")
public Response deleteStudentById(@PathParam("studentId") long id) {
try {
StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
Student student = studentService.deleteStudentById(id);
student.addLink(resourceLinks.self(id));
if (student.getSection() != null) {
Section section = student.getSection();
section.addLink(sectionResourceLinks.self(section.getId()));
if (section.getDepartment() != null)
section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
}
return Response.status(Response.Status.OK).entity(student).build();
} catch (StudentException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class SectionServiceImpl method getSectionList.
@Override
public List<Section> getSectionList() throws SectionException {
final List<Section> sectionList = new ArrayList<>();
try {
return new AsyncTask<String, List<Section>, List<Section>>() {
@Override
protected List<Section> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload);
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
sectionList.add(gson.fromJson(jsonArray.get(ctr).toString(), Section.class));
}
return sectionList;
} else if (httpURLConnection.getResponseCode() == 404) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Section");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return sectionList;
} else
throw new SectionException("Server Error");
} catch (SectionException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.model.Section in project classify-system by anverliedoit.
the class DepartmentDaoImpl method deleteDepartmentById.
@Override
public Department deleteDepartmentById(long id) throws DepartmentException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Department department = session.get(Department.class, id);
if (department == null)
throw new DepartmentDaoException("Department with id : " + id + " does not exist.");
// to avoid the constraints restriction we meed to remove department from the teacher
// that having the department
Query teacherQuery = session.createQuery("from Teacher");
for (Object teacherObj : teacherQuery.list()) {
Teacher teacher = (Teacher) teacherObj;
if (teacher.getDepartment() == null)
continue;
if (teacher.getDepartment().equals(department) || (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0) == department.getId()) {
teacher.setDepartment(null);
}
}
// to avoid the constraints restriction we meed to delete the section that having the department
Query sectionQuery = session.createQuery("from Section");
for (Object sectionObj : sectionQuery.list()) {
Section section = (Section) sectionObj;
if (section.getDepartment() == null)
continue;
if (section.getDepartment().equals(department) || (section.getDepartment() != null ? section.getDepartment().getId() : 0) == department.getId()) {
session.delete(section);
}
}
// to avoid the constraints restriction we meed to remove department from the class's teacher and section
// that having the department
Query classQuery = session.createQuery("from Class");
for (Object classObj : classQuery.list()) {
Class _class = (Class) classObj;
Teacher teacher = _class.getTeacher();
Section section = _class.getSection();
if (teacher != null) {
if (teacher.getDepartment() != null) {
if (teacher.getDepartment().equals(department) || (teacher.getDepartment() != null ? teacher.getDepartment().getId() : 0) == department.getId()) {
teacher.setDepartment(null);
}
}
}
if (section != null) {
if (section.getDepartment() != null) {
if (section.getDepartment().equals(department) || (section.getDepartment() != null ? section.getDepartment().getId() : 0) == department.getId()) {
_class.setSection(null);
}
}
}
}
session.delete(department);
session.getTransaction().commit();
session.close();
return department;
} catch (DepartmentDaoException e) {
session.close();
throw new DepartmentException(e.getMessage());
}
}
Aggregations