public class SyncAction extends AbstractWOJAction {
private static Logger LOGGER = LoggingManager.getLogger(SyncAction.class.getName());
public ActionForward getUsers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
Answer a = new Answer();
try {
Map params = URLHelper.getParametersMap(request.getParameterMap());
String sinceStr = request.getParameter(Params.SYNC.PARAMS.SINCE);
Long since = Long.valueOf((sinceStr==null)?"-1":sinceStr);
User[] foundUsers = DaoFactory.getUserDao().findUpdatedUsers(since);
User[] uSend = new User[foundUsers.length];
for (int i = 0; i < foundUsers.length; i++) {
uSend[i] = new User();
BeanHelper.copy(foundUsers[i], uSend[i], User.class);
if (foundUsers[i].getGroup() != null) {
Group g = new Group();
BeanHelper.copy(foundUsers[i].getGroup(), g, Group.class);
uSend[i].setGroup(g);
}
}
a.setStatus(Answer.STATUS_OK);
a.setObject(uSend);
} catch (Exception e) {
LOGGER.warn("error getting user list", e);
// One of the parameters was eroneous
a.setStatus(Answer.STATUS_INVALID);
a.setObject(new IllegalArgumentException("at least one of the waited parameters " + Params.SYNC.PARAMS.SINCE + " & " + Params.SYNC.PARAMS.UAK + " was invalid"));
}
XMLResponseHelper.writeXMLResponse(response, a);
return null;
}