use of nl.nn.adapterframework.core.BytesResource in project iaf by ibissource.
the class LiquibaseMigrator method getChangeLog.
private Resource getChangeLog() {
AppConstants appConstants = AppConstants.getInstance(getApplicationContext().getClassLoader());
String changeLogFile = appConstants.getString("liquibase.changeLogFile", "DatabaseChangelog.xml");
URL resource = getResource(changeLogFile);
if (resource == null) {
String msg = "unable to find database changelog file [" + changeLogFile + "]";
msg += " classLoader [" + getConfigurationClassLoader() + "]";
log.debug(msg);
return null;
}
try {
return new BytesResource(resource.openStream(), changeLogFile);
} catch (IOException e) {
log.debug("unable to open or read changelog [" + changeLogFile + "]", e);
}
return null;
}
use of nl.nn.adapterframework.core.BytesResource 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();
}
Aggregations