PageRenderTime 383ms CodeModel.GetById 181ms app.highlight 10ms RepoModel.GetById 151ms app.codeStats 0ms

/src/main/java/com/google/ie/business/domain/Comment.java

http://thoughtsite.googlecode.com/
Java | 177 lines | 95 code | 25 blank | 57 comment | 4 complexity | 82f18a4534143258d93ec4e259d3aa33 MD5 | raw file
  1/* Copyright 2010 Google Inc.
  2 * 
  3 * Licensed under the Apache License, Version 2.0 (the "License");
  4 * you may not use this file except in compliance with the License.
  5 * You may obtain a copy of the License at
  6 * 
  7 *      http://www.apache.org/licenses/LICENSE-2.0
  8 * 
  9 * Unless required by applicable law or agreed to in writing, software
 10 * distributed under the License is distributed on an "AS IS" BASIS.
 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12 * See the License for the specific language governing permissions and
 13 * limitations under the License
 14 */
 15
 16package com.google.ie.business.domain;
 17
 18import com.google.ie.common.util.StringUtility;
 19
 20import org.compass.annotations.Searchable;
 21import org.compass.annotations.SearchableId;
 22import org.compass.annotations.SearchableProperty;
 23
 24import java.io.Serializable;
 25import java.util.ArrayList;
 26import java.util.Date;
 27import java.util.List;
 28
 29import javax.jdo.annotations.Extension;
 30import javax.jdo.annotations.IdGeneratorStrategy;
 31import javax.jdo.annotations.IdentityType;
 32import javax.jdo.annotations.Inheritance;
 33import javax.jdo.annotations.InheritanceStrategy;
 34import javax.jdo.annotations.NotPersistent;
 35import javax.jdo.annotations.PersistenceCapable;
 36import javax.jdo.annotations.Persistent;
 37import javax.jdo.annotations.PrimaryKey;
 38import javax.persistence.Transient;
 39
 40@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
 41@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
 42@Searchable(alias = "Comment")
 43public abstract class Comment implements Serializable {
 44
 45    /** A unique identifier for the class */
 46    private static final long serialVersionUID = -7116365690016325012L;
 47    @NotPersistent
 48    public static final String STATUS_OBJECTIONABLE = "Objectionable";
 49    @NotPersistent
 50    public static final String STATUS_SAVED = "Saved";
 51    @NotPersistent
 52    public static final String STATUS_FLAGGED = "Flagged";
 53    @NotPersistent
 54    public static final String FIELD_NAME_TEXT = "text";
 55
 56    @PrimaryKey
 57    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 58    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
 59    @SearchableId
 60    private String key;
 61
 62    @Persistent
 63    @SearchableProperty
 64    private List<String> text = new ArrayList<String>();
 65    @Persistent
 66    private String status;
 67    @Persistent
 68    private Date createdOn;
 69
 70    @Persistent
 71    private String creatorKey;
 72    @Transient
 73    private String commentTextAsString;
 74
 75    /**
 76     * @return the commentTextAsString
 77     */
 78    public String getCommentTextAsString() {
 79        return commentTextAsString;
 80    }
 81
 82    /**
 83     * @param commentTextAsString the commentTextAsString to set
 84     */
 85    public void setCommentTextAsString(String commentTextAsString) {
 86        this.commentTextAsString = commentTextAsString;
 87    }
 88
 89    /**
 90     * @return the key
 91     */
 92    public String getKey() {
 93        return key;
 94    }
 95
 96    /**
 97     * @param key the key to set
 98     */
 99    public void setKey(String key) {
100        this.key = key;
101    }
102
103    /**
104     * @return the text
105     */
106    public String getText() {
107        return convertListToString(text);
108    }
109
110    /**
111     * @param text the text to set
112     */
113    public void setText(String text) {
114        this.text = StringUtility.convertStringToList(text);
115    }
116
117    /**
118     * @return the status
119     */
120    public String getStatus() {
121        return status;
122    }
123
124    /**
125     * @param status the status to set
126     */
127    public void setStatus(String status) {
128        this.status = status;
129    }
130
131    /**
132     * @return the createdOn
133     */
134    public Date getCreatedOn() {
135        return createdOn;
136    }
137
138    /**
139     * @param createdOn the createdOn to set
140     */
141    public void setCreatedOn(Date createdOn) {
142        this.createdOn = createdOn;
143    }
144
145    /**
146     * @param creatorKey the creatorKey to set
147     */
148    public void setCreatorKey(String creatorKey) {
149        this.creatorKey = creatorKey;
150    }
151
152    /**
153     * @return the creatorKey
154     */
155    public String getCreatorKey() {
156        return creatorKey;
157    }
158
159    /**
160     * This method concatenates a list of strings into a single string which
161     * are actually stored as list of string into database.
162     * 
163     * @param strings List of Strings
164     */
165    private String convertListToString(List<String> strings) {
166        StringBuilder content = new StringBuilder("");
167        if (strings != null && strings.size() > 0) {
168            for (String description : strings) {
169                content.append(description);
170            }
171            return content.toString();
172        }
173        return null;
174    }
175
176}
177