Map result = new HashMap();
if ( tid != null )result.put( "tid", tid );
try{
JSONObject payload = new JSONObject();
// change this you need to change update too below
payload.put( "engine_id", decodedMap.get( "engine_id" ));
payload.put( "search_term", decodedMap.get( "search_term" ));
payload.put( "filters", decodedMap.get( "filters" ));
payload.put( "schedule", decodedMap.get( "schedule" ));
payload.put( "options", decodedMap.get( "options" ));
Subscription subs = SubscriptionManagerFactory.getSingleton().create(name, isPublic.booleanValue(), payload.toString());
subs.getHistory().setDetails(
isEnabled==null?true:isEnabled.booleanValue(),
autoDownload==null?false:autoDownload.booleanValue());
result.put( "id", subs.getID());
sendBrowserMessage( "metasearch", "createSubscriptionCompleted", result );
} catch( Throwable e ){
result.put( "error", "create failed: " + Debug.getNestedExceptionMessage(e));
sendBrowserMessage( "metasearch", "createSubscriptionFailed", result );
}
}else if( OP_READ_SUBSCRIPTION.equals(opid)){
Map decodedMap = message.getDecodedMap();
final Long tid = (Long) decodedMap.get("tid");
final String sid = (String) decodedMap.get("id");
Map result = new HashMap();
if ( tid != null )result.put( "tid", tid );
try{
Subscription subs = SubscriptionManagerFactory.getSingleton().getSubscriptionByID( sid );
if ( subs == null ){
result.put( "error", "Subscription not found" );
sendBrowserMessage("metasearch", "readSubscriptionFailed",result);
}else{
boolean shareable = subs.isShareable();
// override public flag if not shareable
result.put( "id", subs.getID());
result.put( "name", subs.getName());
result.put( "is_public", new Boolean( shareable && subs.isPublic()));
result.put( "is_author", new Boolean( subs.isMine()));
result.put( "is_shareable", new Boolean( shareable ));
result.put( "auto_dl_supported", new Boolean( subs.isAutoDownloadSupported()));
SubscriptionHistory history = subs.getHistory();
Map options = new HashMap();
result.put( "options", options );
options.put( "is_enabled", new Boolean( history.isEnabled()));
options.put( "auto_dl", new Boolean( history.isAutoDownload()));
Map info = new HashMap();
result.put( "info", info );
info.put( "last_scan", new Long( history.getLastScanTime()));
info.put( "last_new", new Long( history.getLastNewResultTime()));
info.put( "num_unread", new Long( history.getNumUnread()));
info.put( "num_read", new Long( history.getNumRead()));
String json = subs.getJSON();
Map map = JSONUtils.decodeJSON( json );
result.put( "engine_id", map.get( "engine_id" ));
result.put( "search_term", map.get( "search_term" ));
result.put( "filters", map.get( "filters" ));
result.put( "schedule", map.get( "schedule" ));
sendBrowserMessage( "metasearch", "readSubscriptionCompleted", result );
}
} catch( Throwable e ){
result.put( "error", "read failed: " + Debug.getNestedExceptionMessage(e));
sendBrowserMessage("metasearch", "readSubscriptionFailed",result);
}
}else if (OP_UPDATE_SUBSCRIPTION.equals(opid)) {
Map decodedMap = message.getDecodedMap();
final Long tid = (Long) decodedMap.get("tid");
final String name = (String)decodedMap.get("name");
final Boolean isPublic = (Boolean)decodedMap.get( "is_public" );
final String sid = (String)decodedMap.get("id");
Map options = (Map)decodedMap.get( "options" );
Boolean isEnabled = (Boolean)options.get( "is_enabled" );
Boolean autoDownload = (Boolean)options.get( "auto_dl" );
Map result = new HashMap();
if ( tid != null )result.put( "tid", tid );
try{
Subscription subs = SubscriptionManagerFactory.getSingleton().getSubscriptionByID( sid );
if ( subs == null ){
result.put( "error", "Subscription not found" );
sendBrowserMessage("metasearch", "updateSubscriptionFailed",result);
}else{
JSONObject payload = new JSONObject();
// change this you need to change create too above
payload.put( "engine_id", decodedMap.get( "engine_id" ));
payload.put( "search_term", decodedMap.get( "search_term" ));
payload.put( "filters", decodedMap.get( "filters" ));
payload.put( "schedule", decodedMap.get( "schedule" ));
payload.put( "options", decodedMap.get( "options" ));
boolean changed = subs.setDetails( name, isPublic.booleanValue(), payload.toString());
subs.getHistory().setDetails(
isEnabled==null?true:isEnabled.booleanValue(),
autoDownload==null?false:autoDownload.booleanValue());