View Javadoc
1   /*
2    * Copyright 2010 The Regents of the University of California.
3    */
4   package org.kuali.ole.sys.web.dddumper;
5   
6   import java.util.ArrayList;
7   import java.util.Collections;
8   import java.util.Comparator;
9   import java.util.HashSet;
10  import java.util.List;
11  
12  import javax.servlet.http.HttpServletRequest;
13  import javax.servlet.http.HttpServletResponse;
14  
15  import org.apache.log4j.Logger;
16  import org.apache.struts.action.ActionForm;
17  import org.apache.struts.action.ActionForward;
18  import org.apache.struts.action.ActionMapping;
19  import org.kuali.ole.sys.context.SpringContext;
20  import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
21  import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry;
22  import org.kuali.rice.kns.service.DataDictionaryService;
23  import org.kuali.rice.kns.web.struts.action.KualiAction;
24  import org.kuali.rice.krad.datadictionary.DocumentEntry;
25  
26  public class DataDictionaryDumperAction extends KualiAction {
27      private static final Logger LOG = Logger.getLogger(DataDictionaryDumperAction.class);
28  
29      protected static DataDictionaryService dataDictionaryService;
30      protected static List<DocumentEntry> documentEntries;
31      protected static List<BusinessObjectEntry> businessObjectEntries;
32  
33      @Override
34      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
35  		DataDictionaryDumperForm dumperForm = (DataDictionaryDumperForm)form;
36  		dumperForm.setDocumentEntries(getDocumentEntries());
37  		dumperForm.setBusinessObjectEntries(getBusinessObjectEntries());
38          return mapping.findForward("basic");
39  	}
40  
41      public DataDictionaryService getDataDictionaryService() {
42          if (dataDictionaryService == null) {
43              dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
44          }
45          return dataDictionaryService;
46      }
47  
48      public List<DocumentEntry> getDocumentEntries() {
49          if ( documentEntries == null ) {
50              List<DocumentEntry> temp =  new ArrayList<DocumentEntry>( new HashSet<DocumentEntry>( getDataDictionaryService().getDataDictionary().getDocumentEntries().values() ) );
51              Collections.sort(temp, new Comparator<DocumentEntry>() {
52                  @Override
53                  public int compare(DocumentEntry o1, DocumentEntry o2) {
54                      if ( o1 instanceof MaintenanceDocumentEntry && o2 instanceof MaintenanceDocumentEntry ) {
55                          return ((MaintenanceDocumentEntry)o1).getBusinessObjectClass().getName().compareTo( ((MaintenanceDocumentEntry)o2).getBusinessObjectClass().getName() );
56                      } else if ( o1 instanceof MaintenanceDocumentEntry && !(o2 instanceof MaintenanceDocumentEntry) ) {
57                          return -1;
58                      } else if ( !(o1 instanceof MaintenanceDocumentEntry) && o2 instanceof MaintenanceDocumentEntry ) {
59                          return 1;
60                      }
61                      return o1.getDocumentClass().getName().compareTo(o2.getDocumentClass().getName());
62                  }
63              });
64              documentEntries = temp;
65          }
66          return documentEntries;
67      }
68  
69      public List<BusinessObjectEntry> getBusinessObjectEntries() {
70          List<BusinessObjectEntry> temp =  new ArrayList<BusinessObjectEntry>( new HashSet( getDataDictionaryService().getDataDictionary().getBusinessObjectEntries().values() ) );
71          Collections.sort(temp, new Comparator<BusinessObjectEntry>() {
72              @Override
73              public int compare(BusinessObjectEntry o1, BusinessObjectEntry o2) {
74                  return o1.getObjectLabel().compareTo(o2.getObjectLabel());
75              }
76          });
77          businessObjectEntries = temp;
78          return businessObjectEntries;
79      }
80  
81  }