ntnu-ai-lab / mycbr-rest

7 stars 5 forks source link

Support for ephemeral case bases and self-similarity computation #22

Closed amardj closed 4 years ago

amardj commented 5 years ago

Details of this pull request

Primary focus of this pull request is in syntactic code refactoring

Issues Resolved in this Pull Request

Resolved Issues: #20, #21, #23, #24, #26, #27, #28

Standard and consistent REST API end-point naming

This makes the code highly maintainable and consistent also prevents in accidental naming errors and inconsistencies. This helps to get rid of most common bad practice in coding known as "magic strings/numbers"

1) Adapted for consistent REST API path with naming conventions and String constants defined in ApiPathConstants.java 2) Adapted standard REST end-point operation naming by String constants defined in ApiOperationConstants.java 3) Removed the untidy redundant REST API response codes by creating annotations in the class ApiResponseAnnotations.java

Package Restructuring

The consistent and appropriate packages in java prove to be highly fruitful in the long run

  1. Recommended best practice to keep main code and test code along with their respective resources in separate folders under the "src" folder. Main source codes in the "src/main" and the test source codes in "src/test". Similarly the respective resources in "src/main/resources" and "src/test/resources" folders.
  2. The service package which is only used by the controller is moved under the no.ntnu.mycbr.rest.controller package ( "no.ntnu.mycbr.rest.controller.service")
  3. The "no.ntnu.mycbr.rest.common" package is added to keep all the common constants.
  4. The "no.ntnu.mycbr.rest.config" package is added to keep all the configuration related java classes.
  5. All the java classes in the "no.ntnu.mycbr.rest package" are moved into their appropriate packages.
  6. Many redundant java classes are removed from the codebase.
  7. The "Case.java" and "Query.java" are used as helper classes for the controller and service classes, thus they are moved to the "no.ntnu.mycbr.rest.controller.helper" package.

myCBR project file for Reference and Testing

  1. Added a new myCBR project file (car_mycbr_project.prj). It is based on the used_cars_flat.prj file but with clean and consist names and similarity functions. Also, the attribute and similarity function errors are removed. The same copy of the file is kept under the main and test resources.
  2. The cases with which the case base of car_mycbr_project.prj is populated is preserved in a .csv file under the main resources with the name "dataset_car_mycbr_project.csv"

Controller and Service class Refactoring

The respective controller and service classes are refactored not only to improve code readability, maintainability, and consistency but also to remove the code redundancy.

  1. AttributeController.java is added to serve all the request pertaining to attribute CRUD and attribute similarity function operations.
  2. EphemeralController.java is added to facilitate operations on ephemeral case base creation and retrievals on them.
  3. The InstanceController.java is renamed to CaseController.java as to the external user of myCBR-rest application the term case is more appropriate.
  4. Added the endpoint and implemented the SelfSimilarity computation for a given case base. This is in the class RetrievalController.java with the method name "getCaseBaseSelfSimilarity".
  5. SelfSimilarity computation is also extended for the ephemeral case bases, but they are defined in the EphemeralController.java.
  6. The java docs are provided for the newer implementations, but the legacy code will still require appropriate java docs.
  7. The legacy code functionality and implementation logic and design are not addressed in this refactoring.
  8. Tried to adhere to intuitive and consistent response body across the REST API end points.

maven clean install - failure issues for JUnit test cases

The test cases, which need to load a specific myCBR project file (.prj) in the REST mocking environment, were failing in the CI build but they were passed in the IDE environment. This issue can also be reproduced by executing the command "mvn clean install" on any terminal or command prompt. The issue is fixed in this pull request.

Python Script for Users

amardj commented 4 years ago

I believe, many API endpoint paths were changed. Please add to the PR description what was changed: POST /some/old/path -> PUT /new/path/ + parameter name changes. Or, if everything was changed, please emphasize this in the PR description.

This is an exhaustive task and needs close comparisons not only with respect to the path changes but also the response data changes. We would suggest that we should start writing a wiki page to capture the REST API changes with respect to myCBR-rest version updates.