Coverage Report - org.kuali.rice.krms.impl.ui.TermSpecificationMaintainable
 
Classes in this File Line Coverage Branch Coverage Complexity
TermSpecificationMaintainable
0%
0/27
0%
0/10
1.833
 
 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.ContextBo;
 31  
 import org.kuali.rice.krms.impl.repository.ContextValidTermBo;
 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  
 import org.kuali.rice.krms.impl.repository.TermSpecificationBo;
 36  
 
 37  
 import java.util.ArrayList;
 38  
 import java.util.Collection;
 39  
 import java.util.Collections;
 40  
 import java.util.Comparator;
 41  
 import java.util.List;
 42  
 import java.util.Map;
 43  
 
 44  
 /**
 45  
  * {@link org.kuali.rice.krad.maintenance.Maintainable} for the {@link AgendaEditor}
 46  
  *
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  *
 49  
  */
 50  0
 public class TermSpecificationMaintainable extends MaintainableImpl {
 51  
         
 52  
         private static final long serialVersionUID = 1L;
 53  
 
 54  0
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TermSpecificationMaintainable.class);
 55  
 
 56  
         /**
 57  
          * @return the boService
 58  
          */
 59  
         public BusinessObjectService getBoService() {
 60  0
                 return KRADServiceLocator.getBusinessObjectService();
 61  
         }
 62  
 
 63  
     @Override
 64  
     public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
 65  
 
 66  0
         TermSpecificationBo termSpecificationBo = (TermSpecificationBo) super.retrieveObjectForEditOrCopy(document,
 67  
                 dataObjectKeys);
 68  
 
 69  
         // find contexts for this term spec
 70  0
         Collection<ContextValidTermBo> validContextMappings =
 71  
                 getBoService().findMatching(ContextValidTermBo.class,
 72  
                         Collections.singletonMap("termSpecificationId", termSpecificationBo.getId()));
 73  
 
 74  0
         if (!CollectionUtils.isEmpty(validContextMappings)) for (ContextValidTermBo validContextMapping : validContextMappings) {
 75  0
             ContextBo context = getBoService().findBySinglePrimaryKey(ContextBo.class, validContextMapping.getContextId());
 76  0
             termSpecificationBo.getContexts().add(context);
 77  0
         }
 78  
 
 79  0
         return termSpecificationBo;
 80  
     }
 81  
 
 82  
     /**
 83  
          * {@inheritDoc}
 84  
          */
 85  
         @Override
 86  
         public void processAfterNew(MaintenanceDocument document,
 87  
                 Map<String, String[]> requestParameters) {
 88  
 
 89  0
                 super.processAfterNew(document, requestParameters);
 90  0
         document.getDocumentHeader().setDocumentDescription("New Term Specification Document");
 91  
 
 92  0
         }
 93  
 
 94  
     @Override
 95  
     public void saveDataObject() {
 96  0
         TermSpecificationBo termSpec = (TermSpecificationBo) getDataObject();
 97  
 
 98  0
         super.saveDataObject();    // save it, it should get an id assigned
 99  
 
 100  0
         if (termSpec.getId() != null) {
 101  
             // clear all context valid term mappings
 102  0
             getBoService().deleteMatching(ContextValidTermBo.class,
 103  
                     Collections.singletonMap("termSpecificationId", termSpec.getId()));
 104  
 
 105  
             // add a new mapping for each context in the collection
 106  0
             if (!CollectionUtils.isEmpty(termSpec.getContexts())) for (ContextBo context : termSpec.getContexts()) {
 107  0
                 ContextValidTermBo contextValidTerm = new ContextValidTermBo();
 108  0
                 contextValidTerm.setContextId(context.getId());
 109  0
                 contextValidTerm.setTermSpecificationId(termSpec.getId());
 110  0
                 getBoService().save(contextValidTerm);
 111  0
             }
 112  
         }
 113  
 
 114  0
     }
 115  
 
 116  
     @Override
 117  
     public Class getDataObjectClass() {
 118  0
         return TermSpecificationBo.class;
 119  
     }
 120  
 
 121  
     @Override
 122  
     protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
 123  0
         super.processBeforeAddLine(view, collectionGroup, model, addLine);
 124  0
     }
 125  
 
 126  
 
 127  
 }