use of fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft in project pyramus by otavanopisto.
the class RetrieveFormDraftJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
DraftDAO draftDAO = DAOFactory.getInstance().getDraftDAO();
String url = requestContext.getRequest().getHeader("Referer");
User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
FormDraft formDraft = draftDAO.findByUserAndURL(loggedUser, url);
if (formDraft == null) {
requestContext.addResponseParameter("draftDeleted", true);
} else {
requestContext.addResponseParameter("draftDeleted", false);
requestContext.addResponseParameter("url", formDraft.getUrl());
requestContext.addResponseParameter("draftData", formDraft.getData());
requestContext.addResponseParameter("draftCreated", formDraft.getCreated());
requestContext.addResponseParameter("draftModified", formDraft.getModified());
}
}
use of fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft in project pyramus by otavanopisto.
the class DraftDAO method create.
public FormDraft create(User creator, String url, String draftData) {
EntityManager entityManager = getEntityManager();
Date now = new Date(System.currentTimeMillis());
FormDraft formDraft = new FormDraft();
formDraft.setUrl(url);
formDraft.setData(draftData);
formDraft.setCreated(now);
formDraft.setModified(now);
formDraft.setCreator(creator);
entityManager.persist(formDraft);
return formDraft;
}
use of fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft in project pyramus by otavanopisto.
the class DraftDAO method removeDeprecatedDrafts.
public void removeDeprecatedDrafts() {
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.roll(Calendar.DATE, -14);
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<FormDraft> criteria = criteriaBuilder.createQuery(FormDraft.class);
Root<FormDraft> root = criteria.from(FormDraft.class);
criteria.select(root);
criteria.where(criteriaBuilder.lessThan(root.get(FormDraft_.modified), c.getTime()));
List<FormDraft> formDrafts = entityManager.createQuery(criteria).getResultList();
for (FormDraft formDraft : formDrafts) {
delete(formDraft);
}
}
use of fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft in project pyramus by otavanopisto.
the class DeleteFormDraftJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
DraftDAO draftDAO = DAOFactory.getInstance().getDraftDAO();
String url = requestContext.getRequest().getHeader("Referer");
User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
FormDraft formDraft = draftDAO.findByUserAndURL(loggedUser, url);
if (formDraft != null) {
draftDAO.delete(formDraft);
}
}
use of fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft in project pyramus by otavanopisto.
the class SaveFormDraftJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
DraftDAO draftDAO = DAOFactory.getInstance().getDraftDAO();
String url = requestContext.getRequest().getHeader("Referer");
String draftData = requestContext.getString("draftData");
if (draftData != null) {
User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
FormDraft formDraft = draftDAO.findByUserAndURL(loggedUser, url);
if (formDraft == null)
formDraft = draftDAO.create(loggedUser, url, draftData);
else
draftDAO.update(formDraft, draftData);
requestContext.addResponseParameter("url", formDraft.getUrl());
requestContext.addResponseParameter("draftCreated", formDraft.getCreated());
requestContext.addResponseParameter("draftModified", formDraft.getModified());
}
}
Aggregations