Uploaded image for project: 'DSpace'
  1. DSpace
  2. DS-4089

Use converter.toModel methods in POST create requests



    • Type: Improvement
    • Status: Received (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 7.0
    • Fix Version/s: None
    • Component/s: REST API v7
    • Labels:
    • Attachments:
    • Comments:
    • Documentation Status:


      To create a DSpaceObject via the REST API in DSpace 7, we will catch the request in a method in RestResourceController: https://github.com/DSpace/DSpace/blob/master/dspace-spring-rest/src/main/java/org/dspace/app/rest/RestResourceController.java#L397
      This will lead us to the calling of a createAndReturn method in the Repository for the DSpaceObject it was called on. So performing a POST request to api/core/epersons will trigger the createAndReturn method in the EPersonRestRepository given that this method exists: https://github.com/DSpace/DSpace/blob/master/dspace-spring-rest/src/main/java/org/dspace/app/rest/repository/EPersonRestRepository.java#L67
      This method will create a REST object from the request and it will then proceed to create a DB object manually instead of using our converters that we had made in order to support this kind of functionality. This is where we could make an improvement.
      My current idea is as follows: 
      We would create two toModel methods, one of them would have only the REST object as parameter and it would return a DB object where as the other will have two parameters namely the REST object AND the DB object that will be returned.
      We could use the method with just the one parameter to perform a call to the backend and try to find the DB object through an ID in the backend and then pass this along to the other toModel method with the two parameters. This second toModel method would then fill in all the properties for us as is now done in the createAndReturn method.
      The benefit of creating these two methods means that we can both use a converter to lookup the object in the DB and convert our objects OR we can create an entire new one to then pass along to the converters to be filled in. It would encapsulate all the 'Converter' logic in the converters itself and make our Repository methods a lot cleaner so that they don't need to deal with this logic anymore and it would be easily reusable elsewhere.




            • Assignee:
              kevin van de velde Kevin Van de Velde (Atmire)
              raf.ponsaerts-atmire Raf Ponsaerts (Atmire)
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: