Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Wendys Racing Horses
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
tu-wien
Wendys Racing Horses
Commits
1c31939b
Commit
1c31939b
authored
Apr 05, 2020
by
Ivaylo Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TS18: Add a specific exception for the persistence layer
parent
c10bbb59
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
98 additions
and
92 deletions
+98
-92
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/endpoint/HorseEndpoint.java
...en/sepm/assignment/individual/endpoint/HorseEndpoint.java
+4
-4
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/endpoint/OwnerEndpoint.java
...en/sepm/assignment/individual/endpoint/OwnerEndpoint.java
+4
-4
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/exception/PersistenceException.java
...assignment/individual/exception/PersistenceException.java
+13
-0
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/HorseDao.java
...wien/sepm/assignment/individual/persistence/HorseDao.java
+16
-16
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/OwnerDao.java
...wien/sepm/assignment/individual/persistence/OwnerDao.java
+11
-14
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java
.../assignment/individual/persistence/impl/HorseJdbcDao.java
+7
-9
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/OwnerJdbcDao.java
.../assignment/individual/persistence/impl/OwnerJdbcDao.java
+7
-9
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/HorseService.java
...wien/sepm/assignment/individual/service/HorseService.java
+6
-6
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/OwnerService.java
...wien/sepm/assignment/individual/service/OwnerService.java
+8
-8
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java
...ssignment/individual/service/impl/SimpleHorseService.java
+4
-4
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleOwnerService.java
...ssignment/individual/service/impl/SimpleOwnerService.java
+4
-4
backend/src/test/java/at/ac/tuwien/sepm/assignment/individual/unit/persistence/HorseDaoTestBase.java
...ignment/individual/unit/persistence/HorseDaoTestBase.java
+7
-7
backend/src/test/java/at/ac/tuwien/sepm/assignment/individual/unit/persistence/OwnerDaoTestBase.java
...ignment/individual/unit/persistence/OwnerDaoTestBase.java
+7
-7
No files found.
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/endpoint/HorseEndpoint.java
View file @
1c31939b
...
...
@@ -4,12 +4,12 @@ import at.ac.tuwien.sepm.assignment.individual.endpoint.dto.HorseDto;
import
at.ac.tuwien.sepm.assignment.individual.endpoint.mapper.HorseMapper
;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.service.HorseService
;
import
at.ac.tuwien.sepm.assignment.individual.util.ValidationException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -77,7 +77,7 @@ public class HorseEndpoint {
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
BAD_REQUEST
,
"Error during adding new horse: "
+
e
.
getMessage
());
}
catch
(
DataAccess
Exception
e
)
{
}
catch
(
Persistence
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
UNPROCESSABLE_ENTITY
,
"Something went wrong during the communication with the database"
);
...
...
@@ -96,7 +96,7 @@ public class HorseEndpoint {
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
BAD_REQUEST
,
"Error during updating horse with id "
+
id
+
": "
+
e
.
getMessage
());
}
catch
(
DataAccess
Exception
e
)
{
}
catch
(
Persistence
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
UNPROCESSABLE_ENTITY
,
"Something went wrong during the communication with the database"
);
...
...
@@ -117,7 +117,7 @@ public class HorseEndpoint {
LOGGER
.
info
(
"DELETE "
+
BASE_URL
+
"/{}"
,
id
);
try
{
horseService
.
deleteHorse
(
id
);
}
catch
(
DataAccess
Exception
e
)
{
}
catch
(
Persistence
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
UNPROCESSABLE_ENTITY
,
"Something went wrong during the communication with the database"
);
...
...
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/endpoint/OwnerEndpoint.java
View file @
1c31939b
...
...
@@ -6,6 +6,7 @@ import at.ac.tuwien.sepm.assignment.individual.endpoint.mapper.HorseMapper;
import
at.ac.tuwien.sepm.assignment.individual.endpoint.mapper.OwnerMapper
;
import
at.ac.tuwien.sepm.assignment.individual.entity.Owner
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.service.OwnerService
;
import
java.lang.invoke.MethodHandles
;
...
...
@@ -16,7 +17,6 @@ import at.ac.tuwien.sepm.assignment.individual.util.ValidationException;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -92,7 +92,7 @@ public class OwnerEndpoint {
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
BAD_REQUEST
,
"Error during adding new owner: "
+
e
.
getMessage
());
}
catch
(
DataAccess
Exception
e
)
{
}
catch
(
Persistence
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
UNPROCESSABLE_ENTITY
,
"Something went wrong during the communication with the database"
);
...
...
@@ -111,7 +111,7 @@ public class OwnerEndpoint {
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
BAD_REQUEST
,
"Error during updating owner with id "
+
id
+
": "
+
e
.
getMessage
());
}
catch
(
DataAccess
Exception
e
)
{
}
catch
(
Persistence
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
UNPROCESSABLE_ENTITY
,
"Something went wrong during the communication with the database"
);
...
...
@@ -132,7 +132,7 @@ public class OwnerEndpoint {
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
FORBIDDEN
,
"The requested owner cannot be deleted because there are horses that are assigned to him/her"
);
}
catch
(
DataAccess
Exception
e
)
{
}
catch
(
Persistence
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
throw
new
ResponseStatusException
(
HttpStatus
.
UNPROCESSABLE_ENTITY
,
"Something went wrong during the communication with the database"
);
...
...
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/exception/PersistenceException.java
0 → 100644
View file @
1c31939b
package
at.ac.tuwien.sepm.assignment.individual.exception
;
public
class
PersistenceException
extends
RuntimeException
{
public
PersistenceException
(
String
message
)
{
super
(
message
);
}
public
PersistenceException
(
String
message
,
Exception
e
)
{
super
(
message
,
e
);
}
}
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/HorseDao.java
View file @
1c31939b
...
...
@@ -2,7 +2,7 @@ package at.ac.tuwien.sepm.assignment.individual.persistence;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
org.springframework.dao.DataAccess
Exception
;
import
at.ac.tuwien.sepm.assignment.individual.exception.Persistence
Exception
;
import
java.io.IOException
;
import
java.util.List
;
...
...
@@ -13,46 +13,46 @@ public interface HorseDao {
/**
* @param id of the horse to find.
* @return the horse with the specified id.
* @throws
DataAccess
Exception will be thrown if something goes wrong during the database access.
* @throws
Persistence
Exception will be thrown if something goes wrong during the database access.
* @throws NotFoundException will be thrown if the horse could not be found in the database.
*/
Horse
findOneById
(
Long
id
);
Horse
findOneById
(
Long
id
)
throws
NotFoundException
,
PersistenceException
;
/**
* @return a list of all horses in the system
* @throws NotFoundException will be thrown if no horses are present in the database
* @throws
DataAccess
Exception will be thrown if something goes wrong during the database access
* @throws
Persistence
Exception will be thrown if something goes wrong during the database access
*/
List
<
Horse
>
getAll
()
throws
NotFoundException
;
List
<
Horse
>
getAll
()
throws
NotFoundException
,
PersistenceException
;
/**
* @param filters to use for filtering the horses
* @return a list of all horses that fill the criteria
* @throws NotFoundException wil be thrown if no horses fill the criteria
* @throws
DataAccessException will be thrown if something goes wrong during the database access
* @throws
PersistenceException will be thrown if something goes wrong during the database access.
*/
List
<
Horse
>
getFiltered
(
Map
<
String
,
String
>
filters
)
throws
NotFoundException
;
List
<
Horse
>
getFiltered
(
Map
<
String
,
String
>
filters
)
throws
NotFoundException
,
PersistenceException
;
/**
* @param horse that specifies the horse to add
* @return the newly created horse
* @throws
DataAccess
Exception will be thrown if something goes wrong during the database access.
* @throws
Persistence
Exception will be thrown if something goes wrong during the database access.
*/
Horse
addHorse
(
Horse
horse
);
Horse
addHorse
(
Horse
horse
)
throws
PersistenceException
;
/**
* @param horse that specifies the new horse values alongside with the id of the horse to update
* @return the updated horse
* @throws
DataAccess
Exception will be thrown if something goes wrong during the database access.
* @throws IOException will be thrown if the old horse image could not be deleted
* @throws
Persistence
Exception will be thrown if something goes wrong during the database access.
* @throws IOException
will be thrown if the old horse image could not be deleted
*/
Horse
updateHorse
(
Horse
horse
)
throws
DataAccess
Exception
,
IOException
;
Horse
updateHorse
(
Horse
horse
)
throws
Persistence
Exception
,
IOException
;
/**
* @param id of the horse to delete
* @throws
DataAccess
Exception will be thrown if something goes wrong during the database access.
* @throws NotFoundException will be thrown if the horse could not be found in the database.
* @throws IOException will be thrown if the horse image could not be deleted
* @throws
Persistence
Exception will be thrown if something goes wrong during the database access.
* @throws NotFoundException
will be thrown if the horse could not be found in the database.
* @throws IOException
will be thrown if the horse image could not be deleted
*/
void
deleteHorse
(
Long
id
)
throws
DataAccess
Exception
,
NotFoundException
,
IOException
;
void
deleteHorse
(
Long
id
)
throws
Persistence
Exception
,
NotFoundException
,
IOException
;
}
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/OwnerDao.java
View file @
1c31939b
...
...
@@ -3,7 +3,7 @@ package at.ac.tuwien.sepm.assignment.individual.persistence;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.entity.Owner
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
org.springframework.dao.DataAccess
Exception
;
import
at.ac.tuwien.sepm.assignment.individual.exception.Persistence
Exception
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -13,15 +13,13 @@ public interface OwnerDao {
/**
* @param id of the owner to find.
* @return the owner with the specified id.
* @throws DataAccessException will be thrown if something goes wrong during the database access.
* @throws NotFoundException will be thrown if the owner could not be found in the database.
* @throws NotFoundException will be thrown if the owner could not be found in the database.
*/
Owner
findOneById
(
Long
id
);
Owner
findOneById
(
Long
id
)
throws
NotFoundException
;
/**
* @return a list of all owners in the system
* @throws NotFoundException will be thrown if no owners are present in the database
* @throws DataAccessException will be thrown if something goes wrong during the database access
*/
List
<
Owner
>
getAll
()
throws
NotFoundException
;
...
...
@@ -29,7 +27,6 @@ public interface OwnerDao {
* @param filters to use for filtering the owners
* @return a list of all owners that fill the criteria
* @throws NotFoundException wil be thrown if no owners fill the criteria
* @throws DataAccessException will be thrown if something goes wrong during the database access
*/
List
<
Owner
>
getFiltered
(
Map
<
String
,
String
>
filters
)
throws
NotFoundException
;
...
...
@@ -37,28 +34,28 @@ public interface OwnerDao {
* @param id of the owner whose horses the database should obtain
* @return a list of all horses that the specified owner owns
* @throws NotFoundException will be thrown if the owner owns no horses or if the owner could not be found
* @throws DataAccessException will be thrown if something goes wrong during the database access
*/
List
<
Horse
>
getOwnedHorses
(
Long
id
)
throws
NotFoundException
;
/**
* @param owner that specifies the owner to add
* @return the newly created owner
* @throws
DataAccess
Exception will be thrown if something goes wrong during the database access.
* @throws
Persistence
Exception will be thrown if something goes wrong during the database access.
*/
Owner
addOwner
(
Owner
owner
);
Owner
addOwner
(
Owner
owner
)
throws
PersistenceException
;
/**
* @param owner that specifies the new owner values alongside with the id of the owner to update
* @return the updated owner
* @throws DataAccessException will be thrown if something goes wrong during the database access.
* @throws PersistenceException will be thrown if something goes wrong during the database access.
* @throws NotFoundException wil be thrown if no owners fill the criteria
*/
Owner
updateOwner
(
Owner
owner
)
throws
DataAccess
Exception
;
Owner
updateOwner
(
Owner
owner
)
throws
PersistenceException
,
NotFound
Exception
;
/**
* @param id of the owner to delete
* @throws
DataAccess
Exception will be thrown if something goes wrong during the database access.
* @throws NotFoundException will be thrown if the owner could not be found in the database.
* @throws
Persistence
Exception will be thrown if something goes wrong during the database access.
* @throws NotFoundException
will be thrown if the owner could not be found in the database.
*/
void
deleteOwner
(
Long
id
)
throws
DataAccess
Exception
,
NotFoundException
;
void
deleteOwner
(
Long
id
)
throws
Persistence
Exception
,
NotFoundException
;
}
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java
View file @
1c31939b
...
...
@@ -3,6 +3,7 @@ package at.ac.tuwien.sepm.assignment.individual.persistence.impl;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.enums.ERace
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.FileDao
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.HorseDao
;
import
org.slf4j.Logger
;
...
...
@@ -149,14 +150,13 @@ public class HorseJdbcDao implements HorseDao {
},
keyHolder
);
if
(
changes
==
0
)
throw
new
DataAccessException
(
"Creating horse failed, no rows affected"
)
{}
;
throw
new
PersistenceException
(
"Creating horse failed, no rows affected"
)
;
horse
.
setId
(((
Number
)
keyHolder
.
getKeys
().
get
(
"id"
)).
longValue
());
return
horse
;
}
catch
(
DataAccessException
e
)
{
// We are doing this in order to not change the exception type
throw
new
DataAccessException
(
"Adding new records failed"
,
e
)
{};
throw
new
PersistenceException
(
"Adding new records failed"
,
e
);
}
}
...
...
@@ -197,7 +197,7 @@ public class HorseJdbcDao implements HorseDao {
});
if
(
changes
==
0
)
throw
new
DataAccessException
(
"Updating horse failed, no rows affected"
)
{}
;
throw
new
PersistenceException
(
"Updating horse failed, no rows affected"
)
;
horse
.
setCreatedAt
(
oldHorse
.
getCreatedAt
());
...
...
@@ -206,8 +206,7 @@ public class HorseJdbcDao implements HorseDao {
return
horse
;
}
catch
(
DataAccessException
e
)
{
// We are doing this in order to not change the exception type
throw
new
DataAccessException
(
"Updating records failed"
,
e
)
{};
throw
new
PersistenceException
(
"Updating records failed"
,
e
);
}
}
...
...
@@ -225,12 +224,11 @@ public class HorseJdbcDao implements HorseDao {
});
if
(
changes
==
0
)
throw
new
DataAccessException
(
"Deleting horse failed, no rows affected"
)
{}
;
throw
new
PersistenceException
(
"Deleting horse failed, no rows affected"
)
;
fileDao
.
delete
(
horseToDelete
.
getImagePath
());
}
catch
(
DataAccessException
e
){
// We are doing this in order to not change the exception type
throw
new
DataAccessException
(
"Deleting records failed"
,
e
)
{};
throw
new
PersistenceException
(
"Deleting records failed"
,
e
);
}
}
...
...
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/OwnerJdbcDao.java
View file @
1c31939b
...
...
@@ -3,6 +3,7 @@ package at.ac.tuwien.sepm.assignment.individual.persistence.impl;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.entity.Owner
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.OwnerDao
;
import
java.lang.invoke.MethodHandles
;
...
...
@@ -133,15 +134,14 @@ public class OwnerJdbcDao implements OwnerDao {
},
keyHolder
);
if
(
changes
==
0
)
throw
new
DataAccessException
(
"Creating owner failed, no rows affected"
)
{}
;
throw
new
PersistenceException
(
"Creating owner failed, no rows affected"
)
;
owner
.
setId
(((
Number
)
keyHolder
.
getKeys
().
get
(
"id"
)).
longValue
());
return
owner
;
}
catch
(
DataAccessException
e
)
{
// We are doing this in order to not change the exception type
throw
new
DataAccessException
(
"Adding new records failed"
,
e
)
{};
throw
new
PersistenceException
(
"Adding new records failed"
,
e
);
}
}
...
...
@@ -172,14 +172,13 @@ public class OwnerJdbcDao implements OwnerDao {
});
if
(
changes
==
0
)
throw
new
DataAccessException
(
"Updating owner failed, no rows affected"
)
{}
;
throw
new
PersistenceException
(
"Updating owner failed, no rows affected"
)
;
owner
.
setCreatedAt
(
oldOwner
.
getCreatedAt
());
return
owner
;
}
catch
(
DataAccessException
e
)
{
// We are doing this in order to not change the exception type
throw
new
DataAccessException
(
"Updating records failed"
,
e
)
{};
throw
new
PersistenceException
(
"Updating records failed"
,
e
);
}
}
...
...
@@ -200,11 +199,10 @@ public class OwnerJdbcDao implements OwnerDao {
});
if
(
changes
==
0
)
throw
new
DataAccessException
(
"Deleting owner failed, no rows affected"
)
{}
;
throw
new
PersistenceException
(
"Deleting owner failed, no rows affected"
)
;
}
catch
(
DataAccessException
e
){
// We are doing this in order to not change the exception type
throw
new
DataAccessException
(
"Deleting records failed"
,
e
)
{};
throw
new
PersistenceException
(
"Deleting records failed"
,
e
);
}
}
...
...
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/HorseService.java
View file @
1c31939b
...
...
@@ -2,8 +2,8 @@ package at.ac.tuwien.sepm.assignment.individual.service;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.util.ValidationException
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
...
...
@@ -37,7 +37,7 @@ public interface HorseService {
* @param horse to add.
* @return the new horse.
* @throws ValidationException will be thrown if something goes wrong during verification.
* @throws
DataAccess
Exception will be thrown if the horse could not be saved in the database.
* @throws
Persistence
Exception will be thrown if the horse could not be saved in the database.
*/
Horse
addHorse
(
Horse
horse
);
...
...
@@ -45,18 +45,18 @@ public interface HorseService {
* @param horse that specifies the new horse values alongside with the id of the horse to update
* @return the updated horse
* @throws ValidationException will be thrown if something goes wrong during verification.
* @throws
DataAccess
Exception will be thrown if the horse could not be saved in the database.
* @throws
Persistence
Exception will be thrown if the horse could not be saved in the database.
* @throws IOException will be thrown if the old horse image could not be deleted
*/
Horse
updateHorse
(
Horse
horse
)
throws
ValidationException
,
DataAccess
Exception
,
IOException
;
Horse
updateHorse
(
Horse
horse
)
throws
ValidationException
,
Persistence
Exception
,
IOException
;
/**
* @param id of the horse to delete
* @throws NotFoundException will be thrown if the horse could not be found in the system
* @throws
DataAccess
Exception will be thrown if the horse could not be deleted from the database
* @throws
Persistence
Exception will be thrown if the horse could not be deleted from the database
* @throws IOException will be thrown if the horse image could not be deleted
*/
void
deleteHorse
(
Long
id
)
throws
NotFoundException
,
DataAccess
Exception
,
IOException
;
void
deleteHorse
(
Long
id
)
throws
NotFoundException
,
Persistence
Exception
,
IOException
;
/**
* @param img image to upload
...
...
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/OwnerService.java
View file @
1c31939b
...
...
@@ -3,8 +3,8 @@ package at.ac.tuwien.sepm.assignment.individual.service;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.entity.Owner
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.util.ValidationException
;
import
org.springframework.dao.DataAccessException
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -38,7 +38,7 @@ public interface OwnerService {
* @param id of the owner whose horses the database should obtain
* @return a list of all horses that the specified owner owns
* @throws NotFoundException will be thrown if the owner owns no horses or if the owner could not be found
* @throws
DataAccess
Exception will be thrown if something goes wrong during the database access
* @throws
Persistence
Exception will be thrown if something goes wrong during the database access
*/
List
<
Horse
>
getOwnedHorses
(
Long
id
)
throws
NotFoundException
;
...
...
@@ -46,22 +46,22 @@ public interface OwnerService {
* @param owner to create
* @return the new owner
* @throws ValidationException will be thrown if something goes wrong during verification.
* @throws
DataAccess
Exception will be thrown if the owner could not be saved in the database.
* @throws
Persistence
Exception will be thrown if the owner could not be saved in the database.
*/
Owner
addOwner
(
Owner
owner
)
throws
ValidationException
,
DataAccess
Exception
;
Owner
addOwner
(
Owner
owner
)
throws
ValidationException
,
Persistence
Exception
;
/**
* @param owner that specifies the new owner values alongside with the id of the owner to update
* @return the updated owner
* @throws ValidationException will be thrown if something goes wrong during verification.
* @throws
DataAccess
Exception will be thrown if the owner could not be saved in the database.
* @throws
Persistence
Exception will be thrown if the owner could not be saved in the database.
*/
Owner
updateOwner
(
Owner
owner
)
throws
ValidationException
,
DataAccess
Exception
;
Owner
updateOwner
(
Owner
owner
)
throws
ValidationException
,
Persistence
Exception
;
/**
* @param id of the owner to delete
* @throws NotFoundException will be thrown if the owner could not be found in the system
* @throws
DataAccess
Exception will be thrown if the owner could not be deleted from the database
* @throws
Persistence
Exception will be thrown if the owner could not be deleted from the database
*/
void
deleteOwner
(
Long
id
)
throws
NotFoundException
,
DataAccess
Exception
;
void
deleteOwner
(
Long
id
)
throws
NotFoundException
,
Persistence
Exception
;
}
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java
View file @
1c31939b
...
...
@@ -2,6 +2,7 @@ package at.ac.tuwien.sepm.assignment.individual.service.impl;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.FileDao
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.HorseDao
;
import
at.ac.tuwien.sepm.assignment.individual.service.HorseService
;
...
...
@@ -10,7 +11,6 @@ import at.ac.tuwien.sepm.assignment.individual.util.Validator;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -53,21 +53,21 @@ public class SimpleHorseService implements HorseService {
}
@Override
public
Horse
addHorse
(
Horse
horse
)
throws
ValidationException
,
DataAccess
Exception
{
public
Horse
addHorse
(
Horse
horse
)
throws
ValidationException
,
Persistence
Exception
{
this
.
validator
.
validateNewHorse
(
horse
);
LOGGER
.
debug
(
"addHorse({})"
,
horse
.
toString
());
return
horseJdbcDao
.
addHorse
(
horse
);
}
@Override
public
Horse
updateHorse
(
Horse
horse
)
throws
ValidationException
,
DataAccess
Exception
,
IOException
{
public
Horse
updateHorse
(
Horse
horse
)
throws
ValidationException
,
Persistence
Exception
,
IOException
{
this
.
validator
.
validateUpdateHorse
(
horse
);
LOGGER
.
debug
(
"updateHorse({})"
,
horse
.
toString
());
return
horseJdbcDao
.
updateHorse
(
horse
);
}
@Override
public
void
deleteHorse
(
Long
id
)
throws
NotFoundException
,
DataAccess
Exception
,
IOException
{
public
void
deleteHorse
(
Long
id
)
throws
NotFoundException
,
Persistence
Exception
,
IOException
{
LOGGER
.
debug
(
"deleteHorse({})"
,
id
);
horseJdbcDao
.
deleteHorse
(
id
);
}
...
...
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleOwnerService.java
View file @
1c31939b
...
...
@@ -3,6 +3,7 @@ package at.ac.tuwien.sepm.assignment.individual.service.impl;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.entity.Owner
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.OwnerDao
;
import
at.ac.tuwien.sepm.assignment.individual.service.OwnerService
;
import
at.ac.tuwien.sepm.assignment.individual.util.ValidationException
;
...
...
@@ -15,7 +16,6 @@ import java.util.Map;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.stereotype.Service
;
@Service
...
...
@@ -57,21 +57,21 @@ public class SimpleOwnerService implements OwnerService {
}
@Override
public
Owner
addOwner
(
Owner
owner
)
throws
ValidationException
,
DataAccess
Exception
{
public
Owner
addOwner
(
Owner
owner
)
throws
ValidationException
,
Persistence
Exception
{
LOGGER
.
debug
(
"addOwner({})"
,
owner
);
this
.
validator
.
validateNewOwner
(
owner
);
return
ownerDao
.
addOwner
(
owner
);
}
@Override
public
Owner
updateOwner
(
Owner
owner
)
throws
ValidationException
,
DataAccess
Exception
{
public
Owner
updateOwner
(
Owner
owner
)
throws
ValidationException
,
Persistence
Exception
{
LOGGER
.
debug
(
"updateOwner({})"
,
owner
);
this
.
validator
.
validateUpdateOwner
(
owner
);
return
ownerDao
.
updateOwner
(
owner
);
}
@Override
public
void
deleteOwner
(
Long
id
)
throws
NotFoundException
,
DataAccess
Exception
{
public
void
deleteOwner
(
Long
id
)
throws
NotFoundException
,
Persistence
Exception
{
LOGGER
.
debug
(
"deleteOwner({})"
,
id
);
ownerDao
.
deleteOwner
(
id
);
}
...
...
backend/src/test/java/at/ac/tuwien/sepm/assignment/individual/unit/persistence/HorseDaoTestBase.java
View file @
1c31939b
...
...
@@ -5,11 +5,11 @@ import static org.junit.jupiter.api.Assertions.*;
import
at.ac.tuwien.sepm.assignment.individual.entity.Horse
;
import
at.ac.tuwien.sepm.assignment.individual.enums.ERace
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.HorseDao
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
java.io.IOException
;
import
java.sql.Date
;
...
...
@@ -81,10 +81,10 @@ public abstract class HorseDaoTestBase {
}
@Test
@DisplayName
(
"Adding a new horse with the incorrect parameters should throw
DataAccess
Exception"
)
public
void
addingNewHorse_incorrectParameters_shouldThrow
DataAccess
()
{
@DisplayName
(
"Adding a new horse with the incorrect parameters should throw
Persistence
Exception"
)
public
void
addingNewHorse_incorrectParameters_shouldThrow
Persistence
()
{
Horse
newHorse
=
new
Horse
(
"Zephyr"
,
"Nice horse"
,
(
short
)
80
,
Date
.
valueOf
(
"2020-01-01"
),
null
,
null
,
null
);
assertThrows
(
DataAccess
Exception
.
class
,
()
->
horseDao
.
addHorse
(
newHorse
));
assertThrows
(
Persistence
Exception
.
class
,
()
->
horseDao
.
addHorse
(
newHorse
));
}
@Test
...
...
@@ -117,8 +117,8 @@ public abstract class HorseDaoTestBase {
}
@Test
@DisplayName
(
"Updating a horse with the incorrect parameters should throw
DataAccess
Exception"
)
public
void
updatingHorse_incorrectParameters_shouldThrow
DataAccess
()
{
@DisplayName
(
"Updating a horse with the incorrect parameters should throw
Persistence
Exception"
)
public
void
updatingHorse_incorrectParameters_shouldThrow
Persistence
()
{
// Create horse
Horse
newHorse
=
new
Horse
(
"Zephyr"
,
"Nice horse"
,
(
short
)
4
,
Date
.
valueOf
(
"2020-01-01"
),
ERace
.
APPALOOSA
,
"files/test.png"
,
null
);
Horse
savedHorse
=
horseDao
.
addHorse
(
newHorse
);
...
...
@@ -132,7 +132,7 @@ public abstract class HorseDaoTestBase {
newHorse
.
setRace
(
null
);
newHorse
.
setImagePath
(
null
);
newHorse
.
setOwner
(
null
);
assertThrows
(
DataAccess
Exception
.
class
,
()
->
horseDao
.
updateHorse
(
newHorse
));
assertThrows
(
Persistence
Exception
.
class
,
()
->
horseDao
.
updateHorse
(
newHorse
));
}
@Test
...
...
backend/src/test/java/at/ac/tuwien/sepm/assignment/individual/unit/persistence/OwnerDaoTestBase.java
View file @
1c31939b
...
...
@@ -6,12 +6,12 @@ import at.ac.tuwien.sepm.assignment.individual.entity.Horse;
import
at.ac.tuwien.sepm.assignment.individual.entity.Owner
;
import
at.ac.tuwien.sepm.assignment.individual.enums.ERace
;
import
at.ac.tuwien.sepm.assignment.individual.exception.NotFoundException
;
import
at.ac.tuwien.sepm.assignment.individual.exception.PersistenceException
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.HorseDao
;
import
at.ac.tuwien.sepm.assignment.individual.persistence.OwnerDao
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.dao.DataIntegrityViolationException
;
import
java.io.IOException
;
...
...
@@ -108,10 +108,10 @@ public abstract class OwnerDaoTestBase {
}
@Test
@DisplayName
(
"Adding a new owner with the incorrect parameters should throw
DataAccess
Exception"
)
public
void
addingNewOwner_incorrectParameters_shouldThrow
DataAccess
()
{
@DisplayName
(
"Adding a new owner with the incorrect parameters should throw
Persistence
Exception"
)
public
void
addingNewOwner_incorrectParameters_shouldThrow
Persistence
()
{
Owner
newOwner
=
new
Owner
(
""
);
assertThrows
(
DataAccess
Exception
.
class
,
()
->
ownerDao
.
addOwner
(
newOwner
));
assertThrows
(
Persistence
Exception
.
class
,
()
->
ownerDao
.
addOwner
(
newOwner
));
}
@Test
...
...
@@ -133,8 +133,8 @@ public abstract class OwnerDaoTestBase {
}
@Test
@DisplayName
(
"Updating a owner with the incorrect parameters should throw
DataAccess
Exception"
)
public
void
updatingOwner_incorrectParameters_shouldThrow
DataAccess
()
{
@DisplayName
(
"Updating a owner with the incorrect parameters should throw
Persistence
Exception"
)
public
void
updatingOwner_incorrectParameters_shouldThrow
Persistence
()
{
// Create owner
Owner
newOwner
=
new
Owner
(
"Chad"
);
Owner
savedOwner
=
ownerDao
.
addOwner
(
newOwner
);
...
...
@@ -142,7 +142,7 @@ public abstract class OwnerDaoTestBase {
// Update owner
newOwner
.
setId
(
savedOwner
.
getId
());
newOwner
.
setName
(
""
);
assertThrows
(
DataAccess
Exception
.
class
,
()
->
ownerDao
.
updateOwner
(
newOwner
));
assertThrows
(
Persistence
Exception
.
class
,
()
->
ownerDao
.
updateOwner
(
newOwner
));
}
@Test
...
...
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