chiark / gitweb /
pctb upload: Print and throw an error if there are no offers
[jarrg-ian.git] / src / com / tedpearson / ypp / market / MarketUploader.java
index c5b55f3657bb5d817628acd586a716840ccd3017..715e847b895eac70e691b0fce699ea256b01edc0 100644 (file)
@@ -47,7 +47,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
        private final static String YARRG_CLIENTNAME = "jpctb greenend";
        private final static String YARRG_CLIENTVERSION =
            com.tedpearson.ypp.market.Version.version;
-       private final static String YARRG_CLIENTFIXES = "";
+       private final static String YARRG_CLIENTFIXES = "bug-094";
        private final static String YARRG_LIVE_URL = "http://upload.yarrg.chiark.net/commod-update-receiver";
        private final static String YARRG_TEST_URL = "http://upload.yarrg.chiark.net/test/commod-update-receiver";
        private String YARRG_URL;
@@ -435,7 +435,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                //System.out.println(sells);
                //System.out.println("\n\n\n"+buys);
 
-               if (false) { // uploadToPCTB
+               if (uploadToPCTB) {
                        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                        pm.setProgress(60);
                        pm.setNote("Sending data");
@@ -445,7 +445,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                        GZIPOutputStream out = new GZIPOutputStream(outStream);
                        //FileOutputStream out = new FileOutputStream(new File("output.text"));
                        DataOutputStream dos = new DataOutputStream(out);
-                       dos.writeBytes("005\n");
+                       dos.writeBytes("005y\n");
                        dos.writeBytes(stallMap.size()+"\n");
                        dos.writeBytes(getAbbrevStallList(stallMap));
                        writeBuySellOffers(buys,sells,offerCount,out);
@@ -597,7 +597,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                        //System.out.println(xml);
                        Reader reader = new CharArrayReader(xml.toCharArray());
                        Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(reader));
-                       NodeList maps = d.getElementsByTagName("c");
+                       NodeList maps = d.getElementsByTagName("CommodMap");
                        for(int i=0;i<maps.getLength();i++) {
                                NodeList content = maps.item(i).getChildNodes();
                                Integer num = Integer.parseInt(content.item(1).getTextContent());
@@ -664,9 +664,13 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                                        buySellCount[1]++;
                                }
                        } catch(IllegalArgumentException e) {
-                               // System.err.println("Error: Unsupported Commodity \"" + offer.get(0) + "\"");
+                               System.err.println("Error: Unsupported Commodity \"" + offer.get(0) + "\"");
                        }
                }
+               if (buySellCount[0]==0 && buySellCount[1]==0) {
+                   error("No (valid) offers for PCTB?!");
+                   throw new IllegalArgumentException();
+               }
                return buySellCount;
        }