0

I am trying to add functionality to an existing JAVA Spring/Angular JS web application that uses REST calls along with JPA/Hibernate/Liquibase. I have followed what is there and while I have worked through a lot of errors I cannot figure out what is hopefully the last error. The application loads but there is no data returned to display. And I know the data is in the database as a direct SQL query pulls it back. So it has to be with the Spring/JPA/Hibernate setup. I see in the logs that the Angular controller calls my PropertiesRestController.java file and uses the correct method. That in turn calls the correct method in my PropertiesDataService.java file which uses the correct query/method in my Repository.java file. But when I debug the point of breakdown the code appears to breakdown in the AngularJS service on the line "data = angular.fromJson(data);". The logs show the correct parameters for each method but then error out on the PropertiesRestController.java method call with ". . . logging.LoggingAspect - Illegal Argument ['Sold','30,'jwt.model.UserContext@xzyABC123',Page request[number: 0, size 20, sort: null]] in . . . . web.rest.controller.PropertiesRestController.findMyProperties() . . . logging.LoggingAspect - Exception in . . . web.rest.controller.PropertiesRestController.findMyProperties() with cause = null". Also, on the front end in the browser with developer tools I get "SyntaxError" at the "findMyProperties.transformResponse line of my AngularJS service for this page view.

I have done extensive web research on this. And I have added for example "return Optional.ofNullable(myProperty).map(a -> new ResponseEntity<>(a, HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND) to the PropertiesRestController.java method call. Before I jsut tried to return Page myProperty = myPropertyDataService.getMyProperties( . . . . ). Others had issues with null being returned and needed to handle it. I am getting data for sure (if the SQL is correct) but in case the query needed adjusting I decided to at least handle the null that is reported in the log file. I've made sure my SQL in @Query is referencing entity names not tables/SQL language (although honestly some of the ones already used I don't see in the entity definitions so I don't know where they got those to use from.)

AngularJS Controller

    $scope.myPropertiesP = [];

    $scope.loadall = function(){
    MyProperties.findMyProperties({propertyStatus:"Pending",listingDate:0,function(result){
    $scope.myPropertiesP = result.content;
});
    $scope.loadall();

AngularJS Service

    use strict;
    angular.module('propertyApp')
    .factory('MyProperties',function($resource){
      return $resource('rest/api/Properties/my/:propertyStatusName/:propertyListingDate', {}, {
      'findMyProperties': method: 'GET',
         transformResponse: function(data){
           data = angular.fromJson(data);
           return data;
         });
      });
    });

PropertyRestController.java

    @GetMapping(value='/properties/my/{propertyStatusName}/{propertyListingDate}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Page<Properties>> findMyProperties(@PathVariable propertyStatusName, @PathVariable Integer propertyListingDate, @Authenticated User user, Pageable page){
    Page<Properties> myProperty = myPropertyDataService.getMyProperties(propertyStatusName, propertyListingDate,user.getUser(),pageable);
    return Optional.ofNullable(myProperty).map(a -> new ResponseEntity<>(a, HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
    }

PropertyDataServices.java

    public Page<Properties> getMyProperties(String propertyStatusName, Integer propertyListingDate, User user, Pageable page){
      if(pageable != null){
        if(propertyListingDate==0)&&(propertyStatusName=='Pending'){
          return PropertyRespository.MyPropertiesP(user.getId(),pageable);
        } else {
          return PropertyRespository.MyPropertiesP(user.getId(), newPageRequest(0,20));
    }
    }

PropertyRepository.java

    public interface PropertyRespository extends JpaRepsotiory(Property,Long>{
        Page<Property> findByNameContaingIgnoreCase(String name, Pageable pageable);
     . . . 

       @Query("select prop from Property prop where prop.propertyOwner = :propertyOwnerId AND (propertyStatus=3 OR prop.propertyStatus=2) ORDER BY prop.propertListingDate DESC")
    Page<Property> myPropertiesP(@Param("propertyOwner") Integer propertyOwnerId, Pageable pageable):


    }



I am supposed to get back JSON strings of database objects to display through AngularJS.
STP
  • 51
  • 8
  • Since there were no responses I tried to create a new repository method. Page findByPropertyOwnerIdAndpropertyStatusIdAndpropertyListingDateGreaterThanEqualOrderBypropertyListingDateDesc(Integer propertyOwnerId, Integer propertyStatusId, Date propertyListingDate, Pageable pageable). It won't compile. Inside DataServices.java file it says that method cannot be found. Or cannot find symbol. – STP May 03 '19 at 00:55
  • Maybe you should try to rework your question to get an answer. Format it properly and try to ask clearly – Simon Martinelli May 04 '19 at 06:56
  • My problem with the method not found was that in my long day of debugging I stupidly forgot to put the interface class on the method when I called it. I did and the problem went away. – STP May 08 '19 at 00:05
  • the issue above turned out to be a badly formed custom query despite my many efforts of going over and over it. It had to do with Java dates as I needed to pull data greater or equal to 30 days ago. I got hung up in the date Java hell of not being able to reformat date/calendar/gregorian calendar to a MS Sql Server date/time stamp. I eventually worked all of that out an dmy data was returned. – STP May 08 '19 at 00:06

0 Answers0