Package eu.semberal.reminders.entity

Examples of eu.semberal.reminders.entity.Note


    private Long noteId;
    private SizeAndPosition sizeAndPosition;

    @DefaultHandler
    public Resolution saveNoteSizeAndPosition() {
        Note n = notesService.getNote(noteId);
        if (!n.getUser().equals(getContext().getUser())) return null;

        n.setSizeAndPosition(sizeAndPosition);
        try {
            notesService.saveNote(n);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
View Full Code Here


        return new TextResolution("OK");
    }

    public Resolution deleteNote() {
        Note n = notesService.getNote(noteId);
        if (!n.getUser().equals(getContext().getUser())) return null;
        notesService.deleteNote(noteId);
        return new TextResolution("OK");
    }
View Full Code Here

        notesService.deleteNote(noteId);
        return new TextResolution("OK");
    }

    public Resolution hideNote() {
        Note n = notesService.getNote(noteId);
        if (!n.getUser().equals(getContext().getUser())) return null;
        notesService.activateNote(noteId, false, false);
        return new TextResolution("OK");
    }
View Full Code Here

        this.id = id;
    }

    public Resolution deleteNote() {
        if (id == null) return new ErrorResolution(404); /* check if ID is not null */
        Note n = notesService.getNote(id);
        if (n == null || !n.getUser().equals(getContext().getUser())) return new ErrorResolution(403); //security check

        notesService.deleteNote(id);
        return new RedirectResolution(NotesListActionBean.class);
    }
View Full Code Here

    @DefaultHandler
    @DontValidate
    @SuppressWarnings("unchecked")
    public Resolution form() {
        if (noteId != null) {
            Note n = notesService.getNote(noteId);
            if (n == null || !n.getUser().equals(getContext().getUser()))
                return new ErrorResolution(403);
            this.color = n.getColor().toString();
            this.enableScheduling = n.getSchedulingExpression() != null;
            this.note = new Note();
            this.schedulingVariant = n.getSchedulingVariant();
            this.note.setTitle(n.getTitle());
            this.note.setText(n.getText());
            this.note.setActivated(n.isActivated());
            this.note.setSendActivationNotifications(n.isSendActivationNotifications());
            if (n.getAttachments() != null) {
                selectedAttachments = new ArrayList<Long>();
                for (Attachment a : n.getAttachments()) selectedAttachments.add(a.getId());
            }

            if (this.enableScheduling) {
                switch (this.schedulingVariant) {
                    case VARIANT_1:
                        Map<String, Object> m1 = SchedulingStringParsingHelper.reverseConversion(n.getSchedulingExpression(), SchedulingVariant.VARIANT_1);
                        this.hoursAndMinutes = (String) m1.get("hoursAndMinutes");
                        this.varOneMonths = (List<Integer>) m1.get("months");
                        this.varOneDaysOfMonth = (List<Integer>) m1.get("daysOfMonth");
                        break;
                    case VARIANT_2:
                        Map<String, Object> m2 = SchedulingStringParsingHelper.reverseConversion(n.getSchedulingExpression(), SchedulingVariant.VARIANT_2);
                        this.hoursAndMinutes = (String) m2.get("hoursAndMinutes");
                        this.varTwoDaysOfWeek = (List<Integer>) m2.get("daysOfWeek");
                        this.varTwoMonths = (List<Integer>) m2.get("months");
                        break;
                    case VARIANT_3:
                        Map<String, Object> m3 = SchedulingStringParsingHelper.reverseConversion(n.getSchedulingExpression(), SchedulingVariant.VARIANT_3);
                        this.hoursAndMinutes = (String) m3.get("hoursAndMinutes");
                        this.varThreeMonths = (List<Integer>) m3.get("months");
                        this.varThreeDayOfWeek = (Integer) m3.get("dayOfWeek");
                        this.varThreeFirstOrLast = (FirstOrLast) m3.get("firstOrLast");
                        break;
                    case VARIANT_4:
                        this.varFourSchedulingExpression = n.getSchedulingExpression();
                        break;
                }
            }
        }
        return new ForwardResolution("/WEB-INF/pages/secure/addNoteForm.jsp");
View Full Code Here

        return new ForwardResolution("/WEB-INF/pages/secure/addNoteForm.jsp");
    }

    public Resolution save() {
        if (noteId != null) { //security check, if edited note is owned by the user
            Note tempNote = notesService.getNote(noteId);
            if (tempNote == null || !tempNote.getUser().equals(getContext().getUser()))
                return new ErrorResolution(403);
        }

        String schedulingString = null;
        if (enableScheduling) {
View Full Code Here

    public Resolution changeNoteStatus() {
        if (noteId == null) //if missing noteId, return 404
            return new ErrorResolution(404);

        Note note = notesService.getNote(noteId); //security check if user owns the note
        if (note == null || !note.getUser().equals(getContext().getUser()))
            return new ErrorResolution(403);

        notesService.activateNote(noteId, !note.isActivated(), false);
        return new RedirectResolution(NotesListActionBean.class);
    }
View Full Code Here

    }

    public Resolution putNoteToDefaultLocation() {
        if (noteId == null) return new ErrorResolution(404); //if missing noteId, 404

        Note note = notesService.getNote(noteId); //security check if user owns the note
        if (note == null || !note.getUser().equals(getContext().getUser()))
            return new ErrorResolution(403);

        note.setSizeAndPosition(new SizeAndPosition());
        try {
            notesService.saveNote(note);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
View Full Code Here

        this.scheduler = scheduler;
    }

    @Override
    public void activateNote(Long id, boolean activate, boolean sendNotification) {
        Note n = entityManager.find(Note.class, id);
        if (n == null) throw new IllegalArgumentException("Note has not been found.");
        boolean oldActivated = n.isActivated();
        n.setActivated(activate);
        if (activate && !oldActivated && n.isSendActivationNotifications() && sendNotification) {
            mailService.sendNoteActivationNotification(n);
        }
    }
View Full Code Here

    }

    @Override
    public Note saveNote(Note n) throws ParseException, SchedulerException {

        Note savedNote = entityManager.merge(n);
        if (n.getId() == null && n.getSchedulingExpression() != null) {
            Trigger trigger = new CronTrigger("triggerId" + savedNote.getId(), null, n.getSchedulingExpression()); //create trigger for note
            trigger.setJobName("activateNoteJob"); //set it should trigger the job which activates the note (job in singleton spring bean)
            trigger.getJobDataMap().putAsString("noteId", savedNote.getId()); //set id to the jobDataMap, so job can get the node to activate
            scheduler.scheduleJob(trigger); //schedule

        } else if (n.getId() != null) { // old note being updated
            if (scheduler.getTrigger("triggerId" + n.getId(), null) != null) { //if was scheduled, unschedule
                scheduler.unscheduleJob("triggerId" + n.getId(), null);
View Full Code Here

TOP

Related Classes of eu.semberal.reminders.entity.Note

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.