package gr.ebs.gss.server.webdav.milton;
import static gr.ebs.gss.server.configuration.GSSConfigurationFactory.getConfiguration;
-import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
-import gr.ebs.gss.client.exceptions.RpcException;
+import gr.ebs.gss.common.exceptions.ObjectNotFoundException;
+import gr.ebs.gss.common.exceptions.RpcException;
+import gr.ebs.gss.server.domain.FileHeader;
+import gr.ebs.gss.server.domain.Folder;
import gr.ebs.gss.server.domain.User;
-import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
-import gr.ebs.gss.server.domain.dto.FolderDTO;
-import gr.ebs.gss.server.domain.dto.UserDTO;
import gr.ebs.gss.server.ejb.ExternalAPI;
import gr.ebs.gss.server.ejb.TransactionHelper;
url = stripContext(url);
if(url==null||url.trim().equals("")||url.equals("/")){
url="/";
- return new GssRootFolderResource(host, this, null);
}
- /*log.info("URL:"+url);
+ /*//log.info("URL:"+url);
if(url.equals("/OthersShared")||url.equals("/OthersShared/")){
- log.info("[returning others]");
+ //log.info("[returning others]");
return new GssOthersResource(host, this);
}
if(url.startsWith("/OthersShared")){
}*/
try {
-
- Object r = getResourceGss(url);
- if(r==null)
+ User user =null;
+ if(HttpManager.request().getAuthorization()!=null && HttpManager.request().getAuthorization().getTag()==null){
+ String username = HttpManager.request().getAuthorization().getUser();
+ if(username !=null)
+ user = getService().getUserByUserName(username);
+ }
+ else if(HttpManager.request().getAuthorization()!=null&&HttpManager.request().getAuthorization().getTag()!=null){
+ user =(User) HttpManager.request().getAuthorization().getTag();
+ }
+
+ if(user==null){
+ //create a resource based on path if no resource exists at this path it will be handled by subsequent webdav method calls
+ return new GssRootFolderResource(host, this, null,url);
+ }
+
+ Object r = getResourceGss(url,user);
+ if(r==null){
+
return null;
- if(r instanceof FolderDTO)
- return new GssFolderResource(host, this,r );
+ }
+ if(r instanceof Folder){
+
+ return new GssFolderResource(host, this,r ,user);
+ }
else
- return new GssFileResource(host, this,r);
+ return new GssFileResource(host, this,r,user);
} catch (RpcException e) {
e.printStackTrace();
}
public Long maxAgeSeconds(GssResource resource) {
return maxAgeSeconds;
}
- protected Object getResourceGss(String path) throws RpcException{
- UserDTO user = null;
- String username = HttpManager.request().getHeaders().get("authorization");
-
- if(username!=null){
-
- username=getUsernameFromAuthHeader(username);
- try {
- user= getService().getUserByUserName(username);
- } catch (RpcException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
+ protected Object getResourceGss(String path, User user) throws RpcException{
+
+ if(user ==null){
+ if(HttpManager.request().getAuthorization()!=null && HttpManager.request().getAuthorization().getTag()==null){
+ String username = HttpManager.request().getAuthorization().getUser();
+ if(username !=null)
+ user = getService().getUserByUserName(username);
+ }
+ else if(HttpManager.request().getAuthorization()!=null&&HttpManager.request().getAuthorization().getTag()!=null){
+ user =(User) HttpManager.request().getAuthorization().getTag();
}
- }
+ }
+
+ if(user==null){
+ return null;
+ }
boolean exists = true;
Object resource = null;
- FileHeaderDTO file = null;
- FolderDTO folder = null;
try {
resource = getService().getResourceAtPath(user.getId(), path, true);
} catch (ObjectNotFoundException e) {
return null;
}
-
+ if(resource instanceof Folder){
+ try {
+ resource = getService().expandFolder((Folder) resource);
+ } catch (ObjectNotFoundException e) {
+ // TODO Auto-generated catch block
+ return null;
+ }
+ }
+ else if(resource instanceof FileHeader){
+ try {
+ resource = getService().expandFile((FileHeader) resource);
+ } catch (ObjectNotFoundException e) {
+ // TODO Auto-generated catch block
+ return null;
+ }
+ }
return resource;
}