Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Checking the .yaml file

    1. If you have not yet done so, clone the frontend repository from github.

      1. Change directories to the following: frontend/restapi

      2. Open the file called: DMCInterfaceSwagger.yaml

    2. Check and make sure that the .yaml file has information about your endpoint already there.

      1. If it is missing, you will need to update your endpoint to reflect your code after it is completed.

  2. Working on the data base

    1. 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).

    2. Open the folder structure as such: Server Groups → Servers → <Local Database running with postgres> → Databases → gforge → Schemas → public → Tables

    3. Locate the table(s) that will be required for your endpoint(s) to function

      1. 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

        1. You will need to generate the code required to create your table. To do this do the following

          1. In pgadmin, right click the tables folder and choose new table.

          2. 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).

          3. 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).

            1. When creating an id column that should generate an id on its own, do the following

              1. Create the column with a name and the type of serial.

              2. Click on the constraints tab.

              3. Make sure Primary Key is selected from the drop-down menu.

              4. Click Add.

              5. In the new window, click on the columns tab

              6. In the column drop-down menu, choose the name of the column.

        2. Find the table that you created in the tables folder in pgadmin.

        3. Click on the table name and then click on the table icon (7th icon from the top left of the window).

          1. This is a view of what your table will look like

        4. At the bottom of the pgadmin window, there is a pane with code. Copy this code.

        5. With postgres still running, run the following command:

          1. Code Block
            languagebash
            firstline1
            title This command will show you the full list of migrations for table data
            linenumberstrue
            ./flyway clean migrate info -configFile=conf/core/flyway.conf -url=jdbc:postgresql://localhost:5432/gforge  -user=gforge -password=gforge



          2. Code Block
            languagebash
            firstline1
            title This command will show you the full list of migrations for sample data
            linenumberstrue
            ./flyway info -configFile=conf/data/flyway.conf -url=jdbc:postgresql://localhost:5432/gforge  -user=gforge -password=gforge -locations=filesystem:./sql/data/dev2
            
            


        6. 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.
        7. You will now update 3 files in the database. File names and locations are as follows:

          1. dmcdb/sql/core/tables

            1. Create a new table file.

              1. 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
                1. V1 is the version number
                2. 0081 is the migration number
            2. Edit the file and paste the code that you copied in the step above here.

            3. Cut the line that says CONSTRAINT table_name_PKEY PRIMARY KEY (id)

            4. erase the lines: )WITH ( UIDS=FALSE

            5. Save the file.

          2. /dmcdb/sql/core/constraints/

              1. Create a new primary_key_constraints file.

                1. Just like the new table file make sure the new file has a migration number that is one higher than the table name file.
                  1. 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
                  2. __primary_key_constraints.psql should never change on the version or migration number should.
              2. Add the following lines to the file:


            Code Block
            languagebash
            firstline1
            linenumberstrue
            -
            -Name: table_name_pkey; Type: CONSTRAINT; Schema: public; Owner: gforge; Tablespace:
            -
            
            ALTER TABLE ONLY <table_name>
            ADD <paste what you cut earlier here>;

            1. Save the file.

          3. dmcdb/data/dev2/

            1. Create a new sample data file.

              1. 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
                1. V1 is the version number
                2. 0015 is the migration number
            2. Add three lines of sample data here. Use the following as an example for syntax

              1. insert into table_name (column_name one, column_name_two) values ('text', 'textAlso');

                1. Explanation:

                  1. table_name: use the name of your table here in its place.

                  2. The column names should be listed in order separated by commas.

                  3. The sample data must be listed in the same order as you list the column names.

                  4. Text data should be quoted using apostrophes and separated by commas. Numbers should not be quoted at all.

                  5. The id that should be auto generated should not be listed in the column name or the sample data.

        1. 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.

          1. 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..

          2. 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.
        2. 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.

        3. Once you've confirmed the information in the database is correct and updated you can now start working on your code.

  3. Working on your code

    1. Make sure that if you have not yet cloned the restservices repository from GitHub, that you do so now.

    2. Also, make sure you create a new branch from the master branch.

    3. Open Eclipse

    4. Refresh Eclipse

  4. Testing your code with swagger

    1. Manual


      1. Code Block
        titleDepricated Instructions
        collapsetrue
        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
        languagebash
        firstline1
        linenumberstrue
        
        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
        Code Block
        languageapplescript
        
        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
        javaAll references to DB under the @Beam should be replaced with the following:
        Code Block
        languagebash
        
        
        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:
        Code Block
        languagebash
        
        
        
        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.


    2. Automatic

        1. Once you have code you would like to test, start drop and rebuild your local database.

        2. Next, fine the Config.java file located in the following directory.

        3. restservices/src/main/java/org/dmc/services/

        4. Change the first 6 lines to be the following.


      Code Block
      firstline1
      linenumberstrue
      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";
      1. Save the changes in this file.

      2. Next, add the following to the bottom of your /etc/profile file by using the command:
        1. sudo nano /etc/profile
        2. Run the command: source /etc/profile

          Code Block
          languageapplescript
          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"


      3. Next update the following file restservices/src/main/java/org/dmc/services/Application.java
        1. All references to DB under the @Beam should be replaced with the following:

        2. Code Block
          languagebash
          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);


      4. Save the changes in this file.

      5. Run the command: sudo service tomcat7 stop

      6. Go to the following directory:

        1. /var/lib/tomcat7/webapps

      7. If there are any files in the webapps folder, delete them. The command to do this is:

        1. sudo -r *

      8. Next, go to the restservices directory.

        1. Run the command: mvn spring-boot:run -P swagger

        2. Compilation now happens

      9. When completed, open a web browser and got to the following URL:

        1. http://localhost:8080/swagger-ui.html

      10. You will need to then write tests for the code you have written.

      11. Once you believe your tests are complete, you can test them by first closing all terminals you have.

      12. Open a new terminal.

        1. Make sure postgres is running an instance of your database.

      13. Change directories to your rest services folder

      14. Then write the following command

        1. mvn -Dtest=<TestName> test

          1. DO NOT include the triangle brackets in your command

        2. Make sure your environment variable are set or are included in your Config.java file so that your local database is being referenced.

  5. Submission/Code Review (for database changes and resetservice changes)

    1. To submit your cod for code review use the following commands:

    2. Git status

      1. Shows you what files you have made changes to in the repository

    3. git add -A

      1. -A add all files that have changes, by giving the full file path in its place you can add specific files

    4. Git status

      1. this checks which files you've added to the staging area.

    5. Git commit -m “information about commit”

      1. -m lets you add information about the commit.

      2. “” are used for capturing comments.

    6. Git push origin BranchName

      1. In place of branch name include your actual branch name.

      2. This will push your changes to GitHub.

    7. Go to GitHub, and navigate to your branch

      1. Make sure to sync your branch with the master branch

      2. Make a pull request and add a few reviewers.

    8. Updating the .yaml file

      1. 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.

...