Search in sources :

Example 1 with MEntityType

use of org.compiere.model.MEntityType in project adempiere by adempiere.

the class EntityTypeElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    // TODO
    final int AD_EntityType_ID = Env.getContextAsInt(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_AD_EntityType_ID);
    if (entityTypes.contains(AD_EntityType_ID))
        return;
    entityTypes.add(AD_EntityType_ID);
    final MEntityType entity = new MEntityType(ctx, AD_EntityType_ID, null);
    AttributesImpl atts = new AttributesImpl();
    createMessageBinding(atts, entity);
    document.startElement("", "", TAG_Name, atts);
    document.endElement("", "", TAG_Name);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) MEntityType(org.compiere.model.MEntityType)

Example 2 with MEntityType

use of org.compiere.model.MEntityType in project adempiere by adempiere.

the class EntityTypeElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    final String elementValue = element.getElementValue();
    final Attributes atts = element.attributes;
    final String entitytype = atts.getValue(I_AD_EntityType.COLUMNNAME_EntityType);
    log.info(elementValue + " " + entitytype);
    if (isProcessElement(ctx, entitytype)) {
        int id = get_IDWithColumn(ctx, I_AD_EntityType.Table_Name, I_AD_EntityType.COLUMNNAME_EntityType, entitytype);
        final MEntityType entity = new MEntityType(ctx, id, getTrxName(ctx));
        final int AD_Backup_ID;
        final String Object_Status;
        if (id <= 0 && getIntValue(atts, I_AD_EntityType.COLUMNNAME_AD_EntityType_ID, 0) <= PackOut.MAX_OFFICIAL_ID) {
            entity.setAD_EntityType_ID(getIntValue(atts, I_AD_EntityType.COLUMNNAME_AD_EntityType_ID, 0));
        }
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, I_AD_EntityType.Table_Name, entity);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        entity.setName(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Name));
        entity.setDescription(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Description));
        entity.setHelp(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Help));
        entity.setEntityType(getStringValue(atts, I_AD_EntityType.COLUMNNAME_EntityType));
        entity.setVersion(atts.getValue(I_AD_EntityType.COLUMNNAME_Version));
        entity.setIsActive(getBooleanValue(atts, I_AD_EntityType.COLUMNNAME_IsActive, true));
        entity.setModelPackage(getStringValue(atts, I_AD_EntityType.COLUMNNAME_ModelPackage));
        entity.setClasspath(getStringValue(atts, I_AD_EntityType.COLUMNNAME_Classpath));
        if (entity.save(getTrxName(ctx)) == true) {
            record_log(ctx, 1, entity.getEntityType(), TAG_Name, entity.get_ID(), AD_Backup_ID, Object_Status, I_AD_EntityType.Table_Name, I_AD_EntityType.Table_ID);
        } else {
            record_log(ctx, 0, entity.getEntityType(), TAG_Name, entity.get_ID(), AD_Backup_ID, Object_Status, I_AD_EntityType.Table_Name, I_AD_EntityType.Table_ID);
            throw new POSaveFailedException("Failed to save message.");
        }
    } else {
        element.skip = true;
    }
}
Also used : Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) MEntityType(org.compiere.model.MEntityType)

Example 3 with MEntityType

use of org.compiere.model.MEntityType in project adempiere by adempiere.

the class RecordInfoController method dynInit.

/**
	 * 	Dynamic Init
	 *	@param dse data status event
	 *	@param title title
	 *	@param mField field
	 */
