LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  November 2014

HPS-SVN November 2014

Subject:

r1507 - in /java/trunk/conditions/src/main/java/org/hps/conditions/cli: AddCommand.java CommandLineTool.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Thu, 13 Nov 2014 19:52:04 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (137 lines)

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;
     }
 

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use