Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
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
javab_20230928
Commits
5ced9f55
Commit
5ced9f55
authored
Nov 08, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jeszcze dodatkowe metody
parent
4801701a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletions
+37
-1
PhotoUtil.java
PC33-SoapSerwer/src/main/java/sklep/soap/PhotoUtil.java
+12
-1
Sklep.java
PC33-SoapSerwer/src/main/java/sklep/soap/Sklep.java
+25
-0
No files found.
PC33-SoapSerwer/src/main/java/sklep/soap/PhotoUtil.java
View file @
5ced9f55
...
@@ -7,6 +7,7 @@ import java.nio.file.Files;
...
@@ -7,6 +7,7 @@ import java.nio.file.Files;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.nio.file.StandardCopyOption
;
import
java.nio.file.StandardCopyOption
;
import
java.nio.file.StandardOpenOption
;
import
sklep.db.DBException
;
import
sklep.db.DBException
;
import
sklep.db.DBSettings
;
import
sklep.db.DBSettings
;
...
@@ -46,10 +47,20 @@ public class PhotoUtil {
...
@@ -46,10 +47,20 @@ public class PhotoUtil {
}
}
}
}
public
static
void
writeBytes
(
int
productId
,
byte
[]
bytes
)
{
try
{
Path
path
=
getPath
(
productId
);
Files
.
write
(
path
,
bytes
,
StandardOpenOption
.
CREATE
);
}
catch
(
Exception
e
)
{
// wypisujemy błąd, ale metoda kończy się normalnie
e
.
printStackTrace
();
}
}
private
static
Path
getPath
(
int
productId
)
throws
DBException
{
private
static
Path
getPath
(
int
productId
)
throws
DBException
{
String
dir
=
DBSettings
.
load
().
getProperty
(
"photo_dir"
);
String
dir
=
DBSettings
.
load
().
getProperty
(
"photo_dir"
);
String
fileName
=
productId
+
EXT
;
String
fileName
=
productId
+
EXT
;
return
Paths
.
get
(
dir
,
fileName
);
return
Paths
.
get
(
dir
,
fileName
);
}
}
}
}
PC33-SoapSerwer/src/main/java/sklep/soap/Sklep.java
View file @
5ced9f55
...
@@ -6,10 +6,14 @@ import java.util.List;
...
@@ -6,10 +6,14 @@ import java.util.List;
import
jakarta.jws.WebParam
;
import
jakarta.jws.WebParam
;
import
jakarta.jws.WebResult
;
import
jakarta.jws.WebResult
;
import
jakarta.jws.WebService
;
import
jakarta.jws.WebService
;
import
sklep.db.CustomerDAO
;
import
sklep.db.DBConnection
;
import
sklep.db.DBConnection
;
import
sklep.db.DBException
;
import
sklep.db.DBException
;
import
sklep.db.OrderDAO
;
import
sklep.db.ProductDAO
;
import
sklep.db.ProductDAO
;
import
sklep.db.RecordNotFound
;
import
sklep.db.RecordNotFound
;
import
sklep.model.Customer
;
import
sklep.model.Order
;
import
sklep.model.Product
;
import
sklep.model.Product
;
@WebService
@WebService
...
@@ -50,8 +54,29 @@ public class Sklep {
...
@@ -50,8 +54,29 @@ public class Sklep {
}
}
}
}
@WebResult
(
name
=
"customer"
)
public
Customer
oneCustomer
(
@WebParam
(
name
=
"email"
)
String
email
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
CustomerDAO
customerDAO
=
db
.
customerDAO
();
return
customerDAO
.
findByEmail
(
email
);
}
}
@WebResult
(
name
=
"order"
)
public
Order
oneOrder
(
@WebParam
(
name
=
"id"
)
int
orderId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
OrderDAO
orderDAO
=
db
.
orderDAO
();
return
orderDAO
.
findById
(
orderId
);
}
}
@WebResult
(
name
=
"bytes"
)
@WebResult
(
name
=
"bytes"
)
public
byte
[]
getPhoto
(
@WebParam
(
name
=
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
public
byte
[]
getPhoto
(
@WebParam
(
name
=
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
return
PhotoUtil
.
readBytes
(
productId
);
return
PhotoUtil
.
readBytes
(
productId
);
}
}
public
void
savePhoto
(
@WebParam
(
name
=
"id"
)
int
productId
,
@WebParam
(
name
=
"bytes"
)
byte
[]
bytes
)
{
PhotoUtil
.
writeBytes
(
productId
,
bytes
);
}
}
}
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