Better integration between JBidwatcher and My JBidwatcher.
- M jbidwatcher/trunk/src/com/jbidwatcher/auction/server/ebay/ebayServer.java view
- M jbidwatcher/trunk/src/com/jbidwatcher/my/MyJBidwatcher.java view
- M jbidwatcher/trunk/src/com/jbidwatcher/ui/config/JConfigFrame.java view
- M jbidwatcher/trunk/src/com/jbidwatcher/ui/config/JConfigMyJBidwatcherTab.java view
| 921 | 956 | |
|---|---|---|
| 613 | 613 | MQFactory.getConcrete("Swing").enqueue("Done Getting Selling Items for " + userId); |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | // TODO -- Wouldn't it be nice if this took an item number, and looked it up, instead of keeping a reference to the actual (potentially duplicated) object? | |
| 616 | 617 | private class SnipeListener implements MessageQueue.Listener { |
| 617 | 618 | public void messageAction(Object deQ) { |
| 618 | 619 | AuctionQObject ac = (AuctionQObject) deQ; |
| 955 | 956 | |
|---|---|---|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | public String recognizeBidpage(String identifier, StringBuffer page) { |
| 121 | Parameters p = new Parameters(); | |
| 122 | if(identifier != null) p.put("item", identifier); | |
| 123 | p.put("body", page); | |
| 124 | String url = url("my.jbidwatcher.com/services/recognize"); | |
| 125 | return http().postTo(url, p); | |
| 121 | if(canParse()) { | |
| 122 | Parameters p = new Parameters(); | |
| 123 | if (identifier != null) p.put("item", identifier); | |
| 124 | p.put("body", page); | |
| 125 | String url = url("my.jbidwatcher.com/services/recognize"); | |
| 126 | return http().postTo(url, p); | |
| 127 | } else { | |
| 128 | return null; | |
| 129 | } | |
| 126 | 130 | } |
| 127 | 131 | |
| 128 | 132 | public String reportException(String sb) { |
| --- | --- | |
| 138 | 142 | } |
| 139 | 143 | |
| 140 | 144 | public void postXML(String queue, XMLSerialize ae) { |
| 141 | XMLElement xmlWrapper = new XMLElement("message"); | |
| 142 | XMLElement user = new XMLElement("user"); | |
| 143 | XMLElement access_key = new XMLElement("key"); | |
| 144 | user.setContents(JConfig.queryConfiguration("my.jbidwatcher.id")); | |
| 145 | access_key.setContents(JConfig.queryConfiguration("my.jbidwatcher.key")); | |
| 146 | xmlWrapper.addChild(user); | |
| 147 | xmlWrapper.addChild(access_key); | |
| 148 | xmlWrapper.addChild(ae.toXML()); | |
| 149 | String aucXML = xmlWrapper.toString(); | |
| 145 | if(canSync()) { | |
| 146 | XMLElement xmlWrapper = new XMLElement("message"); | |
| 147 | XMLElement user = new XMLElement("user"); | |
| 148 | XMLElement access_key = new XMLElement("key"); | |
| 149 | user.setContents(JConfig.queryConfiguration("my.jbidwatcher.id")); | |
| 150 | access_key.setContents(JConfig.queryConfiguration("my.jbidwatcher.key")); | |
| 151 | xmlWrapper.addChild(user); | |
| 152 | xmlWrapper.addChild(access_key); | |
| 153 | xmlWrapper.addChild(ae.toXML()); | |
| 154 | String aucXML = xmlWrapper.toString(); | |
| 150 | 155 | |
| 151 | if(queue != null) http().putTo(queue, aucXML); | |
| 156 | if (queue != null) http().putTo(queue, aucXML); | |
| 157 | } | |
| 152 | 158 | } |
| 153 | 159 | |
| 154 | 160 | private MyJBidwatcher() { |
| --- | --- | |
| 169 | 175 | if(JConfig.queryConfiguration("my.jbidwatcher.id") != null) { |
| 170 | 176 | AuctionEntry ae = EntryCorral.getInstance().takeForRead((String) deQ); |
| 171 | 177 | postXML(mSyncQueueURL, ae); |
| 172 | if(JConfig.queryConfiguration("my.jbidwatcher.uploadhtml", "false").equals("true")) { | |
| 173 | uploadAuctionHTML(ae, "uploadhtml"); | |
| 174 | } | |
| 178 | uploadAuctionHTML(ae, "uploadhtml"); | |
| 175 | 179 | } |
| 176 | 180 | } |
| 177 | 181 | }); |
| --- | --- | |
| 200 | 204 | } |
| 201 | 205 | |
| 202 | 206 | private void uploadAuctionHTML(AuctionEntry ae, String uploadType) { |
| 203 | String s3Result = sendFile(ae.getContentFile(), url(ITEM_UPLOAD_URL), JConfig.queryConfiguration("my.jbidwatcher.id"), ae.getLastStatus()); | |
| 204 | XMLElement root = new XMLElement(uploadType); | |
| 205 | XMLElement s3Key = new XMLElement("s3"); | |
| 206 | s3Key.setContents(s3Result); | |
| 207 | root.addChild(ae.toXML()); | |
| 208 | postXML(mReportQueueURL, root); | |
| 207 | if(canUploadHTML()) { | |
| 208 | String s3Result = sendFile(ae.getContentFile(), url(ITEM_UPLOAD_URL), JConfig.queryConfiguration("my.jbidwatcher.id"), ae.getLastStatus()); | |
| 209 | XMLElement root = new XMLElement(uploadType); | |
| 210 | XMLElement s3Key = new XMLElement("s3"); | |
| 211 | s3Key.setContents(s3Result); | |
| 212 | root.addChild(ae.toXML()); | |
| 213 | postXML(mReportQueueURL, root); | |
| 214 | } | |
| 209 | 215 | } |
| 210 | 216 | |
| 217 | private boolean canUploadHTML() { return allow("uploadhtml"); } | |
| 218 | private boolean canSync() { return allow("sync"); } | |
| 219 | private boolean canParse() { return allow("parser"); } | |
| 220 | private boolean canGetSnipes() { return allow("snipes"); } | |
| 221 | private boolean canSendSnipeToGixen() { return allow("gixen"); } | |
| 222 | ||
| 223 | private boolean allow(String type) { | |
| 224 | return JConfig.queryConfiguration("my.jbidwatcher.allow." + type, "false").equals("true") && | |
| 225 | JConfig.queryConfiguration("my.jbidwatcher." + type, "false").equals("true"); | |
| 226 | } | |
| 227 | ||
| 211 | 228 | public boolean getAccountInfo() { |
| 212 | 229 | StringBuffer sb = http().get("https://my.jbidwatcher.com/services/account"); |
| 213 | 230 | if(sb == null) return false; |
| --- | --- | |
| 234 | 251 | } |
| 235 | 252 | } |
| 236 | 253 | |
| 254 | JConfig.setConfiguration("my.jbidwatcher.allow.listings", listingsRemaining.getContents()); | |
| 255 | JConfig.setConfiguration("my.jbidwatcher.allow.categories", categoriesRemaining.getContents()); | |
| 256 | ||
| 237 | 257 | mSyncQueueURL = sync == null ? null : sync.getContents(); |
| 258 | JConfig.setConfiguration("my.jbidwatcher.allow.sync", Boolean.toString(mSyncQueueURL != null)); | |
| 238 | 259 | mReportQueueURL = reporting == null ? null : reporting.getContents(); |
| 239 | 260 | mUseSSL = getBoolean(ssl); |
| 261 | JConfig.setConfiguration("my.jbidwatcher.allow.ssl", Boolean.toString(mUseSSL)); | |
| 240 | 262 | mReadSnipesFromServer = getBoolean(snipesListen); |
| 263 | JConfig.setConfiguration("my.jbidwatcher.allow.snipes", Boolean.toString(mReadSnipesFromServer)); | |
| 241 | 264 | mUploadHTML = getBoolean(uploadHTML); |
| 265 | JConfig.setConfiguration("my.jbidwatcher.allow.uploadhtml", Boolean.toString(mUploadHTML)); | |
| 242 | 266 | mUseServerParser = getBoolean(serverParser); |
| 267 | JConfig.setConfiguration("my.jbidwatcher.allow.parser", Boolean.toString(mUseServerParser)); | |
| 243 | 268 | mGixen = getBoolean(gixen); |
| 269 | JConfig.setConfiguration("my.jbidwatcher.allow.gixen", Boolean.toString(mGixen)); | |
| 244 | 270 | |
| 245 | 271 | return mSyncQueueURL != null && mReportQueueURL != null; |
| 246 | 272 | } |
| 862 | 956 | |
|---|---|---|
| 139 | 139 | } |
| 140 | 140 | allTabs.add(new JConfigFirewallTab()); |
| 141 | 141 | allTabs.add(new JConfigSnipeTab()); |
| 142 | if(JConfig.queryConfiguration("allow.my_jbidwatcher", "false").equals("true")) allTabs.add(new JConfigMyJBidwatcherTab()); | |
| 142 | // if(JConfig.queryConfiguration("allow.my_jbidwatcher", "false").equals("true")) | |
| 143 | allTabs.add(new JConfigMyJBidwatcherTab()); | |
| 143 | 144 | allTabs.add(new JConfigFilePathTab()); |
| 144 | 145 | allTabs.add(new JConfigWebserverTab()); |
| 145 | 146 | allTabs.add(new JConfigDatabaseTab()); |
| 942 | 956 | |
|---|---|---|
| 13 | 13 | import java.awt.*; |
| 14 | 14 | import java.awt.event.ActionListener; |
| 15 | 15 | import java.awt.event.ActionEvent; |
| 16 | import java.util.Map; | |
| 17 | import java.util.HashMap; | |
| 16 | 18 | import javax.swing.*; |
| 17 | 19 | |
| 18 | 20 | public class JConfigMyJBidwatcherTab extends JConfigTab { |
| --- | --- | |
| 20 | 22 | private JTextField mEmail; |
| 21 | 23 | private JTextField mPassword; |
| 22 | 24 | private JButton mCreateOrUpdate; |
| 25 | private Map<JCheckBox,String> mConfigurationMap = new HashMap<JCheckBox,String>(); | |
| 26 | private Map<JCheckBox,String> mEnabledMap = new HashMap<JCheckBox,String>(); | |
| 27 | private JLabel mListingStats; | |
| 28 | private JLabel mCategoryStats; | |
| 29 | private JLabel mSSLEnabled; | |
| 23 | 30 | |
| 24 | 31 | public String getTabName() { return "My JBidwatcher"; } |
| 25 | 32 | public void cancel() { } |
| 26 | 33 | |
| 27 | 34 | public boolean apply() { |
| 28 | boolean enabled = mEnable.isSelected(); | |
| 29 | JConfig.setConfiguration("my.jbidwatcher.enabled", Boolean.toString(enabled)); | |
| 30 | ||
| 31 | 35 | String email = mEmail.getText(); |
| 32 | 36 | String password = mPassword.getText(); |
| 33 | 37 | |
| --- | --- | |
| 38 | 42 | } |
| 39 | 43 | } |
| 40 | 44 | |
| 45 | for(JCheckBox cb : mConfigurationMap.keySet()) { | |
| 46 | String cfg = mConfigurationMap.get(cb); | |
| 47 | JConfig.setConfiguration(cfg, Boolean.toString(cb.isSelected())); | |
| 48 | } | |
| 41 | 49 | return true; |
| 42 | 50 | } |
| 43 | 51 | |
| 44 | 52 | public void updateValues() { |
| 45 | 53 | String email = JConfig.queryConfiguration("my.jbidwatcher.id", ""); |
| 46 | 54 | String pass = JConfig.queryConfiguration("my.jbidwatcher.key", ""); |
| 47 | boolean enabled = JConfig.queryConfiguration("my.jbidwatcher.enabled", "false").equals("true"); | |
| 48 | // String id = JConfig.queryConfiguration("my.jbidwatcher.id"); | |
| 49 | 55 | |
| 56 | mEnable.setSelected(JConfig.queryConfiguration("my.jbidwatcher.enabled", "false").equals("true")); | |
| 57 | ||
| 58 | for (JCheckBox cb : mEnabledMap.keySet()) { | |
| 59 | String cfg = mEnabledMap.get(cb); | |
| 60 | cb.setEnabled(mEnable.isSelected() && JConfig.queryConfiguration(cfg, "false").equals("true")); | |
| 61 | } | |
| 62 | ||
| 50 | 63 | mEmail.setText(email); |
| 51 | 64 | mPassword.setText(pass); |
| 52 | mEnable.setSelected(enabled); | |
| 53 | 65 | |
| 66 | mListingStats.setText(left("listings")); | |
| 67 | mCategoryStats.setText(left("categories")); | |
| 68 | mSSLEnabled.setText(sslState()); | |
| 69 | ||
| 54 | 70 | for(ActionListener al : mEnable.getActionListeners()) { |
| 55 | 71 | al.actionPerformed(new ActionEvent(mEnable, ActionEvent.ACTION_PERFORMED, "Redraw")); |
| 56 | 72 | } |
| --- | --- | |
| 104 | 120 | if(MyJBidwatcher.getInstance().getAccountInfo()) { |
| 105 | 121 | statusLabel.setIcon(successIcon); |
| 106 | 122 | statusLabel.setText("success!"); |
| 123 | updateValues(); | |
| 107 | 124 | } else { |
| 108 | 125 | statusLabel.setIcon(failIcon); |
| 109 | 126 | statusLabel.setText("failed."); |
| --- | --- | |
| 134 | 151 | mPassword.setEditable(selected); |
| 135 | 152 | |
| 136 | 153 | mCreateOrUpdate.setEnabled(selected); |
| 154 | for(JCheckBox cb : mEnabledMap.keySet()) { | |
| 155 | cb.setEnabled(selected && JConfig.queryConfiguration(mEnabledMap.get(cb), "false").equals("true")); | |
| 156 | } | |
| 137 | 157 | } |
| 138 | 158 | }); |
| 139 | 159 | JLabel enableLabel = new JLabel("Enable My JBidwatcher"); |
| 140 | 160 | enableLabel.setLabelFor(mEnable); |
| 161 | mConfigurationMap.put(mEnable, "my.jbidwatcher.enabled"); | |
| 141 | 162 | |
| 142 | 163 | jp.add(makeLine(mEnable, enableLabel), BorderLayout.NORTH); |
| 143 | 164 | jp.add(innerPanel, BorderLayout.CENTER); |
| --- | --- | |
| 151 | 172 | JPanel jp = new JPanel(); |
| 152 | 173 | jp.setLayout(new BorderLayout()); |
| 153 | 174 | jp.add(buildUserSettings(), BorderLayout.NORTH); |
| 154 | // jp.add(buildExtraSettings(), BorderLayout.SOUTH); | |
| 175 | jp.add(buildExtraSettings(), BorderLayout.SOUTH); | |
| 155 | 176 | this.add(panelPack(jp), BorderLayout.NORTH); |
| 156 | 177 | updateValues(); |
| 157 | 178 | } |
| 179 | ||
| 180 | private JPanel buildExtraSettings() { | |
| 181 | JPanel jp = new JPanel(new BorderLayout()); | |
| 182 | jp.setBorder(BorderFactory.createTitledBorder("My JBidwatcher Settings")); | |
| 183 | ||
| 184 | JPanel innerPanel = new JPanel(); | |
| 185 | innerPanel.setLayout(new SpringLayout()); | |
| 186 | ||
| 187 | innerPanel.add(createSettingsCheckbox("Upload item info to My JBidwatcher", "sync")); | |
| 188 | innerPanel.add(createSettingsCheckbox("Upload item HTML", "uploadhtml")); | |
| 189 | // innerPanel.add(createSettingsCheckbox("Upload snipes to Gixen", "gixen")); | |
| 190 | innerPanel.add(createSettingsCheckbox("Allow setting snipes in My JBidwatcher", "snipes")); | |
| 191 | innerPanel.add(createSettingsCheckbox("Use My JBidwatcher as a fallback parser", "parser")); | |
| 192 | ||
| 193 | mListingStats = new JLabel(left("listings")); | |
| 194 | mListingStats.setFont(mListingStats.getFont().deriveFont(Font.BOLD)); | |
| 195 | mCategoryStats = new JLabel(left("categories")); | |
| 196 | mCategoryStats.setFont(mCategoryStats.getFont().deriveFont(Font.BOLD)); | |
| 197 | ||
| 198 | innerPanel.add(mListingStats); | |
| 199 | innerPanel.add(mCategoryStats); | |
| 200 | innerPanel.add(new JLabel("")); | |
| 201 | mSSLEnabled = new JLabel(); | |
| 202 | mSSLEnabled.setText(sslState()); | |
| 203 | mSSLEnabled.setFont(mSSLEnabled.getFont().deriveFont(Font.BOLD | Font.ITALIC)); | |
| 204 | JPanel tmp = new JPanel(new BorderLayout()); | |
| 205 | tmp.add(mSSLEnabled, BorderLayout.EAST); | |
| 206 | innerPanel.add(tmp); | |
| 207 | SpringUtilities.makeCompactGrid(innerPanel, 4, 2, 6, 6, 6, 1); | |
| 208 | ||
| 209 | jp.add(innerPanel, BorderLayout.CENTER); | |
| 210 | return jp; | |
| 211 | } | |
| 212 | ||
| 213 | private String sslState() {return JConfig.queryConfiguration("my.jbidwatcher.allow.ssl", "false").equals("true") ? "SSL Enabled" : "SSL Disabled";} | |
| 214 | ||
| 215 | private JCheckBox createSettingsCheckbox(String text, String identifier) { | |
| 216 | String cfgAllowed = "my.jbidwatcher.allow." + identifier; | |
| 217 | String cfgSetting = "my.jbidwatcher." + identifier; | |
| 218 | final JCheckBox cb = new JCheckBox(text); | |
| 219 | cb.setEnabled(JConfig.queryConfiguration(cfgAllowed, "false").equals("true")); | |
| 220 | mConfigurationMap.put(cb, cfgSetting); | |
| 221 | mEnabledMap.put(cb, cfgAllowed); | |
| 222 | return cb; | |
| 223 | } | |
| 224 | ||
| 225 | private String left(String type) { | |
| 226 | String listings = JConfig.queryConfiguration("my.jbidwatcher.allow." + type, "unknown"); | |
| 227 | if(listings.equals("-1")) listings = "unlimited"; | |
| 228 | return listings + " " + type + " remaining"; | |
| 229 | } | |
| 158 | 230 | } |
