Source code: org/acs/damsel/client/remove/OrphanedAssetsAction.java
1 package org.acs.damsel.client.remove;
2
3 import java.util.*;
4 import javax.servlet.http.*;
5 import org.apache.log4j.*;
6 import org.acs.damsel.srvr.db.*;
7 import org.apache.struts.action.*;
8 import org.acs.damsel.client.ClientApp;
9 import org.acs.damsel.srvr.*;
10
11 /**
12 * @todo user client app class instead of assetdb class
13 */
14 public class OrphanedAssetsAction extends Action {
15 private Logger log = Logger.getLogger(OrphanedAssetsAction.class);
16
17 public OrphanedAssetsAction() {
18 BasicConfigurator.resetConfiguration();
19 PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
20 }
21
22
23 public ActionForward execute(ActionMapping actionMapping,
24 ActionForm actionForm,
25 HttpServletRequest httpServletRequest,
26 HttpServletResponse httpServletResponse) {
27 OrphanedAssetsForm orphanedAssetsForm = (OrphanedAssetsForm) actionForm;
28
29 try {
30 AssetDB assetDB = AssetDB.instance();
31 String value;
32 String name;
33 String potentialName;
34 Vector orphanedAssetsToDelete = new Vector();
35 Vector orphanedAssetsToRestore = new Vector();
36
37 if (orphanedAssetsForm.getSelectString().equals("sort")) {
38 return actionMapping.findForward("orphanSuccess");
39 } // end of if statement
40 for (Enumeration e = httpServletRequest.getParameterNames();
41 e.hasMoreElements(); ) {
42 potentialName = (String) e.nextElement();
43 if (potentialName.indexOf("delete") != -1) {
44 name = potentialName.substring(potentialName.indexOf("delete") + 6);
45 value = httpServletRequest.getParameter(potentialName);
46 if (value.equals("true")) {
47 if(orphanedAssetsForm.getSelectString().equals("delete")){
48 assetDB.deleteAsset(assetDB.getAsset(name));
49 orphanedAssetsToDelete.addElement(name);
50 } // end of if statement
51 else if (orphanedAssetsForm.getSelectString().equals("restore")){
52 ClientApp.instance().getCollectionMgr().addAssetToCollection(name,orphanedAssetsForm.getCollectionSelect());
53 if(!orphanedAssetsForm.getCollectionSelect().equals("AllAssets"))
54 ClientApp.instance().getCollectionMgr().addAssetToCollection(name, "AllAssets");
55 orphanedAssetsToRestore.addElement(name);
56 } // end of else if statement
57 } // end of if statement
58 } // end of if statement
59 } // end of for loop
60 if (orphanedAssetsForm.getSelectString().equals("delete")) {
61 httpServletRequest.getSession().setAttribute("orphanedAssetsToDelete",orphanedAssetsToDelete);
62 return actionMapping.findForward("orphanDelete");
63 } // end of if statement
64 else if (orphanedAssetsForm.getSelectString().equals("restore")) {
65 httpServletRequest.getSession().setAttribute("orphanedAssetsToRestore",orphanedAssetsToRestore);
66 return actionMapping.findForward("orphanRestore");
67 } // end of else if statement
68 return actionMapping.findForward("orphanSuccess");
69 } // end of try statement
70
71 catch (Exception ex) {
72 log.warn("Caught unexpected Exception " + ex.getMessage());
73 return actionMapping.findForward("failure");
74 } // end of catch statement
75 } // end of constructor
76 } // end of class