org.jmonks.dms.versioncontrol.ri
Class DefaultRepository

java.lang.Object
  extended byorg.jmonks.dms.versioncontrol.ri.DefaultRepositoryEntry
      extended byorg.jmonks.dms.versioncontrol.ri.DefaultDirectoryEntry
          extended byorg.jmonks.dms.versioncontrol.ri.DefaultRepository
All Implemented Interfaces:
java.lang.Comparable, DirectoryEntry, Repository, RepositoryEntry

public class DefaultRepository
extends DefaultDirectoryEntry
implements Repository

Author:
Suresh Pragada This is the implementation of Repository class in Version Control API. This class gives the entry point to explore the Repository. It treats everything as directories and files. It treats the repository itself a directory. It uses the configuration file with the extension .vc to store the details of each entry.

Field Summary
private  int cleanupInterval
           
private static org.apache.log4j.Logger logger
           
private static DefaultRepository repository
           
(package private) static java.lang.String REPOSITORY_CLEANUP_INTERVAL
           
(package private) static java.lang.String REPOSITORY_CONFIG_FILE_EXTENSION
           
(package private) static long REPOSITORY_ENTRY_ID
           
(package private) static java.lang.String REPOSITORY_ROOT_PATH_PROPERTY_NAME
           
private  java.lang.String repositoryRootPath
           
 
Fields inherited from class org.jmonks.dms.versioncontrol.ri.DefaultDirectoryEntry
absoluteDirectoryName
 
Fields inherited from class org.jmonks.dms.versioncontrol.ri.DefaultRepositoryEntry
absoluteConfigFilePath, deletedDate, ENTRY_DELETE_KEY_NAME, ENTRY_DELETED_DATE_KEY_NAME, ENTRY_ID_KEY_NAME, ENTRY_NAME_KEY_NAME, ENTRY_PARENT_ENTRY_ID_KEY_NAME, ENTRY_TYPE_DIRECTORY, ENTRY_TYPE_FILE, ENTRY_TYPE_KEY_NAME, entryID, entryName, isDeleted, parentEntryID
 
Constructor Summary
private DefaultRepository()
          Creates a an instance of DefaultRepository and assigns the default directory as repository i.e., "."
 
Method Summary
private  void cleanupDeletedEntries(DefaultRepositoryEntry entry)
           
 boolean cleanupRepository()
          This method helps to cleanup the deleted entries from the repository.
private  boolean createRepositoryDirectoryInHome()
           
(package private)  long generateEntryID()
          Generates the uniquie id to be used as a entry ID in Repository implementation.
 java.util.Map getCompleteDirectoryEntryList()
          It returns all the directory entries in the repository as a map which holds the entryID as key and entryName as the value.
private  void getCompleteDirectoryEntryList(DefaultDirectoryEntry directoryEntry, java.util.Map entryMap)
           
private  java.io.File getConfigFile(java.io.File directory, java.lang.String fileName)
          Gets the configuration file with the name "fileName.vc" in given directory.
 java.lang.String getEntryNameToShowInUI(RepositoryEntry entry)
          It returns the string representation of the input entry to be shown in UI.
static DefaultRepository getInstance()
          Method which returns the singleton object.
 RepositoryEntry getRepositoryEntry(long entryID)
          Gets the requested Repository Entry in the repository.
 boolean moveEntry(RepositoryEntry sourceEntry, RepositoryEntry targetEntry)
          Moves the contents of sourceEntry to the targetEntry.
 java.lang.String toString()
           
 
Methods inherited from class org.jmonks.dms.versioncontrol.ri.DefaultDirectoryEntry
createDirectoryEntry, createFileEntry, getAbosluteConfigFileName, getAbsoluteDirectoryEntryName, getAllEntries, isExistingEntry, moveEntry, remove
 
Methods inherited from class org.jmonks.dms.versioncontrol.ri.DefaultRepositoryEntry
cancelDelete, compareTo, delete, getDeletedDate, getEntryID, getEntryName, getEntryType, getParentEntryID, getParentRepositoryEntry, getRepositoryEntry, isDeleted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jmonks.dms.versioncontrol.api.Repository
createDirectoryEntry, createFileEntry, getAllEntries
 
Methods inherited from interface org.jmonks.dms.versioncontrol.api.RepositoryEntry
cancelDelete, delete, getDeletedDate, getEntryID, getEntryName, getEntryType, getParentEntryID, getParentRepositoryEntry, isDeleted
 

Field Detail

repositoryRootPath

private java.lang.String repositoryRootPath

cleanupInterval

private int cleanupInterval

REPOSITORY_ROOT_PATH_PROPERTY_NAME

static final java.lang.String REPOSITORY_ROOT_PATH_PROPERTY_NAME
See Also:
Constant Field Values

