org.pentaho.platform.repository.solution.dbbased
Class DbBasedSolutionRepository

java.lang.Object
  extended by org.pentaho.platform.engine.core.system.PentahoBase
      extended by org.pentaho.platform.engine.services.PentahoMessenger
          extended by org.pentaho.platform.repository.solution.SolutionRepositoryBase
              extended by org.pentaho.platform.repository.solution.dbbased.DbBasedSolutionRepository
All Implemented Interfaces:
Serializable, ILogger, IPentahoInitializer, ISolutionAttributeContributor, ISolutionFilter, ISolutionRepository
Direct Known Subclasses:
ExtensionDbBasedSolutionRepository

public class DbBasedSolutionRepository
extends SolutionRepositoryBase
implements ISolutionFilter, ISolutionAttributeContributor, IPentahoInitializer

Author:
William Seyler
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.pentaho.platform.repository.solution.SolutionRepositoryBase
SolutionRepositoryBase.ActionSequenceResourceWrapper
 
Field Summary
 
Fields inherited from class org.pentaho.platform.engine.core.system.PentahoBase
EMPTYLOGID, LOGID_MASK1, LOGID_MASK2, LOGID_SEPARATOR
 
Fields inherited from interface org.pentaho.platform.api.repository.ISolutionRepository
ACTION_ADMIN, ACTION_CREATE, ACTION_DELETE, ACTION_EXECUTE, ACTION_SHARE, ACTION_SUBSCRIBE, ACTION_UPDATE, FILE_ADD_FAILED, FILE_ADD_INVALID_PUBLISH_PASSWORD, FILE_ADD_INVALID_USER_CREDENTIALS, FILE_ADD_SUCCESSFUL, FILE_EXISTS, INDEX_FILENAME, SEPARATOR
 
Fields inherited from interface org.pentaho.platform.api.engine.ILogger
ACTIVITY_LOG, DEBUG, ERROR, FATAL, INFO, INSTANCE_LOG, SESSION_LOG, SOLUTION_LOG, TRACE, UNKNOWN, WARN
 
