ch.hsr.bieridee.models
Class BeerModel

java.lang.Object
  extended by ch.hsr.bieridee.models.AbstractModel
      extended by ch.hsr.bieridee.models.BeerModel

public class BeerModel
extends AbstractModel

Model to work and persist the beer object.


Constructor Summary
BeerModel(long beerId)
          Creates a BeerModel for the desired beer.
BeerModel(org.neo4j.graphdb.Node node)
           
 
Method Summary
 void addBarcode(BarcodeModel b)
          Add barcode to BeerModel.
 void addTag(TagModel t)
          Links this Beer to the desired TagModel.
 void calculateAndUpdateAverageRating()
          calculates the average rating and saves the value in the database.
static BeerModel create(java.lang.String name, java.lang.String brand, BeertypeModel beertypeModel, BreweryModel breweryModel)
          Create a new Beer! Including a fresh node and a delicious domain object.
static java.util.List<BeerModel> createModelsFromNodes(java.util.List<org.neo4j.graphdb.Node> beerNodes)
          Creates models from nodes.
 boolean equals(java.lang.Object o)
           
static java.util.List<BeerModel> getAll()
          Gets a list of all beers as BeerModels.
static java.util.List<BeerModel> getAll(int items, int skip)
          Gets a list of all beers as BeerModels.
static java.util.List<BeerModel> getAllByBarcode(java.lang.String filterBarcode)
          Gets a list of beers as BeerModels filtered by a barcode.
static java.util.List<BeerModel> getAllByTag(long filterTag)
          Gets a list of beers as BeerModels filtered by a tag.
static java.util.List<BeerModel> getAllByTag(long filterTag, int items, int skip)
          Gets a list of beers as BeerModels filtered by a tag.
 double getAverageRating()
           
 double getAverageRatingShortened()
           
 BeertypeModel getBeertype()
           
 java.lang.String getBrand()
           
 BreweryModel getBrewery()
           
 Beer getDomainObject()
           
 long getId()
           
 java.lang.String getName()
           
 org.neo4j.graphdb.Node getNode()
           
 java.lang.String getPicture()
           
 java.util.List<TagModel> getTagModels()
           
 java.util.List<Tag> getTags()
           
 int hashCode()
           
 void setBeertype(BeertypeModel beertypeModel)
           
 void setBrand(java.lang.String brand)
           
 void setBrewery(BreweryModel breweryModel)
           
 void setImage(java.lang.String path)
           
 void setName(java.lang.String name)
           
 void setTags(java.lang.Iterable<TagModel> tags)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BeerModel

public BeerModel(long beerId)
          throws WrongNodeTypeException,
                 org.neo4j.graphdb.NotFoundException
Creates a BeerModel for the desired beer.

Parameters:
beerId - The node id of the desired beer
Throws:
WrongNodeTypeException - Thrown when the given id does not reference a beer node
org.neo4j.graphdb.NotFoundException - Thrown when the given ide does not reference an existing node

BeerModel

public BeerModel(org.neo4j.graphdb.Node node)
          throws WrongNodeTypeException,
                 org.neo4j.graphdb.NotFoundException
Parameters:
node - Node containing Properties of the Beer.
Throws:
WrongNodeTypeException - Thrown when the given node is not a beer node
org.neo4j.graphdb.NotFoundException - Thrown when the given node is not existing
Method Detail

getNode

public org.neo4j.graphdb.Node getNode()
Overrides:
getNode in class AbstractModel

getDomainObject

public Beer getDomainObject()
Specified by:
getDomainObject in class AbstractModel

getId

public long getId()

calculateAndUpdateAverageRating

public void calculateAndUpdateAverageRating()
calculates the average rating and saves the value in the database.


getBeertype

public BeertypeModel getBeertype()
                          throws org.neo4j.graphdb.NotFoundException,
                                 WrongNodeTypeException
Throws:
org.neo4j.graphdb.NotFoundException
WrongNodeTypeException

getBrand

public java.lang.String getBrand()

getBrewery

public BreweryModel getBrewery()
                        throws org.neo4j.graphdb.NotFoundException,
                               WrongNodeTypeException
Throws:
org.neo4j.graphdb.NotFoundException
WrongNodeTypeException

getName

public java.lang.String getName()

getPicture

public java.lang.String getPicture()

getTags

public java.util.List<Tag> getTags()

getTagModels

public java.util.List<TagModel> getTagModels()
                                      throws org.neo4j.graphdb.NotFoundException,
                                             WrongNodeTypeException
