Skip to content

Instantly share code, notes, and snippets.

@jonathanGB
Created October 28, 2016 04:03
Show Gist options
  • Save jonathanGB/935f4d77e4193686b536cf3b2f89f88c to your computer and use it in GitHub Desktop.
Save jonathanGB/935f4d77e4193686b536cf3b2f89f88c to your computer and use it in GitHub Desktop.
private boolean getUser(String userId) {
Query query = em.createQuery(
"SELECT u FROM UserProfile u" +
" WHERE u.emailId = :emailId");
query.setParameter("emailId", userId);
System.err.println("after creation");
ArrayList<UserProfile> results = performQuery(query);
System.err.println("after performed");
if (results == null)
return false;
else {
UserProfile result = results.get(0);
Address ad = result.getAddress();
Collection<persistence.Image> imgs = result.getPictures();
for (persistence.Image pImg : imgs) {
Image img = new Image(pImg.getContents(), pImg.getType());
images.put(pImg.getId().toString(), img);
}
this.emailId = result.getEmaild();
this.password = result.getPassword();
this.firstName = result.getFirstName();
this.lastName = result.getLastName();
this.phone = result.getPhone();
this.dob = result.getDob();
this.bio = result.getBio();
this.number = ad.getNumber();
this.street = ad.getName();
this.unit = ad.getUnit();
this.city = ad.getCity();
this.province = ad.getCity();
this.postalCode = ad.getPostalCode();
return true;
}
}
private ArrayList<UserProfile> performQuery(final Query query) {
List resultList = query.getResultList();
if (resultList.isEmpty()) {
return null;
}
ArrayList<UserProfile> results = new ArrayList<>();
results.addAll(resultList);
return results;
}
public String handleFlow(FlowEvent ev) {
if (ev.getNewStep().equals("userProfile")) {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
String userId = ec.getRequestParameterMap().get("form1:emailId");
System.err.println("wazza" + ev.getOldStep() + ev.getNewStep());
return (getUser(userId)) ? ev.getNewStep() : ev.getOldStep();
}
return ev.getNewStep();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment