Warning – lots of code here…
I am trying to migrate the following code to v7. The code uses our business rules (in a service) to identify customers who are bad debt risks and display them to the user. The user can then Accept or Reject the order.
public class BadDebtDatasource extends CustomCollectionDatasource<BadDebt, Long> {
private final BadDebtorService badDebtorService = AppBeans.get(BadDebtorService.NAME);
@Override
protected Collection<BadDebt> getEntities(Map params) {
String lname = (String) params.get("lname");
String postalCode = (String) params.get("postalCode");
if (lname.isEmpty() || postalCode.isEmpty()) {
return new HashSet<>();
}
else {
return badDebtorService.check_bad_debt(lname, postalCode);
}
}
}
What is the v7 equivalent of a CustomCollectionDatasource?
I use it like this - which also needs to be translated to v7. An AbstractWindow becomes a Screen? How do parameters get passed, as I need to pass some to the service? How do I pass the resulting pressed button back to the calling code?
public class Baddebtlist extends AbstractWindow {
@Inject
private BadDebtDatasource badDebtDs;
@Override
public void init(Map<String,Object> params)
{
super.init(params);
getDialogOptions().setModal(true);
WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
badDebtDs.refresh(params);
}
public void onAccept(Component source) {
close("onAccept");
}
public void onReject(Component source) {
close("onReject");
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd" caption="Possible Bad Debt "
class="com.paslists.rade.web.badDebtList.Baddebtlist" focusComponent="btnAccept"
messagesPack="com.paslists.rade.web.badDebtList">
<dsContext>
<collectionDatasource id="badDebtDs" allowCommit="false" class="com.paslists.rade.entity.BadDebt"
datasourceClass="com.paslists.rade.gui.BadDebtDatasource" refreshMode="NEVER"/>
</dsContext>
<dialogMode forceDialog="true" height="600" resizable="true" width="850"/>
<layout>
<vbox id="vboxBadDebt" expand="tblBadDebt" height="500px" spacing="true">
<buttonsPanel id="tblBadDebtButtonsPanel">
<button id="btnAccept" invoke="onAccept" caption="Accept Buyer"/>
<button id="btnReject" invoke="onReject" caption="Reject Buyer"/>
</buttonsPanel>
<table id="tblBadDebt" showSelection="false" width="850px">
<columns>
<column id="lname" caption="Last" width="100"/>
<column id="fname" caption="First" width="100"/>
<column id="address1" caption="Address 1" width="150"/>
<column id="address2" caption="Address 2" width="150"/>
<column id="city" caption="City" width="100"/>
<column id="province" caption="State/Province" width="80"/>
<column id="postalCode" caption="Postal Code" width="150"/>
<column id="countryCode" caption="Country Code" width="50"/>
</columns>
<rows datasource="badDebtDs"/>
</table>
</vbox>
</layout>
</window>
This all gets used like this:
- see if proposed customer is a bad debt:
private boolean check_bad_debt(Mailfile selected) {
badDebtDs.refresh(ParamsMap.of("lname", selected.getLname(), "postalCode", selected.getZip()));
return badDebtDs.getItemIds().size() > 0;
}
- If it is, display the bad debt screen and get the result:
private void check_bad_debt_and_create_updtrans(Updtrans updtrans, Mailfile selected) {
if (check_bad_debt(selected)) {
openWindow("rade$badDebtList",
WindowManager.OpenType.DIALOG,
ParamsMap.of("lname", selected.getLname(), "postalCode", selected.getZip())
).addCloseListener(actionId -> {
if (actionId.equals("onAccept")) {
createUpdtrans(updtrans, selected);
}
return;
});
} else {
createUpdtrans(updtrans, selected);
}
}