Package com.camunda.fox.bean

Source Code of com.camunda.fox.bean.AccountService

package com.camunda.fox.bean;

import java.util.UUID;

import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.camunda.fox.model.dto.Order;
import com.camunda.fox.model.entity.Account;
import com.camunda.fox.model.entity.Address;
import com.camunda.fox.model.entity.Customer;

@Stateless
@Named
public class AccountService {

  private EntityManager entityManager;

  @PersistenceContext
  public void setEntityManager(EntityManager entityManager) {
    this.entityManager = entityManager;
  }
 
  public void setUpAccout(Order order) {
    Account account = new Account(createAccountNumber(),
        order.getAccounttype(), null);
    entityManager.persist(account);

    Address address = new Address(order.getAddress().getStreet(), order
        .getAddress().getNumber(), order.getAddress().getZipcode(),
        order.getAddress().getCity(), order.getAddress().getState(),
        order.getAddress().getCountry());
    Customer customer = new Customer(order.getPerson().getFirstname(),
        order.getPerson().getLastname(), order.getPerson().getTitle(),
        order.getPerson().getDateofbirth(), order.getPerson()
            .getPlaceofbirth(), order.getPerson().getGender(),
        order.getPerson().getPhonenumber(), order.getPerson()
            .getEmail(), address);

    account.setCustomer(customer);
  }

  private String createAccountNumber() {
    return UUID.randomUUID().toString();
  }

}
TOP

Related Classes of com.camunda.fox.bean.AccountService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.