DMS System

Introduction

A Document Management System (DMS) is a system that allows you to store files and keep track of the versions of those files. Ontimize Boot provides a DMS system that allows to store the files that are associated to the different records of a database table.

Previous concepts

  • Document (or workspace): It is superentity into which several files can be grouped.
  • File: The file is the generic representation of a file. A file groups several versions of itself.
  • Version: Is the relationship to a physical file.
  • Category (or folder): Is a way of grouping files within the document.

Prerequisites

Note: You can follow this tutorial using your own application, although for this example we will use an application created using the archetype that can be found on this page and with a REST service.

There are 2 options to follow this tutorial, clone the repository with the initial state and follow the tutorial step by step, or download the final example and see which files are new and which have been updated.

Initial project

/$ git clone https://github.com/ontimize/ontimize-examples 
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-dms-initial

Final example

/$ git clone https://github.com/ontimize/ontimize-examples 
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-dms

Note: To simplify the code being written, three dots (…) may appear in some parts of the code. This indicates that there may be previous code before and after those dots.

Steps

Database

DMS Tables

With the database started, we create the new tables that will store the DMS information.

1
2
3
4
5
6
CREATE TABLE TDMS_DOC(ID_DMS_DOC INTEGER IDENTITY NOT NULL PRIMARY KEY,UPDATE_DATE TIMESTAMP,UPDATE_BY_ID INTEGER,DOC_NAME VARCHAR(255) NOT NULL,OWNER_ID INTEGER NOT NULL,DOC_DESCRIPTION CLOB(1G),DOC_KEYWORDS VARCHAR(255));
CREATE TABLE TDMS_DOC_FILE(ID_DMS_DOC_FILE INTEGER IDENTITY NOT NULL PRIMARY KEY,FILE_NAME VARCHAR(255) NOT NULL,ID_DMS_DOC INTEGER NOT NULL,FILE_TYPE VARCHAR(255),ID_DMS_DOC_CATEGORY INTEGER);
CREATE TABLE TDMS_DOC_FILE_VERSION(ID_DMS_DOC_FILE_VERSION INTEGER IDENTITY NOT NULL PRIMARY KEY,FILE_PATH VARCHAR(500),VERSION INTEGER NOT NULL,FILE_DESCRIPTION CLOB(1G),IS_ACTIVE CHARACTER(1) NOT NULL,FILE_ADDED_DATE TIMESTAMP NOT NULL,FILE_ADDED_USER_ID INTEGER NOT NULL,ID_DMS_DOC_FILE INTEGER NOT NULL,THUMBNAIL BLOB(1G),FILE_SIZE INTEGER);
CREATE TABLE TDMS_DOC_PROPERTY(ID_DMS_DOC_PROPERTY INTEGER IDENTITY NOT NULL PRIMARY KEY,DOC_PROPERTY_KEY VARCHAR(255) NOT NULL,DOC_PROPERTY_VALUE VARCHAR(255),ID_DMS_DOC INTEGER NOT NULL);
CREATE TABLE TDMS_RELATED_DOC(ID_DMS_RELATED_PROPERTY INTEGER IDENTITY NOT NULL PRIMARY KEY,ID_DMS_DOC_MASTER INTEGER NOT NULL,ID_DMS_DOC_CHILD INTEGER NOT NULL);
CREATE TABLE TDMS_DOC_CATEGORY(ID_DMS_DOC_CATEGORY INTEGER IDENTITY NOT NULL PRIMARY KEY,ID_DMS_DOC INTEGER NOT NULL,ID_DMS_DOC_CATEGORY_PARENT INTEGER,CATEGORY_NAME VARCHAR(255) NOT NULL);

Once the tables have been created, we add the foreign keys

1
2
3
4
5
6
7
ALTER TABLE TDMS_DOC_FILE ADD CONSTRAINT TDMS_DOC_FILE_FK FOREIGN KEY(ID_DMS_DOC) REFERENCES TDMS_DOC(ID_DMS_DOC);
ALTER TABLE TDMS_DOC_FILE_VERSION ADD CONSTRAINT TDMS_DOC_FILE_VERSION_FK FOREIGN KEY(ID_DMS_DOC_FILE) REFERENCES TDMS_DOC_FILE(ID_DMS_DOC_FILE);
ALTER TABLE TDMS_DOC_PROPERTY ADD CONSTRAINT TDMS_DOC_PROPERTY_FK FOREIGN KEY(ID_DMS_DOC) REFERENCES TDMS_DOC(ID_DMS_DOC)
ALTER TABLE TDMS_RELATED_DOC ADD CONSTRAINT TDMS_RELATED_DOC_FK FOREIGN KEY(ID_DMS_DOC_MASTER) REFERENCES TDMS_DOC(ID_DMS_DOC);
ALTER TABLE TDMS_RELATED_DOC ADD CONSTRAINT TDMS_RELATED_DOC_FK_1 FOREIGN KEY(ID_DMS_DOC_CHILD) REFERENCES TDMS_DOC(ID_DMS_DOC);
ALTER TABLE TDMS_DOC_CATEGORY ADD CONSTRAINT TDMS_DOC_CATEGORY_FK FOREIGN KEY(ID_DMS_DOC) REFERENCES TDMS_DOC(ID_DMS_DOC);
ALTER TABLE TDMS_DOC_FILE ADD CONSTRAINT TDMS_DOC_FILE_FK_1 FOREIGN KEY(ID_DMS_DOC_CATEGORY) REFERENCES TDMS_DOC_CATEGORY(ID_DMS_DOC_CATEGORY);

In this example we want each new candidate added to the application to have its own space to store documents, so we will modify the CANDIDATES table to contain a column that stores the primary key of the document (or workspace) that will be associated with it.

1
ALTER TABLE CANDIDATE ADD ID_DMS_DOC INTEGER;
1
ALTER TABLE CANDIDATE ADD CONSTRAINT CANDIDATE_FK FOREIGN KEY(ID_DMS_DOC) REFERENCES TDMS_DOC(ID_DMS_DOC);

Server

Add DMS dependencies

  • ontimize-examples
    • projectwiki-api
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IUserService.java
      • pom.xml
    • projectwiki-boot
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • projectwiki-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • projectwiki
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • placeholders.properties
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • projectwiki-ws
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

model/pom.xml

...
<dependencies>
  ...
  <dependency>
    <groupId>com.ontimize.jee.dms</groupId>
    <artifactId>ontimize-jee-dms-server</artifactId>
  </dependency>

  <dependency>
    <groupId>com.ontimize.jee.dms</groupId>
    <artifactId>ontimize-jee-dms-common</artifactId>
  </dependency>
  ...
</dependencies>
...

ws/pom.xml

...
<dependencies>
  ...
    <dependency>
        <groupId>com.ontimize.jee.dms</groupId>
        <artifactId>ontimize-jee-dms-rest</artifactId>
    </dependency>
  ...
</dependencies>
...

Add DMS DAO and modify Candidate DAO

A specific DAO will be created for each table in the DMS system, and each of them will implement a different interface. In turn, the candidate DAO will be modified to reflect the new column it contains.

  • ontimize-examples
    • projectwiki-api
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IUserService.java
      • pom.xml
    • projectwiki-boot
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • projectwiki-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • projectwiki
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • DMSCategoryDao.xml
              • DMSDocumentDao.xml
              • DMSDocumentFileDao.xml
              • DMSDocumentFileVersionDao.xml
              • DMSDocumentPropertyDao.xml
              • DMSRelatedDocumentDao.xml
              • placeholders.properties
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • projectwiki-ws
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

DMSCategoryDao.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<JdbcEntitySetup
  xmlns="http://www.ontimize.com/schema/jdbc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.ontimize.com/schema/jdbc http://www.ontimize.com/schema/jdbc/ontimize-jdbc-dao.xsd"
  catalog="" schema="${mainschema}" table="TDMS_DOC_CATEGORY"
  datasource="mainDataSource" sqlhandler="dbSQLStatementHandler">
  <DeleteKeys>
    <Column>ID_DMS_DOC_CATEGORY</Column>
  </DeleteKeys>
  <UpdateKeys>
    <Column>ID_DMS_DOC_CATEGORY</Column>
  </UpdateKeys>
  <GeneratedKey>ID_DMS_DOC_CATEGORY</GeneratedKey>
</JdbcEntitySetup>

DMSDocumentDao.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<JdbcEntitySetup
  xmlns="http://www.ontimize.com/schema/jdbc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.ontimize.com/schema/jdbc http://www.ontimize.com/schema/jdbc/ontimize-jdbc-dao.xsd"
  catalog="" schema="${mainschema}" table="TDMS_DOC"
  datasource="mainDataSource" sqlhandler="dbSQLStatementHandler">
  <DeleteKeys>
    <Column>ID_DMS_DOC</Column>
  </DeleteKeys>
  <UpdateKeys>
    <Column>ID_DMS_DOC</Column>
  </UpdateKeys>
  <GeneratedKey>ID_DMS_DOC</GeneratedKey>
