| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.student.r2.core.class1.state.service.impl; |
| 18 | |
|
| 19 | |
import javax.jws.WebParam; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.Collection; |
| 22 | |
import java.util.Collections; |
| 23 | |
import java.util.HashMap; |
| 24 | |
import java.util.HashSet; |
| 25 | |
import java.util.List; |
| 26 | |
import java.util.Map; |
| 27 | |
import java.util.Set; |
| 28 | |
|
| 29 | |
import org.kuali.student.r2.core.state.dto.LifecycleInfo; |
| 30 | |
import org.kuali.student.r2.core.state.dto.StateInfo; |
| 31 | |
import org.kuali.student.r2.core.state.service.StateService; |
| 32 | |
|
| 33 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
| 34 | |
|
| 35 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 36 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
| 37 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
| 38 | |
import org.kuali.student.r2.common.exceptions.AlreadyExistsException; |
| 39 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
| 40 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
| 41 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
| 42 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
| 43 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
| 44 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
| 45 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
| 46 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | 0 | public class StateServiceMockImpl |
| 55 | |
implements StateService { |
| 56 | |
|
| 57 | 0 | private final Map<String, LifecycleInfo> lifecycles = new HashMap<String, LifecycleInfo>(); |
| 58 | 0 | private final Map<String, StateInfo> states = new HashMap<String, StateInfo>(); |
| 59 | 0 | private final Map<String, Collection<String>> lifecycleStates = new HashMap<String, Collection<String>>(); |
| 60 | |
|
| 61 | |
@Override |
| 62 | |
public LifecycleInfo getLifecycle(String lifecycleKey, ContextInfo contextInfo) |
| 63 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 64 | |
|
| 65 | 0 | LifecycleInfo lifecycle = this.lifecycles.get(lifecycleKey); |
| 66 | 0 | if (lifecycle == null ) { |
| 67 | 0 | throw new DoesNotExistException(lifecycleKey); |
| 68 | |
} |
| 69 | |
|
| 70 | 0 | return lifecycle; |
| 71 | |
} |
| 72 | |
|
| 73 | |
@Override |
| 74 | |
public List<LifecycleInfo> getLifecyclesByKeys(List<String> lifecycleKeys, ContextInfo contextInfo) |
| 75 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 76 | |
|
| 77 | 0 | List<LifecycleInfo> ret = new ArrayList<LifecycleInfo>(); |
| 78 | 0 | for (String key : lifecycleKeys) { |
| 79 | 0 | ret.add(getLifecycle(key, contextInfo)); |
| 80 | |
} |
| 81 | |
|
| 82 | 0 | return ret; |
| 83 | |
} |
| 84 | |
|
| 85 | |
@Override |
| 86 | |
public List<String> getLifecycleKeysByRefObjectUri(String refObjectUri, ContextInfo contextInfo) |
| 87 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 88 | |
|
| 89 | 0 | List<String> ret = new ArrayList<String>(); |
| 90 | 0 | for (LifecycleInfo lifecycle : this.lifecycles.values()) { |
| 91 | 0 | if (refObjectUri.equals(lifecycle.getRefObjectUri())) { |
| 92 | 0 | ret.add(lifecycle.getKey()); |
| 93 | |
} |
| 94 | |
} |
| 95 | |
|
| 96 | 0 | return ret; |
| 97 | |
} |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public List<String> searchForLifecycleKeys(QueryByCriteria criteria, ContextInfo contextInfo) |
| 101 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 102 | |
|
| 103 | 0 | return new ArrayList<String>(this.lifecycles.keySet()); |
| 104 | |
} |
| 105 | |
|
| 106 | |
@Override |
| 107 | |
public List<LifecycleInfo> searchForLifecycles(QueryByCriteria criteria, ContextInfo contextInfo) |
| 108 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 109 | |
|
| 110 | 0 | return new ArrayList<LifecycleInfo>(this.lifecycles.values()); |
| 111 | |
} |
| 112 | |
|
| 113 | |
@Override |
| 114 | |
public List<ValidationResultInfo> validateLifecycle(String validationTypeKey, LifecycleInfo lifecycleInfo, ContextInfo contextInfo) |
| 115 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 116 | |
|
| 117 | 0 | return new ArrayList<ValidationResultInfo>(); |
| 118 | |
} |
| 119 | |
|
| 120 | |
@Override |
| 121 | |
public LifecycleInfo createLifecycle(String lifecycleKey, LifecycleInfo lifecycleInfo, ContextInfo contextInfo) |
| 122 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 123 | |
|
| 124 | 0 | if (this.lifecycles.get(lifecycleKey) != null) { |
| 125 | 0 | throw new AlreadyExistsException(lifecycleKey + " already exists"); |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | 0 | this.lifecycles.put(lifecycleKey, lifecycleInfo); |
| 131 | 0 | this.lifecycleStates.put(lifecycleKey, new HashSet<String>()); |
| 132 | |
|
| 133 | 0 | return lifecycleInfo; |
| 134 | |
} |
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public LifecycleInfo updateLifecycle(String lifecycleKey, LifecycleInfo lifecycleInfo, ContextInfo contextInfo) |
| 138 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
| 139 | |
|
| 140 | 0 | if (this.lifecycles.get(lifecycleKey) != null) { |
| 141 | 0 | throw new DoesNotExistException(lifecycleKey + " does not exist"); |
| 142 | |
} |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | 0 | this.lifecycles.put(lifecycleKey, lifecycleInfo); |
| 147 | 0 | return lifecycleInfo; |
| 148 | |
} |
| 149 | |
|
| 150 | |
@Override |
| 151 | |
public StatusInfo deleteLifecycle(String lifecycleKey, ContextInfo contextInfo) |
| 152 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 153 | |
|
| 154 | 0 | if (this.lifecycles.get(lifecycleKey) != null) { |
| 155 | 0 | throw new DoesNotExistException(lifecycleKey + " does not exist"); |
| 156 | |
} |
| 157 | |
|
| 158 | 0 | this.lifecycles.remove(lifecycleKey); |
| 159 | 0 | this.lifecycleStates.remove(lifecycleKey); |
| 160 | |
|
| 161 | 0 | return new StatusInfo(); |
| 162 | |
} |
| 163 | |
|
| 164 | |
|
| 165 | |
@Override |
| 166 | |
public StateInfo getState(String stateKey, ContextInfo context) |
| 167 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 168 | |
|
| 169 | 0 | StateInfo state = this.states.get(stateKey); |
| 170 | 0 | if (state == null ) { |
| 171 | 0 | throw new DoesNotExistException(stateKey); |
| 172 | |
} |
| 173 | |
|
| 174 | 0 | return state; |
| 175 | |
} |
| 176 | |
|
| 177 | |
@Override |
| 178 | |
public List<StateInfo> getStatesByKeys(List<String> stateKeys, ContextInfo contextInfo) |
| 179 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 180 | |
|
| 181 | 0 | List<StateInfo> ret = new ArrayList<StateInfo>(); |
| 182 | 0 | for (String key : stateKeys) { |
| 183 | 0 | ret.add(getState(key, contextInfo)); |
| 184 | |
} |
| 185 | |
|
| 186 | 0 | return ret; |
| 187 | |
} |
| 188 | |
|
| 189 | |
public List<StateInfo> getStatesByLifecycle(String lifecycleKey, ContextInfo contextInfo) |
| 190 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 191 | |
|
| 192 | 0 | Collection<String> stateKeys = this.lifecycleStates.get(lifecycleKey); |
| 193 | 0 | if (states == null) { |
| 194 | 0 | throw new DoesNotExistException(lifecycleKey + " not found"); |
| 195 | |
} |
| 196 | |
|
| 197 | 0 | return getStatesByKeys(new ArrayList<String>(stateKeys), contextInfo); |
| 198 | |
} |
| 199 | |
|
| 200 | |
public List<String> searchForStateKeys(QueryByCriteria criteria, ContextInfo contextInfo) |
| 201 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 202 | |
|
| 203 | 0 | return new ArrayList<String>(this.states.keySet()); |
| 204 | |
} |
| 205 | |
|
| 206 | |
public List<StateInfo> searchForStates(QueryByCriteria criteria, ContextInfo contextInfo) |
| 207 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 208 | |
|
| 209 | 0 | return new ArrayList<StateInfo>(this.states.values()); |
| 210 | |
} |
| 211 | |
|
| 212 | |
@Override |
| 213 | |
public List<ValidationResultInfo> validateState(String validationStateKey, String lifecycleKey, StateInfo stateInfo, ContextInfo contextInfo) |
| 214 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 215 | |
|
| 216 | 0 | if (this.lifecycles.get(lifecycleKey) == null) { |
| 217 | 0 | throw new DoesNotExistException(lifecycleKey + " not found"); |
| 218 | |
} |
| 219 | |
|
| 220 | 0 | return new ArrayList<ValidationResultInfo>(); |
| 221 | |
} |
| 222 | |
|
| 223 | |
@Override |
| 224 | |
public StateInfo createState(String lifecycleKey, String stateKey, StateInfo stateInfo, ContextInfo contextInfo) |
| 225 | |
throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 226 | |
|
| 227 | 0 | if (this.states.get(stateKey) != null) { |
| 228 | 0 | throw new AlreadyExistsException(stateKey + " already exists"); |
| 229 | |
} |
| 230 | |
|
| 231 | 0 | if (this.lifecycles.get(lifecycleKey) == null) { |
| 232 | 0 | throw new DoesNotExistException(lifecycleKey + " not found"); |
| 233 | |
} |
| 234 | |
|
| 235 | 0 | if (stateInfo.getKey() == null) { |
| 236 | 0 | stateInfo.setKey(stateKey); |
| 237 | 0 | } else if (!stateKey.equals(stateInfo.getKey())) { |
| 238 | 0 | throw new DataValidationErrorException("attempt to set a state key"); |
| 239 | |
} |
| 240 | |
|
| 241 | 0 | if (stateInfo.getLifecycleKey() == null) { |
| 242 | 0 | stateInfo.setLifecycleKey(lifecycleKey); |
| 243 | 0 | } else if (!lifecycleKey.equals(stateInfo.getLifecycleKey())) { |
| 244 | 0 | throw new DataValidationErrorException("attempt to set a lifecycle in state"); |
| 245 | |
} |
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | 0 | this.states.put(stateKey, stateInfo); |
| 250 | 0 | this.lifecycleStates.get(lifecycleKey).add(stateKey); |
| 251 | |
|
| 252 | 0 | return stateInfo; |
| 253 | |
} |
| 254 | |
|
| 255 | |
@Override |
| 256 | |
public StateInfo updateState(String stateKey, StateInfo stateInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
| 257 | |
|
| 258 | 0 | StateInfo oldState = this.states.get(stateKey); |
| 259 | 0 | if (oldState == null) { |
| 260 | 0 | throw new DoesNotExistException(stateKey + " does not exist"); |
| 261 | |
} |
| 262 | |
|
| 263 | 0 | if (stateInfo.getKey() == null) { |
| 264 | 0 | stateInfo.setKey(oldState.getKey()); |
| 265 | 0 | } else if (!oldState.getKey().equals(stateInfo.getKey())) { |
| 266 | 0 | throw new DataValidationErrorException("attempt to set the state key"); |
| 267 | |
} |
| 268 | |
|
| 269 | 0 | if (stateInfo.getLifecycleKey() == null) { |
| 270 | 0 | stateInfo.setLifecycleKey(oldState.getLifecycleKey()); |
| 271 | 0 | } else if (!oldState.getLifecycleKey().equals(stateInfo.getLifecycleKey())) { |
| 272 | 0 | throw new DataValidationErrorException("attempt to set a lifecycle in state"); |
| 273 | |
} |
| 274 | |
|
| 275 | 0 | this.states.put(oldState.getKey(), stateInfo); |
| 276 | 0 | return stateInfo; |
| 277 | |
} |
| 278 | |
|
| 279 | |
@Override |
| 280 | |
public StatusInfo deleteState(String stateKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 281 | |
|
| 282 | 0 | StateInfo state = this.states.get(stateKey); |
| 283 | 0 | if (state == null) { |
| 284 | 0 | throw new DoesNotExistException( stateKey + " does not exist"); |
| 285 | |
} |
| 286 | |
|
| 287 | 0 | this.states.remove(stateKey); |
| 288 | 0 | this.lifecycleStates.get(state.getLifecycleKey()).remove(stateKey); |
| 289 | |
|
| 290 | 0 | return new StatusInfo(); |
| 291 | |
} |
| 292 | |
} |