1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package edu.sampleu.krms.impl; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
20 | |
import org.kuali.rice.core.api.uif.DataType; |
21 | |
import org.kuali.rice.core.api.uif.RemotableAbstractWidget; |
22 | |
import org.kuali.rice.core.api.uif.RemotableAttributeError; |
23 | |
import org.kuali.rice.core.api.uif.RemotableAttributeField; |
24 | |
import org.kuali.rice.core.api.uif.RemotableAttributeLookupSettings; |
25 | |
import org.kuali.rice.core.api.uif.RemotableQuickFinder; |
26 | |
import org.kuali.rice.core.api.uif.RemotableTextInput; |
27 | |
import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter; |
28 | |
import org.kuali.rice.krad.uif.util.LookupInquiryUtils; |
29 | |
import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition; |
30 | |
import org.kuali.rice.krms.api.repository.type.KrmsTypeAttribute; |
31 | |
import org.kuali.rice.krms.impl.type.AgendaTypeServiceBase; |
32 | |
import org.kuali.rice.location.api.campus.Campus; |
33 | |
import org.kuali.rice.location.api.services.LocationApiServiceLocator; |
34 | |
import org.kuali.rice.location.impl.campus.CampusBo; |
35 | |
|
36 | |
import javax.jws.WebParam; |
37 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
38 | |
import java.util.ArrayList; |
39 | |
import java.util.Collections; |
40 | |
import java.util.List; |
41 | |
import java.util.Map; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class CampusAgendaTypeService extends AgendaTypeServiceBase { |
47 | |
|
48 | |
private static final String CAMPUS_FIELD_NAME = "Campus"; |
49 | |
|
50 | |
@Override |
51 | |
public RemotableAttributeField translateTypeAttribute(KrmsTypeAttribute inputAttribute, |
52 | |
KrmsAttributeDefinition attributeDefinition) { |
53 | |
|
54 | 0 | if (CAMPUS_FIELD_NAME.equals(attributeDefinition.getName())) { |
55 | 0 | return createCampusField(); |
56 | |
} else { |
57 | 0 | return super.translateTypeAttribute(inputAttribute, |
58 | |
attributeDefinition); |
59 | |
} |
60 | |
} |
61 | |
|
62 | |
private RemotableAttributeField createCampusField() { |
63 | |
|
64 | 0 | String campusBoClassName = CampusBo.class.getName(); |
65 | |
|
66 | 0 | String baseLookupUrl = LookupInquiryUtils.getBaseLookupUrl(); |
67 | |
|
68 | 0 | RemotableQuickFinder.Builder quickFinderBuilder = |
69 | |
RemotableQuickFinder.Builder.create(baseLookupUrl, campusBoClassName); |
70 | |
|
71 | 0 | quickFinderBuilder.setLookupParameters(Collections.singletonMap("Campus", "code")); |
72 | 0 | quickFinderBuilder.setFieldConversions(Collections.singletonMap("code","Campus")); |
73 | |
|
74 | 0 | RemotableTextInput.Builder controlBuilder = RemotableTextInput.Builder.create(); |
75 | 0 | controlBuilder.setSize(30); |
76 | 0 | controlBuilder = RemotableTextInput.Builder.create(); |
77 | 0 | controlBuilder.setSize(Integer.valueOf(40)); |
78 | 0 | controlBuilder.setWatermark("campus code"); |
79 | |
|
80 | 0 | RemotableAttributeLookupSettings.Builder lookupSettingsBuilder = RemotableAttributeLookupSettings.Builder.create(); |
81 | 0 | lookupSettingsBuilder.setCaseSensitive(Boolean.TRUE); |
82 | 0 | lookupSettingsBuilder.setInCriteria(true); |
83 | 0 | lookupSettingsBuilder.setInResults(true); |
84 | 0 | lookupSettingsBuilder.setRanged(false); |
85 | |
|
86 | 0 | RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(CAMPUS_FIELD_NAME); |
87 | 0 | builder.setAttributeLookupSettings(lookupSettingsBuilder); |
88 | 0 | builder.setRequired(true); |
89 | 0 | builder.setDataType(DataType.STRING); |
90 | 0 | builder.setControl(controlBuilder); |
91 | 0 | builder.setLongLabel("Campus"); |
92 | 0 | builder.setShortLabel("Campus"); |
93 | 0 | builder.setMinLength(Integer.valueOf(1)); |
94 | 0 | builder.setMaxLength(Integer.valueOf(40)); |
95 | 0 | builder.setWidgets(Collections.<RemotableAbstractWidget.Builder>singletonList(quickFinderBuilder)); |
96 | |
|
97 | 0 | return builder.build(); |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
public List<RemotableAttributeError> validateAttributes(@WebParam(name = "krmsTypeId") String krmsTypeId, |
102 | |
@WebParam(name = "attributes") @XmlJavaTypeAdapter( |
103 | |
value = MapStringStringAdapter.class) Map<String, String> attributes) throws RiceIllegalArgumentException { |
104 | |
|
105 | 0 | List<RemotableAttributeError> errors = new ArrayList<RemotableAttributeError>(super.validateAttributes(krmsTypeId, attributes)); |
106 | |
|
107 | 0 | RemotableAttributeError.Builder campusErrorBuilder = RemotableAttributeError.Builder.create(CAMPUS_FIELD_NAME); |
108 | |
|
109 | 0 | String campusValue = attributes.get(CAMPUS_FIELD_NAME); |
110 | |
|
111 | 0 | if (StringUtils.isEmpty(campusValue)) { |
112 | 0 | campusErrorBuilder.addErrors("error.agenda.invalidAttributeValue"); |
113 | |
} else { |
114 | 0 | Campus campus = LocationApiServiceLocator.getCampusService().getCampus(campusValue); |
115 | |
|
116 | 0 | if (campus == null) { |
117 | 0 | campusErrorBuilder.addErrors("error.agenda.invalidAttributeValue"); |
118 | |
} |
119 | |
} |
120 | |
|
121 | 0 | if (campusErrorBuilder.getErrors().size() > 0) { |
122 | 0 | errors.add(campusErrorBuilder.build()); |
123 | |
} |
124 | |
|
125 | 0 | return errors; |
126 | |
} |
127 | |
} |