I am working with the Roku Dev Tools API to create a remote controller app via a Java Spring Boot backend. I have three JPA repositories: TelevisionRepository, AppsRepository, and AppRepository. My TelevisionRepository saves its entities just fine, but both the AppsRepository and AppRepository fail to do so. I think it might have something to do with these objects getting their attributes from the Roku API call, which returns its data in XML. The “Apps” shares a one-to-many relationship with the “App” object. My intention is to call the Roku API to query for the channels (http://{{rokuIPAddress}}:8060/query/apps
) installed on a given television, then save them to the repository. I made my repo for this code public.
I have tried calling my getApps method from my service and controller to get all of the apps on my tv:
// Get apps list for tv
@GetMapping(path = "/get-apps/{name}")
public ResponseEntity<Apps> getApps(@PathVariable String name) {
return appsService.getApps(name);
}
// Get apps list for tv
public ResponseEntity<Apps> getApps(String name) {
Television tele = televisionRepository.findByTelevisionName(name).orElseThrow(() -> new TelevisionNotFoundException());
log.info(String.format("Requesting apps for %s via: http://%s:8060/query/apps", name, tele.getIpAddress()));
ResponseEntity<Apps> responseEntity = this.restTemplate.getForEntity("http://" + tele.getIpAddress() + ":8060/query/apps", Apps.class);
Apps apps = responseEntity.getBody();
System.out.println(apps.toString());
for (App app : apps.getApp()) {
appRepository.save(app);
}
appsRepository.save(apps);
return ResponseEntity.ok(apps);
}
This implementation fails to save anything to the appRepository and appsRepository.
Here are the classes for Apps and App:
@Entity
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "app")
public class App {
@Id
@XmlAttribute(name = "id")
private String id;
@XmlAttribute(name = "type")
private String type;
@XmlAttribute(name = "version")
private String version;
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnore
private Apps apps;
// Constructors, getters and setters
@Entity
@XmlRootElement(name = "apps")
@Table(name = "apps")
@XmlAccessorType(XmlAccessType.FIELD)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Apps {
@Id
@GeneratedValue
@Column(name = "id", nullable = false)
private Long id;
@OneToMany(mappedBy = "apps", cascade = CascadeType.REMOVE)
@JacksonXmlElementWrapper(useWrapping = false)
private List<App> app;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "television_id")
@JsonIgnore
private Television television;
// Constructors, getters and setters
The repositories:
public interface AppRepository extends JpaRepository<App, String> {
}
public interface AppsRepository extends JpaRepository<Apps, Long> {
}
Here are my H2 db configurations:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
Here is an example of what the API call looks in Postman