//Step 1 Create the person object
//NOTE we use to store subscription info (i.e. in the peoplepojo)
//but it was never used anywhere (validating subscription?)
//its in the WPUserPojo that comes across
ObjectId profileId = new ObjectId();
PersonPojo pp = new PersonPojo();
pp.set_id(profileId);
pp.setAccountStatus("active");
if ((null == wpu.getEmail()) || (0 == wpu.getEmail().size())) {
rp.setResponse(new ResponseObject("WP Register User",false,"Need to specify email"));
return rp;
}//TESTED (2c)
pp.setEmail(wpu.getEmail().get(0));
pp.setFirstName(wpu.getFirstname()); // (optional but one of this + last name must be set)
pp.setLastName(wpu.getLastname()); // (optional but one of this + first name must be set)
if ((null == wpu.getFirstname()) || wpu.getFirstname().isEmpty()){
if (null == wpu.getLastname()) {
rp.setResponse(new ResponseObject("WP Register User",false,"Need to specify one of firstname,lastname"));
return rp;
}
pp.setDisplayName(wpu.getLastname());
}//TESTED (2d)
else if ((null == wpu.getLastname()) || wpu.getLastname().isEmpty()) {
pp.setDisplayName(wpu.getFirstname());
}
else {
pp.setDisplayName(wpu.getFirstname() + " " + wpu.getLastname());
}
// Check if user is already present (+set "primary keys"):
if (null == wpu.getWPUserID()) { // WPUserId is optional, uses email if not present
wpu.setWPUserID(pp.getEmail());
}
else { // Check WPU (+email later)
PersonPojo personQuery = new PersonPojo();
personQuery.setWPUserID(wpu.getWPUserID()); // (can be null, that's fine)
DBObject dboperson = DbManager.getSocial().getPerson().findOne(personQuery.toDb());
if (null != dboperson) {
rp.setResponse(new ResponseObject("WP Register User",false,"User already exists, both WPUserId and first email must be unique"));
return rp;
}//TESTED (2e)
}
pp.setWPUserID(wpu.getWPUserID());
PersonPojo personQuery = new PersonPojo();
personQuery.setEmail(pp.getEmail());
DBObject dboperson = DbManager.getSocial().getPerson().findOne(personQuery.toDb());
if (null != dboperson) {
rp.setResponse(new ResponseObject("WP Register User",false,"User already exists, both WPUserId and first email must be unique"));
return rp;
}//TESTED (2f)