use of nl.nn.adapterframework.jdbc.migration.DatabaseMigratorBase in project iaf by ibissource.
the class ShowLiquibaseScript method getConfigurations.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/jdbc/liquibase")
@Produces(MediaType.APPLICATION_JSON)
public Response getConfigurations() throws ApiException {
List<String> configNames = new ArrayList<String>();
for (Configuration config : getIbisManager().getConfigurations()) {
DatabaseMigratorBase databaseMigrator = config.getBean("jdbcMigrator", DatabaseMigratorBase.class);
if (databaseMigrator.hasMigrationScript()) {
configNames.add(config.getName());
}
}
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("configurationsWithLiquibaseScript", configNames);
return Response.status(Response.Status.OK).entity(resultMap).build();
}
use of nl.nn.adapterframework.jdbc.migration.DatabaseMigratorBase in project iaf by ibissource.
the class ShowLiquibaseScript method generateSQL.
@POST
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/jdbc/liquibase")
@Produces(MediaType.APPLICATION_JSON)
public Response generateSQL(MultipartBody inputDataMap) throws ApiException {
Response.ResponseBuilder response = Response.noContent();
InputStream file = null;
if (inputDataMap.getAttachment("file") != null) {
file = resolveTypeFromMap(inputDataMap, "file", InputStream.class, null);
}
String configuration = resolveStringFromMap(inputDataMap, "configuration", null);
if (configuration == null && file == null) {
return response.status(Response.Status.BAD_REQUEST).build();
}
Writer writer = new StringBuilderWriter();
Configuration config = getIbisManager().getConfiguration(configuration);
try {
DatabaseMigratorBase databaseMigrator = config.getBean("jdbcMigrator", DatabaseMigratorBase.class);
if (file != null) {
String filename = inputDataMap.getAttachment("file").getContentDisposition().getParameter("filename");
if (filename.endsWith(".xml")) {
databaseMigrator.update(writer, new BytesResource(file, filename));
} else {
try (ZipInputStream stream = new ZipInputStream(file)) {
ZipEntry entry;
while ((entry = stream.getNextEntry()) != null) {
databaseMigrator.update(writer, new BytesResource(StreamUtil.dontClose(stream), entry.getName()));
}
}
}
} else {
databaseMigrator.update(writer);
}
} catch (Exception e) {
throw new ApiException("Error generating SQL script", e);
}
String result = writer.toString();
if (StringUtils.isEmpty(result)) {
throw new ApiException("Make sure liquibase xml script exists for configuration [" + configuration + "]");
}
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("result", result);
return Response.status(Response.Status.CREATED).entity(resultMap).build();
}
use of nl.nn.adapterframework.jdbc.migration.DatabaseMigratorBase in project iaf by ibissource.
the class ShowLiquibaseScript method downloadScript.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/jdbc/liquibase/download")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadScript() throws ApiException {
List<Configuration> configurations = new ArrayList<Configuration>();
for (Configuration config : getIbisManager().getConfigurations()) {
DatabaseMigratorBase databaseMigrator = config.getBean("jdbcMigrator", DatabaseMigratorBase.class);
if (databaseMigrator.hasMigrationScript()) {
configurations.add(config);
}
}
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException, WebApplicationException {
try (ZipOutputStream zos = new ZipOutputStream(out)) {
for (Configuration configuration : configurations) {
AppConstants appConstants = AppConstants.getInstance(configuration.getClassLoader());
String changeLogFile = appConstants.getString("liquibase.changeLogFile", "DatabaseChangelog.xml");
try (InputStream file = configuration.getClassLoader().getResourceAsStream(changeLogFile)) {
if (file != null) {
ZipEntry entry = new ZipEntry(changeLogFile);
zos.putNextEntry(entry);
zos.write(StreamUtil.streamToByteArray(file, false));
zos.closeEntry();
}
}
}
} catch (IOException e) {
throw new ApiException("Failed to create zip file with scripts.", e);
}
}
};
return Response.ok(stream).type(MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment; filename=\"DatabaseChangelog.zip\"").build();
}
Aggregations