use of com.vaadin.v7.data.Buffered.SourceException in project SORMAS-Project by hzi-braunschweig.
the class CommitDiscardWrapperComponent method doCommit.
private void doCommit() throws InvalidValueException, SourceException, CommitRuntimeException {
if (fieldGroups != null) {
if (fieldGroups.size() > 1) {
List<InvalidValueException> invalidValueExceptions = fieldGroups.stream().filter(fieldGroup -> !fieldGroup.isValid()).map(fieldGroup -> {
try {
// all invalid fieldGroups are committed to fetch the CommitExceptions
fieldGroup.commit();
} catch (CommitException e) {
return e;
}
// when the fieldGroup did not throw a CommitException, it is invalid and committed
throw new IllegalStateException();
}).map(e -> {
// keep invalid value exceptions, throw the rest
Throwable c = e.getCause();
if (c instanceof InvalidValueException) {
return (InvalidValueException) c;
} else if (c instanceof SourceException) {
throw (SourceException) c;
} else {
throw new CommitRuntimeException(e);
}
}).collect(Collectors.toList());
if (invalidValueExceptions.isEmpty()) {
// NOOP
} else if (invalidValueExceptions.size() == 1) {
throw invalidValueExceptions.get(0);
} else {
throw new InvalidValueException(null, invalidValueExceptions.stream().map(InvalidValueException::getCauses).flatMap(Arrays::stream).toArray(InvalidValueException[]::new));
}
}
try {
for (FieldGroup fieldGroup : fieldGroups) {
fieldGroup.commit();
}
} catch (CommitException e) {
Throwable c = e.getCause();
if (c instanceof InvalidValueException) {
throw (InvalidValueException) c;
} else if (c instanceof SourceException) {
throw (SourceException) c;
} else {
throw new CommitRuntimeException(e);
}
}
} else if (wrappedComponent instanceof Buffered) {
((Buffered) wrappedComponent).commit();
} else {
// NOOP
}
dirty = false;
onCommit();
commited = true;
onDone();
}
use of com.vaadin.v7.data.Buffered.SourceException in project SORMAS-Project by hzi-braunschweig.
the class SampleController method addReferOrLinkToOtherLabButton.
/**
* Initialize 'Refer to another laboratory' button or link to referred sample
*
* @param editForm
* the edit form to attach the 'Refer to another laboratory' button to.
* @param disease
* required for field visibility checks in the sample create form opened when a sample reference shall be created.
* @param createReferral
* instructions for what shall happen when the user chooses to create a referral
* @param openReferredSample
* instructions for what shall happen when the user chooses to open the referred sample
*/
public void addReferOrLinkToOtherLabButton(CommitDiscardWrapperComponent<SampleEditForm> editForm, Disease disease, Consumer<Disease> createReferral, Consumer<SampleDto> openReferredSample) {
Button referOrLinkToOtherLabButton = null;
SampleDto sample = editForm.getWrappedComponent().getValue();
if (sample.getReferredTo() == null) {
if (sample.getSamplePurpose() == SamplePurpose.EXTERNAL && UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_TRANSFER)) {
referOrLinkToOtherLabButton = ButtonHelper.createButton("referOrLinkToOtherLab", I18nProperties.getCaption(Captions.sampleRefer), new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
try {
createReferral.accept(disease);
} catch (SourceException | InvalidValueException e) {
Notification.show(I18nProperties.getString(Strings.messageSampleErrors), Type.ERROR_MESSAGE);
}
}
}, ValoTheme.BUTTON_LINK);
}
} else {
SampleDto referredDto = FacadeProvider.getSampleFacade().getSampleByUuid(sample.getReferredTo().getUuid());
FacilityReferenceDto referredDtoLab = referredDto.getLab();
String referOrLinkToOtherLabButtonCaption = referredDtoLab == null ? I18nProperties.getCaption(Captions.sampleReferredToInternal) + " (" + DateFormatHelper.formatLocalDateTime(referredDto.getSampleDateTime()) + ")" : I18nProperties.getCaption(Captions.sampleReferredTo) + " " + referredDtoLab.toString();
referOrLinkToOtherLabButton = ButtonHelper.createButton("referOrLinkToOtherLab", referOrLinkToOtherLabButtonCaption, new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
openReferredSample.accept(referredDto);
}
});
}
if (referOrLinkToOtherLabButton != null) {
editForm.getButtonsPanel().addComponentAsFirst(referOrLinkToOtherLabButton);
editForm.getButtonsPanel().setComponentAlignment(referOrLinkToOtherLabButton, Alignment.BOTTOM_LEFT);
}
}
Aggregations