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
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
601a2a36
Commit
601a2a36
authored
Nov 22, 2018
by
Maxym Borodenko
Committed by
Matija Obreza
Nov 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable @Validation in the service layer
parent
c4557538
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
54 additions
and
34 deletions
+54
-34
pom.xml
pom.xml
+0
-5
src/main/java/org/genesys/catalog/model/dataset/Dataset.java
src/main/java/org/genesys/catalog/model/dataset/Dataset.java
+4
-0
src/main/java/org/genesys/catalog/model/dataset/DatasetCreator.java
...ava/org/genesys/catalog/model/dataset/DatasetCreator.java
+4
-0
src/main/java/org/genesys/catalog/model/dataset/DatasetLocation.java
...va/org/genesys/catalog/model/dataset/DatasetLocation.java
+4
-0
src/main/java/org/genesys/catalog/service/DatasetService.java
...main/java/org/genesys/catalog/service/DatasetService.java
+10
-8
src/main/java/org/genesys/catalog/service/impl/DatasetServiceImpl.java
.../org/genesys/catalog/service/impl/DatasetServiceImpl.java
+2
-0
src/main/java/org/genesys2/server/model/impl/Subset.java
src/main/java/org/genesys2/server/model/impl/Subset.java
+0
-4
src/main/java/org/genesys2/server/model/impl/SubsetCreator.java
...in/java/org/genesys2/server/model/impl/SubsetCreator.java
+4
-0
src/main/java/org/genesys2/server/service/KPIService.java
src/main/java/org/genesys2/server/service/KPIService.java
+4
-2
src/main/java/org/genesys2/server/service/SubsetService.java
src/main/java/org/genesys2/server/service/SubsetService.java
+6
-4
src/main/java/org/genesys2/server/service/impl/AccessionServiceImpl.java
...rg/genesys2/server/service/impl/AccessionServiceImpl.java
+2
-0
src/main/java/org/genesys2/server/service/impl/KPIServiceImpl.java
...java/org/genesys2/server/service/impl/KPIServiceImpl.java
+3
-4
src/main/java/org/genesys2/server/service/impl/SubsetServiceImpl.java
...a/org/genesys2/server/service/impl/SubsetServiceImpl.java
+3
-5
src/main/java/org/genesys2/spring/config/ApplicationConfig.java
...in/java/org/genesys2/spring/config/ApplicationConfig.java
+6
-0
src/test/java/org/genesys/test/catalog/services/SubsetServiceTest.java
.../org/genesys/test/catalog/services/SubsetServiceTest.java
+2
-2
No files found.
pom.xml
View file @
601a2a36
...
...
@@ -619,11 +619,6 @@
<artifactId>
jna
</artifactId>
<version>
4.5.2
</version>
</dependency>
<dependency>
<groupId>
javax.validation
</groupId>
<artifactId>
validation-api
</artifactId>
<version>
1.1.0.Final
</version>
</dependency>
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-validator
</artifactId>
...
...
src/main/java/org/genesys/catalog/model/dataset/Dataset.java
View file @
601a2a36
...
...
@@ -16,6 +16,7 @@
package
org.genesys.catalog.model.dataset
;
import
javax.persistence.*
;
import
javax.validation.constraints.Size
;
import
java.util.List
;
import
java.util.Set
;
...
...
@@ -112,10 +113,12 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
private
List
<
DatasetLocation
>
locations
;
/** The min start date of all locations */
@Size
(
max
=
8
)
@Column
(
length
=
8
)
private
String
startDate
;
/** The max end date of all locations */
@Size
(
max
=
8
)
@Column
(
length
=
8
)
private
String
endDate
;
...
...
@@ -176,6 +179,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
private
String
source
;
/** Information about time of creation of the dataset. */
@Size
(
max
=
200
)
@Column
(
nullable
=
true
,
length
=
200
)
private
String
created
;
...
...
src/main/java/org/genesys/catalog/model/dataset/DatasetCreator.java
View file @
601a2a36
...
...
@@ -21,6 +21,8 @@ import org.genesys.catalog.annotations.PublishValidation;
import
org.genesys.catalog.service.PublishValidationInterface
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Size
;
import
java.util.Map
;
/**
...
...
@@ -57,6 +59,8 @@ public class DatasetCreator extends UuidModel implements PublishValidationInterf
/** The full name. */
@PublishValidation
@NotNull
@Size
(
max
=
200
)
@Column
(
length
=
200
,
nullable
=
false
)
private
String
fullName
;
...
...
src/main/java/org/genesys/catalog/model/dataset/DatasetLocation.java
View file @
601a2a36
...
...
@@ -22,6 +22,7 @@ import org.genesys.catalog.service.PublishValidationInterface;
import
org.genesys2.util.MCPDUtil
;
import
javax.persistence.*
;
import
javax.validation.constraints.Size
;
import
java.util.Map
;
/**
...
...
@@ -68,14 +69,17 @@ public class DatasetLocation extends UuidModel implements PublishValidationInter
private
Double
decimalLongitude
;
/** ISO3 country code of the location */
@Size
(
max
=
3
)
@Column
(
length
=
3
)
private
String
countryCode
;
/** The start date */
@Size
(
max
=
8
)
@Column
(
length
=
8
)
private
String
startDate
;
/** The end date */
@Size
(
max
=
8
)
@Column
(
length
=
8
)
private
String
endDate
;
...
...
src/main/java/org/genesys/catalog/service/DatasetService.java
View file @
601a2a36
...
...
@@ -40,6 +40,8 @@ import org.springframework.data.domain.Page;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.validation.Valid
;
/**
* The Interface DatasetService.
*/
...
...
@@ -54,7 +56,7 @@ public interface DatasetService {
* @param input new Dataset
* @return saved Dataset in db.
*/
Dataset
createDataset
(
Dataset
input
);
Dataset
createDataset
(
@Valid
Dataset
input
);
/**
* Method updating Dataset.
...
...
@@ -62,7 +64,7 @@ public interface DatasetService {
* @param input new Dataset
* @return updated Dataset in db.
*/
Dataset
updateDataset
(
Dataset
input
);
Dataset
updateDataset
(
@Valid
Dataset
input
);
/**
* Method updating accessionRefs in Dataset.
...
...
@@ -71,7 +73,7 @@ public interface DatasetService {
* @param accessionRefs new accessionRefs
* @return updated Dataset in db.
*/
Dataset
updateAccessionRefs
(
Dataset
dataset
,
Set
<
AccessionRef
>
accessionRefs
);
Dataset
updateAccessionRefs
(
Dataset
dataset
,
@Valid
Set
<
AccessionRef
>
accessionRefs
);
/**
* Method adding new descriptor to Dataset.
...
...
@@ -219,7 +221,7 @@ public interface DatasetService {
* @return updated Dataset
* @throws NotFoundElement the not found element
*/
Dataset
upsertAccessions
(
Dataset
dataset
,
Set
<
AccessionRef
>
accessionRefs
)
throws
NotFoundElement
;
Dataset
upsertAccessions
(
Dataset
dataset
,
@Valid
Set
<
AccessionRef
>
accessionRefs
)
throws
NotFoundElement
;
/**
* Puts the dataset into the Review state to be reviewed by admin.
...
...
@@ -293,7 +295,7 @@ public interface DatasetService {
* @return created DatasetCreator
* @throws NotFoundElement throws if don't match the version
*/
DatasetCreator
createDatasetCreator
(
Dataset
dataset
,
DatasetCreator
input
)
throws
NotFoundElement
;
DatasetCreator
createDatasetCreator
(
Dataset
dataset
,
@Valid
DatasetCreator
input
)
throws
NotFoundElement
;
/**
* Remove DatasetCreator of Dataset.
...
...
@@ -349,7 +351,7 @@ public interface DatasetService {
* @return the dataset creator
* @throws NotFoundElement the not found element
*/
DatasetCreator
updateDatasetCreator
(
Dataset
dataset
,
DatasetCreator
datasetCreator
)
throws
NotFoundElement
;
DatasetCreator
updateDatasetCreator
(
Dataset
dataset
,
@Valid
DatasetCreator
datasetCreator
)
throws
NotFoundElement
;
/**
* Autocomplete creators.
...
...
@@ -368,7 +370,7 @@ public interface DatasetService {
* @return added DatasetLocation
* @throws NotFoundElement the not found element
*/
DatasetLocation
createLocation
(
Dataset
dataset
,
DatasetLocation
input
)
throws
NotFoundElement
;
DatasetLocation
createLocation
(
Dataset
dataset
,
@Valid
DatasetLocation
input
)
throws
NotFoundElement
;
/**
* Method for remove DatasetLocation of Dataset.
...
...
@@ -424,7 +426,7 @@ public interface DatasetService {
* @return updated location
* @throws NotFoundElement the not found element
*/
DatasetLocation
updateLocation
(
Dataset
dataset
,
DatasetLocation
input
)
throws
NotFoundElement
;
DatasetLocation
updateLocation
(
Dataset
dataset
,
@Valid
DatasetLocation
input
)
throws
NotFoundElement
;
/**
* Clear accession references across all Datasets for specified accessions.
...
...
src/main/java/org/genesys/catalog/service/impl/DatasetServiceImpl.java
View file @
601a2a36
...
...
@@ -85,6 +85,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Isolation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.google.common.collect.Lists
;
...
...
@@ -96,6 +97,7 @@ import com.querydsl.core.types.Predicate;
*/
@Service
(
"catalogDatasetService"
)
@Transactional
(
readOnly
=
true
)
@Validated
public
class
DatasetServiceImpl
implements
DatasetService
{
/** The dataset versions repository. */
...
...
src/main/java/org/genesys2/server/model/impl/Subset.java
View file @
601a2a36
...
...
@@ -35,7 +35,6 @@ import javax.persistence.OneToMany;
import
javax.persistence.PrePersist
;
import
javax.persistence.PreUpdate
;
import
javax.persistence.Table
;
import
javax.validation.Valid
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Size
;
...
...
@@ -85,7 +84,6 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
@Column
(
length
=
100
)
protected
String
dateCreated
;
/** The wiews code. */
@NotNull
@Size
(
max
=
8
)
...
...
@@ -93,7 +91,6 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
private
String
wiewsCode
;
/** The institute. */
@NotNull
@ManyToOne
(
cascade
=
{},
optional
=
false
)
@JoinColumn
(
name
=
"institute_id"
,
updatable
=
false
)
@JsonView
({
JsonViews
.
Public
.
class
})
...
...
@@ -106,7 +103,6 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
indexes
=
{
@Index
(
columnList
=
"subsetId, instCode, acceNumb"
),
@Index
(
columnList
=
"subsetId, genus"
)
})
@Field
(
type
=
FieldType
.
Object
)
@JsonIgnore
@Valid
private
Set
<
AccessionRef
>
accessionRefs
;
/** The accession count. */
...
...
src/main/java/org/genesys2/server/model/impl/SubsetCreator.java
View file @
601a2a36
...
...
@@ -21,6 +21,8 @@ import org.genesys.catalog.annotations.PublishValidation;
import
org.genesys.catalog.service.PublishValidationInterface
;
import
javax.persistence.*
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Size
;
import
java.util.Map
;
/**
...
...
@@ -57,6 +59,8 @@ public class SubsetCreator extends UuidModel implements PublishValidationInterfa
/** The full name. */
@PublishValidation
@NotNull
@Size
(
max
=
200
)
@Column
(
length
=
200
,
nullable
=
false
)
private
String
fullName
;
...
...
src/main/java/org/genesys2/server/service/KPIService.java
View file @
601a2a36
...
...
@@ -28,6 +28,8 @@ import org.genesys2.server.model.kpi.Observation;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
javax.validation.Valid
;
public
interface
KPIService
{
KPIParameter
save
(
KPIParameter
parameter
);
...
...
@@ -38,7 +40,7 @@ public interface KPIService {
KPIParameter
delete
(
KPIParameter
parameter
);
<
T
extends
Dimension
<?>>
T
save
(
T
dimension
);
<
T
extends
Dimension
<?>>
T
save
(
@Valid
T
dimension
);
Dimension
<?>
getDimension
(
long
id
);
...
...
@@ -48,7 +50,7 @@ public interface KPIService {
<
T
>
Set
<
T
>
getValues
(
Dimension
<
T
>
loadedJpa
);
Execution
save
(
Execution
execution
);
Execution
save
(
@Valid
Execution
execution
);
Execution
getExecution
(
long
id
);
...
...
src/main/java/org/genesys2/server/service/SubsetService.java
View file @
601a2a36
...
...
@@ -31,6 +31,8 @@ import org.genesys2.server.service.filter.SubsetFilter;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
javax.validation.Valid
;
/**
* @author Maxym Borodenko
*/
...
...
@@ -78,7 +80,7 @@ public interface SubsetService {
* @param source the source
* @return saved Subset in db.
*/
Subset
create
(
FaoInstitute
institute
,
Subset
source
);
Subset
create
(
FaoInstitute
institute
,
@Valid
Subset
source
);
/**
* Load subset based on identifiers and version provided in the input.
...
...
@@ -111,7 +113,7 @@ public interface SubsetService {
* @param subset new Subset
* @return updated Subset in db.
*/
Subset
update
(
Subset
subset
);
Subset
update
(
@Valid
Subset
subset
);
/**
* Remove subset.
...
...
@@ -175,7 +177,7 @@ public interface SubsetService {
* @return created SubsetCreator
* @throws NotFoundElement throws if don't match the version
*/
SubsetCreator
createSubsetCreator
(
Subset
Subset
,
SubsetCreator
input
)
throws
NotFoundElement
;
SubsetCreator
createSubsetCreator
(
Subset
Subset
,
@Valid
SubsetCreator
input
)
throws
NotFoundElement
;
/**
* Remove SubsetCreator of Subset.
...
...
@@ -241,7 +243,7 @@ public interface SubsetService {
* @return the Subset creator
* @throws NotFoundElement the not found element
*/
SubsetCreator
updateSubsetCreator
(
Subset
Subset
,
SubsetCreator
SubsetCreator
)
throws
NotFoundElement
;
SubsetCreator
updateSubsetCreator
(
Subset
Subset
,
@Valid
SubsetCreator
SubsetCreator
)
throws
NotFoundElement
;
/**
* Autocomplete creators.
...
...
src/main/java/org/genesys2/server/service/impl/AccessionServiceImpl.java
View file @
601a2a36
...
...
@@ -52,6 +52,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.data.domain.Pageable
;
...
...
@@ -83,6 +84,7 @@ public class AccessionServiceImpl implements AccessionService {
@Autowired
private
JPAQueryFactory
jpaQueryFactory
;
@Lazy
@Autowired
private
DatasetService
datasetService
;
...
...
src/main/java/org/genesys2/server/service/impl/KPIServiceImpl.java
View file @
601a2a36
...
...
@@ -60,6 +60,7 @@ import org.springframework.validation.annotation.Validated;
@Service
@Transactional
(
readOnly
=
true
)
@Validated
public
class
KPIServiceImpl
implements
KPIService
{
public
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
KPIServiceImpl
.
class
);
...
...
@@ -118,8 +119,7 @@ public class KPIServiceImpl implements KPIService {
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#dimension, 'ADMINISTRATION')"
)
@Override
@Transactional
@Validated
public
<
T
extends
Dimension
<?>>
T
save
(
@Valid
T
dimension
)
{
public
<
T
extends
Dimension
<?>>
T
save
(
T
dimension
)
{
LOG
.
debug
(
"Persising dimension {}"
,
dimension
);
return
lazyLoad
(
dimensionRepository
.
save
(
dimension
));
}
...
...
@@ -174,8 +174,7 @@ public class KPIServiceImpl implements KPIService {
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#execution, 'ADMINISTRATION')"
)
@Override
@Transactional
@Validated
public
Execution
save
(
@Valid
Execution
execution
)
{
public
Execution
save
(
Execution
execution
)
{
Execution
target
=
executionRepository
.
findByName
(
execution
.
getName
());
if
(
target
==
null
)
{
target
=
execution
;
...
...
src/main/java/org/genesys2/server/service/impl/SubsetServiceImpl.java
View file @
601a2a36
...
...
@@ -69,7 +69,6 @@ import org.springframework.validation.annotation.Validated;
import
com.querydsl.core.BooleanBuilder
;
import
com.querydsl.core.types.Predicate
;
import
javax.validation.Valid
;
/**
* The Class SubsetServiceImpl.
...
...
@@ -78,6 +77,7 @@ import javax.validation.Valid;
*/
@Service
@Transactional
(
readOnly
=
true
)
@Validated
public
class
SubsetServiceImpl
implements
SubsetService
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
SubsetServiceImpl
.
class
);
...
...
@@ -152,8 +152,7 @@ public class SubsetServiceImpl implements SubsetService {
@Override
@Transactional
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE')"
)
@Validated
public
Subset
create
(
final
FaoInstitute
institute
,
@Valid
final
Subset
source
)
{
public
Subset
create
(
final
FaoInstitute
institute
,
final
Subset
source
)
{
LOG
.
info
(
"Create Subset."
);
if
(!
StringUtils
.
equals
(
institute
.
getCode
(),
source
.
getWiewsCode
()))
{
throw
new
InvalidApiUsageException
(
"Institute code of the subset does not match the code of Institute"
);
...
...
@@ -254,8 +253,7 @@ public class SubsetServiceImpl implements SubsetService {
@Override
@Transactional
@PreAuthorize
(
"hasRole('ADMINISTRATOR') or hasPermission(#source, 'WRITE')"
)
@Validated
public
Subset
update
(
@Valid
final
Subset
source
)
{
public
Subset
update
(
final
Subset
source
)
{
LOG
.
info
(
"Update Subset."
);
final
Subset
subset
=
loadSubset
(
source
);
copyValues
(
subset
,
source
);
...
...
src/main/java/org/genesys2/spring/config/ApplicationConfig.java
View file @
601a2a36
...
...
@@ -42,6 +42,7 @@ import org.springframework.core.io.FileSystemResource;
import
org.springframework.core.io.Resource
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.validation.beanvalidation.MethodValidationPostProcessor
;
@Configuration
@Import
({
HazelcastConfig
.
class
,
CommonConfig
.
class
,
SchedulerConfig
.
class
,
DatabaseConfig
.
class
,
TemplatingConfig
.
class
,
MailConfig
.
class
,
OAuth2ServerConfig
.
class
,
SecurityConfig
.
class
,
CacheConfig
.
class
,
...
...
@@ -127,4 +128,9 @@ public class ApplicationConfig {
// This provides static access to current application context
return
new
CurrentApplicationContext
();
}
@Bean
public
MethodValidationPostProcessor
methodValidationPostProcessor
()
{
return
new
MethodValidationPostProcessor
();
}
}
src/test/java/org/genesys/test/catalog/services/SubsetServiceTest.java
View file @
601a2a36
...
...
@@ -208,11 +208,11 @@ public class SubsetServiceTest extends CatalogServiceTest {
private
Subset
createSubset
(
UUID
uuid
)
{
subset
=
new
Subset
();
subset
.
setTitle
(
"Subset"
);
subset
.
setWiewsCode
(
"
TEST
"
);
subset
.
setWiewsCode
(
"
0000
"
);
subset
.
setInstitute
(
faoInstitute
);
subset
.
setUuid
(
uuid
);
return
subset
Repository
.
save
(
subset
);
return
subset
Service
.
create
(
faoInstitute
,
subset
);
}
private
FaoInstitute
createInstitute
()
{
...
...
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