|
|
|
@ -38,45 +38,50 @@ import org.glassfish.jersey.media.multipart.FormDataParam;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
|
|
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
|
|
|
|
|
|
|
|
@Path("items")
|
|
|
|
|
@ManagedBy(StorageHubAppllicationManager.class)
|
|
|
|
|
public class ItemsCreator extends Impersonable{
|
|
|
|
|
@RequestHeaders({
|
|
|
|
|
@RequestHeader(name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), })
|
|
|
|
|
public class ItemsCreator extends Impersonable {
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ItemsCreator.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Context
|
|
|
|
|
ServletContext context;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RepositoryInitializer repository = StorageHubAppllicationManager.repository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
ItemHandler itemHandler;
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
|
|
@Path("/{id}/create/FOLDER")
|
|
|
|
|
public Response createFolder(@PathParam("id") String id, @FormParam("name") String name,
|
|
|
|
|
public Response createFolder(@PathParam("id") String id, @FormParam("name") String name,
|
|
|
|
|
@FormParam("description") String description, @FormParam("hidden") boolean hidden) {
|
|
|
|
|
InnerMethodName.instance.set("createItem(FOLDER)");
|
|
|
|
|
log.info("create folder item called");
|
|
|
|
|
Session ses = null;
|
|
|
|
|
String toReturn = null;
|
|
|
|
|
try{
|
|
|
|
|
try {
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
ItemsParameterBuilder<FolderCreationParameters> builder = FolderCreationParameters.builder().name(name).description(description).hidden(hidden).on(id).with(ses).author(currentUser);
|
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
ItemsParameterBuilder<FolderCreationParameters> builder = FolderCreationParameters.builder().name(name)
|
|
|
|
|
.description(description).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 ){
|
|
|
|
|
} catch (RepositoryException re) {
|
|
|
|
|
log.error("jcr error creating item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re));
|
|
|
|
|
}catch(Throwable e ){
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
} finally {
|
|
|
|
|
if (ses != null)
|
|
|
|
|
ses.logout();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -86,69 +91,70 @@ public class ItemsCreator extends Impersonable{
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
|
|
@Path("/{id}/create/EXTERNALFOLDER")
|
|
|
|
|
public Response createExternalFolder(@PathParam("id") String id, @FormParam("name") String name,
|
|
|
|
|
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) {
|
|
|
|
|
@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
|
|
|
|
|
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 ){
|
|
|
|
|
.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 ){
|
|
|
|
|
} catch (RepositoryException re) {
|
|
|
|
|
log.error("jcr error creating item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re));
|
|
|
|
|
}catch(Throwable e ){
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
} finally {
|
|
|
|
|
if (ses != null)
|
|
|
|
|
ses.logout();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return Response.ok(toReturn).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
|
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{
|
|
|
|
|
try {
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
|
|
|
|
|
ItemsParameterBuilder<URLCreationParameters> builder = URLCreationParameters.builder().name(name).description(description).url(value).on(id).with(ses).author(currentUser);
|
|
|
|
|
|
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
ItemsParameterBuilder<URLCreationParameters> builder = URLCreationParameters.builder().name(name)
|
|
|
|
|
.description(description).url(value).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 ){
|
|
|
|
|
} catch (RepositoryException re) {
|
|
|
|
|
log.error("jcr error creating item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re));
|
|
|
|
|
}catch(Throwable e ){
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
} finally {
|
|
|
|
|
if (ses != null)
|
|
|
|
|
ses.logout();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return Response.ok(toReturn).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
|
@Path("/{id}/create/GCUBEITEM")
|
|
|
|
@ -158,58 +164,58 @@ public class ItemsCreator extends Impersonable{
|
|
|
|
|
Session ses = null;
|
|
|
|
|
String toReturn = null;
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
try {
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
ItemsParameterBuilder<GCubeItemCreationParameters> builder = GCubeItemCreationParameters.builder().item(item).on(id).with(ses).author(currentUser);
|
|
|
|
|
|
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
ItemsParameterBuilder<GCubeItemCreationParameters> builder = GCubeItemCreationParameters.builder()
|
|
|
|
|
.item(item).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 ){
|
|
|
|
|
} catch (RepositoryException re) {
|
|
|
|
|
log.error("jcr error creating item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re));
|
|
|
|
|
}catch(Throwable e ){
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
} finally {
|
|
|
|
|
if (ses != null)
|
|
|
|
|
ses.logout();
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
|
|
|
|
@Path("/{id}/create/FILE")
|
|
|
|
|
public String createFileItem(@PathParam("id") String id, @FormDataParam("name") String name,
|
|
|
|
|
@FormDataParam("description") String description,
|
|
|
|
|
@FormDataParam("file") InputStream stream,
|
|
|
|
|
@FormDataParam("file") FormDataContentDisposition fileDetail){
|
|
|
|
|
@FormDataParam("description") String description, @FormDataParam("file") InputStream stream,
|
|
|
|
|
@FormDataParam("file") FormDataContentDisposition fileDetail) {
|
|
|
|
|
InnerMethodName.instance.set("createItem(FILE)");
|
|
|
|
|
|
|
|
|
|
Session ses = null;
|
|
|
|
|
String toReturn = null;
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
ItemsParameterBuilder<FileCreationParameters> builder = FileCreationParameters.builder().name(name).description(description).stream(stream).fileDetails(fileDetail)
|
|
|
|
|
.on(id).with(ses).author(currentUser);
|
|
|
|
|
|
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
|
|
|
|
|
|
}catch(RepositoryException re ){
|
|
|
|
|
ItemsParameterBuilder<FileCreationParameters> builder = FileCreationParameters.builder().name(name)
|
|
|
|
|
.description(description).stream(stream).fileDetails(fileDetail).on(id).with(ses)
|
|
|
|
|
.author(currentUser);
|
|
|
|
|
|
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
|
|
|
|
|
|
} catch (RepositoryException re) {
|
|
|
|
|
log.error("jcr error creating file item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating file item", re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
} catch (StorageHubException she) {
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}catch(Throwable e ){
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null && ses.isLive()) {
|
|
|
|
|
} finally {
|
|
|
|
|
if (ses != null && ses.isLive()) {
|
|
|
|
|
log.info("session closed");
|
|
|
|
|
ses.logout();
|
|
|
|
|
}
|
|
|
|
@ -218,47 +224,39 @@ public class ItemsCreator extends Impersonable{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
|
|
|
|
@Path("/{id}/create/ARCHIVE")
|
|
|
|
|
public String uploadArchive(@PathParam("id") String id, @FormDataParam("parentFolderName") String parentFolderName,
|
|
|
|
|
@FormDataParam("file") InputStream stream,
|
|
|
|
|
@FormDataParam("file") FormDataContentDisposition fileDetail){
|
|
|
|
|
@FormDataParam("file") InputStream stream, @FormDataParam("file") FormDataContentDisposition fileDetail) {
|
|
|
|
|
InnerMethodName.instance.set("createItem(ARCHIVE)");
|
|
|
|
|
|
|
|
|
|
Session ses = null;
|
|
|
|
|
String toReturn = null;
|
|
|
|
|
try{
|
|
|
|
|
try {
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
|
|
|
|
|
ItemsParameterBuilder<ArchiveStructureCreationParameter> builder = ArchiveStructureCreationParameter.builder().parentName(parentFolderName).stream(stream).fileDetails(fileDetail)
|
|
|
|
|
.on(id).with(ses).author(currentUser);
|
|
|
|
|
|
|
|
|
|
toReturn = itemHandler.create(builder.build());
|
|
|
|
|
ItemsParameterBuilder<ArchiveStructureCreationParameter> builder = ArchiveStructureCreationParameter
|
|
|
|
|
.builder().parentName(parentFolderName).stream(stream).fileDetails(fileDetail).on(id).with(ses)
|
|
|
|
|
.author(currentUser);
|
|
|
|
|
|
|
|
|
|
}catch(RepositoryException | ArchiveException | IOException re){
|
|
|
|
|
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 ){
|
|
|
|
|
} catch (StorageHubException she) {
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}catch(Throwable e ){
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("unexpected error", e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(e));
|
|
|
|
|
} finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
} finally {
|
|
|
|
|
if (ses != null)
|
|
|
|
|
ses.logout();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|