View Javadoc
1   package org.kuali.coeus.dc;
2   
3   
4   import org.kuali.coeus.dc.common.db.DbValidatorDaoService;
5   
6   import java.io.BufferedInputStream;
7   import java.io.FileInputStream;
8   import java.io.IOException;
9   import java.io.InputStream;
10  import java.sql.Connection;
11  import java.sql.SQLException;
12  import java.util.Collection;
13  import java.util.logging.LogManager;
14  import java.util.logging.Logger;
15  
16  /**
17   * The main driver program that runs this conversion program.
18   *
19   * Example arguments:
20   *
21   * -debug -dbcoeuscon jdbc:mysql://localhost/kcbnd?user=kcbnd&password=bndpass -dbricecon jdbc:mysql://localhost/kcbnd?user=kcbnd&password=bndpass proposal
22   */
23  public final class Main {
24  
25      private static final Logger LOG = Logger.getLogger(Main.class.getName());
26  
27      public static void main(String[] args) {
28          initLogging("/org/kuali/coeus/dc/jul-default.properties");
29  
30          CliOptions options = new CliOptions(args);
31  
32          if (!options.isValid()) {
33              System.out.println(options.getCliHelpString());
34              return;
35          }
36  
37          if (options.containsDebug()) {
38              initLogging("/org/kuali/coeus/dc/jul-debug.properties");
39          }
40  
41          if (options.containsHelp()) {
42              System.out.println(options.getCliHelpString());
43              return;
44          }
45  
46          if (options.containsVersion()) {
47              System.out.println("6.0-SNAPSHOT");
48              return;
49          }
50  
51          CliOptionsBasedDaoFactory factory = new CliOptionsBasedDaoFactory();
52          factory.setCliOptions(options);
53  
54          if (options.containsValidate()) {
55              DbValidatorDaoService validator = factory.getDbValidatorDaoService();
56  
57              if (validator.isValidCoeusConnection()) {
58                  System.out.println("COEUS SUCCESS: " + options.getCoeusConnectionString());
59              } else {
60                  System.out.println("COEUS FAILED: " + options.getCoeusConnectionString());
61              }
62  
63              if (validator.isValidRiceConnection()) {
64                  System.out.println("RICE SUCCESS: " + options.getRiceConnectionString());
65              } else {
66                  System.out.println("RICE FAILED: " + options.getRiceConnectionString());
67              }
68              return;
69          }
70  
71  
72          try (Connection coeusConnection = factory.getConnectionDaoService().getCoeusConnection();
73              Connection riceConnection = factory.getConnectionDaoService().getRiceConnection()) {
74  
75              if(options.containsProposalPersonRole()) {
76                  factory.getProposalPersonRoleDao().convertParameterValues();
77              }
78  
79              if (options.containsProposal()) {
80                  Collection<String> roleIds = factory.getProposalRoleDao().getRoleIdsToConvert();
81                  factory.getRoleDao().copyRoleMembersToDocAccessType(roleIds, factory.getProposalKimAttributeDocumentValueHandler());
82              }
83  
84              if (options.containsIrb()) {
85                  System.out.println("IRB Conversion not supported");
86              }
87  
88              if (options.containsIacuc()) {
89                  System.out.println("IACUC Conversion not supported");
90              }
91  
92              if (options.containsDryRun()) {
93                  coeusConnection.rollback();
94                  riceConnection.rollback();
95              } else {
96                  coeusConnection.commit();
97                  riceConnection.commit();
98              }
99          } catch (SQLException e) {
100             throw new RuntimeException(e);
101         }
102     }
103 
104     private static void initLogging(String file) {
105         String fname = System.getProperty("java.util.logging.config.file");
106         if (fname == null) {
107             fname = Main.class.getResource(file).getFile();
108         }
109 
110         try (InputStream in = new FileInputStream(fname); BufferedInputStream bin = new BufferedInputStream(in)) {
111             LogManager.getLogManager().readConfiguration(bin);
112         } catch (IOException e) {
113             throw new RuntimeException(e);
114         }
115     }
116 
117 
118 }