Skip to content

Commit

Permalink
merged develop into release/1.0-develop
Browse files Browse the repository at this point in the history
manually resolve merge conflicts
  • Loading branch information
mlm483 committed Nov 18, 2024
2 parents 2c5ec7f + 893ebe0 commit 6afa355
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
USER_ID=<user id of system user>
GROUP_ID=<group id of system user>

ORCID_SANDBOX_AUTHENTICATION=<true or false; true=>use the Sandbox Orcid, false=>use the Production Orcid. Defaults to false.>

# Authentication variables
OAUTH_CLIENT_ID=<oauth app client id>
OAUTH_CLIENT_SECRET=<ouath_client_secret goes here>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* 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.breedinginsight.db.migration;

import lombok.extern.slf4j.Slf4j;
import org.breedinginsight.daos.UserDAO;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.jooq.DSLContext;

import javax.inject.Inject;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

@Slf4j
public class V1_32_0__Set_Dev_Admin_Email extends BaseJavaMigration {

@Inject
private DSLContext dsl;
@Inject
private UserDAO userDAO;

final private String ORCID_SANDBOX_AUTHENTICATION = "orcid-sandbox-authentication";

public void migrate(Context context) throws Exception {
Map<String, String> placeholders = context.getConfiguration().getPlaceholders();
boolean isOrcidSandboxAuthentication = Boolean.parseBoolean( placeholders.get(ORCID_SANDBOX_AUTHENTICATION) );
updateDevAdminUser(context, isOrcidSandboxAuthentication);
//Must delete user "Chris Tucker" before adding the new Constraint (User "Chris Tucker" is added by migration V0.5.2__populate-user-data.sql.
// It would violate the new constraint)
// PS -- We miss Chris Tucker.
deleteUserChris(context);
addConstraint(context);
}

private void updateDevAdminUser(Context context, boolean isOrcidSandboxAuthentication) throws SQLException {
String biDevAdminUserEmail = isOrcidSandboxAuthentication ?
"[email protected]" : "[email protected]";
try (Statement update = context.getConnection().createStatement()) {
String sql = "UPDATE bi_user SET email='" + biDevAdminUserEmail + "' WHERE NULLIF(email,'') IS NULL AND bi_user.name='BI-DEV Admin'";
log.debug(sql);
update.executeUpdate(sql);
}
}

private void deleteUserChris(Context context) throws SQLException {
try (Statement delete = context.getConnection().createStatement()) {
String sql = "DELETE FROM bi_user WHERE name = 'Chris Tucker' AND email IS NULL";
log.debug(sql);
delete.executeUpdate(sql);
}
}

private void addConstraint(Context context) throws SQLException {
final String CONSTRAINT_NAME = "email_orcid";
// First, drop the constraint if it already exist.
try (Statement altTable = context.getConnection().createStatement()) {
String sql = "ALTER TABLE bi_user DROP CONSTRAINT IF EXISTS "+ CONSTRAINT_NAME;
log.debug(sql);
altTable.executeUpdate(sql);
}

// Add new constraint
try (Statement altTable = context.getConnection().createStatement()) {
String sql = "ALTER TABLE bi_user\n" +
"ADD CONSTRAINT " +CONSTRAINT_NAME+ " CHECK ( (email IS NOT NULL ) OR (orcid IS NULL) ) ;";
log.debug(sql);
altTable.executeUpdate(sql);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public ValidationErrors checkTraitFieldsFormat(List<Trait> traits, TraitValidato
}
return errors;
}

public List<Trait> checkDuplicateTraitsExistingByName(UUID programId, List<Trait> traits){

List<Trait> duplicates = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ flyway:
placeholders:
default-url: ${brapi.server.default-url}
brapi-reference-source: ${brapi.server.reference-source}
orcid-sandbox-authentication: ${ORCID_SANDBOX_AUTHENTICATION:false}
out-of-order: true
jooq:
datasources:
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
# limitations under the License.
#

version=v1.0.0+872
versionInfo=https://github.com/Breeding-Insight/bi-api/commit/8b73c45263b416ed0944240f6da23c2810cdd11c

version=v1.1.0+887
versionInfo=https://github.com/Breeding-Insight/bi-api/commit/b7d65b01c976e1c729ef9bb450143e63dad4c014
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void getDataResponseMetadataFilterSuccess() {

// Check our page numbers weren't altered by the filtered
assertEquals(1, data.getAsJsonPrimitive("totalPages").getAsInt(), "Default total pages is incorrect");
assertEquals(38, data.getAsJsonPrimitive("totalCount").getAsInt(), "Default total count is incorrect");
assertEquals(37, data.getAsJsonPrimitive("totalCount").getAsInt(), "Default total count is incorrect");
assertEquals(50, data.getAsJsonPrimitive("pageSize").getAsInt(), "Default page size is incorrect");
assertEquals(1, data.getAsJsonPrimitive("currentPage").getAsInt(), "Default current page is incorrect");
}
Expand Down

0 comments on commit 6afa355

Please sign in to comment.