Search in sources :

Example 6 with WorkspaceEntityFile

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile in project muikku by otavanopisto.

the class WorkspaceEntityFileDAO method create.

public WorkspaceEntityFile create(WorkspaceEntity workspaceEntity, String fileIdentifier, String diskName, String contentType, Date lastModified) {
    WorkspaceEntityFile file = new WorkspaceEntityFile();
    file.setWorkspaceEntity(workspaceEntity.getId());
    file.setFileIdentifier(fileIdentifier);
    file.setDiskName(diskName);
    file.setContentType(contentType);
    file.setLastModified(lastModified);
    return persist(file);
}
Also used : WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile)

Example 7 with WorkspaceEntityFile

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile in project muikku by otavanopisto.

the class WorkspaceRESTService method deleteWorkspaceFileContent.

@DELETE
@Path("/workspaces/{WORKSPACEID}/workspacefile/{FILEIDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response deleteWorkspaceFileContent(@PathParam("WORKSPACEID") Long workspaceId, @PathParam("FILEIDENTIFIER") String fileIdentifier, @Context Request request) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
    if (workspaceEntity == null)
        return Response.status(Status.BAD_REQUEST).build();
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE, workspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    WorkspaceEntityFile workspaceEntityFile = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, fileIdentifier);
    if (workspaceEntityFile == null)
        return Response.status(Status.NOT_FOUND).build();
    fileController.deleteFile("workspace", workspaceEntityFile.getDiskName());
    workspaceEntityFileController.deleteWorkspaceEntityFile(workspaceEntityFile);
    return Response.noContent().build();
}
Also used : WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 8 with WorkspaceEntityFile

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile in project muikku by otavanopisto.

the class WorkspaceRESTService method getWorkspaceFileContent.

