Search in sources :

Example 1 with MAttribute

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

the class MAttributeTest method testQuery.

public void testQuery() throws Exception {
    MAttribute attrib = new MAttribute(getCtx(), 100, getTrxName());
    MAttribute[] attbClient = MAttribute.getOfClient(getCtx(), true, true);
    assertTrue("atrributes must be true", attbClient.length > 0);
    MAttributeValue[] av = attrib.getMAttributeValues();
    assertTrue("atrributes must have values", av.length > 0);
    MAttributeInstance ai = attrib.getMAttributeInstance(100);
    assertTrue("atrributes must have values", ai.isActive());
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) MAttribute(org.compiere.model.MAttribute)

Example 2 with MAttribute

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

the class HTMLMessenger method getAttributeSetInstanceInfo.

public String getAttributeSetInstanceInfo(MAttributeSetInstance asi, boolean singleRow) {
    MAttributeSet as = new MAttributeSet(Env.getCtx(), asi.getM_AttributeSet_ID(), null);
    StorageReasoner mr = new StorageReasoner();
    int[] ids = mr.getAttributeIDs(asi);
    MAttributeInstance ai = null;
    MAttribute a = null;
    MAttributeValue av = null;
    StringBuffer sb = new StringBuffer();
    String value = null;
    Object[] obj = null;
    for (int i = 0; i < ids.length; i++) {
        ai = new MAttributeInstance(Env.getCtx(), ids[i], asi.get_ID(), (String) null, null);
        ai.load(null);
        a = new MAttribute(Env.getCtx(), ai.getM_Attribute_ID(), null);
        av = new MAttributeValue(Env.getCtx(), ai.getM_AttributeValue_ID(), null);
        // e.g. the list validation type 'L'
        if (ai.getValue() == null) {
            value = av.getValue();
        } else // Takes the value of the M_AttributeInstance itself
        {
            // Round number values to a scale of 2, if type is 'N'
            if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(a.getAttributeValueType())) {
                BigDecimal number = ai.getValueNumber();
                value = number.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            } else {
                value = ai.getValue();
            }
        }
        obj = new Object[] { a.getName(), value };
        sb.append(MessageFormat.format(ATTRIBUTE_INFO_PATTERN, obj));
        if (singleRow) {
            sb.append("&nbsp;");
        } else {
            sb.append("<br>");
        }
    }
    return sb.toString();
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeValue(org.compiere.model.MAttributeValue) StorageReasoner(org.eevolution.model.reasoner.StorageReasoner) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Example 3 with MAttribute

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

the class StorageReasoner method equalAttributeInstanceValue.

public boolean equalAttributeInstanceValue(MAttributeInstance ai1, MAttributeInstance ai2) {
    if (ai1.getM_Attribute_ID() != ai2.getM_Attribute_ID()) {
        return false;
    }
    boolean equal = true;
    MAttribute a = new MAttribute(Env.getCtx(), ai1.getM_Attribute_ID(), null);
    if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(a.getAttributeValueType())) {
        if (ai1.getValue() == null) {
            equal = ai2.getValueNumber() == null;
        } else {
            equal = ai1.getValueNumber().compareTo(ai2.getValueNumber()) == 0;
        }
    } else if (MAttribute.ATTRIBUTEVALUETYPE_StringMax40.equals(a.getAttributeValueType())) {
        if (ai1.getValue() == null) {
            equal = ai2.getValue() == null;
        } else {
            equal = ai1.getValue().equals(ai2.getValue());
        }
    } else if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(a.getAttributeValueType())) {
        equal = ai1.getM_AttributeValue_ID() == ai2.getM_AttributeValue_ID();
    }
    return equal;
}
Also used : MAttribute(org.compiere.model.MAttribute)

Example 4 with MAttribute

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

the class MQMSpecification method isValid.

//	getLines
public boolean isValid(int M_AttributeSetInstance_ID) {
    //		Save Instance Attributes
    if (M_AttributeSetInstance_ID == 0)
        return false;
    MAttributeSetInstance asi = new MAttributeSetInstance(getCtx(), M_AttributeSetInstance_ID, get_TrxName());
    MAttributeSet as = MAttributeSet.get(getCtx(), asi.getM_AttributeSet_ID());
    MAttribute[] attributes = as.getMAttributes(true);
    for (int i = 0; i < attributes.length; i++) {
        MAttributeInstance instance = attributes[i].getMAttributeInstance(M_AttributeSetInstance_ID);
        List<MQMSpecificationLine> lines = getLines(" M_Attribute_ID=" + attributes[i].getM_Attribute_ID());
        if (lines == null)
            return false;
        for (MQMSpecificationLine line : lines) {
            if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType())) {
                BigDecimal objValue = instance.getValueNumber();
                if (!line.evaluate(objValue, instance.getValue()))
                    ;
                return false;
            } else {
                String objValue = instance.getValue();
                if (!line.evaluate(objValue, instance.getValue()))
                    return false;
            }
        //if(line.evaluate(mas.getValueNumber())
        }
    }
    //	for all attributes			
    return true;
}
Also used : MAttributeInstance(org.compiere.model.MAttributeInstance) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) BigDecimal(java.math.BigDecimal) MAttributeSet(org.compiere.model.MAttributeSet) MAttribute(org.compiere.model.MAttribute)

Example 5 with MAttribute

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

the class ImportProductASI method fillIDValues.

/**
	 * fill IDs values based on Search Key
	 * 
	 * @throws SQLException
	 */
private void fillIDValues() throws SQLException {
    for (X_I_Product_ASI ip_asi : getRecords(false, m_IsImportOnlyNoErrors)) {
        // Product
        int M_Product_ID = 0;
        if (ip_asi.getM_Product_ID() > 0)
            M_Product_ID = getID(MProduct.Table_Name, "M_Product_ID = ?", ip_asi.getM_Product_ID());
        if (M_Product_ID <= 0 && ip_asi.getProductValue() != null) {
            M_Product_ID = getID(MProduct.Table_Name, "Value = ?", ip_asi.getProductValue());
            ip_asi.setM_Product_ID(M_Product_ID);
        } else
            ip_asi.setM_Product_ID(M_Product_ID);
        // Attribute Set
        int M_AttributeSet_ID = 0;
        if (ip_asi.getM_AttributeSet_ID() > 0)
            M_AttributeSet_ID = getID(MAttributeSet.Table_Name, "M_AttributeSet_ID = ?", ip_asi.getM_AttributeSet_ID());
        if (M_AttributeSet_ID <= 0 && ip_asi.getAttributeSetName() != null) {
            M_AttributeSet_ID = getID(MAttributeSet.Table_Name, "Name = ?", ip_asi.getAttributeSetName());
            ip_asi.setM_AttributeSet_ID(M_AttributeSet_ID);
        } else
            ip_asi.setM_AttributeSet_ID(M_AttributeSet_ID);
        // Attribute
        int M_Attribute_ID = 0;
        if (ip_asi.getM_Attribute_ID() > 0)
            M_Attribute_ID = getID(MAttribute.Table_Name, "M_Attribute_ID = ?", ip_asi.getM_Attribute_ID());
        if (M_Attribute_ID <= 0 && ip_asi.getAttributeName() != null) {
            M_Attribute_ID = getID(MAttribute.Table_Name, "Name = ?", ip_asi.getAttributeName());
            ip_asi.setM_Attribute_ID(M_Attribute_ID);
        } else
            ip_asi.setM_Attribute_ID(M_Attribute_ID);
        if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(ip_asi.getAttributeValueType()) && M_Attribute_ID > 0) {
            MAttribute attribute = new MAttribute(getCtx(), M_Attribute_ID, get_TrxName());
        }
        // Attribute Set Instance
        int M_AttributeSetInstance_ID = 0;
        if (ip_asi.getM_AttributeSetInstance_ID() > 0)
            M_AttributeSetInstance_ID = getID(MAttributeSetInstance.Table_Name, "M_AttributeSetInstance_ID = ?", ip_asi.getM_AttributeSetInstance_ID());
        StringBuffer err = new StringBuffer("");
        if (ip_asi.getM_Product_ID() <= 0)
            err.append(" @M_Product_ID@ @NotFound@,");
        if (ip_asi.getAttributeSetName() == null)
            err.append(" @AttributeSetName@ @NotFound@,");
        if (ip_asi.getMandatoryType() == null)
            err.append(" @MandatoryType@ @NotFound@,");
        if (ip_asi.getAttributeName() == null)
            err.append(" @AttributeName@ @NotFound@,");
        if (ip_asi.getAttributeValueType() == null)
            err.append(" @AttributeValueType@ @NotFound@,");
        if (ip_asi.getAttributeValue() == null)
            err.append(" @AttributeValue@ @NotFound@,");
        if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(ip_asi.getAttributeValueType()) && ip_asi.getElementName() == null)
            err.append(" @ElementName@ @NotFound@,");
        if (err.toString() != null && err.toString().length() > 0) {
            notimported++;
            ip_asi.setI_ErrorMsg(Msg.parseTranslation(getCtx(), err.toString()));
        }
        ip_asi.saveEx();
        commitEx();
    }
}
Also used : X_I_Product_ASI(org.eevolution.model.X_I_Product_ASI) MAttribute(org.compiere.model.MAttribute)

Aggregations

MAttribute (org.compiere.model.MAttribute)13 MAttributeSet (org.compiere.model.MAttributeSet)9 BigDecimal (java.math.BigDecimal)5 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)5 MAttributeValue (org.compiere.model.MAttributeValue)5 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)4 MAttributeInstance (org.compiere.model.MAttributeInstance)4 CComboBox (org.compiere.swing.CComboBox)4 Timestamp (java.sql.Timestamp)3 KeyNamePair (org.compiere.util.KeyNamePair)3 Dimension (java.awt.Dimension)2 ListItem (org.adempiere.webui.component.ListItem)2 Listbox (org.adempiere.webui.component.Listbox)2 CLabel (org.compiere.swing.CLabel)2 CMenuItem (org.compiere.swing.CMenuItem)2 Date (java.util.Date)1 Label (org.adempiere.webui.component.Label)1 NumberBox (org.adempiere.webui.component.NumberBox)1 Row (org.adempiere.webui.component.Row)1 Rows (org.adempiere.webui.component.Rows)1