SSDS

SSDS.pm - Access SSDS Metadata


SYNOPSIS

        use SSDS;
        
        my $ssds = new SSDS();
        my $ssds->ssdsServer("http://ssds.shore.mbari.org:8080/";);
        
        my $deplAccess = new SSDS::DeploymentAccess();
        my @deplAttr = (${$depls}[0]->get_attribute_names());
        my $depls = $deplAccess->findByName("CIMT Mooring Deployment");
        foreach my $d (@{$depls}) {
                foreach my $a (@deplAttr) {
                        next unless $depl->$a;
                        print "  $a = " . $depl->$a . "\n";
                }       
        }
                
        Will print out:
        
          id = 2356
          name = CIMT Mooring Deployment
          startDate = Tue May 18 15:30:00 PDT 2004
          role = platform


DESCRIPTION

The SSDS class provides a Perl interface to the SSDS metadata services provided by the SSDS Web Services. Much of the Java interface to the SSDS model and service objects is implemented here. This module was written to make it easy to write external data processing scripts for SSDS data.

The syntax used to derefernce the return values from the Access methods looks a little hairy, but it's really not that bad. If the method is designed to return a single object (such as findByPK()) then the return value will be an object which you may immediatley use to call its attributes. If the method returns multiple objects (such as listOutputs()) then the return value will be a reference to a list of objects, which you must dereference with a '$' or '@' before using it. Plenty of examples are provided in the method descriptions of this document.

$Id: perlSSDSmodule.html,v 1.12 2005/02/19 00:53:29 mccann Exp $

The SSDS package contains these methods which are inherited by all the SSDS objects declared in the other packages.

Base class with private methods

ObjectCreator

ObjectCreator - Contains private support methods to create SSDS objects. The methods below are inherited by all the SSDS objects declared in the child packages.

new()
_buildHash()

Function to parse return of MetadataAccessServlet into a single (key, value) hash list.

Example:

        my ($returnedObject, $oHash) = $obj->_buildHash($obj->delim, $data);
_buildHashes()
Function to parse return of MetadataAccessServlet into a list of (key, value) hashes list.

Example:

        my ($returnedObject, $oHashes) = $obj->_buildHashes($obj->delim, $data);

_createSSDSobject()
Build and return an SSDS object given a URL to a MetadataAccessServlet call. If a second argument is given then that SSDS object will be instantiated rather than the object returned from the MetadataAccessServlet. If the types do not match a warning message will be printed.

Examples:

        # Request and return a Device object
        my $url = $obj->baseUrl . "className=DeviceTypeAccess&methodName=findByPK&param1Type=Long&param1Value=" . $pk;  
        return $obj->_createSSDSobject($url);
        
        # Request a DataStream and return a DataFile object
        my $url = $obj->baseUrl . "className=DataStreamAccess&methodName=findByPK&param1Type=Long&param1Value=" . $pk;  
        return $obj->_createSSDSobject($url, 'DataFile');

_createSSDSobjects()
Build and return a list of SSDS objects given a URL to a MetadataAccessServlet call. If a second argument is given then that SSDS object will be instantiated rather than the object returned from the MetadataAccessServlet. If the types do not match a warning message will be printed.

Examples:

        # Request and return a Deployment 
        my $url = $obj->baseUrl . "className=Deployment&methodName=listChildDeployments&findBy=PK&findByType=String&findByValue=" . $obj->id;
        return $obj->_createSSDSobjects($url);
        
        # Request a DataStream and return a DataFile
        my $url = $obj->baseUrl . "className=Deployment&methodName=listOutputs&findBy=PK&findByType=String&findByValue=" . $obj->id;
        return $obj->_createSSDSobjects($url, 'DataFile');

_execSSDSmethod()
Execute an SSDS access method that does not return an object. Typically this is used for calling insret()s, update()s, and delete()s. Returns 1 if successful, 0 if a Fault is detected or any data is returned from the call.

Example:

        my $url = $obj->baseUrl . "className=DeviceTypeAccess&methodName=insert&param1Type=DeviceType&param1Value=DeviceType";
        $url .= $obj->delim() . "name=" . $dt->name() if $dt->name();
        $url .= $obj->delim() . "description=" . $dt->description() if $dt->description();
        $url .= $obj->delim() . "defaultDeploymentRole=" . $dt->defaultDeploymentRole() if $dt->defaultDeploymentRole(); 
        $url .= $obj->delim() . "displayInDeviceTypesPicklist=" . $dt->displayInDeviceTypesPicklist() if $dt->displayInDeviceTypesPicklist();
        return $obj->_execSSDSmethod($url);

Value and DataAccessObject classes

Deployment

Deployment - An SSDS Deployment object

new()
Instantiate an SSDS::Deployment object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

        id name description startDate endDate role nominalLatitude nominalLongitude 
        nominalDepth xOffset yOffset zOffset x3DOrientationText

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $depl = $deplAccess->findByPK(4322);
        print "NominalLongitude = " . $depl->nominalLongitude . "\n";
        $depl->nominalDepth(20.0);      # Set nominal depth of Deployment to 20 m

childDeployments()
return list of child deployments

Example:

        my $deplAccess = new SSDS::DeploymentAccess();
        my $depl = $deplAccess->findByPK(4309);
        my @deplAttr = ($depl->get_attribute_names());
        my $childDepls = $depl->childDeployments();
        foreach my $cd (@{$childDepls}) {
                foreach my $a (@deplAttr) {
                        next unless $cd->$a;
                        print "  $a = " . $cd->$a . "\n";
                }
                print"\n";
        }

getDevice()
return the Device object for this Deployment

Example:

        my $dev = $id->getDevice($id->id());
        print "Instrument Deployment " . $id->name() . "\n";
        print "  of Device   " . $dev->name() . "\n";

listOutputs()
return list of output DataStreams or DataFiles

Example:

        $outputs = $depl->listOutputs();
        @dfAttr = ${$outputs}[0]->get_attribute_names() if $outputs;
        foreach my $o (@{$outputs}) {
                foreach my $a (@dfAttr) {
                        next unless $o->$a;
                        print "  $a = " . $o->$a . "\n";
                }
                print"\n";
        }

getParentDeployment()
Return parent Deployment

Example:

        my $depl = $deplAccess->findByPK(4322);
        my $parentDepl = $depl->getParentDeployment();
        foreach my $a (@deplAttr) {
                next unless $parentDepl->$a;
                print "  $a = " . $parentDepl->$a . "\n";
        }

getStartEsecs()
Return the Unix Epoch seconds of the start time for this Deployment

Example:

        print "    startDate = " . $depl->startDate() . "\n";
        print "    start epoch seconds = " . $depl->getStartEsecs() . "\n";

getEndEsecs()
Return the Unix Epoch seconds of the end time for this Deployment

Example:

        print "    endDate = " . $depl->endDate() . "\n" if $depl->endDate();
        print "    end epoch seconds = " . $depl->getEndEsecs() . "\n" if $depl->getEndEsecs();

DeploymentAccess

DeploymentAccess - Contains methods to query for and get Deployment objects

new()
Instantiate an SSDS::DeploymentAccess object

Example:

        my $deplAccess = new SSDS::DeploymentAccess();
        $depl = $deplAccess->findByPK(4322);

findByPK(pk)
return the Deployment that has ID = pk.

Example:

        my $deplAccess = new SSDS::DeploymentAccess();
        my $depl = $deplAccess->findByPK(4322);
        print "NominalLongitude = " . $depl->nominalLongitude . "\n";

findByName(name)
return a list of Deployments that match the name.

Example:

        my $deplAccess = new SSDS::DeploymentAccess();
        my @depl = $deplAccess->findByName("CIMT Mooring Deployment");

Device

Device - An SSDS Device object

new()
Instantiate an SSDS::Device object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

   id name description mfgName mfgModel mfgSerialNumber preferredDeploymentRole

Note: the get_attribute_names() method will return this list of attributes

Example:


        my $devAccess = new SSDS::DeviceAccess();
        $dev = $devAccess->findByPK(1319);
        print "mfgModel = " . $dev->mfgModel . "\n";
        $dev->mfgSerialNumber(1234);    # Set manufacturer serial number to 1234

getDeviceType()
DeviceType is a special attribute. It comes from a database lookup table via a DeviceType object.

Example:

        my $devAccess = new SSDS::DeviceAccess();
        $dev = $devAccess->findByPK(1319);
        print "DeviceType name = " . $dev->getDeviceType()->name() . "\n"

DeviceAccess

DeviceAccess - Contains methods to query for and get Device objects

new()
Instantiate an SSDS::DeviceAccess object

Example:


        my $devAccess = new SSDS::DeviceAccess();
        $dev = $devAccess->findByPK(1319);

findByPK(pk)
return the Device with PK = pk

Example:

        my $devAccess = new SSDS::DeviceAccess();
        $dev = $devAccess->findByPK(1319);

findByLikeName(string)
return a list of Deployments where string matches any part of the Deployment name.

Example:

        $devs = $devAccess->findByLikeName("CTD");

DataFile

DataFile - An SSDS DataFile object

new()
Instantiate an SSDS::DataFile object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

    id name description startDate endDate original url contentLength mimeType
    webAccessible dodsAccessible fileName

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $dcAccess = new SSDS::DataFileAccess();
        my $dc = $dcAccess->findByPK(5777);

getRecordDescription()
Return the RecordDescription object for this DataFile

Example:

        my $rd = $dc->getRecordDescription();
        foreach my $a ($rd->get_attribute_names()) {
                next unless $rd->$a;
                print "  $a = " . $rd->$a . "\n";
        }

DataFileAccess

DataFileAccess - Contains methods to query for and get DataFile objects

new()
Instantiate an SSDS::DataFileAccess object

Example:

        my $dcAccess = new SSDS::DataFileAccess();
        my $dc = $dcAccess->findByPK(5777);

findByPK(pk)
return the DataFile with PK = pk

Example:

        my $dcAccess = new SSDS::DataFileAccess();
        my $dc = $dcAccess->findByPK(5777);

findByUrl(string)
Return a list of DataFiles where the url is string.

Example:

        my $dfAccess = new SSDS::DataFileAccess();
        my $df = $dfAccess->findByUrl("http://ssds-test.shore.mbari.org/ssds/rawpackets/1313_0_1_1327";);
        print "isWebAccessible = " . ${$df}[0]->webAccessible() . "\n";

insert($df)
Insert into the database the DataFile $df

Example:

DataStream

DataStream - An SSDS DataStream object

new()
Instantiate an SSDS::DataStream object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

    id name description startDate endDate original url contentLength mimeType
    webAccessible

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $dcAccess = new SSDS::DataStreamAccess();
        my $dc = $dcAccess->findByPK(5777);

getRecordDescription()
Return the RecordDescription object for this DataStream

Example:

        my $rd = $dc->getRecordDescription();
        foreach my $a ($rd->get_attribute_names()) {
                next unless $rd->$a;
                print "  $a = " . $rd->$a . "\n";
        }

DataStreamAccess

DataStreamAccess - Contains methods to query for and get DataStream objects

new()
Instantiate an SSDS::DataStreamAccess object

Example:

        my $dcAccess = new SSDS::DataStreamAccess();
        my $dc = $dcAccess->findByPK(5777);

findByPK(pk)
return the DataStream with PK = pk

Example:

        my $dcAccess = new SSDS::DataStreamAccess();
        my $dc = $dcAccess->findByPK(5777);

findByUrl(string)
return a list of DataStreams where the url is string.

Example:

        my $dfAccess = new SSDS::DataStreamAccess();
        my $df = $dfAccess->findByUrl("http://ssds-test.shore.mbari.org/ssds/rawpackets/1313_0_1_1327";);
        print "isWebAccessible = " . ${$df}[0]->webAccessible() . "\n";

DeviceType

DeviceType - An SSDS DeviceType object

new()
Instantiate an SSDS::DeviceType object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

    id name description defaultDeploymentRole displayInDeviceTypesPicklist

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $dcAccess = new SSDS::DeviceTypeAccess();
        my $dc = $dcAccess->findByPK(5777);

DeviceTypeAccess

DeviceTypeAccess - Contains methods to query for and get DeviceType objects

new()
Instantiate an SSDS::DeviceTypeAccess object

Example:

        my $dtAccess = new SSDS::DeviceTypeAccess();
        my $dt = $dtAccess->findByPK(102);

findByPK(pk)
return the DeviceType with PK = pk

Example:

        my $dtAccess = new SSDS::DeviceTypeAccess();
        my $dt = $dtAccess->findByPK(110);

findByName(string)
return the DeviceType with name = string

Example:

        my $dtAccess = new SSDS::DeviceTypeAccess();
        my $dt = $dtAccess->findByName("CTD");

insert($dt)
Insert into the database the DeviceType $dt

Example:

        my $dtAccess = new SSDS::DeviceTypeAccess();
        my $dt = new SSDS::DeviceType();
        $dt->name("IMCTD");
        $dt->description("Inductive Modem CTD");
        $dt->defaultDeploymentRole("instrument");
        $dt->displayInDeviceTypesPicklist("true");
        $dtAccess->insert($dt);

delete($dt)
Delete DeviceType $dt from the database

Example:

        my $dtAccess = new SSDS::DeviceTypeAccess();
        my $dt = $dtAccess->findByName("IMCTD");
        $dtAccess->delete($dt);

RecordDescription

RecordDescription - An SSDS RecordDescription object

new()
Instantiate an SSDS::RecordDescription object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

    id recordType bufferStyle bufferLengthType bufferItemSeparator recordTerminator endian parseable

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $rdAccess = new SSDS::RecordDescriptionAccess();
        my $rd = $rdAccess->findByPK(101);

listRecordVariables()
Return list of RecordVariables from this RecordDescription

Example:

        $rvs = $rd->listRecordVariables();
        @rvAttr = ${$rvs}[0]->get_attribute_names() if $outputs;
        foreach my $o (@{$rvs}) {
                foreach my $a (@rvAttr) {
                        next unless $o->$a;
                        print "  $a = " . $o->$a . "\n";
                }
                print"\n";
        }

RecordDescriptionAccess

RecordDescriptionAccess - Contains methods to query for and get RecordDescription objects

new()
Instantiate an SSDS::RecordDescriptionAccess object

Example:

        my $rdAccess = new SSDS::RecordDescriptionAccess();
        my $rd = $rdAccess->findByPK(102);

findByPK(pk)
return the RecordDescription with PK = pk

Example:

        my $rdAccess = new SSDS::RecordDescriptionAccess();
        my $rd = $rdAccess->findByPK(110);

RecordVariable

RecordVariable - An SSDS RecordVariable object

new()
Instantiate an SSDS::RecordVariable object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

    id name longName description format units columnIndex validMin validMax missingValue parseRegExp

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $rvAccess = new SSDS::RecordVariableAccess();
        my $rv = $rvAccess->findByPK(101);

getStandardVariable()
Return the StandardVariable object for this RecordVariable

Example:

        my $standard_name = $rv->getStandardVariable->name();

RecordVariableAccess

RecordVariableAccess - Contains methods to query for and get RecordVariable objects

new()
Instantiate an SSDS::RecordVariableAccess object

Example:

        my $rvAccess = new SSDS::RecordVariableAccess();
        my $rv = $rvAccess->findByPK(102);

findByPK(pk)
return the RecordVariable with PK = pk

Example:

        my $rvAccess = new SSDS::RecordVariableAccess();
        my $rv = $rvAccess->findByPK(110);

StandardVariable

StandardVariable - An SSDS StandardVariable object

new()
Instantiate an SSDS::StandardVariable object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

    id name referenceScale displayInPickList description

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $svAccess = new SSDS::StandardVariableAccess();
        my $sv = $svAccess->findByPK(101);

StandardVariableAccess

StandardVariableAccess - Contains methods to query for and get StandardVariable objects

new()
Instantiate an SSDS::StandardVariableAccess object

Example:

        my $svAccess = new SSDS::StandardVariableAccess();
        my $sv = $svAccess->findByPK(102);

findByPK(pk)
return the StandardVariable with PK = pk

Example:

        my $svAccess = new SSDS::StandardVariableAccess();
        my $sv = $svAccess->findByPK(110);

StandardUnit

StandardUnit - An SSDS StandardUnit object

new()
Instantiate an SSDS::StandardUnit object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

    id name longName symbol displayInPickList Description

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $suAccess = new SSDS::StandardUnitAccess();
        my $su = $suAccess->findByPK(101);

StandardUnitAccess

StandardUnitAccess - Contains methods to query for and get StandardUnit objects

new()
Instantiate an SSDS::StandardUnitAccess object

Example:

        my $suAccess = new SSDS::StandardUnitAccess();
        my $su = $suAccess->findByPK(102);

findByPK(pk)
return the StandardUnit with PK = pk

Example:

        my $suAccess = new SSDS::StandardUnitAccess();
        my $su = $suAccess->findByPK(110);

ProcessRun

ProcessRun - An SSDS ProcessRun object

new()
Instantiate an SSDS::ProcessRun object

The following methods may be used to get or set any of the attributes of a Deployment object (each attribute is both a setter and getter):

    id name description startDate endDate hostName

Note: the get_attribute_names() method will return this list of attributes

Example:

        my $prAccess = new SSDS::ProcessRunAccess();
        my $pr = $prAccess->findByPK(4389);

addInput()
Add an existing Input DataStream or DataFile to an existing ProcessRun. Both objects must already exist in the database for this to work as it simply associates IDs.

Example:

        # Get a DataStream and add as input
        $dcAccess = new SSDS::DataStreamAccess();
        $dc = $dcAccess->findByPK(4283);
        $p->addInput($dc);

addOutput()
Add an Output DataStream or DataFile to a ProcessRun.

Example:

        # Get a DataStream and add as input
        $dcAccess = new SSDS::DataStreamAccess();
        $dc = $dcAccess->findByPK(4283);
        $p->addOutput($dc);

listOutputs()
Return list of output DataStreams or DataFiles from this ProcessRun

Example:

        $outputs = $pr->listOutputs();
        @dfAttr = ${$outputs}[0]->get_attribute_names() if $outputs;
        foreach my $o (@{$outputs}) {
                foreach my $a (@dfAttr) {
                        next unless $o->$a;
                        print "  $a = " . $o->$a . "\n";
                }
                print"\n";
        }

listInputs()
Return list of output DataStreams or DataFiles from this ProcessRun

Example:

        $inputs = $pr->listInputs();
        @dfAttr = ${$Inputs}[0]->get_attribute_names() if $inputs;
        foreach my $o (@{$inputs}) {
                foreach my $a (@dfAttr) {
                        next unless $o->$a;
                        print "  $a = " . $o->$a . "\n";
                }
                print"\n";
        }

ProcessRunAccess

ProcessRunAccess - Contains methods to query for and get ProcessRun objects

new()
Instantiate an SSDS::ProcessRunAccess object

Example:

        my $prAccess = new SSDS::ProcessRunAccess();
        my $pr = $prAccess->findByPK(102);

findByPK(pk)
return the ProcessRun with PK = pk

Example:

        my $prAccess = new SSDS::ProcessRunAccess();
        my $pr = $prAccess->findByPK(110);

findByName(string)
return the ProcessRun with name = string

Example:

        my $prAccess = new SSDS::ProcessRunAccess();
        my $pr = $prAccess->findByName("Test ProcessRun");

insert($pr)
Insert into the database the ProcessRun $pr

Example:

        my $prAccess = new SSDS::ProcessRunAccess();
        my $pr = new SSDS::ProcessRun();
        $pr->
        $prAccess->insert($pr);

delete($pr)
Delete ProcessRun $pr from the database

Example:

        my $prAccess = new SSDS::ProcessRunAccess();
        my $pr = $prAccess->findByPK(1);
        $prAccess->delete($pr);

update($pr)
Update ProcessRun $pr in database

Example:

        my $prAccess = new SSDS::ProcessRunAccess();
        my $pr = $prAccess->findByPK(1);
        $prAccess->update($pr);


EXAMPLES

 #
 # Get top level mooring deployment and work down from there to get
 # URLs of output DataStreams
 #
 my $deplAccess = new SSDS::DeploymentAccess();
 my $devAccess = new SSDS::DeviceAccess();
 my $moorDepl = $deplAccess->findByName("CIMT Mooring Deployment");
 foreach my $md ( @{$moorDepl} ) {      
        my $canDepls = $md->childDeployments();
        foreach my $cd ( @{$canDepls} ) {
                my $instDepls = $cd->childDeployments();
                foreach my $id (@{$instDepls}) {
                        print "Instrument Deployment " . $id->name() . "\n";
                        my $dev = $id->getDevice($id->id());
                        print "of Device " . $dev->name() . "\n";
                        my $outputs = $id->listOutputs();
                        foreach my $o ( @{$outputs} ) {
                                my $name = $o->name();
                                my $url = $o->url();
                                print "  Output file name = $name\n";
                                print "  url = $url\n";
                        }
                        print "\n";
                }
        }
 } 
 
 #
 # Get the variable delimiter for the output from an Instrument Deploymnet
 #
 $delim = ${$id->listOutputs}[0]->getRecordDescription->bufferItemSeparator();
 
 #
 # Get parsing details from the SSDS metadata
 # (ds: DataStream, rd: RecordRescription, rv:RecordVariable)
 #
 my $ds = ${$id->listOutputs}[0];
 print "Input DataStream name: " . $ds->name() . "\n" if $debug;
 foreach my $a ($ds->get_attribute_names()) {
        next unless $ds->$a;
        print "  $a = " . $ds->$a . "\n" if $debug;
 }

 my $rd = $ds->getRecordDescription();
 print "RecordDescription:\n" if $debug;
 foreach my $a ($rd->get_attribute_names()) {
        next unless $rd->$a;
        print "  $a = " . $rd->$a . "\n" if $debug;
 }

 # 
 # Read Record variable attributes into named arrays for use later
 #
 my $rrvs = $rd->listRecordVariables();
 foreach my $a (${$rrvs}[0]->get_attribute_names()) {
        @{$a} = ();
 }
 my $i = 0;
 foreach my $rv ( @{$rrvs} ) {
        print "RecordVariable name: " . $rv->name() . "\n" if $debug;
        foreach my $a ($rv->get_attribute_names()) {
                next unless  $rv->$a;
                print "  $a = " . $rv->$a . "\n" if $debug;
                $$a[$i] = $rv->$a;    # Save variable Attributes in named arrays
        }
        $i++;
 }


SEE ALSO

Java classes in the moos.ssds.model and moos.ssds.services packages of MBARI's SSDS project. Diagrams of the object model and the database are in the poster at http://www.mbari.org/staff/mccann/papers/AGUPoster2004_AUV_data_management.pdf.

The Perl package ObjectTemplate (This package is required for SSDS.pm. for ActiveState Perl's ppm: install Class-ObjectTemplate.) The version used as of this writing is 0.7.


BUGS

Many of the SSDS object attributes are null and these values are simply not set when SSDS.pm materializes the objects. This causes many of these type of warnings from the ObjectTemplate module:

   Use of uninitialized value in numeric eq (==) at (eval 3) line 14.

If you like using the -w option on the perl command then you may want to add this line to your installation of ObjectTemplate.pm:

    no warnings 'uninitialized';

Not all characters work well as delimiters. Ones that have been tested include '|' (the default) and '~'.


AUTHOR

Mike McCann <mccann@mbari.org>

This module was developed as part of the MBARI 2003-2005 Shore Side Data System project.

http://www.mbari.org/ssds