-
Notifications
You must be signed in to change notification settings - Fork 18
Implement TemplatesDAO methods #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jburke-cadc
wants to merge
11
commits into
opencadc:main
Choose a base branch
from
jburke-cadc:templates-impl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1f8023f
added TemplateDAO int-test
jburke-cadc 60d3000
added ServiceDescriptors table to tap_schema db init
jburke-cadc c14eff4
TemplateDAO implemenation, update YoucatInitAction to use InitYoucatTS
jburke-cadc ecee7e9
Merge branch 'templates' into templates-impl
jburke-cadc b84c23e
Merge branch 'main' into templates-impl
jburke-cadc 07bc2a3
implement TemplateDAO methods
jburke-cadc d1bd11d
update TemplateDAO subject comparison check
jburke-cadc 665adeb
added InitDatabaseYoucat to create ServiceDescriptors table
jburke-cadc 8a0ba37
more carefully convert ownerID to a string
jburke-cadc 7401ea0
remove ServiceDescriptors class, use ServiceDescriptorTemplate as tab…
jburke-cadc 3d0f20a
rename InitDatabaseYoucat to InitDatabaseSD
jburke-cadc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
208 changes: 208 additions & 0 deletions
208
youcat/src/intTest/java/org/opencadc/youcat/TemplateDAOTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| /* | ||
| ************************************************************************ | ||
| ******************* CANADIAN ASTRONOMY DATA CENTRE ******************* | ||
| ************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** | ||
| * | ||
| * (c) 2025. (c) 2025. | ||
| * Government of Canada Gouvernement du Canada | ||
| * National Research Council Conseil national de recherches | ||
| * Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 | ||
| * All rights reserved Tous droits réservés | ||
| * | ||
| * NRC disclaims any warranties, Le CNRC dénie toute garantie | ||
| * expressed, implied, or énoncée, implicite ou légale, | ||
| * statutory, of any kind with de quelque nature que ce | ||
| * respect to the software, soit, concernant le logiciel, | ||
| * including without limitation y compris sans restriction | ||
| * any warranty of merchantability toute garantie de valeur | ||
| * or fitness for a particular marchande ou de pertinence | ||
| * purpose. NRC shall not be pour un usage particulier. | ||
| * liable in any event for any Le CNRC ne pourra en aucun cas | ||
| * damages, whether direct or être tenu responsable de tout | ||
| * indirect, special or general, dommage, direct ou indirect, | ||
| * consequential or incidental, particulier ou général, | ||
| * arising from the use of the accessoire ou fortuit, résultant | ||
| * software. Neither the name de l'utilisation du logiciel. Ni | ||
| * of the National Research le nom du Conseil National de | ||
| * Council of Canada nor the Recherches du Canada ni les noms | ||
| * names of its contributors may de ses participants ne peuvent | ||
| * be used to endorse or promote être utilisés pour approuver ou | ||
| * products derived from this promouvoir les produits dérivés | ||
| * software without specific prior de ce logiciel sans autorisation | ||
| * written permission. préalable et particulière | ||
| * par écrit. | ||
| * | ||
| * This file is part of the Ce fichier fait partie du projet | ||
| * OpenCADC project. OpenCADC. | ||
| * | ||
| * OpenCADC is free software: OpenCADC est un logiciel libre ; | ||
| * you can redistribute it and/or vous pouvez le redistribuer ou le | ||
| * modify it under the terms of modifier suivant les termes de | ||
| * the GNU Affero General Public la “GNU Affero General Public | ||
| * License as published by the License” telle que publiée | ||
| * Free Software Foundation, par la Free Software Foundation | ||
| * either version 3 of the : soit la version 3 de cette | ||
| * License, or (at your option) licence, soit (à votre gré) | ||
| * any later version. toute version ultérieure. | ||
| * | ||
| * OpenCADC is distributed in the OpenCADC est distribué | ||
| * hope that it will be useful, dans l’espoir qu’il vous | ||
| * but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE | ||
| * without even the implied GARANTIE : sans même la garantie | ||
| * warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ | ||
| * or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF | ||
| * PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence | ||
| * General Public License for Générale Publique GNU Affero | ||
| * more details. pour plus de détails. | ||
| * | ||
| * You should have received Vous devriez avoir reçu une | ||
| * a copy of the GNU Affero copie de la Licence Générale | ||
| * General Public License along Publique GNU Affero avec | ||
| * with OpenCADC. If not, see OpenCADC ; si ce n’est | ||
| * <http://www.gnu.org/licenses/>. pas le cas, consultez : | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| * : 5 $ | ||
| * | ||
| ************************************************************************ | ||
| */ | ||
|
|
||
| package org.opencadc.youcat; | ||
|
|
||
| import ca.nrc.cadc.auth.AuthenticationUtil; | ||
| import ca.nrc.cadc.auth.SSLUtil; | ||
| import ca.nrc.cadc.dali.tables.votable.VOTableGroup; | ||
| import ca.nrc.cadc.dali.tables.votable.VOTableResource; | ||
| import ca.nrc.cadc.db.ConnectionConfig; | ||
| import ca.nrc.cadc.db.DBConfig; | ||
| import ca.nrc.cadc.db.DBUtil; | ||
| import ca.nrc.cadc.util.FileUtil; | ||
| import ca.nrc.cadc.util.Log4jInit; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import javax.security.auth.Subject; | ||
| import javax.sql.DataSource; | ||
| import org.apache.log4j.Level; | ||
| import org.apache.log4j.Logger; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.opencadc.datalink.ServiceDescriptorTemplate; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
|
|
||
| public class TemplateDAOTest { | ||
| private static final Logger log = Logger.getLogger(TemplateDAOTest.class); | ||
|
|
||
| static { | ||
| Log4jInit.setLevel("org.opencadc.youcat", Level.DEBUG); | ||
| Log4jInit.setLevel("ca.nrc.cadc.tap", Level.DEBUG); | ||
| Log4jInit.setLevel("ca.nrc.cadc.db.version", Level.DEBUG); | ||
| } | ||
|
|
||
| static final String OWNER_CERT = "youcat-owner.pem"; // own test schema | ||
| static final String MEMBER_CERT = "youcat-member.pem"; // member of group | ||
|
|
||
| final Subject owner; | ||
| final Subject member; | ||
| final DataSource dataSource; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| JdbcTemplate jdbc = new JdbcTemplate(dataSource); | ||
| String sql = "DELETE FROM tap_schema.ServiceDescriptorTemplate"; | ||
| jdbc.update(sql); | ||
| log.debug(sql); | ||
| } | ||
|
|
||
| public TemplateDAOTest() { | ||
| try { | ||
| DBConfig conf = new DBConfig(); | ||
| ConnectionConfig cc = conf.getConnectionConfig("TAP_SCHEMA_TEST", "cadctest"); | ||
| dataSource = DBUtil.getDataSource(cc, true, true); | ||
| log.info("configured data source: " + cc.getServer() + "," + cc.getDatabase() + "," + cc.getDriver() + "," + cc.getURL()); | ||
|
|
||
| File cert = FileUtil.getFileFromResource(OWNER_CERT, AbstractTablesTest.class); | ||
| owner = SSLUtil.createSubject(cert); | ||
| log.debug("created owner: " + owner); | ||
|
|
||
| cert = FileUtil.getFileFromResource(MEMBER_CERT, AbstractTablesTest.class); | ||
| member = SSLUtil.createSubject(cert); | ||
| log.debug("created member: " + member); | ||
|
|
||
| } catch (Exception ex) { | ||
| log.error("setup failed", ex); | ||
| throw new IllegalStateException("failed to create DataSource", ex); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testTemplateDAO() { | ||
| try { | ||
| String testName = "test-template"; | ||
| String testTemplate = getTestTemplate("caomPublisherID"); | ||
|
|
||
| ServiceDescriptorTemplate expected = new ServiceDescriptorTemplate(testName, testTemplate); | ||
| expected.owner = owner; | ||
| expected.ownerID = AuthenticationUtil.getIdentityManager().toOwner(owner); | ||
| log.debug("expected: " + expected); | ||
|
|
||
| // PUT a descriptor | ||
| TemplateDAO templateDAO = new TemplateDAO(dataSource); | ||
| templateDAO.put(expected); | ||
|
|
||
| // GET the descriptor | ||
| ServiceDescriptorTemplate actual = templateDAO.get(owner, testName); | ||
| validate(expected, actual, true); | ||
|
|
||
| // UPDATE the descriptor | ||
| expected.owner = member; | ||
| expected.ownerID = AuthenticationUtil.getIdentityManager().toOwner(member); | ||
| templateDAO.put(expected); | ||
|
|
||
| // GET the descriptor again to verify update | ||
| actual = templateDAO.get(member, testName); | ||
| Assert.assertNotNull("expected null", actual); | ||
| validate(expected, actual, true); | ||
|
|
||
| // DELETE the descriptor | ||
| templateDAO.delete(member, testName); | ||
|
|
||
| // GET the descriptor again to verify deletion | ||
| actual = templateDAO.get(member, testName); | ||
| Assert.assertNull("expected null", actual); | ||
|
|
||
| } catch (Exception unexpected) { | ||
| log.error("unexpected exception", unexpected); | ||
| Assert.fail("unexpected exception: " + unexpected); | ||
| } | ||
| } | ||
|
|
||
| private void validate(ServiceDescriptorTemplate expected, ServiceDescriptorTemplate actual, boolean checkOwner) { | ||
| Assert.assertEquals(expected.getName(), actual.getName()); | ||
| Assert.assertEquals(expected.getTemplate(), actual.getTemplate()); | ||
| if (checkOwner) { | ||
| Assert.assertEquals(expected.owner, actual.owner); | ||
| Assert.assertEquals(expected.ownerID, actual.ownerID); | ||
| } | ||
| Assert.assertEquals(expected.getIdentifiers(), actual.getIdentifiers()); | ||
| Assert.assertNotNull(actual.getResource()); | ||
| VOTableResource expectedResource = expected.getResource(); | ||
| VOTableResource actualResource = actual.getResource(); | ||
| Assert.assertEquals(expectedResource.getType(), actualResource.getType()); | ||
| Assert.assertEquals(expectedResource.utype, actualResource.utype); | ||
| Assert.assertFalse(actual.getResource().getGroups().isEmpty()); | ||
| VOTableGroup expectedGroup = expectedResource.getGroups().get(0); | ||
| VOTableGroup actualGroup = actualResource.getGroups().get(0); | ||
| Assert.assertEquals(expectedGroup.getName(), actualGroup.getName()); | ||
| Assert.assertEquals(expectedGroup.getParams().size(), actualGroup.getParams().size()); | ||
| Assert.assertEquals(expectedGroup.getParams().get(0).getName(), actualGroup.getParams().get(0).getName()); | ||
| } | ||
|
|
||
| private String getTestTemplate(String identifier) throws IOException { | ||
| File testFile = FileUtil.getFileFromResource("valid-template.xml", TemplateDAOTest.class); | ||
| String template = Files.readString(testFile.toPath()); | ||
| return template.replace("IDENTIFIER", identifier); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <VOTABLE xmlns="http://www.ivoa.net/xml/VOTable/v1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4"> | ||
| <INFO name="name" value="placeholder: will be removed" ID="IDENTIFIER"/> | ||
| <RESOURCE type="meta" utype="adhoc:service"> | ||
| <PARAM name="standardID" datatype="char" arraysize="*" value="ivo://ivoa.net/std/DataLink#links-1.1" /> | ||
| <PARAM name="accessURL" datatype="char" arraysize="*" value="https://example.net/datalink/links" /> | ||
| <GROUP name="inputParams"> | ||
| <PARAM name="ID" datatype="char" arraysize="*" xtype="uri" ref="IDENTIFIER" value="" /> | ||
| </GROUP> | ||
| </RESOURCE> | ||
| </VOTABLE> |
100 changes: 100 additions & 0 deletions
100
youcat/src/main/java/org/opencadc/youcat/InitDatabaseYoucat.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| ************************************************************************ | ||
| ******************* CANADIAN ASTRONOMY DATA CENTRE ******************* | ||
| ************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** | ||
| * | ||
| * (c) 2025. (c) 2025. | ||
| * Government of Canada Gouvernement du Canada | ||
| * National Research Council Conseil national de recherches | ||
| * Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 | ||
| * All rights reserved Tous droits réservés | ||
| * | ||
| * NRC disclaims any warranties, Le CNRC dénie toute garantie | ||
| * expressed, implied, or énoncée, implicite ou légale, | ||
| * statutory, of any kind with de quelque nature que ce | ||
| * respect to the software, soit, concernant le logiciel, | ||
| * including without limitation y compris sans restriction | ||
| * any warranty of merchantability toute garantie de valeur | ||
| * or fitness for a particular marchande ou de pertinence | ||
| * purpose. NRC shall not be pour un usage particulier. | ||
| * liable in any event for any Le CNRC ne pourra en aucun cas | ||
| * damages, whether direct or être tenu responsable de tout | ||
| * indirect, special or general, dommage, direct ou indirect, | ||
| * consequential or incidental, particulier ou général, | ||
| * arising from the use of the accessoire ou fortuit, résultant | ||
| * software. Neither the name de l'utilisation du logiciel. Ni | ||
| * of the National Research le nom du Conseil National de | ||
| * Council of Canada nor the Recherches du Canada ni les noms | ||
| * names of its contributors may de ses participants ne peuvent | ||
| * be used to endorse or promote être utilisés pour approuver ou | ||
| * products derived from this promouvoir les produits dérivés | ||
| * software without specific prior de ce logiciel sans autorisation | ||
| * written permission. préalable et particulière | ||
| * par écrit. | ||
| * | ||
| * This file is part of the Ce fichier fait partie du projet | ||
| * OpenCADC project. OpenCADC. | ||
| * | ||
| * OpenCADC is free software: OpenCADC est un logiciel libre ; | ||
| * you can redistribute it and/or vous pouvez le redistribuer ou le | ||
| * modify it under the terms of modifier suivant les termes de | ||
| * the GNU Affero General Public la “GNU Affero General Public | ||
| * License as published by the License” telle que publiée | ||
| * Free Software Foundation, par la Free Software Foundation | ||
| * either version 3 of the : soit la version 3 de cette | ||
| * License, or (at your option) licence, soit (à votre gré) | ||
| * any later version. toute version ultérieure. | ||
| * | ||
| * OpenCADC is distributed in the OpenCADC est distribué | ||
| * hope that it will be useful, dans l’espoir qu’il vous | ||
| * but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE | ||
| * without even the implied GARANTIE : sans même la garantie | ||
| * warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ | ||
| * or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF | ||
| * PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence | ||
| * General Public License for Générale Publique GNU Affero | ||
| * more details. pour plus de détails. | ||
| * | ||
| * You should have received Vous devriez avoir reçu une | ||
| * a copy of the GNU Affero copie de la Licence Générale | ||
| * General Public License along Publique GNU Affero avec | ||
| * with OpenCADC. If not, see OpenCADC ; si ce n’est | ||
| * <http://www.gnu.org/licenses/>. pas le cas, consultez : | ||
| * <http://www.gnu.org/licenses/>. | ||
| * | ||
| * : 5 $ | ||
| * | ||
| ************************************************************************ | ||
| */ | ||
|
|
||
| package org.opencadc.youcat; | ||
|
|
||
| import ca.nrc.cadc.db.version.InitDatabase; | ||
| import java.net.URL; | ||
| import java.util.Collections; | ||
| import javax.sql.DataSource; | ||
|
|
||
| public class InitDatabaseYoucat extends InitDatabase { | ||
|
|
||
| public static final String MODEL_NAME = "DESCRIPTORS"; // must be <= 16 chars | ||
| public static final String MODEL_VERSION = "1.0.0"; | ||
| public static final String PREV_MODEL_VERSION = "1.0.0"; | ||
|
|
||
| static String[] CREATE_SQL = new String[] { | ||
| "tap_schema.ServiceDescriptorTemplate.sql" | ||
| }; | ||
|
|
||
| static String[] UPGRADE_SQL = new String[]{}; | ||
|
|
||
| public InitDatabaseYoucat(DataSource dataSource, String database, String schema) { | ||
| super(dataSource, database, schema, MODEL_NAME, MODEL_VERSION, PREV_MODEL_VERSION); | ||
| Collections.addAll(createSQL, CREATE_SQL); | ||
| Collections.addAll(upgradeSQL, UPGRADE_SQL); | ||
| } | ||
|
|
||
| @Override | ||
| protected URL findSQL(String fname) { | ||
| return InitDatabaseYoucat.class.getClassLoader().getResource("postgresql/" + fname); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably poor name because it implies a complete solution... how about InitDatabaseSD (for ServiceDescriptor, which is the core concept). Then this could be an optional feature and concept and config naming would match the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree and updated.