@Test public void testUpdateAttachmentProperty_fail() { handler.addRequest("PUT", "/qcbin/rest/domains/domain/projects/project/defects/1/attachments/logfile.txt", 500) .responseBody("Failed"); Entity attachment = attachmentService.updateAttachmentProperty("logfile.txt", new EntityRef("defect", 1), "description", "newValue", false); Assert.assertNull(attachment); checkError("Failed"); }
public Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent) { Entity attachment = new Entity("attachment", 0); attachment.setProperty(propertyName, propertyValue); String xml = XMLOutputterFactory.getXMLOutputter().outputString(new Document(attachment.toElement(Collections.singleton(propertyName)))); MyResultInfo result = new MyResultInfo(); if(restService.put(xml, result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return null; } EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { Entity entity = list.get(0); entityService.fireEntityLoaded(entity, EntityListener.Event.GET); return entity; } else { return null; } }
AttachmentService { public Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent) { Entity attachment = new Entity("attachment", 0); attachment.setProperty(propertyName, propertyValue); String xml = XMLOutputterFactory.getXMLOutputter().outputString(new Document(attachment.toElement(Collections.singleton(propertyName)))); MyResultInfo result = new MyResultInfo(); if(restService.put(xml, result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return null; } EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { Entity entity = list.get(0); entityService.fireEntityLoaded(entity, EntityListener.Event.GET); return entity; } else { return null; } } }
AttachmentService { public Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent) { Entity attachment = new Entity("attachment", 0); attachment.setProperty(propertyName, propertyValue); String xml = XMLOutputterFactory.getXMLOutputter().outputString(new Document(attachment.toElement(Collections.singleton(propertyName)))); MyResultInfo result = new MyResultInfo(); if(restService.put(xml, result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return null; } EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { Entity entity = list.get(0); entityService.fireEntityLoaded(entity, EntityListener.Event.GET); return entity; } else { return null; } } AttachmentService(RestService restService, EntityService entityService, ErrorService errorService); }
AttachmentService { public Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent) { Entity attachment = new Entity("attachment", 0); attachment.setProperty(propertyName, propertyValue); String xml = XMLOutputterFactory.getXMLOutputter().outputString(new Document(attachment.toElement(Collections.singleton(propertyName)))); MyResultInfo result = new MyResultInfo(); if(restService.put(xml, result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return null; } EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { Entity entity = list.get(0); entityService.fireEntityLoaded(entity, EntityListener.Event.GET); return entity; } else { return null; } } AttachmentService(RestService restService, EntityService entityService, ErrorService errorService); Entity getAttachmentEntity(Entity entity); Entity getAttachmentEntity(String name, EntityRef parent); String createAttachment(String filename, IndicatingInputStream is, long length, EntityRef parent); boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent); Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent); void deleteAttachment(String name, EntityRef parent); }
AttachmentService { public Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent) { Entity attachment = new Entity("attachment", 0); attachment.setProperty(propertyName, propertyValue); String xml = XMLOutputterFactory.getXMLOutputter().outputString(new Document(attachment.toElement(Collections.singleton(propertyName)))); MyResultInfo result = new MyResultInfo(); if(restService.put(xml, result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return null; } EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { Entity entity = list.get(0); entityService.fireEntityLoaded(entity, EntityListener.Event.GET); return entity; } else { return null; } } AttachmentService(RestService restService, EntityService entityService, ErrorService errorService); Entity getAttachmentEntity(Entity entity); Entity getAttachmentEntity(String name, EntityRef parent); String createAttachment(String filename, IndicatingInputStream is, long length, EntityRef parent); boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent); Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent); void deleteAttachment(String name, EntityRef parent);  }