View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.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.rice.krms.impl.ui;
17  
18  import org.apache.commons.collections.CollectionUtils;
19  import org.kuali.rice.core.api.uif.DataType;
20  import org.kuali.rice.core.api.uif.RemotableAttributeField;
21  import org.kuali.rice.core.api.uif.RemotableTextInput;
22  import org.kuali.rice.krad.document.MaintenanceDocument;
23  import org.kuali.rice.krad.maintenance.MaintainableImpl;
24  import org.kuali.rice.krad.service.BusinessObjectService;
25  import org.kuali.rice.krad.service.KRADServiceLocator;
26  import org.kuali.rice.krad.uif.container.CollectionGroup;
27  import org.kuali.rice.krad.uif.container.Container;
28  import org.kuali.rice.krad.uif.view.View;
29  import org.kuali.rice.krad.web.form.MaintenanceForm;
30  import org.kuali.rice.krms.impl.repository.ActionBo;
31  import org.kuali.rice.krms.impl.repository.CategoryBo;
32  import org.kuali.rice.krms.impl.repository.TermBo;
33  import org.kuali.rice.krms.impl.repository.TermResolverBo;
34  import org.kuali.rice.krms.impl.repository.TermResolverParameterSpecificationBo;
35  
36  import java.util.ArrayList;
37  import java.util.Collection;
38  import java.util.Collections;
39  import java.util.Comparator;
40  import java.util.List;
41  import java.util.Map;
42  
43  /**
44   * {@link org.kuali.rice.krad.maintenance.Maintainable} for the {@link org.kuali.rice.krms.impl.ui.AgendaEditor}
45   *
46   * @author Kuali Rice Team (rice.collab@kuali.org)
47   *
48   */
49  public class TermMaintainable extends MaintainableImpl {
50  	
51  	private static final long serialVersionUID = 1L;
52  
53      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TermMaintainable.class);
54  
55  	/**
56  	 * @return the boService
57  	 */
58  	public BusinessObjectService getBoService() {
59  		return KRADServiceLocator.getBusinessObjectService();
60  	}
61  
62  
63  
64      public List<RemotableAttributeField> retrieveCustomAttributes(View view, Object model, Container container) {
65  
66          List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
67  
68          String termSpecId = ((TermBo)((MaintenanceForm)model).getDocument().getNewMaintainableObject().getDataObject()).getSpecificationId();
69  
70          Collection<TermResolverBo> termResolvers = getBoService().findMatching(TermResolverBo.class,
71                  Collections.singletonMap("outputId", termSpecId)
72          );
73  
74          TermResolverBo termResolver = null;
75  
76          if (termResolvers != null && termResolvers.size() == 1) {
77              termResolver = termResolvers.iterator().next();
78          }
79  
80          if (termResolver != null && !CollectionUtils.isEmpty(termResolver.getParameterSpecifications())) {
81              List<TermResolverParameterSpecificationBo> params = new ArrayList<TermResolverParameterSpecificationBo>(termResolver.getParameterSpecifications());
82  
83              Collections.sort(params, new Comparator<TermResolverParameterSpecificationBo>() {
84                  @Override
85                  public int compare(TermResolverParameterSpecificationBo o1, TermResolverParameterSpecificationBo o2) {
86                      return o1.getName().compareTo(o2.getName());
87                  }
88              });
89  
90              for (TermResolverParameterSpecificationBo param : params) {
91                  RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(param.getName());
92                  RemotableTextInput.Builder inputBuilder = RemotableTextInput.Builder.create();
93                  inputBuilder.setSize(80);
94                  builder.setControl(inputBuilder);
95                  builder.setDataType(DataType.STRING);
96                  builder.setLongLabel(param.getName());
97                  builder.setShortLabel(param.getName());
98  
99                  results.add(builder.build());
100             }
101         }
102 
103         return results;
104     }
105 
106 //    private AgendaTypeService getAgendaTypeService(String krmsTypeId) {
107 //        //
108 //        // Get the AgendaTypeService by hook or by crook
109 //        //
110 //
111 //        KrmsTypeDefinition krmsType =
112 //                    KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().
113 //                            getTypeById(krmsTypeId);
114 //
115 //        AgendaTypeService agendaTypeService = null;
116 //
117 //        if (!StringUtils.isBlank(krmsTypeId)) {
118 //            String serviceName = krmsType.getServiceName();
119 //
120 //            if (!StringUtils.isBlank(serviceName)) {
121 //                agendaTypeService = KrmsRepositoryServiceLocator.getService(serviceName);
122 //            }
123 //        }
124 //
125 //        if (agendaTypeService == null) { agendaTypeService = AgendaTypeServiceBase.defaultAgendaTypeService; }
126 //
127 //        return agendaTypeService;
128 //    }
129 
130     @Override
131     public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
132 
133         TermBo termBo = (TermBo)document.getNewMaintainableObject().getDataObject();
134         termBo.exportToParametersMap();
135 
136         return super.retrieveObjectForEditOrCopy(document,
137                 dataObjectKeys);    //To change body of overridden methods use File | Settings | File Templates.
138     }
139 
140     /**
141 	 * {@inheritDoc}
142 	 */
143 	@Override
144 	public void processAfterNew(MaintenanceDocument document,
145 		Map<String, String[]> requestParameters) {
146 
147 		super.processAfterNew(document, requestParameters);
148         document.getDocumentHeader().setDocumentDescription("New Term Document");
149 
150 	}
151 
152     @Override
153     public void saveDataObject() {
154         TermBo term = (TermBo) getDataObject();
155         term.importFromParametersMap();
156 
157         super.saveDataObject();    //To change body of overridden methods use File | Settings | File Templates.
158     }
159 
160     @Override
161     public Class getDataObjectClass() {
162         return TermBo.class;
163     }
164 
165     @Override
166     protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
167         super.processBeforeAddLine(view, collectionGroup, model, addLine);
168     }
169 
170 
171 }