Coverage Report - org.kuali.rice.krms.impl.ui.TermMaintainable
 
Classes in this File Line Coverage Branch Coverage Complexity
TermMaintainable
0%
0/36
0%
0/10
1.625
TermMaintainable$1
0%
0/2
N/A
1.625
 
 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  0
 public class TermMaintainable extends MaintainableImpl {
 50  
         
 51  
         private static final long serialVersionUID = 1L;
 52  
 
 53  0
     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  0
                 return KRADServiceLocator.getBusinessObjectService();
 60  
         }
 61  
 
 62  
 
 63  
 
 64  
     public List<RemotableAttributeField> retrieveCustomAttributes(View view, Object model, Container container) {
 65  
 
 66  0
         List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
 67  
 
 68  0
         String termSpecId = ((TermBo)((MaintenanceForm)model).getDocument().getNewMaintainableObject().getDataObject()).getSpecificationId();
 69  
 
 70  0
         Collection<TermResolverBo> termResolvers = getBoService().findMatching(TermResolverBo.class,
 71  
                 Collections.singletonMap("outputId", termSpecId)
 72  
         );
 73  
 
 74  0
         TermResolverBo termResolver = null;
 75  
 
 76  0
         if (termResolvers != null && termResolvers.size() == 1) {
 77  0
             termResolver = termResolvers.iterator().next();
 78  
         }
 79  
 
 80  0
         if (termResolver != null && !CollectionUtils.isEmpty(termResolver.getParameterSpecifications())) {
 81  0
             List<TermResolverParameterSpecificationBo> params = new ArrayList<TermResolverParameterSpecificationBo>(termResolver.getParameterSpecifications());
 82  
 
 83  0
             Collections.sort(params, new Comparator<TermResolverParameterSpecificationBo>() {
 84  
                 @Override
 85  
                 public int compare(TermResolverParameterSpecificationBo o1, TermResolverParameterSpecificationBo o2) {
 86  0
                     return o1.getName().compareTo(o2.getName());
 87  
                 }
 88  
             });
 89  
 
 90  0
             for (TermResolverParameterSpecificationBo param : params) {
 91  0
                 RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(param.getName());
 92  0
                 RemotableTextInput.Builder inputBuilder = RemotableTextInput.Builder.create();
 93  0
                 inputBuilder.setSize(80);
 94  0
                 builder.setControl(inputBuilder);
 95  0
                 builder.setDataType(DataType.STRING);
 96  0
                 builder.setLongLabel(param.getName());
 97  0
                 builder.setShortLabel(param.getName());
 98  
 
 99  0
                 results.add(builder.build());
 100  0
             }
 101  
         }
 102  
 
 103  0
         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  0
         TermBo termBo = (TermBo)document.getNewMaintainableObject().getDataObject();
 134  0
         termBo.exportToParametersMap();
 135  
 
 136  0
         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  0
                 super.processAfterNew(document, requestParameters);
 148  0
         document.getDocumentHeader().setDocumentDescription("New Term Document");
 149  
 
 150  0
         }
 151  
 
 152  
     @Override
 153  
     public void saveDataObject() {
 154  0
         TermBo term = (TermBo) getDataObject();
 155  0
         term.importFromParametersMap();
 156  
 
 157  0
         super.saveDataObject();    //To change body of overridden methods use File | Settings | File Templates.
 158  0
     }
 159  
 
 160  
     @Override
 161  
     public Class getDataObjectClass() {
 162  0
         return TermBo.class;
 163  
     }
 164  
 
 165  
     @Override
 166  
     protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
 167  0
         super.processBeforeAddLine(view, collectionGroup, model, addLine);
 168  0
     }
 169  
 
 170  
 
 171  
 }