...
Checking the .yaml file
If you have not yet done so, clone the frontend repository from github.
Change directories to the following: frontend/restapi
Open the file called: DMCInterfaceSwagger.yaml
Check and make sure that the .yaml file has information about your endpoint already there.
If it is missing, you will need to update your endpoint to reflect your code after it is completed.
Working on the data base
Follow the instructions listed above for creating a local database and connect to the database using pgAdmin (make sure you are on your own branch).
Open the folder structure as such: Server Groups → Servers → <Local Database running with postgres> → Databases → gforge → Schemas → public → Tables
Locate the table(s) that will be required for your endpoint(s) to function
If your table(s) is missing or has missing or incorrect column names or types, or does not have existing sample data, you will need to do the following
You will need to generate the code required to create your table. To do this do the following
In pgadmin, right click the tables folder and choose new table.
Under properties, fill out the table name (table should use lowercase characters only)(the norm for table names with more than one word should look like this: multiple_word_table_name).
Under columns, click add to create a new column. Fill out the name field (do not use camel case here, follow the same convention as used in the step above) and chose a type for the field such as: text, date, integer, or serial (generally used for ids).
When creating an id column that should generate an id on its own, do the following
Create the column with a name and the type of serial.
Click on the constraints tab.
Make sure Primary Key is selected from the drop-down menu.
Click Add.
In the new window, click on the columns tab
In the column drop-down menu, choose the name of the column.
Find the table that you created in the tables folder in pgadmin.
Click on the table name and then click on the table icon (7th icon from the top left of the window).
This is a view of what your table will look like
At the bottom of the pgadmin window, there is a pane with code. Copy this code.
- With postgres still running, run the following command:
Code Block language bash firstline 1 title This command will show you the full list of migrations for table data linenumbers true ./flyway clean migrate info -configFile=conf/core/flyway.conf -url=jdbc:postgresql://localhost:5432/gforge -user=gforge -password=gforge
Code Block language bash firstline 1 title This command will show you the full list of migrations for sample data linenumbers true ./flyway info -configFile=conf/data/flyway.conf -url=jdbc:postgresql://localhost:5432/gforge -user=gforge -password=gforge -locations=filesystem:./sql/data/dev2
- Thus the lists generated by the commands above to name your database table files and database sample data files such that they are one migration number higher. This will be covered again momentarily.
You will now update 3 files in the database. File names and locations are as follows:
dmcdb/sql/core/tables
Create a new table file.
- If the highest version listed from the ./flyway info -configFile=conf/core/flyway.conf command was 1.0081, the new file should be named V1_0082__<table_name>.psql
- V1 is the version number
- 0081 is the migration number
- If the highest version listed from the ./flyway info -configFile=conf/core/flyway.conf command was 1.0081, the new file should be named V1_0082__<table_name>.psql
Edit the file and paste the code that you copied in the step above here.
Cut the line that says CONSTRAINT table_name_PKEY PRIMARY KEY (id)
erase the lines: )WITH ( UIDS=FALSE
Save the file.
/dmcdb/sql/core/constraints/
Create a new primary_key_constraints file.
- Just like the new table file make sure the new file has a migration number that is one higher than the table name file.
- If the table file you just created is called V1_0082__example_table.psql, the new constrains file should be named V1_0083__primary_key_constrains.psql
- __primary_key_constraints.psql should never change on the version or migration number should.
- Just like the new table file make sure the new file has a migration number that is one higher than the table name file.
Add the following lines to the file:
Code Block language bash firstline 1 linenumbers true - -Name: table_name_pkey; Type: CONSTRAINT; Schema: public; Owner: gforge; Tablespace: - ALTER TABLE ONLY <table_name> ADD <paste what you cut earlier here>;
Save the file.
dmcdb/data/dev2/
Create a new sample data file.
- If the highest version listed from the ./flyway info -configFile=conf/data/flyway.conf command was 1.0014, the new file should be named V1_0015__<sample_data_name>.psql
- V1 is the version number
- 0015 is the migration number
- If the highest version listed from the ./flyway info -configFile=conf/data/flyway.conf command was 1.0014, the new file should be named V1_0015__<sample_data_name>.psql
Add three lines of sample data here. Use the following as an example for syntax
insert into table_name (column_name one, column_name_two) values ('text', 'textAlso');
Explanation:
table_name: use the name of your table here in its place.
The column names should be listed in order separated by commas.
The sample data must be listed in the same order as you list the column names.
Text data should be quoted using apostrophes and separated by commas. Numbers should not be quoted at all.
The id that should be auto generated should not be listed in the column name or the sample data.
Rerun postgres commands to drop database, create a database, check that the data base was created, add the tables to the database, and add the sample data.
Remember, you can not use the above commands if you are connected to the database with pgadmin, you will need to close pgAdmin, run the commands and then reopen pgAdmin..
- At the bottom of this page there is a bash script for dropping your database, creating a new database, checking that the database exists, filling the tables and filling the sample data.
Check to make sure you can open your table and that it has sample data in it. Also try to add another line of information. pgAdmin should handle generating the serial id, and the next line.
Once you've confirmed the information in the database is correct and updated you can now start working on your code.
Working on your code
Make sure that if you have not yet cloned the restservices repository from GitHub, that you do so now.
Also, make sure you create a new branch from the master branch.
Open Eclipse
Refresh Eclipse
Testing your code with swagger
Manual
Code Block title Depricated Instructions collapse true Once you have code you would like to test, start drop and rebuild your local database. Next, fine the Config.java file located in the following directory: restservices/src/main/java/org/dmc/services/ Change the first 6 lines to be the following: public static final String DB_PORT = "5432"; public static final String DB_IP = "127.0.0.1"; public static final String DB_HOST = "jdbc:postgresql://" + DB_IP; public static final String DB_NAME = "gforge"; public static final String DB_USER = "gforge"; public static final String DB_PASS = "gforge"; Save the changes in this file. Next, add the following to the bottom of your /etc/profile file by using the command:sudo nano /etc/profile Run the command: source /etc/profile export DBip="127.0.0.1" export DBport=5432 export DBuser="gforge" export DBpass="gforge" export SOLR_BASE_URL="http://<SOLR IP Address>/solr" export ActiveMQ_URL="<ActiveMQ IP Address>" export ActiveMQ_Port=61616 export ActiveMQ_User="active" export ActiveMQ_Password="active" Next update the following file restservices/src/main/java/org/dmc/services/Application.javaAll references to DB under the @Beam should be replaced with the following: ds.setUser(Config.DB_USER); ds.setPassword(Config.DB_PASS); ds.setServerName(Config.DB_IP); ds.setPortNumber(Integer.parseInt(Config.DB_PORT)); ds.setDatabaseName(Config.DB_NAME); Finally on debian operating systems update the file /etc/default/tomcat7 (also add this to the /etc/tomcat7/tomcat.conf file as well) Add the following to the bottom of the file: DBip="127.0.0.1" DBport=5432 DBuser="gforge" DBpass="gforge" SOLR_BASE_URL="http://<SOLR IP Address>/solr" ActiveMQ_URL="A<ctiveMQ IP Address>" ActiveMQ_Port=61616 ActiveMQ_User="active" Note that the above system environments do include IP addresses from live SOLR and ActiveMQ machines. If the above addresses do not work you will need to get these IP address from a DMC developer Next, go to the restservices directory. Run the command: sudo service tomcat stop Next, run the command: mvn package -P swagger When the .war file build is complete, go to the following directory: /var/lib/tomcat7/webapps If there are any files in the webapps folder, delete them. The command to do this is: sudo -r * Next, go to the following directory restservices/target/ Rename the file named: dmc-site-services-0.1.0-swagger.war to rest.war; you can use the following command to do so: mv dmc-site-services-0.1.0-swagger.war rest.war Move the rest.war file to the /var/lib/tomcat7/webapps/ folder using the following command: sudo mv rest.war /var/lib/tomcat7/webapps/ Now start tomcat using the following command: sudo service tomcat7 start Go to the following URL in a browser: localhost:8080/rest/services/2 or http://localhost:8080/rest/swagger-ui.html. This may take some time to load. Wait a few moments.
Automatic
Once you have code you would like to test, start drop and rebuild your local database.
Next, fine the Config.java file located in the following directory.
restservices/src/main/java/org/dmc/services/
Change the first 6 lines to be the following.
Code Block firstline 1 linenumbers true public static final String DB_PORT = "5432"; public static final String DB_IP = "127.0.0.1"; public static final String DB_HOST = "jdbc:postgresql://" + DB_IP; public static final String DB_NAME = "gforge"; public static final String DB_USER = "gforge"; public static final String DB_PASS = "gforge";
Save the changes in this file.
- Next, add the following to the bottom of your /etc/profile file by using the command:make sure th following is found in one of the the files listed below
- sudo nano /etc/profile, ~/.bashrc, or ~/.zshrc
Run the command: source /etc/profile
Code Block language applescript export DBip="127.0.0.1" export DBport=5432 export DBuser="gforge" export DBpass="gforge" export SOLR_BASE_URL="http://<SOLR IP Address>/solr" export ActiveMQ_URL="<ActiveMQ IP Address>" export ActiveMQ_Port=61616 export ActiveMQ_User="active" export ActiveMQ_Password="active"
- sudo nano /etc/profile, ~/.bashrc, or ~/.zshrc
- Next update the following file restservices/src/main/java/org/dmc/services/Application.java
- All references to DB under the @Beam should be replaced with the following:
Code Block language bash ds.setUser(Config.DB_USER); ds.setPassword(Config.DB_PASS); ds.setServerName(Config.DB_IP); ds.setPortNumber(Integer.parseInt(Config.DB_PORT)); ds.setDatabaseName(Config.DB_NAME);
Save the changes in this file.
Run the command: sudo service tomcat7 stop
Go to the following directory:
/var/lib/tomcat7/webapps
If there are any files in the webapps folder, delete them. The command to do this is:
sudo -r *
Next, go to the restservices directory.
Run the command: mvn spring-boot:run -P swagger
Compilation now happens
When completed, open a web browser and got to the following URL:
You will need to then write tests for the code you have written.
Once you believe your tests are complete, you can test them by first closing all terminals you have.
Open a new terminal.
Make sure postgres is running an instance of your database.
Change directories to your rest services folder
Then write the following command
mvn -Dtest=<TestName> test
DO NOT include the triangle brackets in your command
Make sure your environment variable are set or are included in your Config.java file so that your local database is being referenced.
Submission/Code Review (for database changes and resetservice changes)
To submit your cod for code review use the following commands:
Git status
Shows you what files you have made changes to in the repository
git add -A
-A add all files that have changes, by giving the full file path in its place you can add specific files
Git status
this checks which files you've added to the staging area.
Git commit -m “information about commit”
-m lets you add information about the commit.
“” are used for capturing comments.
Git push origin BranchName
In place of branch name include your actual branch name.
This will push your changes to GitHub.
Go to GitHub, and navigate to your branch
Make sure to sync your branch with the master branch
Make a pull request and add a few reviewers.
Updating the .yaml file
After your changes have been merged, find the .yaml file mentioned in the steps above and edit it as well. Make sure to add tags live and has tests to your endpoint. Submit this for code review.
...