001/** 002 * Copyright 2005-2018 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 */ 016package org.kuali.rice.krad.workflow; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; 020import org.kuali.rice.core.api.uif.RemotableAttributeError; 021import org.kuali.rice.core.api.uif.RemotableAttributeField; 022import org.kuali.rice.core.api.uif.RemotableTextInput; 023import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter; 024import org.kuali.rice.kew.api.KEWPropertyConstants; 025import org.kuali.rice.kew.api.KewApiServiceLocator; 026import org.kuali.rice.kew.api.document.Document; 027import org.kuali.rice.kew.api.document.DocumentContent; 028import org.kuali.rice.kew.api.repository.type.KewAttributeDefinition; 029import org.kuali.rice.kew.api.repository.type.KewTypeAttribute; 030import org.kuali.rice.kew.api.repository.type.KewTypeDefinition; 031import org.kuali.rice.kew.framework.peopleflow.PeopleFlowTypeService; 032import org.kuali.rice.krad.service.DataDictionaryRemoteFieldService; 033import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 034import org.kuali.rice.krad.util.BeanPropertyComparator; 035 036import javax.jws.WebParam; 037import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 038 039import java.util.ArrayList; 040import java.util.Collections; 041import java.util.HashMap; 042import java.util.List; 043import java.util.Map; 044 045/** 046 * @author Kuali Rice Team (rice.collab@kuali.org) 047 */ 048public class DataDictionaryPeopleFlowTypeServiceImpl implements PeopleFlowTypeService { 049 050 /** 051 * {@inheritDoc} 052 */ 053 @Override 054 public List<String> filterToSelectableRoleIds(@WebParam(name = "kewTypeId") String kewTypeId, 055 @WebParam(name = "roleIds") List<String> roleIds) { 056 return roleIds; 057 } 058 059 /** 060 * {@inheritDoc} 061 */ 062 @Override 063 public Map<String, String> resolveRoleQualifiers(@WebParam(name = "kewTypeId") String kewTypeId, 064 @WebParam(name = "roleId") String roleId, @WebParam(name = "document") Document document, 065 @WebParam(name = "documentContent") DocumentContent documentContent) { 066 return new HashMap<String, String>(); 067 } 068 069 /** 070 * Allows for more than one set of qualifiers to be returned for the purpose of matching. 071 * 072 * @param kewTypeId the people flow type identifier. Must not be null or blank. 073 * @param roleId the role that the qualifiers are specific to. Must not be null or blank. 074 * @param document the document that the qualifiers are being resolved against. Must not be null. 075 * @param documentContent the contents for the document that the qualifiers are being resolved against. 076 * Must not be null. 077 * @return List<Map<String, String>> 078 */ 079 @Override 080 public List<Map<String, String>> resolveMultipleRoleQualifiers( 081 @WebParam(name = "kewTypeId") String kewTypeId, 082 @WebParam(name = "roleId") String roleId, 083 @WebParam(name = "document") Document document, 084 @WebParam(name = "documentContent") DocumentContent documentContent) { 085 086 return new ArrayList<Map<String, String>>(); 087 } 088 089 /** 090 * @see org.kuali.rice.kew.framework.peopleflow.PeopleFlowTypeService#getAttributeFields(java.lang.String) 091 */ 092 public List<RemotableAttributeField> getAttributeFields(@WebParam(name = "kewTypeId") String kewTypeId) { 093 List<RemotableAttributeField> fields = new ArrayList<RemotableAttributeField>(); 094 095 KewTypeDefinition typeDefinition = KewApiServiceLocator.getKewTypeRepositoryService().getTypeById(kewTypeId); 096 List<KewTypeAttribute> typeAttributes = new ArrayList<KewTypeAttribute>(typeDefinition.getAttributes()); 097 098 // sort type attributes by sort code 099 List<String> sortAttributes = new ArrayList<String>(); 100 sortAttributes.add(KEWPropertyConstants.SEQUENCE_NUMBER); 101 Collections.sort(typeAttributes, new BeanPropertyComparator(sortAttributes)); 102 103 // build a remotable field for each active type attribute 104 for (KewTypeAttribute typeAttribute : typeAttributes) { 105 if (!typeAttribute.isActive()) { 106 continue; 107 } 108 109 RemotableAttributeField attributeField = null; 110 if (StringUtils.isBlank(typeAttribute.getAttributeDefinition().getComponentName())) { 111 attributeField = buildRemotableFieldWithoutDataDictionary(typeAttribute.getAttributeDefinition()); 112 } else { 113 attributeField = getDataDictionaryRemoteFieldService().buildRemotableFieldFromAttributeDefinition( 114 typeAttribute.getAttributeDefinition().getComponentName(), 115 typeAttribute.getAttributeDefinition().getName()); 116 } 117 118 fields.add(attributeField); 119 } 120 121 return fields; 122 } 123 124 /** 125 * Builds a {@link RemotableAttributeField} instance when there is no component configured (and therefore we can 126 * not lookup the data dictionary) 127 * 128 * <p> 129 * Very basic field, should have labels configured and defaults to using text control 130 * </p> 131 * 132 * @param attributeDefinition - KEW attribute definition configured from which the name, label, and description 133 * will be pulled 134 * @return RemotableAttributeField instance built from the given KEW attribute definition 135 */ 136 protected RemotableAttributeField buildRemotableFieldWithoutDataDictionary( 137 KewAttributeDefinition attributeDefinition) { 138 RemotableAttributeField.Builder definition = RemotableAttributeField.Builder.create( 139 attributeDefinition.getName()); 140 141 definition.setLongLabel(attributeDefinition.getLabel()); 142 definition.setShortLabel(attributeDefinition.getLabel()); 143 definition.setHelpDescription(attributeDefinition.getDescription()); 144 145 // default control to text 146 RemotableTextInput.Builder controlBuilder = RemotableTextInput.Builder.create(); 147 controlBuilder.setSize(30); 148 definition.setControl(controlBuilder); 149 150 return definition.build(); 151 } 152 153 /** 154 * {@inheritDoc} 155 */ 156 @Override 157 public List<RemotableAttributeError> validateAttributes(@WebParam(name = "kewTypeId") String kewTypeId, 158 @WebParam(name = "attributes") @XmlJavaTypeAdapter( 159 value = MapStringStringAdapter.class) Map<String, String> attributes) throws RiceIllegalArgumentException { 160 return null; 161 } 162 163 /** 164 * {@inheritDoc} 165 */ 166 @Override 167 public List<RemotableAttributeError> validateAttributesAgainstExisting( 168 @WebParam(name = "kewTypeId") String kewTypeId, @WebParam(name = "newAttributes") @XmlJavaTypeAdapter( 169 value = MapStringStringAdapter.class) Map<String, String> newAttributes, 170 @WebParam(name = "oldAttributes") @XmlJavaTypeAdapter( 171 value = MapStringStringAdapter.class) Map<String, String> oldAttributes) throws RiceIllegalArgumentException { 172 return null; 173 } 174 175 public DataDictionaryRemoteFieldService getDataDictionaryRemoteFieldService() { 176 return KRADServiceLocatorWeb.getDataDictionaryRemoteFieldService(); 177 } 178}