Commit 6a26bbe7 authored by Daniel Gerhardt's avatar Daniel Gerhardt

Fix property condition which enables v2 to v3 migrations

Migrations are once again enabled if `migrate-from` property is set.
Code has been refactored to use `@ConditionalOnProperty` instead of a
custom implementation for `@Conditional`.
parent 4a9f6e69
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2019 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.persistence.couchdb.migrations;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.stereotype.Component;
@Component
public class MigrateFromLegacyCondition implements Condition {
@Override
public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) {
final String migrateFrom = context.getEnvironment().getProperty("couchdb.migrate-from");
return migrateFrom != null && !migrateFrom.isEmpty();
}
}
......@@ -32,9 +32,10 @@ import org.ektorp.DocumentNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Conditional;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import de.thm.arsnova.config.properties.CouchDbProperties;
import de.thm.arsnova.model.Answer;
import de.thm.arsnova.model.Comment;
import de.thm.arsnova.model.Content;
......@@ -57,8 +58,10 @@ import de.thm.arsnova.persistence.couchdb.support.PagedMangoResponse;
*
* @author Daniel Gerhardt
*/
@Conditional(MigrateFromLegacyCondition.class)
@Service
@ConditionalOnProperty(
name = "migrate-from",
prefix = CouchDbProperties.PREFIX)
public class V2ToV3Migration implements Migration {
private static final String ID = "20170914131300";
private static final int LIMIT = 200;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment