Search in sources :

Example 1 with I_M_AttributeInstance

use of org.compiere.model.I_M_AttributeInstance in project metasfresh-webui-api by metasfresh.

the class ASIRepository method loadReadonly.

/**
 * Retrieves {@link ASIDocument} for given ASI. The document will be readonly and not save-able.
 *
 * IMPORTANT: the retrieved document is not cached, so next time it will be retrieved again
 *
 * @param attributeSetInstanceId
 * @return ASI document
 */
public ASIDocument loadReadonly(final int attributeSetInstanceId) {
    if (attributeSetInstanceId <= 0) {
        throw new EntityNotFoundException("ASI " + attributeSetInstanceId);
    }
    final ASIEditingInfo info = ASIEditingInfo.readonlyASI(attributeSetInstanceId);
    // 
    // Get the ASI descriptor
    final ASIDescriptor asiDescriptor = descriptorsFactory.getASIDescriptor(info);
    // 
    // Create the new ASI document
    final Document asiDocData = Document.builder(asiDescriptor.getEntityDescriptor()).initializeAsNewDocument(() -> DocumentId.of(attributeSetInstanceId), VERSION_DEFAULT).build();
    // 
    // If we have a template ASI, populate the ASI document from it
    final MAttributeSetInstance templateASI = info.getM_AttributeSetInstance();
    for (final I_M_AttributeInstance fromAI : Services.get(IAttributeDAO.class).retrieveAttributeInstances(templateASI)) {
        loadASIDocumentField(asiDocData, fromAI);
    }
    // 
    // Validate, log and add the new ASI document to our index
    asiDocData.checkAndGetValidStatus();
    logger.trace("Created from ASI={}: {}", templateASI, asiDocData);
    final ASIDocument asiDoc = new ASIDocument(asiDescriptor, asiDocData);
    return asiDoc.copy(CopyMode.CheckInReadonly, NullDocumentChangesCollector.instance);
}
Also used : EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) ASIEditingInfo(org.adempiere.mm.attributes.util.ASIEditingInfo) Document(de.metas.ui.web.window.model.Document) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) IAttributeDAO(org.adempiere.mm.attributes.api.IAttributeDAO)

Example 2 with I_M_AttributeInstance

use of org.compiere.model.I_M_AttributeInstance in project metasfresh-webui-api by metasfresh.

the class ASIRepository method createNewFrom.

public ASIDocument createNewFrom(final JSONCreateASIRequest request) {
    final ASIEditingInfo info = createASIEditingInfo(request);
    // 
    // Get the ASI descriptor
    final ASIDescriptor asiDescriptor = descriptorsFactory.getASIDescriptor(info);
    // 
    // Create the new ASI document
    final Document asiDocData = Document.builder(asiDescriptor.getEntityDescriptor()).initializeAsNewDocument(nextASIDocId, VERSION_DEFAULT).build();
    // 
    // If we have a template ASI, populate the ASI document from it
    final MAttributeSetInstance templateASI = info.getM_AttributeSetInstance();
    if (templateASI != null) {
        for (final I_M_AttributeInstance fromAI : Services.get(IAttributeDAO.class).retrieveAttributeInstances(templateASI)) {
            loadASIDocumentField(asiDocData, fromAI);
        }
    }
    // 
    // Validate, log and add the new ASI document to our index
    asiDocData.checkAndGetValidStatus();
    logger.trace("Created from ASI={}: {}", templateASI, asiDocData);
    final ASIDocument asiDoc = new ASIDocument(asiDescriptor, asiDocData);
    commit(asiDoc);
    return asiDoc;
}
Also used : ASIEditingInfo(org.adempiere.mm.attributes.util.ASIEditingInfo) Document(de.metas.ui.web.window.model.Document) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) IAttributeDAO(org.adempiere.mm.attributes.api.IAttributeDAO)

Example 3 with I_M_AttributeInstance

use of org.compiere.model.I_M_AttributeInstance in project metasfresh-webui-api by metasfresh.

the class ASIDescriptorFactory method createDocumentFieldDescriptor.

private DocumentFieldDescriptor.Builder createDocumentFieldDescriptor(final I_M_Attribute attribute) {
    final int attributeId = attribute.getM_Attribute_ID();
    final String fieldName = attribute.getValue();
    final String attributeValueType = attribute.getAttributeValueType();
    final Class<?> valueClass;
    final DocumentFieldWidgetType widgetType;
    final Function<I_M_AttributeInstance, Object> readMethod;
    final BiConsumer<I_M_AttributeInstance, IDocumentFieldView> writeMethod;
    LookupDescriptor lookupDescriptor = null;
    if (X_M_Attribute.ATTRIBUTEVALUETYPE_Date.equals(attributeValueType)) {
        valueClass = java.util.Date.class;
        widgetType = DocumentFieldWidgetType.Date;
        readMethod = I_M_AttributeInstance::getValueDate;
        writeMethod = (aiRecord, field) -> aiRecord.setValueDate(TimeUtil.asTimestamp(field.getValueAs(java.util.Date.class)));
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType)) {
        valueClass = StringLookupValue.class;
        widgetType = DocumentFieldWidgetType.List;
        readMethod = I_M_AttributeInstance::getValue;
        writeMethod = ASIAttributeFieldBinding::writeValueFromLookup;
        lookupDescriptor = getLookupDescriptor(attribute);
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType)) {
        valueClass = BigDecimal.class;
        widgetType = DocumentFieldWidgetType.Number;
        readMethod = I_M_AttributeInstance::getValueNumber;
        writeMethod = (aiRecord, field) -> aiRecord.setValueNumber(field.getValueAs(BigDecimal.class));
    } else if (X_M_Attribute.ATTRIBUTEVALUETYPE_StringMax40.equals(attributeValueType)) {
        valueClass = String.class;
        widgetType = DocumentFieldWidgetType.Text;
        readMethod = I_M_AttributeInstance::getValue;
        writeMethod = (aiRecord, field) -> aiRecord.setValue(field.getValueAs(String.class));
    } else {
        throw new IllegalArgumentException("@NotSupported@ @AttributeValueType@=" + attributeValueType + ", @M_Attribute_ID@=" + attribute);
    }
    final ILogicExpression readonlyLogic = ConstantLogicExpression.FALSE;
    final ILogicExpression displayLogic = ConstantLogicExpression.TRUE;
    final ILogicExpression mandatoryLogic = ConstantLogicExpression.of(attribute.isMandatory());
    final Optional<IExpression<?>> defaultValueExpr = Optional.empty();
    return DocumentFieldDescriptor.builder(fieldName).setCaption(attribute.getName()).setDescription(attribute.getDescription()).setValueClass(valueClass).setWidgetType(widgetType).setLookupDescriptorProvider(lookupDescriptor).setDefaultValueExpression(defaultValueExpr).setReadonlyLogic(readonlyLogic).setDisplayLogic(displayLogic).setMandatoryLogic(mandatoryLogic).addCharacteristic(Characteristic.PublicField).setDataBinding(new ASIAttributeFieldBinding(attributeId, fieldName, attribute.isMandatory(), readMethod, writeMethod));
}
Also used : X_M_Attribute(org.compiere.model.X_M_Attribute) ArrayKey(org.compiere.util.Util.ArrayKey) CCache(org.compiere.util.CCache) IExpression(org.adempiere.ad.expression.api.IExpression) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) TimeUtil(org.compiere.util.TimeUtil) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) Function(java.util.function.Function) DocumentLayoutElementDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor) BigDecimal(java.math.BigDecimal) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) I_M_AttributeSet(org.compiere.model.I_M_AttributeSet) Characteristic(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) BiConsumer(java.util.function.BiConsumer) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) I_M_Attribute(org.compiere.model.I_M_Attribute) DocumentsRepository(de.metas.ui.web.window.model.DocumentsRepository) ConstantLogicExpression(org.adempiere.ad.expression.api.ConstantLogicExpression) DocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor) MAttribute(org.compiere.model.MAttribute) ASIEditingInfo(org.adempiere.mm.attributes.util.ASIEditingInfo) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) DocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor) DocumentLayoutElementFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor) List(java.util.List) Component(org.springframework.stereotype.Component) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) DocumentEntityDataBindingDescriptorBuilder(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor.DocumentEntityDataBindingDescriptorBuilder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(de.metas.printing.esb.base.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) Optional(java.util.Optional) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) I_M_AttributeSetInstance(org.compiere.model.I_M_AttributeSetInstance) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) IExpression(org.adempiere.ad.expression.api.IExpression) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Aggregations

ASIEditingInfo (org.adempiere.mm.attributes.util.ASIEditingInfo)3 I_M_AttributeInstance (org.compiere.model.I_M_AttributeInstance)3 Document (de.metas.ui.web.window.model.Document)2 IAttributeDAO (org.adempiere.mm.attributes.api.IAttributeDAO)2 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)2 Check (de.metas.printing.esb.base.util.Check)1 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 DocumentType (de.metas.ui.web.window.datatypes.DocumentType)1 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)1 DocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor)1 DocumentEntityDataBindingDescriptorBuilder (de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor.DocumentEntityDataBindingDescriptorBuilder)1 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)1 DocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor)1 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)1 Characteristic (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic)1 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)1 DocumentLayoutElementDescriptor (de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor)1 DocumentLayoutElementFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor)1 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)1