View Javadoc

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