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
18
Issues
18
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
8252d12f
Commit
8252d12f
authored
Aug 03, 2018
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added missing controller from the Catalog
- fixed NPE in Dataset#prepersist
parent
8990167d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
157 additions
and
11 deletions
+157
-11
src/main/java/org/genesys/catalog/api/v0/DatasetController.java
...in/java/org/genesys/catalog/api/v0/DatasetController.java
+8
-0
src/main/java/org/genesys/catalog/api/v0/LocationController.java
...n/java/org/genesys/catalog/api/v0/LocationController.java
+129
-0
src/main/java/org/genesys/catalog/model/dataset/Dataset.java
src/main/java/org/genesys/catalog/model/dataset/Dataset.java
+10
-11
src/test/java/org/genesys/test/catalog/services/DatasetServiceTest.java
...org/genesys/test/catalog/services/DatasetServiceTest.java
+10
-0
No files found.
src/main/java/org/genesys/catalog/api/v0/DatasetController.java
View file @
8252d12f
...
...
@@ -16,6 +16,7 @@
package
org.genesys.catalog.api.v0
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
...
...
@@ -244,6 +245,13 @@ public class DatasetController {
return
datasetService
.
addDescriptors
(
dataset
,
descriptors
.
toArray
(
new
Descriptor
[]
{}));
}
@PostMapping
(
value
=
"/set-descriptors/{UUID},{version}"
)
public
Dataset
updateDescriptors
(
@PathVariable
(
"UUID"
)
final
UUID
uuid
,
@PathVariable
(
"version"
)
final
int
version
,
@RequestBody
final
List
<
UUID
>
descriptorUuids
)
{
final
Dataset
dataset
=
datasetService
.
loadDataset
(
uuid
,
version
);
final
List
<
Descriptor
>
descriptors
=
descriptorUuids
.
stream
().
map
(
descriptorUuid
->
descriptorService
.
getDescriptor
(
descriptorUuid
)).
collect
(
Collectors
.
toList
());
return
datasetService
.
updateDescriptors
(
dataset
,
descriptors
);
}
/**
* Removes the descriptors.
*
...
...
src/main/java/org/genesys/catalog/api/v0/LocationController.java
0 → 100644
View file @
8252d12f
/*
* 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.genesys.catalog.api.v0
;
import
java.util.UUID
;
import
org.genesys.catalog.exceptions.NotFoundElement
;
import
org.genesys.catalog.model.dataset.Dataset
;
import
org.genesys.catalog.model.dataset.DatasetLocation
;
import
org.genesys.catalog.service.DatasetService
;
import
org.genesys.catalog.service.LocationService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* The Class LocationController.
*
* @author Andrey Lugovskoy.
*/
@RestController
@RequestMapping
(
LocationController
.
CONTROLLER_URL
)
public
class
LocationController
{
/** The Constant API_BASE. */
protected
static
final
String
CONTROLLER_URL
=
DatasetController
.
CONTROLLER_URL
+
"/{UUID}/location"
;
/** The dataset service. */
@Autowired
protected
DatasetService
datasetService
;
@Autowired
private
LocationService
locationService
;
/**
* List location.
*
* @param page the page
* @param pageSize the page size
* @param direction the direction
* @param sort the sort
* @param uuid the uuid
* @return the page
*/
@GetMapping
(
value
=
"/list"
)
public
Page
<
DatasetLocation
>
listLocation
(
@RequestParam
(
name
=
"p"
,
required
=
false
,
defaultValue
=
"0"
)
final
int
page
,
@RequestParam
(
name
=
"l"
,
required
=
false
,
defaultValue
=
"50"
)
final
int
pageSize
,
@RequestParam
(
name
=
"d"
,
required
=
false
,
defaultValue
=
"ASC"
)
final
Sort
.
Direction
direction
,
@RequestParam
(
name
=
"s"
,
required
=
false
,
defaultValue
=
"id"
)
final
String
[]
sort
,
@PathVariable
(
"UUID"
)
final
UUID
uuid
)
{
return
locationService
.
listLocation
(
uuid
,
new
PageRequest
(
page
,
Integer
.
min
(
pageSize
,
100
),
direction
,
sort
));
}
/**
* Load by uuid.
*
* @param locationUuid the location uuid
* @return the dataset location
* @throws NotFoundElement the not found element
*/
@GetMapping
(
value
=
"/{locationUuid}"
)
public
DatasetLocation
loadByUuid
(
@PathVariable
(
"locationUuid"
)
final
UUID
locationUuid
)
throws
NotFoundElement
{
return
locationService
.
loadLocation
(
locationUuid
);
}
/**
* Creates the location.
*
* @param datasetUuid the dataset uuid
* @param datasetLocation the dataset location
* @return the dataset location
* @throws NotFoundElement the not found element
*/
@PostMapping
(
value
=
"/create"
)
public
DatasetLocation
createLocation
(
@PathVariable
(
"UUID"
)
final
UUID
datasetUuid
,
@RequestBody
final
DatasetLocation
datasetLocation
)
throws
NotFoundElement
{
final
Dataset
dataset
=
datasetService
.
loadDataset
(
datasetUuid
);
return
locationService
.
createLocation
(
dataset
,
datasetLocation
);
}
/**
* Delete location.
*
* @param datasetUuid the dataset uuid
* @param datasetLocation the dataset location
* @return the dataset location
* @throws NotFoundElement the not found element
*/
@RequestMapping
(
value
=
"/delete"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
DELETE
})
public
DatasetLocation
deleteLocation
(
@PathVariable
(
"UUID"
)
final
UUID
datasetUuid
,
@RequestBody
final
DatasetLocation
datasetLocation
)
throws
NotFoundElement
{
final
Dataset
dataset
=
datasetService
.
loadDataset
(
datasetUuid
);
return
locationService
.
removeLocation
(
dataset
,
datasetLocation
);
}
/**
* Update location.
*
* @param datasetUuid the dataset uuid
* @param datasetLocation the dataset location
* @return the dataset location
* @throws NotFoundElement the not found element
*/
@PostMapping
(
value
=
"/update"
)
public
DatasetLocation
updateLocation
(
@PathVariable
(
"UUID"
)
final
UUID
datasetUuid
,
@RequestBody
final
DatasetLocation
datasetLocation
)
throws
NotFoundElement
{
final
Dataset
dataset
=
datasetService
.
loadDataset
(
datasetUuid
);
return
locationService
.
updateLocation
(
dataset
,
datasetLocation
);
}
}
src/main/java/org/genesys/catalog/model/dataset/Dataset.java
View file @
8252d12f
...
...
@@ -46,7 +46,7 @@ import java.util.Set;
* @author Maxim Borodenko
*/
@Entity
@Table
(
name
=
"dataset"
)
@Table
(
name
=
"dataset"
)
@Cacheable
@Audited
@Document
(
indexName
=
"catalog"
)
...
...
@@ -74,7 +74,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@CollectionTable
(
name
=
"dataset_accessions"
,
joinColumns
=
@JoinColumn
(
name
=
"datasetId"
),
// index
indexes
=
{
@Index
(
columnList
=
"datasetId, instCode, acceNumb"
),
@Index
(
columnList
=
"datasetId, genus"
)
})
@Field
(
type
=
FieldType
.
Object
)
@Field
(
type
=
FieldType
.
Object
)
@JsonView
({
JsonViews
.
Public
.
class
})
private
Set
<
AccessionIdentifier
>
accessionIdentifiers
;
...
...
@@ -90,21 +90,21 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@OneToMany
(
fetch
=
FetchType
.
LAZY
,
cascade
=
{})
@JoinTable
(
name
=
"dataset_repositoryfile"
,
joinColumns
=
@JoinColumn
(
name
=
"datasetId"
,
referencedColumnName
=
"id"
),
inverseJoinColumns
=
@JoinColumn
(
name
=
"repositoryfileId"
,
referencedColumnName
=
"id"
))
@OrderColumn
(
name
=
"position"
)
@Field
(
type
=
FieldType
.
Object
)
@Field
(
type
=
FieldType
.
Object
)
@JsonView
({
JsonViews
.
Public
.
class
})
private
List
<
RepositoryFile
>
repositoryFiles
;
/** The creators. */
@PublishValidation
(
innerCheck
=
true
)
@OneToMany
(
cascade
=
{
CascadeType
.
ALL
},
mappedBy
=
"dataset"
,
orphanRemoval
=
true
,
fetch
=
FetchType
.
LAZY
)
@Field
(
type
=
FieldType
.
Object
)
@Field
(
type
=
FieldType
.
Object
)
@JsonView
({
JsonViews
.
Public
.
class
})
private
List
<
DatasetCreator
>
creators
;
/** The locations. */
@PublishValidation
(
innerCheck
=
true
)
@OneToMany
(
cascade
=
{
CascadeType
.
ALL
},
mappedBy
=
"dataset"
,
orphanRemoval
=
true
,
fetch
=
FetchType
.
LAZY
)
@Field
(
type
=
FieldType
.
Object
)
@Field
(
type
=
FieldType
.
Object
)
@JsonView
({
JsonViews
.
Public
.
class
})
private
List
<
DatasetLocation
>
locations
;
...
...
@@ -192,14 +192,13 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
this
.
descriptorCount
=
descriptors
.
size
();
}
if
(
locations
!=
null
)
{
this
.
startDate
=
locations
.
stream
().
map
(
DatasetLocation:
:
getStartDate
).
min
(
String:
:
compareTo
).
orElse
(
null
);
this
.
endDate
=
locations
.
stream
().
map
(
DatasetLocation:
:
getEndDate
).
max
(
String:
:
compareTo
).
orElse
(
null
);
this
.
startDate
=
locations
.
stream
().
map
(
DatasetLocation:
:
getStartDate
).
filter
(
d
->
d
!=
null
).
min
(
String:
:
compareTo
).
orElse
(
null
);
this
.
endDate
=
locations
.
stream
().
map
(
DatasetLocation:
:
getEndDate
).
filter
(
d
->
d
!=
null
).
max
(
String:
:
compareTo
).
orElse
(
null
);
}
trimStringsToNull
();
}
/**
* Owner is the ACL parent object for the dataset
*/
...
...
@@ -313,7 +312,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
* @param startDate the new start date
*/
public
void
setStartDate
(
String
startDate
)
{
if
(
MCPDUtil
.
isMcpdDate
(
startDate
))
{
if
(
MCPDUtil
.
isMcpdDate
(
startDate
))
{
this
.
startDate
=
startDate
;
}
}
...
...
@@ -333,7 +332,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
* @param endDate the new start date
*/
public
void
setEndDate
(
String
endDate
)
{
if
(
MCPDUtil
.
isMcpdDate
(
endDate
))
{
if
(
MCPDUtil
.
isMcpdDate
(
endDate
))
{
this
.
endDate
=
endDate
;
}
}
...
...
src/test/java/org/genesys/test/catalog/services/DatasetServiceTest.java
View file @
8252d12f
...
...
@@ -661,6 +661,16 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
assertThat
(
loadedDataset
.
getLocations
(),
hasSize
(
1
));
assertEquals
(
savedLocation
.
getStartDate
(),
loadedDataset
.
getStartDate
());
assertEquals
(
savedLocation
.
getEndDate
(),
loadedDataset
.
getEndDate
());
savedLocation
.
setEndDate
(
null
);
savedLocation
.
setStartDate
(
null
);
savedLocation
=
locationService
.
updateLocation
(
loadedDataset
,
savedLocation
);
loadedDataset
=
datasetService
.
loadDataset
(
savedDataset
.
getUuid
());
assertThat
(
loadedDataset
.
getLocations
(),
hasSize
(
1
));
assertEquals
(
savedLocation
.
getStartDate
(),
loadedDataset
.
getStartDate
());
assertEquals
(
savedLocation
.
getEndDate
(),
loadedDataset
.
getEndDate
());
}
...
...
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