Search in sources :

Example 1 with StudentFileDAO

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);
}
Also used : StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) FileTypeDAO(fi.otavanopisto.pyramus.dao.file.FileTypeDAO) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) FileType(fi.otavanopisto.pyramus.domainmodel.file.FileType) InputStream(java.io.InputStream) IOException(java.io.IOException) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) WebMethod(javax.jws.WebMethod)

Example 2 with StudentFileDAO

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);
        }
    }
}
Also used : StudentFile(fi.otavanopisto.pyramus.domainmodel.file.StudentFile) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) IOException(java.io.IOException)

Example 3 with StudentFileDAO

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");
}
Also used : FileTypeDAO(fi.otavanopisto.pyramus.dao.file.FileTypeDAO) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) FileType(fi.otavanopisto.pyramus.domainmodel.file.FileType) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator)

Example 4 with StudentFileDAO

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));
    }
}
Also used : StudentFile(fi.otavanopisto.pyramus.domainmodel.file.StudentFile) StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO) IOException(java.io.IOException)

Example 5 with StudentFileDAO

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));
}
Also used : StudentFileDAO(fi.otavanopisto.pyramus.dao.file.StudentFileDAO)

Aggregations

StudentFileDAO (fi.otavanopisto.pyramus.dao.file.StudentFileDAO)13 IOException (java.io.IOException)8 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)6 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)6 User (fi.otavanopisto.pyramus.domainmodel.users.User)6 FileTypeDAO (fi.otavanopisto.pyramus.dao.file.FileTypeDAO)5 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)5 StudentFile (fi.otavanopisto.pyramus.domainmodel.file.StudentFile)5 FileType (fi.otavanopisto.pyramus.domainmodel.file.FileType)4 JSONObject (net.sf.json.JSONObject)3 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)2 ReportDAO (fi.otavanopisto.pyramus.dao.reports.ReportDAO)2 StudentStudyPeriodDAO (fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO)2 UserVariableDAO (fi.otavanopisto.pyramus.dao.users.UserVariableDAO)2 StringAttributeComparator (fi.otavanopisto.pyramus.util.StringAttributeComparator)2 InputStream (java.io.InputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1