Add documentation

This commit is contained in:
René Pfeuffer
2019-06-21 15:32:25 +02:00
parent e1eb7caeab
commit 553997e7f0
7 changed files with 61 additions and 5 deletions

View File

@@ -0,0 +1,15 @@
package sonia.scm.update;
import java.util.Map;
public class GroupV1PropertyReader implements V1PropertyReader {
@Override
public String getStoreName() {
return "group-properties-v1";
}
@Override
public Instance createInstance(Map<String, V1Properties> all) {
return new MapBasedPropertyReaderInstance(all);
}
}

View File

@@ -0,0 +1,15 @@
package sonia.scm.update;
import java.util.Map;
public class UserV1PropertyReader implements V1PropertyReader {
@Override
public String getStoreName() {
return "user-properties-v1";
}
@Override
public Instance createInstance(Map<String, V1Properties> all) {
return new MapBasedPropertyReaderInstance(all);
}
}

View File

@@ -1,5 +1,14 @@
package sonia.scm.update;
/**
* Use this to access old properties from an instance of SCM-Manager v1.
*/
public interface V1PropertyDAO {
/**
* Creates an instance of a property reader to process old properties.
* @param reader The reader for the origin of the properties (for example
* {@link V1PropertyReader#REPOSITORY_PROPERTY_READER} for properties of repositories).
* @return The reader instance.
*/
V1PropertyReader.Instance getProperties(V1PropertyReader reader);
}

View File

@@ -5,15 +5,31 @@ import java.util.function.BiConsumer;
public interface V1PropertyReader {
V1PropertyReader REPOSITORY_PROPERTY_READER = new RepositoryV1PropertyReader();
V1PropertyReader USER_PROPERTY_READER = new RepositoryV1PropertyReader();
V1PropertyReader GROUP_PROPERTY_READER = new RepositoryV1PropertyReader();
String getStoreName();
Instance createInstance(Map<String, V1Properties> all);
interface Instance {
/**
* Will call the given consumer for each id of the corresponding entity with its list of
* properties converted from v1.
* For example for repositories this will call the consumer with the id of each repository
* that had properties attached in v1.
*/
void forEachEntry(BiConsumer<String, V1Properties> propertiesForNameConsumer);
/**
* Filters for entities only having at least one property with a given key name.
*/
Instance havingAnyOf(String... keys);
/**
* Filters for entities only having properties for all given key name.
*/
Instance havingAllOf(String... keys);
}
}

View File

@@ -30,6 +30,7 @@ import java.util.Optional;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static sonia.scm.update.V1PropertyReader.GROUP_PROPERTY_READER;
import static sonia.scm.version.Version.parse;
@Extension
@@ -51,7 +52,7 @@ public class XmlGroupV1UpdateStep implements UpdateStep {
this.groupDAO = groupDAO;
this.propertyStore = configurationEntryStoreFactory
.withType(V1Properties.class)
.withName("group-properties-v1")
.withName(GROUP_PROPERTY_READER.getStoreName())
.build();
}

View File

@@ -5,7 +5,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.SCMContextProvider;
import sonia.scm.migration.UpdateException;
import sonia.scm.migration.UpdateStep;
import sonia.scm.plugin.Extension;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryPermission;
@@ -15,7 +14,6 @@ import sonia.scm.store.ConfigurationEntryStoreFactory;
import sonia.scm.store.StoreConstants;
import sonia.scm.update.CoreUpdateStep;
import sonia.scm.update.V1Properties;
import sonia.scm.update.RepositoryV1PropertyReader;
import sonia.scm.version.Version;
import javax.inject.Inject;
@@ -38,6 +36,7 @@ import java.util.stream.Stream;
import static java.util.Collections.emptyList;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static sonia.scm.update.V1PropertyReader.REPOSITORY_PROPERTY_READER;
import static sonia.scm.version.Version.parse;
/**
@@ -82,7 +81,7 @@ public class XmlRepositoryV1UpdateStep implements CoreUpdateStep {
this.injector = injector;
this.propertyStore = configurationEntryStoreFactory
.withType(V1Properties.class)
.withName(new RepositoryV1PropertyReader().getStoreName())
.withName(REPOSITORY_PROPERTY_READER.getStoreName())
.build();
}

View File

@@ -31,6 +31,7 @@ import java.util.Optional;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static sonia.scm.update.V1PropertyReader.USER_PROPERTY_READER;
import static sonia.scm.version.Version.parse;
@Extension
@@ -50,7 +51,7 @@ public class XmlUserV1UpdateStep implements UpdateStep {
this.configurationEntryStoreFactory = configurationEntryStoreFactory;
this.propertyStore = configurationEntryStoreFactory
.withType(V1Properties.class)
.withName("user-properties-v1")
.withName(USER_PROPERTY_READER.getStoreName())
.build();
}