@Test public void testAttachmentFileSize() { dummyAttachment.setAttachmentFileSize((long) 12345); assertTrue( "Testing AttachmentFileSize of Attachment in AttachmentTest", 12345 == dummyAttachment.getAttachmentFileSize()); }
@Test public void testNoteIdentifier() { dummyAttachment.setNoteIdentifier((long) 12345); assertTrue( "Testing NoteIdentifier of Attachment in AttachmentTest", 12345 == dummyAttachment.getNoteIdentifier()); }
/** * Determines whether there are any unsaved attachment collection changes. * * @return True if attachment adds or deletes haven't been processed yet. * @throws ServiceLocalException */ public boolean hasUnprocessedChanges() throws ServiceLocalException { // Any new attachments? for (Attachment attachment : this) { if (attachment.isNew()) { return true; } } // Any pending deletions? for (Attachment attachment : this.getRemovedItems()) { if (!attachment.isNew()) { return true; } } Collection<ItemAttachment> itemAttachments = new ArrayList<ItemAttachment>(); for (Object event : this.getItems()) { if (event instanceof ItemAttachment) { itemAttachments.add((ItemAttachment) event); } } // Recurse: process item attachments to check // for new or deleted sub-attachments. for (ItemAttachment itemAttachment : itemAttachments) { if (itemAttachment.getItem() != null) { if (itemAttachment.getItem().getAttachments().hasUnprocessedChanges()) { return true; } } } return false; }
public long getAttachmentsSize() { long size = 0; for (Attachment attachment : attachments) { size += attachment.getSize(); } return size; }
public void setAttachments(final List<Attachment> attachments) { // fix bidirectional relationship for (final Attachment attachment : attachments) { attachment.setPost(this); } this.attachments = attachments; }
private static void appendAttachment(Multipart multipart, Attachment attachment) throws MessagingException { BodyPart fileBodyPart = new MimeBodyPart(); fileBodyPart.setDataHandler(new DataHandler(attachment.getDataSource())); fileBodyPart.setFileName(attachment.getFileName()); multipart.addBodyPart(fileBodyPart); }
public void testattachFileSheet() throws SmartsheetException, IOException { // attach file to sheet Attachment attachment = smartsheet.sheetResources().attachmentResources().attachFile(sheetId, file, "text/plain"); testGetAttachmentSheet(attachment.getId()); }
// smartsheet.sheetResources().commentResources().attachmentResources().attachFile(sheetId, // commentId, file,"text/plain"); public void testattachFileComment() throws SmartsheetException, IOException { // create comment to add to discussion Comment comment = new Comment.AddCommentBuilder().setText("This is a test comment").build(); Discussion discussion = new Discussion.CreateDiscussionBuilder() .setTitle("New Discussion") .setComment(comment) .build(); discussion = smartsheet.sheetResources().discussionResources().createDiscussion(sheetId, discussion); // comment = // smartsheet.sheetResources().discussionResources().comments().addComment(sheetId,discussion.getId(), comment); comment = discussion.getComments().get(0); commentId = comment.getId(); discussionId = discussion.getId(); File file1 = new File("src/integration-test/resources/small-text.txt"); // attach file to comment Attachment attachment = smartsheet .sheetResources() .commentResources() .attachmentResources() .attachFile(sheetId, commentId, file1, "text/plain"); testGetAttachmentComment(attachment.getId()); }
public static AttachmentBuilder attachment(Attachment attach) { AttachmentBuilder builder = new AttachmentBuilder(); builder.fileName = attach.getFileName(); builder.contentType = attach.getContentType(); builder.thumbnail = attach.getThumbnail(); builder.fileSize = attach.getFileSize(); return builder; }
@Test public void testAttachmentIdentifier() { dummyAttachment.setAttachmentIdentifier("Att_ID"); assertEquals( "Testing Attachment in AttachmentTest", "Att_ID", dummyAttachment.getAttachmentIdentifier()); }
@Test public void testAttachmentTypeCode() { dummyAttachment.setAttachmentTypeCode("ATT_TYP_CD"); assertEquals( "Testing AttachmentmimeTypeCode of Attachment in AttachmentTest", "ATT_TYP_CD", dummyAttachment.getAttachmentTypeCode()); }
@Test public void testAttachmentFileName() { dummyAttachment.setAttachmentFileName("FILE_NM"); assertEquals( "Testing AttchmentFileName of Attachment in AttachmentTest", "FILE_NM", dummyAttachment.getAttachmentFileName()); }
@Test public void testAttachmentMimeTypeCode() { dummyAttachment.setAttachmentMimeTypeCode("MIME_TYP"); assertEquals( "Testing AttachmentmimeTypeCode of Attachment in AttachmentTest", "MIME_TYP", dummyAttachment.getAttachmentMimeTypeCode()); }
@JsonIgnore public ManyMap<String, Attachment> getAttachmentMap() { ManyMap<String, Attachment> map = new ManyMap<String, Attachment>(); if (attachments != null && !attachments.isEmpty()) { for (Attachment attachment : attachments) { map.putOne(attachment.getName(), attachment); } } return map; }
@Test public void testNote() { Note dummyNote = new Note(); dummyNote.setNoteText("Hello"); dummyAttachment.setNote(dummyNote); assertEquals( "Testing Note of Attachment in AttachmentTest", "Hello", dummyAttachment.getNote().getNoteText()); }
public void testAttachNewVersion() throws IOException, SmartsheetException { Attachment attachment = smartsheet .sheetResources() .attachmentResources() .versioningResources() .attachNewVersion(sheetId, sheetAttachmentId, file, "text/plain"); assertNotNull(attachment); attachmentWithVersionId = attachment.getId(); }
/** * Saves this collection by creating new attachment and deleting removed ones. * * @throws Exception the exception */ public void save() throws Exception { ArrayList<Attachment> attachments = new ArrayList<Attachment>(); for (Attachment attachment : this.getRemovedItems()) { if (!attachment.isNew()) { attachments.add(attachment); } } // If any, delete them by calling the DeleteAttachment web method. if (attachments.size() > 0) { this.internalDeleteAttachments(attachments); } attachments.clear(); // Retrieve a list of attachments that have to be created. for (Attachment attachment : this) { if (attachment.isNew()) { attachments.add(attachment); } } // If there are any, create them by calling the CreateAttachment web // method. if (attachments.size() > 0) { if (this.owner.isAttachment()) { this.internalCreateAttachments(this.owner.getParentAttachment().getId(), attachments); } else { this.internalCreateAttachments(this.owner.getId().getUniqueId(), attachments); } } // Process all of the item attachments in this collection. for (Attachment attachment : this) { ItemAttachment itemAttachment = (ItemAttachment) ((attachment instanceof ItemAttachment) ? attachment : null); if (itemAttachment != null) { // Bug E14:80864: Make sure item was created/loaded before // trying to create/delete sub-attachments if (itemAttachment.getItem() != null) { // Create/delete any sub-attachments itemAttachment.getItem().getAttachments().save(); // Clear the item's change log itemAttachment.getItem().clearChangeLog(); } } } super.clearChangeLog(); }
public void testattachFileRow() throws SmartsheetException, IOException { // add rows Row row = addRows(sheetId); rowId = row.getId(); // attach file to row Attachment attachment = smartsheet .sheetResources() .rowResources() .attachmentResources() .attachFile(sheetId, rowId, file, "text/plain"); testGetAttachmentRow(attachment.getId()); }
public SuperKrzakiPattern(String dataline) { super(); String[] lineElements = dataline.split("\\t"); this.id = lineElements[0]; this.text = lineElements[1]; this.verbPP = lineElements[2]; this.substPP = lineElements[3]; this.ann1 = Attachment.makeAttachment(lineElements[4]); this.ann2 = Attachment.makeAttachment(lineElements[5]); // attachment defined if (lineElements.length > 6) { this.attachment = Attachment.makeAttachment(lineElements[6]); } }
public SequencingAnalysis copy() { SequencingAnalysis dst = new SequencingAnalysis(); dst.subject = subject == null ? null : subject.copy(); dst.date = date == null ? null : date.copy(); dst.name = name == null ? null : name.copy(); dst.genome = genome == null ? null : genome.copy(dst); dst.file = new ArrayList<Attachment>(); for (Attachment i : file) dst.file.add(i.copy()); dst.inputLab = new ArrayList<ResourceReference>(); for (ResourceReference i : inputLab) dst.inputLab.add(i.copy()); dst.inputAnalysis = new ArrayList<ResourceReference>(); for (ResourceReference i : inputAnalysis) dst.inputAnalysis.add(i.copy()); return dst; }
public RelatedPerson copy() { RelatedPerson dst = new RelatedPerson(); dst.identifier = new ArrayList<Identifier>(); for (Identifier i : identifier) dst.identifier.add(i.copy()); dst.patient = patient == null ? null : patient.copy(); dst.relationship = relationship == null ? null : relationship.copy(); dst.name = name == null ? null : name.copy(); dst.telecom = new ArrayList<Contact>(); for (Contact i : telecom) dst.telecom.add(i.copy()); dst.gender = gender == null ? null : gender.copy(); dst.address = address == null ? null : address.copy(); dst.photo = new ArrayList<Attachment>(); for (Attachment i : photo) dst.photo.add(i.copy()); return dst; }
@Override public Transaction newTransaction( short deadline, byte[] senderPublicKey, Long recipientId, long amountNQT, long feeNQT, String referencedTransactionFullHash, Attachment attachment) throws NxtException.ValidationException { TransactionImpl transaction = new TransactionImpl( attachment.getTransactionType(), Convert.getEpochTime(), deadline, senderPublicKey, recipientId, amountNQT, feeNQT, referencedTransactionFullHash, null); transaction.setAttachment(attachment); transaction.validateAttachment(); return transaction; }
@Override public Object nullSafeGet( ResultSet resultSet, String[] names, SessionImplementor sessionImplementor, Object o) throws HibernateException, SQLException { Attachment attachment = null; String contentType = resultSet.getString(names[0]); String name = resultSet.getString(names[1]); byte[] content = resultSet.getBytes(names[2]); if (contentType != null && name != null && content != null) { attachment = new Attachment(); attachment.setContentType(contentType); attachment.setName(name); attachment.setContent(content); } return attachment; }
public static WallMessage parse(JSONObject o) throws JSONException { WallMessage wm = new WallMessage(); wm.id = o.getLong("id"); wm.from_id = o.getLong("from_id"); wm.to_id = o.getLong("to_id"); wm.date = o.getLong("date"); wm.online = o.optString("online"); wm.text = Api.unescape(o.getString("text")); if (o.has("likes")) { JSONObject jlikes = o.getJSONObject(NewsJTags.LIKES); wm.like_count = jlikes.getInt("count"); wm.user_like = jlikes.getInt("user_likes") == 1; wm.can_like = jlikes.getInt("can_like") == 1; wm.like_can_publish = jlikes.getInt("can_publish") == 1; } wm.copy_owner_id = o.optLong("copy_owner_id"); JSONArray attachments = o.optJSONArray("attachments"); JSONObject geo_json = o.optJSONObject("geo"); // владельцем опроса является to_id. Даже если добавить опрос в группу от своего имени, то // from_id буду я, но опрос всё-равно будет принадлежать группе. wm.attachments = Attachment.parseAttachments(attachments, wm.to_id, wm.copy_owner_id, geo_json); if (o.has("comments")) { JSONObject jcomments = o.getJSONObject("comments"); wm.comment_count = jcomments.getInt("count"); wm.comment_can_post = jcomments.getInt("can_post") == 1; } return wm; }
/** * * Writes elements and content to XML. * * @param writer the writer * @throws Exception the exception */ @Override protected void writeElementsToXml(EwsServiceXmlWriter writer) throws Exception { super.writeElementsToXml(writer); // ExchangeVersion ev=writer.getService().getRequestedServerVersion(); if (writer.getService().getRequestedServerVersion().ordinal() > ExchangeVersion.Exchange2007_SP1.ordinal()) { writer.writeElementValue( XmlNamespace.Types, XmlElementNames.IsContactPhoto, this.isContactPhoto); } writer.writeStartElement(XmlNamespace.Types, XmlElementNames.Content); if (!(this.fileName == null || this.fileName.isEmpty())) { File fileStream = new File(this.fileName); FileInputStream fis = null; try { fis = new FileInputStream(fileStream); writer.writeBase64ElementValue(fis); } finally { if (fis != null) { fis.close(); } } } else if (this.contentStream != null) { writer.writeBase64ElementValue(this.contentStream); } else if (this.content != null) { writer.writeBase64ElementValue(this.content); } else { EwsUtilities.EwsAssert( false, "FileAttachment.WriteElementsToXml", "The attachment's content is not set."); } writer.writeEndElement(); }
/** * Removes the Attachment specified by the attachmentId. * * @param attachmentId id of attachment to remove * @return removed Attachment or null if one was not found with the id */ public Attachment removeAttachment(final long attachmentId) { Attachment removedAttachment = null; if (attachments != null) { for (int index = attachments.size() - 1; index >= 0; --index) { Attachment currentAttachment = attachments.get(index); if (currentAttachment.getId() == attachmentId) { removedAttachment = attachments.remove(index); break; } } } return removedAttachment; }
/** Action handler method to remove attachments */ public void removeAttachment() { try { FacesContext context = FacesContext.getCurrentInstance(); String documentKey = (String) context.getExternalContext().getRequestParameterMap().get("documentKey"); for (Attachment attachment1 : attachments) { if (attachment1.getDocumentKey().equals(documentKey)) { attachments.remove(attachment1); break; } } } catch (Exception exception) { ExceptionHandler.handleException(exception); } }
/** * Can we handle a full stream.publish example? * * <p>See http://wiki.developers.facebook.com/index.php/Attachment_(Streams). */ @Test public void streamPublish() throws JSONException { ActionLink category = new ActionLink(); category.href = "http://bit.ly/KYbaN"; category.text = "humor"; Properties properties = new Properties(); properties.category = category; properties.ratings = "5 stars"; Medium medium = new Medium(); medium.href = "http://bit.ly/187gO1"; medium.src = "http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg"; medium.type = "image"; List<Medium> media = new ArrayList<Medium>(); media.add(medium); Attachment attachment = new Attachment(); attachment.name = "i'm bursting with joy"; attachment.href = "http://bit.ly/187gO1"; attachment.caption = "{*actor*} rated the lolcat 5 stars"; attachment.description = "a funny looking cat"; attachment.properties = properties; attachment.media = media; String json = createJsonMapper().toJson(attachment); String expectedJson = "{\"description\":\"a funny looking cat\",\"name\":\"i'm bursting with joy\",\"caption\":\"{*actor*} rated the lolcat 5 stars\",\"properties\":{\"category\":{\"text\":\"humor\",\"href\":\"http://bit.ly/KYbaN\"},\"ratings\":\"5 stars\"},\"media\":[{\"src\":\"http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg\",\"type\":\"image\",\"href\":\"http://bit.ly/187gO1\"}],\"href\":\"http://bit.ly/187gO1\"}"; JSONAssert.assertEquals(expectedJson, json, JSONCompareMode.NON_EXTENSIBLE); }
@Override public void nullSafeSet( PreparedStatement preparedStatement, Object value, int index, SessionImplementor sessionImplementor) throws HibernateException, SQLException { if (value != null) { Attachment attachment = (Attachment) value; preparedStatement.setString(index, attachment.getContentType()); preparedStatement.setString(index + 1, attachment.getName()); preparedStatement.setBytes(index + 2, attachment.getContent()); } else { preparedStatement.setObject(index, null); preparedStatement.setObject(index + 1, null); preparedStatement.setObject(index + 2, null); } }
// FIXME: Should also use events! public void deleteAttachment(Attachment att) throws ProviderException { if (m_provider == null) return; m_provider.deleteAttachment(att); m_engine.getSearchManager().pageRemoved(att); m_engine.getReferenceManager().clearPageEntries(att.getName()); }