use of org.compiere.model.MMigration in project adempiere by adempiere.
the class MigrationApply method doIt.
@Override
protected String doIt() throws Exception {
if (Ini.isPropertyBool(Ini.P_LOGMIGRATIONSCRIPT)) {
addLog(Msg.getMsg(getCtx(), "LogMigrationScriptFlagIsSetMessage"));
return "@Error@";
}
// Use a null transaction to generate a read only query
// Doesn't lock table
MMigration migration = new MMigration(getCtx(), getRecord_ID(), null);
if (migration.is_new()) {
addLog(Msg.getMsg(getCtx(), "NoMigrationMessage"));
//return;
return "@Error@";
}
migration.setIsForce(isForce());
try {
addLog(migration.apply());
} catch (AdempiereException e) {
addLog(e.getMessage());
if (// abort on first error
!isForce())
throw new AdempiereException(e.getMessage(), e);
}
return "@OK@";
}
use of org.compiere.model.MMigration in project adempiere by adempiere.
the class MigrationCreate method doIt.
/**
*
* Process to create migration from selected records
*
* @author Paul Bowden, Adaxa Pty Ltd
*
*/
@Override
protected String doIt() throws Exception {
MMigration migration = new MMigration(getCtx(), 0, get_TrxName());
MTable table = MTable.get(getCtx(), tableId);
String whereClause;
List<PO> pos;
if (recordId > 0) {
pos = new ArrayList<PO>(1);
pos.add(table.getPO(recordId, get_TrxName()));
} else {
String where = "EntityType = ?";
pos = table.createQuery(where, get_TrxName()).list();
}
for (PO po : pos) {
POInfo info = POInfo.getPOInfo(getCtx(), tableId, get_TrxName());
MMigrationStep step = new MMigrationStep(migration, po, info, MMigrationStep.ACTION_Insert);
}
return "@OK@";
}
use of org.compiere.model.MMigration in project adempiere by adempiere.
the class MigrationFromXML method loadFile.
private void loadFile(File file) throws SAXException, IOException {
if (!file.exists())
return;
if (!file.getName().endsWith(".xml"))
return;
if (file.getName().equals("build.xml"))
return;
log.log(Level.CONFIG, "Loading file: " + file);
Document doc = builder.parse(file);
NodeList migrations = doc.getDocumentElement().getElementsByTagName("Migration");
for (int i = 0; i < migrations.getLength(); i++) {
Element element = (Element) migrations.item(i);
// Top level - create a new transaction for every migration and commit
Trx.run(trxName -> {
Properties ctx = Env.getCtx();
MMigration migration;
try {
migration = MMigration.fromXmlNode(ctx, element, trxName);
if (migration == null) {
log.log(Level.CONFIG, "XML file not a Migration. Skipping.");
return;
}
if (isApply()) {
if (MMigration.STATUSCODE_Applied.equals(migration.getStatusCode())) {
log.log(Level.CONFIG, migration.toString() + " ---> Migration already applied - skipping.");
return;
}
if (MMigration.STATUSCODE_Failed.equals(migration.getStatusCode()) || MMigration.STATUSCODE_PartiallyApplied.equals(migration.getStatusCode())) {
log.log(Level.CONFIG, migration.toString() + " ---> Migration exists but has to be rolled back.");
applyMigration(migration.getCtx(), migration.getAD_Migration_ID(), trxName);
}
applyMigration(migration.getCtx(), migration.getAD_Migration_ID(), trxName);
}
} catch (AdempiereException | SQLException e) {
if (!isForce()) {
throw new AdempiereException("Loading migration from " + file.toString() + " failed.", e);
}
}
});
}
}
use of org.compiere.model.MMigration in project adempiere by adempiere.
the class MigrationToXML method doIt.
@Override
protected String doIt() throws Exception {
MMigration migration = new MMigration(getCtx(), migrationId, get_TrxName());
if (migration == null || migration.is_new())
return "No migration to export";
log.log(Level.FINE, "Creating xml document for migration: " + migration);
Document document = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
Element root = document.createElement("Migrations");
document.appendChild(root);
root.appendChild(migration.toXmlNode(document));
//set up a transformer
TransformerFactory transfac = TransformerFactory.newInstance();
transfac.setAttribute("indent-number", 2);
Transformer trans;
trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.STANDALONE, "yes");
log.log(Level.FINE, "Writing xml to file.");
//create string from xml tree
FileWriter fw = new FileWriter(fileName);
StreamResult result = new StreamResult(fw);
DOMSource source = new DOMSource(document);
trans.transform(source, result);
fw.close();
return "Exported migration to: " + fileName;
}
use of org.compiere.model.MMigration in project adempiere by adempiere.
the class MigrationMerge method prepare.
@Override
protected void prepare() {
int fromId = 0, toId = 0;
ProcessInfoParameter[] params = getParameter();
for (ProcessInfoParameter p : params) {
String para = p.getParameterName();
if (para.equals("AD_Migration_ID"))
fromId = p.getParameterAsInt();
else if (para.equals("AD_MigrationTo_ID"))
toId = p.getParameterAsInt();
}
// launched from migration window
if (toId == 0)
toId = getRecord_ID();
migrationTo = new MMigration(getCtx(), toId, get_TrxName());
migrationFrom = new MMigration(getCtx(), fromId, get_TrxName());
}
Aggregations