Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.DataSource; import org.joget.apps.app.service.AppUtil; import org.joget.apps.app.service.AppService; import org.joget.apps.app.model.AppDefinition; import org.joget.commons.util.LogUtil; import java.text.SimpleDateFormat; import java.io.File; import org.joget.commons.util.FileManager; // prepare the connection & appservice instance Connection con = null; AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService"); // prepare the filename common String path = "wflow/jwa_backups/"; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); String timestamp = sdf.format(new Date()); try { // retrieve connection from the default datasource DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource"); con = ds.getConnection(); if(!con.isClosed()) { // query the currently published app from db PreparedStatement stmt = con.prepareStatement("select appId as id, appVersion as version from app_app where published = 1"); ResultSet rs = stmt.executeQuery(); // loop through each eligible apps while (rs.next()) { AppDefinition appDef = appService.getAppDefinition(rs.getObject("id"), Long.toString(rs.getObject("version"))); // complete the filename for each app String filename = "APP_" + appDef.getId() + "-" + appDef.getVersion() + "-" + timestamp + ".jwa"; // create the file File test = new File(path+filename); // move the data to the created file above FileOutputStream fos = null; fos = new FileOutputStream(test); appService.exportApp(appDef.getId(), appDef.getVersion().toString(), fos); } } } catch(Exception e) { LogUtil.error("error", e, "test"); } finally { //always close the connection after used try { if(con != null) { con.close(); } } catch(SQLException e) {/* ignored */} }