2018-05-17 12:51:56 +02:00
|
|
|
package org.gcube.data.access.storagehub.services;
|
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
import java.io.IOException;
|
2018-05-17 12:51:56 +02:00
|
|
|
import java.io.InputStream;
|
2021-10-15 19:51:57 +02:00
|
|
|
import java.net.URI;
|
2019-07-29 16:26:08 +02:00
|
|
|
import java.net.URL;
|
2018-05-17 12:51:56 +02:00
|
|
|
|
|
|
|
import javax.inject.Inject;
|
2018-10-25 16:33:23 +02:00
|
|
|
import javax.jcr.RepositoryException;
|
2018-05-17 12:51:56 +02:00
|
|
|
import javax.jcr.Session;
|
|
|
|
import javax.servlet.ServletContext;
|
2021-10-15 19:51:57 +02:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
2018-05-17 12:51:56 +02:00
|
|
|
import javax.ws.rs.Consumes;
|
2018-10-25 16:33:23 +02:00
|
|
|
import javax.ws.rs.FormParam;
|
2018-05-17 12:51:56 +02:00
|
|
|
import javax.ws.rs.POST;
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
import javax.ws.rs.PathParam;
|
2021-10-15 19:51:57 +02:00
|
|
|
import javax.ws.rs.QueryParam;
|
2018-05-17 12:51:56 +02:00
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
2019-03-26 17:09:26 +01:00
|
|
|
import javax.ws.rs.core.Response;
|
2018-05-17 12:51:56 +02:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
import org.apache.commons.compress.archivers.ArchiveException;
|
|
|
|
import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse;
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
|
|
import org.gcube.common.storagehub.model.items.GCubeItem;
|
2020-03-16 16:55:26 +01:00
|
|
|
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
2018-07-03 12:15:35 +02:00
|
|
|
import org.gcube.data.access.storagehub.handlers.CredentialHandler;
|
2020-04-08 21:11:43 +02:00
|
|
|
import org.gcube.data.access.storagehub.handlers.items.ItemHandler;
|
|
|
|
import org.gcube.data.access.storagehub.handlers.items.builders.ArchiveStructureCreationParameter;
|
|
|
|
import org.gcube.data.access.storagehub.handlers.items.builders.FileCreationParameters;
|
|
|
|
import org.gcube.data.access.storagehub.handlers.items.builders.FolderCreationParameters;
|
|
|
|
import org.gcube.data.access.storagehub.handlers.items.builders.GCubeItemCreationParameters;
|
|
|
|
import org.gcube.data.access.storagehub.handlers.items.builders.ItemsParameterBuilder;
|
|
|
|
import org.gcube.data.access.storagehub.handlers.items.builders.URLCreationParameters;
|
2020-03-16 16:55:26 +01:00
|
|
|
import org.gcube.smartgears.annotations.ManagedBy;
|
2018-07-05 16:26:08 +02:00
|
|
|
import org.gcube.smartgears.utils.InnerMethodName;
|
|
|
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
|
|
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
2018-05-17 12:51:56 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-07-05 16:26:08 +02:00
|
|
|
|
2018-06-29 16:59:24 +02:00
|
|
|
@Path("items")
|
2020-03-16 16:55:26 +01:00
|
|
|
@ManagedBy(StorageHubAppllicationManager.class)
|
2021-03-31 14:49:47 +02:00
|
|
|
public class ItemsCreator extends Impersonable{
|
2018-05-17 12:51:56 +02:00
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ItemsCreator.class);
|
2021-10-15 19:51:57 +02:00
|
|
|
|
2021-04-07 12:38:18 +02:00
|
|
|
@Context
|
|
|
|
ServletContext context;
|
2021-10-15 19:51:57 +02:00
|
|
|
|
2021-03-31 14:49:47 +02:00
|
|
|
RepositoryInitializer repository = StorageHubAppllicationManager.repository;
|
2021-10-15 19:51:57 +02:00
|
|
|
|
2018-05-28 12:01:01 +02:00
|
|
|
@Inject
|
2020-04-08 21:11:43 +02:00
|
|
|
ItemHandler itemHandler;
|
2019-03-27 15:51:27 +01:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
@POST
|
2018-05-28 12:01:01 +02:00
|
|
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
2018-07-12 15:44:11 +02:00
|
|
|
@Path("/{id}/create/FOLDER")
|
2021-04-07 12:38:18 +02:00
|
|
|
public Response createFolder(@PathParam("id") String id, @FormParam("name") String name,
|
|
|
|
@FormParam("description") String description, @FormParam("hidden") boolean hidden) {
|
2018-10-25 16:33:23 +02:00
|
|
|
InnerMethodName.instance.set("createItem(FOLDER)");
|
|
|
|
log.info("create folder item called");
|
2018-05-17 12:51:56 +02:00
|
|
|
Session ses = null;
|
2018-10-25 16:33:23 +02:00
|
|
|
String toReturn = null;
|
2018-05-17 12:51:56 +02:00
|
|
|
try{
|
2018-07-03 12:15:35 +02:00
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
2021-03-31 14:49:47 +02:00
|
|
|
ItemsParameterBuilder<FolderCreationParameters> builder = FolderCreationParameters.builder().name(name).description(description).hidden(hidden).on(id).with(ses).author(currentUser);
|
2021-04-07 12:38:18 +02:00
|
|
|
toReturn = itemHandler.create(builder.build());
|
2018-10-25 16:33:23 +02:00
|
|
|
}catch(StorageHubException she ){
|
2019-03-26 17:09:26 +01:00
|
|
|
log.error(she.getErrorMessage(), she);
|
2019-04-09 18:10:42 +02:00
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
2018-10-25 16:33:23 +02:00
|
|
|
}catch(RepositoryException re ){
|
|
|
|
log.error("jcr error creating item", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re));
|
2020-04-08 21:11:43 +02:00
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
2018-10-25 16:33:23 +02:00
|
|
|
}finally{
|
|
|
|
if (ses!=null)
|
|
|
|
ses.logout();
|
2019-03-27 15:51:27 +01:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
}
|
2019-05-06 18:56:22 +02:00
|
|
|
return Response.ok(toReturn).build();
|
2018-10-25 16:33:23 +02:00
|
|
|
}
|
2018-07-05 16:26:08 +02:00
|
|
|
|
2021-04-07 12:38:18 +02:00
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
|
@Path("/{id}/create/EXTERNALFOLDER")
|
|
|
|
public Response createExternalFolder(@PathParam("id") String id, @FormParam("name") String name,
|
|
|
|
@FormParam("description") String description, @FormParam("hidden") boolean hidden,
|
|
|
|
@FormParam("pluginName") String pluginName,
|
|
|
|
@FormParam("parameters") String pluginParameters) {
|
|
|
|
InnerMethodName.instance.set("createItem(EXTERNALFOLDER)");
|
|
|
|
log.info("create folder item called");
|
|
|
|
Session ses = null;
|
|
|
|
String toReturn = null;
|
|
|
|
try{
|
|
|
|
//TODO
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
ItemsParameterBuilder<FolderCreationParameters> builder = FolderCreationParameters.builder().name(name)
|
|
|
|
.description(description).onRepository(pluginName).withParameters(null).hidden(hidden).on(id).with(ses).author(currentUser);
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
}catch(RepositoryException re ){
|
|
|
|
log.error("jcr error creating item", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re));
|
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
}finally{
|
|
|
|
if (ses!=null)
|
|
|
|
ses.logout();
|
|
|
|
|
|
|
|
}
|
|
|
|
return Response.ok(toReturn).build();
|
|
|
|
}
|
2021-10-15 19:51:57 +02:00
|
|
|
|
2019-07-29 16:26:08 +02:00
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
|
@Path("/{id}/create/URL")
|
|
|
|
public Response createURL(@PathParam("id") String id, @FormParam("name") String name, @FormParam("description") String description, @FormParam("value") URL value) {
|
|
|
|
InnerMethodName.instance.set("createItem(URL)");
|
|
|
|
log.info("create url called");
|
|
|
|
Session ses = null;
|
|
|
|
String toReturn = null;
|
|
|
|
try{
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
2021-10-15 19:51:57 +02:00
|
|
|
|
2021-03-31 14:49:47 +02:00
|
|
|
ItemsParameterBuilder<URLCreationParameters> builder = URLCreationParameters.builder().name(name).description(description).url(value).on(id).with(ses).author(currentUser);
|
2020-04-08 21:11:43 +02:00
|
|
|
|
2021-04-07 12:38:18 +02:00
|
|
|
toReturn = itemHandler.create(builder.build());
|
2019-07-29 16:26:08 +02:00
|
|
|
}catch(StorageHubException she ){
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
}catch(RepositoryException re ){
|
|
|
|
log.error("jcr error creating item", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re));
|
2020-04-08 21:11:43 +02:00
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
2019-07-29 16:26:08 +02:00
|
|
|
}finally{
|
|
|
|
if (ses!=null)
|
|
|
|
ses.logout();
|
|
|
|
|
|
|
|
}
|
|
|
|
return Response.ok(toReturn).build();
|
|
|
|
}
|
2021-10-15 19:51:57 +02:00
|
|
|
|
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("/{id}/create/GCUBEITEM")
|
|
|
|
public String createGcubeItem(@PathParam("id") String id, GCubeItem item) {
|
|
|
|
InnerMethodName.instance.set("createItem(GCUBEITEM)");
|
|
|
|
log.info("create Gcube item called");
|
|
|
|
Session ses = null;
|
|
|
|
String toReturn = null;
|
2019-03-27 15:51:27 +01:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
try{
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
2021-03-31 14:49:47 +02:00
|
|
|
ItemsParameterBuilder<GCubeItemCreationParameters> builder = GCubeItemCreationParameters.builder().item(item).on(id).with(ses).author(currentUser);
|
2021-10-15 19:51:57 +02:00
|
|
|
|
2021-04-07 12:38:18 +02:00
|
|
|
toReturn = itemHandler.create(builder.build());
|
2018-10-25 16:33:23 +02:00
|
|
|
}catch(StorageHubException she ){
|
2019-03-26 17:09:26 +01:00
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
2018-10-25 16:33:23 +02:00
|
|
|
}catch(RepositoryException re ){
|
|
|
|
log.error("jcr error creating item", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re));
|
2020-04-08 21:11:43 +02:00
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
2018-10-25 16:33:23 +02:00
|
|
|
}finally{
|
|
|
|
if (ses!=null)
|
2018-05-17 12:51:56 +02:00
|
|
|
ses.logout();
|
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
return toReturn;
|
2018-05-17 12:51:56 +02:00
|
|
|
}
|
2019-03-27 15:51:27 +01:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
|
2021-10-15 19:51:57 +02:00
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
|
@Path("/{id}/create/FILE")
|
|
|
|
public String createFileItemFromUrl(@PathParam("id") String id, @FormParam("name") String name,
|
|
|
|
@FormParam("description") String description,
|
|
|
|
@FormParam("url") String url){
|
|
|
|
InnerMethodName.instance.set("createItem(FILEFromUrl)");
|
|
|
|
|
|
|
|
Session ses = null;
|
|
|
|
String toReturn = null;
|
|
|
|
try{
|
|
|
|
|
|
|
|
log.debug("UPLOAD: call started");
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
try(InputStream stream = new URI(url).toURL().openStream()){
|
|
|
|
ItemsParameterBuilder<FileCreationParameters> builder = FileCreationParameters.builder().name(name).description(description).stream(stream)
|
|
|
|
.on(id).with(ses).author(currentUser);
|
|
|
|
log.debug("UPLOAD: item prepared");
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
}
|
|
|
|
log.debug("UPLOAD: call finished");
|
|
|
|
}catch(RepositoryException re ){
|
|
|
|
log.error("jcr error creating file item", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating file item", re));
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
}finally{
|
|
|
|
if (ses!=null && ses.isLive()) {
|
|
|
|
log.info("session closed");
|
|
|
|
ses.logout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
|
|
|
|
@Path("/{id}/create/FILE")
|
|
|
|
public String createFileItemStream(@PathParam("id") String id, @QueryParam("name") String name,
|
|
|
|
@QueryParam("description") String description, @Context HttpServletRequest request){
|
|
|
|
InnerMethodName.instance.set("createItem(FILEByStream)");
|
|
|
|
|
|
|
|
Session ses = null;
|
|
|
|
String toReturn = null;
|
|
|
|
try{
|
|
|
|
|
|
|
|
log.debug("UPLOAD: call started");
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
ItemsParameterBuilder<FileCreationParameters> builder = FileCreationParameters.builder().name(name).description(description).stream(request.getInputStream())
|
|
|
|
.on(id).with(ses).author(currentUser);
|
|
|
|
log.debug("UPLOAD: item prepared");
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
log.debug("UPLOAD: call finished");
|
|
|
|
}catch(RepositoryException re ){
|
|
|
|
log.error("jcr error creating file item", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating file item", re));
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
}finally{
|
|
|
|
if (ses!=null && ses.isLive()) {
|
|
|
|
log.info("session closed");
|
|
|
|
ses.logout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
@POST
|
2018-07-05 16:26:08 +02:00
|
|
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
2018-05-17 12:51:56 +02:00
|
|
|
@Path("/{id}/create/FILE")
|
2018-10-25 16:33:23 +02:00
|
|
|
public String createFileItem(@PathParam("id") String id, @FormDataParam("name") String name,
|
2018-07-05 16:26:08 +02:00
|
|
|
@FormDataParam("description") String description,
|
|
|
|
@FormDataParam("file") InputStream stream,
|
|
|
|
@FormDataParam("file") FormDataContentDisposition fileDetail){
|
|
|
|
InnerMethodName.instance.set("createItem(FILE)");
|
2018-10-25 16:33:23 +02:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
Session ses = null;
|
2018-10-25 16:33:23 +02:00
|
|
|
String toReturn = null;
|
2018-05-17 12:51:56 +02:00
|
|
|
try{
|
2021-10-15 19:51:57 +02:00
|
|
|
|
|
|
|
log.debug("UPLOAD: call started");
|
2018-07-03 12:15:35 +02:00
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
2020-04-08 21:11:43 +02:00
|
|
|
ItemsParameterBuilder<FileCreationParameters> builder = FileCreationParameters.builder().name(name).description(description).stream(stream).fileDetails(fileDetail)
|
2021-03-31 14:49:47 +02:00
|
|
|
.on(id).with(ses).author(currentUser);
|
2021-10-15 19:51:57 +02:00
|
|
|
log.debug("UPLOAD: item prepared");
|
2021-04-07 12:38:18 +02:00
|
|
|
toReturn = itemHandler.create(builder.build());
|
2021-10-15 19:51:57 +02:00
|
|
|
log.debug("UPLOAD: call finished");
|
2018-10-25 16:33:23 +02:00
|
|
|
}catch(RepositoryException re ){
|
|
|
|
log.error("jcr error creating file item", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating file item", re));
|
|
|
|
}catch(StorageHubException she ){
|
2019-03-26 17:09:26 +01:00
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
2019-02-14 12:01:59 +01:00
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
}finally{
|
|
|
|
if (ses!=null && ses.isLive()) {
|
|
|
|
log.info("session closed");
|
2018-05-17 12:51:56 +02:00
|
|
|
ses.logout();
|
2019-02-14 12:01:59 +01:00
|
|
|
}
|
2018-05-17 12:51:56 +02:00
|
|
|
}
|
2018-10-25 16:33:23 +02:00
|
|
|
return toReturn;
|
2019-03-27 15:51:27 +01:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-15 19:51:57 +02:00
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
|
@Path("/{id}/create/ARCHIVE")
|
|
|
|
public String uploadArchiveFromURL(@PathParam("id") String id, @FormParam("parentFolderName") String parentFolderName,
|
|
|
|
@FormParam("url") String url){
|
|
|
|
InnerMethodName.instance.set("createItem(ARCHIVEFromURL)");
|
|
|
|
|
|
|
|
Session ses = null;
|
|
|
|
String toReturn = null;
|
|
|
|
try{
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
try(InputStream stream = new URI(url).toURL().openStream()){
|
|
|
|
ItemsParameterBuilder<ArchiveStructureCreationParameter> builder = ArchiveStructureCreationParameter.builder().parentName(parentFolderName).stream(stream)
|
|
|
|
.on(id).with(ses).author(currentUser);
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
}catch(RepositoryException | ArchiveException | IOException re){
|
|
|
|
log.error("jcr error extracting archive", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error extracting archive", re));
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
} finally{
|
|
|
|
if (ses!=null)
|
|
|
|
ses.logout();
|
|
|
|
|
|
|
|
}
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
|
2019-03-27 15:51:27 +01:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
|
2018-07-12 15:44:11 +02:00
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
|
|
|
@Path("/{id}/create/ARCHIVE")
|
2018-10-25 16:33:23 +02:00
|
|
|
public String uploadArchive(@PathParam("id") String id, @FormDataParam("parentFolderName") String parentFolderName,
|
2018-07-12 15:44:11 +02:00
|
|
|
@FormDataParam("file") InputStream stream,
|
|
|
|
@FormDataParam("file") FormDataContentDisposition fileDetail){
|
2018-10-25 16:33:23 +02:00
|
|
|
InnerMethodName.instance.set("createItem(ARCHIVE)");
|
|
|
|
|
2018-07-12 15:44:11 +02:00
|
|
|
Session ses = null;
|
2018-10-25 16:33:23 +02:00
|
|
|
String toReturn = null;
|
2018-07-12 15:44:11 +02:00
|
|
|
try{
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
2020-04-08 21:11:43 +02:00
|
|
|
ItemsParameterBuilder<ArchiveStructureCreationParameter> builder = ArchiveStructureCreationParameter.builder().parentName(parentFolderName).stream(stream).fileDetails(fileDetail)
|
2021-03-31 14:49:47 +02:00
|
|
|
.on(id).with(ses).author(currentUser);
|
2021-10-15 19:51:57 +02:00
|
|
|
|
2021-04-07 12:38:18 +02:00
|
|
|
toReturn = itemHandler.create(builder.build());
|
2019-03-27 15:51:27 +01:00
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
}catch(RepositoryException | ArchiveException | IOException re){
|
|
|
|
log.error("jcr error extracting archive", re);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error extracting archive", re));
|
|
|
|
}catch(StorageHubException she ){
|
2019-03-26 17:09:26 +01:00
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
2020-04-08 21:11:43 +02:00
|
|
|
}catch(Throwable e ){
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
2018-07-12 15:44:11 +02:00
|
|
|
} finally{
|
2018-10-25 16:33:23 +02:00
|
|
|
if (ses!=null)
|
2018-07-12 15:44:11 +02:00
|
|
|
ses.logout();
|
|
|
|
|
2018-10-25 16:33:23 +02:00
|
|
|
}
|
|
|
|
return toReturn;
|
2018-07-12 15:44:11 +02:00
|
|
|
}
|
2018-05-17 12:51:56 +02:00
|
|
|
|
|
|
|
|
2021-10-15 19:51:57 +02:00
|
|
|
|
2018-05-17 12:51:56 +02:00
|
|
|
|
|
|
|
}
|