private void dynInit(DataStatusEvent dse, String title, GridField mField) {
    m_Field = mField;
    //	Yamel Senih FR[ 146 ] Add support to change log in a specific column
    //	2015-12-03
    //	For Field
    int m_Record_ID = 0;
    int m_AD_Table_ID = 0;
    int m_AD_Column_ID = 0;
    if (m_Field != null) {
        //	Set Values
        m_Record_ID = m_Field.getGridTab().getRecord_ID();
        m_AD_Table_ID = m_Field.getGridTab().getAD_Table_ID();
        m_AD_Column_ID = m_Field.getAD_Column_ID();
        //	
        MColumn column = MColumn.get(Env.getCtx(), m_AD_Column_ID);
        X_AD_Reference reference = new X_AD_Reference(Env.getCtx(), m_Field.getDisplayType(), null);
        DecimalFormat format = DisplayType.getNumberFormat(reference.getAD_Reference_ID());
        MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
        //  Info
        m_info.append("(").append(table.getTableName()).append(" - ").append(m_Field.getColumnName()).append(" = ").append(m_Field.getValue()).append(")").append("\n").append(Msg.translate(Env.getCtx(), "Name")).append(": ").append(m_Field.getHeader()).append("\n").append(Msg.translate(Env.getCtx(), "Description")).append(": ").append(m_Field.getDescription()).append("\n").append(Msg.translate(Env.getCtx(), "AD_Reference_ID")).append(": ").append(reference.get_Translation("Name")).append("\n");
        //	For Reference Key
        if (m_Field.getDisplayType() == DisplayType.List || m_Field.getDisplayType() == DisplayType.Table || m_Field.getDisplayType() == DisplayType.Search) {
            //	Valid Reference Value
            if (m_Field.getAD_Reference_Value_ID() != 0) {
                X_AD_Reference referenceKey = new X_AD_Reference(Env.getCtx(), m_Field.getAD_Reference_Value_ID(), null);
                m_info.append(Msg.translate(Env.getCtx(), "AD_Reference_Value_ID")).append(": ").append(referenceKey.get_Translation("Name")).append(" (").append(m_Field.getAD_Reference_Value_ID()).append(")").append("\n");
            }
        }
        //	Valid Dynamic Validation
        if (column.getAD_Val_Rule_ID() != 0) {
            X_AD_Val_Rule validation = (X_AD_Val_Rule) column.getAD_Val_Rule();
            m_info.append(Msg.translate(Env.getCtx(), "AD_Val_Rule_ID")).append(": ").append(validation.get_Translation("Name")).append(" (").append(column.getAD_Val_Rule_ID()).append(")").append("\n");
        }
        m_info.append(Msg.translate(Env.getCtx(), "Length")).append(": ").append(format.format(column.getFieldLength())).append("\n");
        //	Add Entity Type for info
        MEntityType entity = MEntityType.get(Env.getCtx(), column.getEntityType());
        m_info.append(Msg.translate(Env.getCtx(), "EntityType")).append(": ").append(entity.get_Translation("Name"));
        //	Title
        m_Title = title + " - " + m_Field.getHeader();
    } else {
        if (dse.CreatedBy == null)
            return;
        //  Info
        MUser user = MUser.get(Env.getCtx(), dse.CreatedBy.intValue());
        m_info.append(" ").append(Msg.translate(Env.getCtx(), "CreatedBy")).append(": ").append(user.getName()).append(" - ").append(m_dateTimeFormat.format(dse.Created)).append("\n");
        if (!dse.Created.equals(dse.Updated) || !dse.CreatedBy.equals(dse.UpdatedBy)) {
            if (!dse.CreatedBy.equals(dse.UpdatedBy))
                user = MUser.get(Env.getCtx(), dse.UpdatedBy.intValue());
            m_info.append(" ").append(Msg.translate(Env.getCtx(), "UpdatedBy")).append(": ").append(user.getName()).append(" - ").append(m_dateTimeFormat.format(dse.Updated)).append("\n");
        }
        if (dse.Info != null && dse.Info.length() > 0)
            m_info.append("\n (").append(dse.Info).append(")");
        //	Title
        if (dse.AD_Table_ID != 0) {
            m_AD_Table_ID = dse.AD_Table_ID;
            MTable table1 = MTable.get(Env.getCtx(), dse.AD_Table_ID);
            m_Title = title + " - " + table1.getName();
        }
        //	Set Record ID
        if (dse.Record_ID instanceof Integer)
            m_Record_ID = ((Integer) dse.Record_ID).intValue();
        else
            log.info("dynInit - Invalid Record_ID=" + dse.Record_ID);
    }
    //	Valid Record Identifier
    if (m_Record_ID == 0)
        return;
    //	Only Client Preference can view Change Log
    if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()))
        return;
    //	Data
    String sql = "SELECT AD_Column_ID, Updated, UpdatedBy, OldValue, NewValue " + "FROM AD_ChangeLog " + "WHERE AD_Table_ID=? AND Record_ID=? " + (m_AD_Column_ID != 0 ? "AND AD_Column_ID=? " : "") + "ORDER BY Updated DESC";
    PreparedStatement pstmt = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_AD_Table_ID);
        pstmt.setInt(2, m_Record_ID);
        //	Add support to column
        if (m_AD_Column_ID != 0)
            pstmt.setInt(3, m_AD_Column_ID);
        //	
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            addLine(rs.getInt(1), rs.getTimestamp(2), rs.getInt(3), rs.getString(4), rs.getString(5));
        }
        rs.close();
        pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    }
    try {
        if (pstmt != null)
            pstmt.close();
        pstmt = null;
    } catch (Exception e) {
        pstmt = null;
    }
    //	Set Loaded to Ok
    m_IsLoaded = true;
}
Also used : MColumn(org.compiere.model.MColumn) DecimalFormat(java.text.DecimalFormat) PreparedStatement(java.sql.PreparedStatement) X_AD_Val_Rule(org.compiere.model.X_AD_Val_Rule) X_AD_Reference(org.compiere.model.X_AD_Reference) MTable(org.compiere.model.MTable) ResultSet(java.sql.ResultSet) MEntityType(org.compiere.model.MEntityType) MUser(org.compiere.model.MUser)

