net.eusashead.hateoas.springhalbuilder.model.LineItem.java Source code

Java tutorial

Introduction

Here is the source code for net.eusashead.hateoas.springhalbuilder.model.LineItem.java

Source

package net.eusashead.hateoas.springhalbuilder.model;

/*
 * #[license]
 * Spring HalBuilder Example Webapp
 * %%
 * Copyright (C) 2013 Eusa's Head
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * %[license]
 */

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "LINE_ITEMS", schema = "PUBLIC")
public class LineItem implements Serializable {

    private static final long serialVersionUID = 416398598972120937L;

    @Id
    @Column(name = "LINE_ITEM_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer lineItemId;

    @Basic
    @Column(name = "QUANTITY")
    private int quantity;

    @ManyToOne(targetEntity = StockKeepingUnit.class)
    @JoinColumns({ @JoinColumn(name = "SKU_ID", referencedColumnName = "SKU_ID", nullable = false) })
    private StockKeepingUnit sku;

    @JsonBackReference
    @ManyToOne(targetEntity = Order.class)
    @JoinColumns({ @JoinColumn(name = "ORDER_ID", referencedColumnName = "ORDER_ID", nullable = false) })
    private Order order;

    public Integer getLineItemId() {
        return lineItemId;
    }

    public void setLineItemId(Integer lineItemId) {
        this.lineItemId = lineItemId;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public StockKeepingUnit getSku() {
        return sku;
    }

    public void setSku(StockKeepingUnit sku) {
        this.sku = sku;
    }

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    @JsonIgnore
    @Transient
    public BigDecimal getSubTotal() {
        return BigDecimal.valueOf(quantity * sku.getPrice().doubleValue());
    }

}