</JdbcEntitySetup>

DMSDocumentFileDao.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?xml version="1.0" encoding="UTF-8"?>
<JdbcEntitySetup
  xmlns="http://www.ontimize.com/schema/jdbc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.ontimize.com/schema/jdbc http://www.ontimize.com/schema/jdbc/ontimize-jdbc-dao.xsd"
  catalog="" schema="${mainschema}" table="TDMS_DOC_FILE"
  datasource="mainDataSource" sqlhandler="dbSQLStatementHandler">
  <DeleteKeys>
    <Column>ID_DMS_DOC_FILE</Column>
  </DeleteKeys>
  <UpdateKeys>
    <Column>ID_DMS_DOC_FILE</Column>
  </UpdateKeys>
  <GeneratedKey>ID_DMS_DOC_FILE</GeneratedKey>
  <Queries>
    <Query id="default">
      <AmbiguousColumns>
        <AmbiguousColumn name="ID_DMS_DOC_FILE"
          prefix="tddf" />
        <AmbiguousColumn name="ID_DMS_DOC" prefix="tddf" />
      </AmbiguousColumns>
      <ValidColumns>
        <!-- TDMS_DOC_FILE -->
        <Column>ID_DMS_DOC_FILE</Column>
        <Column>FILE_NAME</Column>
        <Column>ID_DMS_DOC</Column>
        <Column>FILE_TYPE</Column>
        <Column>ID_DMS_DOC_CATEGORY</Column>
        <!-- TDMS_DOC -->
        <Column>ID_DMS_DOC</Column>
        <Column>UPDATE_DATE</Column>
        <Column>UPDATE_BY_ID</Column>
        <Column>DOC_NAME</Column>
        <Column>OWNER_ID</Column>
        <Column>DOC_DESCRIPTION</Column>
        <Column>DOC_KEYWORDS</Column>
        <!-- TDMS_DOC_FILE_VERSION -->
        <Column>ID_DMS_DOC_FILE_VERSION</Column>
        <Column>FILE_PATH</Column>
        <Column>VERSION</Column>
        <Column>FILE_DESCRIPTION</Column>
        <Column>IS_ACTIVE</Column>
        <Column>FILE_ADDED_DATE</Column>
        <Column>FILE_ADDED_USER_ID</Column>
        <Column>ID_DMS_DOC_FILE</Column>
        <Column>THUMBNAIL</Column>
        <Column>FILE_SIZE</Column>
      </ValidColumns>
      <Sentence>
        <![CDATA[
          SELECT
            #COLUMNS#
          FROM
            ${mainschema}.TDMS_DOC_FILE AS tddf
            JOIN ${mainschema}.TDMS_DOC AS tdd ON tddf.ID_DMS_DOC = tdd.ID_DMS_DOC
            LEFT JOIN ${mainschema}.TDMS_DOC_FILE_VERSION AS tddfv ON tddf.id_dms_doc_file = tddfv.id_dms_doc_file
          WHERE (tddfv.IS_ACTIVE = 'Y' OR tddfv.id_dms_doc_file_version IS NULL)
          #WHERE_CONCAT#
          #ORDER#
         ]]>
    </Sentence>
    </Query>
    <Query id="allfiles">
      <AmbiguousColumns>
        <AmbiguousColumn name="ID_DMS_DOC_FILE"
          prefix="tddf" />
      </AmbiguousColumns>
      <ValidColumns>
        <Column>ID_DMS_DOC_FILE</Column>
        <Column>FILE_NAME</Column>
        <Column>ID_DMS_DOC</Column>
        <Column>FILE_TYPE</Column>
        <Column>ID_DMS_DOC_CATEGORY</Column>
      </ValidColumns>
      <Sentence>
        <![CDATA[
          SELECT
            #COLUMNS#
          FROM
            ${mainschema}.TDMS_DOC_FILE AS tddf
          #WHERE#
          #ORDER#
         ]]>
    </Sentence>
    </Query>
  </Queries>
</JdbcEntitySetup>

