Search in sources :

Example 21 with PoFiller

use of org.adempiere.pipo2.PoFiller in project idempiere by idempiere.

the class InfoRelatedElementHandler method startElement.

public void startElement(PIPOContext ctx, Element element) throws SAXException {
    List<String> excludes = defaultExcludeList(X_AD_InfoRelated.Table_Name);
    String entitytype = getStringValue(element, "EntityType");
    if (isProcessElement(ctx.ctx, entitytype)) {
        if (isParentDefer(element, I_AD_InfoWindow.Table_Name)) {
            element.defer = true;
            return;
        }
        X_AD_InfoRelated mInfoRelated = findPO(ctx, element);
        if (mInfoRelated == null) {
            mInfoRelated = new X_AD_InfoRelated(ctx.ctx, 0, getTrxName(ctx));
        }
        PoFiller filler = new PoFiller(ctx, mInfoRelated, element, this);
        List<String> notfounds = filler.autoFill(excludes);
        if (notfounds.size() > 0) {
            element.defer = true;
            element.unresolved = notfounds.toString();
            return;
        }
        element.recordId = mInfoRelated.get_ID();
        if (mInfoRelated.is_new() || mInfoRelated.is_Changed()) {
            X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_InfoRelated.Table_Name, X_AD_InfoRelated.Table_ID);
            String action = null;
            if (!mInfoRelated.is_new()) {
                backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_InfoRelated.Table_Name, mInfoRelated);
                action = "Update";
            } else {
                action = "New";
            }
            if (mInfoRelated.save(getTrxName(ctx)) == true) {
                logImportDetail(ctx, impDetail, 1, mInfoRelated.toString(), mInfoRelated.get_ID(), action);
                element.recordId = mInfoRelated.get_ID();
            } else {
                logImportDetail(ctx, impDetail, 0, mInfoRelated.toString(), mInfoRelated.get_ID(), action);
                throw new POSaveFailedException("Failed to save InfoRelated " + mInfoRelated.toString());
            }
        }
    } else {
        element.skip = true;
    }
}
Also used : PoFiller(org.adempiere.pipo2.PoFiller) X_AD_InfoRelated(org.compiere.model.X_AD_InfoRelated) POSaveFailedException(org.adempiere.pipo2.exception.POSaveFailedException) X_AD_Package_Imp_Detail(org.compiere.model.X_AD_Package_Imp_Detail)

Example 22 with PoFiller

use of org.adempiere.pipo2.PoFiller in project idempiere by idempiere.

the class MenuElementHandler method startElement.

