Guest User

Untitled

a guest
Nov 10th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. @Id
  2. private long _id;
  3.  
  4. @Field("account_name")
  5. private String accountName;
  6.  
  7. @Field("connector_type")
  8. private String connectorType;
  9.  
  10. @Field("xsiURI1")
  11. private String xsiURI1;
  12.  
  13. @Field("xsiURI2")
  14. private String xsiURI2;
  15.  
  16. @Field("oci1")
  17. private String OCI1;
  18.  
  19. @Field("oci2")
  20. private String OCI2;
  21.  
  22. @Field("telcomadmin_username")
  23. private String telcomadminUsername;
  24.  
  25. @Field("telcomadmin_password")
  26. private String telcomadminPassword;
  27.  
  28. @Field("password_expdays")
  29. private String passwordExpdays;
  30.  
  31. @Field("account_email_address")
  32. private String accountEmailAddress;
  33.  
  34. @DateTimeFormat(iso = ISO.DATE_TIME)
  35. @Field("inserted_date")
  36. private Date insertedDate;
  37.  
  38. @DateTimeFormat(iso = ISO.DATE_TIME)
  39. @Field("updated_date")
  40. private Date updatedDate;
  41.  
  42. @Field("isActive")
  43. private Boolean isActive;
  44.  
  45. public long get_id() {
  46. return _id;
  47. }
  48.  
  49. public void set_id(long _id) {
  50. this._id = _id;
  51. }
  52.  
  53. public String getXsiURI1() {
  54. return xsiURI1;
  55. }
  56.  
  57. public void setXsiURI1(String xsiURI1) {
  58. this.xsiURI1 = xsiURI1;
  59. }
  60.  
  61. public String getXsiURI2() {
  62. return xsiURI2;
  63. }
  64.  
  65. public void setXsiURI2(String xsiURI2) {
  66. this.xsiURI2 = xsiURI2;
  67. }
  68.  
  69. public String getOCI1() {
  70. return OCI1;
  71. }
  72.  
  73. public void setOCI1(String oCI1) {
  74. OCI1 = oCI1;
  75. }
  76.  
  77. public String getOCI2() {
  78. return OCI2;
  79. }
  80.  
  81. public void setOCI2(String oCI2) {
  82. OCI2 = oCI2;
  83. }
  84.  
  85. public String getAccountName() {
  86. return accountName;
  87. }
  88.  
  89. public void setAccountName(String accountName) {
  90. this.accountName = accountName;
  91. }
  92.  
  93. public String getConnectorType() {
  94. return connectorType;
  95. }
  96.  
  97. public void setConnectorType(String connectorType) {
  98. this.connectorType = connectorType;
  99. }
  100.  
  101. public String getTelcomadminUsername() {
  102. return telcomadminUsername;
  103. }
  104.  
  105. public void setTelcomadminUsername(String telcomadminUsername) {
  106. this.telcomadminUsername = telcomadminUsername;
  107. }
  108.  
  109. public String getTelcomadminPassword() {
  110. return telcomadminPassword;
  111. }
  112.  
  113. public void setTelcomadminPassword(String telcomadminPassword) {
  114. this.telcomadminPassword = telcomadminPassword;
  115. }
  116.  
  117. public String getPasswordExpdays() {
  118. return passwordExpdays;
  119. }
  120.  
  121. public void setPasswordExpdays(String passwordExpdays) {
  122. this.passwordExpdays = passwordExpdays;
  123. }
  124.  
  125. public String getAccountEmailAddress() {
  126. return accountEmailAddress;
  127. }
  128.  
  129. public void setAccountEmailAddress(String accountEmailAddress) {
  130. this.accountEmailAddress = accountEmailAddress;
  131. }
  132.  
  133. public Date getInsertedDate() {
  134. return insertedDate;
  135. }
  136.  
  137. public void setInsertedDate(Date insertedDate) {
  138. this.insertedDate = insertedDate;
  139. }
  140.  
  141. public Date getUpdatedDate() {
  142. return updatedDate;
  143. }
  144.  
  145. public void setUpdatedDate(Date updatedDate) {
  146. this.updatedDate = updatedDate;
  147. }
  148.  
  149. public Boolean getIsActive() {
  150. return isActive;
  151. }
  152.  
  153. public void setIsActive(Boolean isActive) {
  154. this.isActive = isActive;
  155. }
  156.  
  157. @RestController
  158. @RequestMapping("/accounts")
  159. @CrossOrigin("*")
  160. public class AccountsController {
  161. @Autowired
  162. AccountsRepository accountsRepository;
  163.  
  164. @Autowired
  165. SequenceRepository sequenceRepository;
  166.  
  167. private static final String ACCOUNT_SEQ_KEY = "accountsequence";
  168.  
  169. @PostMapping("/create")
  170. public Account createAccount(@Valid @RequestBody Account account) {
  171. account.set_id(sequenceRepository.getNextSequenceId(ACCOUNT_SEQ_KEY));
  172. account.setIsActive(true);
  173. return accountsRepository.save(account);
  174. }
  175.  
  176. @GetMapping(value = "/findByID/{id}")
  177. public ResponseEntity<Account> getAccountById(@PathVariable("id") String id) {
  178. Account account = accountsRepository.findOne(id);
  179. if (account == null) {
  180. return new ResponseEntity<>(HttpStatus.NOT_FOUND);
  181. } else {
  182. return new ResponseEntity<>(account, HttpStatus.OK);
  183. }
  184. }
  185. }
  186.  
  187. public interface AccountsRepository {
  188.  
  189. List<Account> findAll(Sort sortByCreatedAtDesc);
  190.  
  191. Account save(Account account);
  192.  
  193. Account findOne(String id);
  194.  
  195. void delete(String id);
  196.  
  197. }
  198.  
  199. @Repository
  200. public class AccountsRepositoryImpl implements AccountsRepository {
  201. DBOperations dbOperations = new DBOperations();
  202.  
  203. @Override
  204. public List<Account> findAll(Sort sortByCreatedAtDesc) {
  205. Query q = new Query().with(new Sort(Sort.Direction.ASC, "inserted_date"));
  206. List<Account> accountList = dbOperations.getMongoOpertion().findAllAndRemove(q, Account.class);
  207. return accountList;
  208. }
  209.  
  210. @Override
  211. public Account save(Account account) {
  212. try {
  213. dbOperations.getMongoOpertion().save(account);
  214. } catch (Exception e) {
  215. e.printStackTrace();
  216. }
  217. return account;
  218. }
  219.  
  220. @Override
  221. public Account findOne(String id) {
  222. Account account = dbOperations.getMongoOpertion().findOne(Query.query(Criteria.where("_id").is(id)),
  223. Account.class, "account");
  224. return account;
  225. }
  226.  
  227. @Override
  228. public void delete(String id) {
  229. Query query = new Query();
  230. query.addCriteria(Criteria.where("id").is(id));
  231. Account account = dbOperations.getMongoOpertion().findOne(query, Account.class);
  232. dbOperations.getMongoOpertion().remove(account);
  233.  
  234. }
  235.  
  236. }
Add Comment
Please, Sign In to add comment