Search in sources :

Example 6 with TranscriptOfRecordsFile

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile)

Example 7 with TranscriptOfRecordsFile

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();
}
Also used : SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 8 with TranscriptOfRecordsFile

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();
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Date(java.util.Date) NoPassedCoursesNotificationController(fi.otavanopisto.muikku.plugins.timed.notifications.NoPassedCoursesNotificationController) Path(javax.ws.rs.Path) HashMap(java.util.HashMap) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Handling(fi.otavanopisto.security.rest.RESTPermit.Handling) SessionController(fi.otavanopisto.muikku.session.SessionController) Inject(javax.inject.Inject) Map(java.util.Map) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) AssesmentRequestNotificationController(fi.otavanopisto.muikku.plugins.timed.notifications.AssesmentRequestNotificationController) Status(javax.ws.rs.core.Response.Status) DELETE(javax.ws.rs.DELETE) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) WorkspaceEntityController(fi.otavanopisto.muikku.schooldata.WorkspaceEntityController) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) AssessmentRequestController(fi.otavanopisto.muikku.plugins.assessmentrequest.AssessmentRequestController) SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) StreamingOutput(javax.ws.rs.core.StreamingOutput) TranscriptOfRecordsFileController(fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptOfRecordsFileController) NoPassedCoursesNotification(fi.otavanopisto.muikku.plugins.timed.notifications.model.NoPassedCoursesNotification) Stateful(javax.ejb.Stateful) AssesmentRequestNotification(fi.otavanopisto.muikku.plugins.timed.notifications.model.AssesmentRequestNotification) RestCatchSchoolDataExceptions(fi.otavanopisto.muikku.schooldata.RestCatchSchoolDataExceptions) List(java.util.List) StudyTimeNotification(fi.otavanopisto.muikku.plugins.timed.notifications.model.StudyTimeNotification) PluginRESTService(fi.otavanopisto.muikku.plugin.PluginRESTService) WorkspaceAssessmentState(fi.otavanopisto.muikku.plugins.assessmentrequest.WorkspaceAssessmentState) UserEntityController(fi.otavanopisto.muikku.users.UserEntityController) WorkspaceUserEntityController(fi.otavanopisto.muikku.users.WorkspaceUserEntityController) Response(javax.ws.rs.core.Response) RequestScoped(javax.enterprise.context.RequestScoped) WorkspaceRoleArchetype(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleArchetype) StudyTimeLeftNotificationController(fi.otavanopisto.muikku.plugins.timed.notifications.StudyTimeLeftNotificationController) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) StreamingOutput(javax.ws.rs.core.StreamingOutput) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 9 with TranscriptOfRecordsFile

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);
}
Also used : IOException(java.io.IOException) TranscriptOfRecordsFile(fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile) File(java.io.File)

Aggregations

TranscriptOfRecordsFile (fi.otavanopisto.muikku.plugins.transcriptofrecords.model.TranscriptOfRecordsFile)9 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)4 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)4 Path (javax.ws.rs.Path)4 IOException (java.io.IOException)3 DELETE (javax.ws.rs.DELETE)3 GET (javax.ws.rs.GET)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)2 PluginRESTService (fi.otavanopisto.muikku.plugin.PluginRESTService)2 TranscriptOfRecordsFileController (fi.otavanopisto.muikku.plugins.transcriptofrecords.TranscriptOfRecordsFileController)2 RestCatchSchoolDataExceptions (fi.otavanopisto.muikku.schooldata.RestCatchSchoolDataExceptions)2 SessionController (fi.otavanopisto.muikku.session.SessionController)2 UserEntityController (fi.otavanopisto.muikku.users.UserEntityController)2 WorkspaceUserEntityController (fi.otavanopisto.muikku.users.WorkspaceUserEntityController)2 Handling (fi.otavanopisto.security.rest.RESTPermit.Handling)2 List (java.util.List)2 Map (java.util.Map)2 Stateful (javax.ejb.Stateful)2