Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_java2b_20250412
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
alx_java2b_20250412
Commits
02bb20c1
Commit
02bb20c1
authored
May 24, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sklep.model do RestKlient
parent
75b3c1b0
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
530 additions
and
0 deletions
+530
-0
Customer.java
PC27-RestKlient/src/main/java/sklep/model/Customer.java
+101
-0
DateTimeAdapter.java
...RestKlient/src/main/java/sklep/model/DateTimeAdapter.java
+17
-0
Order.java
PC27-RestKlient/src/main/java/sklep/model/Order.java
+135
-0
OrderProduct.java
PC27-RestKlient/src/main/java/sklep/model/OrderProduct.java
+92
-0
Price.java
PC27-RestKlient/src/main/java/sklep/model/Price.java
+33
-0
Product.java
PC27-RestKlient/src/main/java/sklep/model/Product.java
+110
-0
ProductList.java
PC27-RestKlient/src/main/java/sklep/model/ProductList.java
+37
-0
package-info.java
PC27-RestKlient/src/main/java/sklep/model/package-info.java
+5
-0
No files found.
PC27-RestKlient/src/main/java/sklep/model/Customer.java
0 → 100644
View file @
02bb20c1
package
sklep
.
model
;
import
java.util.Objects
;
import
jakarta.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
public
class
Customer
{
private
String
email
;
private
String
name
;
private
String
phoneNumber
;
private
String
address
;
private
String
postalCode
;
private
String
city
;
public
Customer
()
{
}
public
Customer
(
String
email
,
String
name
,
String
phone
,
String
address
,
String
postalCode
,
String
city
)
{
this
.
email
=
email
;
this
.
name
=
name
;
this
.
phoneNumber
=
phone
;
this
.
address
=
address
;
this
.
postalCode
=
postalCode
;
this
.
city
=
city
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPhoneNumber
()
{
return
phoneNumber
;
}
public
void
setPhoneNumber
(
String
phone
)
{
this
.
phoneNumber
=
phone
;
}
public
String
getAddress
()
{
return
address
;
}
public
void
setAddress
(
String
address
)
{
this
.
address
=
address
;
}
public
String
getPostalCode
()
{
return
postalCode
;
}
public
void
setPostalCode
(
String
postalCode
)
{
this
.
postalCode
=
postalCode
;
}
public
String
getCity
()
{
return
city
;
}
public
void
setCity
(
String
city
)
{
this
.
city
=
city
;
}
@Override
public
String
toString
()
{
return
"Customer [email="
+
email
+
", name="
+
name
+
", phone="
+
phoneNumber
+
", address="
+
address
+
", postalCode="
+
postalCode
+
", city="
+
city
+
"]"
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
email
,
name
,
address
,
city
,
phoneNumber
,
postalCode
);
}
@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
;
return
Objects
.
equals
(
email
,
other
.
email
)
&&
Objects
.
equals
(
name
,
other
.
name
)
&&
Objects
.
equals
(
address
,
other
.
address
)
&&
Objects
.
equals
(
city
,
other
.
city
)
&&
Objects
.
equals
(
phoneNumber
,
other
.
phoneNumber
)
&&
Objects
.
equals
(
postalCode
,
other
.
postalCode
);
}
}
PC27-RestKlient/src/main/java/sklep/model/DateTimeAdapter.java
0 → 100644
View file @
02bb20c1
package
sklep
.
model
;
import
java.time.LocalDateTime
;
import
jakarta.xml.bind.annotation.adapters.XmlAdapter
;
public
class
DateTimeAdapter
extends
XmlAdapter
<
String
,
LocalDateTime
>
{
@Override
public
String
marshal
(
LocalDateTime
dt
)
{
return
dt
.
toString
();
}
@Override
public
LocalDateTime
unmarshal
(
String
s
)
{
return
LocalDateTime
.
parse
(
s
);
}
}
PC27-RestKlient/src/main/java/sklep/model/Order.java
0 → 100644
View file @
02bb20c1
package
sklep
.
model
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Objects
;
import
jakarta.xml.bind.annotation.XmlAttribute
;
import
jakarta.xml.bind.annotation.XmlElement
;
import
jakarta.xml.bind.annotation.XmlElementWrapper
;
import
jakarta.xml.bind.annotation.XmlRootElement
;
import
jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter
;
@XmlRootElement
public
class
Order
{
@XmlAttribute
(
name
=
"id"
)
private
Integer
orderId
;
@XmlElement
(
name
=
"customer-email"
)
private
String
customerEmail
;
@XmlElement
(
name
=
"order-date"
)
@XmlJavaTypeAdapter
(
DateTimeAdapter
.
class
)
private
LocalDateTime
orderDate
;
@XmlAttribute
(
name
=
"status"
)
private
Status
orderStatus
;
@XmlElementWrapper
(
name
=
"products"
)
@XmlElement
(
name
=
"product"
)
public
final
List
<
OrderProduct
>
products
=
new
ArrayList
<>();
public
Order
()
{
}
public
Order
(
Integer
orderId
,
String
customerEmail
,
LocalDateTime
orderDate
,
Status
orderStatus
)
{
this
.
orderId
=
orderId
;
this
.
customerEmail
=
customerEmail
;
this
.
orderDate
=
orderDate
;
this
.
orderStatus
=
orderStatus
;
}
public
static
Order
ofDbFields
(
int
orderId
,
String
customerEmail
,
java
.
sql
.
Timestamp
orderDate
,
String
orderStatus
)
{
return
new
Order
(
orderId
,
customerEmail
,
orderDate
.
toLocalDateTime
(),
Status
.
valueOf
(
orderStatus
.
toUpperCase
()));
}
public
Integer
getOrderId
()
{
return
orderId
;
}
public
void
setOrderId
(
Integer
orderId
)
{
this
.
orderId
=
orderId
;
}
public
String
getCustomerEmail
()
{
return
customerEmail
;
}
public
void
setCustomerEmail
(
String
customerEmail
)
{
this
.
customerEmail
=
customerEmail
;
}
public
LocalDateTime
getOrderDate
()
{
return
orderDate
;
}
public
void
setOrderDate
(
LocalDateTime
orderDate
)
{
this
.
orderDate
=
orderDate
;
}
public
Status
getOrderStatus
()
{
return
orderStatus
;
}
public
void
setOrderStatus
(
Status
orderStatus
)
{
this
.
orderStatus
=
orderStatus
;
}
public
List
<
OrderProduct
>
getProducts
()
{
return
Collections
.
unmodifiableList
(
products
);
}
public
void
addProduct
(
OrderProduct
product
)
{
this
.
products
.
add
(
product
);
}
public
void
addProducts
(
Collection
<
OrderProduct
>
products
)
{
this
.
products
.
addAll
(
products
);
}
public
void
setProducts
(
Collection
<
OrderProduct
>
products
)
{
this
.
products
.
clear
();
this
.
products
.
addAll
(
products
);
}
@Override
public
String
toString
()
{
return
"Order [orderId="
+
orderId
+
", customerEmail="
+
customerEmail
+
", orderDate="
+
orderDate
+
", orderStatus="
+
orderStatus
+
"]"
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
customerEmail
,
orderDate
,
orderId
,
orderStatus
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
Order
other
=
(
Order
)
obj
;
return
Objects
.
equals
(
customerEmail
,
other
.
customerEmail
)
&&
Objects
.
equals
(
orderDate
,
other
.
orderDate
)
&&
Objects
.
equals
(
orderId
,
other
.
orderId
)
&&
orderStatus
==
other
.
orderStatus
;
}
public
enum
Status
{
NEW
,
CONFIRMED
,
PAID
,
SHIPPED
,
CLOSED
,
RETURNED
,
;
}
}
PC27-RestKlient/src/main/java/sklep/model/OrderProduct.java
0 → 100644
View file @
02bb20c1
package
sklep
.
model
;
import
java.math.BigDecimal
;
import
java.util.Objects
;
import
jakarta.xml.bind.annotation.XmlAttribute
;
import
jakarta.xml.bind.annotation.XmlElement
;
public
class
OrderProduct
{
@XmlAttribute
(
name
=
"order-id"
)
private
Integer
orderId
;
@XmlAttribute
(
name
=
"product-id"
)
private
Integer
productId
;
private
int
quantity
;
@XmlElement
(
name
=
"price"
)
private
BigDecimal
actualPrice
;
public
OrderProduct
()
{
}
public
OrderProduct
(
Integer
orderId
,
Integer
productId
,
int
quantity
,
BigDecimal
actualPrice
)
{
this
.
orderId
=
orderId
;
this
.
productId
=
productId
;
this
.
quantity
=
quantity
;
this
.
actualPrice
=
actualPrice
;
}
public
static
OrderProduct
of
(
Integer
orderId
,
Product
product
,
int
quantity
)
{
return
new
OrderProduct
(
orderId
,
product
.
getProductId
(),
quantity
,
product
.
getPrice
());
}
public
Integer
getOrderId
()
{
return
orderId
;
}
public
void
setOrderId
(
Integer
orderId
)
{
this
.
orderId
=
orderId
;
}
public
Integer
getProductId
()
{
return
productId
;
}
public
void
setProductId
(
Integer
productId
)
{
this
.
productId
=
productId
;
}
public
int
getQuantity
()
{
return
quantity
;
}
public
void
setQuantity
(
int
quantity
)
{
this
.
quantity
=
quantity
;
}
public
BigDecimal
getActualPrice
()
{
return
actualPrice
;
}
public
void
setActualPrice
(
BigDecimal
actualPrice
)
{
this
.
actualPrice
=
actualPrice
;
}
@Override
public
String
toString
()
{
return
"OrderProduct [orderId="
+
orderId
+
", productId="
+
productId
+
", quantity="
+
quantity
+
", actualPrice="
+
actualPrice
+
"]"
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
orderId
,
productId
,
quantity
,
actualPrice
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
OrderProduct
other
=
(
OrderProduct
)
obj
;
return
Objects
.
equals
(
orderId
,
other
.
orderId
)
&&
Objects
.
equals
(
productId
,
other
.
productId
)
&&
quantity
==
other
.
quantity
&&
Objects
.
equals
(
actualPrice
,
other
.
actualPrice
);
}
}
PC27-RestKlient/src/main/java/sklep/model/Price.java
0 → 100644
View file @
02bb20c1
package
sklep
.
model
;
import
java.math.BigDecimal
;
import
jakarta.xml.bind.annotation.XmlRootElement
;
import
jakarta.xml.bind.annotation.XmlValue
;
@XmlRootElement
public
class
Price
{
@XmlValue
private
BigDecimal
value
;
public
Price
()
{
this
.
value
=
BigDecimal
.
ZERO
;
}
public
Price
(
BigDecimal
value
)
{
this
.
value
=
value
;
}
public
BigDecimal
getValue
()
{
return
value
;
}
public
void
setValue
(
BigDecimal
value
)
{
this
.
value
=
value
;
}
@Override
public
String
toString
()
{
return
value
.
toString
();
}
}
PC27-RestKlient/src/main/java/sklep/model/Product.java
0 → 100644
View file @
02bb20c1
package
sklep
.
model
;
import
java.math.BigDecimal
;
import
java.util.Objects
;
import
jakarta.xml.bind.annotation.XmlAttribute
;
import
jakarta.xml.bind.annotation.XmlElement
;
import
jakarta.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
public
class
Product
{
@XmlAttribute
(
name
=
"id"
)
private
Integer
productId
;
@XmlElement
(
name
=
"product-name"
)
private
String
productName
;
private
BigDecimal
price
;
private
BigDecimal
vat
;
private
String
description
;
public
Product
()
{
}
public
Product
(
Integer
productId
,
String
productName
,
BigDecimal
price
,
BigDecimal
vat
,
String
description
)
{
this
.
productId
=
productId
;
this
.
productName
=
productName
;
this
.
price
=
price
;
this
.
vat
=
vat
;
this
.
description
=
description
;
}
public
Integer
getProductId
()
{
return
productId
;
}
public
void
setProductId
(
Integer
productId
)
{
this
.
productId
=
productId
;
}
public
String
getProductName
()
{
return
productName
;
}
public
void
setProductName
(
String
productName
)
{
this
.
productName
=
productName
;
}
public
BigDecimal
getPrice
()
{
return
price
;
}
public
void
setPrice
(
BigDecimal
price
)
{
this
.
price
=
price
;
}
public
BigDecimal
getVat
()
{
return
vat
;
}
public
void
setVat
(
BigDecimal
vat
)
{
this
.
vat
=
vat
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
description
,
price
,
vat
,
productId
,
productName
);
}
@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
;
return
Objects
.
equals
(
productId
,
other
.
productId
)
&&
Objects
.
equals
(
productName
,
other
.
productName
)
&&
Objects
.
equals
(
price
,
other
.
price
)
&&
Objects
.
equals
(
vat
,
other
.
vat
)
&&
Objects
.
equals
(
description
,
other
.
description
);
}
@Override
public
String
toString
()
{
return
"Product [productId="
+
productId
+
", productName="
+
productName
+
", price="
+
price
+
", vat="
+
vat
+
", description="
+
description
+
"]"
;
}
public
String
toHtml
()
{
return
String
.
format
(
"<div class='product'>"
+
"<h2>%s</h2>"
+
"<p>(nr %d)</p>"
+
"<p>Cena: <strong>%,.2f PLN</strong></p>"
+
"<p>%s</p>"
+
"</div>"
,
getProductName
(),
getProductId
(),
getPrice
(),
getDescription
());
}
}
PC27-RestKlient/src/main/java/sklep/model/ProductList.java
0 → 100644
View file @
02bb20c1
package
sklep
.
model
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
jakarta.xml.bind.annotation.XmlElement
;
import
jakarta.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
(
name
=
"products"
)
public
class
ProductList
{
@XmlElement
(
name
=
"product"
)
private
final
List
<
Product
>
products
=
new
ArrayList
<>();
public
ProductList
()
{
// zostawia pustą listę
}
public
ProductList
(
Collection
<
Product
>
products
)
{
this
.
products
.
addAll
(
products
);
}
public
List
<
Product
>
getProducts
()
{
return
Collections
.
unmodifiableList
(
this
.
products
);
}
public
void
setProducts
(
Collection
<
Product
>
products
)
{
this
.
products
.
clear
();
this
.
products
.
addAll
(
products
);
}
@Override
public
String
toString
()
{
return
this
.
products
.
toString
();
}
}
PC27-RestKlient/src/main/java/sklep/model/package-info.java
0 → 100644
View file @
02bb20c1
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
package
sklep
.
model
;
import
jakarta.xml.bind.annotation.XmlAccessType
;
import
jakarta.xml.bind.annotation.XmlAccessorType
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment