## UIL migration Project

- **uil-migration** - parent project
 - **uil-migration-common** - project with classes that are common to other projects.
 - **uil-migration-common-db** - project with common database classes that other projects use.
 - **uil-migration-common-jndi** - project with common jndi classes that other projects use.
 - **uil-migration-alfersco** - project for importing files to Alfresco.
 - **uil-migration-persons** - project for migrating persons.
 - **uil-migration-staging** - project for migrating from staging database.

### Building project
Firstly open **pom.xml** file and set property **distribution.dir** to folder where you want the result files to be placed:
```
<properties>
    <distribution.dir>YOUR_DIR_LOCATION</distribution.dir>
</properties>
```
Then build project with command:
```
mvn clean install
```

After build your distribution folder should contain 3 new folders (alfresco, persons, staging), inside those folders should be .jar file and .properties files.
 - YOUR_DIR_LOCATION
  - alfresco
    - uil-migration-alfresco-1.0.jar
    - alfresco-application.properties
    - log4j.properties
  - persons
    - uil-migration-persons-1.0.jar
    - persons-application.properties
    - log4j.properties
  - staging
    - uil-migration-stgging-1.0.jar
    - staging-application.properties
    - log4j.properties

### Running project

 #### Alfresco

First set properties in file **YOUR_DIR_LOCATION/alfresco/alfresco-application.properties** then run command:
 - Trademark images:
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=TM_IMAGE FOLDER_PATH=xxxxx
```
 - Design images
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=DS_IMAGE DS_XML_FILE=xxxxx
```
 - Letters:
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=LETTER FOLDER_PATH=xxxxx
```
 - Generate empty publication xml:
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=EMPTY_PUBLICATION_XML PUB_XML_FILE=xxxxx
```

