@Test public void loadSkipsAttachmentsNotSelected() throws ComponentLookupException { when(this.doc.getXObjects(AdditionalDocumentsController.CLASS_REFERENCE)).thenReturn( Collections.singletonList(this.file2)); PatientData<Attachment> result = this.mocker.getComponentUnderTest().load(this.patient); Assert.assertNotNull(result); Assert.assertEquals(1, result.size()); Assert.assertEquals(this.attachment2, result.get(0)); }
@Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); List<BaseObject> data = doc.getXObjects(CLASS_REFERENCE); if (CollectionUtils.isEmpty(data)) { return null; } List<Attachment> result = new ArrayList<>(data.size()); for (BaseObject xobject : data) { if (xobject == null) { continue; } String filename = xobject.getStringValue(FILE_FIELD_NAME); XWikiAttachment xattachment = doc.getAttachment(filename); if (xattachment != null) { Attachment attachment = this.adapter.fromXWikiAttachment(xattachment); attachment.addAttribute(COMMENTS_FIELD_NAME, xobject.getLargeStringValue(COMMENTS_FIELD_NAME)); result.add(attachment); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
AdditionalDocumentsController implements PatientDataController<Attachment> { @Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); List<BaseObject> data = doc.getXObjects(CLASS_REFERENCE); if (CollectionUtils.isEmpty(data)) { return null; } List<Attachment> result = new ArrayList<>(data.size()); for (BaseObject xobject : data) { if (xobject == null) { continue; } String filename = xobject.getStringValue(FILE_FIELD_NAME); XWikiAttachment xattachment = doc.getAttachment(filename); if (xattachment != null) { Attachment attachment = this.adapter.fromXWikiAttachment(xattachment); attachment.addAttribute(COMMENTS_FIELD_NAME, xobject.getLargeStringValue(COMMENTS_FIELD_NAME)); result.add(attachment); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; } }
AdditionalDocumentsController implements PatientDataController<Attachment> { @Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); List<BaseObject> data = doc.getXObjects(CLASS_REFERENCE); if (CollectionUtils.isEmpty(data)) { return null; } List<Attachment> result = new ArrayList<>(data.size()); for (BaseObject xobject : data) { if (xobject == null) { continue; } String filename = xobject.getStringValue(FILE_FIELD_NAME); XWikiAttachment xattachment = doc.getAttachment(filename); if (xattachment != null) { Attachment attachment = this.adapter.fromXWikiAttachment(xattachment); attachment.addAttribute(COMMENTS_FIELD_NAME, xobject.getLargeStringValue(COMMENTS_FIELD_NAME)); result.add(attachment); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  }
AdditionalDocumentsController implements PatientDataController<Attachment> { @Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); List<BaseObject> data = doc.getXObjects(CLASS_REFERENCE); if (CollectionUtils.isEmpty(data)) { return null; } List<Attachment> result = new ArrayList<>(data.size()); for (BaseObject xobject : data) { if (xobject == null) { continue; } String filename = xobject.getStringValue(FILE_FIELD_NAME); XWikiAttachment xattachment = doc.getAttachment(filename); if (xattachment != null) { Attachment attachment = this.adapter.fromXWikiAttachment(xattachment); attachment.addAttribute(COMMENTS_FIELD_NAME, xobject.getLargeStringValue(COMMENTS_FIELD_NAME)); result.add(attachment); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  @Override PatientData<Attachment> load(Patient patient); @Override void save(@Nonnull final Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override void writeJSON(Patient patient, JSONObject json); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<Attachment> readJSON(JSONObject json); @Override String getName(); }
AdditionalDocumentsController implements PatientDataController<Attachment> { @Override public PatientData<Attachment> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); List<BaseObject> data = doc.getXObjects(CLASS_REFERENCE); if (CollectionUtils.isEmpty(data)) { return null; } List<Attachment> result = new ArrayList<>(data.size()); for (BaseObject xobject : data) { if (xobject == null) { continue; } String filename = xobject.getStringValue(FILE_FIELD_NAME); XWikiAttachment xattachment = doc.getAttachment(filename); if (xattachment != null) { Attachment attachment = this.adapter.fromXWikiAttachment(xattachment); attachment.addAttribute(COMMENTS_FIELD_NAME, xobject.getLargeStringValue(COMMENTS_FIELD_NAME)); result.add(attachment); } } return new IndexedPatientData<>(getName(), result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  @Override PatientData<Attachment> load(Patient patient); @Override void save(@Nonnull final Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override void writeJSON(Patient patient, JSONObject json); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<Attachment> readJSON(JSONObject json); @Override String getName(); static final EntityReference CLASS_REFERENCE; }