1 package org.tigris.scarab.actions; 2 3 48 49 import java.util.List ; 50 51 import org.apache.fulcrum.intake.model.Field; 52 import org.apache.fulcrum.intake.model.Group; 53 import org.apache.fulcrum.parser.ParameterParser; 54 import org.apache.torque.om.NumberKey; 55 import org.apache.turbine.RunData; 56 import org.apache.turbine.TemplateContext; 57 import org.apache.turbine.tool.IntakeTool; 58 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 59 import org.tigris.scarab.om.Query; 60 import org.tigris.scarab.om.QueryManager; 61 import org.tigris.scarab.om.RQueryUser; 62 import org.tigris.scarab.om.ScarabUser; 63 import org.tigris.scarab.services.cache.ScarabCache; 64 import org.tigris.scarab.tools.ScarabLocalizationTool; 65 import org.tigris.scarab.tools.ScarabRequestTool; 66 67 73 public class QueryList extends RequireLoginFirstAction 74 { 75 76 79 public void doSave(RunData data, TemplateContext context) 80 throws Exception 81 { 82 IntakeTool intake = getIntakeTool(context); 83 ScarabRequestTool scarabR = getScarabRequestTool(context); 84 ScarabLocalizationTool l10n = getLocalizationTool(context); 85 ScarabUser user = (ScarabUser)data.getUser(); 86 87 if (intake.isAllValid()) 88 { 89 boolean valid = true; 90 List queries = scarabR.getAllQueries(); 91 for (int i = 0; i < queries.size(); i++) 92 { 93 Query query = (Query)queries.get(i); 94 RQueryUser rqu = query.getRQueryUser(user); 95 Group queryGroup = intake.get("RQueryUser", 96 rqu.getQueryKey(), false); 97 if (queryGroup != null) 98 { 99 Field sub = queryGroup.get("Subscribed"); 100 if (sub.toString().equals("true")) 101 { 102 Field freq = queryGroup.get("Frequency"); 103 freq.setRequired(true); 104 if (!freq.isValid()) 105 { 106 valid = false; 107 freq.setMessage("EnterSubscriptionFrequency"); 108 } 109 } 110 if (valid) 111 { 112 queryGroup.setProperties(rqu); 113 rqu.save(); 114 } 115 } 116 } 117 } 118 else 119 { 120 scarabR.setAlertMessage(ERROR_MESSAGE); 121 } 122 ScarabCache.clear(); 123 } 124 125 126 public void doDeletequeries(RunData data, TemplateContext context) 127 throws Exception 128 { 129 Object [] keys = data.getParameters().getKeys(); 130 String key; 131 String queryId; 132 ScarabUser user = (ScarabUser)data.getUser(); 133 134 for (int i =0; i<keys.length; i++) 135 { 136 key = keys[i].toString(); 137 if (key.startsWith("action_")) 138 { 139 queryId = key.substring(7); 140 Query query = QueryManager 141 .getInstance(new NumberKey(queryId), false); 142 try 143 { 144 query.delete(user); 145 query.save(); 146 } 147 catch (Exception e) 148 { 149 ScarabLocalizationTool l10n = getLocalizationTool(context); 150 getScarabRequestTool(context).setAlertMessage(NO_PERMISSION_MESSAGE); 151 } 152 153 } 154 } 155 } 156 157 public void doCopyquery(RunData data, TemplateContext context) 158 throws Exception 159 { 160 ParameterParser pp = data.getParameters(); 161 Object [] keys = pp.getKeys(); 162 String key; 163 String queryId; 164 Query query; 165 166 for (int i =0; i<keys.length; i++) 167 { 168 key = keys[i].toString(); 169 if (key.startsWith("action_")) 170 { 171 queryId = key.substring(7); 172 query = QueryManager 173 .getInstance(new NumberKey(queryId), false); 174 query.copyQuery((ScarabUser)data.getUser()); 175 } 176 } 177 } 178 179 184 public void doGotoadvancedquery(RunData data, TemplateContext context) 185 throws Exception 186 { 187 ScarabUser user = (ScarabUser)data.getUser(); 189 user.setCurrentMITList(null); 190 getScarabRequestTool(context).resetSelectedUsers(); 192 setTarget(data, user.getQueryTarget()); 193 } 194 } 195 | Popular Tags |