- Timestamp:
- 2013-07-11T15:36:11+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DepositorAction.java
r27719 r27806 4 4 import java.io.File; 5 5 import java.io.FileWriter; 6 import java.io.IOException;7 6 import java.io.Serializable; 7 import java.lang.reflect.Type; 8 8 import java.util.ArrayList; 9 9 import java.util.HashMap; 10 10 import java.util.Iterator; 11 import java.util.List; 12 import java.util.Map; 11 13 12 14 import javax.xml.parsers.DocumentBuilderFactory; … … 27 29 import org.w3c.dom.Node; 28 30 31 import com.google.gson.Gson; 32 import com.google.gson.reflect.TypeToken; 33 29 34 public class DepositorAction extends Action 30 35 { 31 36 //Sub actions 32 private final String DE_RETRIEVE_WIZARD = "getWizard"; 33 private final String DE_DEPOSIT_FILE = "depositFile"; 37 private final String DE_RETRIEVE_WIZARD = "getwizard"; 38 private final String DE_DEPOSIT_FILE = "depositfile"; 39 private final String DE_CLEAR_DATABASE = "cleardatabase"; 34 40 35 41 public Node process(Node message) … … 85 91 } 86 92 93 int highestVisitedPage = -1; 94 String result = ""; 95 int counter = 1; 96 while (result != null) 97 { 98 result = database.getUserData(currentUsername, "DE___" + collection + "___" + counter + "___VISITED_PAGE"); 99 if (result != null) 100 { 101 counter++; 102 } 103 } 104 highestVisitedPage = counter - 1; 105 if (highestVisitedPage == 0) 106 { 107 highestVisitedPage = 1; 108 } 109 110 if (pageNum > highestVisitedPage + 1) 111 { 112 pageNum = highestVisitedPage + 1; 113 } 114 115 database.addUserData(currentUsername, "DE___" + collection + "___" + pageNum + "___VISITED_PAGE", "VISITED"); 116 87 117 String subaction = ((Element) request).getAttribute(GSXML.SUBACTION_ATT); 88 if (subaction. equals(DE_RETRIEVE_WIZARD))118 if (subaction.toLowerCase().equals(DE_RETRIEVE_WIZARD)) 89 119 { 90 120 //Save given metadata … … 171 201 pageLi.setAttribute("class", "wizardStepLink ui-state-active ui-corner-all"); 172 202 } 203 else if (i + 1 > highestVisitedPage + 1 && i + 1 > pageNum + 1) 204 { 205 pageLi.setAttribute("class", "wizardStepLink ui-state-disabled ui-corner-all"); 206 } 173 207 else 174 208 { … … 233 267 database.closeDatabase(); 234 268 } 235 else if (subaction. equals(DE_DEPOSIT_FILE))269 else if (subaction.toLowerCase().equals(DE_DEPOSIT_FILE)) 236 270 { 237 271 String fileToAdd = (String) params.get("fileToAdd"); … … 257 291 } 258 292 259 String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!DOCTYPE DirectoryMetadata SYSTEM \"http://greenstone.org/dtd/DirectoryMetadata/1.0/DirectoryMetadata.dtd\"><DirectoryMetadata><FileSet>"; 260 xmlString += "<FileName>" + fileToAdd + "</FileName><Description>"; 261 Iterator<String> paramIter = params.keySet().iterator(); 262 while (paramIter.hasNext()) 263 { 264 String paramName = paramIter.next(); 265 if (paramName.startsWith("md___")) 293 HashMap<String, String> metadataMap = new HashMap<String, String>(); 294 for (int i = pageNum; i > 0; i--) 295 { 296 String cachedValues = database.getUserData(currentUsername, "DE___" + collection + "___" + i + "___CACHED_VALUES"); 297 if (cachedValues != null) 266 298 { 267 Object paramValue = params.get(paramName); 268 269 if (paramValue instanceof String) 299 Type type = new TypeToken<List<Map<String, String>>>() 270 300 { 271 xmlString += "<Metadata name=\"" + paramName.substring(5) + "\" mode=\"accumulate\">" + (String) paramValue + "</Metadata>"; 272 } 273 else if (paramValue instanceof HashMap) 301 }.getType(); 302 303 Gson gson = new Gson(); 304 List<Map<String, String>> metadataList = gson.fromJson(cachedValues, type); 305 for (Map<String, String> metadata : metadataList) 274 306 { 275 HashMap<String, String> subMap = (HashMap<String, String>) paramValue; 276 Iterator<String> subKeyIter = subMap.keySet().iterator(); 277 while (subKeyIter.hasNext()) 278 { 279 String subName = subKeyIter.next(); 280 xmlString += "<Metadata name=\"" + paramName.substring(5) + "." + subName + "\" mode=\"accumulate\">" + subMap.get(subName) + "</Metadata>"; 281 } 307 metadataMap.put(metadata.get("name"), metadata.get("value")); 282 308 } 283 309 } 284 310 } 285 xmlString += "</Description></FileSet><DirectoryMetadata>"; 311 312 String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!DOCTYPE DirectoryMetadata SYSTEM \"http://greenstone.org/dtd/DirectoryMetadata/1.0/DirectoryMetadata.dtd\"><DirectoryMetadata><FileSet>"; 313 xmlString += "<FileName>.*</FileName><Description>"; 314 for (String key : metadataMap.keySet()) 315 { 316 xmlString += "<Metadata name=\"" + key.substring("MD___".length()) + "\" mode=\"accumulate\">" + metadataMap.get(key) + "</Metadata>"; 317 } 318 xmlString += "</Description></FileSet></DirectoryMetadata>"; 286 319 287 320 File metadataFile = new File(GlobalProperties.getGSDL3Home() + File.separator + "sites" + File.separator + this.config_params.get(GSConstants.SITE_NAME) + File.separator + "collect" + File.separator + collection + File.separator + "import" + File.separator + fileToAdd + File.separator + "metadata.xml"); … … 317 350 Element buildResponseMessage = (Element) this.mr.process(buildMessage); 318 351 319 System.err.println("RESPONSE = " + GSXML.xmlNodeToString(buildResponseMessage));320 321 352 response.appendChild(this.doc.importNode(buildResponseMessage, true)); 322 353 } 354 } 355 else if (subaction.toLowerCase().equals(DE_CLEAR_DATABASE)) 356 { 357 database.clearUserData(); 358 System.err.println("\n\nCLEARED\n\n"); 323 359 } 324 360 else
Note:
See TracChangeset
for help on using the changeset viewer.