Skip to content

Implement TemplatesDAO methods#212

Draft
jburke-cadc wants to merge 11 commits intoopencadc:mainfrom
jburke-cadc:templates-impl
Draft

Implement TemplatesDAO methods#212
jburke-cadc wants to merge 11 commits intoopencadc:mainfrom
jburke-cadc:templates-impl

Conversation

@jburke-cadc
Copy link
Contributor

A draft since it depends on cadc-tap-schema 1.28 which is not yet published and will not build.
I didn't add intTest's for the DAO list methods, wanted to see if IdentityManager usage is correct in the DAO before trying to find a way to use an IdentityManager in the intTest such that doesn't want to augment a Subject.

import java.util.Collections;
import javax.sql.DataSource;

public class InitYoucatTS extends InitDatabaseTS {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tight coupling is not going to actually work. There are both create and update sets of SQL and this looks plausible for create (although subtle). But for update it's never going to be viable to extend the base when there are conceptually two separate things.

As long as this is a youcat only feature, it has to have an independent InitDatabase extension with it's own previous and current version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a InitDatabaseYoucat class for the ServiceDescriptor table.


private String getOwnerID(Subject owner) {
IdentityManager identityManager = AuthenticationUtil.getIdentityManager();
return (String) identityManager.toOwner(owner);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast is wrong and can fail. IdentityManager.toOwner(Subject) returns Object, not String, and does not always return String. It's true that the reverse IdentityManager.toSubject(Object) should be able to reconstruct from a String, but toSubject has to do more anyway. toOwner could return a Principal or more primitive value or a String... not ideal and we could think about restricting the types from Object, but that requires some thought.

To support different types, you need to have code to convert the Object to a String to store it as a String

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not converting the ownerID to a string property, and checking it was null, was hiding a bug in the intTest, which isn't configuring a IdentityManager, hence getting the ownerID from an owner Subject returns null from the IdentityManager.


// generate the key for the KeyValue pair
private String generateKey(String name, Object ownerID) {
return name + ":" + ownerID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implicitly using ownerID.toString() here, which might not be right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

import ca.nrc.cadc.db.version.KeyValue;
import org.apache.log4j.Logger;

public class ServiceDescriptors extends KeyValue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The KeyValueDAO constructor takes a class and uses the class name as the name of the KeyValue table.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, but in this case the table stores ServiceDescritorTemplate(s), so you don't need to make up a new class just to name the table. There might be an argument to think about how we'll transition to a custom table in future and what that might be called... for now, just use the ServiceDescritorTemplate.class

aside: recall that in caom2 an Observation is stored in the Observation table, not Observations, uws.Job table, etc. Ignore the naming style in tap_schema core (with plurals)... that's a bad way to go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the initial use case for KeyVaueDAO: ModelVersion, non-plural

import java.util.Collections;
import javax.sql.DataSource;

public class InitDatabaseYoucat extends InitDatabase {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree and updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants