use of fi.otavanopisto.pyramus.dao.file.StudentFileDAO in project pyramus by otavanopisto.
the class FileService method uploadStudentFile.
@WebMethod
public void uploadStudentFile(@WebParam(name = "studentId") Long studentId, @WebParam(name = "name") String name, @WebParam(name = "fileName") String fileName, @WebParam(name = "fileTypeId") Long fileTypeId, @WebParam(name = "contentType") String contentType, @WebParam(name = "creatorId") Long creatorId, @WebParam(name = "content") DataHandler content) {
StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
Student student = studentDAO.findById(studentId);
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
User creator = creatorId != null ? userDAO.findById(creatorId) : null;
FileType fileType = fileTypeId != null ? fileTypeDAO.findById(fileTypeId) : null;
byte[] data = null;
try {
InputStream inputStream = content.getInputStream();
data = IOUtils.toByteArray(inputStream);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
studentFileDAO.create(student, name, fileName, null, fileType, contentType, data, creator);
}
use of fi.otavanopisto.pyramus.dao.file.StudentFileDAO in project pyramus by otavanopisto.
the class DownloadStudentFile method process.
/**
* Processes a binary request.
* The request should contain the following parameters:
* <dl>
* <dt><code>fileId</code></dt>
* <dd>The ID of the student file.</dd>
* </dl>
*
* @param binaryRequestContext The context of the binary request.
*/
public void process(BinaryRequestContext binaryRequestContext) {
StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
Long fileId = binaryRequestContext.getLong("fileId");
StudentFile studentFile = studentFileDAO.findById(fileId);
if (studentFile != null) {
binaryRequestContext.setFileName(studentFile.getFileName());
try {
binaryRequestContext.setResponseContent(PyramusFileUtils.getFileData(studentFile), studentFile.getContentType());
} catch (IOException e) {
logger.log(Level.SEVERE, String.format("Exception retrieving user file %d", studentFile.getId()), e);
}
}
}
use of fi.otavanopisto.pyramus.dao.file.StudentFileDAO in project pyramus by otavanopisto.
the class EditFileDialogViewController method process.
/**
* Processes the page request by including the corresponding JSP page to the response.
*
* @param pageRequestContext Page request context
*/
public void process(PageRequestContext pageRequestContext) {
Long fileId = pageRequestContext.getLong("fileId");
StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
List<FileType> fileTypes = fileTypeDAO.listUnarchived();
Collections.sort(fileTypes, new StringAttributeComparator("getName"));
pageRequestContext.getRequest().setAttribute("file", studentFileDAO.findById(fileId));
pageRequestContext.getRequest().setAttribute("fileTypes", fileTypes);
pageRequestContext.setIncludeJSP("/templates/studentfiles/editfile.jsp");
}
use of fi.otavanopisto.pyramus.dao.file.StudentFileDAO in project pyramus by otavanopisto.
the class MoveStudentFilesViewController method process.
public void process(PageRequestContext pageRequestContext) {
int count = pageRequestContext.getInteger("count");
StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
if (count > 0) {
int bytes = 0;
int totalBytes = 0;
int totalFiles = 0;
Long currentEntityId = PyramusFileUtils.getLastMovedEntityId();
List<Long> entityIds = studentFileDAO.listIdsByLargerAndLimit(currentEntityId, count);
for (Long entityId : entityIds) {
try {
StudentFile studentFile = studentFileDAO.findById(entityId);
if (studentFile != null) {
bytes = PyramusFileUtils.relocateToFileSystem(studentFile);
if (bytes > 0) {
totalBytes += bytes;
totalFiles++;
}
currentEntityId = entityId;
}
PyramusFileUtils.setLastMovedEntityId(currentEntityId);
} catch (IOException e) {
logger.log(Level.SEVERE, String.format("Failed to relocate StudentFile %d", currentEntityId), e);
}
}
logger.info(String.format("Moved %d files (%d bytes) with latest entity at %d", totalFiles, totalBytes, currentEntityId));
}
}
use of fi.otavanopisto.pyramus.dao.file.StudentFileDAO in project pyramus by otavanopisto.
the class ArchiveStudentFileJSONRequestController method process.
/**
* Processes the request to archive a municipality.
*
* @param jsonRequestContext The JSON request context
*/
public void process(JSONRequestContext jsonRequestContext) {
StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
Long fileId = jsonRequestContext.getLong("fileId");
studentFileDAO.archive(studentFileDAO.findById(fileId));
}
Aggregations