Example 4 with MEntityType

use of org.compiere.model.MEntityType in project adempiere by adempiere.

the class DeveloperModeBL method getEntityType.

private String getEntityType(Properties ctx) {
    final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    boolean skipStackTraceElement = true;
    for (StackTraceElement ste : stackTrace) {
        final String classnameFQ = ste.getClassName();
        if (classnameFQ == null) {
            continue;
        }
        if (classnameFQ.startsWith(getClass().getName())) {
            skipStackTraceElement = false;
            continue;
        }
        if (skipStackTraceElement || classnameFQ.startsWith("java.lang.") || classnameFQ.startsWith("sun.")) {
            continue;
        }
        int idx = classnameFQ.lastIndexOf(".");
        if (idx <= 0)
            continue;
        final String packageName = classnameFQ.substring(0, idx);
        //
        // Get EntityType by PackageName
        final MEntityType[] entityTypes = MEntityType.getEntityTypes(Env.getCtx());
        MEntityType entityType = null;
        for (MEntityType et : entityTypes) {
            String modelPackage = et.getModelPackage();
            if (Check.isEmpty(modelPackage, true) || "org.compiere.model".equals(modelPackage) || "org.adempiere.model".equals(modelPackage)) {
                continue;
            }
            if (modelPackage.endsWith(".model")) {
                modelPackage = modelPackage.substring(0, modelPackage.length() - ".model".length());
            }
            if (packageName.equals(modelPackage) || packageName.startsWith(modelPackage + ".")) {
                entityType = et;
                break;
            }
        }
        if (entityType != null) {
            return entityType.getEntityType();
        }
    }
    String entityType = Env.getContext(ctx, "#EntityType");
    if (Check.isEmpty(entityType)) {
        entityType = "U";
    }
    return entityType;
}
Also used : MEntityType(org.compiere.model.MEntityType)

Example 5 with MEntityType

use of org.compiere.model.MEntityType in project adempiere by adempiere.

the class ModelInterfaceGenerator method isGenerateModelGetterForEntity.

/**
	 * 
	 * @param AD_Table_ID
	 * @param toEntityType
	 * @return true if a model getter method (method that is returning referenced PO) should be generated
	 */
public static boolean isGenerateModelGetterForEntity(int AD_Table_ID, String toEntityType) {
    final String fromEntityType = DB.getSQLValueString(null, "SELECT EntityType FROM AD_Table where AD_Table_ID=?", AD_Table_ID);
    final MEntityType fromEntity = MEntityType.get(Env.getCtx(), fromEntityType);
    final MEntityType toEntity = MEntityType.get(Env.getCtx(), toEntityType);
    return // Same entities
    fromEntityType.equals(toEntityType) || // Both are system entities
    (fromEntity.isSystemMaintained() && toEntity.isSystemMaintained()) || // Not Sys Entity referencing a Sys Entity
    (!fromEntity.isSystemMaintained() && toEntity.isSystemMaintained());
}
Also used : MEntityType(org.compiere.model.MEntityType)

Aggregations

MEntityType (org.compiere.model.MEntityType)6 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 DecimalFormat (java.text.DecimalFormat)1 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)1 MColumn (org.compiere.model.MColumn)1 MTable (org.compiere.model.MTable)1 MUser (org.compiere.model.MUser)1 X_AD_Reference (org.compiere.model.X_AD_Reference)1 X_AD_Val_Rule (org.compiere.model.X_AD_Val_Rule)1 AdempiereSystemError (org.compiere.util.AdempiereSystemError)1 AdempiereUserError (org.compiere.util.AdempiereUserError)1 Attributes (org.xml.sax.Attributes)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1