Author: [log in to unmask]
Date: Thu Nov 13 11:52:01 2014
New Revision: 1507
Log:
Add conditions CLI command for registering a conditions set in the conditions table.
Added:
java/trunk/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java
Modified:
java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java
Added: java/trunk/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java (added)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java Thu Nov 13 11:52:01 2014
@@ -0,0 +1,95 @@
+package org.hps.conditions.cli;
+
+import java.util.Date;
+
+import org.hps.conditions.ConditionsObject.FieldValueMap;
+import org.hps.conditions.ConditionsObjectException;
+import org.hps.conditions.ConditionsRecord;
+import org.hps.conditions.DatabaseConditionsManager;
+import org.hps.conditions.TableConstants;
+
+/**
+ * This is a command for the conditions CLI that will add a conditions record,
+ * making a conditions set with a particular collection ID available by
+ * run number via the {@link org.hps.conditions.DatabaseConditionsManager}.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class AddCommand extends AbstractCommand {
+
+ AddCommand() {
+ super("add", "Add a conditions record");
+ options.addOption("r", true, "The starting run number");
+ options.getOption("r").setRequired(true);
+ options.addOption("e", true, "The ending run number");
+ options.addOption("k", true, "The conditions key");
+ options.addOption("t", true, "The table name");
+ options.getOption("t").setRequired(true);
+ options.addOption("T", true, "A tag value");
+ options.addOption("u", true, "Your user name");
+ options.addOption("c", true, "The collection ID");
+ options.getOption("c").setRequired(true);
+ options.addOption("m", true, "The notes");
+ }
+
+ void execute(String[] arguments) {
+ super.execute(arguments);
+
+ int runStart = Integer.parseInt(commandLine.getOptionValue("r"));
+ int runEnd = runStart;
+ if (commandLine.hasOption("e")) {
+ runEnd = Integer.parseInt(commandLine.getOptionValue("e"));
+ }
+
+ String tableName = commandLine.getOptionValue("t");
+ String name = tableName;
+ if (commandLine.hasOption("k")) {
+ name = commandLine.getOptionValue("k");
+ }
+
+ String createdBy = System.getProperty("user.name");
+ if (commandLine.hasOption("u")) {
+ createdBy = commandLine.getOptionValue("u");
+ }
+
+ String tag = null;
+ if (commandLine.hasOption("T")) {
+ tag = commandLine.getOptionValue("T");
+ }
+
+ String notes = null;
+ if (commandLine.hasOption("m")) {
+ notes = commandLine.getOptionValue("m");
+ }
+
+ int collectionId = Integer.parseInt(commandLine.getOptionValue("c"));
+
+ ConditionsRecord conditionsRecord = new ConditionsRecord();
+ try {
+ conditionsRecord.setTableMetaData(DatabaseConditionsManager.getInstance().findTableMetaData(TableConstants.CONDITIONS_RECORD));
+ } catch (ConditionsObjectException e) {
+ throw new RuntimeException("Problem assigning meta data to record.", e);
+ }
+ FieldValueMap fieldValues = new FieldValueMap();
+ fieldValues.put("run_start", runStart);
+ fieldValues.put("run_end", runEnd);
+ fieldValues.put("table_name", tableName);
+ fieldValues.put("name", name);
+ fieldValues.put("collection_id", collectionId);
+ fieldValues.put("created_by", createdBy);
+ if (tag != null) {
+ fieldValues.put("tag", tag);
+ }
+ if (notes != null) {
+ fieldValues.put("notes", notes);
+ }
+ conditionsRecord.setFieldValues(fieldValues);
+ fieldValues.put("created", new Date());
+ try {
+ conditionsRecord.insert();
+ } catch (ConditionsObjectException e) {
+ throw new RuntimeException("An error occurred while adding a conditions record.", e);
+ }
+ }
+
+}
Modified: java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java (original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java Thu Nov 13 11:52:01 2014
@@ -16,9 +16,7 @@
/**
* <p>
* This class is a command-line tool for performing commands on the conditions
- * database. It has sub-commands much like the cvs or svn clients. The only
- * current implemented command is 'load' to import text files, but more will be
- * added.
+ * database. It has sub-commands much like the cvs or svn clients.
* <p>
* Command line options allow a custom connection properties file or XML
* configuration to be supplied by the user which will override the default.
@@ -133,6 +131,7 @@
cli.options.addOption(new Option("x", true, "Set the conditions database XML configuration file"));
cli.registerCommand(new LoadCommand());
cli.registerCommand(new PrintCommand());
+ cli.registerCommand(new AddCommand());
return cli;
}
|