use of fi.otavanopisto.pyramus.domainmodel.file.StudentFile 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.domainmodel.file.StudentFile 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.domainmodel.file.StudentFile in project pyramus by otavanopisto.
the class ListStudentFilesJSONRequestController 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();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
Long studentId = requestContext.getLong("studentId");
Student student = studentDAO.findById(studentId);
List<StudentFile> studentFiles = studentFileDAO.listByStudent(student);
Collections.sort(studentFiles, new StringAttributeComparator("getName", true));
JSONArray filesJSON = new JSONArray();
for (StudentFile file : studentFiles) {
JSONObject fileJSON = new JSONObject();
fileJSON.put("id", file.getId());
fileJSON.put("name", file.getName());
fileJSON.put("fileTypeName", file.getFileType() != null ? file.getFileType().getName() : "");
fileJSON.put("created", file.getCreated().getTime());
fileJSON.put("lastModified", file.getLastModified().getTime());
filesJSON.add(fileJSON);
}
requestContext.addResponseParameter("files", filesJSON.toString());
}
use of fi.otavanopisto.pyramus.domainmodel.file.StudentFile in project pyramus by otavanopisto.
the class StudentFileDAO method findByFileId.
public StudentFile findByFileId(String fileId) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<StudentFile> criteria = criteriaBuilder.createQuery(StudentFile.class);
Root<StudentFile> root = criteria.from(StudentFile.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(StudentFile_.fileId), fileId));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.pyramus.domainmodel.file.StudentFile in project pyramus by otavanopisto.
the class StudentFileDAO method listIdsByLargerAndLimit.
public List<Long> listIdsByLargerAndLimit(Long id, int count) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<StudentFile> root = criteria.from(StudentFile.class);
criteria.select(root.get(StudentFile_.id));
criteria.where(criteriaBuilder.greaterThan(root.get(StudentFile_.id), id));
criteria.orderBy(criteriaBuilder.asc(root.get(StudentFile_.id)));
TypedQuery<Long> query = entityManager.createQuery(criteria);
query.setMaxResults(count);
return query.getResultList();
}
Aggregations