Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
7dc9d393
Commit
7dc9d393
authored
Jul 16, 2018
by
Matija Obreza
Browse files
Subsets model and API
parent
e18b62fe
Changes
22
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
7dc9d393
...
...
@@ -566,6 +566,7 @@
<includes>
<!-- List packages to be processed -->
<include>
org.genesys2.server.model
</include>
<include>
org.genesys2.server.model.*
</include>
</includes>
<outputDirectory>
target/generated-sources/querydsl
</outputDirectory>
<processor>
com.querydsl.apt.jpa.JPAAnnotationProcessor
</processor>
...
...
src/main/java/org/genesys2/server/
service/worker
/InvalidApiUsageException.java
→
src/main/java/org/genesys2/server/
exception
/InvalidApiUsageException.java
View file @
7dc9d393
/*
* Copyright 201
7
Global Crop Diversity Trust
/*
*
* Copyright 201
8
Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -12,8 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys2.server.
service.worker
;
*
*/
package
org.genesys2.server.
exception
;
/**
* Parent exception for cases where data does not match business logic.
...
...
src/main/java/org/genesys2/server/exception/NotFoundElement.java
0 → 100644
View file @
7dc9d393
/**
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.exception
;
/**
* This exception should generate when some element not found somewhere.
* Example: some element not found in DB by ID or UUId.
*
* @author Andrey Lugovskoy.
*/
public
class
NotFoundElement
extends
InvalidApiUsageException
{
private
static
final
long
serialVersionUID
=
6621976491018091330L
;
/**
* Instantiates a new not found element.
*/
public
NotFoundElement
()
{
}
/**
* Instantiates a new not found element.
*
* @param message the message
*/
public
NotFoundElement
(
final
String
message
)
{
super
(
message
);
}
/**
* Instantiates a new not found element.
*
* @param message the message
* @param cause the cause
*/
public
NotFoundElement
(
final
String
message
,
final
Throwable
cause
)
{
super
(
message
,
cause
);
}
/**
* Instantiates a new not found element.
*
* @param cause the cause
*/
public
NotFoundElement
(
final
Throwable
cause
)
{
super
(
cause
);
}
}
src/main/java/org/genesys2/server/model/impl/Subset.java
0 → 100644
View file @
7dc9d393
/**
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.model.impl
;
import
org.genesys.blocks.model.AuditedVersionedModel
;
import
org.genesys.blocks.security.model.AclAwareModel
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.FetchType
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.JoinTable
;
import
javax.persistence.Lob
;
import
javax.persistence.ManyToMany
;
import
javax.persistence.PrePersist
;
import
javax.persistence.Table
;
import
java.util.List
;
import
java.util.UUID
;
import
org.genesys2.server.model.genesys.AccessionId
;
import
org.hibernate.annotations.Type
;
@Entity
@Table
public
class
Subset
extends
AuditedVersionedModel
implements
AclAwareModel
{
/** The Constant serialVersionUID. */
private
static
final
long
serialVersionUID
=
7021405309572916429L
;
@Column
(
unique
=
true
,
updatable
=
false
,
nullable
=
false
,
columnDefinition
=
"binary(16)"
)
protected
UUID
uuid
;
@Column
protected
boolean
published
;
@Column
protected
String
title
;
@Column
@Lob
@Type
(
type
=
"org.hibernate.type.TextType"
)
protected
String
description
;
@Column
protected
String
publisher
;
@Column
protected
String
dateCreated
;
@Column
protected
String
rights
;
@ManyToMany
(
cascade
=
{},
fetch
=
FetchType
.
LAZY
)
@JoinTable
(
name
=
"SubsetAccessions"
,
joinColumns
=
@JoinColumn
(
name
=
"subsetId"
),
inverseJoinColumns
=
@JoinColumn
(
name
=
"acceId"
))
private
List
<
AccessionId
>
accessionIds
;
/**
* Generate UUID if missing
*/
@PrePersist
protected
void
prepersist
()
{
if
(
this
.
uuid
==
null
)
{
this
.
uuid
=
UUID
.
randomUUID
();
}
}
/**
* Gets the uuid.
*
* @return the uuid
*/
public
UUID
getUuid
()
{
return
uuid
;
}
/**
* Sets the uuid.
*
* @param uuid the new uuid
*/
public
void
setUuid
(
final
UUID
uuid
)
{
this
.
uuid
=
uuid
;
}
/**
* Checks if published.
*
* @return the published
*/
public
boolean
isPublished
()
{
return
published
;
}
/**
* Sets the published.
*
* @param published the new published
*/
public
void
setPublished
(
final
boolean
published
)
{
this
.
published
=
published
;
}
/**
* Gets the subset title.
*
* @return the subset title
*/
public
String
getTitle
()
{
return
title
;
}
/**
* Sets the subset title.
*
* @param title the new subset title
*/
public
void
setTitle
(
final
String
title
)
{
this
.
title
=
title
;
}
/**
* Gets the subset description.
*
* @return the subset description
*/
public
String
getDescription
()
{
return
description
;
}
/**
* Sets the subset description.
*
* @param description the new descriptor list
*/
public
void
setDescription
(
final
String
description
)
{
this
.
description
=
description
;
}
/**
* Gets the subset publisher.
*
* @return the subset publisher
*/
public
String
getPublisher
()
{
return
publisher
;
}
/**
* Sets the subset publisher.
*
* @param publisher the new subset publisher
*/
public
void
setPublisher
(
final
String
publisher
)
{
this
.
publisher
=
publisher
;
}
/**
* Gets the subset date created.
*
* @return the date created
*/
public
String
getDateCreated
()
{
return
dateCreated
;
}
/**
* Sets the date created.
*
* @param dateCreated the new date created
*/
public
void
setDateCreated
(
final
String
dateCreated
)
{
this
.
dateCreated
=
dateCreated
;
}
/**
* Gets the subset rights.
*
* @return the subset rights
*/
public
String
getRights
()
{
return
rights
;
}
/**
* Sets the subset rights.
*
* @param rights the new subset rights
*/
public
void
setRights
(
final
String
rights
)
{
this
.
rights
=
rights
;
}
/**
* Gets the accessionIds list.
*
* @return the accessionIds list
*/
public
List
<
AccessionId
>
getAccessionIds
()
{
return
accessionIds
;
}
/**
* Sets the accessionIds list.
*
* @param accessionIds the new accessionIds list
*/
public
void
setAccessionIds
(
final
List
<
AccessionId
>
accessionIds
)
{
this
.
accessionIds
=
accessionIds
;
}
}
src/main/java/org/genesys2/server/persistence/domain/AccessionIdRepository.java
View file @
7dc9d393
...
...
@@ -18,6 +18,7 @@ package org.genesys2.server.persistence.domain;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.UUID
;
import
org.genesys2.server.model.genesys.AccessionId
;
import
org.springframework.data.domain.Pageable
;
...
...
@@ -35,4 +36,6 @@ public interface AccessionIdRepository extends JpaRepository<AccessionId, Long>
@Query
(
"select id from AccessionId"
)
Collection
<
Long
>
findAllIds
();
AccessionId
findByUuid
(
UUID
uuid
);
}
src/main/java/org/genesys2/server/persistence/domain/SubsetRepository.java
0 → 100644
View file @
7dc9d393
/**
* Copyright 2018 Global Crop Diversity Trust
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.persistence.domain
;
import
java.util.UUID
;
import
org.genesys2.server.model.impl.Subset
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.querydsl.QueryDslPredicateExecutor
;
import
org.springframework.stereotype.Repository
;
/**
* The Class SubsetRepository.
*
* @author Maxym Borodenko
*/
@Repository
public
interface
SubsetRepository
extends
JpaRepository
<
Subset
,
Long
>,
QueryDslPredicateExecutor
<
Subset
>
{
/**
* Gets the subset by uuid.
*
* @param uuid the uuid
* @return the subset by uuid
*/
Subset
getByUuid
(
UUID
uuid
);
/**
* Gets the record by uuid and version.
*
* @param uuid the uuid
* @param version the version
* @return the by uuid and version
*/
Subset
getByUuidAndVersion
(
UUID
uuid
,
int
version
);
}
src/main/java/org/genesys2/server/service/SubsetService.java
0 → 100644
View file @
7dc9d393
/**
* Copyright 2018 Global Crop Diversity Trust
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.service
;
import
java.util.Set
;
import
java.util.UUID
;
import
org.genesys2.server.model.impl.Subset
;
import
org.genesys2.server.service.filter.SubsetFilter
;
import
org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
/**
* @author Maxym Borodenko
*/
public
interface
SubsetService
{
/**
* List published subsets matching the filter.
*
* @param filter filter data
* @param page Pageable
* @return list of Subset
*/
Page
<
Subset
>
list
(
SubsetFilter
filter
,
Pageable
page
);
/**
* Method creating Subset.
*
* @param subset new Subset
* @return saved Subset in db.
*/
Subset
create
(
Subset
subset
);
/**
* Load subset based on identifiers and version provided in the input.
*
* @param input query by example
* @return subset loaded from the database
*/
Subset
loadSubset
(
Subset
input
);
/**
* Load Subset.
*
* @param uuid the uuid
* @return the subset
*/
Subset
get
(
UUID
uuid
);
/**
* Load Subset.
*
* @param uuid the uuid
* @param version the version
* @return the subset
*/
Subset
get
(
UUID
uuid
,
int
version
);
/**
* Method updating Subset.
*
* @param subset new Subset
* @return updated Subset in db.
*/
Subset
update
(
Subset
subset
);
/**
* Remove subset.
*
* @param subset subset
* @return removed subset
*/
Subset
delete
(
Subset
subset
);
/**
* Method removing preserved accessionIds from Subset.
*
* @param input current Subset
* @param accesionsUuid the accessions UUIDs
* @return updated Subset in db.
*/
Subset
removeAccessions
(
Subset
input
,
Set
<
UUID
>
accesionsUuid
);
/**
* Method adding new accessionId to Subset.
*
* @param input current Subset
* @param accessionIds the accessions IDs
* @return updated Subset in db.
*/
Subset
addAccessions
(
Subset
input
,
Set
<
AccessionHeaderJson
>
accessionIds
);
}
src/main/java/org/genesys2/server/service/filter/SubsetFilter.java
0 → 100644
View file @
7dc9d393
/**
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.service.filter
;
import
static
org
.
genesys2
.
server
.
model
.
impl
.
QSubset
.
subset
;
import
java.util.Set
;
import
com.querydsl.core.BooleanBuilder
;
import
com.querydsl.core.types.Predicate
;
import
org.genesys.blocks.model.filters.AuditedVersionedModelFilter
;
import
org.genesys.blocks.model.filters.StringFilter
;
/**
* The Class SubsetFilter.
*
* @author Maxym Borodenko
*/
public
class
SubsetFilter
extends
AuditedVersionedModelFilter
{
/** The published. */
public
Boolean
published
;
/** The title. */
public
StringFilter
title
;
/** The description. */
public
StringFilter
description
;
/** The publisher. */
public
Set
<
String
>
publisher
;
/** The date created. */
public
StringFilter
dateCreated
;
/** The rights. */
public
Set
<
String
>
rights
;
/**
* Builds the query.
*
* @return the predicate
*/
public
Predicate
buildQuery
()
{
final
BooleanBuilder
and
=
new
BooleanBuilder
();
super
.
buildQuery
(
subset
.
_super
,
and
);
if
(
published
!=
null
)
{
and
.
and
(
subset
.
published
.
eq
(
published
));
}
if
(
title
!=
null
)
{
and
.
and
(
title
.
buildQuery
(
subset
.
title
));
}
if
(
description
!=
null
)
{
and
.
and
(
description
.
buildQuery
(
subset
.
description
));
}
if
((
publisher
!=
null
)
&&
!
publisher
.
isEmpty
())
{
and
.
and
(
subset
.
publisher
.
in
(
publisher
));
}
if
(
dateCreated
!=
null
)
{
and
.
and
(
dateCreated
.
buildQuery
(
subset
.
dateCreated
));
}
if
((
rights
!=
null
)
&&
!
rights
.
isEmpty
())
{
and
.
and
(
subset
.
rights
.
in
(
rights
));
}
return
and
;
}
}
src/main/java/org/genesys2/server/service/impl/SubsetServiceImpl.java
0 → 100644
View file @
7dc9d393
/**
* Copyright 2018 Global Crop Diversity Trust
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.service.impl
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
import
org.genesys.blocks.model.BasicModel
;
import
org.genesys2.server.exception.NotFoundElement
;
import
org.genesys2.server.model.genesys.AccessionId
;
import
org.genesys2.server.model.impl.Subset
;
import
org.genesys2.server.persistence.domain.AccessionIdRepository
;
import
org.genesys2.server.persistence.domain.AccessionRepository
;
import
org.genesys2.server.persistence.domain.FaoInstituteRepository
;
import
org.genesys2.server.persistence.domain.SubsetRepository
;