001 /** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krms.impl.ui; 017 018 import org.apache.commons.collections.CollectionUtils; 019 import org.kuali.rice.core.api.uif.DataType; 020 import org.kuali.rice.core.api.uif.RemotableAttributeField; 021 import org.kuali.rice.core.api.uif.RemotableTextInput; 022 import org.kuali.rice.krad.maintenance.MaintenanceDocument; 023 import org.kuali.rice.krad.maintenance.MaintainableImpl; 024 import org.kuali.rice.krad.service.BusinessObjectService; 025 import org.kuali.rice.krad.service.KRADServiceLocator; 026 import org.kuali.rice.krad.uif.container.CollectionGroup; 027 import org.kuali.rice.krad.uif.container.Container; 028 import org.kuali.rice.krad.uif.view.View; 029 import org.kuali.rice.krad.util.KRADConstants; 030 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm; 031 import org.kuali.rice.krms.impl.repository.TermBo; 032 import org.kuali.rice.krms.impl.repository.TermResolverBo; 033 import org.kuali.rice.krms.impl.repository.TermResolverParameterSpecificationBo; 034 035 import java.util.ArrayList; 036 import java.util.Collection; 037 import java.util.Collections; 038 import java.util.Comparator; 039 import java.util.List; 040 import java.util.Map; 041 042 /** 043 * {@link org.kuali.rice.krad.maintenance.Maintainable} for the {@link org.kuali.rice.krms.impl.ui.AgendaEditor} 044 * 045 * @author Kuali Rice Team (rice.collab@kuali.org) 046 * 047 */ 048 public class TermMaintainable extends MaintainableImpl { 049 050 private static final long serialVersionUID = 1L; 051 052 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TermMaintainable.class); 053 054 /** 055 * @return the boService 056 */ 057 public BusinessObjectService getBoService() { 058 return KRADServiceLocator.getBusinessObjectService(); 059 } 060 061 062 063 public List<RemotableAttributeField> retrieveCustomAttributes(View view, Object model, Container container) { 064 065 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>(); 066 067 String termSpecId = ((TermBo)((MaintenanceDocumentForm)model).getDocument().getNewMaintainableObject().getDataObject()).getSpecificationId(); 068 069 Collection<TermResolverBo> termResolvers = getBoService().findMatching(TermResolverBo.class, 070 Collections.singletonMap("outputId", termSpecId) 071 ); 072 073 TermResolverBo termResolver = null; 074 075 if (termResolvers != null && termResolvers.size() == 1) { 076 termResolver = termResolvers.iterator().next(); 077 } 078 079 if (termResolver != null && !CollectionUtils.isEmpty(termResolver.getParameterSpecifications())) { 080 List<TermResolverParameterSpecificationBo> params = new ArrayList<TermResolverParameterSpecificationBo>(termResolver.getParameterSpecifications()); 081 082 Collections.sort(params, new Comparator<TermResolverParameterSpecificationBo>() { 083 @Override 084 public int compare(TermResolverParameterSpecificationBo o1, TermResolverParameterSpecificationBo o2) { 085 return o1.getName().compareTo(o2.getName()); 086 } 087 }); 088 089 for (TermResolverParameterSpecificationBo param : params) { 090 RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(param.getName()); 091 RemotableTextInput.Builder inputBuilder = RemotableTextInput.Builder.create(); 092 inputBuilder.setSize(80); 093 builder.setControl(inputBuilder); 094 builder.setDataType(DataType.STRING); 095 builder.setLongLabel(param.getName()); 096 builder.setShortLabel(param.getName()); 097 098 results.add(builder.build()); 099 } 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 }