use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class StudentServiceImpl method deleteStudentById.
@Override
public Student deleteStudentById(long id) throws StudentException {
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 (Student) response.readEntity(Student.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new StudentServiceException(message.getMessage());
} else
throw new StudentServiceException("The request might invalid or server is down");
} catch (StudentServiceException e) {
throw new StudentException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class StudentServiceImpl method getStudentBySn.
public Student getStudentBySn(long id) throws StudentException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("?sn=");
uri.append(id);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Response response = target.request().get();
if (response.getStatus() == 200) {
return (Student) response.readEntity(Student.class);
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new StudentServiceException(message.getMessage());
} else
throw new StudentServiceException("The request might invalid or server is down");
} catch (StudentServiceException e) {
throw new StudentException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class XcellHelperBean method loadFile.
public List<Student> loadFile(File file) {
List<Student> studentList = new ArrayList<>();
try {
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
final int size = sheet.getLastRowNum();
for (int row = 1; row <= size; row++) {
Student student = new Student();
student.setStudentNumber((long) sheet.getRow(row).getCell(0).getNumericCellValue());
student.setFirstName(sheet.getRow(row).getCell(1).getStringCellValue());
student.setLastName(sheet.getRow(row).getCell(2).getStringCellValue());
student.setMiddleName(sheet.getRow(row).getCell(3).getStringCellValue());
studentList.add(student);
}
return studentList;
} catch (FileNotFoundException e) {
e.printStackTrace();
return studentList;
} catch (IOException e) {
e.printStackTrace();
return studentList;
} catch (RuntimeException e) {
e.printStackTrace();
return studentList;
}
}
use of com.remswork.project.alice.model.Student in project classify-system by anverliedoit.
the class XcellHelperBean method loadFile.
public List<Student> loadFile(File file, boolean withFormat) {
List<Student> studentList = new ArrayList<>();
try {
if (!withFormat)
return loadFile(file);
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
final int size = sheet.getLastRowNum();
final int colSize = sheet.getRow(0).getLastCellNum() > 6 ? 6 : sheet.getRow(0).getLastCellNum();
final int[] header = new int[colSize];
for (int i = 0; i < colSize; i++) {
if (sheet.getRow(0).getCell(i).getCellType() != Cell.CELL_TYPE_STRING)
continue;
if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("studentNumber"))
header[0] = i;
if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("firstName"))
header[1] = i;
if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("lastName"))
header[2] = i;
if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("middleName"))
header[3] = i;
if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("gender"))
header[4] = i;
if (sheet.getRow(0).getCell(i).getStringCellValue().equalsIgnoreCase("age"))
header[5] = i;
}
for (int row = 1; row <= size; row++) {
Student student = new Student();
if (sheet.getRow(row).getCell(header[0]).getCellType() == Cell.CELL_TYPE_NUMERIC)
student.setStudentNumber((long) sheet.getRow(row).getCell(header[0]).getNumericCellValue());
else
student.setStudentNumber(0);
if (sheet.getRow(row).getCell(header[1]).getCellType() == Cell.CELL_TYPE_STRING)
student.setFirstName(sheet.getRow(row).getCell(header[1]).getStringCellValue());
else
student.setFirstName("none");
if (sheet.getRow(row).getCell(header[2]).getCellType() == Cell.CELL_TYPE_STRING)
student.setLastName(sheet.getRow(row).getCell(header[2]).getStringCellValue());
else
student.setLastName("none");
if (sheet.getRow(row).getCell(header[3]).getCellType() == Cell.CELL_TYPE_STRING)
student.setMiddleName(sheet.getRow(row).getCell(header[3]).getStringCellValue());
else
student.setMiddleName("none");
if (sheet.getRow(row).getCell(header[4]).getCellType() == Cell.CELL_TYPE_STRING)
student.setGender(sheet.getRow(row).getCell(header[4]).getStringCellValue());
else
student.setGender("Male");
if (sheet.getRow(row).getCell(header[5]).getCellType() == Cell.CELL_TYPE_NUMERIC)
student.setAge((int) sheet.getRow(row).getCell(header[5]).getNumericCellValue());
else
student.setAge(0);
studentList.add(student);
}
return studentList;
} catch (FileNotFoundException e) {
e.printStackTrace();
return studentList;
} catch (IOException e) {
e.printStackTrace();
return studentList;
} catch (RuntimeException e) {
e.printStackTrace();
return studentList;
}
}
use of com.remswork.project.alice.model.Student 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();
}
}
Aggregations