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
VOSpace INAF
vospace-rest
Commits
d2c453c1
Commit
d2c453c1
authored
Oct 06, 2021
by
Nicola Fulvio Calabria
Browse files
Added DAO for linked services
parent
3ecea878
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/it/inaf/oats/vospace/persistence/LinkedServiceDAO.java
0 → 100644
View file @
d2c453c1
/*
* This file is part of vospace-rest
* Copyright (C) 2021 Istituto Nazionale di Astrofisica
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package
it.inaf.oats.vospace.persistence
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
javax.sql.DataSource
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Repository
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
@Repository
public
class
LinkedServiceDAO
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
LinkedServiceDAO
.
class
);
private
static
final
ObjectMapper
MAPPER
=
new
ObjectMapper
();
private
final
JdbcTemplate
jdbcTemplate
;
@Autowired
public
LinkedServiceDAO
(
DataSource
dataSource
)
{
jdbcTemplate
=
new
JdbcTemplate
(
dataSource
);
}
boolean
isLinkedServiceUrl
(
String
targetUrl
)
{
String
sql
=
" SELECT COUNT(*) > 0\n"
+
"FROM linked_service\n"
+
"WHERE ? LIKE service_base_url || '%'"
;
return
jdbcTemplate
.
query
(
sql
,
ps
->
{
ps
.
setString
(
1
,
targetUrl
);
},
row
->
{
if
(!
row
.
next
())
{
throw
new
IllegalStateException
(
"Expected one result"
);
}
return
row
.
getBoolean
(
1
);
});
}
}
src/test/java/it/inaf/oats/vospace/persistence/LinkedServiceDAOTest.java
0 → 100644
View file @
d2c453c1
/*
* This file is part of vospace-rest
* Copyright (C) 2021 Istituto Nazionale di Astrofisica
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package
it.inaf.oats.vospace.persistence
;
import
javax.sql.DataSource
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.TestPropertySource
;
import
org.springframework.test.context.junit.jupiter.SpringExtension
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
@ExtendWith
(
SpringExtension
.
class
)
@ContextConfiguration
(
classes
=
{
DataSourceConfig
.
class
})
@TestPropertySource
(
locations
=
"classpath:test.properties"
)
public
class
LinkedServiceDAOTest
{
@Autowired
private
DataSource
dataSource
;
private
LinkedServiceDAO
dao
;
@BeforeEach
public
void
init
()
{
dao
=
new
LinkedServiceDAO
(
dataSource
);
}
@Test
void
testIsLinkedService
()
{
assertTrue
(
dao
.
isLinkedServiceUrl
(
"http://archives.ia2.inaf.it/files/aao/pippofile.fits.gz"
));
assertFalse
(
dao
.
isLinkedServiceUrl
(
"http://noportal.ia2.inaf.it/files/nop/nopippofile.tar.gz"
));
}
}
src/test/resources/test-data.sql
View file @
d2c453c1
INSERT
INTO
linked_service
(
service_base_url
)
VALUES
(
'http://archives.ia2.inaf.it/files/aao'
);
INSERT
INTO
storage
(
storage_type
,
base_path
,
base_url
,
hostname
)
VALUES
(
'cold'
,
'/ia2_tape/users'
,
NULL
,
'tape-server'
);
INSERT
INTO
storage
(
storage_type
,
base_path
,
base_url
,
hostname
)
VALUES
(
'hot'
,
'/mnt/hot_storage/users'
,
NULL
,
'server'
);
INSERT
INTO
storage
(
storage_type
,
base_path
,
base_url
,
hostname
)
VALUES
(
'local'
,
'/home'
,
NULL
,
'localhost'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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