|
|
|
@ -15,13 +15,10 @@ import java.util.concurrent.Future;
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.jcr.ItemNotFoundException;
|
|
|
|
|
import javax.jcr.Node;
|
|
|
|
|
import javax.jcr.NodeIterator;
|
|
|
|
|
import javax.jcr.PathNotFoundException;
|
|
|
|
|
import javax.jcr.RepositoryException;
|
|
|
|
|
import javax.jcr.Session;
|
|
|
|
|
import javax.jcr.lock.Lock;
|
|
|
|
|
import javax.jcr.lock.LockException;
|
|
|
|
|
import javax.jcr.lock.LockManager;
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
import javax.ws.rs.Consumes;
|
|
|
|
|
import javax.ws.rs.FormParam;
|
|
|
|
@ -37,7 +34,6 @@ import org.apache.commons.compress.archivers.ArchiveEntry;
|
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveException;
|
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
|
|
|
|
|
import org.apache.jackrabbit.commons.cnd.TemplateBuilderFactory.NodeDefinitionTemplateBuilder;
|
|
|
|
|
import org.apache.tika.config.TikaConfig;
|
|
|
|
|
import org.apache.tika.detect.Detector;
|
|
|
|
|
import org.apache.tika.io.TikaInputStream;
|
|
|
|
@ -56,7 +52,6 @@ import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.GCubeItem;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.SharedFolder;
|
|
|
|
|
import org.gcube.common.storagehub.model.types.ItemAction;
|
|
|
|
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
|
|
|
|
import org.gcube.data.access.storagehub.AuthorizationChecker;
|
|
|
|
@ -109,7 +104,7 @@ public class ItemsCreator {
|
|
|
|
|
@POST
|
|
|
|
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
|
|
|
|
@Path("/{id}/create/FOLDER")
|
|
|
|
|
public String createFolder(@PathParam("id") String id, @FormParam("name") String name, @FormParam("description") String description, @FormParam("hidden") boolean hidden) {
|
|
|
|
|
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;
|
|
|
|
@ -157,7 +152,7 @@ public class ItemsCreator {
|
|
|
|
|
ses.logout();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
return Response.ok(toReturn).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
@ -268,20 +263,14 @@ public class ItemsCreator {
|
|
|
|
|
|
|
|
|
|
private Node createFileItemInternally(Session ses, Node destinationNode, InputStream stream, String name, String description, String login, boolean withLock) throws RepositoryException, UserNotAuthorizedException, ItemLockedException, BackendGenericError{
|
|
|
|
|
|
|
|
|
|
ContentHandler handler = getContentHandler(stream , name, destinationNode.getPath(), login);
|
|
|
|
|
|
|
|
|
|
AbstractFileItem item =handler.buildItem(name, description, login);
|
|
|
|
|
|
|
|
|
|
//to inherit hidden property
|
|
|
|
|
//item.setHidden(destinationItem.isHidden());
|
|
|
|
|
|
|
|
|
|
log.debug("item prepared, fulfilling content");
|
|
|
|
|
log.debug("content prepared");
|
|
|
|
|
|
|
|
|
|
Node newNode;
|
|
|
|
|
try {
|
|
|
|
|
newNode = ses.getNode(org.gcube.common.storagehub.model.Paths.append(org.gcube.common.storagehub.model.Paths.getPath(destinationNode.getPath()), name).toPath());
|
|
|
|
|
authChecker.checkWriteAuthorizationControl(ses, newNode.getIdentifier(), false);
|
|
|
|
|
AbstractFileItem item = fillItemWithContent(stream, name, description, destinationNode.getPath(), login);
|
|
|
|
|
if (withLock) {
|
|
|
|
|
try {
|
|
|
|
|
ses.getWorkspace().getLockManager().lock(newNode.getPath(), true, true, 0,login);
|
|
|
|
@ -300,6 +289,7 @@ public class ItemsCreator {
|
|
|
|
|
}
|
|
|
|
|
}catch(PathNotFoundException pnf) {
|
|
|
|
|
authChecker.checkWriteAuthorizationControl(ses, destinationNode.getIdentifier(), true);
|
|
|
|
|
AbstractFileItem item = fillItemWithContent(stream, name, description, destinationNode.getPath(), login);
|
|
|
|
|
if (withLock) {
|
|
|
|
|
try {
|
|
|
|
|
log.debug("trying to acquire lock");
|
|
|
|
@ -320,7 +310,12 @@ public class ItemsCreator {
|
|
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AbstractFileItem fillItemWithContent(InputStream stream, String name, String description, String path, String login) throws BackendGenericError{
|
|
|
|
|
ContentHandler handler = getContentHandler(stream , name, path, login);
|
|
|
|
|
AbstractFileItem item =handler.buildItem(name, description, login);
|
|
|
|
|
return item ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|