Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CommonServiceConstants |
|
| 6.0;6 |
1 | /* | |
2 | * Copyright 2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 1.0 (the | |
5 | * "License"); you may not use this file except in compliance with the | |
6 | * License. You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl1.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.student.r2.common.constants; | |
17 | ||
18 | import java.util.ArrayList; | |
19 | import org.kuali.student.r2.common.dto.AttributeInfo; | |
20 | import org.kuali.student.r2.common.dto.ContextInfo; | |
21 | ||
22 | /** | |
23 | * Constants used by for LuiPersonRelationService | |
24 | * | |
25 | * @author nwright | |
26 | */ | |
27 | 0 | public class CommonServiceConstants { |
28 | ||
29 | /** | |
30 | * Reference Object URI's | |
31 | */ | |
32 | public static final String REF_OBJECT_URI_GLOBAL_PREFIX = "http://student.kuali.org/wsdl/"; | |
33 | /** | |
34 | * Special attribute value which when supplied on the context during | |
35 | * a create will allow the calling program to supply an ID to the | |
36 | * implementation bypassing the check that throws a ReadOnlyException | |
37 | * if this is the case. | |
38 | */ | |
39 | public static final String ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_KEY = "kuali.context.allow.id.on.create"; | |
40 | public static final String ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_TRUE_VALUE = "TRUE"; | |
41 | public static final String ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_FALSE_VALUE = "FALSE"; | |
42 | ||
43 | /** | |
44 | * Checks if should allow Ids to be supplied on creates | |
45 | */ | |
46 | public static boolean isIdAllowedOnCreate(ContextInfo context) { | |
47 | 0 | if (context.getAttributes() == null) { |
48 | 0 | return false; |
49 | } | |
50 | 0 | for (AttributeInfo attr : context.getAttributes()) { |
51 | 0 | if (ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_KEY.equals(attr.getKey())) { |
52 | 0 | if (ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_TRUE_VALUE.equals(attr.getValue())) { |
53 | 0 | return true; |
54 | } | |
55 | } | |
56 | } | |
57 | 0 | return false; |
58 | } | |
59 | ||
60 | public static void setIsIdAllowedOnCreate(ContextInfo context, boolean allowed) { | |
61 | 0 | if (context.getAttributes() == null) { |
62 | 0 | context.setAttributes(new ArrayList<AttributeInfo>()); |
63 | } | |
64 | 0 | for (AttributeInfo attr : context.getAttributes()) { |
65 | 0 | if (ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_KEY.equals(attr.getKey())) { |
66 | 0 | attr.setValue(ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_TRUE_VALUE); |
67 | 0 | return; |
68 | } | |
69 | } | |
70 | 0 | AttributeInfo attr = new AttributeInfo (); |
71 | 0 | attr.setKey(ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_KEY); |
72 | 0 | attr.setValue(ALLOW_ID_ON_CREATE_CONTEXT_ATTRIBUTE_TRUE_VALUE); |
73 | 0 | context.getAttributes().add(attr); |
74 | 0 | } |
75 | } |