DMSDocumentFileVersionDao.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?xml version="1.0" encoding="UTF-8"?>
<JdbcEntitySetup
  xmlns="http://www.ontimize.com/schema/jdbc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.ontimize.com/schema/jdbc http://www.ontimize.com/schema/jdbc/ontimize-jdbc-dao.xsd"
  catalog="" schema="${mainschema}" table="TDMS_DOC_FILE_VERSION"
  datasource="mainDataSource" sqlhandler="dbSQLStatementHandler">
  <DeleteKeys>
    <Column>ID_DMS_DOC_FILE_VERSION</Column>
  </DeleteKeys>
  <UpdateKeys>
    <Column>ID_DMS_DOC_FILE_VERSION</Column>
  </UpdateKeys>
  <GeneratedKey>ID_DMS_DOC_FILE_VERSION</GeneratedKey>
  <Queries>
    <Query id="default">
      <AmbiguousColumns>
        <AmbiguousColumn name="ID_DMS_DOC_FILE"
          prefix="tddfv" />
      </AmbiguousColumns>
      <ValidColumns>
        <!-- TDMS_DOC_FILE_VERSION -->
        <Column>ID_DMS_DOC_FILE_VERSION</Column>
        <Column>FILE_PATH</Column>
        <Column>VERSION</Column>
        <Column>FILE_DESCRIPTION</Column>
        <Column>IS_ACTIVE</Column>
        <Column>FILE_ADDED_DATE</Column>
        <Column>FILE_ADDED_USER_ID</Column>
        <Column>ID_DMS_DOC_FILE</Column>
        <Column>THUMBNAIL</Column>
        <Column>FILE_SIZE</Column>
        <!-- TDMS_DOC_FILE -->
        <Column>ID_DMS_DOC_FILE</Column>
        <Column>FILE_NAME</Column>
        <Column>ID_DMS_DOC</Column>
        <Column>FILE_TYPE</Column>
        <Column>ID_DMS_DOC_CATEGORY</Column>
      </ValidColumns>
      <Sentence>
        <![CDATA[
           SELECT
             #COLUMNS#
        FROM
          ${mainschema}.TDMS_DOC_FILE_VERSION AS tddfv
          LEFT JOIN ${mainschema}.TDMS_DOC_FILE AS tddf ON tddfv.ID_DMS_DOC_FILE = tddf.ID_DMS_DOC_FILE
        #WHERE#
        #ORDER#
         ]]>
      </Sentence>
    </Query>
  </Queries>
</JdbcEntitySetup>

DMSDocumentPropertyDao.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<JdbcEntitySetup
  xmlns="http://www.ontimize.com/schema/jdbc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.ontimize.com/schema/jdbc http://www.ontimize.com/schema/jdbc/ontimize-jdbc-dao.xsd"
  catalog="" schema="${mainschema}" table="TDMS_DOC_PROPERTY"
  datasource="mainDataSource" sqlhandler="dbSQLStatementHandler">
  <DeleteKeys>
    <Column>ID_DMS_DOC_PROPERTY</Column>
  </DeleteKeys>
  <UpdateKeys>
    <Column>ID_DMS_DOC_PROPERTY</Column>
  </UpdateKeys>
  <GeneratedKey>ID_DMS_DOC_PROPERTY</GeneratedKey>
</JdbcEntitySetup>

DMSRelatedDocumentDao.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<JdbcEntitySetup
  xmlns="http://www.ontimize.com/schema/jdbc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.ontimize.com/schema/jdbc http://www.ontimize.com/schema/jdbc/ontimize-jdbc-dao.xsd"
  catalog="" schema="${mainschema}" table="TDMS_RELATED_DOC"
  datasource="mainDataSource" sqlhandler="dbSQLStatementHandler">
  <DeleteKeys>
    <Column>ID_DMS_RELATED_PROPERTY</Column>
  </DeleteKeys>
  <UpdateKeys>
    <Column>ID_DMS_RELATED_PROPERTY</Column>
  </UpdateKeys>
  <GeneratedKey>ID_DMS_RELATED_PROPERTY</GeneratedKey>
</JdbcEntitySetup>
  • ontimize-examples
    • projectwiki-api
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IUserService.java
      • pom.xml
    • projectwiki-boot
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • projectwiki-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • projectwiki
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • DMSCategoryDao.java
                        • DMSDocumentDao.java
                        • DMSDocumentFileDao.java
                        • DMSDocumentFileVersionDao.java
                        • DMSDocumentPropertyDao.java
                        • DMSRelatedDocumentDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • DMSCategoryDao.xml
              • DMSDocumentDao.xml
              • DMSDocumentFileDao.xml
              • DMSDocumentFileVersionDao.xml
              • DMSDocumentPropertyDao.xml
              • DMSRelatedDocumentDao.xml
              • placeholders.properties
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • projectwiki-ws
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

