View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may
3    * not use this file except in compliance with the License. You may obtain a copy of the License at
4    * http://www.osedu.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed
5    * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
6    * implied. See the License for the specific language governing permissions and limitations under the License.
7    */
8   
9   package org.kuali.student.lum.workflow.search;
10  
11  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
12  import org.kuali.rice.kew.api.document.DocumentWithContent;
13  import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
14  import org.kuali.rice.kew.api.extension.ExtensionDefinition;
15  import org.kuali.rice.kew.docsearch.SearchableAttributeValue;
16  import org.kuali.rice.kew.doctype.service.impl.DocumentTypeServiceImpl;
17  import org.kuali.rice.krad.workflow.attribute.KualiXmlSearchableAttributeImpl;
18  import org.kuali.student.r2.common.exceptions.*;
19  import org.kuali.student.r2.core.organization.dto.OrgInfo;
20  import org.kuali.student.r2.core.organization.service.OrganizationService;
21  
22  import javax.xml.namespace.QName;
23  import java.util.List;
24  
25  /**
26   * Extension for CluCreditCourse documents searches that converts Organization ID to the Organization Long Name
27   * 
28   * @author lindholm
29   */
30  public class OrgSearchAttribute extends KualiXmlSearchableAttributeImpl {
31      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentTypeServiceImpl.class);
32  
33      private static final long serialVersionUID = 1L;
34  
35      // TODO: RICE=M9 UPGRADE check that replacing getDocumentAttributes with extractDocumentAttributes is really the intended
36      // behavior
37      @SuppressWarnings("unchecked")
38      @Override
39      public List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition, DocumentWithContent documentSearchContext) {
40          OrganizationService orgService = null;
41          List<DocumentAttribute> attributeValues = super.extractDocumentAttributes(extensionDefinition, documentSearchContext);
42          for (DocumentAttribute value : attributeValues) {
43              String orgId = (String) value.getValue();
44              if (orgId != null) {
45                  try {
46                      if (orgService == null) {
47                          orgService = (OrganizationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/organization", "OrganizationService"));
48                      }
49                      OrgInfo orgInfo = orgService.getOrg(orgId, null);
50                      // TODO: RICE-M7 UPGRADE I think this is correct but I'm not sure
51                      ((SearchableAttributeValue) value).setupAttributeValue(orgInfo.getShortName());
52                  } catch (DoesNotExistException e) {
53                      LOG.error(e);
54                      throw new RuntimeException(e);
55                  } catch (InvalidParameterException e) {
56                      LOG.error(e);
57                      throw new RuntimeException(e);
58                  } catch (MissingParameterException e) {
59                      LOG.error(e);
60                      throw new RuntimeException(e);
61                  } catch (OperationFailedException e) {
62                      LOG.error(e);
63                      throw new RuntimeException(e);
64                  } catch (PermissionDeniedException e) {
65                      LOG.error(e);
66                      throw new RuntimeException(e);
67                  }
68              }
69          }
70          return attributeValues;
71      }
72  }