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.kew.routeheader;
017
018import org.kuali.rice.core.api.util.xml.XmlJotter;
019
020import javax.persistence.Basic;
021import javax.persistence.Column;
022import javax.persistence.Convert;
023import javax.persistence.Entity;
024import javax.persistence.FetchType;
025import javax.persistence.Id;
026import javax.persistence.Lob;
027import javax.persistence.NamedQuery;
028import javax.persistence.Table;
029import java.io.Serializable;
030import 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")
036public 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