How should I keep my stores in react mobx for my Java entitiy models? - reactjs

I'm developing an application with React mobx. I have a complex data on the Java server side. How should I keep my data in my mobx store in for this data? I've read a lot about it. But I couldn't decide how to do it.
I have lots of classes nested. I'm just writing a part.
How should I keep nested classes? Or should I use inheritance in mobx? Thank you from now.
On the Java side I am holding List of PlanManagement.
public class Template {
private String templateName;
private String templateId;
.....
}
public class Group {
private String groupId;
private String groupName;
private String groupType;
private Template template;
....
}
public class PlanManagement {
private String id;
private String text;
private Group group;
.....
}
public class PlanCore extends PlanManagement {
private PlanStatusEnum statusValue;
private String statusType;
..............
}
public class OrderCore extends PlanManagement {
private OrderStatusEnum statusValue;
private String status;
private String task;
............
}

Related

How to return JSON objects from spring boot controller methods?

I am using spring boot along with react js and postgresql. I am trying to print the rows of table from postgresql to a react js page. I have used crud repository function findAll() in the controller method to get the List. My problem is that when I am printing the List in spring boot console, it prints the list but it's printing empty objects' list when that url is accessed.
User.java
#Entity
#Table(name="users")
public class User implements Serializable{
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private long id;
#Column(name="name")
private String name;
#Column(name="email")
private String email;
public User() {
}
public User(String name, String email) {
this.name = name;
this.email = email;
}
#Override
public String toString() {
return String.format("User[id=%d, name='%s', email='%s']",this.id,this.name,this.email);
}
}
UserRepository.java
public interface UserRepository extends CrudRepository<User, Long>{
}
WebController.java
public class WebController {
#Autowired
private UserRepository repository;
#GetMapping("home")
public String home() {
System.out.println("whaaat");
return "hi ssup";
}
#GetMapping("/save")
public String process() {
repository.save(new User("vidhi","vd#gmail.com"));
System.out.print("apple ");
return "Done";
}
#GetMapping("findall")
#ResponseBody
public Collection<User> findAll() {
System.out.println("cc");
List<User> users = (List<User>) repository.findAll();
System.out.println(users);
return users;
}
}
On printing users in boot: [User[id=33, name='i', email='vd#gmail.com'], User[id=34, name='v', email='d#gmail.com']
on localhost:8080/findall: [{},{}]
What's going on wrong here? I am very confused and trying to figure this out since a lot of time and it's eating my head.
Any help would be wonderful!
Thanks for your time.
You have to add getters and setters to the User class.
Change it to:
#GetMapping("findall", produces= MediaType.APPLICATION_JSON_VALUE)
#ResponseBody
public ResponseEntity<Collection<User>> findAll() {
System.out.println("cc");
List<User> users = (List<User>) repository.findAll();
System.out.println(users);
return ResponseEntity.ok(users);
}
change your repo to:
#Repository
public interface UserRepository extends JpaRepository<User, Long>{
}

Spring Data MongoDB interface-based projection recursively

I'm trying to work with an interface-based projection recursively, However it is not projecting on the appropriate subfields, but only on the whole nested object.
Consider the document / collection class:
#Document
public class Person {
private String firstName;
private String lastName;
private Address address;
static class Address {
private String zipCode, city;
// getters and setters
}
// getters and setters
}
The closed projection:
public interface PersonSummary {
String getFirstName();
AddressSummary getAddress();
interface AddressSummary {
String getCity();
}
}
However when I'm using the following repository query:
public interface PersonRepository extends ReactiveCrudRepository<Person, String> {
Flux<PersonSummary> findAll();
}
The query is executed with the following fields: fields: Document{{firstName=1, address=1}} instead of fields: Document{{firstName=1, address.city=1}}
What are we doing wrong and is there some solution how to work around this?
According to Mark Paluch (#mp911de) at Gitter this is not yet possible, so I filed an improvement request at jira.spring.io, see: https://jira.spring.io/browse/DATAMONGO-1989

Test class for public final static string

How to write a test class for a class containing public final static strings in salesforce?
I tried using system.assertequals
Doesnt seem to work properly.
#isTest
private class Test_TPET_Constants{
private static testMethod void test() {
//TPET_Constants inst= new TPET_Constants();
System.assertEquals(TPET_Constants.PICKLIST_COLLAB_SERVICE_SECURE_EMAIL,'Enterprise Secure Email');
System.assertEquals(TPET_Constants.DRAFT_STATUS, 'Draft');
System.assertEquals(TPET_Constants.ACTIVE_STATUS, 'Active');
System.assertEquals(TPET_Constants.INACTIVE_STATUS, 'Inactive');
System.assertEquals(TPET_Constants.SUBMITTED_STATUS, 'Submitted');
System.assertEquals(TPET_Constants.REJECTED_STATUS , 'Rejected');
System.assertEquals(TPET_Constants.PICKLIST_COLLAB_SERVICE , 'Collab Service');
System.assertEquals(TPET_Constants.PENDING_IMPLEMENTATION_STATUS ,'Pending Implementation');
}
}
In your class you need to markthe variable #TestVisible. Check here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testvisible.htm.
#TestVisible private static Integer recordNumber = 1;

Angulajs ,Hibernate and Spring MVC -Form Submit with list of objects using http.post

I am very new to angularjs facing some issues to post list of object which inturn has set of objects.Below is my backend bean object strurcture :
public class UserBean{
private String userName;
private Set<ContactBean> contactBean= new HashSet<ContactBean>();
private Set<LocationBean> locationBean= new HashSet<LocationBean>();
//getter and setter over here
}
public class ContactBean{
private String contactName;
private String contactPhone;
private String contactEmail;
//getter and setter over here
}
public class LocationBean{
private String country;
private String state;
private String city;
//getter and setter over here
}
my controller structure is,
#RequestMapping(value = "/addUser", method = {RequestMethod.POST })
public #ResponseBody String addUser(#RequestBody UserBean userBean){
return "";
}
and my angular js script is
var response = $http.post("addUser", JSON.parse(JSON.stringify($scope.userBean,$scope.contactBean,$scope.locationBean,)), config);
I am setting my data-ng-model like this
data-ng-model="userBean.userName"
data-ng-model="contactBean.contactName"
data-ng-model="locationBean.country"
How can I set contact and location bean object to UserBean. Any help would be really appreciated.

Getting AssertionError while using ObjectifyService.register

I am in the middle of trying to refactor some of my data models, but I've run into a problem that I don't understand.
Originally I had a simple data model comprised of 3 entity classes, which looked something like this:
#Entity
public final class Teacher {
#Id
private Long id;
private String primarySubject;
public Teacher() {}
public Teacher(String primarySubject) {
this.primarySubject = primarySubject;
}
//getters & setters
}
#Entity
public final class Student {
#Id
private String username;
#Load
#Index
private Ref<Teacher> homeRoomTeacher;
public Student() {}
public Student(String username, Teacher teacher) {
this.username = username;
homeRoomTeacher = Ref.create(teacher);
}
//getters & setters
}
#Entity
public final class School {
#Id
private String name;
#Load
private Set<Ref<Teacher>> teachers;
#Load
private Set<Ref<Student>> students;
public School() {}
public School(String name) {
this.name = name;
}
//getters & setters
}
And this all worked fine.
But we decided that it would be more useful for us to embed the entities directly instead of Refs...
#Entity
#Embed
public final class Teacher {
#Id
private Long id;
private String primarySubject;
public Teacher() {}
public Teacher(String primarySubject) {
this.primarySubject = primarySubject;
}
//getters & setters
}
#Entity
#Embed
public final class Student {
#Id
private String username;
#Index
private Ref<Teacher> homeRoomTeacher;
public Student() {}
public Student(String username, Teacher teacher) {
this.username = username;
homeRoomTeacher = Ref.create(teacher);
}
//getters & setters
}
#Entity
public final class School {
#Id
private String name;
private Set<Teacher> teachers;
private Set<Student> students;
public School() {}
public School(String name) {
this.name = name;
}
//getters & setters
}
After making those changes, then all of our junit tests started to fail with an AssertionError during registration of the School class in our test setup methods which look like:
#Before
public void setUp() throws Exception {
helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
helper.setUp();
ObjectifyService.register(Teacher.class);
ObjectifyService.register(Student.class);
ObjectifyService.register(School.class);
// more setup
}
The AssertionError doesn't appear until the line that registers the School class, and according to the stack trace is being thrown from the method "com.googlecode.objectify.impl.translate.CreateContext.enterCollection" but I'm not certain how to go about fixing it.
Does anyone have any ideas?
I suspect the error you are getting is to do with the fact that you are trying to register a class which you have annotated with #Embed.
The objectify documentation clearly states that #Embed classes do not have to be registered - maybe this is the cause of the issue.
Also, I'm not 100% sure on this but I don't think you need #Id on an embedded class.
I would suggest you give the following changes a go:
#Embed
public final class Teacher {
#Id
private Long id;
private String primarySubject;
public Teacher() {}
public Teacher(String primarySubject) {
this.primarySubject = primarySubject;
}
//getters & setters
}
#Embed
public final class Student {
#Id
private String username;
#Index
private Ref<Teacher> homeRoomTeacher;
public Student() {}
public Student(String username, Teacher teacher) {
this.username = username;
homeRoomTeacher = Ref.create(teacher);
}
//getters & setters
}
#Before
public void setUp() throws Exception
{
helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
helper.setUp();
ObjectifyService.register(School.class);
// more setup
}
Hope this helps!

Resources