Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. /**
  2. * This Source Code Form is subject to the terms of the Mozilla Public License,
  3. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  4. * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
  5. * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
  6. *
  7. * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
  8. * graphic logo is a trademark of OpenMRS Inc.
  9. */
  10. package org.openmrs.module.chartsearch.solr.nonPatient;
  11.  
  12. import java.io.Serializable;
  13. import java.util.List;
  14.  
  15. import javax.persistence.Column;
  16. import javax.persistence.Entity;
  17. import javax.persistence.GeneratedValue;
  18. import javax.persistence.GenerationType;
  19. import javax.persistence.Id;
  20. import javax.persistence.Table;
  21.  
  22. import org.apache.commons.lang.StringUtils;
  23. import org.openmrs.BaseOpenmrsObject;
  24. import org.openmrs.util.OpenmrsConstants;
  25.  
  26. /**
  27. * A web project that has database data attached to it. Such as Chart Search Module et-cetera
  28. */
  29. @Entity
  30. @Table(name = "chartsearch_project", schema = "public")
  31. public class SearchProject extends BaseOpenmrsObject implements Serializable {
  32.  
  33. private static final long serialVersionUID = 1L;
  34.  
  35. @Id
  36. @GeneratedValue(strategy = GenerationType.AUTO)
  37. @Column(name = "project_id")
  38. private int projectId;
  39.  
  40. @Column(name = "name")
  41. private String projectName;
  42.  
  43. @Column(name = "description")
  44. private String projectDescription;
  45.  
  46. @Column(name = "database")
  47. private String database;
  48.  
  49. @Column(name = "database_user")
  50. private String databaseUser;
  51.  
  52. @Column(name = "database_user_password")
  53. private String databaseUSerPassword;
  54.  
  55. @Column(name = "server_name")
  56. private String serverName;
  57.  
  58. @Column(name = "dbms")
  59. private String dbms;
  60.  
  61. @Column(name = "port_number")
  62. private String portNumber;
  63.  
  64. /**
  65. * The SQL Query to be run to return the data that need to be indexed for this particular
  66. * project
  67. */
  68. private String sqlQuery;
  69.  
  70. /**
  71. * List of column names that need to be added as fields obtained from the client
  72. */
  73. private List<String> columnNamesList;
  74.  
  75. /**
  76. * column names separated by commas, these should be unique from one another and the same ones
  77. * as mentioned in the sqlQuery, take use of AS key word in MySQL to make them unique
  78. */
  79. private String columnNames;
  80.  
  81. /**
  82. * Creates a SearchProject object when registering a project, must always use this when creating
  83. * this object
  84. *
  85. * @param projectName
  86. * @param sqlQuery
  87. * @param columnNamesList
  88. */
  89. public SearchProject(String projectName, String sqlQuery, List<String> columnNamesList, String database) {
  90. setProjectName(projectName);
  91. setSqlQuery(sqlQuery);
  92. setColumnNamesList(columnNamesList);
  93. setColumnNames(getColumnNamesSeparatedWithCommas());
  94. setDatabase(database);
  95. }
  96.  
  97. public SearchProject() {
  98.  
  99. }
  100.  
  101. public String getProjectName() {
  102. return projectName;
  103. }
  104.  
  105. public void setProjectName(String projectName) {
  106. this.projectName = projectName;
  107. }
  108.  
  109. public String getProjectDescription() {
  110. return projectDescription;
  111. }
  112.  
  113. public void setProjectDescription(String projectDescription) {
  114. this.projectDescription = projectDescription;
  115. }
  116.  
  117. public int getProjectId() {
  118. return projectId;
  119. }
  120.  
  121. public void setProjectId(int projectId) {
  122. this.projectId = projectId;
  123. }
  124.  
  125. public String getSqlQuery() {
  126. return sqlQuery;
  127. }
  128.  
  129. public void setSqlQuery(String sqlQuery) {
  130. this.sqlQuery = sqlQuery;
  131. }
  132.  
  133. /**
  134. * Doesn't return from the database, use {@link #getColumnNames()}
  135. *
  136. * @return
  137. */
  138. public List<String> getColumnNamesList() {
  139. return columnNamesList;
  140. }
  141.  
  142. public void setColumnNamesList(List<String> columnNamesList) {
  143. this.columnNamesList = columnNamesList;
  144. }
  145.  
  146. @Override
  147. public Integer getId() {
  148. return getProjectId();
  149. }
  150.  
  151. @Override
  152. public void setId(Integer id) {
  153. setProjectId(id);
  154. }
  155.  
  156. /**
  157. * Read only - Returns all columns separated by a comma and space(, ) from the the
  158. * {@link #getColumnNamesList()} Auto generated method comment
  159. *
  160. * @return comma separated column names otherwise NULL if no column name exists
  161. */
  162. public String getColumnNamesSeparatedWithCommas() {
  163. String commaSeperateColumnNames = "";
  164. List<String> columnNames = getColumnNamesList();
  165. for (int i = 0; i < columnNames.size(); i++) {
  166. if (i != columnNames.size() - 1) {
  167. commaSeperateColumnNames += columnNames.get(i) + ", ";
  168. } else
  169. commaSeperateColumnNames += columnNames.get(i);
  170. }
  171. if (StringUtils.isBlank(commaSeperateColumnNames)) {
  172. commaSeperateColumnNames = null;
  173. }
  174. return commaSeperateColumnNames;
  175. }
  176.  
  177. /**
  178. * Gets column names separated commas
  179. *
  180. * @see {@link #getColumnNamesSeparatedWithCommas()}
  181. */
  182. public String getColumnNames() {
  183. return columnNames;
  184. }
  185.  
  186. /**
  187. * @see {@link #getColumnNamesSeparatedWithCommas()}
  188. */
  189. public void setColumnNames(String columnNames) {
  190. this.columnNames = columnNames;
  191. }
  192.  
  193. public String getDatabase() {
  194. return database;
  195. }
  196.  
  197. /**
  198. * Sets the database name, if it is empty or whitespace or bull, it sets it to the openmrs
  199. * database
  200. *
  201. * @param database
  202. */
  203. public void setDatabase(String database) {
  204. if (StringUtils.isBlank(database)) {
  205. database = System.getProperty(OpenmrsConstants.DATABASE_NAME);
  206. }
  207. this.database = database;
  208. }
  209.  
  210. public String getDatabaseUser() {
  211. return databaseUser;
  212. }
  213.  
  214. public void setDatabaseUser(String databaseUser) {
  215. this.databaseUser = databaseUser;
  216. }
  217.  
  218. public String getDatabaseUSerPassword() {
  219. return databaseUSerPassword;
  220. }
  221.  
  222. public void setDatabaseUSerPassword(String databaseUSerPassword) {
  223. this.databaseUSerPassword = databaseUSerPassword;
  224. }
  225.  
  226. public String getServerName() {
  227. return serverName;
  228. }
  229.  
  230. public void setServerName(String serverName) {
  231. this.serverName = serverName;
  232. }
  233.  
  234. public String getDbms() {
  235. return dbms;
  236. }
  237.  
  238. public void setDbms(String dbms) {
  239. this.dbms = dbms;
  240. }
  241.  
  242. public String getPortNumber() {
  243. return portNumber;
  244. }
  245.  
  246. public void setPortNumber(String portNumber) {
  247. this.portNumber = portNumber;
  248. }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement