+
+
+ /*
+ * sync will retrieve current config from DR and add it to the DB
+ * when hard = true, then first git rid of current DR provisioning data (from the DB)
+ */
+ public void sync( boolean hard, ApiError err ) {
+
+ if ( hard ) {
+
+ ArrayList<Feed> flist = new ArrayList<Feed>(this.getAllFeeds());
+ for ( Iterator<Feed> it = flist.iterator(); it.hasNext(); ) {
+ Feed f = it.next();
+
+ @SuppressWarnings("unused")
+ Feed old = removeFeed( f, err, false );
+ if (! err.is2xx()) {
+ return;
+ }
+ }
+ }
+
+ DrProvConnection prov = new DrProvConnection();
+ prov.makeDumpConnection();
+ String resp = prov.doGetDump( err );
+ if (! err.is2xx()) {
+ return;
+ }
+ logger.debug("sync: resp from DR is: " + resp);
+
+ JSONParser parser = new JSONParser();
+ JSONObject jsonObj;
+ try {
+ jsonObj = (JSONObject) parser.parse( resp );
+ } catch ( ParseException pe ) {
+ logger.error( "Error parsing provisioning data: " + resp );
+ err.setCode(500);
+ return;
+ }
+
+ int i;
+
+ JSONArray feedsArray = (JSONArray) jsonObj.get( "feeds");
+ for( i = 0; i < feedsArray.size(); i++ ) {
+ JSONObject entry = (JSONObject) feedsArray.get(i);
+ Feed fnew = new Feed( entry.toJSONString() );
+
+ logger.info( "fnew status is:" + fnew.getStatus() );
+ if ( ! fnew.isStatusValid()) {
+ err.setCode(500);
+ err.setMessage( "Unexpected response from DR backend" );
+ err.setFields("response");
+ return;
+ }
+
+ if ( ! savePubs( fnew ) ) {
+ err.setCode(Status.BAD_REQUEST.getStatusCode());
+ err.setMessage("Unable to save Pub or Sub objects");
+ return;
+ }
+ fnew.setFormatUuid(fnew.getFormatUuid());
+ fnew.setLastMod();
+ feeds.put( fnew.getFeedId(), fnew );
+
+ }
+
+ JSONArray subArray = (JSONArray) jsonObj.get( "subscriptions");
+ for( i = 0; i < subArray.size(); i++ ) {
+ JSONObject entry = (JSONObject) subArray.get(i);
+ DR_Sub snew = new DR_Sub( entry.toJSONString() );
+
+ logger.info( "snew status is:" + snew.getStatus() );
+ if ( ! snew.isStatusValid()) {
+ err.setCode(500);
+ err.setMessage( "Unexpected response from DR backend" );
+ err.setFields("response");
+ return;
+ }
+
+ dr_subs.put( snew.getSubId(), snew );
+
+ }
+ err.setCode(200);
+ return;
+
+ }