001    /**
002     * Copyright 2005-2014 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     */
016    package org.kuali.rice.kew.routeheader;
017    
018    import org.kuali.rice.core.api.util.xml.XmlJotter;
019    
020    import javax.persistence.Basic;
021    import javax.persistence.Column;
022    import javax.persistence.Convert;
023    import javax.persistence.Entity;
024    import javax.persistence.FetchType;
025    import javax.persistence.Id;
026    import javax.persistence.Lob;
027    import javax.persistence.NamedQuery;
028    import javax.persistence.Table;
029    import java.io.Serializable;
030    import java.util.Map;
031    
032    @Entity
033    @Table(name="KREW_DOC_HDR_CNTNT_T")
034    @NamedQuery(name="DocumentRouteHeaderValueContent.FindByDocumentId", query="select d from "
035            + "DocumentRouteHeaderValueContent as d where d.documentId = :documentId")
036    public class DocumentRouteHeaderValueContent implements Serializable {
037    
038            private static final long serialVersionUID = 1L;
039    
040            @Id
041            @Column(name="DOC_HDR_ID")
042            private String documentId;
043    
044            @Lob
045            @Basic(fetch=FetchType.LAZY)
046            @Column(name="DOC_CNTNT_TXT")
047        @Convert(converter = DocumentContentEncryptionConverter.class)
048            private String documentContent;
049                    
050            public DocumentRouteHeaderValueContent() {}
051            
052            public DocumentRouteHeaderValueContent(String documentId) {
053                    this.documentId = documentId;
054            }
055            
056            public String getDocumentContent() {
057                    return documentContent;
058            }
059            public void setDocumentContent(String documentContent) {
060                    this.documentContent = documentContent;
061            }
062            public String getDocumentId() {
063                    return documentId;
064            }
065            public void setDocumentId(String documentId) {
066                    this.documentId = documentId;
067            }
068    
069        public DocumentRouteHeaderValueContent deepCopy(Map<Object, Object> visited) {
070            if (visited.containsKey(this)) {
071                return (DocumentRouteHeaderValueContent)visited.get(this);
072            }
073            DocumentRouteHeaderValueContent copy = new DocumentRouteHeaderValueContent();
074            visited.put(this, copy);
075            copy.documentId = documentId;
076            copy.documentContent = documentContent;
077            return copy;
078        }
079            
080            public static org.kuali.rice.kew.api.document.DocumentContent to(DocumentRouteHeaderValueContent content) {
081                    if (content == null) {
082                            return null;
083                    }
084                    org.kuali.rice.kew.api.document.DocumentContent.Builder builder = org.kuali.rice.kew.api.document.DocumentContent.Builder.create(content.getDocumentId());
085                    // initialize the content fields
086                    builder.setApplicationContent("");
087                    builder.setAttributeContent("");
088                    builder.setSearchableContent("");
089                    DocumentContent documentContent = new StandardDocumentContent(content.getDocumentContent());
090                    if (documentContent.getApplicationContent() != null) {
091                            builder.setApplicationContent(XmlJotter.jotNode(documentContent.getApplicationContent()));
092                    }
093                    if (documentContent.getAttributeContent() != null) {
094                            builder.setAttributeContent(XmlJotter.jotNode(documentContent.getAttributeContent()));
095                    }
096                    if (documentContent.getSearchableContent() != null) {
097                            builder.setSearchableContent(XmlJotter.jotNode(documentContent.getSearchableContent()));
098                    }
099                    return builder.build();
100            }
101    
102    }
103