Source code: org/acs/damsel/client/edit/EditCollectionAction.java
1 package org.acs.damsel.client.edit;
2
3 import java.util.*;
4 import javax.servlet.http.*;
5
6 import org.acs.damsel.client.*;
7 import org.acs.damsel.srvr.*;
8 import org.acs.damsel.srvr.auth.*;
9 import org.acs.damsel.srvr.collection.*;
10 import org.acs.damsel.srvr.collection.Collection;
11 import org.apache.log4j.*;
12 import org.apache.struts.action.*;
13 import org.acs.damsel.srvr.schema.*;
14
15 public class EditCollectionAction
16 extends Action {
17 private Logger log = Logger.getLogger(EditCollectionAction.class);
18
19 public EditCollectionAction() {
20 BasicConfigurator.resetConfiguration();
21 PropertyConfigurator.configure(Config.instance().getLogPropertiesFileName());
22 }
23
24 public ActionForward execute(ActionMapping actionMapping,
25 ActionForm actionForm,
26 HttpServletRequest httpServletRequest,
27 HttpServletResponse httpServletResponse) {
28
29 EditCollectionForm editCollectionForm = (EditCollectionForm) actionForm;
30 ActionErrors errors;
31
32 CollectionMgr cMgr = ClientApp.instance().getCollectionMgr();
33 String potentialName;
34 AuthMgr aMgr = ClientApp.instance().getAuthMgr();
35
36 if (editCollectionForm.isCollectionChanged()) {
37 editCollectionForm.setCollectionChanged(false);
38 editCollectionForm.setDescription("");
39 editCollectionForm.setSchemaSelect("");
40 return (actionMapping.findForward("failure"));
41 }
42
43 if (editCollectionForm.isSchemaSelected()) {
44 editCollectionForm.setSchemaSelected(false);
45 return (actionMapping.findForward("failure"));
46 }
47
48 if (editCollectionForm.isPermSelected()) {
49 editCollectionForm.setPermSelected(false);
50 editCollectionForm.setCollectionChanged(false);
51 editCollectionForm.setButtonSelect(false);
52 return actionMapping.findForward("failure");
53 }
54
55 if (editCollectionForm.getAssetViewSelected().equals("assetView")) {
56 editCollectionForm.setAssetViewSelected("");
57 return actionMapping.findForward("failure");
58 }
59 if (editCollectionForm.getResultsViewSelected().equals("results")) {
60 editCollectionForm.setResultsViewSelected("");
61 return actionMapping.findForward("failure");
62 }
63
64 String perm = "";
65 Collection collection = cMgr.getCollection(editCollectionForm.
66 getCollectionSelect());
67 // Check the public, private, custom permissions value
68 String permType = (String) editCollectionForm.getPermission();
69 if (permType.equals("public")) {
70 String permissions = Integer.toString(ClientApp.instance().getAuthMgr().
71 getAllPermissions("rwdr--r--"));
72 collection.setPermissionID(permissions);
73 editCollectionForm.setPermissionID(permissions);
74
75 }
76 else if (permType.equals("private")) {
77 String permissionID = Integer.toString(ClientApp.instance().getAuthMgr().
78 getAllPermissions("rwdr-----"));
79
80 collection.setPermissionID(permissionID);
81 editCollectionForm.setPermissionID(permissionID);
82
83 }
84 else {
85
86 // Access the vector of the 9 permissions which was initialized in the
87 // editCollection.jsp page.
88 Vector allPerms = (Vector) httpServletRequest.getSession().getAttribute(
89 "allCollectionPermissions");
90
91 // Build a vector of containing 9 "false" strings to correspond to the
92 // 9 permissions in the allPerms vector.
93 Vector allFalse = new Vector();
94
95 for (int i = 0; i < allPerms.size(); i++) {
96 allFalse.add("false");
97 }
98
99 for (Enumeration e = httpServletRequest.getParameterNames();
100 e.hasMoreElements(); ) {
101 potentialName = (String) e.nextElement();
102
103 //goes through the vector allPerms until it finds the name of the
104 //checkbox in the vector. Once it finds the name it sets the value
105 //to true. All permissions that were not selected remain false.
106 //If the name of the checkbox is not found in the list of permissions
107 //the checkbox will not be counted as checked.
108 int indexOfPerm = 0;
109 boolean found = false;
110 while (!found && indexOfPerm < allPerms.size()) {
111 if (allPerms.elementAt(indexOfPerm).equals(potentialName)) {
112 found = true;
113 allFalse.setElementAt("true", indexOfPerm);
114 }
115 else {
116 indexOfPerm++;
117 }
118 }
119 //reset found and index so that the next checked permission can be found
120 //by searching through the vector of allPerms
121 found = false;
122 indexOfPerm = 0;
123 }
124 AuthMgr amgr = new AuthMgr();
125
126 //get the permissionID that matches the true and false permisssions sent
127 //to getAllPermissions
128 int intPerm = amgr.getAllPermissions(allPerms, allFalse);
129 perm = Integer.toString(intPerm);
130 editCollectionForm.setPermissionID(perm);
131 collection.setPermissionID(perm);
132 }
133 collection.setSchemaName(editCollectionForm.getSchemaSelect());
134 collection.setGroupName(editCollectionForm.getGroupSelect());
135 collection.setDescription(editCollectionForm.getDescription());
136 collection.setOwnerName(collection.getOwnerName());
137 collection.setRepositoryName(collection.getRepositoryName());
138
139 try {
140 SchemaMgr smgr = ClientApp.instance().getSchemaMgr();
141 Schema resultsMask = smgr.getSchema(collection.getCollectionName() + "ResultsMask");
142 Schema assetViewMask = smgr.getSchema(collection.getCollectionName() + "AssetViewMask");
143 Schema newResultsMask = new Schema();
144 Schema newAssetViewMask = new Schema();
145
146 newResultsMask.setName(resultsMask.getName());
147 newResultsMask.setGroupName(resultsMask.getGroupName());
148 newResultsMask.setOwnerName(resultsMask.getOwnerName());
149 newResultsMask.setPermissionID(resultsMask.getPermissionID());
150
151 newAssetViewMask.setName(assetViewMask.getName());
152 newAssetViewMask.setGroupName(assetViewMask.getGroupName());
153 newAssetViewMask.setOwnerName(assetViewMask.getOwnerName());
154 newAssetViewMask.setPermissionID(assetViewMask.getPermissionID());
155
156 for(Enumeration e = httpServletRequest.getParameterNames(); e.hasMoreElements(); ) {
157 potentialName = (String) e.nextElement();
158 if(potentialName.indexOf("AssetViewMask") != -1) {
159 String name = potentialName.substring(13);
160 MetaDataTag tag = new MetaDataTag();
161 tag.setName(name);
162 newAssetViewMask.addTag(tag);
163 }
164 else if(potentialName.indexOf("ResultsViewMask") != -1) {
165 String name = potentialName.substring(15);
166 MetaDataTag tag = new MetaDataTag();
167 tag.setName(name);
168 newResultsMask.addTag(tag);
169 }
170 }
171 smgr.updateSchema(newResultsMask);
172 smgr.updateSchema(newAssetViewMask);
173 }
174 catch (SchemaException ex) {
175 }
176 catch (SchemaMgrException ex) {
177 }
178
179 cMgr.updateCollection(collection);
180
181 editCollectionForm.reset(actionMapping, httpServletRequest);
182 return (actionMapping.findForward("success"));
183 }
184 }