/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. package com.google.ie.business.domain;
  16. import com.google.ie.common.util.StringUtility;
  17. import org.compass.annotations.Searchable;
  18. import org.compass.annotations.SearchableId;
  19. import org.compass.annotations.SearchableProperty;
  20. import java.io.Serializable;
  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.List;
  24. import javax.jdo.annotations.Extension;
  25. import javax.jdo.annotations.IdGeneratorStrategy;
  26. import javax.jdo.annotations.IdentityType;
  27. import javax.jdo.annotations.Inheritance;
  28. import javax.jdo.annotations.InheritanceStrategy;
  29. import javax.jdo.annotations.NotPersistent;
  30. import javax.jdo.annotations.PersistenceCapable;
  31. import javax.jdo.annotations.Persistent;
  32. import javax.jdo.annotations.PrimaryKey;
  33. import javax.persistence.Transient;
  34. @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
  35. @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
  36. @Searchable(alias = "Comment")
  37. public abstract class Comment implements Serializable {
  38. /** A unique identifier for the class */
  39. private static final long serialVersionUID = -7116365690016325012L;
  40. @NotPersistent
  41. public static final String STATUS_OBJECTIONABLE = "Objectionable";
  42. @NotPersistent
  43. public static final String STATUS_SAVED = "Saved";
  44. @NotPersistent
  45. public static final String STATUS_FLAGGED = "Flagged";
  46. @NotPersistent
  47. public static final String FIELD_NAME_TEXT = "text";
  48. @PrimaryKey
  49. @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  50. @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
  51. @SearchableId
  52. private String key;
  53. @Persistent
  54. @SearchableProperty
  55. private List<String> text = new ArrayList<String>();
  56. @Persistent
  57. private String status;
  58. @Persistent
  59. private Date createdOn;
  60. @Persistent
  61. private String creatorKey;
  62. @Transient
  63. private String commentTextAsString;
  64. /**
  65. * @return the commentTextAsString
  66. */
  67. public String getCommentTextAsString() {
  68. return commentTextAsString;
  69. }
  70. /**
  71. * @param commentTextAsString the commentTextAsString to set
  72. */
  73. public void setCommentTextAsString(String commentTextAsString) {
  74. this.commentTextAsString = commentTextAsString;
  75. }
  76. /**
  77. * @return the key
  78. */
  79. public String getKey() {
  80. return key;
  81. }
  82. /**
  83. * @param key the key to set
  84. */
  85. public void setKey(String key) {
  86. this.key = key;
  87. }
  88. /**
  89. * @return the text
  90. */
  91. public String getText() {
  92. return convertListToString(text);
  93. }
  94. /**
  95. * @param text the text to set
  96. */
  97. public void setText(String text) {
  98. this.text = StringUtility.convertStringToList(text);
  99. }
  100. /**
  101. * @return the status
  102. */
  103. public String getStatus() {
  104. return status;
  105. }
  106. /**
  107. * @param status the status to set
  108. */
  109. public void setStatus(String status) {
  110. this.status = status;
  111. }
  112. /**
  113. * @return the createdOn
  114. */
  115. public Date getCreatedOn() {
  116. return createdOn;
  117. }
  118. /**
  119. * @param createdOn the createdOn to set
  120. */
  121. public void setCreatedOn(Date createdOn) {
  122. this.createdOn = createdOn;
  123. }
  124. /**
  125. * @param creatorKey the creatorKey to set
  126. */
  127. public void setCreatorKey(String creatorKey) {
  128. this.creatorKey = creatorKey;
  129. }
  130. /**
  131. * @return the creatorKey
  132. */
  133. public String getCreatorKey() {
  134. return creatorKey;
  135. }
  136. /**
  137. * This method concatenates a list of strings into a single string which
  138. * are actually stored as list of string into database.
  139. *
  140. * @param strings List of Strings
  141. */
  142. private String convertListToString(List<String> strings) {
  143. StringBuilder content = new StringBuilder("");
  144. if (strings != null && strings.size() > 0) {
  145. for (String description : strings) {
  146. content.append(description);
  147. }
  148. return content.toString();
  149. }
  150. return null;
  151. }
  152. }