This commit is contained in:
Lucio Lelii 2018-07-05 14:26:08 +00:00
parent fc2d19204b
commit ec82e41948
6 changed files with 83 additions and 68 deletions

View File

@ -48,6 +48,11 @@
<dependencies>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>

View File

@ -19,12 +19,12 @@ import javax.ws.rs.core.MediaType;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.common.storagehub.model.acls.ACL;
import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.types.ACLList;
import org.gcube.data.access.storagehub.AuthorizationChecker;
import org.gcube.data.access.storagehub.handlers.CredentialHandler;
import org.gcube.smartgears.utils.InnerMethodName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -50,7 +50,7 @@ public class ACLManager {
@GET
@Path("{id}/acls")
public ACLList getACL() {
CalledMethodProvider.instance.set("getACLById");
InnerMethodName.instance.set("getACLById");
Session ses = null;
List<ACL> acls = new ArrayList<>();
try{

View File

@ -7,7 +7,6 @@ import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.security.AccessControlManager;
import javax.jcr.security.Privilege;
import javax.servlet.ServletContext;
@ -23,7 +22,6 @@ import javax.ws.rs.core.MediaType;
import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.common.storagehub.model.NodeConstants;
import org.gcube.common.storagehub.model.Paths;
import org.gcube.common.storagehub.model.acls.AccessType;
@ -37,6 +35,7 @@ import org.gcube.data.access.storagehub.accounting.AccountingHandler;
import org.gcube.data.access.storagehub.handlers.CredentialHandler;
import org.gcube.data.access.storagehub.handlers.ItemHandler;
import org.gcube.data.access.storagehub.handlers.VersionHandler;
import org.gcube.smartgears.utils.InnerMethodName;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -70,7 +69,7 @@ public class ItemSharing {
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String share(@FormDataParam("users") Set<String> users, @FormDataParam("defaultAccessType") AccessType accessType){
CalledMethodProvider.instance.set("findChildrenByNamePattern");
InnerMethodName.instance.set("findChildrenByNamePattern");
Session ses = null;
try{
String login = AuthorizationProvider.instance.get().getClient().getId();

View File

@ -33,7 +33,6 @@ import org.apache.tika.detect.Detector;
import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
@ -48,9 +47,13 @@ import org.gcube.data.access.storagehub.handlers.ItemHandler;
import org.gcube.data.access.storagehub.handlers.VersionHandler;
import org.gcube.data.access.storagehub.handlers.content.ContentHandler;
import org.gcube.data.access.storagehub.handlers.content.ContentHandlerFactory;
import org.gcube.smartgears.utils.InnerMethodName;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Path("items")
public class ItemsCreator {
@ -81,7 +84,7 @@ public class ItemsCreator {
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/create/{type:(?!FILE)[^/?$]*}")
public Response createItem(@PathParam("id") String id, @PathParam("type") String type,@QueryParam("name") String name, @QueryParam("description") String description){
CalledMethodProvider.instance.set(String.format("createItem(%s)",type));
InnerMethodName.instance.set(String.format("createItem(%s)",type));
log.info("create generic item called");
Session ses = null;
Item destinationItem = null;
@ -149,16 +152,19 @@ public class ItemsCreator {
@POST
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/create/FILE")
public Response createFileItem(InputStream stream , @PathParam("id") String id,
@QueryParam("name") String name, @QueryParam("description") String description){
CalledMethodProvider.instance.set("createItem(FILE)");
public Response createFileItem(@PathParam("id") String id, @FormDataParam("name") String name,
@FormDataParam("description") String description,
@FormDataParam("file") InputStream stream,
@FormDataParam("file") FormDataContentDisposition fileDetail){
InnerMethodName.instance.set("createItem(FILE)");
Session ses = null;
Item destinationItem = null;
try{
if (name==null || name.trim().isEmpty() || description ==null) throw new Exception("name or description are null");
final String login = AuthorizationProvider.instance.get().getClient().getId();
//TODO check if it is possible to change all the ACL on a workspace
@ -249,7 +255,7 @@ public class ItemsCreator {
handler.getContent().setMimeType(mimeType);
} catch (Throwable e) {
log.error("error retreiving content",e);
log.error("error retrieving mimeType",e);
throw new RuntimeException(e);
}
return handler;
@ -261,14 +267,20 @@ public class ItemsCreator {
@Override
public MetaInfo call() throws Exception {
String remotePath= path+"/"+name;
String storageId = Utils.getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient().put(true).LFile(mos.get()).RFile(remotePath);
long size = Utils.getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient().getSize().RFileById(storageId);
MetaInfo info = new MetaInfo();
info.setSize(size);
info.setStorageId(storageId);
info.setRemotePath(remotePath);
return info;
try {
String remotePath= path+"/"+name;
String storageId = Utils.getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient().put(true).LFile(mos.get()).RFile(remotePath);
long size = Utils.getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient().getSize().RFileById(storageId);
MetaInfo info = new MetaInfo();
info.setSize(size);
info.setStorageId(storageId);
info.setRemotePath(remotePath);
return info;
}catch (Throwable e) {
log.error("error writing content");
throw e;
}
}
};

View File

@ -37,7 +37,6 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.common.storagehub.model.NodeConstants;
import org.gcube.common.storagehub.model.Paths;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
@ -59,6 +58,7 @@ import org.gcube.data.access.storagehub.accounting.AccountingHandler;
import org.gcube.data.access.storagehub.handlers.CredentialHandler;
import org.gcube.data.access.storagehub.handlers.ItemHandler;
import org.gcube.data.access.storagehub.handlers.VersionHandler;
import org.gcube.smartgears.utils.InnerMethodName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -90,7 +90,7 @@ public class ItemsManager {
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public ItemWrapper<Item> getById(@QueryParam("exclude") List<String> excludes){
CalledMethodProvider.instance.set("getById");
InnerMethodName.instance.set("getById");
Session ses = null;
Item toReturn = null;
try{
@ -112,7 +112,7 @@ public class ItemsManager {
@Path("{id}/items/{name}")
@Produces(MediaType.APPLICATION_JSON)
public ItemList findChildrenByNamePattern(@QueryParam("exclude") List<String> excludes, @PathParam("name") String name){
CalledMethodProvider.instance.set("findChildrenByNamePattern");
InnerMethodName.instance.set("findChildrenByNamePattern");
Session ses = null;
List<Item> toReturn = new ArrayList<>();
try{
@ -137,7 +137,7 @@ public class ItemsManager {
@Path("{id}/children/count")
@Produces(MediaType.APPLICATION_JSON)
public Long countById(@QueryParam("showHidden") Boolean showHidden, @QueryParam("exclude") List<String> excludes){
CalledMethodProvider.instance.set("countById");
InnerMethodName.instance.set("countById");
Session ses = null;
Long toReturn = null;
try{
@ -158,7 +158,7 @@ public class ItemsManager {
@Path("{id}/children")
@Produces(MediaType.APPLICATION_JSON)
public ItemList listById(@QueryParam("showHidden") Boolean showHidden, @QueryParam("exclude") List<String> excludes){
CalledMethodProvider.instance.set("listById");
InnerMethodName.instance.set("listById");
Session ses = null;
List<? extends Item> toReturn = null;
try{
@ -180,7 +180,7 @@ public class ItemsManager {
@Path("{id}/children/paged")
@Produces(MediaType.APPLICATION_JSON)
public ItemList listByIdPaged(@QueryParam("showHidden") Boolean showHidden, @QueryParam("start") Integer start, @QueryParam("limit") Integer limit, @QueryParam("exclude") List<String> excludes){
CalledMethodProvider.instance.set("listByIdPaged");
InnerMethodName.instance.set("listByIdPaged");
Session ses = null;
List<? extends Item> toReturn = null;
try{
@ -201,7 +201,7 @@ public class ItemsManager {
@GET
@Path("{id}/publiclink")
public URL getPubliclink() {
CalledMethodProvider.instance.set("getPubliclink");
InnerMethodName.instance.set("getPubliclink");
//TODO: check who can call this method
Session ses = null;
try{
@ -231,7 +231,7 @@ public class ItemsManager {
@Path("{id}/rootSharedFolder")
@Produces(MediaType.APPLICATION_JSON)
public ItemWrapper<Item> getRootSharedFolder(@QueryParam("exclude") List<String> excludes){
CalledMethodProvider.instance.set("getRootSharedFolder");
InnerMethodName.instance.set("getRootSharedFolder");
Session ses = null;
try{
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
@ -259,7 +259,7 @@ public class ItemsManager {
@Path("{id}/anchestors")
@Produces(MediaType.APPLICATION_JSON)
public ItemList getAnchestors(@QueryParam("exclude") List<String> excludes){
CalledMethodProvider.instance.set("getAnchestors");
InnerMethodName.instance.set("getAnchestors");
org.gcube.common.storagehub.model.Path absolutePath = Utils.getHomePath();
Session ses = null;
List<Item> toReturn = new LinkedList<>();
@ -303,7 +303,7 @@ public class ItemsManager {
@GET
@Path("{id}/download")
public Response download(){
CalledMethodProvider.instance.set("downloadById");
InnerMethodName.instance.set("downloadById");
Session ses = null;
try{
final String login = AuthorizationProvider.instance.get().getClient().getId();
@ -370,7 +370,7 @@ public class ItemsManager {
@PUT
@Path("{id}/move")
public Response move(@QueryParam("destinationId") String destinationId, @PathParam("id") String identifier){
CalledMethodProvider.instance.set("move");
InnerMethodName.instance.set("move");
//TODO: check if identifier is The Workspace root, or the thras folder or the VREFolder root or if the item is thrashed
Session ses = null;
try{
@ -425,7 +425,7 @@ public class ItemsManager {
@DELETE
@Path("{id}")
public Response deleteItem(@PathParam("id") String identifier){
CalledMethodProvider.instance.set("deleteItem");
InnerMethodName.instance.set("deleteItem");
//TODO: check if identifier is The Workspace root, or the trash folder or the VREFolder root
//TODO: check also that is not already trashed
Session ses = null;

View File

@ -10,7 +10,6 @@ import javax.inject.Inject;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.query.Query;
import javax.jcr.query.QueryResult;
import javax.servlet.ServletContext;
@ -23,7 +22,6 @@ import javax.ws.rs.core.MediaType;
import javax.xml.ws.WebServiceException;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
@ -43,6 +41,7 @@ import org.gcube.data.access.storagehub.handlers.ItemHandler;
import org.gcube.data.access.storagehub.handlers.VRE;
import org.gcube.data.access.storagehub.handlers.VREManager;
import org.gcube.data.access.storagehub.query.sql2.evaluators.Evaluators;
import org.gcube.smartgears.utils.InnerMethodName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -79,7 +78,7 @@ public class WorkspaceManager {
@GET
@Produces(MediaType.APPLICATION_JSON)
public ItemWrapper<Item> getWorkspace(@QueryParam("relPath") String relPath){
CalledMethodProvider.instance.set("getWorkspace");
InnerMethodName.instance.set("getWorkspace");
Session ses = null;
org.gcube.common.storagehub.model.Path absolutePath;
if (relPath==null)
@ -132,7 +131,7 @@ public class WorkspaceManager {
@GET
@Produces(MediaType.APPLICATION_JSON)
public ItemWrapper<Item> getVreRootFolder(){
CalledMethodProvider.instance.set("getVreRootFolder");
InnerMethodName.instance.set("getVreRootFolder");
Session ses = null;
try {
String login = AuthorizationProvider.instance.get().getClient().getId();
@ -151,7 +150,7 @@ public class WorkspaceManager {
@GET
@Produces(MediaType.APPLICATION_JSON)
public ItemList getVreFolderRecentsDocument(){
CalledMethodProvider.instance.set("getVreFolderRecents");
InnerMethodName.instance.set("getVreFolderRecents");
Session ses = null;
try{
@ -177,7 +176,7 @@ public class WorkspaceManager {
@GET
@Produces(MediaType.APPLICATION_JSON)
public ItemWrapper<Item> getTrashRootFolder(){
CalledMethodProvider.instance.set("getTrashRootFolder");
InnerMethodName.instance.set("getTrashRootFolder");
Session ses = null;
org.gcube.common.storagehub.model.Path trashPath = Paths.append(Utils.getHomePath(), Constants.TRASH_ROOT_FOLDER_NAME);
@ -208,7 +207,7 @@ public class WorkspaceManager {
@GET
@Produces(MediaType.APPLICATION_JSON)
public ItemList getVreFolders(){
CalledMethodProvider.instance.set("getVreFolders");
InnerMethodName.instance.set("getVreFolders");
Session ses = null;
org.gcube.common.storagehub.model.Path vrePath = Paths.append(Utils.getHomePath(), Constants.VRE_FOLDER_PARENT_NAME);
@ -232,7 +231,7 @@ public class WorkspaceManager {
@GET
@Produces(MediaType.APPLICATION_JSON)
public ItemList getVreFoldersPaged(@QueryParam("start") Integer start, @QueryParam("limit") Integer limit){
CalledMethodProvider.instance.set("getVreFoldersPaged");
InnerMethodName.instance.set("getVreFoldersPaged");
Session ses = null;
org.gcube.common.storagehub.model.Path vrePath = Paths.append(Utils.getHomePath(), Constants.VRE_FOLDER_PARENT_NAME);
@ -258,7 +257,7 @@ public class WorkspaceManager {
@GET
@Produces(MediaType.APPLICATION_JSON)
public ItemList searchItems(@QueryParam("n") String node, @QueryParam("e") String jsonExpr, @QueryParam("o") List<String> orderField, @QueryParam("l") Integer limit, @QueryParam("f") Integer offset){
CalledMethodProvider.instance.set("searchItems");
InnerMethodName.instance.set("searchItems");
Session ses = null;
List<? extends Item> toReturn = new ArrayList<>();