001/** 002 * Copyright 2005-2017 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.labs; 017 018 019import org.kuali.rice.krad.bo.DataObjectBase; 020import org.kuali.rice.krad.bo.PersistableAttachment; 021import org.kuali.rice.krad.data.provider.annotation.Description; 022import org.kuali.rice.krad.data.provider.annotation.Label; 023import org.kuali.rice.krad.data.provider.annotation.UifAutoCreateViewType; 024import org.kuali.rice.krad.data.provider.annotation.UifAutoCreateViews; 025import org.kuali.rice.krad.data.provider.annotation.UifDisplayHint; 026import org.kuali.rice.krad.data.provider.annotation.UifDisplayHintType; 027import org.kuali.rice.krad.data.provider.annotation.UifDisplayHints; 028import org.kuali.rice.krad.data.provider.annotation.UifValidCharactersConstraintBeanName; 029import org.kuali.rice.krad.uif.util.SessionTransient; 030import org.springframework.web.multipart.MultipartFile; 031import javax.persistence.Column; 032import javax.persistence.Entity; 033import javax.persistence.Id; 034import javax.persistence.JoinColumn; 035import javax.persistence.ManyToOne; 036import javax.persistence.Table; 037import javax.validation.constraints.NotNull; 038import java.io.Serializable; 039 040/** 041 * @author Kuali Rice Team (rice.collab@kuali.org) 042 */ 043@Entity 044@Table(name="trv_att_sample") 045@UifAutoCreateViews({UifAutoCreateViewType.LOOKUP}) 046public class LabsTravelAttachment extends DataObjectBase implements PersistableAttachment, Serializable { 047 048 @Id 049 @Column(name="ATTACHMENT_ID",length=30) 050 @Label("Id") 051 @Description("Unique identifier for the attachment") 052 @UifValidCharactersConstraintBeanName("AlphaNumericPatternConstraint") 053 private String id; 054 055 @ManyToOne 056 @JoinColumn(name = "ATT_GRP_NUM" ,insertable=false, updatable=false) 057 LabsTravelAttachmentGroup labsTravelAttachmentGroup; 058 059 @Id 060 @Column(name = "ATT_GRP_NUM",length = 10) 061 @Label("Travel Attachment Group Number") 062 @NotNull 063 private String travelAttachmentGroupNumber; 064 065 @Column(name="DESCRIPTION",length=100) 066 @Label("Description") 067 @Description("Descriptor for the attachment") 068 @UifDisplayHints({ 069 @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA)}) 070 private String description; 071 072 @Column(name="ATTACHMENT_FILENAME",length=300) 073 @Label("File Name") 074 @Description("File name of the attachment") 075 @UifDisplayHints({ 076 @UifDisplayHint(UifDisplayHintType.NO_INQUIRY), 077 @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA), 078 @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_RESULT)}) 079 private String fileName; 080 081 @Column(name="ATTACHMENT_FILE_CONTENT_TYPE",length=255) 082 @Label("Content Type") 083 @Description("Content Type of the attachment") 084 @UifDisplayHints({ 085 @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_RESULT)}) 086 private String contentType; 087 088 @Column(name="ATTACHMENT_FILE") 089 @Label("Attachment Content") 090 @Description("Content of the attachment") 091 @UifDisplayHints({ 092 @UifDisplayHint(UifDisplayHintType.NO_INQUIRY), 093 @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA), 094 @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_RESULT)}) 095 private byte[] attachmentContent; 096 097 @Label("Attachment File") 098 @Description("File of the attachment") 099 @SessionTransient 100 @UifDisplayHints({ 101 @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_CRITERIA), 102 @UifDisplayHint(UifDisplayHintType.NO_LOOKUP_RESULT)}) 103 private transient MultipartFile attachmentFile; 104 105 public String getId() { 106 return id; 107 } 108 109 public void setId(String id) { 110 this.id = id; 111 } 112 113 public String getDescription() { 114 return description; 115 } 116 117 public void setDescription(String description) { 118 this.description = description; 119 } 120 121 public String getFileName() { 122 return fileName; 123 } 124 125 public void setFileName(String fileName) { 126 this.fileName = fileName; 127 } 128 129 public String getContentType() { 130 return contentType; 131 } 132 133 public void setContentType(String contentType) { 134 this.contentType = contentType; 135 } 136 137 public byte[] getAttachmentContent() { 138 return attachmentContent; 139 } 140 141 public void setAttachmentContent(byte[] attachmentContent) { 142 this.attachmentContent = attachmentContent; 143 } 144 145 public MultipartFile getAttachmentFile() { 146 return attachmentFile; 147 } 148 149 public void setAttachmentFile(MultipartFile attachmentFile) { 150 //Convert multiPartFile to fields that can be saved in db 151 if(attachmentFile != null) { 152 setContentType(attachmentFile.getContentType()); 153 setFileName(attachmentFile.getOriginalFilename()); 154 try { 155 setAttachmentContent(attachmentFile.getBytes()); 156 157 }catch (Exception e) { 158 throw new RuntimeException(e); 159 } 160 } 161 } 162 163 public LabsTravelAttachmentGroup getLabsTravelAttachmentGroup() { 164 return labsTravelAttachmentGroup; 165 } 166 167 public void setLabsTravelAttachmentGroup(LabsTravelAttachmentGroup labsTravelAttachmentGroup) { 168 this.labsTravelAttachmentGroup = labsTravelAttachmentGroup; 169 } 170 171 public String getTravelAttachmentGroupNumber() { 172 return travelAttachmentGroupNumber; 173 } 174 175 public void setTravelAttachmentGroupNumber(String travelAttachmentGroupNumber) { 176 this.travelAttachmentGroupNumber = travelAttachmentGroupNumber; 177 } 178}