public void startElement(PIPOContext ctx, Element element) throws SAXException {
    List<String> excludes = defaultExcludeList(X_AD_Menu.Table_Name);
    X_AD_Menu mMenu = findPO(ctx, element);
    if (mMenu == null) {
        mMenu = new X_AD_Menu(ctx.ctx, 0, getTrxName(ctx));
    }
    PoFiller filler = new PoFiller(ctx, mMenu, element, this);
    List<String> notFounds = filler.autoFill(excludes);
    if (notFounds.size() > 0) {
        element.defer = true;
        element.unresolved = notFounds.toString();
        return;
    }
    element.recordId = mMenu.get_ID();
    if (!mMenu.is_new() && !mMenu.is_Changed())
        return;
    X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Menu.Table_Name, X_AD_Menu.Table_ID);
    String action = null;
    if (!mMenu.is_new()) {
        backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Menu.Table_Name, mMenu);
        action = "Update";
    } else {
        action = "New";
    }
    if (mMenu.save(getTrxName(ctx)) == true) {
        try {
            logImportDetail(ctx, impDetail, 1, mMenu.getName(), mMenu.get_ID(), action);
            element.recordId = mMenu.get_ID();
        } catch (SAXException e) {
            if (log.isLoggable(Level.INFO))
                log.info("setmenu:" + e);
        }
    } else {
        try {
            logImportDetail(ctx, impDetail, 0, mMenu.getName(), mMenu.get_ID(), action);
        } catch (SAXException e) {
            if (log.isLoggable(Level.INFO))
                log.info("setmenu:" + e);
        }
    }
    Element parentElement = element.properties.get("Parent_ID");
    int parentId = 0;
    if (parentElement != null) {
        parentId = ReferenceUtils.resolveReference(ctx.ctx, parentElement, getTrxName(ctx));
    }
    String strSeqNo = getStringValue(element, "SeqNo");
    int seqNo = 0;
    if (strSeqNo != null)
        seqNo = Integer.valueOf(strSeqNo);
    int AD_Tree_ID = getDefaultMenuTreeId();
    final String updateSeqNo = "UPDATE AD_TREENODEMM SET SeqNo=SeqNo+1 WHERE Parent_ID=? AND SeqNo>=? AND AD_Tree_ID=?";
    final String sql1 = "SELECT COUNT(Parent_ID) FROM AD_TREENODEMM WHERE AD_Tree_ID=? AND Node_ID=?";
    int countRecords = DB.getSQLValueEx(getTrxName(ctx), sql1, AD_Tree_ID, mMenu.getAD_Menu_ID());
    if (countRecords > 0) {
        int oldseqNo = 0;
        final String sql2 = "SELECT * FROM AD_TREENODEMM WHERE AD_Tree_ID=? AND Node_ID=?";
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = DB.prepareStatement(sql2, getTrxName(ctx));
            pstmt.setInt(1, AD_Tree_ID);
            pstmt.setInt(2, mMenu.getAD_Menu_ID());
            rs = pstmt.executeQuery();
            if (rs.next()) {
                String colValue = null;
                ResultSetMetaData meta = rs.getMetaData();
                int columns = meta.getColumnCount();
                int tableID = X_AD_TreeNodeMM.Table_ID;
                for (int q = 1; q <= columns; q++) {
                    String colName = meta.getColumnName(q).toUpperCase();
                    final String sql3 = "SELECT AD_Column_ID FROM AD_column WHERE Upper(ColumnName) = ? AND AD_Table_ID = ?";
                    int columnID = DB.getSQLValueEx(getTrxName(ctx), sql3, colName, tableID);
                    final String sql4 = "SELECT AD_Reference_ID FROM AD_COLUMN WHERE AD_Column_ID = ?";
                    int referenceID = DB.getSQLValueEx(getTrxName(ctx), sql4, columnID);
                    Object obj = rs.getObject(q);
                    colValue = obj == null ? "" : obj.toString();
                    X_AD_Package_Imp_Backup backup = new X_AD_Package_Imp_Backup(ctx.ctx, 0, getTrxName(ctx));
                    backup.setAD_Package_Imp_Detail_ID(impDetail.getAD_Package_Imp_Detail_ID());
                    backup.setAD_Package_Imp_ID(getPackageImpId(ctx.ctx));
                    backup.setAD_Table_ID(tableID);
                    backup.setAD_Column_ID(columnID);
                    backup.setAD_Reference_ID(referenceID);
                    backup.setColValue(colValue);
                    backup.saveEx();
                }
                oldseqNo = rs.getInt("SeqNo");
                if (rs.wasNull())
                    oldseqNo = seqNo;
            }
        } catch (SQLException e) {
            throw new DBException(e);
        } finally {
            DB.close(rs, pstmt);
        }
        if (seqNo != oldseqNo)
            DB.executeUpdateEx(updateSeqNo, new Object[] { parentId, seqNo, AD_Tree_ID }, getTrxName(ctx));
        final String updateSQL = "UPDATE AD_TREENODEMM SET Parent_ID=?, SeqNo=? WHERE AD_Tree_ID=? AND Node_ID=?";
        DB.executeUpdateEx(updateSQL, new Object[] { parentId, seqNo, AD_Tree_ID, mMenu.getAD_Menu_ID() }, getTrxName(ctx));
    } else {
        DB.executeUpdateEx(updateSeqNo, new Object[] { parentId, seqNo, AD_Tree_ID }, getTrxName(ctx));
        final String insertSQL = "INSERT INTO AD_TREENODEMM (AD_Client_ID, AD_Org_ID, CreatedBy, UpdatedBy,Parent_ID, SeqNo, AD_Tree_ID, Node_ID, AD_TREENODEMM_UU) VALUES(0,0,0,0,?,?,?,?,?)";
        DB.executeUpdateEx(insertSQL, new Object[] { parentId, seqNo, AD_Tree_ID, mMenu.getAD_Menu_ID(), UUID.randomUUID().toString() }, getTrxName(ctx));
    }
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) X_AD_Menu(org.compiere.model.X_AD_Menu) Element(org.adempiere.pipo2.Element) PreparedStatement(java.sql.PreparedStatement) X_AD_Package_Imp_Detail(org.compiere.model.X_AD_Package_Imp_Detail) X_AD_Package_Imp_Backup(org.compiere.model.X_AD_Package_Imp_Backup) SAXException(org.xml.sax.SAXException) PoFiller(org.adempiere.pipo2.PoFiller) ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet)

