1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.test;
17
18 import org.apache.bcel.generic.NEW;
19 import org.kuali.rice.krad.service.BusinessObjectService;
20 import org.kuali.rice.krad.service.KRADServiceLocator;
21 import org.kuali.rice.krms.api.repository.context.ContextDefinition;
22 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
23 import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition;
24 import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition.Builder;
25 import org.kuali.rice.krms.api.repository.type.KrmsTypeAttribute;
26 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
27 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
28 import org.kuali.rice.krms.impl.repository.ContextAttributeBo;
29 import org.kuali.rice.krms.impl.repository.ContextBoService;
30 import org.kuali.rice.krms.impl.repository.KrmsAttributeDefinitionService;
31 import org.kuali.rice.krms.impl.repository.TermBoService;
32 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
33 import org.kuali.rice.test.BaselineTestCase.Mode;
34
35 import java.util.ArrayList;
36 import java.util.Collection;
37 import java.util.Collections;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 @BaselineMode(Mode.ROLLBACK)
43 public abstract class KSLumAbstractBoTest extends KRMSTestCase {
44
45 private static final String ATTR_NUMBER_OF_CREDITS = "Number of Credits";
46 private static final String ATTR_DEPT_ORG_NUMBER = "Dept Org Number";
47 private static final String ATTR_PROPOSED_COURSE = "Proposed Course";
48 private static final String ATTR_APPROVED_COURSE = "Approved Course";
49 protected ContextBoService contextRepository;
50 protected KrmsTypeRepositoryService krmsTypeRepository;
51 protected KrmsAttributeDefinitionService krmsAttributeDefinitionService;
52 protected Map<String, KrmsAttributeDefinition> ksLumAttributeDefinitions = new HashMap<String, KrmsAttributeDefinition>();
53
54 private TermBoService termBoService;
55
56 protected BusinessObjectService getBoService() {
57 return KRADServiceLocator.getBusinessObjectService();
58 }
59
60 protected ContextDefinition createContextDefinition(String nameSpace, String name,
61 Map<String, String> contextAttributes) {
62
63 List<KrmsTypeAttribute.Builder> contextAttributeBuilders = new ArrayList<KrmsTypeAttribute.Builder>();
64 int contextAttrSequenceIndex = 0;
65
66 List<KrmsAttributeDefinition> attributeDefintions = new ArrayList<KrmsAttributeDefinition>();
67
68 createAllLumAttributeDefinitions(nameSpace);
69
70 KrmsTypeDefinition krmsContextTypeDefinition = createContextType(nameSpace);
71
72 ContextDefinition contextDefinition = createContext(nameSpace, name,
73 krmsContextTypeDefinition);
74
75
76
77 for (KrmsAttributeDefinition contextTypeAttributeDefinition : attributeDefintions) {
78 ContextAttributeBo contextAttribute = new ContextAttributeBo();
79 contextAttribute.setAttributeDefinitionId(contextTypeAttributeDefinition.getId());
80 contextAttribute.setContextId(contextDefinition.getId());
81 contextAttribute.setValue(contextAttributes.get(contextTypeAttributeDefinition.getName()));
82 getBoService().save(contextAttribute);
83 }
84
85 return contextDefinition;
86 }
87
88 public ContextDefinition createContext(String nameSpace, String name,
89 KrmsTypeDefinition krmsContextTypeDefinition) {
90
91 ContextDefinition.Builder contextBuilder = ContextDefinition.Builder.create(nameSpace, name);
92
93 contextBuilder.setTypeId("T1003");
94 ContextDefinition contextDefinition = contextBuilder.build();
95 contextDefinition = contextRepository.createContext(contextDefinition);
96 return contextDefinition;
97 }
98
99 protected KrmsTypeDefinition createContextType(String nameSpace) {
100
101 KrmsTypeDefinition.Builder krmsContextTypeDefnBuilder = KrmsTypeDefinition.Builder.create("KSLumContextType-Course", nameSpace);
102 krmsContextTypeDefnBuilder.setServiceName("myKSService");
103
104 int contextAttrSequenceIndex = 0;
105 List<KrmsTypeAttribute.Builder> contextAttributeBuilders = new ArrayList<KrmsTypeAttribute.Builder>();
106 for (KrmsAttributeDefinition attrDef : ksLumAttributeDefinitions.values()) {
107 contextAttributeBuilders.add(KrmsTypeAttribute.Builder.create(null, attrDef.getId(),
108 contextAttrSequenceIndex));
109 contextAttrSequenceIndex += 1;
110
111 }
112 krmsContextTypeDefnBuilder.setAttributes(contextAttributeBuilders);
113
114 KrmsTypeDefinition krmsContextTypeDefinition = krmsContextTypeDefnBuilder.build();
115 krmsContextTypeDefinition = krmsTypeRepository.createKrmsType(krmsContextTypeDefinition);
116 return krmsContextTypeDefinition;
117 }
118
119
120
121 protected void createAllLumAttributeDefinitions(
122 String nameSpace) {
123
124 createNumberOfCreditsAttributeDefinition(nameSpace);
125 createDeptOrgNumberAttributeDefinition(nameSpace);
126 createProposedCourseAttributeDefinition(nameSpace);
127 createApprovedCourseAttributeDefinition(nameSpace);
128 }
129
130 private void createNumberOfCreditsAttributeDefinition(
131 String nameSpace) {
132 KrmsAttributeDefinition.Builder numberOfCreditsBuilder = KrmsAttributeDefinition.Builder.create(null, ATTR_NUMBER_OF_CREDITS, nameSpace);
133 numberOfCreditsBuilder.setLabel(numberOfCreditsBuilder.getName());
134 numberOfCreditsBuilder.setDescription(numberOfCreditsBuilder.getName());
135
136 KrmsAttributeDefinition attributeDefinition = krmsAttributeDefinitionService.createAttributeDefinition(numberOfCreditsBuilder.build());
137 ksLumAttributeDefinitions.put(attributeDefinition.getName(),attributeDefinition);
138 }
139
140 private void createDeptOrgNumberAttributeDefinition(
141 String nameSpace) {
142 KrmsAttributeDefinition.Builder deptOrgNumberBuilder = KrmsAttributeDefinition.Builder.create(null, ATTR_DEPT_ORG_NUMBER, nameSpace);
143 deptOrgNumberBuilder.setLabel(deptOrgNumberBuilder.getName());
144 deptOrgNumberBuilder.setDescription(deptOrgNumberBuilder.getName());
145
146 KrmsAttributeDefinition attributeDefinition = krmsAttributeDefinitionService.createAttributeDefinition(deptOrgNumberBuilder.build());
147 ksLumAttributeDefinitions.put(attributeDefinition.getName(),attributeDefinition);
148 }
149
150 private void createProposedCourseAttributeDefinition(
151 String nameSpace) {
152 KrmsAttributeDefinition.Builder proposedCourseBuilder = KrmsAttributeDefinition.Builder.create(null, ATTR_PROPOSED_COURSE, nameSpace);
153 proposedCourseBuilder.setLabel(proposedCourseBuilder.getName());
154 proposedCourseBuilder.setDescription(proposedCourseBuilder.getName());
155
156 KrmsAttributeDefinition attributeDefinition = krmsAttributeDefinitionService.createAttributeDefinition(proposedCourseBuilder.build());
157 ksLumAttributeDefinitions.put(attributeDefinition.getName(),attributeDefinition);
158 }
159
160 private void createApprovedCourseAttributeDefinition(
161 String nameSpace) {
162 KrmsAttributeDefinition.Builder approvedCourseBuilder = KrmsAttributeDefinition.Builder.create(null, ATTR_APPROVED_COURSE, nameSpace);
163 approvedCourseBuilder.setLabel(approvedCourseBuilder.getName());
164 approvedCourseBuilder.setDescription(approvedCourseBuilder.getName());
165
166 KrmsAttributeDefinition attributeDefinition = krmsAttributeDefinitionService.createAttributeDefinition(approvedCourseBuilder.build());
167 ksLumAttributeDefinitions.put(attributeDefinition.getName(),attributeDefinition);
168 }
169
170
171
172
173
174
175
176
177
178
179
180
181 protected KrmsTypeDefinition createKrmsGenericTypeDefinition(String nameSpace, String serviceName,
182 String attributeDefinitionLabel, String attributeDefinitionName) {
183 KrmsTypeDefinition krmsGenericTypeDefinition = krmsTypeRepository.getTypeByName(nameSpace, "Event");
184
185 if (null == krmsGenericTypeDefinition) {
186
187
188 KrmsAttributeDefinition.Builder genericTypeAttributeDefnBuilder = KrmsAttributeDefinition.Builder.create(null,
189 attributeDefinitionName, nameSpace);
190 genericTypeAttributeDefnBuilder.setLabel(attributeDefinitionLabel);
191 KrmsAttributeDefinition genericTypeAttributeDefinition1 = krmsAttributeDefinitionService.createAttributeDefinition(genericTypeAttributeDefnBuilder.build());
192
193
194 KrmsTypeAttribute.Builder genericTypeAttrBuilder = KrmsTypeAttribute.Builder.create(null, genericTypeAttributeDefinition1.getId(), 1);
195
196
197 KrmsTypeDefinition.Builder krmsGenericTypeDefnBuilder = KrmsTypeDefinition.Builder.create("KrmsTestGenericType", nameSpace);
198 krmsGenericTypeDefnBuilder.setServiceName(serviceName);
199 krmsGenericTypeDefnBuilder.setAttributes(Collections.singletonList(genericTypeAttrBuilder));
200 krmsGenericTypeDefinition = krmsTypeRepository.createKrmsType(krmsGenericTypeDefnBuilder.build());
201
202 }
203
204 return krmsGenericTypeDefinition;
205 }
206
207 }