1 package org.kuali.coeus.dc; 2 3 public class CliOptions { 4 5 private String[] args; 6 7 public CliOptions(String[] args) { 8 this.args = args; 9 } 10 11 public boolean isValid() { 12 boolean valid = args != null && args.length > 0; 13 if (valid && (containsHelp() || containsVersion())) { 14 return true; 15 } 16 17 if (valid && (containsValidate() && !"".equals(getCoeusConnectionString()) && !"".equals(getRiceConnectionString()))) { 18 return true; 19 } 20 21 if (valid && (containsProposalPersonRole() && !"".equals(getCoeusConnectionString()) && !"".equals(getRiceConnectionString()))) { 22 return true; 23 } 24 25 if (valid && (containsProposal() && !"".equals(getCoeusConnectionString()) && !"".equals(getRiceConnectionString()))) { 26 return true; 27 } 28 29 if (valid && (containsIrb() && !"".equals(getCoeusConnectionString()) && !"".equals(getRiceConnectionString()))) { 30 return true; 31 } 32 33 if (valid && (containsIacuc() && !"".equals(getCoeusConnectionString()) && !"".equals(getRiceConnectionString()))) { 34 return true; 35 } 36 37 if (valid && (inactivateCleanupPolicy() || deleteCleanupPolicy())) { 38 return true; 39 } 40 41 return false; 42 } 43 44 public boolean containsHelp() { 45 return contains("-help"); 46 } 47 48 public boolean containsVersion() { 49 return contains("-version"); 50 } 51 52 public boolean containsDebug() { 53 return contains("-debug"); 54 } 55 56 public boolean containsDryRun() { 57 return contains("-dryrun"); 58 } 59 60 public boolean containsValidate() { 61 return contains("-validate"); 62 } 63 64 public boolean containsProposalPersonRole() { 65 return contains("pprole"); 66 } 67 68 public boolean containsProposal() { 69 return contains("proposal"); 70 } 71 72 public boolean containsIrb() { 73 return contains("irb"); 74 } 75 76 public boolean containsIacuc() { 77 return contains("iacuc"); 78 } 79 80 private boolean contains(String name) { 81 for (String arg : args) { 82 if (name.equals(arg)) { 83 return true; 84 } 85 } 86 return false; 87 } 88 89 private String nextArg(String name) { 90 boolean returnNext = false; 91 for (String arg : args) { 92 if (returnNext) { 93 return arg; 94 } 95 96 if (name.equals(arg)) { 97 returnNext = true; 98 } 99 } 100 return ""; 101 } 102 103 public String getCoeusConnectionString() { 104 if (contains("-dbcoeuscon")) { 105 return nextArg("-dbcoeuscon"); 106 } 107 return ""; 108 } 109 110 public String getRiceConnectionString() { 111 if (contains("-dbricecon")) { 112 return nextArg("-dbricecon"); 113 } 114 return ""; 115 } 116 117 public String getCoeusUser() { 118 if (contains("-dbcoeususer")) { 119 return nextArg("-dbcoeususer"); 120 } 121 return ""; 122 } 123 public String getCoeusPassword() { 124 if (contains("-dbcoeuspwd")) { 125 return nextArg("-dbcoeuspwd"); 126 } 127 return ""; 128 } 129 public String getRiceUser() { 130 if (contains("-dbriceuser")) { 131 return nextArg("-dbriceuser"); 132 } 133 return ""; 134 } 135 public String getRicePassword() { 136 if (contains("-dbricepwd")) { 137 return nextArg("-dbricepwd"); 138 } 139 return ""; 140 } 141 public String getCleanupPolicy() { 142 if (contains("-cleanup")) { 143 return nextArg("-cleanup"); 144 } 145 return "inactivate"; 146 } 147 148 public boolean deleteCleanupPolicy() { 149 return getCleanupPolicy().equals("delete"); 150 } 151 152 public boolean inactivateCleanupPolicy() { 153 return getCleanupPolicy().equals("inactivate"); 154 } 155 156 public boolean isMySql() { 157 if (contains("-platform") && "MySql".equalsIgnoreCase(nextArg("-platform"))) { 158 return true; 159 } else if (contains("-dbricecon") && nextArg("-dbricecon").startsWith("jdbc:mysql")) { 160 return true; 161 } else if (contains("-dbcoeuscon") && nextArg("-dbcoeuscon").startsWith("jdbc:mysql")) { 162 return true; 163 } 164 165 return false; 166 } 167 168 public boolean isOracle() { 169 if (contains("-platform") && "Oracle".equalsIgnoreCase(nextArg("-platform"))) { 170 return true; 171 } else if (contains("-dbricecon") && nextArg("-dbricecon").startsWith("jdbc:oracle")) { 172 return true; 173 } else if (contains("-dbcoeuscon") && nextArg("-dbcoeuscon").startsWith("jdbc:oracle")) { 174 return true; 175 } 176 177 return false; 178 } 179 180 public String getCliHelpString() { 181 return "coeus-data-conv [options] [conv_target [conv_target2 [conv_target3] ...]]\n" 182 + " Options:\n" 183 + " -help print this message\n" 184 + " -version print the version information and exit\n" 185 + " -dryrun executes conversion without writing out to the database\n" 186 + " -validate validates database connections only\n" 187 + " -debug print debugging information\n" 188 + " -cleanup <policy> the policy used for data cleanup (delete|inactivate)\n" 189 + " -dbplatform <platform> the database platform (MySql|Oracle)\n" 190 + " -dbricecon <connection> the kuali rice jdbc database connection string (jdbc:mysql://localhost/rice?user=usr&password=pwd)\n" 191 + " -dbcoeuscon <connection> the kuali coeus jdbc database connection string (jdbc:mysql://localhost/coeus?user=usr&password=pwd)\n" 192 + " -dbriceuser <ricedbuser> the kuali rice database user\n" 193 + " -dbricepwd <ricerbpassword> the kuali rice database password\n" 194 + " -dbcoeususer <coeususer> the kuali coeus database user\n" 195 + " -dbcoeuspwd <coeuspassword> the kuali coeus database password\n" 196 + "\n" 197 + "If platform is not specified then the platform will be autodetected from the connection strings.\n" 198 + "\n" 199 + "The valid conversion targets are (proposal|irb|iacuc|pprole).\n" 200 + "\n" 201 + "The dryrun flag may still cause database sequences to increment.\n" 202 + "\n" 203 + "The cleanup flag when choosing inactivate will attempt to set the active flag to false when possible. This is the default. "; 204 } 205 206 }