Guest User

Untitled

a guest
Apr 11th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.07 KB | None | 0 0
  1. <beans:bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
  2. <beans:property name="dataSourceClassName" value="org.postgresql.ds.PGSimpleDataSource"/>
  3.  
  4. <beans:property name="maximumPoolSize" value="100" />
  5. <beans:property name="maxLifetime" value="300000" />
  6. <beans:property name="idleTimeout" value="300000" />
  7. <beans:property name="dataSourceProperties">
  8. <beans:props>
  9. <beans:prop key="url">jdbc:postgresql://localhost:PORT_NOS/DB_NAME</beans:prop>
  10. <beans:prop key="user">USERNAME</beans:prop>
  11. <beans:prop key="password">PASSWORD</beans:prop>
  12.  
  13. </beans:props>
  14. </beans:property>
  15. </beans:bean>
  16.  
  17. <!-- Hibernate 4 SessionFactory Bean definition -->
  18. <beans:bean id="hibernate4AnnotatedSessionFactory"
  19. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  20. <beans:property name="dataSource" ref="dataSource"/>
  21. <beans:property name="packagesToScan" value="com.ourapp.spring.model"/>
  22. <beans:property name="hibernateProperties">
  23. <beans:props>
  24. <beans:prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</beans:prop>
  25. <beans:prop key="hibernate.show_sql">false</beans:prop>
  26. <beans:prop key="hibernate.jdbc.batch_size">50</beans:prop>
  27. <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>
  28. <beans:prop key="cache.use_second_level_cache">true</beans:prop>
  29. <beans:prop key="cache.use_query_cache">true</beans:prop>
  30. <beans:prop key="hibernate.order_updates">true</beans:prop>
  31. <beans:prop key="show_sql">false</beans:prop>
  32. </beans:props>
  33. </beans:property>
  34.  
  35. </beans:bean>
  36.  
  37. @Override
  38. public int duplicateGroupNote(int groupNoteId, int sectionId, long groupAccountId, boolean duplicateFlag,
  39. boolean sendNotification, double sortValue, boolean copyFlag) {
  40. Person person = this.personService.getCurrentlyAuthenticatedUser();
  41. GroupNotes savedNote = this.groupNotesDAO.getGroupNoteById(groupNoteId);
  42. GroupSection originSection = this.groupSectionService.getGroupSectionById(savedNote.getOwnedSectionId());
  43. GroupCanvas originCanvas = this.groupCanvasService.getCanvasById(originSection.getCurrentCanvasId());
  44. GroupAccount originAccount = this.groupAccountService.getGroupById(originCanvas.getGroupAccountId());
  45. GroupMembers etherPadMember = this.groupMembersService.returnMembersMatchingUsernameAccountId(person.getUsername(), groupAccountId);
  46. GroupAccount destinationGroupAccount = this.groupAccountService.getGroupById(groupAccountId);
  47. GroupSection groupSection = this.groupSectionService.getGroupSectionById(sectionId);
  48. GroupCanvas groupCanvas = this.groupCanvasService.getCanvasById(groupSection.getCurrentCanvasId());
  49. GroupAccount groupAccount = this.groupAccountService.getGroupById(groupCanvas.getGroupAccountId());
  50. Permission permission = this.permissionService.getPermissionForMember(groupAccount.getGroupId());
  51. GroupMembers actionMember = this.groupMembersService.returnMembersMatchingUsernameAccountId(person.getUsername(), originAccount.getGroupId());
  52.  
  53. String teamAndBoardNameOrigin = originAccount.getGroupName() + ", " + originCanvas.getMcanvasname();
  54. String teamAndBoardTextOrigin = savedNote.getMnotetag() + ", Note Verschoben";
  55.  
  56. String teamAndBoardNameDestination = groupAccount.getGroupName() + ", " + groupCanvas.getMcanvasname();
  57.  
  58. List<Object> toSendObjectList = new ArrayList<>();
  59. final int[] updatedNoteId = new int[1];
  60. if (permission.isAddNote()) {
  61. this.activityCounterService.saveGroupNotActivity(groupNoteId);
  62. this.noteActivityService.saveGroupNotActivity(actionMember.getMemberid());
  63. GroupNotes duplicateNote;
  64. if (duplicateFlag) {
  65. duplicateNote = new GroupNotes("Kopie von: " + savedNote.getMnotetag(), "",
  66. sortValue, savedNote.getMnotecolor(),
  67. new Timestamp(System.currentTimeMillis()), savedNote.getCreatorId(),
  68. savedNote.getNoteCreatorEmail(), savedNote.getNoteDate());
  69. } else {
  70. duplicateNote = new GroupNotes(savedNote.getMnotetag(), "",
  71. sortValue, savedNote.getMnotecolor(),
  72. new Timestamp(System.currentTimeMillis()), savedNote.getCreatorId(),
  73. savedNote.getNoteCreatorEmail(), savedNote.getNoteDate());
  74. }
  75. duplicateNote.setAttachCount(savedNote.getAttachCount());
  76. duplicateNote.setCanvasUrl(savedNote.getCanvasUrl());
  77. duplicateNote.setCollapse(savedNote.isCollapse());
  78. duplicateNote.setDisabledSortId(savedNote.getDisabledSortId());
  79. duplicateNote.setEndIsMilestone(savedNote.isEndIsMilestone());
  80. duplicateNote.setGannt(false);
  81. duplicateNote.setGanntOrder(0);
  82. duplicateNote.setGanttDuration(0);
  83. duplicateNote.setGanttStatus("");
  84. duplicateNote.setRandomNos(UUID.randomUUID().toString());
  85. duplicateNote.setLevel(0);
  86. duplicateNote.setNoteDisabled(savedNote.isNoteDisabled());
  87. duplicateNote.setNoteInActive(savedNote.isNoteInActive());
  88. duplicateNote.setNoteTarget(savedNote.getNoteTarget());
  89. duplicateNote.setUploader(savedNote.getUploader());
  90. duplicateNote.setCanvasId(groupCanvas.getMcanvasid());
  91. duplicateNote.setGroupId(groupAccount.getGroupId());
  92. duplicateNote.setUrgent(savedNote.isUrgent());
  93. duplicateNote.setTags(savedNote.getTags());
  94. duplicateNote.setErledigtPersonId(savedNote.getErledigtPersonId());
  95. duplicateNote.setErledigtTimestamp(savedNote.getErledigtTimestamp());
  96. duplicateNote.setFinished(savedNote.isFinished());
  97. duplicateNote.setProcessing(true);
  98.  
  99. try {
  100. if ((savedNote.getPadId() != null) && (!savedNote.getPadId().isEmpty())) {
  101. String text = this.initailizeEpadClient.getTextForGivePad(savedNote.getPadId());
  102. //text = Jsoup.parse(text).text();
  103. String padID = this.initailizeEpadClient.createPadObjectsWithHtmlForDuplicateNotes(etherPadMember.getSessionData(), text);
  104.  
  105. duplicateNote.setPadId(padID);
  106. //this.initailizeEpadClient.copyPad(savedNote.getPadId(), padID);
  107. String oldText = this.initailizeEpadClient.getTextForGivePad(padID);
  108. if (oldText != null) {
  109. duplicateNote.setMnotetext(oldText);
  110. }
  111. } else {
  112. duplicateNote.setMnotetext(savedNote.getMnotetext());
  113. }
  114. } catch (Exception e) {
  115. e.printStackTrace();
  116.  
  117. duplicateNote.setMnotetext(savedNote.getMnotetext());
  118. }
  119.  
  120. if (!duplicateFlag) {
  121. duplicateNote.setNoteNumber(savedNote.getNoteNumber());
  122. duplicateNote.setCreatorId(savedNote.getCreatorId());
  123. } else {
  124. duplicateNote.setCreatorId(person.getId());
  125. this.groupCanvasService.directUpdateGroupCanvas(groupCanvas);
  126. groupCanvas = this.groupCanvasService.getCanvasById(groupCanvas.getMcanvasid());
  127. groupCanvas.setNoteCount(groupCanvas.getNoteCount() + 1);
  128. this.groupCanvasService.directUpdateGroupCanvas(groupCanvas);
  129. duplicateNote.setNoteNumber(groupCanvas.getNoteCount());
  130. }
  131. duplicateNote.setFinished(savedNote.isFinished());
  132. duplicateNote.setExcelData(savedNote.getExcelData());
  133. if (savedNote.getZugwisenPersonId() != 0) {
  134. Person zugweisedUser = this.personService.getPersonById(savedNote.getZugwisenPersonId());
  135. if (zugweisedUser != null) {
  136. GroupMembers groupMembers = this.groupMembersService.returnMembersMatchingUsernameAccountId(zugweisedUser.getUsername(), groupAccountId);
  137. if (groupMembers != null) {
  138. duplicateNote.setZugwisenPersonId(savedNote.getZugwisenPersonId());
  139. duplicateNote.setZugwisenPersonTimestamp(savedNote.getZugwisenPersonTimestamp());
  140. duplicateNote.setPersonWhoZugweised(savedNote.getPersonWhoZugweised());
  141. } else {
  142. duplicateNote.setZugwisenPersonId(0);
  143. duplicateNote.setZugwisenPersonTimestamp(null);
  144. duplicateNote.setPersonWhoZugweised(0);
  145. }
  146. }
  147. }
  148. duplicateNote.setStartDateTimestamp(savedNote.getStartDateTimestamp());
  149. duplicateNote.setPrefix(savedNote.getPrefix());
  150. duplicateNote.setTaskRelations(savedNote.getTaskRelations());
  151. duplicateNote.setPrivateNoteFlag(savedNote.isPrivateNoteFlag());
  152. duplicateNote.setProcessing(true);
  153. try {
  154. if (duplicateFlag) {
  155. updatedNoteId[0] = this.groupNotesDAO.saveGroupNoteAndReturnId(duplicateNote, sectionId);
  156. } else {
  157. updatedNoteId[0] = this.groupNotesDAO.saveGroupNoteAndReturnId(duplicateNote, sectionId);
  158. if (originAccount.getGroupId() != groupAccount.getGroupId()) {
  159. this.activityCounterService.saveGroupNotActivity(updatedNoteId[0]);
  160. GroupMembers groupMembers = this.groupMembersService.returnMembersMatchingUsernameAccountId(person.getUsername(), groupAccount.getGroupId());
  161. if (groupMembers != null) {
  162. this.noteActivityService.saveGroupNotActivity(groupMembers.getMemberid());
  163. }
  164. }
  165. }
  166. sendControlNotificationsForNote(null, updatedNoteId[0], groupSection.getMsectionid(), groupCanvas.getMcanvasid(), destinationGroupAccount.getGroupId(), false);
  167. GroupNotes databaseNoteObject = this.groupNotesDAO.getGroupNoteById(updatedNoteId[0]);
  168. this.groupAttachmentsService.saveIndexes(databaseNoteObject.getMnotetext() + " " + databaseNoteObject.getTags(), databaseNoteObject.getMnotetag(), null, groupAccount.getGroupId(), true, databaseNoteObject.getMnoticesid());
  169. List<Integer> noteFollowers = this.noteFollowService.getNoteFollowsForNote(groupNoteId);
  170. if (noteFollowers != null) {
  171. for (Integer id : noteFollowers) {
  172. this.noteFollowService.addNoteFollow(id, updatedNoteId[0]);
  173. }
  174. }
  175. } catch (Exception e) {
  176. e.printStackTrace();
  177.  
  178. }
  179.  
  180. List<GroupNoteHistory> groupNoteHistoryList = this.groupNoteHistoryService.getNoteHistoryById(savedNote.getMnoticesid());
  181. try {
  182. int i = 0;
  183. for (GroupNoteHistory groupNoteHistory : groupNoteHistoryList) {
  184. i++;
  185. GroupNoteHistory targetGroupHistory = new GroupNoteHistory();
  186. targetGroupHistory.setChangedMessage(groupNoteHistory.getChangedMessage());
  187. targetGroupHistory.setEditorId(groupNoteHistory.getEditorId());
  188. targetGroupHistory.setFirstName(groupNoteHistory.getFirstName());
  189. targetGroupHistory.setMnoteEditDate(groupNoteHistory.getMnoteEditDate());
  190. targetGroupHistory.setNestedComment(groupNoteHistory.isNestedComment());
  191. targetGroupHistory.setNestedId(groupNoteHistory.getNestedId());
  192. targetGroupHistory.setNestedCommentList(groupNoteHistory.getNestedCommentList());
  193. targetGroupHistory.setNewNoteHeadline(groupNoteHistory.getNewNoteHeadline());
  194. targetGroupHistory.setNewNoteText(groupNoteHistory.getNewNoteText());
  195. targetGroupHistory.setOldHeadLine(groupNoteHistory.getOldHeadLine());
  196. targetGroupHistory.setOldText(groupNoteHistory.getOldText());
  197. targetGroupHistory.setParent(groupNoteHistory.isParent());
  198. targetGroupHistory.setPinned(groupNoteHistory.isPinned());
  199. targetGroupHistory.setPinnedTime(groupNoteHistory.getPinnedTime());
  200. targetGroupHistory.setWhatHasChanged(groupNoteHistory.getWhatHasChanged());
  201.  
  202. int saveId = this.groupNoteHistoryService.addNoteHistory(targetGroupHistory, updatedNoteId[0]);
  203. if (saveId != 0) {
  204. toSendObjectList.add(this.groupNoteHistoryService.getGroupNoteHistoryById(saveId));
  205. }
  206. if (groupNoteHistory.isParent()) {
  207. int j = 0;
  208. List<GroupNoteHistory> nestedList = this.groupNoteHistoryService.getChildHistoryEntries(groupNoteHistory.getMhistoryid());
  209. for (GroupNoteHistory nestedHistory : nestedList) {
  210. j++;
  211. GroupNoteHistory nestedHistoryEntry = new GroupNoteHistory();
  212. nestedHistoryEntry.setFirstName(nestedHistory.getFirstName());
  213. nestedHistoryEntry.setChangedMessage(nestedHistory.getChangedMessage());
  214. nestedHistoryEntry.setEditorId(nestedHistory.getEditorId());
  215. nestedHistoryEntry.setFirstName(nestedHistory.getFirstName());
  216. nestedHistoryEntry.setMnoteEditDate(nestedHistory.getMnoteEditDate());
  217. nestedHistoryEntry.setNestedComment(nestedHistory.isNestedComment());
  218. nestedHistoryEntry.setNestedCommentList(nestedHistory.getNestedCommentList());
  219. nestedHistoryEntry.setNewNoteHeadline(nestedHistory.getNewNoteHeadline());
  220. nestedHistoryEntry.setNewNoteText(nestedHistory.getNewNoteText());
  221. nestedHistoryEntry.setOldHeadLine(nestedHistory.getOldHeadLine());
  222. nestedHistoryEntry.setOldText(nestedHistory.getOldText());
  223. nestedHistoryEntry.setParent(nestedHistory.isParent());
  224. nestedHistoryEntry.setPinned(nestedHistory.isPinned());
  225. nestedHistoryEntry.setPinnedTime(nestedHistory.getPinnedTime());
  226. nestedHistoryEntry.setWhatHasChanged(nestedHistory.getWhatHasChanged());
  227. nestedHistoryEntry.setNestedId(saveId);
  228. int nestedId = this.groupNoteHistoryService.addNoteHistory(nestedHistoryEntry, updatedNoteId[0]);
  229. if (nestedId != 0) {
  230. toSendObjectList.add(this.groupNoteHistoryService.getGroupNoteHistoryById(nestedId));
  231. }
  232. if (j % 50 == 0) {
  233. this.groupNoteHistoryService.flushSession();
  234. }
  235.  
  236. }
  237. }
  238. if (i % 50 == 0) {
  239. this.groupNoteHistoryService.flushSession();
  240. }
  241.  
  242. }
  243. } catch (Exception e) {
  244. e.printStackTrace();
  245.  
  246. }
  247. this.groupNoteHistoryService.flushSession();
  248. GroupNotes dbNote = getGroupNoteObjectById(updatedNoteId[0]);
  249. try {
  250. try {
  251. List<GroupAttachments> groupAttachmentsSet = this.groupAttachmentsService.getAttachmenByNoteId(groupNoteId);
  252. Collections.reverse(groupAttachmentsSet);
  253. boolean flag;
  254. int i = 0;
  255. for (GroupAttachments groupAttachments : groupAttachmentsSet) {
  256. flag = false;
  257. i++;
  258. if ((groupAttachments.getApiUsed() == null) || (groupAttachments.getApiUsed().isEmpty())) {
  259. flag = true;
  260. GroupAttachments attachmentWithData = this.groupAttachmentsService
  261. .getAttachmenById(groupAttachments.getGroupAttachId());
  262. if (attachmentWithData != null) {
  263. this.groupAttachmentsService.addAttachmentForCopy(attachmentWithData, dbNote, false,
  264. groupSection, groupCanvas, destinationGroupAccount);
  265. }
  266. }
  267.  
  268.  
  269. if (!(groupAttachments.getApiUsed() == null)) {
  270. if (!(groupAttachments.getApiUsed().isEmpty())) {
  271. if ((groupAttachments.getApiUsed().equals("google")) && (!flag)) {
  272. flag = true;
  273.  
  274. if (destinationGroupAccount.isUseDrive()) {
  275. InputStream inputStream = this.driveQuickstart.downloadFile(groupAttachments
  276. .getGroupAttachId(), destinationGroupAccount.getGroupId(), false);
  277. byte[] bytes = IOUtils.toByteArray(inputStream);
  278.  
  279. this.driveQuickstart.insertFile(bytes, groupAttachments.getFileName(),
  280. groupAttachments.getMimeType(), groupAttachments.getFileSize(),
  281. updatedNoteId[0], destinationGroupAccount.getGroupId(),
  282. "", false, groupAttachments);
  283.  
  284. }
  285. }
  286. }
  287. }
  288.  
  289. if (!(groupAttachments.getApiUsed() == null)) {
  290. if (!(groupAttachments.getApiUsed().isEmpty())) {
  291. if (((groupAttachments.getApiUsed().equals("dropbox")) && (!flag))) {
  292. flag = true;
  293.  
  294. if (destinationGroupAccount.isUseDropbox()) {
  295. InputStream inputStream = this.dropboxTask.downloadFile(groupAttachments
  296. .getGroupAttachId()
  297. , false);
  298. byte[] bytes = IOUtils.toByteArray(inputStream);
  299.  
  300. this.dropboxTask.insertFileAsByteArray(bytes, groupAttachments.getFileName(),
  301. groupAttachments.getMimeType(),
  302. groupAttachments.getFileSize(), "", updatedNoteId[0],
  303. destinationGroupAccount.getGroupId(), false, groupAttachments);
  304. }
  305. }
  306. }
  307. }
  308.  
  309. if (!flag) {
  310. if (!(groupAttachments.getApiUsed() == null)) {
  311. if (!(groupAttachments.getApiUsed().isEmpty())) {
  312. if ((groupAttachments.getApiUsed().equals("google"))) {
  313. flag = true;
  314. InputStream inputStream = this.driveQuickstart.downloadFile(groupAttachments
  315. .getGroupAttachId(), destinationGroupAccount.getGroupId(), true);
  316.  
  317. byte[] bytes = IOUtils.toByteArray(inputStream);
  318. groupAttachments.setSendAttachment(bytes);
  319. this.groupAttachmentsService.addAttachmentForCopy(groupAttachments, dbNote, false,
  320. groupSection, groupCanvas, destinationGroupAccount);
  321. }
  322. }
  323. }
  324.  
  325. if (!(groupAttachments.getApiUsed() == null)) {
  326. if (!(groupAttachments.getApiUsed().isEmpty())) {
  327. if (groupAttachments.getApiUsed().equals("dropbox")) {
  328. flag = true;
  329.  
  330.  
  331. InputStream inputStream = this.dropboxTask.downloadFile(groupAttachments.getGroupAttachId()
  332. , false);
  333. byte[] bytes = IOUtils.toByteArray(inputStream);
  334.  
  335. groupAttachments.setSendAttachment(bytes);
  336. this.groupAttachmentsService.addAttachmentForCopy(groupAttachments, dbNote, false,
  337. groupSection, groupCanvas, destinationGroupAccount);
  338. }
  339. }
  340. }
  341.  
  342. if (!flag) {
  343. GroupAttachments attachmentWithData = this.groupAttachmentsService
  344. .getAttachmenById(groupAttachments.getGroupAttachId());
  345. if (attachmentWithData != null) {
  346. this.groupAttachmentsService.addAttachmentForCopy(attachmentWithData, dbNote, false,
  347. groupSection, groupCanvas, destinationGroupAccount);
  348. }
  349. }
  350.  
  351. }
  352. if (i % 50 == 0) {
  353. this.groupNoteHistoryService.flushSession();
  354. }
  355.  
  356. }
  357. } catch (Exception e) {
  358. e.printStackTrace();
  359.  
  360. }
  361.  
  362. } catch (Exception e) {
  363. e.printStackTrace();
  364.  
  365. }
  366. this.groupNoteHistoryService.flushSession();
  367.  
  368.  
  369. if ((!duplicateFlag)) {
  370. final GroupCanvas finalGroupCanvas = groupCanvas;
  371.  
  372. Thread saveThread = new Thread(() -> {
  373. List<GroupMembers> groupMembersList = this.groupMembersService.returnGroupMembers(groupAccount.getGroupId());
  374. boolean archiveSuccess = this.groupNotesDAO.setNoteStatus(groupNoteId, true);
  375. if (archiveSuccess && sendNotification) {
  376. for (GroupMembers groupMembers : groupMembersList) {
  377. if (!(person.getUsername().equals(groupMembers.getMemberUsername()))) {
  378. NotificationType notificationType = this.notificationTypeService.getNotificationTypeForMember(groupMembers.getMemberid());
  379. if (notificationType.isRemoveNote()) {
  380. Notification notification = this.notificationService.createNotification(person.getId(), false, "",
  381. groupAccount.getGroupName() + ", " + finalGroupCanvas.getMcanvasname(),
  382. "", "", originSection.getMsectionid(),
  383. originCanvas.getMcanvasid(), savedNote.getMnoticesid(), savedNote.getMnotecolor(), groupAccountId);
  384. notification.setBroadCast(false);
  385. notification.setZugweisedPersonId(savedNote.getZugwisenPersonId());
  386. notification.setSendNoteId(groupNoteId);
  387. notification.setRemove(true);
  388. notification.setSubject(teamAndBoardNameOrigin);
  389. notification.setText(teamAndBoardTextOrigin);
  390. this.notificationService.addNotification(notification,
  391. groupMembers.getMemberid());
  392. }
  393.  
  394. if (groupMembers.isNotifyWhenNoteDeleted()) {
  395. if (!(person.getUsername().equals(groupMembers.getMemberUsername()))) {
  396. Person memberPerson = this.personService.findPersonByUsername(groupMembers.getMemberUsername());
  397. Permission emailPerm = this.permissionService.getPermissionByEmailAndGroupId(groupMembers.getTempgroupaccountid(), memberPerson.getId());
  398. if (emailPerm != null) {
  399. if ((emailPerm.isAllNotes()) ||
  400. (savedNote.getZugwisenPersonId() == groupMembers.getTransientPerson().getId())) {
  401. boolean allowed = this.canvasAllowedService.checkIfCanvasAllowedForMember(groupMembers.getMemberid(), originCanvas.getMcanvasid());
  402. if (allowed) {
  403. sendNoteDeletionEmail(originAccount.getGroupName(),
  404. groupMembers.getMemberUsername(), person.getFirstName(),
  405. savedNote.getMnotetag(), originCanvas.getMcanvasname(), originSection.getMsectionname(),
  406. originCanvas.getMcanvasid(),
  407. savedNote, originAccount.getGroupId(), person.getId());
  408. }
  409. }
  410. }
  411. }
  412. }
  413. } else {
  414. sendControlNotificationsForNote(null, groupNoteId, originSection.getMsectionid(), originCanvas.getMcanvasid(), originAccount.getGroupId(), true);
  415. }
  416. }
  417. } else {
  418. sendControlNotificationsForNote(null, groupNoteId, originSection.getMsectionid(), originCanvas.getMcanvasid(), originAccount.getGroupId(), true);
  419. }
  420. });
  421. saveThread.start();
  422. }
  423.  
  424. GroupNotes updatedNote =
  425. this.groupNotesDAO.getGroupNoteById(updatedNoteId[0]);
  426. if (!duplicateFlag) {
  427. int copyHistoryID = this.groupNoteHistoryService.addNoteHistory(new GroupNoteHistory(new Timestamp(System.currentTimeMillis()),
  428. "cut", "Diese Note wurde in das Board " + groupCanvas.getMcanvasname() + " ausgeschnitten",
  429. person.getId()), groupNoteId);
  430. GroupNoteHistory copyHistory = this.groupNoteHistoryService.getGroupNoteHistoryById(copyHistoryID);
  431. toSendObjectList.add(copyHistory);
  432.  
  433. List<GroupMembers> groupMembersList = this.groupMembersService.returnGroupMembers(originAccount.getGroupId());
  434. for (GroupMembers groupMembers : groupMembersList) {
  435. if (!person.getUsername().equals(groupMembers.getMemberUsername())) {
  436. NotificationType notificationType = this.notificationTypeService.getNotificationTypeForMember(groupMembers.getMemberid());
  437. if (notificationType.isNoteCopy()) {
  438. Notification copyNotification = new Notification(teamAndBoardNameOrigin + "Note Ausgeschnitten", "Note Ausgeschnitten",
  439. originSection.getMsectionid(), originCanvas.getMcanvasid(),
  440. person.getId(), false, new Timestamp(System.currentTimeMillis()), "copy",
  441. savedNote.getMnotecolor(), true, originAccount.getGroupId());
  442. copyNotification.setSendNoteId(groupNoteId);
  443. copyNotification.setObjects(toSendObjectList);
  444. copyNotification.setSubject(teamAndBoardNameOrigin);
  445. copyNotification.setText(teamAndBoardTextOrigin);
  446. this.chatService.sendNotification(copyNotification, groupMembers.getMemberid());
  447. }
  448. }
  449. }
  450.  
  451. // toSendObjectList.clear();
  452.  
  453.  
  454. int pasteId = this.groupNoteHistoryService.addNoteHistory(new GroupNoteHistory(new Timestamp(System.currentTimeMillis()),
  455. "paste", "Eingefügt in: " + groupAccount.getGroupName() + ", " + groupCanvas.getMcanvasname() + ", " + groupSection.getMsectionname(),
  456. person.getId()), updatedNote.getMnoticesid());
  457. GroupNoteHistory pasteHistory = this.groupNoteHistoryService.getGroupNoteHistoryById(pasteId);
  458. toSendObjectList.add(pasteHistory);
  459.  
  460. List<GroupMembers> updatedGroupMembersList = this.groupMembersService.returnGroupMembers(groupAccountId);
  461. for (GroupMembers groupMembers : updatedGroupMembersList) {
  462. if (!person.getUsername().equals(groupMembers.getMemberUsername())) {
  463. Notification pasteNotification = new Notification(teamAndBoardNameDestination + "Note Eingefügt", "Note Eingefügt",
  464. groupSection.getMsectionid(), groupCanvas.getMcanvasid(),
  465. person.getId(), false, new Timestamp(System.currentTimeMillis()), "copy",
  466. savedNote.getMnotecolor(), true, groupAccount.getGroupId());
  467. pasteNotification.setSendNoteId(updatedNoteId[0]);
  468. pasteNotification.setObjects(toSendObjectList);
  469. pasteNotification.setSubject(teamAndBoardNameDestination);
  470. pasteNotification.setText(updatedNote.getMnotetag() + ", Note Eingefügt");
  471. this.chatService.sendNotification(pasteNotification, groupMembers.getMemberid());
  472.  
  473. }
  474. }
  475.  
  476.  
  477. } else {
  478. if (!copyFlag) {
  479. int originCopyId = this.groupNoteHistoryService.addNoteHistory(new GroupNoteHistory(new Timestamp(System.currentTimeMillis()),
  480. "copy", "Diese Note wurde dupliziert",
  481. person.getId()), groupNoteId);
  482. List<Object> objects = new ArrayList<>();
  483. objects.add(this.groupNoteHistoryService.getGroupNoteHistoryById(originCopyId));
  484. sendControlNotificationsForNote(objects, groupNoteId, originSection.getMsectionid(), originCanvas.getMcanvasid(), originAccount.getGroupId(), false);
  485. } else {
  486. int originCopyId = this.groupNoteHistoryService.addNoteHistory(new GroupNoteHistory(new Timestamp(System.currentTimeMillis()),
  487. "copy", "Diese Note wurde kopiert",
  488. person.getId()), groupNoteId);
  489. List<Object> objects = new ArrayList<>();
  490. objects.add(this.groupNoteHistoryService.getGroupNoteHistoryById(originCopyId));
  491. sendControlNotificationsForNote(objects, groupNoteId, originSection.getMsectionid(), originCanvas.getMcanvasid(), originAccount.getGroupId(), false);
  492. }
  493.  
  494.  
  495. int copyHistoryID = this.groupNoteHistoryService.addNoteHistory(new GroupNoteHistory(new Timestamp(System.currentTimeMillis()),
  496. "copy", "Kopiert von: " + originAccount.getGroupName() + ", " + originCanvas.getMcanvasname() + ", " + originSection.getMsectionname(),
  497. person.getId()), updatedNote.getMnoticesid());
  498.  
  499. GroupNoteHistory copyHistory = this.groupNoteHistoryService.getGroupNoteHistoryById(copyHistoryID);
  500. toSendObjectList.add(copyHistory);
  501. if (!sendNotification) {
  502. List<GroupMembers> groupMembersList = this.groupMembersService.returnGroupMembers(originAccount.getGroupId());
  503. for (GroupMembers groupMembers : groupMembersList) {
  504. if (!person.getUsername().equals(groupMembers.getMemberUsername())) {
  505. NotificationType notificationType = this.notificationTypeService.getNotificationTypeForMember(groupMembers.getMemberid());
  506. if (notificationType.isNoteCopy()) {
  507. Notification copyNotification = new Notification(teamAndBoardNameOrigin + "Note Kopiert", "Note kopiert",
  508. originSection.getMsectionid(), originCanvas.getMcanvasid(),
  509. person.getId(), false, new Timestamp(System.currentTimeMillis()), "copy",
  510. savedNote.getMnotecolor(), true, originAccount.getGroupId());
  511. copyNotification.setSendNoteId(updatedNoteId[0]);
  512. copyNotification.setObjects(toSendObjectList);
  513. copyNotification.setSubject(teamAndBoardNameOrigin);
  514. copyNotification.setText(teamAndBoardTextOrigin);
  515. this.chatService.sendNotification(copyNotification, groupMembers.getMemberid());
  516. }
  517. }
  518. }
  519. }
  520.  
  521.  
  522. int pasteId = this.groupNoteHistoryService.addNoteHistory(new GroupNoteHistory(new Timestamp(System.currentTimeMillis()),
  523. "paste", "Eingefügt in: " + groupAccount.getGroupName() + ", " + groupCanvas.getMcanvasname() + ", " + groupSection.getMsectionname(),
  524. person.getId()), updatedNote.getMnoticesid());
  525.  
  526. GroupNoteHistory pasteHistory = this.groupNoteHistoryService.getGroupNoteHistoryById(pasteId);
  527. toSendObjectList.add(pasteHistory);
  528. if (!sendNotification) {
  529. List<GroupMembers> updatedGroupMembersList = this.groupMembersService.returnGroupMembers(groupAccountId);
  530. for (GroupMembers groupMembers : updatedGroupMembersList) {
  531. if (!person.getUsername().equals(groupMembers.getMemberUsername())) {
  532. Notification pasteNotification = new Notification("Note Eingefügt: " + savedNote.getMnotetag(), "Note kopiert",
  533. originSection.getMsectionid(), originCanvas.getMcanvasid(),
  534. person.getId(), false, new Timestamp(System.currentTimeMillis()), "copy",
  535. savedNote.getMnotecolor(), true, originAccount.getGroupId());
  536. pasteNotification.setSendNoteId(updatedNoteId[0]);
  537. pasteNotification.setObjects(toSendObjectList);
  538. this.chatService.sendNotification(pasteNotification, groupMembers.getMemberid());
  539.  
  540. }
  541. }
  542. }
  543. }
  544.  
  545.  
  546. GroupSection updatedSection = this.groupSectionService.getGroupSectionById(updatedNote.getOwnedSectionId());
  547. GroupCanvas updatedCanvas = this.groupCanvasService.getCanvasById(updatedSection.getCurrentCanvasId());
  548. final GroupCanvas finalGroupCanvas1 = groupCanvas;
  549. if (sendNotification) {
  550. List<GroupMembers> newMemberList = this.groupMembersService.returnGroupMembers(groupAccountId);
  551. for (GroupMembers members : newMemberList) {
  552. if (members.getMemberUsername().equals(person.getUsername())) {
  553. sendControlNotificationsForNote(toSendObjectList, updatedNoteId[0], groupSection.getMsectionid(), finalGroupCanvas1.getMcanvasid(), destinationGroupAccount.getGroupId(), false);
  554. } else {
  555. NotificationType notificationType = this.notificationTypeService.getNotificationTypeForMember(members.getMemberid());
  556. if (notificationType.isAddNote()) {
  557. Notification notification = this.notificationService.createNotification(person.getId(), true, "/section/listing/" +
  558. updatedCanvas.getMcanvasid() + "?note="
  559. + updatedNote.getMnoticesid(),
  560. groupAccount.getGroupName() + ", " + updatedCanvas.getMcanvasname(), "", "note", updatedSection.getMsectionid(),
  561. updatedCanvas.getMcanvasid(), 0, updatedNote.getMnotecolor(), destinationGroupAccount.getGroupId());
  562. notification.setBroadCast(false);
  563. notification.setZugweisedPersonId(updatedNote.getZugwisenPersonId());
  564. notification.setNoteid(updatedNoteId[0]);
  565. notification.setSendNoteId(updatedNoteId[0]);
  566. notification.setObjects(toSendObjectList);
  567. if (duplicateFlag) {
  568. notification.setText("Note kopiert/ eingefügt: <span class='bold'>" + updatedNote.getMnotetag() + "</span> ");
  569. } else {
  570. notification.setText("Note ausgeschn./ eingefügt: <span class='bold'>" + updatedNote.getMnotetag() + "</span> ");
  571. }
  572. this.chatService.sendNotification(notification, members.getMemberid());
  573. this.notificationService.addNotification(notification, members.getMemberid());
  574. } else {
  575. sendControlNotificationsForNote(toSendObjectList, updatedNoteId[0], groupSection.getMsectionid(), finalGroupCanvas1.getMcanvasid(), destinationGroupAccount.getGroupId(), false);
  576. }
  577. }
  578.  
  579. }
  580. } else {
  581. sendControlNotificationsForNote(toSendObjectList, updatedNoteId[0], groupSection.getMsectionid(), finalGroupCanvas1.getMcanvasid(), destinationGroupAccount.getGroupId(), false);
  582. }
  583. GroupNotes processNote = this.groupNotesDAO.getGroupNoteById(updatedNoteId[0]);
  584. if (processNote != null) {
  585. processNote.setProcessing(false);
  586. processNote.setFinished(savedNote.isFinished());
  587. this.groupNotesDAO.editGroupNote(processNote, sectionId);
  588. List<GroupAttachments> groupAttachmentsList = this.groupAttachmentsService.getAttachmenByNoteId(updatedNoteId[0]);
  589. List<Object> objectList = new ArrayList<>();
  590. objectList.addAll(groupAttachmentsList);
  591. sendControlNotificationsForNote(objectList, updatedNoteId[0], groupSection.getMsectionid(), groupCanvas.getMcanvasid(), destinationGroupAccount.getGroupId(), false);
  592. }
  593. return updatedNoteId[0];
  594. }
  595.  
  596. return 0;
  597. }
  598.  
  599. @Override
  600. public boolean addAttachmentForCopy(GroupAttachments originalFile, GroupNotes groupNotes,
  601. boolean notify, GroupSection groupSection,
  602. GroupCanvas groupCanvas, GroupAccount groupAccount){
  603. try {
  604. if (!(originalFile.getSendAttachment() == null)) {
  605. Person person = this.personService.getCurrentlyAuthenticatedUser();
  606. Permission permission = this.permissionService.getPermissionForMember(groupAccount.getGroupId());
  607. boolean uploadAllowed = this.personService.isUploadAllowed(originalFile.getFileSize(), person.getUsername());
  608. Person attachmentUploader = this.personService.getPersonById(originalFile.getUploaderId());
  609. if (uploadAllowed) {
  610. if ((permission.isAddAttachment()) || (person.getId() == groupAccount.getUserId())) {
  611. String identifier = new BigInteger(130, random).toString(32);
  612. GroupAttachments attachment = new GroupAttachments(originalFile.getFileName(), new Timestamp(System.currentTimeMillis()),
  613. this.personService.returnLoggedInUsersEmail(), person.getId(), originalFile.getFileSize(), groupAccount.getGroupId(), identifier,
  614. msg + "groupattach/" + groupAccount.getGroupId() + "/", groupSection.getMsectionid(), groupCanvas.getMcanvasid(), groupNotes.getMnoticesid(), originalFile.getMimeType(), "");
  615. attachment.setApiUsed("media");
  616. if (attachmentUploader != null) {
  617. attachment.setUploaderId(attachmentUploader.getId());
  618. }
  619. attachment.setFullSizePath(identifier);
  620. if (originalFile.getFileUploadDate() != null) {
  621. attachment.setFileUploadDate(originalFile.getFileUploadDate());
  622. } else {
  623. attachment.setFileUploadDate(new Timestamp(System.currentTimeMillis()));
  624. }
  625. final int[] attachId = {0};
  626. attachId[0] = this.groupAttachmentsDAO.directAddAttachment(attachment, groupNotes);
  627.  
  628.  
  629. try {
  630. File file = new File(msg + "groupattach/" + groupAccount.getGroupId());
  631. boolean creationResult = (file.exists() && file.isDirectory()) || new File(msg + "groupattach/" + groupAccount.getGroupId()).mkdir();
  632. if (creationResult) {
  633. OutputStream outputStream = new FileOutputStream(new File(msg + "groupattach/" + groupAccount.getGroupId() + "/" + identifier));
  634. outputStream.write(originalFile.getSendAttachment());
  635. outputStream.close();
  636.  
  637. }
  638. } catch (Exception e) {
  639. e.printStackTrace();
  640.  
  641. }
  642.  
  643. String extension = originalFile.getFileName().substring(originalFile.getFileName().lastIndexOf(".") + 1, originalFile.getFileName().length()).toLowerCase();
  644.  
  645. try {
  646. GroupAttachments attachments = this.groupAttachmentsDAO.getAttachmenById(attachId[0]);
  647. if (extension.toLowerCase().equals("zip")) {
  648. Path path = Paths.get(msg + "groupattach/" + groupAccount.getGroupId() + "/" + identifier);
  649. List<String> fileNames = getListOfFileNamesForZipFile(path);
  650. String allNames = "";
  651. int counter = 0;
  652. for (String str : fileNames) {
  653. allNames += str + ":/";
  654. if (counter >= 50) {
  655. break;
  656. }
  657. counter++;
  658. }
  659. attachments.setFileNames(allNames);
  660. }
  661. if (extension.toLowerCase().equals("png") || (extension.equals("jpg")) || (extension.equals("jpeg"))) {
  662. File outFileForWidth = new File(msg + "groupattach/" + groupAccount.getGroupId() + "/" + identifier);
  663. BufferedImage bufferedImage = null;
  664. try {
  665. bufferedImage = ImageIO.read(outFileForWidth);
  666. } catch (IOException e) {
  667. e.printStackTrace();
  668.  
  669. }
  670. if (bufferedImage != null) {
  671. attachments.setWidth(bufferedImage.getWidth());
  672. attachments.setHeight(bufferedImage.getHeight());
  673. attachments.setNoteid(groupNotes.getMnoticesid());
  674. this.groupAttachmentsDAO.updateAttachment(attachments);
  675. }
  676. }
  677. } catch (Exception e) {
  678. e.printStackTrace();
  679.  
  680. }
  681.  
  682. try {
  683. GroupAttachments attachments = this.groupAttachmentsDAO.getAttachmenById(attachId[0]);
  684. if (attachments != null) {
  685. try {
  686. GroupAttachments originAttachment = this.groupAttachmentsDAO.getAttachmenById(originalFile.getGroupAttachId());
  687. if (originAttachment != null) {
  688. File originThumbnail = new File(msg + "thumbnail/" + originAttachment.getGroupId() + "/" + originAttachment.getFileIdentifier());
  689. if (originThumbnail.exists()) {
  690. if (originThumbnail.isFile()) {
  691. byte[] originThumbBytes = FileUtils.readFileToByteArray(originThumbnail);
  692. if (originThumbBytes != null) {
  693. File thumbnail = new File(msg + "thumbnail/" + groupAccount.getGroupId());
  694. boolean result = (thumbnail.exists() && thumbnail.isDirectory()) || new File(msg + "thumbnail/" + groupAccount.getGroupId()).mkdirs();
  695. if (result) {
  696. OutputStream outputStream = new FileOutputStream(new File(msg + "thumbnail/" + groupAccount.getGroupId() + "/" + identifier));
  697. outputStream.write(originThumbBytes);
  698. outputStream.close();
  699. attachments.setThumbNailAvailable(true);
  700. this.groupAttachmentsDAO.updateAttachment(attachments);
  701. addForNoteAndCanvasCopyForLucene(originalFile.getGroupAttachId(), attachId[0], false);
  702.  
  703. }
  704. }
  705. }
  706. }
  707. }
  708.  
  709. } catch (Exception e) {
  710. e.printStackTrace();
  711.  
  712.  
  713. }
  714. }
  715.  
  716.  
  717. } catch (Exception e) {
  718. e.printStackTrace();
  719.  
  720. }
  721.  
  722. return true;
  723. }
  724. }
  725. }
  726. } catch (Exception e) {
  727. e.printStackTrace();
  728.  
  729. }
  730.  
  731. return false;
  732. }
Add Comment
Please, Sign In to add comment