/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */

package com.haulmont.cuba.core.entity;

import com.haulmont.cuba.core.entity.annotation.SystemLevel;
import com.haulmont.cuba.core.global.SendingStatus;

import javax.persistence.*;
import javax.persistence.Entity;
import java.util.Date;
import java.util.List;

/**
 * Entity to store information about sending emails.
 *
 * @author ovchinnikov
 * @version $Id$
 */
@Entity(name = "sys$SendingMessage")
@Table(name = "SYS_SENDING_MESSAGE")
@SystemLevel
public class SendingMessage extends StandardEntity {

    private static final long serialVersionUID = -8156998515878702538L;

    public static final int CAPTION_LENGTH = 500;

    @Column(name = "ADDRESS_TO")
    protected String address;

    @Column(name = "ADDRESS_FROM")
    protected String from;

    @Column(name = "CAPTION", length = CAPTION_LENGTH)
    protected String caption;

    /**
     * Email body is stored either in this field or in {@link #contentTextFile}.
     */
    @Column(name = "CONTENT_TEXT")
    protected String contentText;

    @JoinColumn(name = "CONTENT_TEXT_FILE_ID")
    @OneToOne(fetch = FetchType.LAZY)
    protected FileDescriptor contentTextFile;

    @Column(name = "STATUS")
    protected Integer status;

    @Column(name = "DATE_SENT")
    protected Date dateSent;

    @Column(name = "ATTACHMENTS_NAME")
    protected String attachmentsName;

    @Column(name = "DEADLINE")
    protected Date deadline;

    @Column(name = "ATTEMPTS_COUNT")
    protected Integer attemptsCount;

    @Column(name = "ATTEMPTS_MADE")
    protected Integer attemptsMade;

    @OneToMany(mappedBy = "message", fetch = FetchType.LAZY)
    protected List<SendingAttachment> attachments;

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getContentText() {
        return contentText;
    }

    public void setContentText(String contentText) {
        this.contentText = contentText;
    }

    public Date getDeadline() {
        return deadline;
    }

    public void setDeadline(Date deadline) {
        this.deadline = deadline;
    }

    public SendingStatus getStatus() {
        return status == null ? null : SendingStatus.fromId(status);
    }

    public void setStatus(SendingStatus status) {
        this.status = status == null ? null : status.getId();
    }

    public Date getDateSent() {
        return dateSent;
    }

    public void setDateSent(Date dateSent) {
        this.dateSent = dateSent;
    }

    public Integer getAttemptsCount() {
        return attemptsCount;
    }

    public void setAttemptsCount(Integer attemptsCount) {
        this.attemptsCount = attemptsCount;
    }

    public String getAttachmentsName() {
        return attachmentsName;
    }

    public void setAttachmentsName(String attachmentsName) {
        this.attachmentsName = attachmentsName;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public void setCaption(String caption) {
        if (caption != null && caption.length() > SendingMessage.CAPTION_LENGTH) {
            caption = caption.substring(0, SendingMessage.CAPTION_LENGTH);
        }
        this.caption = caption;
    }

    public String getCaption() {
        return caption;
    }

    public List<SendingAttachment> getAttachments() {
        return attachments;
    }

    public void setAttachments(List<SendingAttachment> attachments) {
        this.attachments = attachments;
    }

    public Integer getAttemptsMade() {
        return attemptsMade;
    }

    public void setAttemptsMade(Integer attemptsMade) {
        this.attemptsMade = attemptsMade;
    }

    public FileDescriptor getContentTextFile() {
        return contentTextFile;
    }

    public void setContentTextFile(FileDescriptor contentTextFile) {
        this.contentTextFile = contentTextFile;
    }
}

@@ -310,16 +310,61 @@
 Status;%0D
+%0Aimport org.apache.commons.lang.StringUtils;%0D
 %0A%0D%0Aimpor
@@ -3417,113 +3417,34 @@
     
-if (caption != null && caption.length() %3E SendingMessage.CAPTION_LENGTH) %7B%0D%0A            caption = caption
+this.caption = StringUtils
 .sub
@@ -3450,16 +3450,25 @@
 bstring(
+caption, 
 0, Sendi
@@ -3499,52 +3499,8 @@
 );%0D%0A
-        %7D%0D%0A        this.caption = caption;%0D%0A
     

Use StringUtils cuba-trunk #PL-3137