Red Hat Application Migration Toolkit
package com.mpdmal.cloudental.beans;
import com.mpdmal.cloudental.beans.base.AbstractEaoService;
import com.mpdmal.cloudental.entities.Dentist;
import com.mpdmal.cloudental.entities.UserPreferences;
import com.mpdmal.cloudental.util.exception.DentistExistsException;
import com.mpdmal.cloudental.util.exception.DentistNotFoundException;
import com.mpdmal.cloudental.util.exception.base.CloudentException;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Vector;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.jws.WebService;
import javax.persistence.Query;
@Named
@Stateless
@LocalBean
@WebService
public class DentistBean extends AbstractEaoService implements Serializable {
private static final long serialVersionUID = 1L;
public Dentist createDentist(String name, String surname, String username, String password) throws CloudentException {
if(this.findDentistByUsername(username) != null) {
throw new DentistExistsException(username);
} else {
Dentist d = new Dentist();
d.setName(name);
d.setSurname(surname);
d.setUsername(username);
d.setPassword(password);
UserPreferences prefs = new UserPreferences();
prefs.setDailyreports(true);
prefs.setEmailcontent("");
prefs.setEmailnotification(true);
prefs.setEventTitleFormatType(UserPreferences.DEFAULT_USER_EVTITLEFORMAT);
prefs.setTheme("aristo");
prefs.setSchedulerMaxHour(22);
prefs.setSchedulerMinHour(6);
prefs.setSchedulerStartHour(8);
prefs.setSchedulerSlotMins(5);
prefs.setPrescriptionHeader("");
prefs.setReportemail("");
prefs.setDentist(d);
this.emgr.persist(d);
this.emgr.persist(prefs);
return d;
}
}
public long countDentists() {
Query q = this.emgr.getEM().createQuery("select count(d) from Dentist d");
return this.emgr.executeSingleLongQuery(q);
}
public void updateDentist(Dentist d) throws DentistNotFoundException {
if(this.emgr.findOrFail(Dentist.class, d.getId()) == null) {
throw new DentistNotFoundException(d.getUsername());
} else {
this.emgr.update(d);
}
}
public void deleteDentist(int id) throws DentistNotFoundException {
Dentist d = this.findDentist(id);
this.emgr.delete(d);
}
public void deleteDentistByUsername(String username) throws DentistNotFoundException {
Dentist d = this.findDentistByUsername(username);
this.emgr.delete(d);
}
public Vector getDentists() {
Query q = this.emgr.getEM().createQuery("select d from Dentist d");
return (Vector)this.emgr.executeMultipleObjectQuery(q);
}
public void deleteDentists() {
Vector dents = this.getDentists();
Iterator var2 = dents.iterator();
while(var2.hasNext()) {
Dentist dentist = (Dentist)var2.next();
try {
this.deleteDentist(dentist.getId().intValue());
} catch (DentistNotFoundException var5) {
var5.printStackTrace();
}
}
}
}