Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.peopleway.invoicesystem.customer;
- Customer
- package net.peopleway.invoicesystem.customer;
- import java.io.Serializable;
- import java.util.Date;
- import java.util.List;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.FetchType;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- import net.peopleway.invoicesystem.subscription.Subscription;
- import net.peopleway.invoicesystem.user.User;
- import org.hibernate.annotations.Fetch;
- import org.hibernate.annotations.LazyCollection;
- import org.hibernate.annotations.LazyCollectionOption;
- @Entity
- @Table(name = "customer")
- public class Customer implements Serializable,Comparable<Customer>{
- private static final long serialVersionUID = -1111803252737409312L;
- private List<Subscription> subscriptions;
- private User user;
- private Date creationDate;
- private String mailaddress, phonenumber, EANnumber, name, contactPerson,
- currency, departmentName, addressCustomer, country, zipcode;
- private int customer_id, testserver;
- private boolean active;
- public Customer(int customer_id , User user,
- Date creationDate, String mailaddress, String phonenumber,
- String EANnumber, String name, String contactPerson,
- String currency, String departmentName, String addressCustomer,
- String country, String zipcode, boolean active) {
- this.customer_id = customer_id;
- this.user = user;
- this.creationDate = creationDate;
- this.mailaddress = mailaddress;
- this.phonenumber = phonenumber;
- this.EANnumber = EANnumber;
- this.name = name;
- this.contactPerson = contactPerson;
- this.currency = currency;
- this.departmentName = departmentName;
- this.addressCustomer = addressCustomer;
- this.country = country;
- this.zipcode = zipcode;
- this.active = active;
- }
- public Customer() {
- }
- @Id
- @GeneratedValue
- @Column
- public int getCustomer_id() {
- return customer_id;
- }
- public void setCustomer_id(int customer_id) {
- this.customer_id = customer_id;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer", orphanRemoval=true)
- public List<Subscription> getSubscriptions() {
- return subscriptions;
- }
- public void setSubscriptions(List<Subscription> subscriptions) {
- this.subscriptions = subscriptions;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @ManyToOne(optional = false)
- @JoinColumn(name = "user_id")
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
- @Column
- public Date getCreationDate() {
- return creationDate;
- }
- public void setCreationDate(Date creationDate) {
- this.creationDate = creationDate;
- }
- @Column
- public String getMailaddress() {
- return mailaddress;
- }
- public void setMailaddress(String mailaddress) {
- this.mailaddress = mailaddress;
- }
- @Column
- public String getPhonenumber() {
- return phonenumber;
- }
- public void setPhonenumber(String phoneNumber) {
- this.phonenumber = phoneNumber;
- }
- @Column
- public String getEANnumber() {
- return EANnumber;
- }
- public void setEANnumber(String EANnumber) {
- this.EANnumber = EANnumber;
- }
- @Column
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Column
- public String getContactPerson() {
- return contactPerson;
- }
- public void setContactPerson(String contactPerson) {
- this.contactPerson = contactPerson;
- }
- @Column
- public String getCurrency() {
- return currency;
- }
- public void setCurrency(String currency) {
- this.currency = currency;
- }
- @Column
- public String getDepartmentName() {
- return departmentName;
- }
- public void setDepartmentName(String departmentName) {
- this.departmentName = departmentName;
- }
- @Column
- public String getAddressCustomer() {
- return addressCustomer;
- }
- public void setAddressCustomer(String addressCustomer) {
- this.addressCustomer = addressCustomer;
- }
- @Column
- public String getCountry() {
- return country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- @Column
- public String getZipcode() {
- return zipcode;
- }
- public void setZipcode(String zipcode) {
- this.zipcode = zipcode;
- }
- @Column
- public boolean isActive() {
- return active;
- }
- public void setActive(boolean active) {
- this.active = active;
- }
- public int compareTo(Customer c){
- return this.name.compareTo(c.name);
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Customer other = (Customer) obj;
- if (customer_id != other.customer_id)
- return false;
- return true;
- }
- @Override
- public int hashCode() {
- return super.hashCode();
- }
- @Override
- public String toString() {
- String str = name;
- String cap = str.substring(0, 1).toUpperCase() + str.substring(1);
- return cap;
- }
- @Column
- public int getTestserver() {
- return testserver;
- }
- public void setTestserver(int testserver) {
- this.testserver = testserver;
- }
- }
- CustomerConverter
- package net.peopleway.invoicesystem.customer;
- import java.sql.SQLException;
- import javax.enterprise.context.ApplicationScoped;
- import javax.faces.application.FacesMessage;
- import javax.faces.component.UIComponent;
- import javax.faces.context.FacesContext;
- import javax.faces.convert.Converter;
- import javax.faces.convert.ConverterException;
- import javax.inject.Inject;
- import javax.inject.Named;
- import org.apache.commons.lang.StringUtils;
- @Named
- @ApplicationScoped
- public class CustomerConverter implements Converter {
- @Inject
- private CustomerService ss;
- @Override
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
- if(StringUtils.isBlank(value)){
- return null;
- }
- try {
- int id = Integer.parseInt(value);
- for (Customer c : ss.getCustomers()) {
- if (c.getCustomer_id() == id) {
- return c;
- }
- }
- return null;
- } catch (NumberFormatException | ClassNotFoundException | SQLException e) {
- throw new ConverterException(new FacesMessage("Could not convert to customer"));
- }
- }
- @Override
- public String getAsString(FacesContext context, UIComponent component, Object value) {
- if (value == null)
- return "";
- return Integer.toString(((Customer) value).getCustomer_id());
- }
- }
- CustomerDao
- package net.peopleway.invoicesystem.customer;
- import java.io.Serializable;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import org.hibernate.Criteria;
- import org.hibernate.Hibernate;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import org.hibernate.criterion.Restrictions;
- import net.peopleway.invoicesystem.dbproperties.DatabaseConnectionPraktik2016;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.invoice.InvoiceInterval;
- import net.peopleway.invoicesystem.product.Product;
- import net.peopleway.invoicesystem.subscription.State;
- import net.peopleway.invoicesystem.subscription.Subscription;
- import net.peopleway.invoicesystem.subscription.SubscriptionDao;
- import net.peopleway.invoicesystem.user.User;
- import net.peopleway.invoicesystem.user.UserDao;
- import net.peopleway.invoicesystem.user.UserService;
- @Named
- @ApplicationScoped
- public class CustomerDao implements Serializable {
- @Inject DatabaseConnectionPraktik2016 db = new DatabaseConnectionPraktik2016();
- @Inject SubscriptionDao subdb;
- public void saveCustomer(Customer c){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- session.save(c);
- t.commit();
- }
- public void updateCustomer(Customer c){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- session.update(c);
- t.commit();
- }
- public Customer getCustomerById(int id){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.getTransaction();
- session.beginTransaction();
- Criteria criteria = session.createCriteria(Customer.class);
- criteria.add(Restrictions.eq("customer_id", id));
- Customer s = (Customer) criteria.uniqueResult();
- t.commit();
- return s;
- }
- public void createCustomer(User user,
- Date creationDate, String mailAddress, String phoneNumber,
- String eANNumber, String name, String contactPerson,
- String currency, String departmentName, String address,
- String country, int district) throws ClassNotFoundException, SQLException{
- if(eANNumber == null || eANNumber == ""){
- eANNumber = "null";
- }
- Timestamp ts_now = new Timestamp(creationDate.getTime());
- db.open();
- db.executeUpdate("insert into Customer values(?,?,?,?,?,?,?,?,?,?,?,?,?)", ts_now+"",
- mailAddress, phoneNumber+"", eANNumber+"", "true", name, contactPerson, currency, departmentName, address,
- district+"", country, user.getUser_id()+"");
- }
- public List<Customer> getCustomersUser(User u){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria c = session.createCriteria(User.class);
- c.add(Restrictions.idEq(u.getUser_id()));
- u = (User) c.uniqueResult();
- Hibernate.initialize(u.getCustomers());
- t.commit();
- return u.getCustomers();
- }
- public List<Customer> getCustomers() throws SQLException, ClassNotFoundException{
- List<Customer> l = new ArrayList<Customer>();
- ResultSet rs = null;
- db.open();
- db.prepare("select customer_id, creationdate, mailaddress, phonenumber, EANNumber, active, name, contactPerson, currency, departmentname, addresscustomer, zipcode, country, user_id from customer");
- rs = db.execute();
- while(rs.next()){
- Customer c = new Customer(rs.getInt("customer_id") ,getUserById(rs.getInt("user_id")), rs.getDate("creationDate"), rs.getString("mailAddress"), rs.getString("phonenumber"), rs.getString("EANNumber"), rs.getString("name"), rs.getString("contactPerson"), rs.getString("currency"), rs.getString("departmentname"), rs.getString("addresscustomer"), rs.getString("country"), rs.getString("zipcode"), rs.getBoolean("active"));
- l.add(c);
- }
- return l;
- }
- public void deleteById(Class<Customer> customer, Serializable id) {
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Object persistentInstance = session.load(customer, id);
- if (persistentInstance != null) {
- session.delete(persistentInstance);
- }
- t.commit();
- }
- public void deleteCustomer(Customer c){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- session.delete(c);
- t.commit();
- }
- public void changeStateCustomer(Customer c){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- session.update(c);
- t.commit();
- }
- public List<User> getUsers() throws SQLException, ClassNotFoundException{
- List<User> l = new ArrayList<User>();
- ResultSet rs = null;
- db.open();
- db.prepare("Select user_id, username, pass, name, administrator, accountant from Users");
- rs = db.execute();
- while(rs.next()){
- User u = new User(rs.getString("username"), rs.getString("pass"), rs.getString("name"),
- rs.getInt("user_id"), rs.getBoolean("administrator"), rs.getBoolean("accountant"));
- l.add(u);
- }
- return l;
- }
- public User getUserById(int j) throws ClassNotFoundException, SQLException{
- for(int i = 0; i < getUsers().size(); i++){
- if(getUsers().get(i).getUser_id() == j){
- return getUsers().get(i);
- }
- }
- return null;
- }
- public void saveOrUpdateCustomer(Customer c){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- session.saveOrUpdate(c);
- t.commit();
- }
- public List<Subscription> getSubs(Customer c){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria u = session.createCriteria(Customer.class);
- u.add(Restrictions.idEq(c.getCustomer_id()));
- // The object we are interested in
- c = (Customer) u.uniqueResult();
- // Important to use to get the objects with hibernate
- Hibernate.initialize(c.getSubscriptions());
- // Any reference to another object in the subscriptions objects other than customer is a Hibernate references so if needed
- // use Hibernate.initialize on them also.
- t.commit();
- return c.getSubscriptions();
- }
- }
- CustomerManagementBean
- package net.peopleway.invoicesystem.customer;
- import java.io.IOException;
- import java.io.Serializable;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.annotation.PostConstruct;
- import javax.enterprise.context.spi.CreationalContext;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import org.omnifaces.util.Faces;
- import net.peopleway.invoicesystem.login.UserManager;
- import net.peopleway.invoicesystem.subscription.Subscription;
- import net.peopleway.invoicesystem.subscription.SubscriptionService;
- import net.peopleway.invoicesystem.user.UserService;
- @Named
- @ViewScoped
- public class CustomerManagementBean implements Serializable{
- private String name;
- private String contactPerson;
- private String mailAddress;
- private String departmentName;
- private String addressCustomer;
- private String country;
- private String zipcode;
- private String EAN;
- private String phonenumber;
- private String currency;
- private int testserver;
- private Integer expectedParticipants;
- private Integer employees;
- private boolean active;
- private boolean editing;
- private Customer selectedCustomer;
- private List<Customer> customers;
- private Date creationDate;
- @Inject CustomerService cs;
- @Inject UserManager userManager;
- @Inject SubscriptionService ss;
- @Inject UserService us;
- public void customerlistener(){
- if(selectedCustomer != null){
- addressCustomer = selectedCustomer.getAddressCustomer();
- contactPerson = selectedCustomer.getContactPerson();
- country = selectedCustomer.getCountry();
- creationDate = selectedCustomer.getCreationDate();
- departmentName = selectedCustomer.getDepartmentName();
- mailAddress = selectedCustomer.getMailaddress();
- EAN = selectedCustomer.getEANnumber();
- name = selectedCustomer.getName();
- phonenumber = selectedCustomer.getPhonenumber();
- zipcode = selectedCustomer.getZipcode();
- currency = selectedCustomer.getCurrency();
- active = selectedCustomer.isActive();
- editing = true;
- }else{
- editing = false;
- }
- }
- public void back() throws IOException{
- Faces.redirect("customers");
- }
- public String createNewCustomer() throws Exception{
- Customer c = null;
- if(selectedCustomer != null){
- c = selectedCustomer;
- }else{
- c = new Customer();
- }
- c.setAddressCustomer(addressCustomer);
- c.setContactPerson(contactPerson);
- c.setCountry(country);
- c.setCreationDate(new Date());
- c.setDepartmentName(departmentName);
- c.setMailaddress(mailAddress);
- c.setEANnumber(EAN);
- c.setName(name);
- c.setPhonenumber(phonenumber);
- c.setSubscriptions(new ArrayList<Subscription>());
- c.setZipcode(zipcode);
- c.setCurrency("depends on country");
- c.setActive(false);
- c.setUser(us.getUserById(userManager.getUser().getUser_id()));
- if(editing){
- cs.updateCustomer(c);
- return null;
- }
- else{
- cs.saveCustomer(c);
- return "customers.xhtml?faces-redirect=true";
- }
- }
- public String deleteCustomer() throws ClassNotFoundException, SQLException{
- try {
- cs.deleteCustomer(selectedCustomer);
- return "customers.xhtml?faces-redirect=true";
- } catch (Exception e) {
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- return null;
- }
- public int getExpectedParticipants() {
- return expectedParticipants;
- }
- public void setExpectedParticipants(int expectedParticipants) {
- this.expectedParticipants = expectedParticipants;
- }
- public int getEmployees() {
- return employees;
- }
- public void setEmployees(int employees) {
- this.employees = employees;
- }
- public String getCurrency() {
- return currency;
- }
- public void setCurrency(String currency) {
- this.currency = currency;
- }
- public boolean isActive() {
- return active;
- }
- public void setActive(boolean active) {
- this.active = active;
- }
- public Date getCreationDate() {
- return creationDate;
- }
- public void setCreationDate(Date creationDate) {
- this.creationDate = creationDate;
- }
- public Customer getSelectedCustomer() {
- return selectedCustomer;
- }
- public void setSelectedCustomer(Customer selectedCustomer) {
- this.selectedCustomer = selectedCustomer;
- }
- public List<Customer> getCustomers() {
- return customers;
- }
- public void setCustomers(List<Customer> customers) {
- this.customers = customers;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getContactPerson() {
- return contactPerson;
- }
- public void setContactPerson(String contactPerson) {
- this.contactPerson = contactPerson;
- }
- public String getMailAddress() {
- return mailAddress;
- }
- public void setMailAddress(String mailAddress) {
- this.mailAddress = mailAddress;
- }
- public String getDepartmentName() {
- return departmentName;
- }
- public void setDepartmentName(String departmentName) {
- this.departmentName = departmentName;
- }
- public String getAddressCustomer() {
- return addressCustomer;
- }
- public void setAddressCustomer(String addressCustomer) {
- this.addressCustomer = addressCustomer;
- }
- public String getCountry() {
- return country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- public String getZipcode() {
- return zipcode;
- }
- public void setZipcode(String zipcode) {
- this.zipcode = zipcode;
- }
- public String getEAN() {
- return EAN;
- }
- public void setEAN(String eAN) {
- EAN = eAN;
- }
- public String getPhonenumber() {
- return phonenumber;
- }
- public void setPhonenumber(String phonenumber) {
- this.phonenumber = phonenumber;
- }
- public boolean isEditing() {
- return editing;
- }
- public void setEditing(boolean editing) {
- this.editing = editing;
- }
- }
- CustomerBean
- package net.peopleway.invoicesystem.customer;
- import java.io.Serializable;
- import java.util.List;
- import javax.annotation.PostConstruct;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import com.sun.faces.config.processor.FacesConfigExtensionProcessor;
- import net.peopleway.invoicesystem.login.UserManager;
- import net.peopleway.invoicesystem.subscription.Subscription;
- import net.peopleway.invoicesystem.subscription.SubscriptionService;
- import net.peopleway.invoicesystem.user.UserService;
- @Named
- @ViewScoped
- public class CustomersBean implements Serializable{
- private static final long serialVersionUID = -5892408888372620597L;
- @Inject private UserManager userManager;
- @Inject private SubscriptionService ss;
- @Inject private CustomerService cs;
- @Inject private UserService us;
- private List<Customer> customers;
- private List<Subscription> subscriptions;
- private List<Subscription> activeSubscription;
- private Customer selectedCustomer;
- private int subId;
- private int subToStart;
- private int subToEnd;
- public String edit(){
- try{
- if(selectedCustomer == null){
- throw new Exception("You have no customers");
- }
- return "customer.xhtml?faces-redirect=true&id=" + selectedCustomer.getCustomer_id();
- }catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- return null;
- }
- public String newSub(){
- try{
- if(selectedCustomer == null){
- throw new Exception("You have no customers");
- }
- return "subscription.xhtml?faces-redirect=true&customerId=" + selectedCustomer.getCustomer_id();
- }catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- return null;
- }
- public void updateSubList(){
- subscriptions = ss.getCustSubs(selectedCustomer);
- }
- public void deleteSub(){
- try{
- ss.deleteSubscription(ss.getSubscriptionById(subId));
- }catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- subscriptions = ss.getCustSubs(selectedCustomer);
- }
- public void startSub() throws Exception{
- try{
- ss.startSub(ss.getSubscriptionById(subToStart));
- updateSubList();
- }catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- }
- public void endSub(){
- try{
- ss.stopSub(ss.getSubscriptionById(subToEnd));
- updateSubList();
- }
- catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- }
- public int getSubToEnd() {
- return subToEnd;
- }
- public void setSubToEnd(int subToEnd) {
- this.subToEnd = subToEnd;
- }
- public int getSubToStart() {
- return subToStart;
- }
- public void setSubToStart(int subToStart) {
- this.subToStart = subToStart;
- }
- public int getSubId() {
- return subId;
- }
- public void setSubId(int subId) {
- this.subId = subId;
- }
- public Customer getSelectedCustomer() {
- return selectedCustomer;
- }
- public void setSelectedCustomer(Customer selectedCustomer) {
- this.selectedCustomer = selectedCustomer;
- }
- public List<Customer> getCustomers() {
- return customers;
- }
- public void setCustomers(List<Customer> customers) {
- this.customers = customers;
- }
- public List<Subscription> getSubscriptions() {
- return subscriptions;
- }
- public void setSubscriptions(List<Subscription> subscriptions) {
- this.subscriptions = subscriptions;
- }
- public List<Subscription> getActiveSubscription() {
- return activeSubscription;
- }
- public void setActiveSubscription(List<Subscription> activeSubscription) {
- this.activeSubscription = activeSubscription;
- }
- @PostConstruct
- public void initialize(){
- customers = cs.getCustomersUser(userManager.getUser());
- if(customers.size()>0){
- selectedCustomer = customers.get(0);
- subscriptions = ss.getCustSubs(selectedCustomer);
- }
- }
- }
- CustomerService
- package net.peopleway.invoicesystem.customer;
- import java.io.Serializable;
- import java.sql.SQLException;
- import java.util.Date;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.subscription.Subscription;
- import net.peopleway.invoicesystem.user.User;
- @Named
- @ApplicationScoped
- public class CustomerService implements Serializable {
- @Inject
- static CustomerDao db = new CustomerDao();
- public Customer getCustomerById(int id){
- return db.getCustomerById(id);
- }
- public void saveorUpdateCustomer(Customer c){
- db.saveOrUpdateCustomer(c);
- }
- public void saveCustomer(Customer c) throws Exception{
- try{
- if(c.getName().isEmpty() || c.getAddressCustomer().isEmpty() || c.getContactPerson().isEmpty() || c.getCountry().isEmpty() || c.getCurrency().isEmpty() || c.getDepartmentName().isEmpty() || c.getPhonenumber().isEmpty() || c.getZipcode().isEmpty()){
- throw new Exception();
- }else{
- db.saveCustomer(c);
- }
- }catch(Exception e){
- throw new Exception("Name, Address, Contact person, Country, Currency, Department, Phone number and Zipcode must be filled");
- }
- }
- public void updateCustomer(Customer c) throws Exception{
- try{
- if(c.getName().isEmpty() || c.getAddressCustomer().isEmpty() || c.getContactPerson().isEmpty() || c.getCountry().isEmpty() || c.getCurrency().isEmpty() || c.getDepartmentName().isEmpty() || c.getPhonenumber().isEmpty() || c.getZipcode().isEmpty()){
- throw new Exception();
- }
- else{
- db.updateCustomer(c);
- }
- }catch(Exception e){
- throw new Exception("Name, Address, Contact person, Country, Currency, Department, Phone number and Zipcode must be filled");
- }
- }
- public void changeStateCustomer(Customer c){
- db.changeStateCustomer(c);
- }
- public void deletebyid(Class<Customer> customer, Serializable id){
- db.deleteById(customer, id);
- }
- public void createCustomer(User user,
- Date creationDate, String mailAddress, String phoneNumber,
- String eANNumber, String name, String contactPerson,
- String currency, String departmentName, String address,
- String country, int district) throws ClassNotFoundException, SQLException{
- db.createCustomer(user, creationDate, mailAddress, phoneNumber, eANNumber, name, contactPerson, currency, departmentName, address, country, district);
- }
- public List<Customer> getCustomersUser(User u){
- return db.getCustomersUser(u);
- }
- public void deleteCustomer(Customer c) throws Exception{
- try{
- if(c.isActive()){
- throw new Exception();
- }else{
- db.deleteCustomer(c);
- }
- }catch(Exception e){
- throw new Exception("Cannot delete a customer with subscriptions not in progress");
- }
- }
- public List<Subscription> getSubscriptions(Customer c) throws ClassNotFoundException, SQLException{
- return db.getSubs(c);
- }
- public List<Customer> getCustomers() throws ClassNotFoundException, SQLException{
- return db.getCustomers();
- }
- }
- package net.peopleway.invoicesystem.dbproperties;
- DatabaseConnection
- package net.peopleway.invoicesystem.dbproperties;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Named;
- import javax.transaction.Transaction;
- @Named
- @ApplicationScoped
- public class DatabaseConnection {
- private Connection connection;
- private PreparedStatement prepared;
- private ThreadLocal<Transaction> currentTransaction;
- public Connection getConnection() {
- return connection;
- }
- public Connection open() throws SQLException {
- if (connection == null || connection.isClosed()) {
- connection = DriverManager.getConnection(DatabaseProperties.getConnectionString());
- connection.setAutoCommit(true);
- }
- return connection;
- }
- public PreparedStatement prepare(String sql, String... params) throws SQLException {
- prepared = connection.prepareStatement(sql);
- for(int i = 0; i < params.length; i++) {
- prepared.setString(i + 1, params[i]);
- }
- return prepared;
- }
- public ResultSet execute() throws SQLException {
- return prepared.executeQuery();
- }
- public void update() throws SQLException {
- prepared.executeUpdate();
- }
- public void close() throws SQLException {
- if (connection != null) {
- connection.close();
- }
- }
- public Integer executeUpdate(String sql, Object... parameters) {
- return executeUpdate(sql, toParameterList(parameters));
- }
- public Integer executeUpdate(String sql, List<Object> parameters) {
- Integer key = null;
- try {
- open();
- PreparedStatement statement = connection.prepareStatement(sql);
- setParameters(statement, parameters);
- statement.executeUpdate();
- statement.close();
- if (sql.trim().toUpperCase().startsWith("INSERT")) {
- Statement keyStatement = connection.createStatement();
- ResultSet generatedKeys = keyStatement.executeQuery("SELECT last_insert_rowid()");
- if (generatedKeys.next()) {
- key = generatedKeys.getInt(1);
- }
- }
- close();
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- return key;
- }
- public List<Object[]> query(String sql, Object... parameters) {
- return query(sql, toParameterList(parameters));
- }
- private List<Object> toParameterList(Object[] parameters) {
- List<Object> parameterList = new ArrayList<>();
- if (parameters != null && parameters.length > 0) {
- for (int i = 0; i < parameters.length; i++) {
- parameterList.add(parameters[i]);
- }
- }
- return parameterList;
- }
- public List<Object[]> query(String sql, List<Object> parameters) {
- List<Object[]> listResult = new ArrayList<>();
- try {
- open();
- PreparedStatement statement = connection.prepareStatement(sql);
- setParameters(statement, parameters);
- ResultSet result = statement.executeQuery();
- listResult = transform(result);
- result.close();
- statement.close();
- close();
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- return listResult;
- }
- private void setParameters(PreparedStatement statement, List<Object> parameters) throws SQLException {
- if (parameters != null && !parameters.isEmpty()) {
- int i = 1;
- for (Object parameter : parameters) {
- if (parameter instanceof Integer) {
- statement.setInt(i++, (Integer) parameter);
- }
- else if (parameter instanceof Long) {
- statement.setLong(i++, (Long) parameter);
- }
- else if (parameter instanceof Double) {
- statement.setDouble(i++, (Double) parameter);
- }
- else if (parameter instanceof Float) {
- statement.setFloat(i++, (Float) parameter);
- }
- else if (parameter instanceof Date) {
- statement.setTimestamp(i++, new Timestamp(((Date) parameter).getTime()));
- }
- else {
- statement.setString(i++, (String) parameter);
- }
- }
- }
- }
- private List<Object[]> transform(ResultSet result) throws SQLException {
- List<Object[]> listResult = new ArrayList<>();
- ResultSetMetaData meta = result.getMetaData();
- int columnCount = meta.getColumnCount();
- while (result.next()) {
- Object[] data = new Object[columnCount];
- for (int i = 0; i < columnCount; i++) {
- data[i] = result.getObject(i + 1);
- }
- listResult.add(data);
- }
- return listResult;
- }
- }
- DatabaseConnectionPraktik2016
- package net.peopleway.invoicesystem.dbproperties;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Named;
- import javax.transaction.Transaction;
- @Named
- @ApplicationScoped
- public class DatabaseConnectionPraktik2016 {
- private Connection connection;
- private PreparedStatement prepared;
- private ThreadLocal<Transaction> currentTransaction;
- public Connection getConnection() {
- return connection;
- }
- public Connection open() throws SQLException, ClassNotFoundException {
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- if (connection == null || connection.isClosed()) {
- connection = DriverManager.getConnection(DatabasePropertiesPraktik2016.getConnectionString());
- connection.setAutoCommit(true);
- }
- return connection;
- }
- public PreparedStatement prepare(String sql, String... params) throws SQLException {
- prepared = connection.prepareStatement(sql);
- for(int i = 0; i < params.length; i++) {
- prepared.setString(i + 1, params[i]);
- }
- return prepared;
- }
- public ResultSet execute() throws SQLException {
- return prepared.executeQuery();
- }
- public void update() throws SQLException {
- prepared.executeUpdate();
- }
- public void close() throws SQLException {
- if (connection != null) {
- connection.close();
- }
- }
- public Integer executeUpdate(String sql, Object... parameters) throws ClassNotFoundException {
- return executeUpdate(sql, toParameterList(parameters));
- }
- public Integer executeUpdate(String sql, List<Object> parameters) throws ClassNotFoundException {
- Integer key = null;
- try {
- open();
- PreparedStatement statement = connection.prepareStatement(sql);
- setParameters(statement, parameters);
- statement.executeUpdate();
- statement.close();
- if (sql.trim().toUpperCase().startsWith("INSERT")) {
- Statement keyStatement = connection.createStatement();
- ResultSet generatedKeys = keyStatement.executeQuery("Select scope_identity()");
- if (generatedKeys.next()) {
- key = generatedKeys.getInt(1);
- }
- }
- close();
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- return key;
- }
- public List<Object[]> query(String sql, Object... parameters) throws ClassNotFoundException {
- return query(sql, toParameterList(parameters));
- }
- private List<Object> toParameterList(Object[] parameters) {
- List<Object> parameterList = new ArrayList<>();
- if (parameters != null && parameters.length > 0) {
- for (int i = 0; i < parameters.length; i++) {
- parameterList.add(parameters[i]);
- }
- }
- return parameterList;
- }
- public List<Object[]> query(String sql, List<Object> parameters) throws ClassNotFoundException {
- List<Object[]> listResult = new ArrayList<>();
- try {
- open();
- PreparedStatement statement = connection.prepareStatement(sql);
- setParameters(statement, parameters);
- ResultSet result = statement.executeQuery();
- listResult = transform(result);
- result.close();
- statement.close();
- close();
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- return listResult;
- }
- private void setParameters(PreparedStatement statement, List<Object> parameters) throws SQLException {
- if (parameters != null && !parameters.isEmpty()) {
- int i = 1;
- for (Object parameter : parameters) {
- if (parameter instanceof Integer) {
- statement.setInt(i++, (Integer) parameter);
- }
- else if (parameter instanceof Long) {
- statement.setLong(i++, (Long) parameter);
- }
- else if (parameter instanceof Double) {
- statement.setDouble(i++, (Double) parameter);
- }
- else if (parameter instanceof Float) {
- statement.setFloat(i++, (Float) parameter);
- }
- else if (parameter instanceof Date) {
- statement.setTimestamp(i++, new Timestamp(((Date) parameter).getTime()));
- }
- else {
- statement.setString(i++, (String) parameter);
- }
- }
- }
- }
- private List<Object[]> transform(ResultSet result) throws SQLException {
- List<Object[]> listResult = new ArrayList<>();
- ResultSetMetaData meta = result.getMetaData();
- int columnCount = meta.getColumnCount();
- while (result.next()) {
- Object[] data = new Object[columnCount];
- for (int i = 0; i < columnCount; i++) {
- data[i] = result.getObject(i + 1);
- }
- listResult.add(data);
- }
- return listResult;
- }
- }
- DatabaseProperties
- package net.peopleway.invoicesystem.dbproperties;
- public class DatabaseProperties {
- public static final String driver = "net.sourceforge.jtds.jdbc.Driver";
- public static final String database = "DWBI";
- public static final String ip = "152.115.57.214";
- public static final Integer port = 1433;
- public static final String user = "biuser";
- public static final String password = "EaseData2015!";
- public static String getConnectionString() {
- return "jdbc:jtds:sqlserver://" + ip + ":" + port + ";databaseName=" + database + ";user=" + user + ";password=" + password;
- }
- }
- DatabasePropertiesPraktik2016
- package net.peopleway.invoicesystem.dbproperties;
- public class DatabasePropertiesPraktik2016 {
- public static final String driver = "net.sourceforge.jtds.jdbc.Driver";
- public static final String database = "Praktik_2016_invoice";
- public static final String ip = "10.0.88.145";
- public static final Integer port = 1433;
- public static final String user = "sa";
- public static final String password = "needFORspeed!";
- public static String getConnectionString() {
- return "jdbc:jtds:sqlserver://" + ip + ":" + port + ";databaseName=" + database + ";user=" + user + ";password=" + password;
- }
- }
- package net.peopleway.invoicesystem.extra;
- Extra
- package net.peopleway.invoicesystem.extra;
- import java.io.Serializable;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name="extra")
- public class Extra implements Serializable{
- private int extra_id;
- private String title;
- private Double price;
- @Id
- @GeneratedValue
- @Column
- public int getExtra_id() {
- return extra_id;
- }
- public void setExtra_id(int extra_id) {
- this.extra_id = extra_id;
- }
- @Column
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- @Column
- public Double getPrice() {
- return price;
- }
- public void setPrice(Double price) {
- this.price = price;
- }
- @Override
- public String toString() {
- return title;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + extra_id;
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Extra other = (Extra) obj;
- if (extra_id != other.extra_id)
- return false;
- return true;
- }
- }
- ExtraBean
- package net.peopleway.invoicesystem.extra;
- import java.io.IOException;
- import java.io.Serializable;
- import javax.annotation.PostConstruct;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.login.UserManager;
- @Named
- @ViewScoped
- public class ExtraBean implements Serializable {
- private static final long serialVersionUID = 5633130014334164042L;
- @Inject
- private UserManager userManager;
- @Inject
- private ExtraService service;
- private Extra newExtra;
- @PostConstruct
- public void test() throws IOException {
- System.out.println("Init");
- if(!userManager.getUser().isAdministrator()){
- FacesContext.getCurrentInstance().getExternalContext().redirect("/invoicesystem/customers");
- }
- newExtra = new Extra();
- }
- public void saveExtra() {
- try{
- service.saveExtra(newExtra);
- newExtra = new Extra();
- }
- catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null,
- new FacesMessage(e.getMessage()));
- }
- }
- public Extra getNewExtra() {
- return newExtra;
- }
- public void setNewExtra(Extra newExtra) {
- this.newExtra = newExtra;
- }
- }
- ExtraConverter
- package net.peopleway.invoicesystem.extra;
- import javax.enterprise.context.ApplicationScoped;
- import javax.faces.component.UIComponent;
- import javax.faces.context.FacesContext;
- import javax.faces.convert.Converter;
- import javax.inject.Inject;
- import javax.inject.Named;
- @Named
- @ApplicationScoped
- public class ExtraConverter implements Converter{
- @Inject
- private ExtraService ss;
- @Override
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
- if (value == null) {
- return null;
- }
- for (Extra c : ss.getExtras()) {
- if (c.getExtra_id() == Integer.parseInt(value)) {
- return c;
- }
- }
- return null;
- }
- @Override
- public String getAsString(FacesContext context, UIComponent component, Object value) {
- if (value == null)
- return "";
- return Integer.toString(((Extra) value).getExtra_id());
- }
- }
- ExtraDao
- package net.peopleway.invoicesystem.extra;
- import java.io.Serializable;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.faces.view.ViewScoped;
- import javax.inject.Named;
- import org.hibernate.Criteria;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import org.hibernate.criterion.Restrictions;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.license.License;
- @Named
- @ApplicationScoped
- public class ExtraDao implements Serializable {
- public boolean saveExtra(Extra newExtra) {
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- session.save(newExtra);
- t.commit();
- return true;
- }
- public List<Extra> getExtras(){
- Session session = DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria c = session.createCriteria(Extra.class);
- List<Extra> pl = c.list();
- t.commit();
- return pl;
- }
- }
- ExtraService
- package net.peopleway.invoicesystem.extra;
- import java.io.Serializable;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- @Named
- @ApplicationScoped
- public class ExtraService implements Serializable{
- @Inject
- private ExtraDao dao;
- public List<Extra> getExtras(){
- return dao.getExtras();
- }
- public void saveExtra(Extra newExtra) throws Exception {
- if(newExtra == null){
- throw new Exception("No Extra is present");
- }
- if(newExtra.getTitle() == null || newExtra.getTitle().trim().length()== 0){
- throw new Exception("Does not contain a title");
- }
- if(newExtra.getPrice() == null ){
- throw new Exception("Price is required");
- }
- if(newExtra.getPrice() < 1){
- throw new Exception("Price must be higher or equal to 1");
- }
- if(!dao.saveExtra(newExtra)){
- throw new Exception("The title "+newExtra.getTitle() + " already exists");
- }
- }
- }
- DatabaseSessionFactory
- package net.peopleway.invoicesystem.hibernate;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.cfg.Configuration;
- public class DatabaseSessionFactory {
- private static SessionFactory factory;
- public static SessionFactory getFactory() {
- return factory;
- }
- public static void configure(){
- Configuration config = new Configuration();
- config.configure("hibernate.cfg.xml");
- factory = config.buildSessionFactory();
- }
- public static Session getSession(){
- return factory.getCurrentSession();
- }
- }
- DatabaseStartupListener
- package net.peopleway.invoicesystem.hibernate;
- import javax.servlet.ServletContextEvent;
- import javax.servlet.ServletContextListener;
- public class DatabaseStartupListener implements ServletContextListener{
- @Override
- public void contextDestroyed(ServletContextEvent arg0) {
- }
- @Override
- public void contextInitialized(ServletContextEvent arg0) {
- DatabaseSessionFactory.configure();
- }
- }
- package net.peopleway.invoicesystem.index;
- IndexBean
- package net.peopleway.invoicesystem.index;
- import java.io.Serializable;
- import java.util.Date;
- import javax.annotation.PostConstruct;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- @Named
- @ViewScoped
- public class IndexBean implements Serializable {
- private static final long serialVersionUID = 4995482822989124736L;
- @Inject
- private IndexService service;
- private Date startdate;
- private Double amount;
- private String start;
- @PostConstruct
- public void test() {
- }
- public void updatePrices() {
- try {
- service.updatePrices(service.createUpdatePrices(startdate, amount));
- } catch (Exception e) {
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- }
- public Date getStartdate() {
- return startdate;
- }
- public void setStartdate(Date startdate) {
- this.startdate = startdate;
- }
- public Double getAmount() {
- return amount;
- }
- public void setAmount(Double amount) {
- this.amount = amount;
- }
- public String getStart() {
- return start;
- }
- public void setStart(String start) {
- this.start = start;
- }
- }
- IndexDao
- package net.peopleway.invoicesystem.index;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.TreeMap;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.pricelist.Interval;
- import net.peopleway.invoicesystem.pricelist.Pricelist;
- import org.hibernate.Criteria;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import org.hibernate.criterion.Restrictions;
- @Named
- @ApplicationScoped
- public class IndexDao implements Serializable {
- public List<Pricelist> getStartLicenses() {
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria c = session.createCriteria(Pricelist.class);
- c.add(Restrictions.isNull("enddate"));
- List<Pricelist> pricelists = c.list();
- TreeMap<License, Pricelist> mapping = new TreeMap<License, Pricelist>();
- for (Pricelist p : pricelists) {
- if (p.getStartdate().compareTo(new Date()) < 0) {
- if (!mapping.containsKey(p.getLicense())) {
- mapping.put(p.getLicense(), p);
- }
- }
- }
- List<Pricelist> plist = new ArrayList<Pricelist>();
- for (Pricelist p : mapping.values()) {
- plist.add(p);
- }
- t.commit();
- return plist;
- }
- public List<Pricelist> getCurrentLicenses() {
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria c = session.createCriteria(Pricelist.class);
- c.add(Restrictions.isNull("enddate"));
- List<Pricelist> pricelists = c.list();
- TreeMap<License, Pricelist> mapping = new TreeMap<License, Pricelist>();
- for (Pricelist p : pricelists) {
- if (p.getStartdate().compareTo(new Date()) < 0) {
- if (!mapping.containsKey(p.getLicense())) {
- mapping.put(p.getLicense(), p);
- }
- else{
- Pricelist pValue = mapping.get(p.getLicense());
- if(p.getStartdate().compareTo(pValue.getStartdate()) > 0){
- mapping.put(p.getLicense(), p);
- }
- }
- }
- }
- List<Pricelist> plist = new ArrayList<Pricelist>();
- for (Pricelist p : mapping.values()) {
- plist.add(p);
- }
- t.commit();
- return plist;
- }
- public boolean priceExistForThatDate(Date startdate) {
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria c = session.createCriteria(Pricelist.class);
- c.add(Restrictions.eq("startdate", startdate));
- List<Pricelist> pricelists = c.list();
- t.commit();
- return pricelists.size() != 0;
- }
- public void updatePrices(List<Pricelist> licenses) {
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- for (Pricelist p : licenses) {
- for (Interval i : p.getIntervals()) {
- session.save(i);
- }
- session.save(p);
- }
- t.commit();
- }
- }
- IndexService
- package net.peopleway.invoicesystem.index;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.pricelist.Interval;
- import net.peopleway.invoicesystem.pricelist.Pricelist;
- @Named
- @ApplicationScoped
- public class IndexService implements Serializable {
- @Inject
- IndexDao dao;
- public List<Pricelist> getCurrentLicenses(){
- return dao.getCurrentLicenses();
- }
- public List<Pricelist> createUpdatePrices(Date startdate, Double amount)
- throws Exception {
- if (dao == null) {
- dao = new IndexDao();
- }
- if (startdate == null) {
- throw new Exception(
- "A start date is required for making an update to all prices");
- }
- Calendar c = Calendar.getInstance();
- c.setTime(new Date());
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
- c.add(Calendar.DAY_OF_YEAR, 1);
- if (startdate.compareTo(c.getTime()) < 0) {
- throw new Exception("The startdate must be minimum tomorrow");
- }
- if (dao.priceExistForThatDate(startdate)) {
- throw new Exception("Update prices exists at the specified date");
- }
- if (amount == null) {
- throw new Exception(
- "A index value is required to update all prices");
- } else if (amount <= 0) {
- throw new Exception("The index value must be higher than 0");
- }
- List<Pricelist> licenses = dao.getStartLicenses();
- List<Pricelist> licensesNew = new ArrayList<Pricelist>();
- for (Pricelist p : licenses) {
- Pricelist pCopy = new Pricelist();
- pCopy.setLicense(p.getLicense());
- ;
- pCopy.setStartdate(startdate);
- pCopy.setEnddate(p.getEnddate());
- pCopy.setTitle(p.getTitle());
- pCopy.setIntervals(new ArrayList<Interval>());
- for (Interval i : p.getIntervals()) {
- Interval iCopy = new Interval();
- iCopy.setPrice(i.getPrice() * amount);
- iCopy.setFromInterval(i.getFromInterval());
- iCopy.setToInterval(i.getToInterval());
- pCopy.getIntervals().add(iCopy);
- }
- licensesNew.add(pCopy);
- }
- return licensesNew;
- }
- public void updatePrices(List<Pricelist> pricelists) throws Exception {
- if (dao == null) {
- dao = new IndexDao();
- }
- dao.updatePrices(pricelists);
- }
- public IndexDao getDao() {
- return dao;
- }
- public void setDao(IndexDao dao) {
- this.dao = dao;
- }
- }
- package net.peopleway.invoicesystem.invoice;
- Invoice
- package net.peopleway.invoicesystem.invoice;
- import java.io.File;
- import java.util.Date;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.EnumType;
- import javax.persistence.Enumerated;
- import javax.persistence.FetchType;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.Table;
- import net.peopleway.invoicesystem.subscription.Subscription;
- @Entity
- @Table(name="invoice")
- public class Invoice {
- private Subscription subscription;
- private Date creationDate, invoicesent, payday;
- private String invoiceNr, currency;
- private Double total;
- private int poNr, invoice_id;
- private InvoiceState invoicestate;
- // PDFs // Ignore
- private File finalPDF, originalPDF;
- public Invoice() {
- // TODO Auto-generated constructor stub
- }
- @ManyToOne(optional = true, fetch = FetchType.LAZY)
- @JoinColumn(name = "subscription_id")
- public Subscription getSubscription() {
- return subscription;
- }
- public void setSubscription(Subscription subscription) {
- this.subscription = subscription;
- }
- @Column
- public Date getCreationDate() {
- return creationDate;
- }
- public void setCreationDate(Date creationDate) {
- this.creationDate = creationDate;
- }
- @Column
- public Date getInvoicesent() {
- return invoicesent;
- }
- public void setInvoicesent(Date invoicesent) {
- this.invoicesent = invoicesent;
- }
- @Column
- public Date getPayday() {
- return payday;
- }
- public void setPayday(Date payday) {
- this.payday = payday;
- }
- @Column
- public String getInvoiceNr() {
- return invoiceNr;
- }
- public void setInvoiceNr(String invoiceNr) {
- this.invoiceNr = invoiceNr;
- }
- @Column
- public String getCurrency() {
- return currency;
- }
- public void setCurrency(String currency) {
- this.currency = currency;
- }
- @Column
- public Double getTotal() {
- return total;
- }
- public void setTotal(Double total) {
- this.total = total;
- }
- @Column
- public int getPoNr() {
- return poNr;
- }
- public void setPoNr(int poNr) {
- this.poNr = poNr;
- }
- @Enumerated(EnumType.STRING)
- public InvoiceState getInvoicestate() {
- return invoicestate;
- }
- public void setInvoicestate(InvoiceState invoicestate) {
- this.invoicestate = invoicestate;
- }
- @Id
- @GeneratedValue
- @Column
- public int getInvoice_id() {
- return invoice_id;
- }
- public void setInvoice_id(int invoice_id) {
- this.invoice_id = invoice_id;
- }
- }
- InvoiceInterval
- package net.peopleway.invoicesystem.invoice;
- import javax.persistence.EnumType;
- import javax.persistence.Enumerated;
- public enum InvoiceInterval {
- Daily, Weekly, Monthly, Quarterly, Yearly
- }
- InvoiceState
- package net.peopleway.invoicesystem.invoice;
- public enum InvoiceState {
- Paid, InProgress, ApprovedAndSent, PastDeadline, PastDeadlineDelay, Draft
- }
- package net.peopleway.invoicesystem.junit.index;
- IndexJUnit
- package net.peopleway.invoicesystem.junit.index;
- import static org.junit.Assert.assertEquals;
- import java.util.Calendar;
- import java.util.List;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.index.IndexDao;
- import net.peopleway.invoicesystem.index.IndexService;
- import net.peopleway.invoicesystem.pricelist.Interval;
- import net.peopleway.invoicesystem.pricelist.Pricelist;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- public class IndexJUnit {
- private IndexService service;
- @Before
- public void setUp() throws Exception {
- service = new IndexService();
- DatabaseSessionFactory.configure();
- }
- @After
- public void destroy(){
- }
- @Test
- public void updatePrices() throws Exception{
- Double amount = 2.0;
- Calendar c = Calendar.getInstance();
- c.add(Calendar.YEAR, 1);
- List<Pricelist> currentPricelist = new IndexDao().getStartLicenses();
- List<Pricelist> nextPricelist = service.createUpdatePrices(c.getTime(), amount);
- for(int i = 0; i < currentPricelist.size(); i++){
- Pricelist p = currentPricelist.get(i);
- Pricelist pNew = nextPricelist.get(i);
- for(int j = 0; j < p.getIntervals().size(); j++){
- Interval interval = p.getIntervals().get(j);
- Interval intervalNew = pNew.getIntervals().get(j);
- interval.setPrice(interval.getPrice()*amount);
- assertEquals(interval.getPrice(), intervalNew.getPrice());
- }
- }
- }
- }
- package net.peopleway.invoicesystem.junit.login;
- LoginJUnit
- package net.peopleway.invoicesystem.junit.login;
- import static org.junit.Assert.*;
- import java.sql.SQLException;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.login.LoginService;
- import net.peopleway.invoicesystem.user.User;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- public class LoginJUnit {
- private LoginService service;
- private User user;
- @Before
- public void setUp() throws Exception {
- user = new User();
- service = new LoginService();
- DatabaseSessionFactory.configure();
- }
- @After
- public void destroy(){
- service.destroyUserToken(user);
- }
- @Test
- public void loginAttempt() throws ClassNotFoundException, SQLException {
- user.setUsername("Lars");
- user.setPass("123");
- assertNotNull(service.validate(user.getUsername(), user.getPass()));
- }
- }
- package net.peopleway.invoicesystem.junit.subscription;
- SubscriptionJUnit
- package net.peopleway.invoicesystem.junit.subscription;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNull;
- import java.util.Date;
- import java.util.List;
- import net.peopleway.invoicesystem.customer.Customer;
- import net.peopleway.invoicesystem.extra.Extra;
- import net.peopleway.invoicesystem.extra.ExtraService;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.index.IndexService;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.license.LicenseService;
- import net.peopleway.invoicesystem.pricelist.Pricelist;
- import net.peopleway.invoicesystem.pricelist.PricelistService;
- import net.peopleway.invoicesystem.subscription.Subscription;
- import net.peopleway.invoicesystem.subscription.SubscriptionDao;
- import net.peopleway.invoicesystem.subscription.SubscriptionService;
- import net.peopleway.invoicesystem.user.User;
- import net.peopleway.invoicesystem.user.UserService;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- public class SubscriptionJUnit {
- private SubscriptionService service;
- private User user;
- private Customer c;
- private Subscription s;
- @Before
- public void setUp() throws Exception {
- user = new User();
- service = new SubscriptionService();
- DatabaseSessionFactory.configure();
- }
- @After
- public void destroy(){
- }
- @Test
- public void createUpdateRemoveUser() throws Exception {
- user.setUsername("Test12345");
- user.setPass("521");
- user.setName("Test");
- UserService uS = new UserService();
- uS.createUser(user);
- uS.getUserById(uS.getUsers().size()-1);
- Customer customer = new Customer();
- customer.setActive(false);
- customer.setAddressCustomer("Testing Ville");
- customer.setContactPerson("Børge Buller");
- customer.setCountry("Urgana");
- customer.setCreationDate(new Date());
- customer.setCurrency("DKK");
- customer.setDepartmentName("Danish Testers");
- customer.setEANnumber("Testing");
- customer.setMailaddress("Testing@Testing.net");
- customer.setName("Anne Jørgensen");
- customer.setPhonenumber("124254252");
- customer.setTestserver(0);
- customer.setZipcode("1234");
- user.getCustomers().add(customer);
- Subscription s = new Subscription();
- s.setCustomer(customer);
- new SubscriptionDao().createSub(s);
- assertEquals(s, new SubscriptionService().getCustSubs(c).get(new SubscriptionService().getCustSubs(c).size()-1));
- new SubscriptionService().deleteSubscription(s);
- }
- }
- package net.peopleway.invoicesystem.junit.user;
- UserJUnit
- package net.peopleway.invoicesystem.junit.user;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotEquals;
- import static org.junit.Assert.assertNull;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.user.User;
- import net.peopleway.invoicesystem.user.UserService;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- public class UserJUnit {
- private UserService service;
- private User user;
- @Before
- public void setUp() throws Exception {
- user = new User();
- service = new UserService();
- DatabaseSessionFactory.configure();
- }
- @After
- public void destroy(){
- }
- @Test
- public void createUpdateRemoveUser() throws Exception {
- user.setUsername("Test12345");
- user.setPass("521");
- user.setName("Test");
- service.createUser(user);
- assertNotEquals(0, user.getUser_id());
- String name = "Test12345";
- user.setName(name);
- service.updateUser(user);
- assertEquals(name,service.getUserById(user.getUser_id()).getName());
- service.removeUser(user);
- assertNull(service.getUserById(user.getUser_id()));
- }
- }
- package net.peopleway.invoicesystem.license;
- License
- package net.peopleway.invoicesystem.license;
- import java.io.Serializable;
- import java.util.List;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- import net.peopleway.invoicesystem.pricelist.Pricelist;
- import org.hibernate.annotations.LazyCollection;
- import org.hibernate.annotations.LazyCollectionOption;
- @Entity
- @Table(name = "license")
- public class License implements Serializable, Comparable<License>{
- private int license_id;
- private String title;
- private String licensestate;
- private List<Pricelist> pricelists;
- private Double price;
- @Id
- @GeneratedValue
- @Column
- public int getLicense_id() {
- return license_id;
- }
- public void setLicense_id(int license_id) {
- this.license_id = license_id;
- }
- @Column
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "license")
- public List<Pricelist> getPricelists() {
- return pricelists;
- }
- public void setPricelists(List<Pricelist> pricelists) {
- this.pricelists = pricelists;
- }
- @Override
- public boolean equals(Object o){
- if(o != null && o instanceof License){
- return license_id == ((License) o).getLicense_id();
- }
- return false;
- }
- public String toString(){
- return "" + title;
- }
- @Column
- public Double getPrice() {
- return price;
- }
- public void setPrice(Double price) {
- this.price = price;
- }
- @Override
- public int compareTo(License o) {
- if(o.getLicense_id() == license_id) return 0;
- if(o.getLicense_id() > license_id) return 1;
- return -1;
- }
- @Column
- public String getLicensestate() {
- return licensestate;
- }
- public void setLicensestate(String licensestate) {
- this.licensestate = licensestate;
- }
- }
- LicenseBean
- package net.peopleway.invoicesystem.license;
- import java.io.IOException;
- import java.io.Serializable;
- import javax.annotation.PostConstruct;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.login.UserManager;
- @Named
- @ViewScoped
- public class LicenseBean implements Serializable {
- @Inject
- private UserManager userManager;
- @Inject
- private LicenseService service;
- private License newLicense;
- @PostConstruct
- public void test() throws IOException {
- System.out.println("Init");
- if(!userManager.getUser().isAdministrator()){
- FacesContext.getCurrentInstance().getExternalContext().redirect("/invoicesystem/customers");
- }
- newLicense = new License();
- }
- public void saveLicense() {
- try{
- service.saveLicense(newLicense);
- newLicense = new License();
- }
- catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null,
- new FacesMessage(e.getMessage()));
- }
- }
- public License getNewLicense() {
- return newLicense;
- }
- public void setNewLicense(License newLicense) {
- this.newLicense = newLicense;
- }
- }
- LicenseConverter
- package net.peopleway.invoicesystem.license;
- import javax.enterprise.context.ApplicationScoped;
- import javax.faces.component.UIComponent;
- import javax.faces.context.FacesContext;
- import javax.faces.convert.Converter;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.pricelist.PricelistService;
- import net.peopleway.invoicesystem.product.Product;
- @Named
- @ApplicationScoped
- public class LicenseConverter implements Converter{
- @Inject
- private PricelistService ss;
- @Override
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
- if (value == null) {
- return null;
- }
- for (License c : ss.getLicenses()) {
- if (c.getLicense_id() == Integer.parseInt(value)) {
- return c;
- }
- }
- return null;
- }
- @Override
- public String getAsString(FacesContext context, UIComponent component, Object value) {
- if (value == null)
- return "";
- return Integer.toString(((License) value).getLicense_id());
- }
- }
- LicenseDao
- package net.peopleway.invoicesystem.license;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.faces.view.ViewScoped;
- import javax.inject.Named;
- import org.hibernate.Criteria;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import org.hibernate.criterion.Restrictions;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- @Named
- @ApplicationScoped
- public class LicenseDao {
- public boolean saveLicense(License newLicense) {
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria c = session.createCriteria(License.class);
- c.add(Restrictions.eq("title", newLicense.getTitle()));
- List<License> licenses = c.list();
- if(licenses.size() == 0){
- session.save(newLicense);
- }
- t.commit();
- return licenses.size() == 0;
- }
- }
- LicenseService
- package net.peopleway.invoicesystem.license;
- import java.io.Serializable;
- import java.util.ArrayList;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.pricelist.Pricelist;
- @Named
- @ApplicationScoped
- public class LicenseService implements Serializable{
- @Inject
- private LicenseDao dao;
- public void saveLicense(License newLicense) throws Exception {
- if(newLicense == null){
- throw new Exception("No license is present");
- }
- newLicense.setPricelists(new ArrayList<Pricelist>());
- if(newLicense.getTitle() == null || newLicense.getTitle().trim().length() == 0){
- throw new Exception("License does not contain a title");
- }
- if(!dao.saveLicense(newLicense)){
- throw new Exception("The title "+newLicense.getTitle() + " already exists");
- }
- }
- }
- import net.peopleway.invoicesystem.user.User;
- LoginBean
- package net.peopleway.invoicesystem.login;
- import java.io.Serializable;
- import java.sql.SQLException;
- import java.util.HashMap;
- import java.util.Map;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.user.User;
- import org.apache.commons.lang.StringUtils;
- @Named
- @ViewScoped
- public class LoginBean implements Serializable{
- private static final long serialVersionUID = 2524140245116159619L;
- @Inject UserManager userManager;
- @Inject LoginService loginService;
- private String password;
- private String username;
- private String returnUrl;
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getReturnUrl() {
- return returnUrl;
- }
- public void setReturnUrl(String returnUrl) {
- this.returnUrl = returnUrl;
- }
- public String validateUsernamePassword() throws SQLException, ClassNotFoundException {
- User user = loginService.validate(username, password);
- if (user != null) {
- userManager.setUser(user);
- String token = loginService.storeUserToken(user.getUser_id());
- Map<String, Object> props = new HashMap<>();
- props.put("httpOnly", true);
- props.put("maxAge", 1000 * 10);
- if(StringUtils.isBlank(returnUrl)){
- return "/private/customers.xhtml?faces-redirect=true";
- }
- return returnUrl + "?faces-redirect=true";
- } else {
- FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Incorrect Username and Password","Please enter correct username and Password"));
- }
- return null;
- }
- }
- LoginDao
- package net.peopleway.invoicesystem.login;
- import java.io.Serializable;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.enterprise.context.ApplicationScoped;
- import javax.enterprise.context.Destroyed;
- import javax.enterprise.event.Observes;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.dbproperties.DatabaseConnectionPraktik2016;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.user.User;
- import org.hibernate.Criteria;
- import org.hibernate.SQLQuery;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import org.hibernate.criterion.Restrictions;
- @Named
- @ApplicationScoped
- public class LoginDao implements Serializable{
- private static final long serialVersionUID = -4503635128189222548L;
- @Inject DatabaseConnectionPraktik2016 db = new DatabaseConnectionPraktik2016();
- public void destroy(@Observes @Destroyed(ApplicationScoped.class) Object init) throws SQLException {
- db.close();
- }
- public void destoryUserTokens(Integer id){
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- SQLQuery q = session.createSQLQuery("delete from usertoken where user_id = ?");
- q.setInteger(0, id);
- q.executeUpdate();
- t.commit();
- }
- public User validate(String username, String keyphrase) throws SQLException, ClassNotFoundException{
- User u = null;
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria c = session.createCriteria(User.class);
- c.add(Restrictions.eq("username", username));
- c.add(Restrictions.eq("pass", keyphrase));
- u = (User) c.uniqueResult();
- t.commit();
- return u;
- }
- public User getUserByToken(String token) throws SQLException, ClassNotFoundException{
- User u = null;
- ResultSet rs = null;
- db.open();
- db.prepare("select * from users, userToken where token = ? and userToken.user_id = users.user_id", token);
- rs = db.execute();
- while(rs.next()){
- u = new User();
- u.setName(rs.getString("name"));
- u.setUsername(rs.getString("username"));
- u.setPass(rs.getString("pass"));
- u.setUser_id(rs.getInt("user_id"));
- u.setAdministrator(rs.getBoolean("administrator"));
- }
- return u;
- }
- public void storeUserToken(Integer id, String token) throws SQLException, ClassNotFoundException{
- db.open();
- db.executeUpdate("insert into UserToken values (?,?); SELECT SCOPE_IDENTITY();", token, id);
- }
- }
- LoginFilter
- package net.peopleway.invoicesystem.login;
- import java.io.IOException;
- import java.net.URLEncoder;
- import java.sql.SQLException;
- import javax.inject.Inject;
- import javax.servlet.Filter;
- import javax.servlet.FilterChain;
- import javax.servlet.FilterConfig;
- import javax.servlet.ServletException;
- import javax.servlet.ServletRequest;
- import javax.servlet.ServletResponse;
- import javax.servlet.http.Cookie;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import net.peopleway.invoicesystem.user.User;
- public class LoginFilter implements Filter{
- @Inject UserManager userManager;
- @Inject LoginService loginService;
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- }
- @Override
- public void doFilter(ServletRequest req, ServletResponse res,
- FilterChain chain) throws IOException, ServletException {
- if(userManager.isLoggedIn()){
- chain.doFilter(req, res);
- return;
- }
- HttpServletRequest request = (HttpServletRequest) req;
- HttpServletResponse response = (HttpServletResponse) res;
- String token = getCookie(request, "token");
- User user = null;
- try {
- user = loginService.getUserByToken(token);
- } catch (SQLException | ClassNotFoundException e) {
- e.printStackTrace();
- }
- if (user != null) {
- userManager.setUser(user);
- chain.doFilter(req, res);
- return;
- }
- String s = request.getRequestURI();
- s = s.substring(request.getContextPath().length());
- s = URLEncoder.encode(s, "UTF-8");
- response.sendRedirect(request.getContextPath()+ "/login?returnUrl=" + s);
- }
- @Override
- public void destroy() {
- }
- private String getCookie(HttpServletRequest request, String name){
- Cookie[] cookies = request.getCookies();
- if(cookies != null){
- for(int i = 0; i < cookies.length; i++){
- Cookie cookie = cookies[i];
- if(cookie.getName().equals(name))
- return cookie.getValue();
- }
- }
- return null;
- }
- }
- LoginService
- package net.peopleway.invoicesystem.login;
- import java.io.Serializable;
- import java.security.SecureRandom;
- import java.sql.SQLException;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.user.User;
- import org.apache.commons.codec.binary.Hex;
- @Named
- @ApplicationScoped
- public class LoginService implements Serializable{
- private static final long serialVersionUID = 3065017410480034450L;
- @Inject LoginDao db = new LoginDao();
- public User validate(String username, String keyphrase) throws SQLException, ClassNotFoundException{
- return db.validate(username, keyphrase);
- }
- public User getUserByToken(String token) throws SQLException, ClassNotFoundException{
- return db.getUserByToken(token);
- }
- public String storeUserToken(Integer id) throws SQLException, ClassNotFoundException{
- SecureRandom rnd = new SecureRandom();
- byte bytes[] = new byte[16];
- rnd.nextBytes(bytes);
- String token = Hex.encodeHexString(bytes);
- db.storeUserToken(id, token);
- return token;
- }
- public void destroyUserToken(User user){
- db.destoryUserTokens(user.getUser_id());
- }
- }
- UserManager
- package net.peopleway.invoicesystem.login;
- import java.io.Serializable;
- import javax.enterprise.context.SessionScoped;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.user.User;
- @Named
- @SessionScoped
- public class UserManager implements Serializable {
- private static final long serialVersionUID = 5174712862754337675L;
- private User user;
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
- public boolean isLoggedIn() {
- return user != null;
- }
- }
- package net.peopleway.invoicesystem.pricecalculator;
- PriceCalculatorBean
- package net.peopleway.invoicesystem.pricecalculator;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
- import javax.annotation.PostConstruct;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.index.IndexService;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.pricelist.Pricelist;
- import net.peopleway.invoicesystem.pricelist.PricelistService;
- import net.peopleway.invoicesystem.product.Template;
- import net.peopleway.invoicesystem.subscription.SubscriptionService;
- @Named
- @ViewScoped
- public class PriceCalculatorBean implements Serializable {
- private static final long serialVersionUID = -8282945470947331710L;
- @Inject
- private SubscriptionService ss;
- @Inject
- private PricelistService ps;
- @Inject
- private IndexService is;
- private int expectedParticipants;
- private int employees;
- private int endUsers;
- private int testserver;
- private License license;
- private List<Template> templates;
- private List<PriceCalculatorResult> results;
- private PriceCalculatorResult recommended;
- @PostConstruct
- public void initialize() {
- templates = ss.getTemplates();
- }
- public void calculate() {
- results = new ArrayList<>();
- recommended = null;
- for (Template template : templates) {
- PriceCalculatorResult result = new PriceCalculatorResult();
- Pricelist p = null;
- for(Pricelist list : is.getCurrentLicenses()){
- if(list.getLicense().equals(template.getLicense())){
- p = list;
- break;
- }
- }
- result.setTitle(template.getTitle());
- result.setTemplateId(template.getTemplate_id());
- result.setLicense(template.getLicense());
- result.setExtras(template.getExtras());
- if(result.getLicense().getLicensestate().toLowerCase().equals("enduser")){
- result.setVolume(endUsers);
- }else if(result.getLicense().getLicensestate().toLowerCase().equals("ppu")|| result.getLicense().getLicensestate().toLowerCase().equals("vendor")){
- result.setVolume(expectedParticipants);
- }else if(result.getLicense().getLicensestate().toLowerCase().equals("enterprise")){
- result.setVolume(employees);
- }
- result.calculate(p);
- if (recommended == null || recommended.getTotalPrice() > result.getTotalPrice()) {
- recommended = result;
- }
- results.add(result);
- }
- }
- public int getEndUsers() {
- return endUsers;
- }
- public void setEndUsers(int endUsers) {
- this.endUsers = endUsers;
- }
- public PriceCalculatorResult getRecommended() {
- return recommended;
- }
- public void setRecommended(PriceCalculatorResult recommended) {
- this.recommended = recommended;
- }
- public List<Template> getTemplates() {
- return templates;
- }
- public void setTemplates(List<Template> templates) {
- this.templates = templates;
- }
- public License getLicense() {
- return license;
- }
- public void setLicense(License license) {
- this.license = license;
- }
- public int getExpectedParticipants() {
- return expectedParticipants;
- }
- public void setExpectedParticipants(int expectedParticipants) {
- this.expectedParticipants = expectedParticipants;
- }
- public int getEmployees() {
- return employees;
- }
- public void setEmployees(int employees) {
- this.employees = employees;
- }
- public int getTestserver() {
- return testserver;
- }
- public void setTestserver(int testserver) {
- this.testserver = testserver;
- }
- public List<PriceCalculatorResult> getResults() {
- return results;
- }
- public SubscriptionService getSs() {
- return ss;
- }
- public void setSs(SubscriptionService ss) {
- this.ss = ss;
- }
- public PricelistService getPs() {
- return ps;
- }
- public void setPs(PricelistService ps) {
- this.ps = ps;
- }
- public IndexService getIs() {
- return is;
- }
- public void setIs(IndexService is) {
- this.is = is;
- }
- }
- PriceCalculatorResult
- package net.peopleway.invoicesystem.pricecalculator;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import net.peopleway.invoicesystem.extra.Extra;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.pricelist.Interval;
- import net.peopleway.invoicesystem.pricelist.Pricelist;
- public class PriceCalculatorResult {
- private Integer templateId;
- private License license;
- private Integer volume;
- private List<Extra> extras = new ArrayList<>();
- private String title;
- private Double licensePrice = 0.0;
- private Double usagePrice = 0.0;
- private Double extrasPrice = 0.0;
- private Double totalPrice = 0.0;
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public void setTemplateId(Integer templateId) {
- this.templateId = templateId;
- }
- public void setLicense(License license) {
- this.license = license;
- }
- public License getLicense() {
- return license;
- }
- public List<Extra> getExtras() {
- return extras;
- }
- public void setExtras(List<Extra> extras) {
- this.extras = extras;
- }
- public void setVolume(Integer volume) {
- this.volume = volume;
- }
- public Double getLicensePrice() {
- return licensePrice;
- }
- public Double getUsagePrice() {
- return usagePrice;
- }
- public Double getExtrasPrice() {
- return extrasPrice;
- }
- public Double getTotalPrice() {
- return totalPrice;
- }
- public void calculate(Pricelist list) {
- licensePrice = license.getPrice();
- usagePrice = 0.0;
- if(list.getLicense().getLicensestate().toLowerCase().equals("enterprise")){
- if(volume <= 420){
- usagePrice += list.getIntervals().get(0).getPrice() * 420;
- totalPrice = licensePrice + extrasPrice + usagePrice;
- return;
- }
- }
- for(Interval interval : list.getIntervals()){
- Integer from = interval.getFromInterval();
- Integer to = interval.getToInterval();
- Double price = interval.getPrice();
- if(volume > to) {
- usagePrice += (to - from + 1) * price;
- }
- else if(volume >= from) {
- usagePrice += (volume - from + 1) * price;
- }
- }
- extrasPrice = 0.0;
- if(extras != null) {
- for(Extra extra : extras) {
- extrasPrice += extra.getPrice();
- }
- }
- totalPrice = licensePrice + usagePrice + extrasPrice;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((templateId == null) ? 0 : templateId.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- PriceCalculatorResult other = (PriceCalculatorResult) obj;
- if (templateId == null) {
- if (other.templateId != null)
- return false;
- } else if (!templateId.equals(other.templateId))
- return false;
- return true;
- }
- }
- package net.peopleway.invoicesystem.pricelist;
- Interval
- package net.peopleway.invoicesystem.pricelist;
- import java.io.Serializable;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.Table;
- @Entity
- @Table(name = "intervals")
- public class Interval implements Serializable {
- private static final long serialVersionUID = -4187575836573185736L;
- private Integer intervals_id;
- private Integer fromInterval, toInterval;
- private Double price;
- @Column
- @Id
- @GeneratedValue
- public Integer getIntervals_id() {
- return intervals_id;
- }
- public void setIntervals_id(Integer intervals_id) {
- this.intervals_id = intervals_id;
- }
- @Column
- public Integer getFromInterval() {
- return fromInterval;
- }
- public void setFromInterval(Integer fromInterval) {
- this.fromInterval = fromInterval;
- }
- @Column
- public Integer getToInterval() {
- return toInterval;
- }
- public void setToInterval(Integer toInterval) {
- this.toInterval = toInterval;
- }
- @Column
- public Double getPrice() {
- return price;
- }
- public void setPrice(Double price) {
- this.price = price;
- }
- @Override
- public boolean equals(Object o){
- if(o != null && o instanceof Interval){
- if(intervals_id == ((Interval)o).getIntervals_id()){
- return true;
- }
- }
- return false;
- }
- }
- ListBean
- package net.peopleway.invoicesystem.pricelist;
- import java.io.IOException;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
- import javax.annotation.PostConstruct;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.login.UserManager;
- @Named
- @ViewScoped
- public class ListBean implements Serializable {
- private static final long serialVersionUID = 4995482822989124736L;
- @Inject
- private PricelistService service;
- @Inject private UserManager userManager;
- private List<License> licenses;
- private Pricelist list;
- @PostConstruct
- public void test() throws IOException {
- if(!userManager.getUser().isAdministrator()){
- FacesContext.getCurrentInstance().getExternalContext().redirect("/invoicesystem/customers");
- }else{
- list = new Pricelist();
- list.setIntervals(new ArrayList<Interval>());
- add();
- licenses = service.getLicenses();
- }
- }
- public List<License> getLicenses() {
- return licenses;
- }
- public Pricelist getList() {
- return list;
- }
- public List<Interval> getIntervals() {
- return list.getIntervals();
- }
- public Integer getSize() {
- return list.getIntervals().size();
- }
- public void add() {
- List<Interval> intervals = list.getIntervals();
- Interval interval = new Interval();
- Integer from = 1;
- if(!intervals.isEmpty()) {
- from = intervals.get(intervals.size() - 1).getFromInterval();
- from = (from != null ? from + 100 : null);
- }
- interval.setFromInterval(from);
- list.getIntervals().add(interval);
- }
- public void remove(Interval interval) {
- list.getIntervals().remove(interval);
- }
- public void save() {
- System.out.println(list.getStartdate());
- try {
- service.savePricelist(list);
- } catch (Exception e) {
- e.printStackTrace();
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- }
- }
- Pricelist
- package net.peopleway.invoicesystem.pricelist;
- import java.io.Serializable;
- import java.util.Date;
- import java.util.List;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.EnumType;
- import javax.persistence.Enumerated;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- import org.hibernate.annotations.LazyCollection;
- import org.hibernate.annotations.LazyCollectionOption;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.subscription.State;
- @Entity
- @Table(name = "pricelist")
- public class Pricelist implements Serializable {
- private int pricelist_id;
- private String title;
- private Date startdate, enddate;
- private List<Interval> intervals;
- private License license;
- @Id
- @GeneratedValue
- @Column
- public int getPricelist_id() {
- return pricelist_id;
- }
- public void setPricelist_id(int pricelist_id) {
- this.pricelist_id = pricelist_id;
- }
- @Column
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- @Column
- public Date getStartdate() {
- return startdate;
- }
- public void setStartdate(Date startdate) {
- this.startdate = startdate;
- }
- @Column
- public Date getEnddate() {
- return enddate;
- }
- public void setEnddate(Date enddate) {
- this.enddate = enddate;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @OneToMany(cascade = CascadeType.ALL)
- @JoinColumn(name = "pricelist_id")
- public List<Interval> getIntervals() {
- return intervals;
- }
- public void setIntervals(List<Interval> intervals) {
- this.intervals = intervals;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @ManyToOne
- @JoinColumn(name = "license_id")
- public License getLicense() {
- return license;
- }
- public void setLicense(License license) {
- this.license = license;
- }
- @Override
- public boolean equals(Object o) {
- if (o != null && o instanceof Pricelist) {
- if (((Pricelist) o).getPricelist_id() == pricelist_id) {
- return true;
- }
- }
- return false;
- }
- }
- PricelistDao
- package net.peopleway.invoicesystem.pricelist;
- import java.io.Serializable;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.product.Product;
- import net.peopleway.invoicesystem.subscription.Subscription;
- import org.hibernate.Criteria;
- import org.hibernate.Hibernate;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import org.hibernate.criterion.Restrictions;
- @Named
- @ApplicationScoped
- public class PricelistDao implements Serializable {
- private static PricelistDao dao;
- public List<License> getLicenses() {
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- Criteria c = session.createCriteria(License.class);
- List<License> licenses = c.list();
- t.commit();
- return licenses;
- }
- public void savePriceList(Pricelist newPricelist) {
- Session session = (Session) DatabaseSessionFactory.getSession();
- Transaction t = session.beginTransaction();
- session.save(newPricelist);
- t.commit();
- }
- }
- PricelistService
- package net.peopleway.invoicesystem.pricelist;
- import java.io.Serializable;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- import javax.enterprise.context.ApplicationScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.license.License;
- @Named
- @ApplicationScoped
- public class PricelistService implements Serializable {
- @Inject
- private PricelistDao dao;
- public List<License> getLicenses() {
- return dao.getLicenses();
- }
- public void savePricelist(Pricelist newPricelist) throws Exception {
- if (newPricelist != null) {
- List<Interval> intervals = newPricelist.getIntervals();
- Interval prev = null;
- if(intervals.get(0).getFromInterval() != 1) {
- throw new RuntimeException("First interval must start from 1!");
- }
- int start = 0;
- for(Interval interval : newPricelist.getIntervals()) {
- if(1 >= interval.getFromInterval()){
- throw new Exception("The value cannot be less than 1");
- }
- if(start >= interval.getFromInterval()){
- throw new Exception("There is intervals with a start value that is lower or equal to the previos intervals start value: "+start);
- }
- start = interval.getFromInterval();
- if(interval.getPrice() == null) {
- throw new RuntimeException("There intervals with empty price!");
- }
- if(interval.getFromInterval() == null) {
- throw new RuntimeException("There empty intervals!");
- }
- if(prev != null && interval.getFromInterval() < prev.getFromInterval()) {
- throw new RuntimeException("There are overlapping intervals!");
- }
- if(prev != null) {
- prev.setToInterval(interval.getFromInterval() - 1);
- }
- prev = interval;
- }
- intervals.get(intervals.size() - 1).setToInterval(Integer.MAX_VALUE);
- dao.savePriceList(newPricelist);
- }
- }
- public PricelistDao getDao() {
- return dao;
- }
- public void setDao(PricelistDao dao) {
- this.dao = dao;
- }
- }
- product
- package net.peopleway.invoicesystem.product;
- import java.io.Serializable;
- import java.util.Date;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.EnumType;
- import javax.persistence.Enumerated;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.OneToOne;
- import javax.persistence.Table;
- import org.hibernate.annotations.LazyCollection;
- import org.hibernate.annotations.LazyCollectionOption;
- import net.peopleway.invoicesystem.extra.Extra;
- import net.peopleway.invoicesystem.invoice.InvoiceInterval;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.subscription.Subscription;
- @Entity
- @Table(name="product")
- public class Product implements Serializable, Comparable<Product>{
- private static final long serialVersionUID = 1L;
- private int product_id;
- private Subscription subscription;
- private Double discount;
- private Date startDate, endDate, resignationDate, indexFreeze;
- private InvoiceInterval periodInterval;
- private Double price;
- private License license;
- private Extra extra;
- public Product() {
- }
- @Id
- @GeneratedValue
- @Column
- public int getProduct_id() {
- return product_id;
- }
- public void setProduct_id(int product_id) {
- this.product_id = product_id;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @ManyToOne(optional = false, cascade=CascadeType.ALL)
- @JoinColumn(name = "subscription_id")
- public Subscription getSubscription() {
- return subscription;
- }
- public void setSubscription(Subscription subscription) {
- this.subscription = subscription;
- }
- @Column
- public Date getStartDate() {
- return startDate;
- }
- public void setStartDate(Date startDate) {
- this.startDate = startDate;
- }
- @Column
- public Date getEndDate() {
- return endDate;
- }
- public void setEndDate(Date endDate) {
- this.endDate = endDate;
- }
- @Column
- public Date getResignationDate() {
- return resignationDate;
- }
- public void setResignationDate(Date resignationDate) {
- this.resignationDate = resignationDate;
- }
- @Enumerated(EnumType.STRING)
- public InvoiceInterval getPeriodInterval() {
- return periodInterval;
- }
- public void setPeriodInterval(InvoiceInterval periodInterval) {
- this.periodInterval = periodInterval;
- }
- @Override
- public String toString() {
- if(license != null){
- return license.getTitle();
- }
- else if(extra != null){
- return extra.getTitle();
- }
- else{
- return "No License or Extra";
- }
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Product other = (Product) obj;
- if (product_id != other.product_id)
- return false;
- return true;
- }
- @Override
- public int compareTo(Product o) {
- if(this.product_id == o.getProduct_id()){
- return 0;
- }
- else if(this.product_id > o.getProduct_id()){
- return 1;
- }
- else{
- return -1;
- }
- }
- @Column
- public Double getPrice() {
- return price;
- }
- public void setPrice(Double price) {
- this.price = price;
- }
- @Column
- public Double getDiscount() {
- return discount;
- }
- public void setDiscount(Double discount) {
- this.discount = discount;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @OneToOne
- @JoinColumn(name = "license_id", nullable= true)
- public License getLicense() {
- return license;
- }
- public void setLicense(License license) {
- this.license = license;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @OneToOne
- @JoinColumn(name = "extra_id", nullable = true)
- public Extra getExtra() {
- return extra;
- }
- public void setExtra(Extra extra) {
- this.extra = extra;
- }
- @Column
- public Date getIndexFreeze() {
- return indexFreeze;
- }
- public void setIndexFreeze(Date indexFreeze) {
- this.indexFreeze = indexFreeze;
- }
- }
- ProductBean
- package net.peopleway.invoicesystem.product;
- import java.io.IOException;
- import java.io.Serializable;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.customer.Customer;
- import net.peopleway.invoicesystem.customer.CustomerService;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.login.LoginService;
- import net.peopleway.invoicesystem.login.UserManager;
- import net.peopleway.invoicesystem.subscription.Subscription;
- import net.peopleway.invoicesystem.subscription.SubscriptionService;
- @Named
- @ViewScoped
- public class ProductBean implements Serializable{
- @Inject private SubscriptionService ss;
- @Inject private UserManager userManager;
- @Inject private LoginService loginService;
- @Inject private CustomerService customerService;
- private List<Subscription> subscriptions = new ArrayList<Subscription>();
- private List<Product> products;
- private List<License> licenses;
- private Subscription selectedSubscription;
- private Customer selectedCustomer;
- private Product selectedProduct;
- private License selectedLicense;
- private boolean subDetails;
- private boolean productDetails;
- private boolean createProduct;
- private boolean editProductSave;
- private boolean productgroup;
- private boolean addButton;
- private Product newProduct;
- public void logout() throws IOException{
- loginService.destroyUserToken(userManager.getUser());
- userManager.setUser(null);
- FacesContext.getCurrentInstance().getExternalContext().redirect("/invoicesystem/login");
- }
- public void renderSubDetails(){
- if(selectedCustomer != null && selectedSubscription != null){
- subDetails = true;
- products = selectedSubscription.getProducts();
- }else{
- subDetails = false;
- }
- }
- public void renderProductDetails(){
- if(selectedProduct != null){
- newProduct = selectedProduct;
- createProduct = false;
- productDetails = true;
- }else{
- productDetails = false;
- editProductSave = false;
- productgroup = false;
- }
- addButton = false;
- }
- public void addProduct(){
- newProduct = new Product();
- productDetails = true;
- createProduct = true;
- addButton = true;
- productgroup = false;
- editProductSave = false;
- }
- public void createNewProduct() throws Exception{
- if(!selectedSubscription.getSubstate().toString().toLowerCase().equals("active")){
- if(newProduct.getDiscount() != null && newProduct.getLicense() != null && newProduct.getPrice() != null){
- ss.createNewProduct(newProduct, selectedSubscription);
- }else{
- FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Fill out all blanks","Fill out all blanks"));
- }
- }else{
- FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_WARN,"Cannot add product to active subscription","Cannot add product to active subscription"));
- }
- }
- public void deleteProduct(){
- if(selectedProduct != null && !selectedSubscription.toString().toLowerCase().equals("active")){
- ss.deleteLicenseSubscription(selectedProduct);
- products = ss.getProductsSub(selectedSubscription);
- productDetails = false;
- }
- }
- public void editProduct(){
- if(selectedProduct != null){
- newProduct = selectedProduct;
- editProductSave = true;
- createProduct = true;
- addButton = false;
- selectedLicense = newProduct.getLicense();
- }
- }
- public void editOldProduct(){
- if(selectedProduct != null)
- ss.editProduct(newProduct);
- }
- public boolean isAddButton() {
- return addButton;
- }
- public void setAddButton(boolean addButton) {
- this.addButton = addButton;
- }
- public boolean isProductgroup() {
- return productgroup;
- }
- public void setProductgroup(boolean productgroup) {
- this.productgroup = productgroup;
- }
- public boolean isEditProductSave() {
- return editProductSave;
- }
- public void setEditProductSave(boolean editProductSave) {
- this.editProductSave = editProductSave;
- }
- public Product getNewProduct() {
- return newProduct;
- }
- public void setNewProduct(Product newProduct) {
- this.newProduct = newProduct;
- }
- public boolean isCreateProduct() {
- return createProduct;
- }
- public void setCreateProduct(boolean createProduct) {
- this.createProduct = createProduct;
- }
- public boolean isProductDetails() {
- return productDetails;
- }
- public void setProductDetails(boolean productDetails) {
- this.productDetails = productDetails;
- }
- public boolean isSubDetails() {
- return subDetails;
- }
- public void setSubDetails(boolean subDetails) {
- this.subDetails = subDetails;
- }
- public List<Product> getProducts() {
- return products;
- }
- public void setProducts(List<Product> products) {
- this.products = products;
- }
- public Product getSelectedProduct() {
- return selectedProduct;
- }
- public void setSelectedProduct(Product selectedProduct) {
- this.selectedProduct = selectedProduct;
- }
- public Customer getSelectedCustomer() {
- return selectedCustomer;
- }
- public void setSelectedCustomer(Customer selectedCustomer) {
- this.selectedCustomer = selectedCustomer;
- }
- public List<Subscription> getSubscriptions() {
- return subscriptions;
- }
- public void setSubscriptions(List<Subscription> subscriptions) {
- this.subscriptions = subscriptions;
- }
- public Subscription getSelectedSubscription() {
- return selectedSubscription;
- }
- public void setSelectedSubscription(Subscription selectedSubscription) {
- this.selectedSubscription = selectedSubscription;
- }
- public void load() throws IOException, ClassNotFoundException, SQLException{
- if(selectedCustomer != null){
- subscriptions = ss.getCustSubs(selectedCustomer);
- }else{
- for(Customer c : customerService.getCustomers()){
- if(c.getUser().equals(userManager.getUser())){
- selectedCustomer = c;
- subscriptions.addAll(ss.getCustSubs(c));
- }else{
- FacesContext.getCurrentInstance().getExternalContext().redirect("/invoicesystem/consultant");
- }
- }
- }
- licenses = ss.getLicenses();
- }
- }
- ProductConverter
- package net.peopleway.invoicesystem.product;
- import javax.enterprise.context.ApplicationScoped;
- import javax.faces.component.UIComponent;
- import javax.faces.context.FacesContext;
- import javax.faces.convert.Converter;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.subscription.SubscriptionService;
- @Named
- @ApplicationScoped
- public class ProductConverter implements Converter{
- @Inject
- private SubscriptionService ss;
- @Override
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
- if (value == null) {
- return null;
- }
- for (Product c : ss.getProducts()) {
- if (c.getProduct_id()== Integer.parseInt(value)) {
- return c;
- }
- }
- return null;
- }
- @Override
- public String getAsString(FacesContext context, UIComponent component, Object value) {
- if (value == null)
- return "";
- return Integer.toString(((Product) value).getProduct_id());
- }
- }
- Template
- package net.peopleway.invoicesystem.product;
- import java.util.List;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.JoinTable;
- import javax.persistence.ManyToMany;
- import javax.persistence.ManyToOne;
- import javax.persistence.Table;
- import net.peopleway.invoicesystem.extra.Extra;
- import net.peopleway.invoicesystem.license.License;
- import org.hibernate.annotations.LazyCollection;
- import org.hibernate.annotations.LazyCollectionOption;
- @Entity
- @Table(name="template")
- public class Template {
- private int template_id;
- private String title;
- private License license;
- private List<Extra> extras;
- @Id
- @GeneratedValue
- @Column
- public int getTemplate_id() {
- return template_id;
- }
- public void setTemplate_id(int template_id) {
- this.template_id = template_id;
- }
- @Column
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @ManyToOne
- @JoinColumn(name = "license_id")
- public License getLicense() {
- return license;
- }
- public void setLicense(License license) {
- this.license = license;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @ManyToMany(cascade= CascadeType.ALL)
- @JoinTable(name = "templateExtras", joinColumns = @JoinColumn(name = "template_id"))
- public List<Extra> getExtras() {
- return extras;
- }
- public void setExtras(List<Extra> extras) {
- this.extras = extras;
- }
- }
- package net.peopleway.invoicesystem.rewrite;
- ConfigurationProvider
- package net.peopleway.invoicesystem.rewrite;
- import javax.servlet.ServletContext;
- import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
- import org.ocpsoft.rewrite.config.Configuration;
- import org.ocpsoft.rewrite.config.ConfigurationBuilder;
- import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
- import org.ocpsoft.rewrite.servlet.config.rule.Join;
- @RewriteConfiguration
- public class ConfigurationProvider extends HttpConfigurationProvider {
- @Override
- public int priority() {
- return 10;
- }
- @Override
- public Configuration getConfiguration(final ServletContext context) {
- return ConfigurationBuilder.begin()
- .addRule(Join.path("/login").to("/public/login.xhtml"))
- .addRule(Join.path("/subscriptionmanagement").to("/private/SubStart.xhtml"))
- .addRule(Join.path("/subscription").to("/private/subscription.xhtml"))
- .addRule(Join.path("/customers").to("/private/customers.xhtml"))
- .addRule(Join.path("/customer").to("/private/customer.xhtml"))
- .addRule(Join.path("/users").to("/private/adminUserManagement.xhtml"))
- .addRule(Join.path("/newLicense").to("/private/licenseNew.xhtml"))
- .addRule(Join.path("/newExtra").to("/private/extraNew.xhtml"))
- .addRule(Join.path("/newPricelist").to("/private/pricelistNew.xhtml"))
- .addRule(Join.path("/priceCalculator").to("/private/priceCalculator.xhtml"))
- .addRule(Join.path("/updatePrices").to("/private/pricesUpdateIndex.xhtml"));
- }
- }
- package net.peopleway.invoicesystem.server;
- InvoiceThread
- package net.peopleway.invoicesystem.server;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
- import java.util.TimeZone;
- import java.util.TreeMap;
- import net.peopleway.invoicesystem.product.Product;
- import net.peopleway.invoicesystem.utilities.DateUtilities;
- public class InvoiceThread extends Thread {
- private TreeMap<Date, List<Product>> invoices;
- public InvoiceThread(){
- invoices = new TreeMap<Date, List<Product>>();
- }
- public void run(){
- boolean run = true;
- while(run){
- long sleepTime = DateUtilities.timeUntilNextWakeUp(new Date());
- try {
- Thread.sleep(sleepTime);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- public void startUp(){
- this.start();
- }
- public static void main(String[] args) {
- InvoiceThread thread = new InvoiceThread();
- thread.startUp();
- }
- }
- package net.peopleway.invoicesystem.serverstartup;
- InvoiceStartUpListener
- package net.peopleway.invoicesystem.serverstartup;
- import javax.servlet.ServletContextEvent;
- import javax.servlet.ServletContextListener;
- import net.peopleway.invoicesystem.hibernate.DatabaseSessionFactory;
- import net.peopleway.invoicesystem.server.InvoiceThread;
- public class InvoiceStartUpListener implements ServletContextListener{
- @Override
- public void contextDestroyed(ServletContextEvent arg0) {
- }
- @Override
- public void contextInitialized(ServletContextEvent arg0) {
- DatabaseSessionFactory.configure();
- InvoiceThread thread = new InvoiceThread();
- thread.startUp();
- }
- }
- package net.peopleway.invoicesystem.subscription;
- NewSubscriptionBean
- package net.peopleway.invoicesystem.subscription;
- import java.io.IOException;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.faces.application.FacesMessage;
- import javax.faces.context.FacesContext;
- import javax.faces.view.ViewScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import net.peopleway.invoicesystem.customer.Customer;
- import net.peopleway.invoicesystem.customer.CustomerService;
- import net.peopleway.invoicesystem.extra.Extra;
- import net.peopleway.invoicesystem.extra.ExtraService;
- import net.peopleway.invoicesystem.invoice.InvoiceInterval;
- import net.peopleway.invoicesystem.license.License;
- import net.peopleway.invoicesystem.login.UserManager;
- import net.peopleway.invoicesystem.product.Product;
- import org.omnifaces.util.Faces;
- @Named
- @ViewScoped
- public class NewSubscriptionBean implements Serializable{
- private static final long serialVersionUID = 8327353921900478821L;
- private String name;
- private List<Product> products;
- private Customer customer;
- private int dateInterval;
- private State substate;
- private Date creationdate;
- private Date indexFreeze;
- private InvoiceInterval paymentDelay;
- private int id;
- private int customerId;
- private Product selectedProduct;
- private License selectedLicense;
- private List<License> availableLicenses;
- private List<String> periodintervals = new ArrayList<String>();
- private List<String> periodintervalsProduct = new ArrayList<String>();
- private List<Extra> availableExtras = new ArrayList<Extra>();
- private Extra selectedExtra;
- private String selectedTitle;
- private Double discount;
- private Date resignationDate;
- private Date startDate;
- private String periodInterval;
- private String periodIntervalSub;
- private Double price;
- private Subscription s;
- private String deleteSubString;
- private boolean viewProduct;
- private boolean newSub;
- private Product newProduct;
- private boolean editing;
- @Inject private SubscriptionService ss;
- @Inject private CustomerService cs;
- @Inject private UserManager userManager;
- @Inject private ExtraService es;
- public void load() throws IOException {
- if(customerId != 0 && id == 0 && checkcustomerid() == true){
- products = new ArrayList<Product>();
- customer = cs.getCustomerById(customerId);
- s = new Subscription();
- newSub = true;
- periodIntervalSub = "None";
- deleteSubString = "Cancel";
- }else if(id != 0 && checksubscriptionid() == true){
- Subscription sub = ss.getSubscriptionById(id);
- customer = sub.getCustomer();
- dateInterval = sub.getDateInterval();
- substate = sub.getSubstate();
- creationdate = sub.getCreationDate();
- paymentDelay = sub.getPaymentDelay();
- name = sub.getName();
- products = sub.getProducts();
- newSub = false;
- deleteSubString ="Delete subscription";
- }else{
- Faces.redirect("customers");
- }
- availableLicenses = ss.getLicenses();
- availableExtras = es.getExtras();
- periodintervals.add("None");
- periodintervals.add("Days");
- periodintervals.add("Weeks");
- periodintervals.add("Months");
- periodintervals.add("Years");
- periodintervals.add("Quarters");
- periodintervalsProduct.add("Daily");
- periodintervalsProduct.add("Weekly");
- periodintervalsProduct.add("Monthly");
- periodintervalsProduct.add("Quarterly");
- periodintervalsProduct.add("Yearly");
- editing = false;
- }
- public String back(){
- return "customers.xhtml?faces-redirect=true";
- }
- public void deleteProduct(){
- if(id != 0){
- ss.deleteLicenseSubscription(selectedProduct);
- products = ss.getSubscriptionById(id).getProducts();
- }else{
- products.remove(selectedProduct);
- }
- }
- public boolean checkcustomerid(){
- for(Customer c : cs.getCustomersUser(userManager.getUser())){
- if(c.getCustomer_id() == customerId){
- return true;
- }
- }
- return false;
- }
- public boolean checksubscriptionid(){
- for(Customer c : cs.getCustomersUser(userManager.getUser())){
- for(Subscription s : c.getSubscriptions()){
- if(s.getSubscription_id() == id){
- return true;
- }
- }
- }
- return false;
- }
- public void createSubscription() throws Exception{
- if(!name.isEmpty()){
- //TODO relog side med nye sub id?
- s.setCustomer(customer);
- s.setName(name);
- s.setCreationDate(new Date());
- s.setPaymentDelay(checkInterval(periodIntervalSub));
- s.setDateInterval(dateInterval);
- ss.createSub(s);
- for(Product p : products){
- ss.createNewProduct(p, s);
- }
- deleteSubString = "Delete Subscription";
- Faces.redirect("customers");
- }
- else{
- FacesContext.getCurrentInstance().addMessage("subname",new FacesMessage(FacesMessage.SEVERITY_WARN,"Name is required","Name is required"));
- }
- }
- public void viewProduct(){
- viewProduct = true;
- price = selectedProduct.getPrice();
- discount = selectedProduct.getDiscount();
- startDate = selectedProduct.getStartDate();
- resignationDate = selectedProduct.getResignationDate();
- periodInterval = selectedProduct.getPeriodInterval().toString();
- }
- // public void edit() {
- // editing = true;
- // selectedGroupProduct = selectedProduct.getGroupProduct();
- // selectedTitle = selectedProduct.getTitle();
- // discount = selectedProduct.getDiscount();
- // resignationDate = selectedProduct.getResignationDate();
- // startDate = selectedProduct.getStartDate();
- // periodInterval = selectedProduct.getPeriodInterval().toString();
- // }
- public void newProduct(){
- viewProduct = false;
- price = 0.0;
- discount = 0.0;
- editing = false;
- selectedLicense = null;
- selectedExtra = null;
- selectedTitle = null;
- discount = null;
- resignationDate = null;
- startDate = null;
- periodInterval = null;
- }
- public void addProduct() throws Exception{
- newProduct = new Product();
- Double d = 0.0;
- if(discount == null){
- discount = 0.0;
- }
- try{
- newProduct.setDiscount(discount);
- if(selectedExtra != null && selectedLicense == null){
- d = selectedExtra.getPrice() - (selectedExtra.getPrice() * (discount/100));
- newProduct.setExtra(selectedExtra);
- } else if(selectedLicense != null && selectedExtra == null){
- d = selectedLicense.getPrice() - (selectedLicense.getPrice() * (discount/100));
- newProduct.setLicense(selectedLicense);
- }else if((selectedLicense != null && selectedExtra != null)|| (selectedLicense == null && selectedExtra == null)){
- throw new Exception("Must choose between license or extra");
- }
- }
- catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- return;
- }
- newProduct.setPrice((double) Math.round(d));
- newProduct.setPeriodInterval(productinterval(periodInterval));
- newProduct.setResignationDate(resignationDate);
- newProduct.setStartDate(startDate);
- newProduct.setIndexFreeze(indexFreeze);
- if(id != 0){
- try{
- ss.createNewProduct(newProduct, ss.getSubscriptionById(id));
- products.add(newProduct);
- }
- catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(e.getMessage()));
- }
- }else{
- try{
- if(newProduct.getStartDate() == null || newProduct.getResignationDate() == null){
- throw new Exception("Can't create a product without start and resignation date");
- }
- products.add(newProduct);
- }
- catch(Exception e){
- FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
- }
- }
- }
- // Save er edit
- // public void saveProduct() throws IOException {
- // Product p = new Product();
- // p.setGroupProduct(selectedGroupProduct);
- // p.setSubscription(selectedProduct.getSubscription());
- // p.setTitle(selectedTitle);
- // p.setPrice(price);
- // p.setDiscount(discount);
- // p.setResignationDate(resignationDate);
- // p.setStartDate(startDate);
- // p.setPeriodInterval(checkInterval(periodInterval));
- // p.setSubscription(s);
- // p.setProduct_id(selectedProduct.getProduct_id());
- // ss.editProduct(p);
- // load();
- // editing = false;
- // }
- public InvoiceInterval checkInterval(String s){
- if (s.toLowerCase().equals("days")) {
- return InvoiceInterval.Daily;
- } else if (s.toLowerCase().equals("weeks")) {
- return InvoiceInterval.Weekly;
- } else if (s.toLowerCase().equals("months")) {
- return InvoiceInterval.Monthly;
- } else if (s.toLowerCase().equals("years")) {
- return InvoiceInterval.Yearly;
- } else if (s.toLowerCase().equals("quarters")) {
- return InvoiceInterval.Quarterly;
- }
- return null;
- }
- public InvoiceInterval productinterval(String s){
- if (s.toLowerCase().equals("daily")) {
- return InvoiceInterval.Daily;
- } else if (s.toLowerCase().equals("weekly")) {
- return InvoiceInterval.Weekly;
- } else if (s.toLowerCase().equals("monthly")) {
- return InvoiceInterval.Monthly;
- } else if (s.toLowerCase().equals("yearly")) {
- return InvoiceInterval.Yearly;
- } else if (s.toLowerCase().equals("quarterly")) {
- return InvoiceInterval.Quarterly;
- }
- return null;
- }
- public List<Extra> getAvailableExtras() {
- return availableExtras;
- }
- public void setAvailableExtras(List<Extra> availableExtras) {
- this.availableExtras = availableExtras;
- }
- public Extra getSelectedExtra() {
- return selectedExtra;
- }
- public void setSelectedExtra(Extra selectedExtra) {
- this.selectedExtra = selectedExtra;
- }
- public boolean isViewProduct() {
- return viewProduct;
- }
- public void setViewProduct(boolean viewProduct) {
- this.viewProduct = viewProduct;
- }
- public List<String> getPeriodintervalsProduct() {
- return periodintervalsProduct;
- }
- public void setPeriodintervalsProduct(List<String> periodintervalsProduct) {
- this.periodintervalsProduct = periodintervalsProduct;
- }
- public String getDeleteSubString() {
- return deleteSubString;
- }
- public void setDeleteSubString(String deleteSubString) {
- this.deleteSubString = deleteSubString;
- }
- public boolean isEditing() {
- return editing;
- }
- public void setEditing(boolean editing) {
- this.editing = editing;
- }
- public Product getNewProduct() {
- return newProduct;
- }
- public void setNewProduct(Product newProduct) {
- this.newProduct = newProduct;
- }
- public int getCustomerId() {
- return customerId;
- }
- public void setCustomerId(int customerId) {
- this.customerId = customerId;
- }
- public String getPeriodIntervalSub() {
- return periodIntervalSub;
- }
- public void setPeriodIntervalSub(String periodIntervalSub) {
- this.periodIntervalSub = periodIntervalSub;
- }
- public boolean isNewSub() {
- return newSub;
- }
- public void setNewSub(boolean newSub) {
- this.newSub = newSub;
- }
- public List<String> getPeriodintervals() {
- return periodintervals;
- }
- public void setPeriodintervals(List<String> periodintervals) {
- this.periodintervals = periodintervals;
- }
- public Double getPrice() {
- return price;
- }
- public void setPrice(Double price) {
- this.price = price;
- }
- public String getSelectedTitle() {
- return selectedTitle;
- }
- public void setSelectedTitle(String selectedTitle) {
- this.selectedTitle = selectedTitle;
- }
- public Double getDiscount() {
- return discount;
- }
- public void setDiscount(Double discount) {
- this.discount = discount;
- }
- public Date getResignationDate() {
- return resignationDate;
- }
- public void setResignationDate(Date resignationDate) {
- this.resignationDate = resignationDate;
- }
- public Date getStartDate() {
- return startDate;
- }
- public void setStartDate(Date startDate) {
- this.startDate = startDate;
- }
- public String getPeriodInterval() {
- return periodInterval;
- }
- public void setPeriodInterval(String periodInterval) {
- this.periodInterval = periodInterval;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public List<Product> getProducts() {
- return products;
- }
- public void setProducts(List<Product> products) {
- this.products = products;
- }
- public Customer getCustomer() {
- return customer;
- }
- public void setCustomer(Customer customer) {
- this.customer = customer;
- }
- public int getDateInterval() {
- return dateInterval;
- }
- public void setDateInterval(int dateInterval) {
- this.dateInterval = dateInterval;
- }
- public State getSubstate() {
- return substate;
- }
- public void setSubstate(State substate) {
- this.substate = substate;
- }
- public Date getCreationdate() {
- return creationdate;
- }
- public void setCreationdate(Date creationdate) {
- this.creationdate = creationdate;
- }
- public Date getIndexFreeze() {
- return indexFreeze;
- }
- public void setIndexFreeze(Date indexFreeze) {
- this.indexFreeze = indexFreeze;
- }
- public InvoiceInterval getPaymentDelay() {
- return paymentDelay;
- }
- public void setPaymentDelay(InvoiceInterval paymentDelay) {
- this.paymentDelay = paymentDelay;
- }
- public Product getSelectedProduct() {
- return selectedProduct;
- }
- public void setSelectedProduct(Product selectedProduct) {
- this.selectedProduct = selectedProduct;
- }
- public License getSelectedLicense() {
- return selectedLicense;
- }
- public void setSelectedLicense(License selectedLicense) {
- this.selectedLicense = selectedLicense;
- }
- public List<License> getAvailableLicenses() {
- return availableLicenses;
- }
- public void setAvailableLicenses(List<License> availableLicenses) {
- this.availableLicenses = availableLicenses;
- }
- }
- State
- package net.peopleway.invoicesystem.subscription;
- public enum State {
- InProgress, Active,InActive, ToStart, ToEnd
- }
- Subscription
- package net.peopleway.invoicesystem.subscription;
- import java.io.Serializable;
- import java.util.Date;
- import java.util.List;
- import javax.persistence.CascadeType;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.EnumType;
- import javax.persistence.Enumerated;
- import javax.persistence.FetchType;
- import javax.persistence.GeneratedValue;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.JoinTable;
- import javax.persistence.ManyToOne;
- import javax.persistence.OneToMany;
- import javax.persistence.Table;
- import net.peopleway.invoicesystem.customer.Customer;
- import net.peopleway.invoicesystem.invoice.Invoice;
- import net.peopleway.invoicesystem.invoice.InvoiceInterval;
- import net.peopleway.invoicesystem.product.Product;
- import org.hibernate.annotations.LazyCollection;
- import org.hibernate.annotations.LazyCollectionOption;
- @Entity
- @Table(name="subscription")
- public class Subscription implements Serializable, Comparable<Subscription> {
- private int subscription_id;
- private List<Product> products;
- private List<Invoice> invoices;
- private Customer customer;
- private InvoiceInterval paymentDelay;
- private int dateInterval;
- private State substate;
- private Date creationDate;
- private String name;
- public Subscription() {
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY,orphanRemoval=true, mappedBy = "subscription")
- public List<Product> getProducts() {
- return products;
- }
- public void setProducts(List<Product> products) {
- this.products = products;
- }
- @Id
- @GeneratedValue
- @Column(name="subscription_id")
- public int getSubscription_id() {
- return subscription_id;
- }
- public void setSubscription_id(int subscription_id) {
- this.subscription_id = subscription_id;
- }
- public void setInvoices(List<Invoice> invoices) {
- this.invoices = invoices;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @OneToMany(cascade = CascadeType.ALL, mappedBy = "subscription")
- public List<Invoice> getInvoices() {
- return invoices;
- }
- @Enumerated(EnumType.STRING)
- public InvoiceInterval getPaymentDelay() {
- return paymentDelay;
- }
- public void setPaymentDelay(InvoiceInterval paymentDelay) {
- this.paymentDelay = paymentDelay;
- }
- @Column
- public int getDateInterval() {
- return dateInterval;
- }
- public void setDateInterval(int dateInterval) {
- this.dateInterval = dateInterval;
- }
- @Enumerated(EnumType.STRING)
- public State getSubstate() {
- return substate;
- }
- public void setSubstate(State substate) {
- this.substate = substate;
- }
- @Column
- public Date getCreationDate() {
- return creationDate;
- }
- public void setCreationDate(Date creationDate) {
- this.creationDate = creationDate;
- }
- @LazyCollection(LazyCollectionOption.FALSE)
- @ManyToOne(optional = false)
- @JoinColumn(name = "customer_id")
- public Customer getCustomer() {
- return customer;
- }
- public void setCustomer(Customer customer) {
- this.customer = customer;
- }
- @Column
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Override
- public String toString() {
- return name + " " + substate.toString().toLowerCase();
- }
- @Override
- public int hashCode() {
- return super.hashCode();
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Subscription other = (Subscription) obj;
- if (subscription_id != other.subscription_id)
- return false;
- return true;
- }
- @Override
- public int compareTo(Subscription o) {
- return this.name.compareTo(o.name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement