Skip to content
Snippets Groups Projects
Commit 4c817052 authored by srosse's avatar srosse
Browse files

FXOLAT-282: fix the configuration panel, load the list of customers if the url connection is ok

parent 137ebfaf
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import com.frentix.olat.vitero.manager.ViteroZombieSlayerJob;
......@@ -140,7 +141,7 @@ public class ViteroModule extends AbstractOLATModule implements ConfigOnOff {
private void initCronJob() {
try {
if(scheduler.getTrigger("Vitero_Cleaner_Cron_Job", Scheduler.DEFAULT_GROUP) == null) {
if(scheduler.getTrigger("Vitero_Cleaner_Cron_Trigger", Scheduler.DEFAULT_GROUP) == null) {
JobDetail jobDetail = new JobDetail("Vitero_Cleaner_Cron_Job", Scheduler.DEFAULT_GROUP, ViteroZombieSlayerJob.class);
CronTrigger trigger = new CronTrigger();
......
......@@ -199,6 +199,28 @@ public class ViteroManager extends BasicManager implements UserDataDeletable {
}
}
public List<ViteroCustomer> getCustomers(String url, String login, String password)
throws VmsNotAvailableException {
try {
CustomerServiceStub customerWs = new CustomerServiceStub(url + "/services");
SecurityHeader.addAdminSecurityHeader(login, password, customerWs);
CustomerServiceStub.GetCustomerListRequest listRequest = new CustomerServiceStub.GetCustomerListRequest();
listRequest.setGetCustomerListRequest(new EmptyOMElement());
CustomerServiceStub.GetCustomerListResponse response = customerWs.getCustomerList(listRequest);
CustomerServiceStub.Customertype[] customerTypes = response.getCustomer();
return convert(customerTypes);
} catch (AxisFault f) {
int code = handleAxisFault(f);
switch(code) {
default: logAxisError("Cannot get the list of customers.", f);
}
return Collections.emptyList();
} catch (RemoteException e) {
logError("Cannot get the list of customers.", e);
return Collections.emptyList();
}
}
/**
* Create a session code with a one hour expiration date
* @param identity
......
......@@ -85,8 +85,22 @@ public class ViteroConfigurationController extends FormBasicController {
enabledValues = new String[]{translate("enabled")};
loadCustomers(false);
initForm(ureq);
}
private void loadCustomers(boolean fromEditor) {
try {
List<ViteroCustomer> customers = viteroManager.getCustomers();
List<ViteroCustomer> customers;
if(fromEditor) {
String url = urlEl.getValue();
String login = loginEl.getValue();
String password = passwordEl.getValue();
customers = viteroManager.getCustomers(url, login, password);
} else {
customers = viteroManager.getCustomers();
}
customerKeys = new String[customers.size()];
customerValues = new String[customers.size()];
int i=0;
......@@ -98,8 +112,6 @@ public class ViteroConfigurationController extends FormBasicController {
customerKeys = new String[0];
customerValues = new String[0];
}
initForm(ureq);
}
@Override
......@@ -192,6 +204,30 @@ public class ViteroConfigurationController extends FormBasicController {
@Override
protected boolean validateFormLogic(UserRequest ureq) {
boolean allOk = validateURL();
customersEl.clearError();
if(customersEl.isOneSelected()) {
try {
String customerId = customersEl.getSelectedKey();
Integer.parseInt(customerId);
} catch(Exception e) {
customersEl.setErrorKey("error.customer.invalid", null);
allOk = false;
}
} else {
if(customersEl.getSize() == 0) {
loadCustomers(true);
customersEl.setKeysAndValues(customerKeys, customerValues, null);
}
customersEl.setErrorKey("form.legende.mandatory", null);
allOk = false;
}
return allOk && super.validateFormLogic(ureq);
}
private boolean validateURL() {
boolean allOk = true;
String url = urlEl.getValue();
......@@ -221,22 +257,8 @@ public class ViteroConfigurationController extends FormBasicController {
passwordEl.setErrorKey("form.legende.mandatory", null);
allOk = false;
}
customersEl.clearError();
if(customersEl.isOneSelected()) {
try {
String customerId = customersEl.getSelectedKey();
Integer.parseInt(customerId);
} catch(Exception e) {
customersEl.setErrorKey("error.customer.invalid", null);
allOk = false;
}
} else {
customersEl.setErrorKey("form.legende.mandatory", null);
allOk = false;
}
return allOk && super.validateFormLogic(ureq);
return allOk;
}
@Override
......@@ -245,14 +267,18 @@ public class ViteroConfigurationController extends FormBasicController {
boolean enabled = viteroEnabled.isSelected(0);
viteroModule.setEnabled(enabled);
} else if(source == checkLink) {
if(validateFormLogic(ureq)) {
checkConnection(ureq);
if(validateURL()) {
boolean ok = checkConnection(ureq);
if(ok && customersEl.getSize() == 0) {
loadCustomers(true);
customersEl.setKeysAndValues(customerKeys, customerValues, null);
}
}
}
super.formInnerEvent(ureq, source, event);
}
protected void checkConnection(UserRequest ureq) {
protected boolean checkConnection(UserRequest ureq) {
String url = urlEl.getValue();
String login = loginEl.getValue();
String password = passwordEl.getValue();
......@@ -265,10 +291,13 @@ public class ViteroConfigurationController extends FormBasicController {
} else {
showError("check.nok");
}
return ok;
} catch (NumberFormatException e) {
showError("error.customer.invalid");
return false;
} catch (VmsNotAvailableException e) {
showError(VmsNotAvailableException.I18N_KEY);
return false;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment