return;
}
// Business logic
// :: Find Location by code
Location loc = dao.findLocationByCode(code);
if(loc == null) {
return;
}
// Add location to user expertise
boolean hasExpertise = user.hasExpertise(loc);
if(action.equals("add")) { // Add
// Do nothing if user is already expert
if(hasExpertise) {
return;
}
user.addExpertise(loc);
} else { // Remove
// Do nothing if user is already expert
if(!hasExpertise) {
return;
}
user.removeExpertise(loc);
}
try {
dao.persistChanges(user);
} catch(Exception e) {
e.printStackTrace();
return;
}
String contextPath = request.getContextPath();
PrintWriter out = response.getWriter();
if(action.equals("add")) {
out.println("<li id=\"expertise_" + loc.getCode() + "\">");
out.println(" <span class=\"expertise_name\">" + loc.toString() + "</span> |");
out.println(" <a class=\"expertise_remove\" href=\"" + contextPath + "/expertise/remove\">Eliminar</a>");
out.println("</li>");
} else { // Remove
out.println("<option value=\"" + loc.getCode() + "\">" + loc.toString() + "</option>");
}
out.flush();
out.close();
return;
}