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.