git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/data-access/storagehub-webapp/1.0@179288 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
acbf277683
commit
9c4699b57e
14
pom.xml
14
pom.xml
|
@ -327,6 +327,20 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.test-framework</groupId>
|
||||
<artifactId>jersey-test-framework-core</artifactId>
|
||||
<version>2.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
|
||||
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
|
||||
<version>2.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${artifactId}</finalName>
|
||||
|
|
|
@ -39,6 +39,8 @@ import org.reflections.util.ConfigurationBuilder;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.collect.ClassToInstanceMap;
|
||||
|
||||
@Singleton
|
||||
public class Node2ItemConverter {
|
||||
|
||||
|
@ -304,7 +306,12 @@ public class Node2ItemConverter {
|
|||
|
||||
public boolean checkNodeType(Node node, Class<? extends Item> classToCompare) throws BackendGenericError{
|
||||
try {
|
||||
return (node.isNodeType(ClassHandler.instance().getNodeType(classToCompare)));
|
||||
|
||||
logger.info("class from nodetype is {} and class to compare is {}",ClassHandler.instance().get(node.getPrimaryNodeType().getName()), classToCompare);
|
||||
|
||||
return classToCompare.isAssignableFrom(ClassHandler.instance().get(node.getPrimaryNodeType().getName()));
|
||||
|
||||
//(node.isNodeType(ClassHandler.instance().getNodeType(classToCompare)));
|
||||
}catch (Throwable e) {
|
||||
throw new BackendGenericError(e);
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class UnshareHandler {
|
|||
Node unsharedNode;
|
||||
try {
|
||||
log.debug("user list is empty, I'm going to remove also the shared dir");
|
||||
//TODO: take the admin folder and remove his clone then move the shared folder from share to the user home and change the folder type
|
||||
//take the admin folder and remove his clone then move the shared folder from share to the user home and change the folder type
|
||||
String adminDirPath = (String)item.getUsers().getMap().get(login);
|
||||
String[] splitString = adminDirPath.split("/");
|
||||
String parentDirectoryId = splitString[0];
|
||||
|
|
|
@ -56,6 +56,7 @@ public class GroupManager {
|
|||
|
||||
@GET
|
||||
@Path("")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@AuthorizationControl(allowed={"lucio.lelii"}, exception=MyAuthException.class)
|
||||
public List<String> getGroups(){
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
@ -321,6 +311,11 @@ 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
|
||||
|
|
|
@ -588,12 +588,15 @@ public class ItemsManager {
|
|||
log.trace("current node is {}",currentNode.getPath());
|
||||
while (!(currentNode.getPath()+"/").equals(absolutePath.toPath())) {
|
||||
if (currentItem instanceof SharedFolder){
|
||||
Map<String, Object> users = ((SharedFolder) currentItem).getUsers().getMap();
|
||||
String[] user = ((String)users.get(login)).split("/");
|
||||
String parentId = user[0];
|
||||
currentNode = ses.getNodeByIdentifier(parentId);
|
||||
NodeIterator sharedSetIterator = currentNode.getSharedSet();
|
||||
while (sharedSetIterator.hasNext()) {
|
||||
Node sharedNode = sharedSetIterator.nextNode();
|
||||
if (sharedNode.getPath().startsWith(Utils.getWorkspacePath(login).toPath())) {
|
||||
currentNode = sharedNode.getParent();
|
||||
break;
|
||||
}
|
||||
}
|
||||
currentItem = node2Item.getItem(currentNode, excludes);
|
||||
|
||||
}else {
|
||||
currentNode = currentNode.getParent();
|
||||
currentItem = node2Item.getItem(currentNode, excludes);
|
||||
|
|
|
@ -25,7 +25,7 @@ no. 654119), SoBigData (grant no. 654024), AGINFRA PLUS (grant no. 731001).
|
|||
Version
|
||||
--------------------------------------------------
|
||||
|
||||
1.0.5-SNAPSHOT (2019-04-15)
|
||||
1.0.5-SNAPSHOT (2019-05-06)
|
||||
|
||||
Please see the file named "changelog.xml" in this directory for the release notes.
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package org.gcube.data.access.fs;
|
||||
|
||||
import javax.ws.rs.core.Application;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.data.access.storagehub.services.ItemsCreator;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ItemCreatorIntegrationTest extends JerseyTest {
|
||||
|
||||
@Override
|
||||
protected Application configure() {
|
||||
return new ResourceConfig(ItemsCreator.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenGetHiGreeting_whenCorrectRequest_thenResponseIsOkAndContainsHi() {
|
||||
Response response = target("/greetings/hi").request()
|
||||
.get();
|
||||
|
||||
|
||||
String content = response.readEntity(String.class);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue