View Javadoc
1   /**
2    * Copyright 2005-2014 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.criteria.QueryByCriteria;
20  import org.kuali.rice.core.api.criteria.QueryResults;
21  import org.kuali.rice.core.api.data.DataType;
22  import org.kuali.rice.core.api.uif.RemotableAttributeField;
23  import org.kuali.rice.core.api.uif.RemotableTextInput;
24  import org.kuali.rice.krad.maintenance.MaintainableImpl;
25  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
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.uif.view.ViewModel;
30  import org.kuali.rice.krad.util.KRADConstants;
31  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
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.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      public List<RemotableAttributeField> retrieveCustomAttributes(View view, Object model, Container container) {
56  
57          List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
58          String termSpecId = ((TermBo)((MaintenanceDocumentForm)model).getDocument().getNewMaintainableObject().getDataObject()).getSpecificationId();
59  
60          QueryResults<TermResolverBo> termResolvers = getDataObjectService().findMatching(TermResolverBo.class,
61                  QueryByCriteria.Builder.forAttribute("outputId", termSpecId).build()
62          );
63  
64          TermResolverBo termResolver = null;
65  
66          if (termResolvers.getResults() != null && termResolvers.getResults().size() == 1) {
67              termResolver = termResolvers.getResults().get(0);
68          }
69  
70          if (termResolver != null && !CollectionUtils.isEmpty(termResolver.getParameterSpecifications())) {
71              List<TermResolverParameterSpecificationBo> params = new ArrayList<TermResolverParameterSpecificationBo>(termResolver.getParameterSpecifications());
72  
73              Collections.sort(params, new Comparator<TermResolverParameterSpecificationBo>() {
74                  @Override
75                  public int compare(TermResolverParameterSpecificationBo o1, TermResolverParameterSpecificationBo o2) {
76                      return o1.getName().compareTo(o2.getName());
77                  }
78              });
79  
80              for (TermResolverParameterSpecificationBo param : params) {
81                  RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(param.getName());
82                  RemotableTextInput.Builder inputBuilder = RemotableTextInput.Builder.create();
83                  inputBuilder.setSize(80);
84                  builder.setControl(inputBuilder);
85                  builder.setDataType(DataType.STRING);
86                  builder.setLongLabel(param.getName());
87                  builder.setShortLabel(param.getName());
88  
89                  results.add(builder.build());
90              }
91          }
92  
93          return results;
94      }
95  
96  //    private AgendaTypeService getAgendaTypeService(String krmsTypeId) {
97  //        //
98  //        // Get the AgendaTypeService by hook or by crook
99  //        //
100 //
101 //        KrmsTypeDefinition krmsType =
102 //                    KrmsRepositoryServiceLocator.getKrmsTypeRepositoryService().
103 //                            getTypeById(krmsTypeId);
104 //
105 //        AgendaTypeService agendaTypeService = null;
106 //
107 //        if (!StringUtils.isBlank(krmsTypeId)) {
108 //            String serviceName = krmsType.getServiceName();
109 //
110 //            if (!StringUtils.isBlank(serviceName)) {
111 //                agendaTypeService = KrmsRepositoryServiceLocator.getService(serviceName);
112 //            }
113 //        }
114 //
115 //        if (agendaTypeService == null) { agendaTypeService = AgendaTypeServiceBase.defaultAgendaTypeService; }
116 //
117 //        return agendaTypeService;
118 //    }
119 
120     @Override
121     public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
122 
123         TermBo termBo = (TermBo) super.retrieveObjectForEditOrCopy(document, dataObjectKeys);
124         termBo.exportToParametersMap();
125 
126         if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(getMaintenanceAction())) {
127             document.getDocumentHeader().setDocumentDescription("New Term Document");
128         }
129 
130         return termBo;
131     }
132 
133     /**
134      * {@inheritDoc}
135      */
136     @Override
137     public void processAfterNew(MaintenanceDocument document,
138             Map<String, String[]> requestParameters) {
139 
140         super.processAfterNew(document, requestParameters);
141         document.getDocumentHeader().setDocumentDescription("New Term Document");
142 
143     }
144 
145     /**
146      * {@inheritDoc}
147      */
148     @Override
149     public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
150 
151 
152         super.processAfterEdit(document,
153                 requestParameters);
154 
155         document.getDocumentHeader().setDocumentDescription("Edited Term Document");
156     }
157 
158     @Override
159     public void saveDataObject() {
160         TermBo term = (TermBo) getDataObject();
161         term.importFromParametersMap();
162 
163         super.saveDataObject();    //To change body of overridden methods use File | Settings | File Templates.
164     }
165 
166     @Override
167     public Class getDataObjectClass() {
168         return TermBo.class;
169     }
170 
171     @Override
172     public void processBeforeAddLine(ViewModel model, Object addLine, String collectionId, String collectionPath) {
173         super.processBeforeAddLine(model, addLine, collectionId, collectionPath);
174     }
175 
176 
177 }