## com.imcode.imcms.mapping
Class DocumentMapper

    java.lang.Object
      com.imcode.imcms.mapping.DocumentMapper

All Implemented Interfaces:
  DocumentGetter

    public class DocumentMapper

extends java.lang.Object
implements DocumentGetter

NOTES: DocumentSaver is instantiated using SpringFramework factory in order to support declared (AOP) transactions. DatabseDocumentGetter is instantiated using SpringFramework factory in order to support declared (AOP) transactions. There is a major difference between getDocument and getDocumentForShowing: getDocument returns document instance unmodified. getDocumentForShowing will throw an exception if a user who have requested the document does not has appropriate permissions or settings. Additionally returned document instance is adviced using AOP interceptors to provide workaround for legacy code which does not support translated (i18n) content - currently this is a prototype implementation.

Nested Class Summary
`static class` `DocumentMapper.PublushDocumentCommand`
`static class` `DocumentMapper.SaveEditedDocumentCommand`
`static class` `DocumentMapper.TextDocumentMenuIndexPair`

Constructor Summary
`DocumentMapper(ImcmsServices services, com.imcode.db.Database database)`

Method Summary
`DocumentDomainObject` `copyDocument(DocumentDomainObject document, UserDomainObject user)`
`DocumentDomainObject` `createDocumentOfTypeFromParent(int documentTypeId, DocumentDomainObject parent, UserDomainObject user)`
`void` `createWorkingDocumentFromExisting(DocumentDomainObject document, UserDomainObject user)` Creates working document from existing one.
`void` `deleteDocument(DocumentDomainObject document, UserDomainObject user)`
`java.util.Set<java.lang.String>` `getAllDocumentAlias()`
`int[]` `getAllDocumentIds()`
`java.util.Map` `getAllDocumentTypeIdsAndNamesInUsersLanguage(UserDomainObject user)`
`java.lang.String[]` `getAllMimeTypes()`
`java.lang.String[][]` `getAllMimeTypesWithDescriptions(UserDomainObject user)`
`SectionDomainObject[]` `getAllSections()`
`CategoryMapper` `getCategoryMapper()`
`Clock` `getClock()`
`com.imcode.db.Database` `getDatabase()`
`DocumentDomainObject` `getDocument(java.lang.Integer documentId)` Returns published version of document.
`DocumentDomainObject` `getDocument(java.lang.Integer documentId, DocumentVersionTag versionTag)`
`DocumentDomainObject` `getDocument(java.lang.Integer documentId, java.lang.Integer version)` Returns document by id and version.
`DocumentDomainObject` `getDocument(java.lang.String documentIdString)`
`DocumentDomainObject` `getDocumentForShowing(java.lang.Integer documentId, java.lang.Integer version)` TODO: implement Returns document for showing by document id and version.
`DocumentDomainObject` `getDocumentForShowing(java.lang.Integer documentId, UserDomainObject user)` Returns published or working document depending on user's view settings and i18n meta settings.
`DocumentDomainObject` `getDocumentForShowing(java.lang.String documentIdString, UserDomainObject user)` Returns document for showing.
`CachingDocumentGetter` `getDocumentGetter()`
`DocumentIndex` `getDocumentIndex()`
`DocumentMapper.TextDocumentMenuIndexPair[]` `getDocumentMenuPairsContainingDocument(DocumentDomainObject document)`
`DocumentPermissionSetMapper` `getDocumentPermissionSetMapper()`
`DocumentReference` `getDocumentReference(DocumentDomainObject document)`
`DocumentReference` `getDocumentReference(int childId)`
`java.util.List` `getDocuments(java.util.Collection documentIds)` Return a list of published documents in the same order as the documentIds
`DocumentSaver` `getDocumentSaver()`
`java.util.Iterator` `getDocumentsIterator(org.apache.commons.lang.math.IntRange idRange)`
`java.util.List` `getDocumentsWithPermissionsForRole(RoleDomainObject role)`
`int` `getHighestDocumentId()`
`ImcmsServices` `getImcmsServices()`
`int` `getLowestDocumentId()`
`java.lang.String[][]` `getParentDocumentAndMenuIdsForDocument(DocumentDomainObject document)`
`SectionDomainObject` `getSectionById(int sectionId)`
`SectionDomainObject` `getSectionByName(java.lang.String name)`
`java.util.Set` `getSections(java.util.Collection sectionIds)`
`DocumentDomainObject` `getWorkingDocument(java.lang.Integer documentId)` Returns working version of a document.
`boolean` `hasPublishedVersion(java.lang.Integer documentId)`
`void` `initSections()`
`void` `invalidateDocument(DocumentDomainObject document)`
`void` `publishWorkingDocument(DocumentDomainObject document, UserDomainObject user)` Published working version of a document.
`void` `saveDocument(DocumentDomainObject document, UserDomainObject user)` Saves published or working document.
`void` `saveNewDocument(DocumentDomainObject document, UserDomainObject user, boolean copying)`
`void` `setClock(Clock clock)`
`void` `setDocumentIndex(DocumentIndex documentIndex)`
`void` `setDocumentPermissionSetMapper(DocumentPermissionSetMapper documentPermissionSetMapper)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### DocumentMapper

    public DocumentMapper(ImcmsServices services,
                          com.imcode.db.Database database)

Method Detail

### initSections

    public void initSections()

### getDocumentSaver

    public DocumentSaver getDocumentSaver()

### createDocumentOfTypeFromParent

    public DocumentDomainObject createDocumentOfTypeFromParent(int documentTypeId,
                                                               DocumentDomainObject parent,
                                                               UserDomainObject user)

### getAllSections

    public SectionDomainObject[] getAllSections()

### getDocumentReference

    public DocumentReference getDocumentReference(DocumentDomainObject document)

### getDocumentReference

    public DocumentReference getDocumentReference(int childId)

### getSectionById

    public SectionDomainObject getSectionById(int sectionId)

### getSectionByName

    public SectionDomainObject getSectionByName(java.lang.String name)

### saveNewDocument

    public void saveNewDocument(DocumentDomainObject document,
                                UserDomainObject user,
                                boolean copying)
                         throws DocumentSaveException,
                                NoPermissionToAddDocumentToMenuException

  Throws:
    `DocumentSaveException`
    `NoPermissionToAddDocumentToMenuException`

### saveDocument

    public void saveDocument(DocumentDomainObject document,
                             UserDomainObject user)
                      throws DocumentSaveException,
                             NoPermissionToAddDocumentToMenuException,
                             NoPermissionToEditDocumentException

  Saves published or working document.

  Throws:
    `DocumentSaveException`
    `NoPermissionToAddDocumentToMenuException`
    `NoPermissionToEditDocumentException`

### publishWorkingDocument

    public void publishWorkingDocument(DocumentDomainObject document,
                                       UserDomainObject user)
                                throws DocumentSaveException,
                                       NoPermissionToEditDocumentException

  Published working version of a document.

  Throws:
    `DocumentSaveException`
    `NoPermissionToEditDocumentException`

### createWorkingDocumentFromExisting

    public void createWorkingDocumentFromExisting(DocumentDomainObject document,
                                                  UserDomainObject user)
                                           throws DocumentSaveException,
                                                  NoPermissionToEditDocumentException

  Creates working document from existing one.

  Throws:
    `DocumentSaveException`
    `NoPermissionToEditDocumentException`

### getDocument

    public DocumentDomainObject getDocument(java.lang.Integer documentId,
                                            java.lang.Integer version)

  Returns document by id and version.

  Specified by:
    `getDocument` in interface `DocumentGetter`
  Parameters:
    `documentId` - document's id.

### getDocumentForShowing

    public DocumentDomainObject getDocumentForShowing(java.lang.Integer documentId,
                                                      java.lang.Integer version)

  TODO: implement Returns document for showing by document id and version.

### hasPublishedVersion

    public boolean hasPublishedVersion(java.lang.Integer documentId)

### invalidateDocument

    public void invalidateDocument(DocumentDomainObject document)

### getDocumentIndex

    public DocumentIndex getDocumentIndex()

### getParentDocumentAndMenuIdsForDocument

    public java.lang.String[][] getParentDocumentAndMenuIdsForDocument(DocumentDomainObject document)

### getAllMimeTypesWithDescriptions

    public java.lang.String[][] getAllMimeTypesWithDescriptions(UserDomainObject user)

### getAllMimeTypes

    public java.lang.String[] getAllMimeTypes()

### deleteDocument

    public void deleteDocument(DocumentDomainObject document,
                               UserDomainObject user)

### getAllDocumentTypeIdsAndNamesInUsersLanguage

    public java.util.Map getAllDocumentTypeIdsAndNamesInUsersLanguage(UserDomainObject user)

### getDocumentMenuPairsContainingDocument

    public DocumentMapper.TextDocumentMenuIndexPair[] getDocumentMenuPairsContainingDocument(DocumentDomainObject document)

### getDocumentsIterator

    public java.util.Iterator getDocumentsIterator(org.apache.commons.lang.math.IntRange idRange)

### getAllDocumentIds

    public int[] getAllDocumentIds()

### getAllDocumentAlias

    public java.util.Set<java.lang.String> getAllDocumentAlias()

### getDocument

    public DocumentDomainObject getDocument(java.lang.String documentIdString)

### getDocumentPermissionSetMapper

    public DocumentPermissionSetMapper getDocumentPermissionSetMapper()

### getLowestDocumentId

    public int getLowestDocumentId()

### getHighestDocumentId

    public int getHighestDocumentId()

### copyDocument

    public DocumentDomainObject copyDocument(DocumentDomainObject document,
                                             UserDomainObject user)
                                      throws NoPermissionToAddDocumentToMenuException,
                                             DocumentSaveException

  Throws:
    `NoPermissionToAddDocumentToMenuException`
    `DocumentSaveException`

### getDocumentsWithPermissionsForRole

    public java.util.List getDocumentsWithPermissionsForRole(RoleDomainObject role)

### getDocument

    public DocumentDomainObject getDocument(java.lang.Integer documentId,
                                            DocumentVersionTag versionTag)

  Returns:
    tagged version of document.

### getDocument

    public DocumentDomainObject getDocument(java.lang.Integer documentId)

  Returns published version of document.

  Specified by:
    `getDocument` in interface `DocumentGetter`

### getWorkingDocument

    public DocumentDomainObject getWorkingDocument(java.lang.Integer documentId)

  Description copied from interface: `DocumentGetter`
  Returns working version of a document.

  Specified by:
    `getWorkingDocument` in interface `DocumentGetter`
  Parameters:
    `documentId` - document's id.

### getDocumentForShowing

    public DocumentDomainObject getDocumentForShowing(java.lang.String documentIdString,
                                                      UserDomainObject user)

  Returns document for showing.

  Parameters:
    `documentIdString` - document's id or alias
    `user` - an user requesting document

### getDocumentForShowing

    public DocumentDomainObject getDocumentForShowing(java.lang.Integer documentId,
                                                      UserDomainObject user)

  Returns published or working document depending on user's view settings and i18n meta settings.

  Parameters:
    `documentId` - document id.
  Returns:
    document.

### getCategoryMapper

    public CategoryMapper getCategoryMapper()

### getDatabase

    public com.imcode.db.Database getDatabase()

### getClock

    public Clock getClock()

### getImcmsServices

    public ImcmsServices getImcmsServices()

### setClock

    public void setClock(Clock clock)

### setDocumentPermissionSetMapper

    public void setDocumentPermissionSetMapper(DocumentPermissionSetMapper documentPermissionSetMapper)

### setDocumentIndex

    public void setDocumentIndex(DocumentIndex documentIndex)

### getDocuments

    public java.util.List getDocuments(java.util.Collection documentIds)

  Description copied from interface: `DocumentGetter`
  Return a list of published documents in the same order as the documentIds

  Specified by:
    `getDocuments` in interface `DocumentGetter`

### getSections

    public java.util.Set getSections(java.util.Collection sectionIds)

### getDocumentGetter

    public CachingDocumentGetter getDocumentGetter()