|
|
|
@ -20,6 +20,7 @@ import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
|
|
import javax.enterprise.context.RequestScoped;
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.jcr.ItemNotFoundException;
|
|
|
|
|
import javax.jcr.Node;
|
|
|
|
|
import javax.jcr.NodeIterator;
|
|
|
|
|
import javax.jcr.RepositoryException;
|
|
|
|
@ -38,6 +39,7 @@ import javax.ws.rs.QueryParam;
|
|
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
import javax.ws.rs.core.Response.Status;
|
|
|
|
|
import javax.ws.rs.core.StreamingOutput;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
|
@ -52,6 +54,7 @@ import org.gcube.common.storagehub.model.Excludes;
|
|
|
|
|
import org.gcube.common.storagehub.model.NodeConstants;
|
|
|
|
|
import org.gcube.common.storagehub.model.Paths;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
|
|
@ -116,21 +119,24 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public ItemWrapper<Item> getById(@QueryParam("exclude") List<String> excludes){
|
|
|
|
|
InnerMethodName.instance.set("getById");
|
|
|
|
|
Session ses = null;
|
|
|
|
|
Item toReturn = null;
|
|
|
|
|
try{
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
Node node = ses.getNodeByIdentifier(id);
|
|
|
|
|
authChecker.checkReadAuthorizationControl(ses, id);
|
|
|
|
|
toReturn = node2Item.getItem(ses.getNodeByIdentifier(id), excludes);
|
|
|
|
|
toReturn = node2Item.getItem(node, excludes);
|
|
|
|
|
}catch (ItemNotFoundException e) {
|
|
|
|
|
log.error("id {} not found",id,e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND);
|
|
|
|
|
}catch(RepositoryException re){
|
|
|
|
|
log.error("jcr error getting item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error searching item", re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error getting item", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -141,7 +147,6 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}/items/{name}")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public ItemList findChildrenByNamePattern(@QueryParam("exclude") List<String> excludes, @PathParam("name") String name){
|
|
|
|
|
InnerMethodName.instance.set("findChildrenByNamePattern");
|
|
|
|
|
Session ses = null;
|
|
|
|
@ -166,13 +171,15 @@ public class ItemsManager {
|
|
|
|
|
|| (nodeName.equals(cleanedName) || title.equals(cleanedName)))
|
|
|
|
|
toReturn.add(node2Item.getItem(child, excludes));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}catch (ItemNotFoundException e) {
|
|
|
|
|
log.error("id {} not found",id,e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND);
|
|
|
|
|
}catch(RepositoryException re){
|
|
|
|
|
log.error("jcr error searching item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error searching item", re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error searching item", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -184,23 +191,24 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}/children/count")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public Long countById(@QueryParam("showHidden") Boolean showHidden, @QueryParam("exclude") List<String> excludes, @QueryParam("onlyType") String nodeType){
|
|
|
|
|
InnerMethodName.instance.set("countById");
|
|
|
|
|
Session ses = null;
|
|
|
|
|
Long toReturn = null;
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
authChecker.checkReadAuthorizationControl(ses, id);
|
|
|
|
|
toReturn = Utils.getItemCount(ses.getNodeByIdentifier(id), showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null);
|
|
|
|
|
}catch (ItemNotFoundException e) {
|
|
|
|
|
log.error("id {} not found",id,e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND);
|
|
|
|
|
}catch(RuntimeException | RepositoryException re){
|
|
|
|
|
log.error("jcr error counting item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error counting item", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -210,7 +218,6 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}/children")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public ItemList listById(@QueryParam("showHidden") Boolean showHidden, @QueryParam("exclude") List<String> excludes, @QueryParam("onlyType") String nodeType){
|
|
|
|
|
InnerMethodName.instance.set("listById");
|
|
|
|
|
Session ses = null;
|
|
|
|
@ -219,12 +226,15 @@ public class ItemsManager {
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
authChecker.checkReadAuthorizationControl(ses, id);
|
|
|
|
|
toReturn = Utils.getItemList(ses.getNodeByIdentifier(id), excludes, null, showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null);
|
|
|
|
|
}catch (ItemNotFoundException e) {
|
|
|
|
|
log.error("id {} not found",id,e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND);
|
|
|
|
|
}catch(RepositoryException re){
|
|
|
|
|
log.error("jcr error getting children", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error getting children", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -235,7 +245,6 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@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, @QueryParam("onlyType") String nodeType){
|
|
|
|
|
InnerMethodName.instance.set("listByIdPaged");
|
|
|
|
|
Session ses = null;
|
|
|
|
@ -244,12 +253,15 @@ public class ItemsManager {
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
authChecker.checkReadAuthorizationControl(ses, id);
|
|
|
|
|
toReturn = Utils.getItemList(ses.getNodeByIdentifier(id), excludes, new Range(start, limit),showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null);
|
|
|
|
|
}catch (ItemNotFoundException e) {
|
|
|
|
|
log.error("id {} not found",id,e);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND);
|
|
|
|
|
}catch(RepositoryException re){
|
|
|
|
|
log.error("jcr error getting paged children", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error getting paged children", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -259,7 +271,6 @@ public class ItemsManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
@Path("publiclink/{id}")
|
|
|
|
|
@AuthorizationControl(allowed={"URIResolver"}, exception=MyAuthException.class)
|
|
|
|
|
public Response resolvePublicLink() {
|
|
|
|
@ -318,8 +329,8 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error getting public link", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error getting public link", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -328,7 +339,6 @@ public class ItemsManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
@Path("{id}/publiclink")
|
|
|
|
|
public URL getPublicLink(@QueryParam("version") String version) {
|
|
|
|
|
InnerMethodName.instance.set("getPubliclink");
|
|
|
|
@ -393,8 +403,8 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error getting public link", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error getting public link", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -412,7 +422,6 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}/rootSharedFolder")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public ItemWrapper<Item> getRootSharedFolder(@QueryParam("exclude") List<String> excludes){
|
|
|
|
|
InnerMethodName.instance.set("getRootSharedFolder");
|
|
|
|
|
Session ses = null;
|
|
|
|
@ -434,8 +443,8 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error getting rootSharedFolder", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error getting rootSharedFolder", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -455,7 +464,6 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}/versions")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public VersionList getVersions(){
|
|
|
|
|
InnerMethodName.instance.set("getVersions");
|
|
|
|
|
Session ses = null;
|
|
|
|
@ -481,8 +489,8 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error retrieving versions", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error retrieving versions", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -506,8 +514,8 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error downloading version", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error downloading version", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -555,7 +563,6 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}/anchestors")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public ItemList getAnchestors(@QueryParam("exclude") List<String> excludes){
|
|
|
|
|
InnerMethodName.instance.set("getAnchestors");
|
|
|
|
|
org.gcube.common.storagehub.model.Path absolutePath = Utils.getWorkspacePath();
|
|
|
|
@ -589,8 +596,8 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error getting anchestors", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error getting anchestors", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
@ -658,8 +665,8 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error download", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error download", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
} finally{
|
|
|
|
|
if (ses!=null) ses.logout();
|
|
|
|
|
}
|
|
|
|
@ -746,8 +753,8 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error moving item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error moving item", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
} finally{
|
|
|
|
|
if (ses!=null) {
|
|
|
|
|
ses.logout();
|
|
|
|
@ -820,9 +827,9 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error moving item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error moving item", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
} finally{
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null) {
|
|
|
|
|
ses.logout();
|
|
|
|
|
}
|
|
|
|
@ -875,9 +882,9 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error moving item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error moving item", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
} finally{
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null) {
|
|
|
|
|
ses.logout();
|
|
|
|
|
}
|
|
|
|
@ -917,9 +924,9 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error moving item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error moving item", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
} finally{
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null) {
|
|
|
|
|
ses.logout();
|
|
|
|
|
}
|
|
|
|
@ -964,9 +971,9 @@ public class ItemsManager {
|
|
|
|
|
log.error("jcr error moving item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error("error moving item", she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she);
|
|
|
|
|
} finally{
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null) {
|
|
|
|
|
ses.logout();
|
|
|
|
|
}
|
|
|
|
|