@GET
@Path("/workspaces/{WORKSPACEID}/workspacefile/{FILEIDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getWorkspaceFileContent(@PathParam("WORKSPACEID") Long workspaceId, @PathParam("FILEIDENTIFIER") String fileIdentifier, @Context Request request) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
    if (workspaceEntity == null)
        return Response.status(Status.BAD_REQUEST).build();
    WorkspaceEntityFile imageFile = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, fileIdentifier);
    if (imageFile == null)
        return Response.status(Status.NOT_FOUND).build();
    StreamingOutput output = s -> fileController.outputFileToStream("workspace", imageFile.getDiskName(), s);
    String contentType = imageFile.getContentType();
    String tagIdentifier = String.format("%d-%s-%d", imageFile.getWorkspaceEntity(), imageFile.getDiskName(), imageFile.getLastModified().getTime());
    EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(tagIdentifier)));
    ResponseBuilder builder = request.evaluatePreconditions(tag);
    if (builder != null) {
        return builder.build();
    }
    CacheControl cacheControl = new CacheControl();
    cacheControl.setMustRevalidate(true);
    return Response.ok().cacheControl(cacheControl).tag(tag).type(contentType).entity(output).build();
}
Also used : WorkspaceEntityFileRESTModel(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceEntityFileRESTModel) Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) WorkspaceCompositeReply(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceCompositeReply) EnvironmentRoleArchetype(fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype) WorkspaceMaterialFileFieldAnswerFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialFileFieldAnswerFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Material(fi.otavanopisto.muikku.plugins.material.model.Material) Flag(fi.otavanopisto.muikku.model.users.Flag) StringUtils(org.apache.commons.lang3.StringUtils) User(fi.otavanopisto.muikku.schooldata.entity.User) WorkspaceEntityFileController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceEntityFileController) WorkspaceMaterialAudioFieldAnswerClip(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAudioFieldAnswerClip) Map(java.util.Map) CourseMetaController(fi.otavanopisto.muikku.schooldata.CourseMetaController) WorkspaceMaterialCompositeReply(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterialCompositeReply) Instance(javax.enterprise.inject.Instance) WorkspaceDetails(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceDetails) WorkspaceFeeInfo(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceFeeInfo) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) WorkspaceEntityController(fi.otavanopisto.muikku.schooldata.WorkspaceEntityController) AssessmentRequestController(fi.otavanopisto.muikku.plugins.assessmentrequest.AssessmentRequestController) SchoolDataIdentifier(fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) Set(java.util.Set) TempFileUtils(fi.otavanopisto.muikku.files.TempFileUtils) IOUtils(org.apache.commons.io.IOUtils) WorkspaceMaterialProducer(fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer) WorkspaceType(fi.otavanopisto.muikku.schooldata.entity.WorkspaceType) WorkspaceFieldIOException(fi.otavanopisto.muikku.plugins.workspace.fieldio.WorkspaceFieldIOException) DatatypeConverter(javax.xml.bind.DatatypeConverter) WorkspaceIndexer(fi.otavanopisto.muikku.plugins.search.WorkspaceIndexer) ZipOutputStream(java.util.zip.ZipOutputStream) GET(javax.ws.rs.GET) MuikkuPermissions(fi.otavanopisto.muikku.security.MuikkuPermissions) WorkspaceMaterialField(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialField) RESTPermitUnimplemented(fi.otavanopisto.muikku.rest.RESTPermitUnimplemented) Handling(fi.otavanopisto.security.rest.RESTPermit.Handling) WorkspaceVisitController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceVisitController) ArrayList(java.util.ArrayList) SessionController(fi.otavanopisto.muikku.session.SessionController) WorkspaceJournalEntryRESTModel(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceJournalEntryRESTModel) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) WorkspaceMaterialReplyController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialReplyController) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) WorkspaceMaterialFieldAnswer(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterialFieldAnswer) IOException(java.io.IOException) MaterialViewRestrict(fi.otavanopisto.muikku.plugins.material.model.MaterialViewRestrict) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) Stateful(javax.ejb.Stateful) RestCatchSchoolDataExceptions(fi.otavanopisto.muikku.schooldata.RestCatchSchoolDataExceptions) WorkspaceUserEntityController(fi.otavanopisto.muikku.users.WorkspaceUserEntityController) SearchProvider(fi.otavanopisto.muikku.search.SearchProvider) WorkspaceMaterialFieldController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialFieldController) WorkspaceNodeType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNodeType) MaterialController(fi.otavanopisto.muikku.plugins.material.MaterialController) WorkspaceMaterialController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialController) WorkspaceMaterialReplyState(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialReplyState) Date(java.util.Date) Path(javax.ws.rs.Path) BooleanPredicate(fi.otavanopisto.muikku.model.base.BooleanPredicate) QueryParam(javax.ws.rs.QueryParam) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultValue(javax.ws.rs.DefaultValue) Any(javax.enterprise.inject.Any) Workspace(fi.otavanopisto.muikku.schooldata.entity.Workspace) ZipEntry(java.util.zip.ZipEntry) Sort(fi.otavanopisto.muikku.search.SearchProvider.Sort) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) WorkspaceMaterialAssignmentType(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialAssignmentType) Collection(java.util.Collection) WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceMaterialContainsAnswersExeption(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialContainsAnswersExeption) StreamingOutput(javax.ws.rs.core.StreamingOutput) Logger(java.util.logging.Logger) GradingController(fi.otavanopisto.muikku.schooldata.GradingController) Objects(java.util.Objects) EducationType(fi.otavanopisto.muikku.schooldata.entity.EducationType) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) UserEntityController(fi.otavanopisto.muikku.users.UserEntityController) Response(javax.ws.rs.core.Response) UserController(fi.otavanopisto.muikku.users.UserController) WorkspaceNode(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceNode) WorkspaceMaterialReply(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceMaterialReply) WorkspaceRoleArchetype(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleArchetype) Request(javax.ws.rs.core.Request) CacheControl(javax.ws.rs.core.CacheControl) WorkspaceStudent(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceStudent) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) UserIndexer(fi.otavanopisto.muikku.plugins.search.UserIndexer) WorkspaceController(fi.otavanopisto.muikku.schooldata.WorkspaceController) PathParam(javax.ws.rs.PathParam) WorkspaceRootFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceRootFolder) FlagController(fi.otavanopisto.muikku.users.FlagController) WorkspaceUser(fi.otavanopisto.muikku.schooldata.entity.WorkspaceUser) HashMap(java.util.HashMap) WorkspaceMaterialDeleteError(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialDeleteError) Level(java.util.logging.Level) MessagingWidget(fi.otavanopisto.muikku.controller.messaging.MessagingWidget) HashSet(java.util.HashSet) Inject(javax.inject.Inject) FileController(fi.otavanopisto.muikku.plugins.data.FileController) CollectionUtils(org.apache.commons.collections.CollectionUtils) Status(javax.ws.rs.core.Response.Status) OutputStream(java.io.OutputStream) POST(javax.ws.rs.POST) Iterator(java.util.Iterator) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceStaffMember(fi.otavanopisto.muikku.plugins.workspace.rest.model.WorkspaceStaffMember) SearchResult(fi.otavanopisto.muikku.search.SearchResult) EntityTag(javax.ws.rs.core.EntityTag) WorkspaceJournalController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceJournalController) PluginRESTService(fi.otavanopisto.muikku.plugin.PluginRESTService) RequestScoped(javax.enterprise.context.RequestScoped) UserSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier) QueryFieldController(fi.otavanopisto.muikku.plugins.material.QueryFieldController) WorkspaceMaterialFieldAnswerController(fi.otavanopisto.muikku.plugins.workspace.WorkspaceMaterialFieldAnswerController) SchoolDataBridgeSessionController(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeSessionController) PUT(javax.ws.rs.PUT) Comparator(java.util.Comparator) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Collections(java.util.Collections) InputStream(java.io.InputStream) WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) StreamingOutput(javax.ws.rs.core.StreamingOutput) EntityTag(javax.ws.rs.core.EntityTag) CacheControl(javax.ws.rs.core.CacheControl) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 9 with WorkspaceEntityFile

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile in project muikku by otavanopisto.

