use of fi.otavanopisto.pyramus.dao.file.FileTypeDAO 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.FileTypeDAO in project pyramus by otavanopisto.
the class UploadReportDialogViewController 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) {
FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
Long studentId = pageRequestContext.getLong("studentId");
Long reportId = pageRequestContext.getLong("reportId");
List<FileType> fileTypes = fileTypeDAO.listUnarchived();
Collections.sort(fileTypes, new StringAttributeComparator("getName"));
StringBuffer reportParameters = new StringBuffer();
Map<String, String[]> parameterMap = pageRequestContext.getRequest().getParameterMap();
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
if (!reservedParameters.contains(entry.getKey())) {
String[] values = entry.getValue();
for (String value : values) {
// TODO ISO-8859-1 should be UTF-8, once Birt's parameter dialog form has its accept-charset="UTF-8" set
try {
reportParameters.append('&').append(entry.getKey()).append('=').append(URLEncoder.encode(value, "ISO-8859-1"));
} catch (UnsupportedEncodingException e) {
throw new SmvcRuntimeException(e);
}
}
}
}
pageRequestContext.getRequest().setAttribute("student", studentDAO.findById(studentId));
pageRequestContext.getRequest().setAttribute("report", reportDAO.findById(reportId));
pageRequestContext.getRequest().setAttribute("reportParameters", reportParameters);
pageRequestContext.getRequest().setAttribute("fileTypes", fileTypes);
pageRequestContext.setIncludeJSP("/templates/studentfiles/uploadreport.jsp");
}
use of fi.otavanopisto.pyramus.dao.file.FileTypeDAO 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.FileTypeDAO in project pyramus by otavanopisto.
the class UploadStudentFileJSONRequestController method process.
/**
* Processes the request to edit a student group.
*
* @param requestContext
* The JSON request context
*/
public void process(JSONRequestContext requestContext) {
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
Long userId = requestContext.getLoggedUserId();
User loggedUser = userDAO.findById(userId);
Long studentId = requestContext.getLong("studentId");
String name = requestContext.getString("fileName");
Long fileTypeId = requestContext.getLong("fileType");
FileItem fileItem = requestContext.getFile("file");
Student student = studentDAO.findById(studentId);
FileType fileType = fileTypeId != null ? fileTypeDAO.findById(fileTypeId) : null;
if (fileItem != null) {
String fileId = null;
byte[] data = fileItem.get();
if (PyramusFileUtils.isFileSystemStorageEnabled()) {
try {
fileId = PyramusFileUtils.generateFileId();
PyramusFileUtils.storeFile(student, fileId, data);
data = null;
} catch (IOException e) {
fileId = null;
logger.log(Level.SEVERE, "Store user file to file system failed", e);
}
}
studentFileDAO.create(student, name, fileItem.getName(), fileId, fileType, fileItem.getContentType(), data, loggedUser);
}
}
use of fi.otavanopisto.pyramus.dao.file.FileTypeDAO in project pyramus by otavanopisto.
the class UploadStudentReportJSONRequestController method process.
/**
* Processes the request to edit a student group.
*
* @param requestContext
* The JSON request context
*/
public void process(JSONRequestContext requestContext) {
StudentFileDAO studentFileDAO = DAOFactory.getInstance().getStudentFileDAO();
FileTypeDAO fileTypeDAO = DAOFactory.getInstance().getFileTypeDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
Long studentId = requestContext.getLong("studentId");
Long reportId = requestContext.getLong("reportId");
String reportParameters = requestContext.getString("reportParameters");
Long userId = requestContext.getLoggedUserId();
User loggedUser = userDAO.findById(userId);
String name = requestContext.getString("fileName");
Long fileTypeId = requestContext.getLong("fileType");
String contentType;
String format = requestContext.getString("reportFormat");
if ("doc".equals(format)) {
contentType = "application/msword";
} else {
format = "pdf";
contentType = "application/pdf";
}
Student student = studentDAO.findById(studentId);
FileType fileType = fileTypeId != null ? fileTypeDAO.findById(fileTypeId) : null;
Report report = reportDAO.findById(reportId);
MagicKeyDAO magicKeyDAO = DAOFactory.getInstance().getMagicKeyDAO();
String reportsContextPath = System.getProperty("reports.contextPath");
String reportsHost = System.getProperty("reports.host");
String reportsProtocol = System.getProperty("reports.protocol");
String reportsPort = System.getProperty("reports.port");
// output or preview
String outputMethod = "preview";
MagicKey magicKey = magicKeyDAO.findByApplicationScope();
StringBuilder urlBuilder = new StringBuilder().append(reportsProtocol).append("://").append(reportsHost).append(":").append(reportsPort).append(reportsContextPath).append("/").append(outputMethod).append("?magicKey=").append(magicKey.getName()).append("&__report=reports/").append(reportId).append(".rptdesign");
urlBuilder.append("&__format=").append(format);
urlBuilder.append(reportParameters);
try {
URL url = new URL(urlBuilder.toString());
URLConnection urlConn = url.openConnection();
InputStream inputStream = urlConn.getInputStream();
String fileId = null;
byte[] data = IOUtils.toByteArray(inputStream);
if (PyramusFileUtils.isFileSystemStorageEnabled()) {
try {
fileId = PyramusFileUtils.generateFileId();
PyramusFileUtils.storeFile(student, fileId, data);
data = null;
} catch (IOException e) {
fileId = null;
logger.log(Level.SEVERE, "Store user file to file system failed", e);
}
}
String reportName = report.getName().toLowerCase().replaceAll("[^a-z0-9\\.]", "_");
studentFileDAO.create(student, name, reportName + "." + format, fileId, fileType, contentType, data, loggedUser);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations