SSDS.pm - Access SSDS Metadata
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
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.
ObjectCreator - Contains private support methods to create SSDS objects. The methods below are inherited by all the SSDS objects declared in the child packages.
Function to parse return of MetadataAccessServlet into a single (key, value) hash list.
Example:
my ($returnedObject, $oHash) = $obj->_buildHash($obj->delim, $data);
Example:
my ($returnedObject, $oHashes) = $obj->_buildHashes($obj->delim, $data);
Examples:
# Request and return a Device object
my $url = $obj->baseUrl . "className=DeviceTypeAccess&methodName=findByPK¶m1Type=Long¶m1Value=" . $pk;
return $obj->_createSSDSobject($url);
# Request a DataStream and return a DataFile object
my $url = $obj->baseUrl . "className=DataStreamAccess&methodName=findByPK¶m1Type=Long¶m1Value=" . $pk;
return $obj->_createSSDSobject($url, 'DataFile');
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');
Example:
my $url = $obj->baseUrl . "className=DeviceTypeAccess&methodName=insert¶m1Type=DeviceType¶m1Value=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);
Deployment - 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
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";
}
Example:
my $dev = $id->getDevice($id->id());
print "Instrument Deployment " . $id->name() . "\n";
print " of Device " . $dev->name() . "\n";
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";
}
Example:
my $depl = $deplAccess->findByPK(4322);
my $parentDepl = $depl->getParentDeployment();
foreach my $a (@deplAttr) {
next unless $parentDepl->$a;
print " $a = " . $parentDepl->$a . "\n";
}
Example:
print " startDate = " . $depl->startDate() . "\n";
print " start epoch seconds = " . $depl->getStartEsecs() . "\n";
Example:
print " endDate = " . $depl->endDate() . "\n" if $depl->endDate();
print " end epoch seconds = " . $depl->getEndEsecs() . "\n" if $depl->getEndEsecs();
DeploymentAccess - Contains methods to query for and get Deployment objects
Example:
my $deplAccess = new SSDS::DeploymentAccess();
$depl = $deplAccess->findByPK(4322);
Example:
my $deplAccess = new SSDS::DeploymentAccess();
my $depl = $deplAccess->findByPK(4322);
print "NominalLongitude = " . $depl->nominalLongitude . "\n";
Example:
my $deplAccess = new SSDS::DeploymentAccess();
my @depl = $deplAccess->findByName("CIMT Mooring Deployment");
Device - 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
Example:
my $devAccess = new SSDS::DeviceAccess();
$dev = $devAccess->findByPK(1319);
print "DeviceType name = " . $dev->getDeviceType()->name() . "\n"
DeviceAccess - Contains methods to query for and get Device objects
Example:
my $devAccess = new SSDS::DeviceAccess();
$dev = $devAccess->findByPK(1319);
Example:
my $devAccess = new SSDS::DeviceAccess();
$dev = $devAccess->findByPK(1319);
Example:
$devs = $devAccess->findByLikeName("CTD");
DataFile - 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);
Example:
my $rd = $dc->getRecordDescription();
foreach my $a ($rd->get_attribute_names()) {
next unless $rd->$a;
print " $a = " . $rd->$a . "\n";
}
DataFileAccess - Contains methods to query for and get DataFile objects
Example:
my $dcAccess = new SSDS::DataFileAccess();
my $dc = $dcAccess->findByPK(5777);
Example:
my $dcAccess = new SSDS::DataFileAccess();
my $dc = $dcAccess->findByPK(5777);
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";
Example:
DataStream - 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);
Example:
my $rd = $dc->getRecordDescription();
foreach my $a ($rd->get_attribute_names()) {
next unless $rd->$a;
print " $a = " . $rd->$a . "\n";
}
DataStreamAccess - Contains methods to query for and get DataStream objects
Example:
my $dcAccess = new SSDS::DataStreamAccess();
my $dc = $dcAccess->findByPK(5777);
Example:
my $dcAccess = new SSDS::DataStreamAccess();
my $dc = $dcAccess->findByPK(5777);
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 - 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 - Contains methods to query for and get DeviceType objects
Example:
my $dtAccess = new SSDS::DeviceTypeAccess();
my $dt = $dtAccess->findByPK(102);
Example:
my $dtAccess = new SSDS::DeviceTypeAccess();
my $dt = $dtAccess->findByPK(110);
Example:
my $dtAccess = new SSDS::DeviceTypeAccess();
my $dt = $dtAccess->findByName("CTD");
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);
Example:
my $dtAccess = new SSDS::DeviceTypeAccess();
my $dt = $dtAccess->findByName("IMCTD");
$dtAccess->delete($dt);
RecordDescription - 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);
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 - Contains methods to query for and get RecordDescription objects
Example:
my $rdAccess = new SSDS::RecordDescriptionAccess();
my $rd = $rdAccess->findByPK(102);
Example:
my $rdAccess = new SSDS::RecordDescriptionAccess();
my $rd = $rdAccess->findByPK(110);
RecordVariable - 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);
Example:
my $standard_name = $rv->getStandardVariable->name();
RecordVariableAccess - Contains methods to query for and get RecordVariable objects
Example:
my $rvAccess = new SSDS::RecordVariableAccess();
my $rv = $rvAccess->findByPK(102);
Example:
my $rvAccess = new SSDS::RecordVariableAccess();
my $rv = $rvAccess->findByPK(110);
StandardVariable - 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 - Contains methods to query for and get StandardVariable objects
Example:
my $svAccess = new SSDS::StandardVariableAccess();
my $sv = $svAccess->findByPK(102);
Example:
my $svAccess = new SSDS::StandardVariableAccess();
my $sv = $svAccess->findByPK(110);
StandardUnit - 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 - Contains methods to query for and get StandardUnit objects
Example:
my $suAccess = new SSDS::StandardUnitAccess();
my $su = $suAccess->findByPK(102);
Example:
my $suAccess = new SSDS::StandardUnitAccess();
my $su = $suAccess->findByPK(110);
ProcessRun - 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);
Example:
# Get a DataStream and add as input
$dcAccess = new SSDS::DataStreamAccess();
$dc = $dcAccess->findByPK(4283);
$p->addInput($dc);
Example:
# Get a DataStream and add as input
$dcAccess = new SSDS::DataStreamAccess();
$dc = $dcAccess->findByPK(4283);
$p->addOutput($dc);
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";
}
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 - Contains methods to query for and get ProcessRun objects
Example:
my $prAccess = new SSDS::ProcessRunAccess();
my $pr = $prAccess->findByPK(102);
Example:
my $prAccess = new SSDS::ProcessRunAccess();
my $pr = $prAccess->findByPK(110);
Example:
my $prAccess = new SSDS::ProcessRunAccess();
my $pr = $prAccess->findByName("Test ProcessRun");
Example:
my $prAccess = new SSDS::ProcessRunAccess();
my $pr = new SSDS::ProcessRun();
$pr->
$prAccess->insert($pr);
Example:
my $prAccess = new SSDS::ProcessRunAccess();
my $pr = $prAccess->findByPK(1);
$prAccess->delete($pr);
Example:
my $prAccess = new SSDS::ProcessRunAccess();
my $pr = $prAccess->findByPK(1);
$prAccess->update($pr);
#
# 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++;
}
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.
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 '~'.
Mike McCann <mccann@mbari.org>
This module was developed as part of the MBARI 2003-2005 Shore Side Data System project.