CandidateDao.java

...
public class CandidateDao extends OntimizeJdbcDaoSupport {
  ...
  public static final String ATTR_ID_DMS_DOC = "ID_DMS_DOC";
}

DMSCategoryDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.ontimize.projectwiki.model.core.dao;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import com.ontimize.jee.server.dao.common.ConfigurationFile;
import com.ontimize.jee.server.dao.jdbc.OntimizeJdbcDaoSupport;
import com.ontimize.jee.server.services.dms.dao.IDMSCategoryDao;

@Repository("DMSCategoryDao")
@Lazy
@ConfigurationFile(configurationFile = "dao/DMSCategoryDao.xml", configurationFilePlaceholder = "dao/placeholders.properties")
public class DMSCategoryDao extends OntimizeJdbcDaoSupport implements IDMSCategoryDao {

  public static final String ATTR_ID_DMS_DOC_CATEGORY = "ID_DMS_DOC_CATEGORY";
  public static final String ATTR_ID_DMS_DOC = "ID_DMS_DOC";
  public static final String ATTR_ID_DMS_DOC_CATEGORY_PARENT = "ID_DMS_DOC_CATEGORY_PARENT";
  public static final String ATTR_CATEGORY_NAME = "CATEGORY_NAME";

}

DMSDocumentDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.ontimize.projectwiki.model.core.dao;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import com.ontimize.jee.server.dao.common.ConfigurationFile;
import com.ontimize.jee.server.dao.jdbc.OntimizeJdbcDaoSupport;
import com.ontimize.jee.server.services.dms.dao.IDMSDocumentDao;

@Repository("DMSDocumentDao")
@Lazy
@ConfigurationFile(configurationFile = "dao/DMSDocumentDao.xml", configurationFilePlaceholder = "dao/placeholders.properties")
public class DMSDocumentDao extends OntimizeJdbcDaoSupport implements IDMSDocumentDao {

  public static final String ATTR_ID_DMS_DOC = "ID_DMS_DOC";
  public static final String ATTR_UPDATE_DATE = "UPDATE_DATE";
  public static final String ATTR_UPDATE_BY_ID = "UPDATE_BY_ID";
  public static final String ATTR_DOC_NAME = "DOC_NAME";
  public static final String ATTR_OWNER_ID = "OWNER_ID";
  public static final String ATTR_DOC_DESCRIPTION = "DOC_DESCRIPTION";
  public static final String ATTR_DOC_KEYWORDS = "DOC_KEYWORDS";

}

DMSDocumentFileDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.ontimize.projectwiki.model.core.dao;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import com.ontimize.jee.server.dao.common.ConfigurationFile;
import com.ontimize.jee.server.dao.jdbc.OntimizeJdbcDaoSupport;
import com.ontimize.jee.server.services.dms.dao.IDMSDocumentFileDao;

@Repository("DMSDocumentFileDao")
@Lazy
@ConfigurationFile(configurationFile = "dao/DMSDocumentFileDao.xml", configurationFilePlaceholder = "dao/placeholders.properties")
public class DMSDocumentFileDao extends OntimizeJdbcDaoSupport implements IDMSDocumentFileDao{

  public static final String ATTR_ID_DMS_DOC_FILE = "ID_DMS_DOC_FILE";         
  public static final String ATTR_FILE_NAME = "FILE_NAME";         
  public static final String ATTR_ID_DMS_DOC = "ID_DMS_DOC";         
  public static final String ATTR_FILE_TYPE = "FILE_TYPE";         
  public static final String ATTR_ID_DMS_DOC_CATEGORY = "ID_DMS_DOC_CATEGORY";         
    
}

DMSDocumentFileVersionDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.ontimize.projectwiki.model.core.dao;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import com.ontimize.jee.server.dao.common.ConfigurationFile;
import com.ontimize.jee.server.dao.jdbc.OntimizeJdbcDaoSupport;
import com.ontimize.jee.server.services.dms.dao.IDMSDocumentFileVersionDao;

@Repository("DMSDocumentFileVersionDao")
@Lazy
@ConfigurationFile(configurationFile = "dao/DMSDocumentFileVersionDao.xml", configurationFilePlaceholder = "dao/placeholders.properties")
public class DMSDocumentFileVersionDao extends OntimizeJdbcDaoSupport implements IDMSDocumentFileVersionDao {

  public static final String ATT_ID_DMS_DOC_FILE_VERSION = "ID_DMS_DOC_FILE_VERSION";
  public static final String ATT_FILE_PATH = "FILE_PATH";
  public static final String ATT_VERSION = "VERSION";
  public static final String ATT_FILE_DESCRIPTION = "FILE_DESCRIPTION";
  public static final String ATT_IS_ACTIVE = "IS_ACTIVE";
  public static final String ATT_FILE_ADDED_DATE = "FILE_ADDED_DATE";
  public static final String ATT_FILE_ADDED_USER_ID = "FILE_ADDED_USER_ID";
  public static final String ATT_ID_DMS_DOC_FILE = "ID_DMS_DOC_FILE";
  public static final String ATT_THUMBNAIL = "THUMBNAIL";
  public static final String ATT_FILE_SIZE = "FILE_SIZE";

}

DMSDocumentPropertyDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.ontimize.projectwiki.model.core.dao;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import com.ontimize.jee.server.dao.common.ConfigurationFile;
import com.ontimize.jee.server.dao.jdbc.OntimizeJdbcDaoSupport;
import com.ontimize.jee.server.services.dms.dao.IDMSDocumentPropertyDao;

@Repository("DMSDocumentPropertyDao")
@Lazy
@ConfigurationFile(configurationFile = "dao/DMSDocumentPropertyDao.xml", configurationFilePlaceholder = "dao/placeholders.properties")
public class DMSDocumentPropertyDao extends OntimizeJdbcDaoSupport implements IDMSDocumentPropertyDao {

  public static final String ATTR_ID_DMS_DOC_PROPERTY = "ID_DMS_DOC_PROPERTY";
  public static final String ATTR_DOC_PROPERTY_KEY = "DOC_PROPERTY_KEY";
  public static final String ATTR_DOC_PROPERTY_VALUE = "DOC_PROPERTY_VALUE";
  public static final String ATTR_ID_DMS_DOC = "ID_DMS_DOC";

}

DMSRelatedDocumentDao.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.ontimize.projectwiki.model.core.dao;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import com.ontimize.jee.server.dao.common.ConfigurationFile;
import com.ontimize.jee.server.dao.jdbc.OntimizeJdbcDaoSupport;
import com.ontimize.jee.server.services.dms.dao.IDMSRelatedDocumentDao;

@Repository("DMSRelatedDocumentDao")
@Lazy
@ConfigurationFile(configurationFile = "dao/DMSRelatedDocumentDao.xml", configurationFilePlaceholder = "dao/placeholders.properties")
public class DMSRelatedDocumentDao extends OntimizeJdbcDaoSupport implements IDMSRelatedDocumentDao {

  public static final String ATTR_ID_DMS_RELATED_PROPERTY = "ID_DMS_RELATED_PROPERTY";
  public static final String ATTR_ID_DMS_DOC_MASTER = "ID_DMS_DOC_MASTER";
  public static final String ATTR_ID_DMS_DOC_CHILD = "ID_DMS_DOC_CHILD";

}

Modify CandidateService insert method

The method of inserting new candidates will be modified so that, when inserting them, they will have a workspace to maintain the files to be uploaded associated with the inserted candidate.

  • ontimize-examples
    • projectwiki-api
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IUserService.java
      • pom.xml
    • projectwiki-boot
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • projectwiki-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • projectwiki
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • DMSCategoryDao.java
                        • DMSDocumentDao.java
                        • DMSDocumentFileDao.java
                        • DMSDocumentFileVersionDao.java
                        • DMSDocumentPropertyDao.java
                        • DMSRelatedDocumentDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • DMSCategoryDao.xml
              • DMSDocumentDao.xml
              • DMSDocumentFileDao.xml
              • DMSDocumentFileVersionDao.xml
              • DMSDocumentPropertyDao.xml
              • DMSRelatedDocumentDao.xml
              • placeholders.properties
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • projectwiki-ws
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • MainRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

CandidateService.java

...
import com.ontimize.jee.common.exceptions.DmsException;
import com.ontimize.jee.common.naming.DMSNaming;
import com.ontimize.jee.common.services.dms.DocumentIdentifier;
import com.ontimize.jee.server.services.dms.DMSCreationHelper;
...

