KEYCLOAK-2613 Add version to RealmRepresentation in JSON exports

This commit is contained in:
mposolda 2016-04-01 15:49:22 +02:00
parent f83b67cdf5
commit a4d9aaf916
5 changed files with 18 additions and 18 deletions

View file

@ -121,6 +121,8 @@ public class RealmRepresentation {
protected String resetCredentialsFlow;
protected String clientAuthenticationFlow;
protected String keycloakVersion;
@Deprecated
protected Boolean social;
@Deprecated
@ -814,6 +816,14 @@ public class RealmRepresentation {
this.clientAuthenticationFlow = clientAuthenticationFlow;
}
public String getKeycloakVersion() {
return keycloakVersion;
}
public void setKeycloakVersion(String keycloakVersion) {
this.keycloakVersion = keycloakVersion;
}
public List<GroupRepresentation> getGroups() {
return groups;
}

View file

@ -17,7 +17,6 @@
package org.keycloak.exportimport.dir;
import org.keycloak.representations.VersionRepresentation;
import org.keycloak.exportimport.util.ExportUtils;
import org.keycloak.exportimport.util.MultipleStepsExportProvider;
import org.keycloak.models.KeycloakSession;
@ -86,13 +85,6 @@ public class DirExportProvider extends MultipleStepsExportProvider {
ExportUtils.exportUsersToStream(session, realm, users, JsonSerialization.prettyMapper, os);
}
@Override
protected void writeVersion(String fileName, VersionRepresentation version) throws IOException {
File file = new File(this.rootDirectory, fileName);
FileOutputStream stream = new FileOutputStream(file);
JsonSerialization.prettyMapper.writeValue(stream, version);
}
@Override
public void close() {
}

View file

@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.keycloak.common.Version;
import org.keycloak.common.util.Base64;
import org.keycloak.models.*;
import org.keycloak.models.utils.ModelToRepresentation;
@ -39,6 +40,9 @@ public class ExportUtils {
public static RealmRepresentation exportRealm(KeycloakSession session, RealmModel realm, boolean includeUsers) {
RealmRepresentation rep = ModelToRepresentation.toRepresentation(realm, true);
// Project/product version
rep.setKeycloakVersion(Version.VERSION);
// Client Templates
List<ClientTemplateModel> templates = realm.getClientTemplates();
List<ClientTemplateRepresentation> templateReps = new ArrayList<>();

View file

@ -18,7 +18,6 @@
package org.keycloak.exportimport.util;
import org.jboss.logging.Logger;
import org.keycloak.representations.VersionRepresentation;
import org.keycloak.exportimport.ExportImportConfig;
import org.keycloak.exportimport.ExportProvider;
import org.keycloak.exportimport.UsersExportStrategy;
@ -57,14 +56,11 @@ public abstract class MultipleStepsExportProvider implements ExportProvider {
for (RealmModel realm : holder.realms) {
exportRealmImpl(factory, realm.getName());
}
writeVersion("version.json", VersionRepresentation.SINGLETON);
}
@Override
public void exportRealm(KeycloakSessionFactory factory, String realmName) throws IOException {
exportRealmImpl(factory, realmName);
writeVersion("version.json", VersionRepresentation.SINGLETON);
}
protected void exportRealmImpl(KeycloakSessionFactory factory, final String realmName) throws IOException {
@ -127,8 +123,6 @@ public abstract class MultipleStepsExportProvider implements ExportProvider {
protected abstract void writeUsers(String fileName, KeycloakSession session, RealmModel realm, List<UserModel> users) throws IOException;
protected abstract void writeVersion(String fileName, VersionRepresentation version) throws IOException;
public static class RealmsHolder {
List<RealmModel> realms;

View file

@ -166,8 +166,8 @@ public class ExportImportTest {
testFullExportImport();
// There should be 6 files in target directory (3 realm, 3 user, 1 version)
Assert.assertEquals(7, new File(targetDirPath).listFiles().length);
// There should be 6 files in target directory (3 realm, 3 user)
Assert.assertEquals(6, new File(targetDirPath).listFiles().length);
}
@Test
@ -180,9 +180,9 @@ public class ExportImportTest {
testRealmExportImport();
// There should be 3 files in target directory (1 realm, 3 user, 1 version)
// There should be 3 files in target directory (1 realm, 3 user)
File[] files = new File(targetDirPath).listFiles();
Assert.assertEquals(5, files.length);
Assert.assertEquals(4, files.length);
}
@Test