Search in sources :

Example 1 with I_M_Attribute

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

the class ASIDescriptorFactory method createDocumentEntityDescriptor.

private final // 
DocumentEntityDescriptor createDocumentEntityDescriptor(// 
DocumentId asiDescriptorId, // 
final String name, // 
final String description, // 
final List<MAttribute> attributes) {
    if (attributes.isEmpty()) {
        throw new AdempiereException("No attributes are configured").setParameter("asiDescriptorId", asiDescriptorId);
    }
    final DocumentEntityDescriptor.Builder attributeSetDescriptor = DocumentEntityDescriptor.builder().setDocumentType(DocumentType.ProductAttributes, asiDescriptorId).setCaption(name).setDescription(description).setDataBinding(getASIBindingsBuilder()).disableCallouts().setDetailId(null);
    for (final I_M_Attribute attribute : attributes) {
        final DocumentFieldDescriptor.Builder fieldDescriptor = createDocumentFieldDescriptor(attribute);
        attributeSetDescriptor.addField(fieldDescriptor);
    }
    return attributeSetDescriptor.build();
}
Also used : DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) AdempiereException(org.adempiere.exceptions.AdempiereException) I_M_Attribute(org.compiere.model.I_M_Attribute) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 2 with I_M_Attribute

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

the class HUEditorRowAttributes method processChange.

private void processChange(final JSONDocumentChangedEvent event) {
    if (JSONDocumentChangedEvent.JSONOperation.replace == event.getOperation()) {
        final String attributeName = event.getPath();
        if (isReadonly(attributeName)) {
            throw new DocumentFieldReadonlyException(attributeName, event.getValue());
        }
        final I_M_Attribute attribute = attributesStorage.getAttributeByValueKeyOrNull(attributeName);
        final Object value = convertFromJson(attribute, event.getValue());
        attributesStorage.setValue(attribute, value);
    } else {
        throw new IllegalArgumentException("Unknown operation: " + event);
    }
}
Also used : DocumentFieldReadonlyException(de.metas.ui.web.window.exceptions.DocumentFieldReadonlyException) I_M_Attribute(org.compiere.model.I_M_Attribute)

Example 3 with I_M_Attribute

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

the class HUEditorRowAttributes method getBestBeforeDate.

public Optional<Date> getBestBeforeDate() {
    final I_M_Attribute bestBeforeDateAttribute = Services.get(IAttributeDAO.class).retrieveAttributeByValue(Constants.ATTR_BestBeforeDate);
    if (!attributesStorage.hasAttribute(bestBeforeDateAttribute)) {
        return Optional.empty();
    }
    Date bestBeforeDate = attributesStorage.getValueAsDate(bestBeforeDateAttribute);
    return Optional.ofNullable(bestBeforeDate);
}
Also used : I_M_Attribute(org.compiere.model.I_M_Attribute) Date(java.util.Date) JSONDate(de.metas.ui.web.window.datatypes.json.JSONDate) IAttributeDAO(org.adempiere.mm.attributes.api.IAttributeDAO)

Example 4 with I_M_Attribute

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

the class HUEditorRowAttributes method getSSCC18.

public Optional<String> getSSCC18() {
    final I_M_Attribute sscc18Attribute = Services.get(ISSCC18CodeDAO.class).retrieveSSCC18Attribute(Env.getCtx());
    if (!attributesStorage.hasAttribute(sscc18Attribute)) {
        return Optional.empty();
    }
    final String sscc18 = attributesStorage.getValueAsString(sscc18Attribute);
    if (Check.isEmpty(sscc18, true)) {
        return Optional.empty();
    }
    return Optional.of(sscc18.trim());
}
Also used : I_M_Attribute(org.compiere.model.I_M_Attribute) ISSCC18CodeDAO(de.metas.handlingunits.attributes.sscc18.ISSCC18CodeDAO)

Example 5 with I_M_Attribute

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

the class AvailableToPromiseAdapterTests method extractAttributeSetFromStorageAttributesKey.

@Test
public void extractAttributeSetFromStorageAttributesKey() {
    final I_M_Attribute attr1 = attributesTestHelper.createM_Attribute("attr1", X_M_Attribute.ATTRIBUTEVALUETYPE_List, true);
    final I_M_AttributeValue attributeValue1 = attributesTestHelper.createM_AttributeValue(attr1, "value1");
    final I_M_Attribute attr2 = attributesTestHelper.createM_Attribute("attr2", X_M_Attribute.ATTRIBUTEVALUETYPE_List, true);
    final I_M_AttributeValue attributeValue2 = attributesTestHelper.createM_AttributeValue(attr2, "value2");
    // invoke the method under test
    final AttributesKey attributesKey = AttributesKey.ofAttributeValueIds(attributeValue1.getM_AttributeValue_ID(), attributeValue2.getM_AttributeValue_ID());
    final List<I_M_AttributeValue> result = availableToPromiseAdapter.extractAttributeSetFromStorageAttributesKey(attributesKey);
    assertThat(result).hasSize(2);
    assertThat(result).anySatisfy(attributeValue -> {
        assertThatModel(attributeValue).hasSameIdAs(attributeValue1);
        assertThat(attributeValue.getValue()).isEqualTo("value1");
    });
    assertThat(result).anySatisfy(attributeValue -> {
        assertThatModel(attributeValue).hasSameIdAs(attributeValue2);
        assertThat(attributeValue.getValue()).isEqualTo("value2");
    });
}
Also used : AttributesKey(de.metas.material.event.commons.AttributesKey) I_M_Attribute(org.compiere.model.I_M_Attribute) I_M_AttributeValue(org.compiere.model.I_M_AttributeValue) Test(org.junit.Test)

Aggregations

I_M_Attribute (org.compiere.model.I_M_Attribute)9 AdempiereException (org.adempiere.exceptions.AdempiereException)3 I_M_HU (de.metas.handlingunits.model.I_M_HU)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)2 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)2 IHUContext (de.metas.handlingunits.IHUContext)1 IAttributeStorage (de.metas.handlingunits.attribute.storage.IAttributeStorage)1 ISSCC18CodeDAO (de.metas.handlingunits.attributes.sscc18.ISSCC18CodeDAO)1 IHUDDOrderBL (de.metas.handlingunits.ddorder.api.IHUDDOrderBL)1 HUToDistribute (de.metas.handlingunits.ddorder.api.impl.HUs2DDOrderProducer.HUToDistribute)1 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 AttributesKey (de.metas.material.event.commons.AttributesKey)1 Check (de.metas.printing.esb.base.util.Check)1 I_M_Product_LotNumber_Lock (de.metas.product.model.I_M_Product_LotNumber_Lock)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 JSONDate (de.metas.ui.web.window.datatypes.json.JSONDate)1