Throws:
org.neo4j.graphdb.NotFoundException
WrongNodeTypeException

getAverageRating

public double getAverageRating()

getAverageRatingShortened

public double getAverageRatingShortened()
Returns:
double value containing only one decimal place.

setBeertype

public void setBeertype(BeertypeModel beertypeModel)

setBrand

public void setBrand(java.lang.String brand)

setBrewery

public void setBrewery(BreweryModel breweryModel)

setName

public void setName(java.lang.String name)

setImage

public void setImage(java.lang.String path)

addTag

public void addTag(TagModel t)
Links this Beer to the desired TagModel.

Parameters:
t - TagModel to add.

addBarcode

public void addBarcode(BarcodeModel b)
Add barcode to BeerModel.

Parameters:
b - BarcodeModel

setTags

public void setTags(java.lang.Iterable<TagModel> tags)

create

public static BeerModel create(java.lang.String name,
                               java.lang.String brand,
                               BeertypeModel beertypeModel,
                               BreweryModel breweryModel)
Create a new Beer! Including a fresh node and a delicious domain object.

Parameters:
name - Name of the new beer
brand - Brand of the new beer
beertypeModel - The beertype of the new beer
breweryModel - The the sacred place where this beer was brewn
Returns:
A new BeerModel representing the new beer

getAll

public static java.util.List<BeerModel> getAll()
                                        throws org.neo4j.graphdb.NotFoundException,
                                               WrongNodeTypeException
Gets a list of all beers as BeerModels.

Returns:
List of BeerModel
Throws:
org.neo4j.graphdb.NotFoundException - Thrown if a node is not existing
WrongNodeTypeException - Thrown if a node is not of the desired type

getAll

public static java.util.List<BeerModel> getAll(int items,
                                               int skip)
                                        throws org.neo4j.graphdb.NotFoundException,
                                               WrongNodeTypeException
Gets a list of all beers as BeerModels.

Parameters:
items - Number of items to be displayed
skip - Number of items to be skipped
Returns:
List of BeerModel
Throws:
org.neo4j.graphdb.NotFoundException - Thrown if a node is not existsing
WrongNodeTypeException - Thrown if a node is not of the desired type

getAllByTag

public static java.util.List<BeerModel> getAllByTag(long filterTag)
                                             throws org.neo4j.graphdb.NotFoundException,
                                                    WrongNodeTypeException
Gets a list of beers as BeerModels filtered by a tag.

Parameters:
filterTag - Tag to be filterd with
Returns:
Filtered list of BeerModels
Throws:
org.neo4j.graphdb.NotFoundException - Thrown if a node is not existing
WrongNodeTypeException - Thrown if a node is not of the desired type

getAllByTag

public static java.util.List<BeerModel> getAllByTag(long filterTag,
                                                    int items,
                                                    int skip)
                                             throws org.neo4j.graphdb.NotFoundException,
                                                    WrongNodeTypeException
Gets a list of beers as BeerModels filtered by a tag.

Parameters:
filterTag - Tag to be filterd with
items - Number of items to be displayed
skip - Number of items to be skipped
Returns:
Filtered list of BeerModels
Throws:
org.neo4j.graphdb.NotFoundException - Thrown if a node is not existant
WrongNodeTypeException - Thrown if a node is not of the desired type

createModelsFromNodes

public static java.util.List<BeerModel> createModelsFromNodes(java.util.List<org.neo4j.graphdb.Node> beerNodes)
                                                       throws org.neo4j.graphdb.NotFoundException,
                                                              WrongNodeTypeException
Creates models from nodes.

Parameters:
beerNodes - Beernodes
Returns:
A list of BeerModels
Throws:
org.neo4j.graphdb.NotFoundException - Thrown if a node is not existing
WrongNodeTypeException - Thrown if a node is not of the desired type

getAllByBarcode

public static java.util.List<BeerModel> getAllByBarcode(java.lang.String filterBarcode)
                                                 throws org.neo4j.graphdb.NotFoundException,
                                                        WrongNodeTypeException
Gets a list of beers as BeerModels filtered by a barcode. Should just return one beer.

Parameters:
filterBarcode - Barcode to be filterd with
Returns:
Filtered list of BeerModels
Throws:
org.neo4j.graphdb.NotFoundException - Thrown if a node is not existant
WrongNodeTypeException - Thrown if a node is not of the desired type

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object