Search in sources :

Example 1 with DraftDAO

use of fi.otavanopisto.pyramus.dao.drafts.DraftDAO 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 DraftDAO

use of fi.otavanopisto.pyramus.dao.drafts.DraftDAO in project pyramus by otavanopisto.

the class RemoveDeprecatedDrafts method removeDeprecatedDrafts.

/**
 * Removes the deprecated drafts from the repository.
 * This method is called automatically every 5 minutes.
 */
@Schedule(second = "0", minute = "0/5", hour = "*", persistent = false)
public void removeDeprecatedDrafts() {
    DraftDAO draftDAO = DAOFactory.getInstance().getDraftDAO();
    draftDAO.removeDeprecatedDrafts();
}
Also used : DraftDAO(fi.otavanopisto.pyramus.dao.drafts.DraftDAO) Schedule(javax.ejb.Schedule)

Example 3 with DraftDAO

use of fi.otavanopisto.pyramus.dao.drafts.DraftDAO 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 4 with DraftDAO

use of fi.otavanopisto.pyramus.dao.drafts.DraftDAO 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

DraftDAO (fi.otavanopisto.pyramus.dao.drafts.DraftDAO)4 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)3 FormDraft (fi.otavanopisto.pyramus.domainmodel.drafts.FormDraft)3 User (fi.otavanopisto.pyramus.domainmodel.users.User)3 Schedule (javax.ejb.Schedule)1