use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile in project muikku by otavanopisto.
the class TranscriptOfRecordsFileDAO method listByUserEntity.
public List<TranscriptOfRecordsFile> listByUserEntity(UserEntity userEntity) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<TranscriptOfRecordsFile> criteria = criteriaBuilder.createQuery(TranscriptOfRecordsFile.class);
Root<TranscriptOfRecordsFile> root = criteria.from(TranscriptOfRecordsFile.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(TranscriptOfRecordsFile_.userEntityId), userEntity.getId()), criteriaBuilder.equal(root.get(TranscriptOfRecordsFile_.archived), false)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile in project muikku by otavanopisto.
the class GuiderRESTService method listTranscriptOfRecordsFiles.
@GET
@Path("/users/{IDENTIFIER}/files")
@RESTPermit(GuiderPermissions.GUIDER_LIST_TORFILES)
public Response listTranscriptOfRecordsFiles(@PathParam("IDENTIFIER") String identifierString) {
SchoolDataIdentifier identifier = SchoolDataIdentifier.fromId(identifierString);
UserEntity ue = userEntityController.findUserEntityByUserIdentifier(identifier);
if (ue == null) {
return Response.status(Status.NOT_FOUND).entity("User entity not found").build();
}
List<TranscriptOfRecordsFile> torFiles = torFileController.listFiles(ue);
return Response.ok().entity(torFiles).build();
}
use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile in project muikku by otavanopisto.
the class GuiderRESTService method getTranscriptOfRecordsFileContent.
@GET
@Path("/files/{ID}/content")
@RESTPermit(GuiderPermissions.GUIDER_GET_TORFILE_CONTENT)
public Response getTranscriptOfRecordsFileContent(@PathParam("ID") Long fileId) {
TranscriptOfRecordsFile file = torFileController.findFileById(fileId);
if (file == null) {
return Response.status(Status.NOT_FOUND).entity("File not found").build();
}
StreamingOutput output = s -> torFileController.outputFileToStream(file, s);
String contentType = file.getContentType();
return Response.ok().type(contentType).entity(output).build();
}
use of fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile in project muikku by otavanopisto.
the class TranscriptOfRecordsFileController method attachFile.
public TranscriptOfRecordsFile attachFile(UserEntity student, InputStream content, String contentType, String title, String description) throws IOException {
String fileUuid = UUID.randomUUID().toString();
File file = Paths.get(getFileUploadBasePath(), fileUuid).toFile();
try {
FileUtils.copyInputStreamToFile(content, file);
} catch (IOException ex) {
file.delete();
throw new RuntimeException("Couldn't save file", ex);
}
return transcriptOfRecordsFileDAO.create(student, fileUuid, contentType, title, description);
}
Aggregations