use of org.olat.restapi.support.MultipartReader in project openolat by klemens.
the class CourseElementWebService method updateSinglePage.
/**
* This updates a Single Page Element onto a given course.
* @response.representation.mediaType multipart/form-data
* @response.representation.doc The content of the single page
* @response.representation.200.qname {http://www.example.com}courseNodeVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc the course node metadatas
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSENODEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or parentNode not found
* @param courseId The course resourceable's id
* @param nodeId The node's id of this single page
* @param position The node's position relative to its sibling nodes (optional)
* @param shortTitle The node short title
* @param longTitle The node long title
* @param objectives The node learning objectives
* @param visibilityExpertRules The rules to view the node (optional)
* @param accessExpertRules The rules to access the node (optional)
* @param filename The single page file name
* @param file The file input stream
* @param request The HTTP request
* @return The persisted Single Page Element(fully populated)
*/
@POST
@Path("singlepage/{nodeId}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateSinglePage(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest request) {
InputStream in = null;
MultipartReader reader = null;
try {
reader = new MultipartReader(request);
String shortTitle = reader.getValue("shortTitle");
String longTitle = reader.getValue("longTitle");
String objectives = reader.getValue("objectives");
String visibilityExpertRules = reader.getValue("visibilityExpertRules");
String filename = reader.getValue("filename", "attachment");
String accessExpertRules = reader.getValue("accessExpertRules");
in = new FileInputStream(reader.getFile());
SinglePageCustomConfig config = new SinglePageCustomConfig(in, filename);
return update(courseId, nodeId, shortTitle, longTitle, objectives, visibilityExpertRules, accessExpertRules, config, request);
} catch (Exception e) {
log.error("", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
MultipartReader.closeQuietly(reader);
IOUtils.closeQuietly(in);
}
}
use of org.olat.restapi.support.MultipartReader in project openolat by klemens.
the class CourseResourceFolderWebService method attachFileToCourseFolder.
private Response attachFileToCourseFolder(Long courseId, List<PathSegment> path, HttpServletRequest request) {
MultipartReader partsReader = null;
try {
partsReader = new MultipartReader(request);
File tmpFile = partsReader.getFile();
InputStream in = new FileInputStream(tmpFile);
String filename = partsReader.getValue("filename");
return attachFileToCourseFolder(courseId, path, filename, in, request);
} catch (FileNotFoundException e) {
log.error("", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
MultipartReader.closeQuietly(partsReader);
}
}
use of org.olat.restapi.support.MultipartReader in project openolat by klemens.
the class ForumWebService method replyToPostAttachment.
/**
* Upload the attachment of a message, as parameter:<br>
* filename The name of the attachment<br>
* file The attachment.
* @response.representation.200.mediaType application/json, application/xml
* @response.representation.200.doc Ok
* @response.representation.404.doc The identity or the portrait not found
* @param messageKey The key of the message
* @param request The HTTP request
* @return Ok
*/
@POST
@Path("posts/{messageKey}/attachments")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response replyToPostAttachment(@PathParam("messageKey") Long messageKey, @Context HttpServletRequest request) {
InputStream in = null;
MultipartReader partsReader = null;
try {
partsReader = new MultipartReader(request);
File tmpFile = partsReader.getFile();
in = new FileInputStream(tmpFile);
String filename = partsReader.getValue("filename");
return attachToPost(messageKey, filename, in, request);
} catch (FileNotFoundException e) {
log.error("", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
MultipartReader.closeQuietly(partsReader);
IOUtils.closeQuietly(in);
}
}
Aggregations