Skip to content

Commit 9bb0466

Browse files
committed
IRSA-729: added server commands
1 parent bd5d77d commit 9bb0466

23 files changed

+1029
-151
lines changed

config/app-test.prop

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ irsa.gator.service.periodogram.keys=x y alg peaks
1212

1313
workspace.host.url=https://irsa.ipac.caltech.edu
1414
workspace.root.dir=/work
15-
workspace.protocol.irsa=webdav
16-
workspace.protocol.irsa.webdav=edu.caltech.ipac.firefly.server.WebDAVWorkspaceManager
17-
15+
workspace.protocol=webdav
16+
workspace.protocol.webdav=edu.caltech.ipac.firefly.server.WebDAVWorkspaceManager
1817
# Another Impl?-> See edu.caltech.ipac.firefly.server.ws.WebDAVWorkspaceHandler#withCredentials
19-
# workspace.protocol.irsa.webdav=edu.caltech.ipac.firefly.server.ws.WebdavImpl
18+
# workspace.protocol.webdav=edu.caltech.ipac.firefly.server.ws.WebdavImpl
2019

2120
atlas.ibe.host=irsadev.ipac.caltech.edu
2221

src/firefly/java/edu/caltech/ipac/firefly/data/ServerParams.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,14 @@ public class ServerParams {
179179
public static final String LOGOUT = "CmdLogout";
180180

181181
//Workspaces
182-
public static final String WS_LIST = "wsList";
183-
public static final String WS_GET_FILE = "wsGet";
184-
public static final String WS_PUT_FILE = "wsPut";
182+
public static final String WS_LIST = "wsList"; // Gets the list of content/files
183+
public static final String WS_GET_FILE = "wsGet"; // TODO
184+
public static final String WS_UPLOAD_FILE = "wsUpload";// to get the path of the file uploaded into firefly server from WS
185+
public static final String WS_PUT_IMAGE_FILE = "wsPut"; //FITS, PNG, comes from edu.caltech.ipac.firefly.server.servlets.AnyFileDownload
186+
public static final String WS_PUT_TABLE_FILE = "wsPutTable";
187+
public static final String WS_DELETE_FILE = "wsDel";
188+
public static final String WS_MOVE_FILE = "wsMove";
189+
public static final String WS_GET_METADATA = "wsGetMeta";
190+
public static final String WS_CREATE_PARENT = "wsParent";
185191
}
186192

src/firefly/java/edu/caltech/ipac/firefly/data/WspaceMeta.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class WspaceMeta implements Serializable {
2525

2626
public static final String DESC = "desc";
2727
public static final String TYPE = "type";
28+
private boolean isFile = false; //folder
2829

2930
public void setUrl(String url) {
3031
this.url = url;
@@ -34,6 +35,10 @@ public String getUrl() {
3435
return url;
3536
}
3637

38+
public boolean isFile() {
39+
return this.isFile;
40+
}
41+
3742
public enum Includes {
3843
NONE(false, 0), NONE_PROPS(true, 0), CHILDREN(false, 1), CHILDREN_PROPS(true, 1), ALL(false), ALL_PROPS(true);
3944
public boolean inclProps = false;
@@ -176,6 +181,10 @@ public String getProperty(String keyname) {
176181
return val;
177182
}
178183

184+
public void setIsFile(boolean isFile) {
185+
this.isFile = isFile;
186+
}
187+
179188
public void setSize(long size) {
180189
this.size = size;
181190
}

src/firefly/java/edu/caltech/ipac/firefly/server/LocalFSWorkspace.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public WsResponse renameFile(String originalFileRelPath, String fileName, boolea
140140
throw new IllegalArgumentException("not implemented");
141141
}
142142

143+
@Override
144+
public WsResponse moveFile(String originalFileRelPath, String newfilepath, boolean shouldOverwrite) throws WsException {
145+
throw new IllegalArgumentException("not implemented");
146+
}
147+
143148
@Override
144149
public WspaceMeta getMeta(String uri, WspaceMeta.Includes includes) {
145150
throw new IllegalArgumentException("not implemented");

src/firefly/java/edu/caltech/ipac/firefly/server/RequestOwner.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,15 @@ public Date getStartTime() {
116116
}
117117

118118
public Map<String, String> getCookieMap() {
119-
Map<String, Cookie> cookies = requestAgent.getCookies();
120-
Map<String, String> cmap = new HashMap<>(cookies.size());
121-
for(Cookie c : cookies.values()) {
122-
String v = c == null ? null : c.getValue();
123-
if (v != null) {
124-
cmap.put(c.getName(), c.getValue());
119+
Map<String, String> cmap = null;
120+
if(requestAgent!=null) {
121+
Map<String, Cookie> cookies = requestAgent.getCookies();
122+
for (Cookie c : cookies.values()) {
123+
cmap = new HashMap<>(cookies.size());
124+
String v = c == null ? null : c.getValue();
125+
if (v != null) {
126+
cmap.put(c.getName(), c.getValue());
127+
}
125128
}
126129
}
127130
return cmap;

src/firefly/java/edu/caltech/ipac/firefly/server/ServerCommandAccess.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ private static void initCommand() {
7272
//Workspaces
7373
_cmdMap.put(ServerParams.WS_LIST, new WsServerCommands.WsList());
7474
_cmdMap.put(ServerParams.WS_GET_FILE, new WsServerCommands.WsGetFile());
75-
_cmdMap.put(ServerParams.WS_PUT_FILE, new WsServerCommands.WsPutFile());
75+
_cmdMap.put(ServerParams.WS_UPLOAD_FILE, new WsServerCommands.WsUploadFile());
76+
_cmdMap.put(ServerParams.WS_DELETE_FILE, new WsServerCommands.WsDeleteFile());
77+
_cmdMap.put(ServerParams.WS_MOVE_FILE, new WsServerCommands.WsMoveFile());
78+
_cmdMap.put(ServerParams.WS_GET_METADATA, new WsServerCommands.WsGetMeta());
79+
_cmdMap.put(ServerParams.WS_CREATE_PARENT, new WsServerCommands.WsCreateParent());
80+
_cmdMap.put(ServerParams.WS_PUT_TABLE_FILE, new WsServerCommands.WsPutTableFile());
81+
_cmdMap.put(ServerParams.WS_PUT_IMAGE_FILE, new WsServerCommands.WsPutImgFile());
7682

7783
_cmdMap.put(ServerParams.RAW_DATA_SET, new SearchServerCommands.GetRawDataSet());
7884
_cmdMap.put(ServerParams.JSON_DATA, new SearchServerCommands.GetJSONData());

src/firefly/java/edu/caltech/ipac/firefly/server/WebDAVWorkspaceManager.java

Lines changed: 60 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,25 @@ public WsResponse createParent(String newRelPath) throws WsException {
407407
return WsUtil.success(200, "Created", getResourceUrl(newRelPath));
408408
}
409409

410+
public WsResponse moveFile(String originalFileRelPath, String newPath, boolean overwrite) throws WsException {
411+
WspaceMeta meta = new WspaceMeta(newPath);
412+
String parent = meta.getParentPath();
413+
414+
//WARNING: WEBDAv forces me to create new parent first! UGLY!
415+
createParent(parent);
416+
417+
String newUrl = getResourceUrl(newPath);
418+
419+
// This doesn't create parent , you must create the parent folder in order to move it
420+
MoveMethod move = new MoveMethod(getResourceUrl(originalFileRelPath), newUrl, overwrite);
421+
if (!executeMethod(move)) {
422+
// handle error
423+
LOG.error("Unable to move:" + originalFileRelPath + " -- " + move.getStatusText());
424+
return WsUtil.error(move.getStatusCode(), move.getStatusLine().getReasonPhrase());
425+
}
426+
return WsUtil.success(move.getStatusCode(), move.getStatusText(), newUrl);
427+
}
428+
410429
@Override
411430
public WsResponse renameFile(String originalFileRelPath, String newfileName, boolean overwrite) throws WsException {
412431
WspaceMeta meta = new WspaceMeta(originalFileRelPath);
@@ -427,34 +446,6 @@ public WspaceMeta getMeta(String relPath) {
427446
return getMeta(relPath, WspaceMeta.Includes.ALL);
428447
}
429448

430-
public WsResponse search(String relPath) throws IOException {
431-
String query = "" +
432-
" " +
433-
" SELECT *" +
434-
" " +
435-
"";
436-
query = "//element(*,rep:root)";
437-
438-
OptionsMethod options = new OptionsMethod(getResourceUrl(relPath));
439-
executeMethod(options);
440-
String okMethod = "SEARCH";
441-
if (!options.isAllowed(okMethod)) {
442-
String s = "";
443-
String[] allowedMethods = options.getAllowedMethods();
444-
for (String method : allowedMethods) {
445-
s += method + "\n";
446-
}
447-
return WsUtil.error(options.getStatusCode(), options.getStatusText(), okMethod + " is not allowed - only:\n" + s);
448-
}
449-
SearchMethod m = new SearchMethod(getResourceUrl(relPath), query, "xpath");
450-
if (!executeMethod(m)) {
451-
// handle error
452-
LOG.error("Unable to move:" + relPath + " -- " + m.getStatusText());
453-
return WsUtil.error(m.getStatusCode(), m.getStatusLine().getReasonPhrase());
454-
}
455-
return WsUtil.success(m.getStatusCode(), m.getStatusText(), relPath);
456-
}
457-
458449
public WspaceMeta getMeta(String relPath, WspaceMeta.Includes includes) {
459450

460451
// this can be optimized by retrieving only the props we care for.
@@ -594,7 +585,9 @@ private WspaceMeta convertToWspaceMeta(WspaceMeta meta, MultiStatusResponse res)
594585
if (name.equals(DavConstants.PROPERTY_GETLASTMODIFIED)) {
595586
meta.setLastModified(v);
596587
} else if (name.equals(DavConstants.PROPERTY_GETCONTENTLENGTH)) {
597-
meta.setSize(Long.parseLong(v));
588+
long size = Long.parseLong(v);
589+
meta.setSize(size);
590+
meta.setIsFile(true); // WEBDAV/IRSA only set cvontent length for files. (?)TODO: is it WEBDav general behaviour?
598591
} else if (name.equals(DavConstants.PROPERTY_GETCONTENTTYPE)) {
599592
meta.setContentType(v);
600593
} else if (p.getName().getNamespace().equals(IRSA_NS)) {
@@ -635,45 +628,45 @@ private boolean executeMethod(DavMethod method, boolean releaseConnection) {
635628

636629
}
637630

638-
// public static void main(String[] args) {
639-
// WebDAVWorkspaceManager man = null;
640-
//// man = (WebDAVWorkspaceManager) ServerContext.getRequestOwner().getWsManager();
641-
//
642-
// man = new WebDAVWorkspaceManager("ejoliet-tmp2");
643-
//
631+
public static void main(String[] args) {
632+
WebDAVWorkspaceManager man = null;
633+
// man = (WebDAVWorkspaceManager) ServerContext.getRequestOwner().getWsManager();
634+
635+
man = new WebDAVWorkspaceManager("ejoliet-tmp2");
636+
637+
simpleTest(man);
638+
639+
// AppProperties.setProperty("sso.server.url", "http://irsa.ipac.caltech.edu/account/");
640+
// String session = JOSSOAdapter.createSession("", "");
641+
// Map<String, String> cookies = new HashMap<String, String>();
642+
// cookies.put(WebAuthModule.AUTH_KEY, session);
643+
// WorkspaceManager man = new WorkspaceManager("<someuser>@ipac.caltech.edu", cookies);
644644
// simpleTest(man);
645-
//
646-
//// AppProperties.setProperty("sso.server.url", "http://irsa.ipac.caltech.edu/account/");
647-
//// String session = JOSSOAdapter.createSession("", "");
648-
//// Map<String, String> cookies = new HashMap<String, String>();
649-
//// cookies.put(WebAuthModule.AUTH_KEY, session);
650-
//// WorkspaceManager man = new WorkspaceManager("<someuser>@ipac.caltech.edu", cookies);
651-
//// simpleTest(man);
652-
// }
653-
//
654-
// private static void simpleTest(WebDAVWorkspaceManager man) {
655-
// String relPath = "124/";
656-
// File f = man.davMakeDir(relPath);
657-
// System.out.println("new directory: " + String.valueOf(f));
658-
//
659-
// WspaceMeta m = new WspaceMeta(null, relPath);
660-
// m.setProperty("test1", "an awesome idea");
661-
// m.setProperty("test", null);
662-
// man.setMeta(m);
663-
//
664-
// String ufilePath = relPath + "gaia-binary.vot";
665-
// WsResponse wsResponse = man.davPut(new File("/Users/ejoliet/devspace/branch/dev/firefly_test_data/edu/caltech/ipac/firefly/ws/gaia-binary.vot"), ufilePath, null);
666-
//
667-
// System.out.println(wsResponse);
668-
//
669-
// WspaceMeta meta = new WspaceMeta(null, ufilePath);
670-
// meta.setProperty("added_by", man.userHome);
671-
// man.setMeta(meta);
672-
// man.setMeta(ufilePath, "added_by", man.userHome);
673-
//
674-
// WspaceMeta meta2 = man.getMeta("/", WspaceMeta.Includes.ALL_PROPS);
675-
// System.out.println(meta2.getNodesAsString());
676-
// }
645+
}
646+
647+
private static void simpleTest(WebDAVWorkspaceManager man) {
648+
String relPath = "124/";
649+
File f = man.davMakeDir(relPath);
650+
System.out.println("new directory: " + String.valueOf(f));
651+
652+
WspaceMeta m = new WspaceMeta(null, relPath);
653+
m.setProperty("test1", "an awesome idea");
654+
m.setProperty("test", null);
655+
man.setMeta(m);
656+
657+
String ufilePath = relPath + "gaia-binary.vot";
658+
WsResponse wsResponse = man.davPut(new File("/Users/ejoliet/devspace/branch/dev/firefly_test_data/edu/caltech/ipac/firefly/ws/gaia-binary.vot"), ufilePath, null);
659+
660+
System.out.println(wsResponse);
661+
662+
WspaceMeta meta = new WspaceMeta(null, ufilePath);
663+
meta.setProperty("added_by", man.userHome);
664+
man.setMeta(meta);
665+
man.setMeta(ufilePath, "added_by", man.userHome);
666+
667+
WspaceMeta meta2 = man.getMeta("/", WspaceMeta.Includes.ALL_PROPS);
668+
System.out.println(meta2.getNodesAsString());
669+
}
677670

678671

679672
class WebDAVGetMethod extends DavMethodBase {

src/firefly/java/edu/caltech/ipac/firefly/server/ws/LocalWorkspaceHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
*/
1414
public class LocalWorkspaceHandler implements WorkspaceHandler {
1515

16-
String p = AppProperties.getProperty("workspace.protocol.irsa.webdav", "edu.caltech.ipac.firefly.server.WebDAVWorkspaceManager");
17-
1816
/**
1917
* map userKey and ws,
2018
* TODO we don't want to create a new Wsmanager for every user access, do we?

src/firefly/java/edu/caltech/ipac/firefly/server/ws/WebDAVWorkspaceHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
public class WebDAVWorkspaceHandler implements WorkspaceHandler {
1717

18-
String managerClass = AppProperties.getProperty("workspace.protocol.irsa.webdav", "edu.caltech.ipac.firefly.server.WebDAVWorkspaceManager");
18+
1919

2020
/**
2121
* map userKey and ws,
@@ -31,10 +31,13 @@ public WorkspaceManager withCredentials(WsCredentials cred) {
3131

3232
synchronized (cred) {
3333
String id = cred.getWsId();
34+
String protocol = AppProperties.getProperty("workspace.protocol", "webdav");
35+
String managerClass = AppProperties.getProperty("workspace.protocol."+protocol.toLowerCase(), "edu.caltech.ipac.firefly.server.WebDAVWorkspaceManager");
3436

35-
if (wsPool.containsKey(id)) {
37+
//TODO The problem is how do i know that the cookkie/session is authtenticated at this point?
38+
/*if (wsPool.containsKey(id)) {
3639
return wsPool.get(id);
37-
}
40+
}*/
3841
WorkspaceManager ws = null;//new WebDAVWorkspaceManager(cred.getWsId(), cred.getCookies());
3942
try {
4043
Class clazz = Class.forName(managerClass);

src/firefly/java/edu/caltech/ipac/firefly/server/ws/WorkspaceFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
*/
1111
public class WorkspaceFactory {
1212

13-
static String protocolProp = AppProperties.getProperty("workspace.protocol.irsa", "webdav");
13+
static String protocolProp = AppProperties.getProperty("workspace.protocol", "webdav");
14+
private static WebDAVWorkspaceHandler webDavHdlr;
1415

1516
/**
16-
* @return Handler based on protocol read from properties workspace.protocol.irsa
17+
* @return Handler based on protocol read from properties workspace.protocol
1718
* @throws WsException
1819
*/
1920
public static WorkspaceHandler getWorkspaceHandler() {
@@ -31,7 +32,10 @@ public static WorkspaceHandler getWorkspaceHandler(WorkspaceManager.PROTOCOL p)
3132
case LOCAL:
3233
return new LocalWorkspaceHandler();
3334
case WEBDAV:
34-
return new WebDAVWorkspaceHandler();
35+
if(webDavHdlr==null){
36+
webDavHdlr = new WebDAVWorkspaceHandler();
37+
}
38+
return webDavHdlr;
3539
case VOSPACE:
3640
throw new ResourceNotFoundException(p.name() + " not implemented yet ");
3741
}

src/firefly/java/edu/caltech/ipac/firefly/server/ws/Workspaces.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ public interface Workspaces {
8686
*/
8787
WsResponse renameFile(String originalFileRelPath, String newfileName, boolean shouldOverwrite) throws WsException;
8888

89+
/**
90+
* @param originalFileRelPath relative current path
91+
* @param newfilepath new path
92+
* @param shouldOverwrite
93+
* @return
94+
* @throws WsException
95+
*/
96+
WsResponse moveFile(String originalFileRelPath, String newfilepath, boolean shouldOverwrite) throws WsException;
97+
98+
8999
WspaceMeta getMeta(String uri, WspaceMeta.Includes includes);
90100

91101
boolean setMeta(WspaceMeta... metas);

src/firefly/java/edu/caltech/ipac/firefly/server/ws/WsCredentials.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ enum AUTH {NONE, TOKEN, DIGEST, BASIC}
2727

2828
public WsCredentials(String wsId, Map<String, String> cookies) {
2929
this.wsId = wsId;
30-
3130
this.cookies = cookies;
3231
}
3332

0 commit comments

Comments
 (0)