@Service("CandidateService")
@Lazy
public class CandidateService implements ICandidateService {

  ...

  @Autowired
  private DMSCreationHelper dmsHelper;

  ...

  @Override
  public EntityResult candidateInsert(Map<String, Object> attrMap) throws OntimizeJEERuntimeException {

    try {
    DocumentIdentifier docId = this.dmsHelper.createDocument((String) attrMap.get(CandidateDao.ATTR_DNI));
    attrMap.put(DMSNaming.DOCUMENT_ID_DMS_DOCUMENT, docId.getDocumentId());
    } catch (DmsException e) {
      throw new OntimizeJEERuntimeException("ERROR_CREATING_DMS_DOC", e);
    }

    return this.daoHelper.insert(this.candidateDao, attrMap);
  }

  ...
}

Add File Manager Rest Controller

  • ontimize-examples
    • projectwiki-api
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IUserService.java
      • pom.xml
    • projectwiki-boot
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • projectwiki-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • projectwiki
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • DMSCategoryDao.java
                        • DMSDocumentDao.java
                        • DMSDocumentFileDao.java
                        • DMSDocumentFileVersionDao.java
                        • DMSDocumentPropertyDao.java
                        • DMSRelatedDocumentDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • DMSCategoryDao.xml
              • DMSDocumentDao.xml
              • DMSDocumentFileDao.xml
              • DMSDocumentFileVersionDao.xml
              • DMSDocumentPropertyDao.xml
              • DMSRelatedDocumentDao.xml
              • placeholders.properties
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • projectwiki-ws
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • DMSNameConverter.java
                        • FileManagerRestController.java
                        • MainRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

DMSNameConverter.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.ontimize.projectwiki.ws.core.rest;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ontimize.jee.common.naming.DMSNaming;
import com.ontimize.jee.server.dms.model.OFile;
import com.ontimize.jee.server.dms.rest.IDMSNameConverter;

@Service("DMSNameConverter")
public class DMSNameConverter implements IDMSNameConverter {

  @Override
  public Object getFileIdColumn() {
    return DMSNaming.DOCUMENT_FILE_ID_DMS_DOCUMENT_FILE;
  }

  @Override
  public Object getFileNameColumn() {
    return DMSNaming.DOCUMENT_FILE_NAME;
  }

  @Override
  public Object getFileSizeColumn() {
    return DMSNaming.DOCUMENT_FILE_VERSION_FILE_SIZE;
  }

  @Override
  public Object getCategoryIdColumn() {
    return DMSNaming.CATEGORY_ID_CATEGORY;
  }

  @Override
  public Object getCategoryNameColumn() {
    return DMSNaming.CATEGORY_CATEGORY_NAME;
  }

  @Override
  public OFile createOFile(Map<?, ?> params) {
    OFile file = new OFile();
    file.setId((Integer) params.get(DMSNaming.DOCUMENT_FILE_ID_DMS_DOCUMENT_FILE));
    file.setName((String) params.get(DMSNaming.DOCUMENT_FILE_NAME));
    file.setType((String) params.get(DMSNaming.DOCUMENT_FILE_TYPE));
    file.setSize((Integer) params.get(DMSNaming.DOCUMENT_FILE_VERSION_FILE_SIZE));
    file.setCreationDate(((Date) params.get(DMSNaming.DOCUMENT_FILE_VERSION_FILE_ADDED_DATE)).getTime());
    file.setDirectory(false);
    return file;
  }

  @Override
  public List<?> getFileColumns(List<?> columns) {
    return Arrays.asList(DMSNaming.DOCUMENT_FILE_ID_DMS_DOCUMENT_FILE, DMSNaming.DOCUMENT_FILE_NAME,
        DMSNaming.DOCUMENT_FILE_TYPE, DMSNaming.DOCUMENT_FILE_VERSION_FILE_SIZE,
        DMSNaming.DOCUMENT_FILE_VERSION_FILE_ADDED_DATE);
  }

  @Override
  public List<?> getCategoryColumns(List<?> columns) {
    return Arrays.asList(DMSNaming.CATEGORY_ID_CATEGORY, DMSNaming.CATEGORY_CATEGORY_NAME,
        DMSNaming.CATEGORY_ID_CATEGORY_PARENT);
  }

}

