Skip to content

Commit

Permalink
Move Liberty OAuth tables to the FHIR_OAUTH schema and gen by default
Browse files Browse the repository at this point in the history
Previously, a user needed to create these tables themselves if they
wanted to use liberty as an OAuth 2.0 provider with a databaseStore
(e.g. to dynamically manage OAuth 2.0 clients).

Now these tables will be created/updated as part of the
fhir-persistence-schema create-schema/update-schema actions, or as part
of derby bootstrapping.

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Apr 21, 2020
1 parent 6625b99 commit 98daf11
Show file tree
Hide file tree
Showing 20 changed files with 337 additions and 79 deletions.
14 changes: 7 additions & 7 deletions docs/src/pages/guides/FHIRServerUsersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ To configure the FHIR server to use the JDBC persistence layer, complete the fol
1. First, modify the `fhirServer/persistence/factoryClassname` property in `fhir-server-config.json` to specify the JDBC persistence factory, like this:
```
{
fhirServer: {
"fhirServer": {
persistence: {
"persistence": {
"factoryClassname": "com.ibm.fhir.persistence.jdbc.FHIRPersistenceJDBCFactory",
}
Expand All @@ -232,13 +232,13 @@ To configure the FHIR server to use the JDBC persistence layer, complete the fol
2. Next, modify the `fhirServer/persistence/jdbc/dataSourceJndiName` property in `fhir-server-config.json` to specify the proxy datasource's JNDI name, like this:
```
{
fhirServer: {
"fhirServer": {
persistence: {
"persistence": {
"jdbc": {
dataSourceJndiName”: “jdbc/fhirProxyDataSource
"dataSourceJndiName": "jdbc/fhirProxyDataSource"
}
}
Expand Down Expand Up @@ -557,7 +557,7 @@ By default, notification messages are published for all _create_ and _update_ pe
"common":{
"includeResourceTypes":[
"Observation",
Patient
"Patient"
]
},
Expand Down Expand Up @@ -851,7 +851,7 @@ Response resource:
```

## 4.8 Using local references within request bundles
Inter-dependencies between resources are typically defined by one resource containing a field of type `Reference` which contains an _external reference_<sup id="a5">[5](#f5)</sup> to another resource. For example, an `Observation` resource could reference a `Patient` resource via the Observation's `subject` field. The value that is stored in the `Reference-type` field (for example, `subject` in the case of the `Observation` resource) could be an absolute URL, such as `https://fhirserver1:9443/fhir-server/api/v4/Patient/12345`, or a relative URL (for example, `Patient/12345`).
Inter-dependencies between resources are typically defined by one resource containing a field of type `Reference` which contains an _external reference_<sup id="a5">[5](#f5)</sup> to another resource. For example, an `Observation` resource could reference a `Patient` resource via the Observation's `subject` field. The value that is stored in the `Reference-type` field (for example, `subject` in the case of the `Observation` resource) could be an absolute URL, such as `https://fhirserver1:9443/fhir-server/api/v4/Patient/12345`, or a relative URL (for example, `Patient/12345`).

In order to establish a reference to a resource, you must first know its resource identifier. However, if you are using a request bundle to create both the referenced resource (`Patient` in this example) and the resource which references it (`Observation`), then it is impossible to know the `Patient`resource identifier before the request bundle has been process (that is, before the new `Patient` resource is created).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,9 @@ public void grantSequencePrivileges(String schemaName, String objectName, Collec


/**
* Create FHIR data and admin schemas
* Create a database schema
*
* @param schemaName
* @param adminSchemaName
*/
public void createFhirSchemas(String schemaName, String adminSchemaName);


public void createSchema(String schemaName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import com.ibm.fhir.database.utils.api.DuplicateNameException;
import com.ibm.fhir.database.utils.api.IConnectionProvider;
import com.ibm.fhir.database.utils.api.IDatabaseAdapter;
import com.ibm.fhir.database.utils.api.IDatabaseStatement;
Expand Down Expand Up @@ -499,4 +500,14 @@ public void grantSequencePrivileges(String schemaName, String variableName, Coll
logger.info("Applying: " + grant); // Grants are very useful to see logged
runStatement(grant);
}

@Override
public void createSchema(String schemaName) {
try {
String ddl = "CREATE SCHEMA " + schemaName;
runStatement(ddl);
} catch (DuplicateNameException e) {
logger.log(Level.WARNING, "The schema '" + schemaName + "' already exists; proceed with caution.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.logging.Logger;

import com.ibm.fhir.database.utils.api.DataAccessException;
import com.ibm.fhir.database.utils.api.DuplicateNameException;
import com.ibm.fhir.database.utils.api.IConnectionProvider;
import com.ibm.fhir.database.utils.api.IDatabaseStatement;
import com.ibm.fhir.database.utils.api.IDatabaseTarget;
Expand Down Expand Up @@ -431,22 +430,6 @@ public boolean checkCompatibility(String adminSchema) {
return true;
}

@Override
public void createFhirSchemas(String schemaName, String adminSchemaName) {
try {
String ddl = "CREATE SCHEMA " + schemaName;
runStatement(ddl);
} catch (DuplicateNameException e) {
logger.log(Level.WARNING, "The schema '" + schemaName + "' already exists; proceed with caution.");
}
try {
String ddl = "CREATE SCHEMA " + adminSchemaName;
runStatement(ddl);
} catch (DuplicateNameException e) {
logger.log(Level.WARNING, "The schema '" + adminSchemaName + "' already exists; proceed with caution.");
}
}

@Override
public void runStatement(IDatabaseStatement stmt) {
super.runStatement(stmt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,6 @@ protected List<String> prefixTenantColumn(String tenantColumnName, List<String>
return columns;
}

@Override
public void createFhirSchemas(String schemaName, String adminSchemaName) {
String ddl = "CREATE SCHEMA " + schemaName;
runStatement(ddl);
ddl = "CREATE SCHEMA " + adminSchemaName;
runStatement(ddl);
}

@Override
public void runStatement(IDatabaseStatement stmt) {
if (stmt instanceof AddForeignKeyConstraint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.ibm.fhir.database.utils.api.ConnectionDetails;
import com.ibm.fhir.database.utils.api.ConnectionException;
import com.ibm.fhir.database.utils.api.DataAccessException;
import com.ibm.fhir.database.utils.api.DuplicateNameException;
import com.ibm.fhir.database.utils.api.IDatabaseTranslator;
import com.ibm.fhir.database.utils.api.LockException;
import com.ibm.fhir.database.utils.api.UndefinedNameException;
Expand Down Expand Up @@ -52,7 +53,8 @@ public boolean isDuplicate(SQLException x) {

@Override
public boolean isAlreadyExists(SQLException x) {
return "42710".equals(x.getSQLState());
// X0Y68 is for a schema, X0Y32 is for an object (e.g. a table)
return "X0Y68".equals(x.getSQLState()) || "X0Y32".equals(x.getSQLState());
}

@Override
Expand Down Expand Up @@ -86,6 +88,9 @@ else if (isConnectionError(x)) {
else if (isDuplicate(x)) {
return new UniqueConstraintViolationException(x);
}
else if (isAlreadyExists(x)) {
return new DuplicateNameException(x);
}
else if (isUndefinedName(x)) {
return new UndefinedNameException(x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import com.ibm.fhir.database.utils.api.IDatabaseTypeAdapter;

/**
* Blob Column
* Binary Large OBject (BLOB) Column
*/
public class BlobColumn extends ColumnBase {

private final long size;

private final int inlineSize;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* (C) Copyright IBM Corp. 2020
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.database.utils.model;

import com.ibm.fhir.database.utils.api.IDatabaseTypeAdapter;

/**
* Character Large OBject (CLOB) Column
*/
public class ClobColumn extends ColumnBase {
public ClobColumn(String name, boolean nullable) {
super(name, nullable);
}

public ClobColumn(String name, boolean nullable, String defaultVal) {
super(name, nullable, defaultVal);
}

@Override
public String getTypeInfo(IDatabaseTypeAdapter adapter) {
return "CLOB";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019
* (C) Copyright IBM Corp. 2019, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -12,13 +12,16 @@
* An immutable definition of a column in a table
*/
public abstract class ColumnBase {

// Name of the column
private final String name;

// Does the column allow null values
private final boolean nullable;

// The default value for the column (usually null)
private final String defaultVal;

/**
* Protected constructor - for use by subclasses
* @param name
Expand All @@ -27,6 +30,19 @@ public abstract class ColumnBase {
protected ColumnBase(String name, boolean nullable) {
this.name = name;
this.nullable = nullable;
this.defaultVal = null;
}

/**
* Protected constructor - for use by subclasses
* @param name
* @param nullable
* @param defaultVal
*/
protected ColumnBase(String name, boolean nullable, String defaultVal) {
this.name = name;
this.nullable = nullable;
this.defaultVal = defaultVal;
}

/**
Expand All @@ -45,6 +61,14 @@ public boolean isNullable() {
return nullable;
}

/**
* Getter for the default value of this column
* @return possibly null
*/
public String getDefaultVal() {
return defaultVal;
}

/**
* Get the type info string
* @param adapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019
* (C) Copyright IBM Corp. 2019, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -16,19 +16,20 @@ public class ColumnDef implements Comparable<ColumnDef> {
private long size;
private Integer precision;
private int inlineSize;

private String defaultVal;

/**
* Public constructor
* @param name
*/
public ColumnDef(String name) {
this.name = name;
}

public String getName() {
return name;
}

public boolean isNullable() {
return nullable;
}
Expand All @@ -53,13 +54,22 @@ public Integer getPrecision() {
public void setPrecision(int precision) {
this.precision = precision;
}
public String getDefaultVal() {
return defaultVal;
}
/**
* @implNote Currently only works for CLOB columns
*/
public void setDefaultVal(String defaultVal) {
this.defaultVal = defaultVal;
}

@Override
public int compareTo(ColumnDef that) {
return this.name.compareTo(that.name);
}
@Override

@Override
public boolean equals(Object other) {
if (other instanceof ColumnDef) {
ColumnDef that = (ColumnDef)other;
Expand All @@ -69,8 +79,8 @@ public boolean equals(Object other) {
return false;
}
}
@Override

@Override
public int hashCode() {
return this.name.hashCode();
}
Expand All @@ -82,5 +92,4 @@ public int getInlineSize() {
public void setInlineSize(int inlineSize) {
this.inlineSize = inlineSize;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ public List<ColumnBase> buildColumns() {
case BLOB:
column = new BlobColumn(cd.getName(), cd.getSize(), cd.getInlineSize(), cd.isNullable());
break;
case CLOB:
column = new ClobColumn(cd.getName(), cd.isNullable(), cd.getDefaultVal());
break;
default:
throw new IllegalStateException("Unsupported column type: " + cd.getColumnType().name());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019
* (C) Copyright IBM Corp. 2019, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -18,5 +18,6 @@ public enum ColumnType {
DECIMAL,
DOUBLE,
TIMESTAMP,
BLOB
BLOB,
CLOB
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019
* (C) Copyright IBM Corp. 2019, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -10,7 +10,7 @@
* Basic set of privileges that can be granted to a database object
*/
public enum Privilege {

ALL,
SELECT,
INSERT,
UPDATE,
Expand Down
Loading

0 comments on commit 98daf11

Please sign in to comment.