use of de.metas.ui.web.window.model.Document 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;
}
use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.
the class HUReportProcessInstancesRepository method createNewProcessInstance.
@Override
public HUReportProcessInstance createNewProcessInstance(final CreateProcessInstanceRequest request) {
final WebuiHUProcessDescriptor descriptor = getWebuiHUProcessDescriptor(request.getProcessId());
final DocumentId instanceId = nextPInstanceId();
final Document parameters = Document.builder(descriptor.getParametersDescriptor()).initializeAsNewDocument(instanceId, /* version */
"0");
final HUReportProcessInstance instance = HUReportProcessInstance.builder().instanceId(instanceId).viewRowIdsSelection(request.getViewRowIdsSelection()).reportAdProcessId(descriptor.getReportAdProcessId()).parameters(parameters).build();
instance.setCopies(1);
putInstance(instance);
return instance;
}
use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.
the class DataEntrySubTabBindingRepository method extractDataEntryRecordQuery.
private static DataEntryRecordQuery extractDataEntryRecordQuery(@NonNull final Document document) {
final DetailId detailId = document.getEntityDescriptor().getDetailId();
final DataEntrySubTabId subGroupId = extractDataEntrySubGroupId(detailId);
final Document parentDocument = document.getParentDocument();
final TableRecordReference parentRecordReference = extractParentRecordReference(parentDocument);
return DataEntryRecordQuery.builder().dataEntrySubTabId(subGroupId).recordId(parentRecordReference.getRecord_ID()).build();
}
use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.
the class DataEntrySubTabBindingRepository method retrieveDocumentIfExists.
private Optional<Document> retrieveDocumentIfExists(@NonNull final DocumentQuery query, @NonNull final IDocumentChangesCollector changesCollector) {
final DocumentEntityDescriptor entityDescriptor = query.getEntityDescriptor();
final Document parentDocument = query.getParentDocument();
final Function<DocumentId, Document> existingDocumentsSupplier = query.getExistingDocumentsSupplier();
final DetailId detailId = query.getEntityDescriptor().getDetailId();
final DataEntrySubTabId dataEntrySubTabId = extractDataEntrySubGroupId(detailId);
final TableRecordReference parentRecordReference = extractParentRecordReference(parentDocument);
final DataEntryRecordQuery dataEntryRecordQuery = DataEntryRecordQuery.builder().dataEntrySubTabId(dataEntrySubTabId).recordId(parentRecordReference.getRecord_ID()).build();
final Optional<DataEntryRecord> dataEntryRecord = dataEntryRecordRepository.getBy(dataEntryRecordQuery);
if (!dataEntryRecord.isPresent()) {
return Optional.empty();
}
final DocumentValuesSupplier documentValuesSupplier = new DataEntryDocumentValuesSupplier(dataEntryRecord.get(), dataEntryWebuiTools);
Document document = null;
if (existingDocumentsSupplier != null) {
final DocumentId documentId = documentValuesSupplier.getDocumentId();
document = existingDocumentsSupplier.apply(documentId);
}
if (document == null) {
document = Document.builder(entityDescriptor).setParentDocument(parentDocument).setChangesCollector(changesCollector).initializeAsExistingRecord(documentValuesSupplier);
}
return Optional.ofNullable(document);
}
use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.
the class WEBUI_Fact_Acct_Repost_SingleDocument method checkPreconditionsApplicable.
@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable(IProcessPreconditionsContext context) {
final String recordTableName = context.getTableName();
if (I_Fact_Acct.Table_Name.equals(recordTableName) || WEBUI_Fact_Acct_Repost_ViewRows.TABLENAME_RV_UnPosted.contentEquals(recordTableName)) {
return ProcessPreconditionsResolution.accept();
} else {
final AdWindowId adWindowId = context.getAdWindowId();
final int recordId = context.getSingleSelectedRecordId();
final DocumentPath documentPath = DocumentPath.rootDocumentPath(adWindowId, recordId);
final Document document = documentsCollection.getDocumentReadonly(documentPath);
final BooleanWithReason allowPosting = checkAllowReposting(document);
return allowPosting.isTrue() ? ProcessPreconditionsResolution.accept() : ProcessPreconditionsResolution.reject(allowPosting.getReason()).toInternal();
}
}
Aggregations