john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

getoxygenfileinfo

// 2012-08-06 johnpfeiffer requires O2JavaSDK-0.0.241 , FileSystemPath, OxygenSpace, OxygenFile, httpcore-4.2 , httpclient-4.2


import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;

import com.oxygen.sdk.O2Agent;
import com.oxygen.sdk.O2File;
import com.oxygen.sdk.O2Space;

public class getoxygenfileinfo
{
    private static final String CLASSVERSION = "0.21";
    private static final String CORRECTUSAGE = " CORRECT Usage: java -jar getoxygenfileinfo-" + CLASSVERSION
            + ".jar URL APIKEY oxygenUserId oxygenPassword /Space/DirectoryPath/Filename ";

    private String accessUrl;
    private String apiKey;
    private String oxygenUserId;
    private String oxygenPassword;
    private String spaceIdentifier;
    private String pathAndFileIdentifier;

    public static void main( String[] args ) throws Exception
    {
        long start = System.currentTimeMillis();
        getoxygenfileinfo main = new getoxygenfileinfo();
        try{
            main.validArguments( args );
        }catch( IllegalArgumentException e )
        {
            System.out.println( e.getMessage() + "," + CORRECTUSAGE );
            System.exit( 1 );
        }
        OxygenLogin login = new OxygenLogin( main.accessUrl , main.apiKey , main.oxygenUserId , main.oxygenPassword );
        O2Agent agent = login.getAgent();
        try
        {
            O2Space tempSpace = OxygenSpace.getInstanceById( agent , main.spaceIdentifier );
            if( tempSpace == null )
            {
                tempSpace = OxygenSpace.getInstanceByName( agent , main.spaceIdentifier );      //try again by Name
            }
            if( tempSpace == null )
            {
                throw new FileNotFoundException( "ERROR: [Space] " + main.spaceIdentifier + " not found." );
            }
            OxygenSpace space = new OxygenSpace( tempSpace );
            O2File temp = OxygenFile.getInstanceByNameFromSpace( agent , main.pathAndFileIdentifier , space.get() );
            if( temp == null )
            {
                throw new FileNotFoundException( main.pathAndFileIdentifier + " not found in " + main.spaceIdentifier );
            }
            OxygenFile file = new OxygenFile( temp );
            System.out.println( "filename,id,lastModifiedBy,created,sizeInBytes" );
            System.out.print( file.getName() + "," + file.getId() + "," + file.getLastModifiedBy() + "," + file.getCreatedTimestamp() + "," + file.getSizeInBytes() );

        }catch( IllegalArgumentException e )
        {
            System.err.println( "ERROR accessing Space " + main.spaceIdentifier + e.getMessage() );
        }catch( FileNotFoundException e )
        {
            System.out.print( e.getMessage() );
        }finally
        {
            agent.logout();
            System.out.print( " [in " + main.calculateRuntime( start ) + " ms]" );
        }
    }

    private long calculateRuntime( long start )
    {
        return ( System.currentTimeMillis() - start );
    }

    private void validArguments( String args[] ) throws IllegalArgumentException
    {
        if( args.length != 5 )
        {
            throw new IllegalArgumentException( "ERROR: " + args.length + " is the incorrect number of arguments" );
        }
        for( int i = 0 ; i < args.length ; i++ )
        {
            if( args[i] == null || args[i].isEmpty() )
            {
                throw new IllegalArgumentException( "ERROR: argument " + i+1 + " is null or empty" );
            }
        }
        try
        {
            new URL( args[0] );
        }catch( MalformedURLException e )
        {
            throw new IllegalArgumentException( "ERROR: malformed URL: " + args[0] );
        }

        accessUrl = args[0];
        apiKey = args[1];
        oxygenUserId = args[2];
        oxygenPassword = args[3];
        FileSystemPath cleanPath = new FileSystemPath( args[4] );
        spaceIdentifier = cleanPath.getFirstDirectory();
        if( spaceIdentifier.isEmpty() )
        {
            throw new IllegalArgumentException( "ERROR: Space parameter is null or empty" );
        }
        String temp = cleanPath.get();
        pathAndFileIdentifier = temp.substring( spaceIdentifier.length() );
        System.out.println( "DEBUG: " + spaceIdentifier + " : " + pathAndFileIdentifier );
    }


} // end class

  • « OxygenFile
  • oxygenget »

Published

Aug 8, 2012

Category

java-oxygencloud

~290 words

Tags

  • getoxygenfileinfo 1
  • java 252
  • oxygencloud 19