FileManagerRestController.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.ontimize.projectwiki.ws.core.rest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ontimize.jee.common.services.dms.IDMSService;
import com.ontimize.jee.server.dms.rest.DMSRestController;
import com.ontimize.jee.server.dms.rest.IDMSNameConverter;

@RestController
@RequestMapping("/filemanager")
@ComponentScan(basePackageClasses = { com.ontimize.jee.common.services.dms.IDMSService.class,
    com.ontimize.jee.server.dms.rest.IDMSNameConverter.class })
public class FileManagerRestController extends DMSRestController<IDMSService, IDMSNameConverter> {

  @Autowired
  private IDMSService dmsService;

  @Override
  public IDMSService getService() {
    return this.dmsService;
  }

}

Modify application.yml

The application.yml file will be modified to indicate the path where the dms files will be stored and the engine it will use. In this link you have information about the configuration of the DMS system in the application.yml file.

Note: The path specified in the basePath variable must exist before the server is started.

  • ontimize-examples
    • projectwiki-api
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • api
                    • core
                      • service
                        • ICandidateService.java
                        • IUserService.java
      • pom.xml
    • projectwiki-boot
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ServerApplication.java
          • resources
            • application.yml
      • pom.xml
    • projectwiki-model
      • src
        • main
          • db
            • templateDB.properties
            • templateDB.txt
          • java
            • com
              • ontimize
                • projectwiki
                  • model
                    • core
                      • dao
                        • CandidateDao.java
                        • DMSCategoryDao.java
                        • DMSDocumentDao.java
                        • DMSDocumentFileDao.java
                        • DMSDocumentFileVersionDao.java
                        • DMSDocumentPropertyDao.java
                        • DMSRelatedDocumentDao.java
                        • UserDao.java
                        • UserRoleDao.java
                      • service
                        • CandidateService.java
                        • UserService.java
          • resources
            • dao
              • CandidateDao.xml
              • DMSCategoryDao.xml
              • DMSDocumentDao.xml
              • DMSDocumentFileDao.xml
              • DMSDocumentFileVersionDao.xml
              • DMSDocumentPropertyDao.xml
              • DMSRelatedDocumentDao.xml
              • placeholders.properties
              • RoleDao.xml
              • RoleServerPermissionDao.xml
              • ServerPermissionDao.xml
              • UserDao.xml
              • UserRoleDao.xml
      • pom.xml
    • projectwiki-ws
      • src
        • main
          • java
            • com
              • ontimize
                • projectwiki
                  • ws
                    • core
                      • rest
                        • CandidateRestController.java
                        • DMSNameConverter.java
                        • FileManagerRestController.java
                        • MainRestController.java
                        • TestRestController.java
                        • UserRestController.java
      • pom.xml
    • .gitignore
    • pom.xml
    • README.md

application.yml

ontimize:
   dms:
      engine: odms
      basePath: file:/C:/applications/projectwiki/dms

Add permissions

It is necessary to add the permissions required for the role associated with the user to be able to execute REST requests, which are secured. For the example, we will add all the methods and give access to the demo user role.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileGetContentOfVersion');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentGetProperty');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileRecoverPreviousVersion');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentDeleteProperties');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentGetProperties');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentGetAllFiles');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/setRelatedDocuments');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentAddProperties');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/getRelatedDocument');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/categoryGetForDocument');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/moveFilesToCategory');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileVersionQuery');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentQuery');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentInsert');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentUpdate');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentGetFiles');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/categoryInsert');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileInsert');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/categoryUpdate');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/categoryDelete');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileDelete');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileGetVersions');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileGetContent');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileUpdate');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/documentDelete');
INSERT INTO TSERVER_PERMISSION (PERMISSION_NAME) VALUES('com.ontimize.jee.server.services.dms.DMSServiceImpl/fileQuery');

Add all permissions to the user role demo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
INSERT
	INTO
	PUBLIC.PUBLIC.TROLE_SERVER_PERMISSION tsp (ID_SERVER_PERMISSION, ID_ROLENAME)
SELECT
	ID_SERVER_PERMISSION,
	(
	SELECT
		ID_ROLENAME
	FROM
		TUSER_ROLE
	WHERE
		USER_ = 'demo') AS ID_ROLENAME
FROM
	TSERVER_PERMISSION tp
LEFT JOIN TROLE_SERVER_PERMISSION tsp ON
	tp.ID_SERVER_PERMISSION = tsp.ID_SERVER_PERMISSION
WHERE
	tsp.ID_SERVER_PERMISSION IS NULL