Repository: incubator-fineract Updated Branches: refs/heads/0.5.0-incubating 8cc4b6e4f -> cd75af296
Fix for resolving scorecards, and replacing dead fk relation Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/0a4dc11a Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/0a4dc11a Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/0a4dc11a Branch: refs/heads/0.5.0-incubating Commit: 0a4dc11a8783925177a7944cb796c66bedfeaa96 Parents: e79d51e Author: Markus Geiss <mge...@mifos.org> Authored: Fri Nov 18 14:29:25 2016 +0100 Committer: Markus Geiss <mge...@mifos.org> Committed: Fri Nov 18 14:29:25 2016 +0100 ---------------------------------------------------------------------- .../fineract/spm/api/ScorecardApiResource.java | 4 +- ...__spm_replace_dead_fk_with_exisiting_one.sql | 49 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/0a4dc11a/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java index 9c4ed7d..84987da 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/spm/api/ScorecardApiResource.java @@ -76,7 +76,7 @@ public class ScorecardApiResource { final List<Scorecard> scorecards = this.scorecardService.findBySurvey(survey); - if (scorecards == null) { + if (scorecards != null) { return ScorecardMapper.map(scorecards); } @@ -105,7 +105,7 @@ public class ScorecardApiResource { final Survey survey = findSurvey(surveyId); final Client client = this.clientRepositoryWrapper.findOneWithNotFoundDetection(clientId); final List<Scorecard> scorecards = this.scorecardService.findBySurveyAndClient(survey, client); - if (scorecards == null) { + if (scorecards != null) { return ScorecardMapper.map(scorecards); } return Collections.EMPTY_LIST; http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/0a4dc11a/fineract-provider/src/main/resources/sql/migrations/core_db/V323__spm_replace_dead_fk_with_exisiting_one.sql ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/resources/sql/migrations/core_db/V323__spm_replace_dead_fk_with_exisiting_one.sql b/fineract-provider/src/main/resources/sql/migrations/core_db/V323__spm_replace_dead_fk_with_exisiting_one.sql new file mode 100644 index 0000000..06b880e --- /dev/null +++ b/fineract-provider/src/main/resources/sql/migrations/core_db/V323__spm_replace_dead_fk_with_exisiting_one.sql @@ -0,0 +1,49 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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. +-- + +DROP PROCEDURE IF EXISTS remove_anonymous_fk; + +DELIMITER $$ + +CREATE PROCEDURE remove_anonymous_fk (IN referencee VARCHAR(255), IN referenced VARCHAR(255)) + BEGIN + DECLARE fk2drop VARCHAR(255); + + SELECT + CONSTRAINT_NAME + FROM + INFORMATION_SCHEMA.KEY_COLUMN_USAGE + WHERE + TABLE_NAME = referencee + AND REFERENCED_TABLE_NAME = referenced + INTO fk2drop; + + SET @alter_stmt = concat('ALTER TABLE ',referencee,' DROP FOREIGN KEY ',fk2drop); + PREPARE pstmt FROM @alter_stmt; + EXECUTE pstmt; + DEALLOCATE PREPARE pstmt; + END $$ + +DELIMITER ; + +CALL remove_anonymous_fk('m_survey_scorecards', 'm_appusers'); + +ALTER TABLE `m_survey_scorecards` ADD FOREIGN KEY `m_appuser` (`user_id`); + +DROP PROCEDURE IF EXISTS remove_anonymous_fk;