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);
}
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();
}
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();
}
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();
}
Aggregations