the class WorkspaceRESTService method createWorkspaceFile.

@POST
@Path("/workspaces/{FROMWORKSPACEID}/workspacefilecopy/{TOWORKSPACEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createWorkspaceFile(@PathParam("FROMWORKSPACEID") Long sourceWorkspaceId, @PathParam("TOWORKSPACEID") Long destinationWorkspaceId) {
    if (Objects.equals(sourceWorkspaceId, destinationWorkspaceId))
        return Response.status(Status.BAD_REQUEST).build();
    WorkspaceEntity sourceWorkspaceEntity = workspaceEntityController.findWorkspaceEntityById(sourceWorkspaceId);
    WorkspaceEntity destinationWorkspaceEntity = workspaceEntityController.findWorkspaceEntityById(destinationWorkspaceId);
    if (sourceWorkspaceEntity == null || destinationWorkspaceEntity == null)
        return Response.status(Status.BAD_REQUEST).build();
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE, sourceWorkspaceEntity) || !sessionController.hasWorkspacePermission(MuikkuPermissions.MANAGE_WORKSPACE, destinationWorkspaceEntity)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    try {
        List<WorkspaceEntityFile> workspaceEntityFiles = workspaceEntityFileController.listWorkspaceEntityFiles(sourceWorkspaceEntity);
        for (WorkspaceEntityFile workspaceEntityFile : workspaceEntityFiles) {
            String diskName = fileController.copyFile("workspace", workspaceEntityFile.getDiskName());
            workspaceEntityFileController.createWorkspaceEntityFile(destinationWorkspaceEntity, workspaceEntityFile.getFileIdentifier(), diskName, workspaceEntityFile.getContentType(), new Date());
        }
    } catch (IOException e) {
        logger.log(Level.SEVERE, String.format("Copying workspace file failed while copying workspace %s", sourceWorkspaceId), e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
    return Response.noContent().build();
}
Also used : WorkspaceEntityFile(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceFieldIOException(fi.otavanopisto.muikku.plugins.workspace.fieldio.WorkspaceFieldIOException) IOException(java.io.IOException) Date(java.util.Date) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Aggregations

WorkspaceEntityFile (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceEntityFile)9 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)6 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)4 Path (javax.ws.rs.Path)4 WorkspaceFieldIOException (fi.otavanopisto.muikku.plugins.workspace.fieldio.WorkspaceFieldIOException)3 IOException (java.io.IOException)3 Date (java.util.Date)3 POST (javax.ws.rs.POST)3 DELETE (javax.ws.rs.DELETE)2 MessagingWidget (fi.otavanopisto.muikku.controller.messaging.MessagingWidget)1 TempFileUtils (fi.otavanopisto.muikku.files.TempFileUtils)1 BooleanPredicate (fi.otavanopisto.muikku.model.base.BooleanPredicate)1 EnvironmentRoleArchetype (fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype)1 Flag (fi.otavanopisto.muikku.model.users.Flag)1 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)1 WorkspaceMaterialProducer (fi.otavanopisto.muikku.model.workspace.WorkspaceMaterialProducer)1 WorkspaceRoleArchetype (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleArchetype)1 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)1 PluginRESTService (fi.otavanopisto.muikku.plugin.PluginRESTService)1