Search in sources :

Example 1 with ASIEditingInfo

use of org.adempiere.mm.attributes.util.ASIEditingInfo 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 ASIEditingInfo

use of org.adempiere.mm.attributes.util.ASIEditingInfo 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)

Aggregations

Document (de.metas.ui.web.window.model.Document)2 IAttributeDAO (org.adempiere.mm.attributes.api.IAttributeDAO)2 ASIEditingInfo (org.adempiere.mm.attributes.util.ASIEditingInfo)2 I_M_AttributeInstance (org.compiere.model.I_M_AttributeInstance)2 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)2 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)1