use of de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getDocumentFieldZoomInto.
private JSONZoomInto getDocumentFieldZoomInto(final DocumentPath documentPath, final String fieldName) {
userSession.assertLoggedIn();
final DocumentZoomIntoInfo zoomIntoInfo = documentCollection.forDocumentReadonly(documentPath, document -> {
final IDocumentFieldView field = document.getFieldView(fieldName);
// Generic ZoomInto button
if (field.getDescriptor().getWidgetType() == DocumentFieldWidgetType.ZoomIntoButton) {
final ButtonFieldActionDescriptor buttonActionDescriptor = field.getDescriptor().getButtonActionDescriptor();
final String zoomIntoTableIdFieldName = buttonActionDescriptor.getZoomIntoTableIdFieldName();
final Integer adTableId = document.getFieldView(zoomIntoTableIdFieldName).getValueAs(Integer.class);
if (adTableId == null || adTableId <= 0) {
throw new EntityNotFoundException("Cannot fetch ZoomInto infos from a null value. No AD_Table_ID.").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName).setParameter("zoomIntoTableIdFieldName", zoomIntoTableIdFieldName);
}
final Integer recordId = field.getValueAs(Integer.class);
if (recordId == null) {
throw new EntityNotFoundException("Cannot fetch ZoomInto infos from a null value. No Record_ID.").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName).setParameter("zoomIntoTableIdFieldName", zoomIntoTableIdFieldName);
}
final String tableName = Services.get(IADTableDAO.class).retrieveTableName(adTableId);
return DocumentZoomIntoInfo.of(tableName, recordId);
} else // Key Field
if (field.isKey()) {
// Allow zooming into key column. It shall open precisely this record in a new window.
// (see https://github.com/metasfresh/metasfresh/issues/1687 to understand the use-case)
final String tableName = document.getEntityDescriptor().getTableName();
final int recordId = document.getDocumentIdAsInt();
return DocumentZoomIntoInfo.of(tableName, recordId);
} else // Regular lookup value
{
return field.getZoomIntoInfo();
}
});
final JSONDocumentPath jsonZoomIntoDocumentPath;
if (zoomIntoInfo == null) {
throw new EntityNotFoundException("ZoomInto not supported").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName);
} else if (!zoomIntoInfo.isRecordIdPresent()) {
final WindowId windowId = documentCollection.getWindowId(zoomIntoInfo);
jsonZoomIntoDocumentPath = JSONDocumentPath.newWindowRecord(windowId);
} else {
final DocumentPath zoomIntoDocumentPath = documentCollection.getDocumentPath(zoomIntoInfo);
jsonZoomIntoDocumentPath = JSONDocumentPath.ofWindowDocumentPath(zoomIntoDocumentPath);
}
return JSONZoomInto.builder().documentPath(jsonZoomIntoDocumentPath).source(JSONDocumentPath.ofWindowDocumentPath(documentPath, fieldName)).build();
}
use of de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method getDocumentPath.
/**
* Retrieves document path for given ZoomInto info.
*
* @param zoomIntoInfo
*/
public DocumentPath getDocumentPath(@NonNull final DocumentZoomIntoInfo zoomIntoInfo) {
if (!zoomIntoInfo.isRecordIdPresent()) {
throw new IllegalArgumentException("recordId must be set in " + zoomIntoInfo);
}
//
// Find the root window ID
final WindowId zoomIntoWindowIdEffective = getWindowId(zoomIntoInfo);
final DocumentEntityDescriptor rootEntityDescriptor = getDocumentEntityDescriptor(zoomIntoWindowIdEffective);
final String zoomIntoTableName = zoomIntoInfo.getTableName();
// (i.e. root descriptor's table is matching record's table)
if (Objects.equals(rootEntityDescriptor.getTableName(), zoomIntoTableName)) {
final DocumentId rootDocumentId = DocumentId.of(zoomIntoInfo.getRecordId());
return DocumentPath.rootDocumentPath(zoomIntoWindowIdEffective, rootDocumentId);
} else //
// We are dealing with an included document
{
// Search the root descriptor for any child entity descriptor which would match record's TableName
final List<DocumentEntityDescriptor> childEntityDescriptors = rootEntityDescriptor.getIncludedEntities().stream().filter(includedEntityDescriptor -> Objects.equals(includedEntityDescriptor.getTableName(), zoomIntoTableName)).collect(ImmutableList.toImmutableList());
if (childEntityDescriptors.isEmpty()) {
throw new EntityNotFoundException("Cannot find the detail tab to zoom into").setParameter("zoomIntoInfo", zoomIntoInfo).setParameter("zoomIntoWindowId", zoomIntoWindowIdEffective).setParameter("rootEntityDescriptor", rootEntityDescriptor);
} else if (childEntityDescriptors.size() > 1) {
logger.warn("More then one child descriptors matched our root descriptor. Picking the fist one. \nRoot descriptor: {} \nChild descriptors: {}", rootEntityDescriptor, childEntityDescriptors);
}
//
final DocumentEntityDescriptor childEntityDescriptor = childEntityDescriptors.get(0);
// Find the root DocumentId
final DocumentId rowId = DocumentId.of(zoomIntoInfo.getRecordId());
final DocumentId rootDocumentId = DocumentQuery.ofRecordId(childEntityDescriptor, rowId).retrieveParentDocumentId(rootEntityDescriptor);
//
return DocumentPath.includedDocumentPath(zoomIntoWindowIdEffective, rootDocumentId, childEntityDescriptor.getDetailId(), rowId);
}
}
use of de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo in project metasfresh-webui-api by metasfresh.
the class ADProcessParametersRepository method extractParameterValue.
private static Object extractParameterValue(final Map<String, ProcessInfoParameter> processInfoParameters, final DocumentFieldDescriptor parameterDescriptor) {
final String fieldName = parameterDescriptor.getFieldName();
final ProcessInfoParameter processInfoParameter = processInfoParameters.get(fieldName);
if (processInfoParameter == null) {
return null;
}
final Object parameterValue = processInfoParameter.getParameter();
final String parameterDisplay = processInfoParameter.getInfo();
final Object parameterValueConv = parameterDescriptor.convertToValueClass(parameterValue, new LookupValueByIdSupplier() {
@Override
public DocumentZoomIntoInfo getDocumentZoomInto(final int id) {
throw new UnsupportedOperationException();
}
@Override
public LookupValue findById(final Object id) {
return LookupValue.fromObject(id, parameterDisplay);
}
});
return parameterValueConv;
}
Aggregations