Author: jgao
Date: 2010-09-03 13:36:14 -0700 (Fri, 03 Sep 2010)
New Revision: 21690
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/IDMappingServiceSuppport.java
Log:
CyThesaurus: commands revision
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
2010-09-03 19:58:40 UTC (rev 21689)
+++
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/CyThesaurusNamespace.java
2010-09-03 20:36:14 UTC (rev 21690)
@@ -78,8 +78,8 @@
private static final String RESOURCE_DIALOG = "resource config dialog";
private static final String LIST_RESOURCE = "list resources";
private static final String LIST_SELECTED_RESOURCE = "list selected
resources";
- private static final String ADD_RESOURCE = "add resource";
- private static final String REMOVE_RESOURCE = "remove resource";
+ private static final String ADD_RESOURCE = "register resource";
+ private static final String REMOVE_RESOURCE = "unregister resource";
private static final String SELECT_RESOURCE = "select resource";
private static final String DESELECT_RESOURCE = "deselect resource";
private static final String GET_SRC_ID_TYPES = "get source id types";
@@ -100,6 +100,7 @@
private static final String SOURCE_ATTR = "sourceattr";
private static final String TARGET_ATTR = "targetattr";
private static final String SOURCE_ID = "sourceid";
+ private static final String REPORT = "report";
protected CyThesaurusNamespace(CyCommandNamespace ns) {
super(ns);
@@ -124,6 +125,9 @@
addArgument(ADD_RESOURCE, DISPLAY_NAME);
addDescription(ADD_RESOURCE, "Add/register an ID mapping resource");
+ addArgument(REMOVE_RESOURCE, CONN_STRING);
+ addDescription(REMOVE_RESOURCE, "Remove/unregister an ID mapping
resource");
+
addArgument(SELECT_RESOURCE, CONN_STRING);
addDescription(SELECT_RESOURCE, "Select an ID mapping resource for
use");
@@ -190,7 +194,7 @@
if (command.equals(ADD_RESOURCE))
return addResource(command, args);
if (command.equals(REMOVE_RESOURCE))
- remvoeResource(command, args);
+ removeResource(command, args);
if (command.equals(SELECT_RESOURCE))
return selectResource(command, args);
if (command.equals(DESELECT_RESOURCE))
@@ -215,6 +219,7 @@
private CyCommandResult version(String command, Map<String, Object>args)
throws CyCommandException {
CyCommandResult result = new CyCommandResult();
result.addResult(CyThesaurusPlugin.VERSION);
+ result.addMessage("Current version: "+CyThesaurusPlugin.VERSION);
return result;
}
@@ -224,6 +229,7 @@
dialog.setLocationRelativeTo(Cytoscape.getDesktop());
dialog.setMapSrcAttrIDTypes(CyThesaurusPlugin.mapSrcAttrIDTypes);
dialog.setVisible(true);
+ result.addResult(!dialog.isCancelled());
return result;
}
@@ -232,6 +238,7 @@
IDMappingSourceConfigDialog srcConfDialog
= new IDMappingSourceConfigDialog(Cytoscape.getDesktop(),
true);
srcConfDialog.setVisible(true);
+ result.addResult(srcConfDialog.isModified());
return result;
}
@@ -289,12 +296,12 @@
result.addMessage("Successfully registered");
} catch (Exception e) {
// throw new CyCommandException(e);
- result.addError("Failed to add the resource\n"+e.getMessage());
+ result.addError("Failed to register the
resource\n"+e.getMessage());
}
return result;
}
- private CyCommandResult remvoeResource(String command, Map<String,
Object>args) throws CyCommandException {
+ private CyCommandResult removeResource(String command, Map<String,
Object>args) throws CyCommandException {
CyCommandResult result = new CyCommandResult();
String connString = getArg(command, CONN_STRING, args);
if (connString == null)
@@ -591,10 +598,20 @@
}
String tgtAttr = getArg(command, TARGET_ATTR, args);
- Set<String> usedName = new HashSet();
- usedName.add("ID"); //TODO remove in Cy3
-
usedName.addAll(java.util.Arrays.asList(Cytoscape.getNodeAttributes().getAttributeNames()));
-
+ if (tgtAttr==null) {
+ Set<String> usedName = new HashSet();
+ usedName.add("ID"); //TODO remove in Cy3
+
usedName.addAll(java.util.Arrays.asList(Cytoscape.getNodeAttributes().getAttributeNames()));
+ if (usedName.contains(tgtType)) {
+ int num = 1;
+ while (usedName.contains(tgtType+"."+num)) {
+ num ++;
+ }
+ tgtAttr = tgtType+"."+num;
+ } else {
+ tgtAttr = tgtType;
+ }
+ }
// mapping ids
AttributeBasedIDMapping service
= new AttributeBasedIDMappingImpl();
@@ -619,6 +636,8 @@
}
result.addMessage(service.getReport());
+ result.addResult(TARGET_ATTR, tgtAttr);
+ result.addResult(REPORT, service.getReport());
return result;
}
@@ -703,7 +722,34 @@
private CyCommandResult idExists(String command, Map<String, Object>args)
throws CyCommandException {
CyCommandResult result = new CyCommandResult();
+
+ String id = getArg(command, SOURCE_ID, args);
+ String type = getArg(command, SOURCE_TYPE, args);
+ if (id==null || type==null)
+
+ if (id==null || type==null) {
+ throw new CyCommandException("Null argument of "+SOURCE_ID+" or
"+SOURCE_TYPE);
+ } else {
+ if (!DataSource.getFullNames().contains(type)) {
+ throw new CyCommandException("Type \""+type+"\" does not
exist.");
+ } else {
+ DataSource ds = DataSource.getByFullName(type);
+ IDMapperStack stack =
IDMapperClientManager.selectedIDMapperStack();
+ try {
+ result.addResult(stack.xrefExists(new Xref(id, ds)));
+ } catch (Exception e) {
+ throw new CyCommandException(e);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private CyCommandResult guessIDTypes(String command, Map<String,
Object>args) throws CyCommandException {
+ CyCommandResult result = new CyCommandResult();
+
Set<String> srcIDs = null;
Object obj = args.get(SOURCE_ID);
if (obj instanceof String) {
@@ -734,16 +780,6 @@
sb.append("\n");
}
result.addMessage(sb.toString());
-
- return result;
- }
-
- private CyCommandResult guessIDTypes(String command, Map<String,
Object>args) throws CyCommandException {
- CyCommandResult result = new CyCommandResult();
-
- String id = getArg(command, SOURCE_ID, args);
- String type = getArg(command, SOURCE_TYPE, args);
-
return result;
}
Modified:
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/IDMappingServiceSuppport.java
===================================================================
---
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/IDMappingServiceSuppport.java
2010-09-03 19:58:40 UTC (rev 21689)
+++
csplugins/trunk/soc/jgao/IDMapping/src/csplugins/id/mapping/service/IDMappingServiceSuppport.java
2010-09-03 20:36:14 UTC (rev 21690)
@@ -47,6 +47,7 @@
import csplugins.id.mapping.ui.IDMappingSourceConfigDialog;
import org.bridgedb.DataSource;
+import org.bridgedb.DataSourcePatterns;
import org.bridgedb.IDMapperStack;
import org.bridgedb.IDMapperCapabilities;
import org.bridgedb.Xref;
@@ -82,6 +83,7 @@
private static final String MSG_TYPE_REQUEST_UNREGISTER_MAPPER =
"UNREGISTER_ID_MAPPER";
private static final String MSG_TYPE_REQUEST_SELECT_MAPPER =
"SELECT_ID_MAPPER";;
private static final String MSG_TYPE_REQUEST_ID_EXIST = "ID_EXIST";
+ private static final String MSG_TYPE_REQUEST_GUESS_TYPE = "GUESSING_TYPE";
private static final String VERSION = "VERSION";
private static final String NETWORK_ID = "NETWORK_ID";
@@ -135,6 +137,8 @@
response = selectIDMapperService(msg);
} else if (msgType.compareTo(MSG_TYPE_REQUEST_ID_EXIST)==0) {
response = idExistsService(msg);
+ } else if (msgType.compareTo(MSG_TYPE_REQUEST_GUESS_TYPE)==0) {
+ response = guessTypeService(msg);
} else if
(msgType.compareTo(MSG_TYPE_REQUEST_MAPPING_SERVICE)==0) {
response = mappingService(msg);
} else if
(msgType.compareTo(MSG_TYPE_REQUEST_UNREGISTER_MAPPER)==0) {
@@ -190,6 +194,7 @@
supportedTypes.add(MSG_TYPE_REQUEST_MAPPING_SERVICE);
supportedTypes.add(MSG_TYPE_REQUEST_UNREGISTER_MAPPER);
supportedTypes.add(MSG_TYPE_REQUEST_CHECK_MAPPING_SUPPORTED);
+ supportedTypes.add(MSG_TYPE_REQUEST_GUESS_TYPE);
content.put(Message.MSG_TYPE_GET_MSG_TYPES, supportedTypes);
return createResponse(msg, content);
@@ -454,10 +459,40 @@
return createResponse(msg, content);
}
+ private static ResponseMessage guessTypeService(Message msg) {
+ Set<String> srcIDs = null;
+
+ Object obj = msg.getContent();
+ if (obj!=null && obj instanceof Map) {
+ Object obj1 = ((Map)obj).get(SOURCE_ID);
+ if (obj1 instanceof String) {
+ srcIDs = new HashSet(1);
+ srcIDs.add((String)obj1);
+ } else if (obj1 instanceof Set) {
+ srcIDs = (Set<String>)obj1;
+ }
+ }
+
+ Set<String> types = new HashSet<String>();
+ for (String id : srcIDs) {
+ Set<DataSource> dss = DataSourcePatterns.getDataSourceMatches(id);
+ for (DataSource ds : dss)
+ types.add(ds.getFullName());
+ }
+
+ Map content = new HashMap();
+ content.put(SUCCESS, true);
+ content.put(SOURCE_ID_TYPE, types);
+
+ return createResponse(msg, content);
+ }
+
private static ResponseMessage mappingSrcConfigDialogService(Message msg) {
IDMappingSourceConfigDialog srcConfDialog
= new IDMappingSourceConfigDialog(Cytoscape.getDesktop(),
true);
srcConfDialog.setVisible(true);
+ boolean succ = true;
+ StringBuilder error = new StringBuilder();
Map content = new HashMap();
content.put(SUCCESS, true);
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.