use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.
the class RepositoryEntriesResource method putResource.
/**
* Import a resource in the repository
* @response.representation.mediaType multipart/form-data
* @response.representation.doc The file, its name and the resourcename
* @response.representation.200.qname {http://www.example.com}repositoryEntryVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc Import the resource and return the repository entry
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param filename The name of the imported file
* @param file The file input stream
* @param resourcename The name of the resource
* @param displayname The display name
* @param softkey The soft key (can be null)
* @param request The HTTP request
* @return
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response putResource(@Context HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
MultipartReader partsReader = null;
try {
Identity identity = RestSecurityHelper.getUserRequest(request).getIdentity();
partsReader = new MultipartReader(request);
File tmpFile = partsReader.getFile();
long length = tmpFile.length();
if (length > 0) {
Long accessRaw = partsReader.getLongValue("access");
int access = accessRaw != null ? accessRaw.intValue() : RepositoryEntry.ACC_OWNERS;
String softkey = partsReader.getValue("softkey");
String resourcename = partsReader.getValue("resourcename");
String displayname = partsReader.getValue("displayname");
RepositoryEntry re = importFileResource(identity, tmpFile, resourcename, displayname, softkey, access);
RepositoryEntryVO vo = ObjectFactory.get(re);
return Response.ok(vo).build();
}
return Response.serverError().status(Status.NO_CONTENT).build();
} catch (Exception e) {
log.error("Error while importing a file", e);
} finally {
MultipartReader.closeQuietly(partsReader);
}
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
use of org.olat.restapi.support.vo.RepositoryEntryVO in project openolat by klemens.
the class RepositoryEntryResource method replaceResource.
/**
* Replace a resource in the repository and update its display name. The implementation is
* limited to CP.
* @response.representation.mediaType multipart/form-data
* @response.representation.doc Import the resource file
* @response.representation.200.qname {http://www.example.com}repositoryEntryVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc Replace the resource and return the updated repository entry
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param repoEntryKey The key or soft key of the repository entry
* @param filename The name of the file
* @param file The file input stream
* @param displayname The display name
* @param request The HTTP request
* @return
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response replaceResource(@PathParam("repoEntryKey") String repoEntryKey, @Context HttpServletRequest request) {
if (!RestSecurityHelper.isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
MultipartReader reader = null;
try {
final RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
reader = new MultipartReader(request);
File tmpFile = reader.getFile();
String displayname = reader.getValue("displayname");
String location = reader.getValue("location");
String authors = reader.getValue("authors");
String description = reader.getValue("description");
String externalId = reader.getValue("externalId");
String externalRef = reader.getValue("externalRef");
String managedFlags = reader.getValue("managedFlags");
Identity identity = RestSecurityHelper.getUserRequest(request).getIdentity();
RepositoryEntry replacedRe;
if (tmpFile == null) {
replacedRe = repositoryManager.setDescriptionAndName(re, displayname, description, location, authors, externalId, externalRef, managedFlags, re.getLifecycle());
} else {
long length = tmpFile.length();
if (length == 0) {
return Response.serverError().status(Status.NO_CONTENT).build();
}
replacedRe = replaceFileResource(identity, re, tmpFile);
if (replacedRe == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else {
replacedRe = repositoryManager.setDescriptionAndName(replacedRe, displayname, description, location, authors, externalId, externalRef, managedFlags, replacedRe.getLifecycle());
}
}
RepositoryEntryVO vo = ObjectFactory.get(replacedRe);
return Response.ok(vo).build();
} catch (Exception e) {
log.error("Error while importing a file", e);
} finally {
MultipartReader.closeQuietly(reader);
}
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
Aggregations