Example 23 with PoFiller

use of org.adempiere.pipo2.PoFiller in project idempiere by idempiere.

the class MessageElementHandler method startElement.

public void startElement(PIPOContext ctx, Element element) throws SAXException {
    String entitytype = getStringValue(element, "EntityType");
    if (isProcessElement(ctx.ctx, entitytype)) {
        MMessage mMessage = findPO(ctx, element);
        if (mMessage == null) {
            mMessage = new MMessage(ctx.ctx, 0, getTrxName(ctx));
        }
        PoFiller filler = new PoFiller(ctx, mMessage, element, this);
        List<String> excludes = defaultExcludeList(X_AD_Message.Table_Name);
        if (messages.contains(mMessage.getAD_Message_ID())) {
            element.skip = true;
            return;
        }
        List<String> notfounds = filler.autoFill(excludes);
        if (notfounds.size() > 0) {
            element.defer = true;
            element.unresolved = notfounds.toString();
            return;
        }
        element.recordId = mMessage.getAD_Message_ID();
        if (mMessage.is_new() || mMessage.is_Changed()) {
            X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Message.Table_Name, X_AD_Message.Table_ID);
            String action = null;
            if (!mMessage.is_new()) {
                backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Message.Table_Name, mMessage);
                action = "Update";
            } else {
                action = "New";
            }
            if (mMessage.save(getTrxName(ctx)) == true) {
                logImportDetail(ctx, impDetail, 1, mMessage.getValue(), mMessage.get_ID(), action);
                messages.add(mMessage.getAD_Message_ID());
                element.recordId = mMessage.getAD_Message_ID();
            } else {
                logImportDetail(ctx, impDetail, 0, mMessage.getValue(), mMessage.get_ID(), action);
                throw new POSaveFailedException("Failed to save message " + mMessage.getValue());
            }
        }
    } else {
        element.skip = true;
    }
}
Also used : PoFiller(org.adempiere.pipo2.PoFiller) MMessage(org.compiere.model.MMessage) POSaveFailedException(org.adempiere.pipo2.exception.POSaveFailedException) X_AD_Package_Imp_Detail(org.compiere.model.X_AD_Package_Imp_Detail)

Example 24 with PoFiller

use of org.adempiere.pipo2.PoFiller in project idempiere by idempiere.

the class ModelValidatorElementHandler method startElement.

@Override
public void startElement(PIPOContext ctx, Element element) throws SAXException {
    String action = null;
    String entitytype = getStringValue(element, "EntityType");
    if (isProcessElement(ctx.ctx, entitytype)) {
        X_AD_ModelValidator validator = findPO(ctx, element);
        if (validator == null) {
            validator = new X_AD_ModelValidator(ctx.ctx, 0, getTrxName(ctx));
        }
        List<String> excludes = defaultExcludeList(X_AD_ModelValidator.Table_Name);
        if (validators.contains(validator.getAD_ModelValidator_ID())) {
            element.skip = true;
            return;
        }
        PoFiller pf = new PoFiller(ctx, validator, element, this);
        List<String> notfounds = pf.autoFill(excludes);
        if (notfounds.size() > 0) {
            element.defer = true;
            element.unresolved = notfounds.toString();
            return;
        }
        if (validator.is_new() || validator.is_Changed()) {
            X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_ModelValidator.Table_Name, X_AD_ModelValidator.Table_ID);
            if (!validator.is_new()) {
                backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), AD_MODELVALIDATOR, validator);
                action = "Update";
            } else {
                action = "New";
            }
            if (validator.save(getTrxName(ctx)) == true) {
                logImportDetail(ctx, impDetail, 1, validator.getName(), validator.get_ID(), action);
                element.recordId = validator.getAD_ModelValidator_ID();
                validators.add(validator.getAD_ModelValidator_ID());
            } else {
                logImportDetail(ctx, impDetail, 0, validator.getName(), validator.get_ID(), action);
                throw new POSaveFailedException("Failed to save Model Validator " + validator.getName());
            }
        }
    } else {
        element.skip = true;
    }
}
Also used : PoFiller(org.adempiere.pipo2.PoFiller) X_AD_ModelValidator(org.compiere.model.X_AD_ModelValidator) POSaveFailedException(org.adempiere.pipo2.exception.POSaveFailedException) X_AD_Package_Imp_Detail(org.compiere.model.X_AD_Package_Imp_Detail)

Example 25 with PoFiller

use of org.adempiere.pipo2.PoFiller in project idempiere by idempiere.

the class ModificationElementHandler method startElement.

@Override
public void startElement(PIPOContext ctx, Element element) throws SAXException {
    String action = null;
    String entitytype = getStringValue(element, "EntityType");
    if (isProcessElement(ctx.ctx, entitytype)) {
        X_AD_Modification modification = findPO(ctx, element);
        if (modification == null) {
            modification = new X_AD_Modification(ctx.ctx, 0, getTrxName(ctx));
        }
        List<String> excludes = defaultExcludeList(X_AD_Modification.Table_Name);
        if (modifications.contains(modification.getAD_Modification_ID())) {
            element.skip = true;
            return;
        }
        PoFiller pf = new PoFiller(ctx, modification, element, this);
        List<String> notfounds = pf.autoFill(excludes);
        if (notfounds.size() > 0) {
            element.defer = true;
            element.unresolved = notfounds.toString();
            return;
        }
        if (modification.is_new() || modification.is_Changed()) {
            X_AD_Package_Imp_Detail impDetail = createImportDetail(ctx, element.qName, X_AD_Modification.Table_Name, X_AD_Modification.Table_ID);
            if (!modification.is_new()) {
                backupRecord(ctx, impDetail.getAD_Package_Imp_Detail_ID(), X_AD_Modification.Table_Name, modification);
                action = "Update";
            } else {
                action = "New";
            }
            if (modification.save(getTrxName(ctx)) == true) {
                logImportDetail(ctx, impDetail, 1, modification.getName(), modification.get_ID(), action);
                element.recordId = modification.getAD_Modification_ID();
                modifications.add(modification.getAD_Modification_ID());
            } else {
                logImportDetail(ctx, impDetail, 0, modification.getName(), modification.get_ID(), action);
                throw new POSaveFailedException("Failed to save Model Validator " + modification.getName());
            }
        }
    } else {
        element.skip = true;
    }
}
Also used : X_AD_Modification(org.compiere.model.X_AD_Modification) PoFiller(org.adempiere.pipo2.PoFiller) POSaveFailedException(org.adempiere.pipo2.exception.POSaveFailedException) X_AD_Package_Imp_Detail(org.compiere.model.X_AD_Package_Imp_Detail)

Aggregations

PoFiller (org.adempiere.pipo2.PoFiller)53 X_AD_Package_Imp_Detail (org.compiere.model.X_AD_Package_Imp_Detail)45 POSaveFailedException (org.adempiere.pipo2.exception.POSaveFailedException)42 Element (org.adempiere.pipo2.Element)4 MReference (org.compiere.model.MReference)2 MTable (org.compiere.model.MTable)2 MWorkflow (org.compiere.wf.MWorkflow)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 DBException (org.adempiere.exceptions.DBException)1 GenericPO (org.adempiere.model.GenericPO)1 PackIn (org.adempiere.pipo2.PackIn)1 MAttachment (org.compiere.model.MAttachment)1 MColumn (org.compiere.model.MColumn)1 MField (org.compiere.model.MField)1 MForm (org.compiere.model.MForm)1 MFormAccess (org.compiere.model.MFormAccess)1 MIndexColumn (org.compiere.model.MIndexColumn)1