- Generate empty pdf used for dossiers in stagging migration (note that on classpath must exists file with name empty_letter.pdf 
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=EMPTY_LETTER_PDF 
```

- Generate empty image used for dossiers in stagging migration (note that on classpath must exists file with name empty_image.jpg 
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=EMPTY_IMAGE 
```

- Count all files in Alfresco migrated folder
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=COUNT_FILES
```

For logging properties, set the **log4j.properties** file.

After running the process three new files should appear in **YOUR_DIR_LOCATION/alfresco/** folder (where *TYPE* is the input parameter and *TIMESTAMP* is the time when process has finished):
  - **TYPE_log_TIMESTAMP.txt**: List of successfully and unsuccessfully imported files with file info and error description if there was any. It also contains the count of documents processed and time taken.
  - **TYPE_result_TIMESTAMP.csv**: It's CSV file of successfully imported files with informations of names and ids.
  - **TYPE_statistic_TIMESTAMP.txt**: Count of successfully imported files by type.


 #### Persons

 First set properties in file **YOUR_DIR_LOCATION/persons/persons-application.properties**. Make sure that you have defined application user in BO Wildfly with permissions to call EJB then run command:

 - Basic run
 ```
 java -jar uil-migration-persons-1.0.jar --spring.config.location=persons-application.properties RECORD_NUMBER=xxxxx
 ```

- Continue run
```
java -jar uil-migration-persons-1.0.jar --spring.config.location=persons-application.properties RECORD_NUMBER=xxxxx CSV_FILE=xxxxx
```

- Add empty person run
```
java -jar uil-migration-persons-1.0.jar --spring.config.location=persons-application.properties ADD_EMPTY_PERSON=true
```

Note that parameter **RECORD_NUMBER** is number of master records to process, not the total number of persons to process. Total number of processed persons will probably be higher because one master person has more related persons which are all processed. Set this parameter to zero if you don't want to limit number of records to process.

Set parameter **CSV_FILE** if you wish to continue process. Value of the parameter is the path to the csv file that was created by previous process. All records in given csv file will be skipped and n new records will be processed (value of parameter RECORD_NUMBER).

 For logging properties, set the **log4j.properties** file.

 After running the process three new files should appear in **YOUR_DIR_LOCATION/persons/** folder (where *TIMESTAMP* is the time when process has finished):
   - **PERSONS_log_TIMESTAMP.txt**: List of successfully and unsuccessfully imported persons with person info and error description if there was any. It also contains the process time taken.
   - **PERSONS_result_TIMESTAMP.csv**: It's CSV file of successfully imported persons with informations of ids.
   - **PERSONS_statistic_TIMESTAMP.txt**: Count of successfully imported persons.



 #### Staging
 
First set properties in file **YOUR_DIR_LOCATION/staging/staging-application.properties**. Make sure that you have defined application user in BO Wildfly with permissions to call EJB then run command:

 - Basic run for Trademark migration
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_TM RECORD_NUMBER=1
 ```

 - Basic run for Design migration
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_DS RECORD_NUMBER=1
 ```

 - Basic run for Oppositions migration
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_OPPOSITION RECORD_NUMBER=1
 ```

- Basic run for TM Cancellations migration
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_TM_CANCELLATION RECORD_NUMBER=1
 ```

- Basic run for DS Cancellations migration
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_DS_CANCELLATION RECORD_NUMBER=1
 ```

- Basic run for TM Appeals migration
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_TM_APPEAL RECORD_NUMBER=1
 ```

- Basic run for DS Appeals migration
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_DS_APPEAL RECORD_NUMBER=1
 ```

- Basic run for TM Recordal - Renewal
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_TM_RECORDAL_RENEWAL RECORD_NUMBER=1
 ```

- Basic run for DS Recordal - Renewal
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_DS_RECORDAL_RENEWAL RECORD_NUMBER=1
 ```

- Basic run for TM Recordal - Limitation
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_TM_RECORDAL_LIMITATION RECORD_NUMBER=1
 ```

- Basic run for DS Recordal - Limitation
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_DS_RECORDAL_LIMITATION RECORD_NUMBER=1
 ```

- Basic run for TM Recordal - Other
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_TM_RECORDAL RECORD_NUMBER=1
 ```

- Basic run for DS Recordal - Other
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_DS_RECORDAL RECORD_NUMBER=1
 ```

- Basic run for TM Recordal - Generic
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_TM_RECORDAL_GENERIC RECORD_NUMBER=1
 ```

- Basic run for DS Recordal - Generic
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_DS_RECORDAL_GENERIC RECORD_NUMBER=1
 ```

- Basic run for IA
 ```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=STAGING_IA RECORD_NUMBER=1
 ```

- Continue run
```
 java -jar uil-migration-staging-1.0.jar --spring.config.location=staging-application.properties TYPE=XXX RECORD_NUMBER=xxxxx CSV_FILE=xxxxx
```

Note that parameter **RECORD_NUMBER** is mandatory. Set this parameter to zero if you don't want to limit number of records to process.

Set parameter **CSV_FILE** if you wish to continue process. Value of the parameter is the path to the csv file that was created by previous process. All records in given csv file will be skipped and n new records will be processed (value of parameter RECORD_NUMBER).

 For logging properties, set the **log4j.properties** file.

 After running the process four new files should appear in **YOUR_DIR_LOCATION/staging/** folder (where *TIMESTAMP* is the time when process has finished):
   - **STAGING_log_TIMESTAMP.txt**: List of successfully and unsuccessfully imported dossiers with dossier info and error description if there was any. It also contains the process time taken.
   - **STAGING_result_TIMESTAMP.csv**: It's CSV file of successfully imported dossiers with informations of ids.
   - **STAGING_statistic_TIMESTAMP.txt**: Count of successfully imported dossiers.
   - **STAGING_missing_letter_doc_TIMESTAMP.csv**: List of letters where document could not be found.


Before running Staging part of migration you should complete Alfresco and Persons part of migration.
Staging migration methods expects documents to be loaded on Alfresco and added to database.
At this point is also expected that empty publication xml and empty pdf for letters is created.
Use commands (for details see Alfresco section):

 - empty letter pdf: 
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=EMPTY_LETTER_PDF 
```

 - empty publication xml:
```
java -jar uil-migration-alfresco-1.0.jar --spring.config.location=alfresco-application.properties TYPE=EMPTY_PUBLICATION_XML PUB_XML_FILE=xxxxx
```

In some cases BO persons are mandatory (for example appelant on appeal dossier) but source database doesn't have this information. 
In this case migration process adds empty person to dossier. This person is not active so the user can't use it.
Staging process finds this person by identifier defined in MigrationConstants.java class.
To add this person to BO use command in Persons part of migration:

- empty person:
```
java -jar uil-migration-persons-1.0.jar --spring.config.location=persons-application.properties ADD_EMPTY_PERSON=true
```