private void handleRemove() { if (!PortalUtils.exists(getSelectedAttachments())) { error(getLocalizer().getString("msgAttachment.nothing.selected.remove", this)); return; } try { Iterator<Long> iterator = message.getAttachments().iterator(); while (iterator.hasNext()) { Long attId = iterator.next(); for (MessageAttachment removeId : getSelectedAttachments()) { if (attId.equals(removeId.getId())) { iterator.remove(); } } } if (updateMessage()) { info(getLocalizer().getString("remove.attachment.success", this)); getAttachments(); } } catch (Exception e) { error(getLocalizer().getString("remove.attachment.error", this)); LOG.error("Error in removing attachment", e); } };
private List<KeyValue<Long, String>> getAttachments() { attachmentsList = new ArrayList<KeyValue<Long, String>>(); if (!isCreateMode) { try { FindAttachmentsRequest request = basePage.getNewMobiliserRequest(FindAttachmentsRequest.class); AttachmentSearchCriteria criteria = new AttachmentSearchCriteria(); criteria.getTemplateExclusion().add(message.getId()); request.setCriteria(criteria); FindAttachmentsResponse response = basePage.wsTemplateClient.findAttachments(request); if (basePage.evaluateMobiliserResponse(response)) { List<MessageAttachment> attachments = response.getAttachments(); for (MessageAttachment att : attachments) { attachmentsList.add(new KeyValue<Long, String>(att.getId(), att.getName())); } } } catch (Exception e) { error(getLocalizer().getString("load.attachment.error", this)); LOG.error("Error in getAttachments", e); } } return attachmentsList; }