REPOSITORY_CLEANUP_INTERVAL

static final java.lang.String REPOSITORY_CLEANUP_INTERVAL
See Also:
Constant Field Values

REPOSITORY_CONFIG_FILE_EXTENSION

static final java.lang.String REPOSITORY_CONFIG_FILE_EXTENSION
See Also:
Constant Field Values

REPOSITORY_ENTRY_ID

static final long REPOSITORY_ENTRY_ID
See Also:
Constant Field Values

logger

private static final org.apache.log4j.Logger logger

repository

private static final DefaultRepository repository
Constructor Detail

DefaultRepository

private DefaultRepository()
Creates a an instance of DefaultRepository and assigns the default directory as repository i.e., "."

Method Detail

createRepositoryDirectoryInHome

private boolean createRepositoryDirectoryInHome()

getInstance

public static DefaultRepository getInstance()
Method which returns the singleton object.

Returns:
Returns the default repository object.

getRepositoryEntry

public RepositoryEntry getRepositoryEntry(long entryID)
Description copied from interface: Repository
Gets the requested Repository Entry in the repository. This entry can exist at any level in repository.

Specified by:
getRepositoryEntry in interface Repository
Parameters:
entryID - ID which identifies the entry.
Returns:
Returns the list of RepositoryEntry objects. If not exists, it returns the list of size 0.
See Also:
Repository.getRepositoryEntry(long)

getConfigFile

private java.io.File getConfigFile(java.io.File directory,
                                   java.lang.String fileName)
Gets the configuration file with the name "fileName.vc" in given directory.

Parameters:
directory - Directory, where configuration file needs to be found.
fileName - configuration filename to look for.
Returns:
Return the file "fileName.vc" as file object.

generateEntryID

long generateEntryID()
Generates the uniquie id to be used as a entry ID in Repository implementation. This will look for the file ENTRYID.COUNTER in repository root path.

Returns:
Returns the unique ID.

getEntryNameToShowInUI

public java.lang.String getEntryNameToShowInUI(RepositoryEntry entry)
Description copied from interface: Repository
It returns the string representation of the input entry to be shown in UI.

Specified by:
getEntryNameToShowInUI in interface Repository
Parameters:
entry - The entry would like to be shown in UI.
Returns:
Returns the string representation of passed entry.
See Also:
Repository.getEntryNameToShowInUI(RepositoryEntry)

getCompleteDirectoryEntryList

public java.util.Map getCompleteDirectoryEntryList()
Description copied from interface: Repository
It returns all the directory entries in the repository as a map which holds the entryID as key and entryName as the value. The entryName should be the value to be shown in the UI. The entries will not be sorted and not guraanteed of the ordering. The return Map would be something like
      Key     Value
      ---     -----
      1234    REPOSITORY/abc/xyz.txt
 

Specified by:
getCompleteDirectoryEntryList in interface Repository
Returns:
Returns the map consist of entryID as the key and entryName as the value.
See Also:
Repository.getCompleteDirectoryEntryList()

getCompleteDirectoryEntryList

private void getCompleteDirectoryEntryList(DefaultDirectoryEntry directoryEntry,
                                           java.util.Map entryMap)

cleanupRepository

public boolean cleanupRepository()
Description copied from interface: Repository
This method helps to cleanup the deleted entries from the repository. This should look for the configuration property "dms.delete.interval" in application.properties file and remove the entries from repository which are deleted and exceeded that time period.

Specified by:
cleanupRepository in interface Repository
Returns:
boolean Returns true, if the cleanup happend smoothly, otherwise, false.
See Also:
Repository.cleanupRepository()

cleanupDeletedEntries

private void cleanupDeletedEntries(DefaultRepositoryEntry entry)
                            throws java.lang.Exception
Throws:
java.lang.Exception

moveEntry

public boolean moveEntry(RepositoryEntry sourceEntry,
                         RepositoryEntry targetEntry)
                  throws java.lang.IllegalArgumentException
Description copied from interface: Repository
Moves the contents of sourceEntry to the targetEntry. The targetEntry should be directory entry. It it is not a directory entry, IllegalArgumentException will be thrown.

Specified by:
moveEntry in interface Repository
Parameters:
sourceEntry - RepositoryEntry that needs to be moved.
targetEntry - RepositoryEntry where the source needs to be moved.
Returns:
Return true, if it could move the sourceEntry to targetEntry, false otherwise.
Throws:
java.lang.IllegalArgumentException - if the targetEntry is not a directory Entry.
See Also:
Repository.moveEntry(RepositoryEntry,RepositoryEntry)

toString

public java.lang.String toString()
Overrides:
toString in class DefaultDirectoryEntry
See Also:
Object.toString()