Changeset 633 for AE/installer2/src/net/oni2/aeinstaller/backend/depot
- Timestamp:
- Jan 18, 2013, 7:18:45 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/backend/depot/DepotManager.java
r621 r633 72 72 taxonomyVocabulary.clear(); 73 73 74 HashMap<Integer, Node> oldNodes = null;75 HashMap<Integer, File> oldFiles = null;76 77 if (forceRefreshAll) {78 oldNodes = new HashMap<Integer, Node>();79 oldFiles = new HashMap<Integer, File>();80 } else {81 oldNodes = nodes;82 oldFiles = files;83 }84 85 74 nodes = new HashMap<Integer, Node>(); 86 75 nodesByType = new HashMap<String, HashMap<Integer, Node>>(); … … 90 79 JSONArray ja; 91 80 JSONObject jo; 92 int page; 93 94 // Get taxonomy vocabulary 95 if (listener != null) 96 listener.cacheUpdateProgress("Updating taxonomy vocabulary", 0, 97 100); 98 page = 0; 99 do { 100 ja = DrupalJSONQuery.getIndex("taxonomy_vocabulary", page, 100); 101 for (int i = 0; i < ja.length(); i++) { 102 jo = ja.getJSONObject(i); 103 TaxonomyVocabulary tv = new TaxonomyVocabulary(jo); 104 taxonomyVocabulary.put(tv.getVid(), tv); 105 } 106 page++; 107 } while (ja.length() > 0); 108 109 // Get taxonomy terms 110 if (listener != null) 111 listener.cacheUpdateProgress("Updating taxonomy terms", 0, 100); 112 page = 0; 113 do { 114 ja = DrupalJSONQuery.getIndex("taxonomy_term", page, 100); 115 for (int i = 0; i < ja.length(); i++) { 116 jo = ja.getJSONObject(i); 117 TaxonomyTerm tt = new TaxonomyTerm(jo); 118 taxonomyTerms.put(tt.getTid(), tt); 119 } 120 page++; 121 } while (ja.length() > 0); 122 123 // Check nodes for new information 124 if (listener != null) 125 listener.cacheUpdateProgress("Checking for new/updated nodes", 126 1, 100); 127 HashSet<Integer> nodesToUpdate = new HashSet<Integer>(); 128 page = 0; 129 do { 130 ja = DrupalJSONQuery.getIndex("node", page, 500); 131 for (int i = 0; i < ja.length(); i++) { 132 jo = ja.getJSONObject(i); 133 int nid = jo.getInt("nid"); 134 long changedRemote = jo.getLong("changed"); 135 if (oldNodes.containsKey(nid)) { 136 if (changedRemote > oldNodes.get(nid).getChanged()) 137 nodesToUpdate.add(nid); 138 else { 139 Node n = oldNodes.get(nid); 140 nodes.put(nid, n); 141 if (!nodesByType.containsKey(n.getType())) 142 nodesByType.put(n.getType(), 143 new HashMap<Integer, Node>()); 144 nodesByType.get(n.getType()).put(nid, n); 145 } 146 } else { 147 nodesToUpdate.add(nid); 148 } 149 } 150 page++; 151 } while (ja.length() > 0); 152 153 // Check files for new stuff 154 if (listener != null) 155 listener.cacheUpdateProgress("Checking for new/updated files", 156 2, 100); 157 HashSet<Integer> filesToUpdate = new HashSet<Integer>(); 158 page = 0; 159 do { 160 ja = DrupalJSONQuery.getIndex("file", page, 500); 161 for (int i = 0; i < ja.length(); i++) { 162 jo = ja.getJSONObject(i); 163 int fid = jo.getInt("fid"); 164 long changedRemote = jo.getLong("timestamp"); 165 if (oldFiles.containsKey(fid)) { 166 if (changedRemote > oldFiles.get(fid).getTimestamp()) 167 filesToUpdate.add(fid); 168 else 169 files.put(fid, oldFiles.get(fid)); 170 } else { 171 filesToUpdate.add(fid); 172 } 173 } 174 page++; 175 } while (ja.length() > 0); 176 177 int total = nodesToUpdate.size() + filesToUpdate.size() + 3; 178 int step = 3; 179 // Update nodes with new information 180 for (int nid : nodesToUpdate) { 181 if (listener != null) 182 listener.cacheUpdateProgress("Updating nodes", step++, 183 total); 184 185 ja = DrupalJSONQuery.getItem("node", nid, ""); 186 jo = ja.getJSONObject(0); 81 82 ja = DrupalJSONQuery 83 .executeQuery("http://mods.oni2.net/jsoncache/vocabulary.json"); 84 for (int i = 0; i < ja.length(); i++) { 85 jo = ja.getJSONObject(i); 86 TaxonomyVocabulary tv = new TaxonomyVocabulary(jo); 87 taxonomyVocabulary.put(tv.getVid(), tv); 88 } 89 90 ja = DrupalJSONQuery 91 .executeQuery("http://mods.oni2.net/jsoncache/terms.json"); 92 for (int i = 0; i < ja.length(); i++) { 93 jo = ja.getJSONObject(i); 94 TaxonomyTerm tt = new TaxonomyTerm(jo); 95 taxonomyTerms.put(tt.getTid(), tt); 96 } 97 98 ja = DrupalJSONQuery 99 .executeQuery("http://mods.oni2.net/jsoncache/nodes.json"); 100 for (int i = 0; i < ja.length(); i++) { 101 jo = ja.getJSONObject(i); 102 103 int nid = jo.getInt("nid"); 187 104 String type = jo.getString("type"); 188 105 … … 199 116 } 200 117 201 // Update new files 202 for (int fid : filesToUpdate) { 203 if (listener != null) 204 listener.cacheUpdateProgress("Updating files", step++, 205 total); 206 207 ja = DrupalJSONQuery.getItem("file", fid, "&file_contents=0"); 208 jo = ja.getJSONObject(0); 118 ja = DrupalJSONQuery 119 .executeQuery("http://mods.oni2.net/jsoncache/files.json"); 120 for (int i = 0; i < ja.length(); i++) { 121 jo = ja.getJSONObject(i); 122 123 int fid = jo.getInt("fid"); 209 124 210 125 File f = new File(jo);
Note:
See TracChangeset
for help on using the changeset viewer.