Search in sources :

Example 1 with FormDraft

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());
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) DraftDAO(fi.otavanopisto.pyramus.dao.drafts.DraftDAO) FormDraft(fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft)

Example 2 with FormDraft

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;
}
Also used : EntityManager(javax.persistence.EntityManager) Date(java.util.Date) FormDraft(fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft)

Example 3 with 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);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Calendar(java.util.Calendar) Date(java.util.Date) FormDraft(fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft)

Example 4 with 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);
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) DraftDAO(fi.otavanopisto.pyramus.dao.drafts.DraftDAO) FormDraft(fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft)

Example 5 with 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());
    }
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) DraftDAO(fi.otavanopisto.pyramus.dao.drafts.DraftDAO) FormDraft(fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft)

Aggregations

FormDraft (fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft)6 DraftDAO (fi.otavanopisto.pyramus.dao.drafts.DraftDAO)3 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)3 User (fi.otavanopisto.pyramus.domainmodel.users.User)3 EntityManager (javax.persistence.EntityManager)3 Date (java.util.Date)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Calendar (java.util.Calendar)1