Constructor Summary
DbBasedSolutionRepository()
           
 
Method Summary
 void addPermission(ISolutionFile file, IPermissionRecipient recipient, IPermissionMask permission)
          TODO mlowery Need to throw exception if unauthorized.
 int addSolutionFile(String baseUrl, String path, String fileName, byte[] data, boolean overwrite)
          Adds a solution to the solution repository defined by the url that is built by concatenating baseUrl, path, and fileName.
 int addSolutionFile(String baseUrl, String path, String fileName, File f, boolean overwrite)
          Adds a solution to the solution repository defined by the url that is built by concatenating baseUrl, path, and fileName.
 void contributeAttributes(ISolutionFile solutionFile, Element childNode)
           
 ISolutionFile createFolder(File newFolder)
          This method creates a new folder in the Repository
 boolean deleteRepository(String repositoryNameToDelete)
           
 void exitPoint()
           
 IActionSequence getActionSequence(String solutionName, String actionPath, String sequenceName, int localLoggingLevel, int actionOperation)
          Retrieves the action sequence from the repository.
 String[] getAllActionSequences()
           
 List getChildrenFilesByParentId(String parentId)
           
 ClassLoader getClassLoader(String path)
          Returns an appropriate class loader for a specific path
 Map<IPermissionRecipient,IPermissionMask> getEffectivePermissions(ISolutionFile file)
          TODO mlowery Need to throw exception if unauthorized.
 ISolutionFile getFileByPath(String path)
           
 Map<IPermissionRecipient,IPermissionMask> getPermissions(ISolutionFile file)
          TODO mlowery Need to throw exception if unauthorized.
 String getRepositoryName()
           
 ISolutionFile getRootFolder()
           
 RepositoryFile getSolutionById(String anId)
           
 Document getSolutionDocument(String documentPath, int actionOperation)
          TODO mlowery This method trusts that actionOperation is what the caller really wants to do???
 long getSolutionFileLastModified(String path)
          Returns a long that represents the last time this file was modified
 Document getSolutions(String solutionName, String pathName, int actionOperation, boolean visibleOnly)
          Gets an XML Document representing all the files within a certain path within a solution
 Document getSolutionStructure(int actionOperation)
          Returns an XML document that represents the parent/child relationship of the current solution repository
 Document getSolutionTree(int actionOperation)
          Returns an XML document that defines the entire solution tree.
 Document getSolutionTree(int actionOperation, ISolutionFilter filter)
           
 String getValue(Document doc, String xPath, String defaultValue)
           
 boolean hasAccess(IPermissionRecipient permRecipient, ISolutionFile aFile, int actionOperation)
          Checks permission.
 boolean hasAccess(ISolutionFile aFile, int actionOperation)
          TODO mlowery Need to throw exception if unauthorized.
 void init()
           
 boolean isPentahoAdministrator()
           
 boolean keepFile(ISolutionFile solutionFile, int actionOperation)
           
 List loadSolutionFromFileSystem(IPentahoSession pSession, String solutionRoot, boolean deleteOrphans)
          This method loads solution files and folders from the file system into the RDBMS repository.
 int publish(String baseUrl, String path, String fileName, byte[] data, boolean overwrite)
          Put a file into the solution repo.
 int publish(String baseUrl, String path, String fileName, File f, boolean overwrite)
          Put a file into the solution repo.
 void reloadSolutionRepository(IPentahoSession localSession, int localLoggingLevel)
          Loads or reloads a solution repository after a structure change.
 boolean removeSolutionFile(String solutionPath)
           
 boolean removeSolutionFile(String solution, String path, String fileName)
          this is the file based removeSolutionFile, used by subclasses
 String resetSolutionFromFileSystem(IPentahoSession pSession)
           
 boolean resourceExists(String solutionPath)
          Returns a true if the specified resource exists.
 long resourceSize(String solutionPath)
          Returns the size of the specfied resource.
 void setPermissions(ISolutionFile file, Map<IPermissionRecipient,IPermissionMask> acl)
          TODO mlowery Need to throw exception if unauthorized.
 void setRepositoryName(String value)
           
 void share(ISolutionFile file, List<IPermissionRecipient> shareRecipients)
          Share file with recipient.
 boolean solutionSynchronizationSupported()
           
 boolean supportsAccessControls()
           
 boolean synchronizeSolutionWithSolutionSource(IPentahoSession pSession)
          For ISolutionRepository implementations that have a source and a destination (for example, DBBasedSolutionRepository which has a file-system source and a DB destination) this is the entry point that allows synchronization.
 void unshare(ISolutionFile file, List<IPermissionRecipient> shareRecipients)
          Undoes the share operation.
 
Methods inherited from class org.pentaho.platform.repository.solution.SolutionRepositoryBase
getFullSolutionTree, getLocaleString, getLocalizedFile, getLocalizedFileProperty, getLogger, getNavigationUIDocument, getResourceAsBytes, getResourceAsBytes, getResourceAsDocument, getResourceAsDocument, getResourceAsString, getResourceAsString, getResourceDataSource, getResourceDataSource, getResourceInputStream, getResourceInputStream, getResourceReader, getResourceReader, getSolutionFile, getSolutions, getXSLName, init, isSystemPath, isSystemTmpPath, localizeDoc, resetRepository
 
Methods inherited from class org.pentaho.platform.engine.services.PentahoMessenger
debug, debug, error, error, fatal, fatal, getMessages, getUserString, info, info, setMessages, trace, trace, warn, warn
 
Methods inherited from class org.pentaho.platform.engine.core.system.PentahoBase
genLogIdFromInfo, genLogIdFromInfo, genLogIdFromSession, getLoggingLevel, getLogId, getObjectName, setLoggingLevel, setLogId
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.pentaho.platform.api.engine.IPentahoInitializer
init
 
Methods inherited from interface org.pentaho.platform.api.repository.ISolutionRepository
getMessages, setMessages
 
Methods inherited from interface org.pentaho.platform.api.engine.ILogger
debug, debug, error, error, fatal, fatal, getLoggingLevel, info, info, setLoggingLevel, trace, trace, warn, warn
 

Constructor Detail

DbBasedSolutionRepository

public DbBasedSolutionRepository()
Method Detail

init

public void init()
Overrides:
init in class SolutionRepositoryBase

getActionSequence

public IActionSequence getActionSequence(String solutionName,
                                         String actionPath,
                                         String sequenceName,
                                         int localLoggingLevel,
                                         int actionOperation)
Description copied from interface: ISolutionRepository
Retrieves the action sequence from the repository. Should return null if the requested action seqeuence is not found.

Specified by:
getActionSequence in interface ISolutionRepository
Parameters:
solutionName - The name of the solution - like the root folder
actionPath - The relative path (from the solution) of where the file is stored
sequenceName - The name of the action sequence
localLoggingLevel - The level at which to log messages
actionOperation - Whether the action sequence is being retrieved for administration or execution
Returns:

hasAccess

public boolean hasAccess(IPermissionRecipient permRecipient,
                         ISolutionFile aFile,
                         int actionOperation)
Description copied from interface: ISolutionRepository
Checks permission. Although implementations should enforce permissions, some clients may want to see beforehand whether or not an operation will succeed. An example is enabling/disable UI controls based on access.

Specified by:
hasAccess in interface ISolutionRepository
aFile - domain instance to check
actionOperation - permission requested (A constant from ISolutionRepository.)
Returns:
true if actionOperation is allowed for this aFile

hasAccess

public boolean hasAccess(ISolutionFile aFile,
                         int actionOperation)
TODO mlowery Need to throw exception if unauthorized. (If there ever is a READ_PERMISSIONS permission.

Specified by:
hasAccess in interface ISolutionRepository
Parameters:
aFile - domain instance to check
actionOperation - permission requested (A constant from ISolutionRepository.)
Returns:
true if actionOperation is allowed for this aFile

isPentahoAdministrator

public boolean isPentahoAdministrator()

getSolutionDocument

public Document getSolutionDocument(String documentPath,
                                    int actionOperation)
TODO mlowery This method trusts that actionOperation is what the caller really wants to do???


reloadSolutionRepository

public void reloadSolutionRepository(IPentahoSession localSession,
                                     int localLoggingLevel)
Description copied from interface: ISolutionRepository
Loads or reloads a solution repository after a structure change.

Specified by:
reloadSolutionRepository in interface ISolutionRepository
Parameters:
localSession - - The session associated with this solution repository
localLoggingLevel - - The requested level of logging

getSolutions

public Document getSolutions(String solutionName,
                             String pathName,
                             int actionOperation,
                             boolean visibleOnly)
Description copied from interface: ISolutionRepository
Gets an XML Document representing all the files within a certain path within a solution

Specified by:
getSolutions in interface ISolutionRepository
Parameters:
solutionName - The name of the solution to get
pathName - The path from which to retrieve
actionOperation - Indicates what the list will be used for - execution or administration
Returns:
Document

getValue

public String getValue(Document doc,
                       String xPath,
                       String defaultValue)

getSolutionTree

public Document getSolutionTree(int actionOperation)
Description copied from interface: ISolutionRepository
Returns an XML document that defines the entire solution tree. This general purpose method return all files/folders in the solution in an easily understood XML document.

Specified by:
getSolutionTree in interface ISolutionRepository
Returns:

getSolutionTree

public Document getSolutionTree(int actionOperation,
                                ISolutionFilter filter)
Specified by:
getSolutionTree in interface ISolutionRepository
filter - an implementation of a ISolutionFilter that determines which files will be returned
Returns:
Document representing the solution tree

getSolutionStructure

public Document getSolutionStructure(int actionOperation)
Description copied from interface: ISolutionRepository
Returns an XML document that represents the parent/child relationship of the current solution repository

Specified by:
getSolutionStructure in interface ISolutionRepository
Returns:
an XML document

synchronizeSolutionWithSolutionSource

public boolean synchronizeSolutionWithSolutionSource(IPentahoSession pSession)
Description copied from interface: ISolutionRepository
For ISolutionRepository implementations that have a source and a destination (for example, DBBasedSolutionRepository which has a file-system source and a DB destination) this is the entry point that allows synchronization. Implementors should throw an UnsupportedOperationException if there is no synchronization necessary (for example, the FileBasedSolutionRepository).

Specified by:
synchronizeSolutionWithSolutionSource in interface ISolutionRepository
Returns:
boolean true if the synchronization succeeded

solutionSynchronizationSupported

public boolean solutionSynchronizationSupported()
Specified by:
solutionSynchronizationSupported in interface ISolutionRepository
Returns:
True if solution synchronization is supported by this implementor

resetSolutionFromFileSystem

public String resetSolutionFromFileSystem(IPentahoSession pSession)

loadSolutionFromFileSystem

public List loadSolutionFromFileSystem(IPentahoSession pSession,
                                       String solutionRoot,
                                       boolean deleteOrphans)
                                throws RepositoryException
This method loads solution files and folders from the file system into the RDBMS repository.

Parameters:
pSession - Users' Session
solutionRoot - The file system root folder
deleteOrphans - Whether to delete stranded references from RDBMS repository
Returns:
List of orphans that were deleted - returns list of deleted solution files.
Throws:
RepositoryException

getRootFolder

public ISolutionFile getRootFolder()
Specified by:
getRootFolder in interface ISolutionRepository
Overrides:
getRootFolder in class SolutionRepositoryBase
Returns:
the ISolutionFile for the root of the repository

getSolutionById

public RepositoryFile getSolutionById(String anId)

getChildrenFilesByParentId

public List getChildrenFilesByParentId(String parentId)

getFileByPath

public ISolutionFile getFileByPath(String path)
Specified by:
getFileByPath in interface ISolutionRepository
Overrides:
getFileByPath in class SolutionRepositoryBase
Parameters:
path - the solution path to the desired resource
Returns:
the ISolutionFile for the given path

getClassLoader

public ClassLoader getClassLoader(String path)
Description copied from interface: ISolutionRepository
Returns an appropriate class loader for a specific path

Specified by:
getClassLoader in interface ISolutionRepository
Returns:
- A ClassLoader

resourceExists

public boolean resourceExists(String solutionPath)
Description copied from interface: ISolutionRepository
Returns a true if the specified resource exists.

Specified by:
resourceExists in interface ISolutionRepository
Parameters:
solutionPath - - path to the resource
Returns:
- boolean true if resource exists

resourceSize

public long resourceSize(String solutionPath)
Description copied from interface: ISolutionRepository
Returns the size of the specfied resource. If resource doesn't exit a -1 is returned

Specified by:
resourceSize in interface ISolutionRepository
Parameters:
solutionPath - - path to the resource
Returns:
- long value of the size

removeSolutionFile

public boolean removeSolutionFile(String solutionPath)
Specified by:
removeSolutionFile in interface ISolutionRepository
Overrides:
removeSolutionFile in class SolutionRepositoryBase

removeSolutionFile

public boolean removeSolutionFile(String solution,
                                  String path,
                                  String fileName)
Description copied from class: SolutionRepositoryBase
this is the file based removeSolutionFile, used by subclasses

Specified by:
removeSolutionFile in interface ISolutionRepository
Overrides:
removeSolutionFile in class SolutionRepositoryBase
Returns:
- boolean indicating success

deleteRepository

public boolean deleteRepository(String repositoryNameToDelete)

getRepositoryName

public String getRepositoryName()
Specified by:
getRepositoryName in interface ISolutionRepository
Returns:
Returns the repositoryName.

setRepositoryName

public void setRepositoryName(String value)
Parameters:
repositoryName - The repositoryName to set.

keepFile

public boolean keepFile(ISolutionFile solutionFile,
                        int actionOperation)
Specified by:
keepFile in interface ISolutionFilter

contributeAttributes

public void contributeAttributes(ISolutionFile solutionFile,
                                 Element childNode)
Specified by:
contributeAttributes in interface ISolutionAttributeContributor

exitPoint

public void exitPoint()

addSolutionFile

public int addSolutionFile(String baseUrl,
                           String path,
                           String fileName,
                           byte[] data,
                           boolean overwrite)
Description copied from interface: ISolutionRepository
Adds a solution to the solution repository defined by the url that is built by concatenating baseUrl, path, and fileName. The fileName that is added has its data populated by the data.

Specified by:
addSolutionFile in interface ISolutionRepository
Overrides:
addSolutionFile in class SolutionRepositoryBase
Returns:
- int indicating status of return

addSolutionFile

public int addSolutionFile(String baseUrl,
                           String path,
                           String fileName,
                           File f,
                           boolean overwrite)
Description copied from interface: ISolutionRepository
Adds a solution to the solution repository defined by the url that is built by concatenating baseUrl, path, and fileName. The fileName that is added has its data populated by the data from File (on disk).

Specified by:
addSolutionFile in interface ISolutionRepository
Overrides:
addSolutionFile in class SolutionRepositoryBase
Returns:
int possible values: ISolutionRepository.FILE_ADD_SUCCESSFUL ISolutionRepository.FILE_EXISTS ISolutionRepository.FILE_ADD_FAILED TODO mlowery Why can't this delegate to the other addSolutionFile?

getAllActionSequences

public String[] getAllActionSequences()
Specified by:
getAllActionSequences in interface ISolutionRepository
Returns:
An array of Strings where each string is the fully qualified path of every *.xaction contained in the repository.

getSolutionFileLastModified

public long getSolutionFileLastModified(String path)
Description copied from interface: ISolutionRepository
Returns a long that represents the last time this file was modified

Specified by:
getSolutionFileLastModified in interface ISolutionRepository

supportsAccessControls

public boolean supportsAccessControls()
Specified by:
supportsAccessControls in interface ISolutionRepository
Returns:
whether or not the concrete versions of this interface support access controls

publish

public int publish(String baseUrl,
                   String path,
                   String fileName,
                   byte[] data,
                   boolean overwrite)
            throws PentahoAccessControlException
Description copied from interface: ISolutionRepository
Put a file into the solution repo. This method differs from addSolutionFile. Only Pentaho administrators can successfully execute addSolutionFile. addSolutionFile is a low-level operation. There is potentially more logic in the implementation of this method than in the implementation of addSolutionFile.

Specified by:
publish in interface ISolutionRepository
Returns:
Throws:
PentahoAccessControlException

publish

public int publish(String baseUrl,
                   String path,
                   String fileName,
                   File f,
                   boolean overwrite)
            throws PentahoAccessControlException
Description copied from interface: ISolutionRepository
Put a file into the solution repo. This method differs from addSolutionFile. Only Pentaho administrators can successfully execute addSolutionFile. addSolutionFile is a low-level operation. There is potentially more logic in the implementation of this method than in the implementation of addSolutionFile.

Specified by:
publish in interface ISolutionRepository
Returns:
constant from ISolutionRepository
Throws:
PentahoAccessControlException

share

public void share(ISolutionFile file,
                  List<IPermissionRecipient> shareRecipients)
Description copied from interface: ISolutionRepository
Share file with recipient. This version is appropriate for sharing with a particular role. The semantics of share are encapsulated in the implementation. (The sharer comes from the IPentahoSession.)

Specified by:
share in interface ISolutionRepository
Parameters:
file - file to share
shareRecipients - the users or roles with which to share (aka share-ees)

unshare

public void unshare(ISolutionFile file,
                    List<IPermissionRecipient> shareRecipients)
Description copied from interface: ISolutionRepository
Undoes the share operation.

Specified by:
unshare in interface ISolutionRepository
Parameters:
file - file to stop sharing
shareRecipients - the users or roles with which to stop sharing

addPermission

public void addPermission(ISolutionFile file,
                          IPermissionRecipient recipient,
                          IPermissionMask permission)
TODO mlowery Need to throw exception if unauthorized.

Specified by:
addPermission in interface ISolutionRepository
Parameters:
file - file whose ACL is to be modified
recipient - recipient of the permission
permission - right to an action on this file by this user

setPermissions

public void setPermissions(ISolutionFile file,
                           Map<IPermissionRecipient,IPermissionMask> acl)
                    throws PentahoAccessControlException
TODO mlowery Need to throw exception if unauthorized.

Specified by:
setPermissions in interface ISolutionRepository
Parameters:
file - file whose ACL is to be modified
acl - new ACL
Throws:
PentahoAccessControlException

getPermissions

public Map<IPermissionRecipient,IPermissionMask> getPermissions(ISolutionFile file)
TODO mlowery Need to throw exception if unauthorized. TODO mlowery If we had a READ_PERMS bit, then it would be enforced here.

Specified by:
getPermissions in interface ISolutionRepository
Parameters:
file - file whose ACL is to be returned
Returns:
ACL

getEffectivePermissions

public Map<IPermissionRecipient,IPermissionMask> getEffectivePermissions(ISolutionFile file)
TODO mlowery Need to throw exception if unauthorized. TODO mlowery If we had a READ_PERMS bit, then it would be enforced here.

Specified by:
getEffectivePermissions in interface ISolutionRepository
Parameters:
file - file whose ACL is to be returned
Returns:
ACL

createFolder

public ISolutionFile createFolder(File newFolder)
                           throws IOException
Description copied from interface: ISolutionRepository
This method creates a new folder in the Repository

Specified by:
createFolder in interface ISolutionRepository
Overrides:
createFolder in class SolutionRepositoryBase
Parameters:
newFolder - The File that points to the new folder to create
Returns:
The RepositoryFile object created
Throws:
IOException