6. Summary

And that is basically it. All other operations are variations on this theme, and the API is pretty self-explanatory. To put everything together, the following code, taken from one of the the unit tests, illustrates writing and reading files in a repostory:


# Create DB connection
vars = { 
  host: 'localhost',
  db: 'rsp', 
  username: 'root',
  password: 'password',
  driver: 'QPSQL'
}

db = JW::DBI::Database.new()

if db.open(vars) == false
  raise "Failed to connect: #{db.error()}"
end

# Create DMS connection
dms = JW::DMS::Repository.new(db, path, uuid)

# Create the file
fileId = dms.createFile(name)

fileData = 'some data'

# File should not exist
assert File.exist?(dms.idToPath(fileId)) == false

# Since file doesn't exist, we must open if for writing, otherwise it will
# throw an exception.
file = dms.openFile(fileId, 'w')
file.write(fileData)
file.close()

# Since there was data, the file should exist.
assert File.exist?(dms.idToPath(fileId)) == true
assert dms.fileExists?(fileId) == true

# Now read back the data
file = dms.openFile(fileId)
assert file.read() == fileData
file.close()    

# Get the info related to file
info = dms.fileInfo(fileId)
assert info['fileid'].to_s == fileId.to_s
assert info['guid']       != nil
assert info['guid'].class == String

# Delete it
dms.deleteFile(fileId)