use of de.metas.i18n.ITranslatableString in project metasfresh-webui-api by metasfresh.
the class DocumentReferencesService method getDocumentReference.
public DocumentReference getDocumentReference(final DocumentPath sourceDocumentPath, final WindowId targetWindowId) {
return documentCollection.forDocumentReadonly(sourceDocumentPath, sourceDocument -> {
if (sourceDocument.isNew()) {
throw new IllegalArgumentException("New documents cannot be referenced: " + sourceDocument);
}
final DocumentAsZoomSource zoomSource = new DocumentAsZoomSource(sourceDocument);
final ZoomInfo zoomInfo = ZoomInfoFactory.get().retrieveZoomInfo(zoomSource, targetWindowId.toInt());
final ITranslatableString filterCaption = extractFilterCaption(sourceDocument);
return createDocumentReference(zoomInfo, filterCaption);
});
}
use of de.metas.i18n.ITranslatableString in project metasfresh-webui-api by metasfresh.
the class GenericSqlLookupDataSourceFetcher method retrieveLookupValueById.
@Override
public final LookupValue retrieveLookupValueById(final LookupDataSourceContext evalCtx) {
final Object id = evalCtx.getIdToFilter();
if (id == null) {
throw new IllegalStateException("No ID provided in " + evalCtx);
}
final String sqlDisplayName = sqlForFetchingDisplayNameByIdExpression.evaluate(evalCtx, OnVariableNotFound.Fail);
final String displayName = DB.getSQLValueStringEx(ITrx.TRXNAME_ThreadInherited, sqlDisplayName, id);
if (displayName == null) {
return LOOKUPVALUE_NULL;
}
final ITranslatableString displayNameTrl;
if (isTranslatable) {
final String adLanguage = evalCtx.getAD_Language();
displayNameTrl = ImmutableTranslatableString.singleLanguage(adLanguage, displayName);
} else {
displayNameTrl = ImmutableTranslatableString.anyLanguage(displayName);
}
//
if (id instanceof Integer) {
final Integer idInt = (Integer) id;
return IntegerLookupValue.of(idInt, displayNameTrl);
} else {
final String idString = id.toString();
return StringLookupValue.of(idString, displayNameTrl);
}
}
use of de.metas.i18n.ITranslatableString in project metasfresh-webui-api by metasfresh.
the class DocumentReferencesService method getDocumentReferences.
public List<DocumentReference> getDocumentReferences(final DocumentPath documentPath) {
return documentCollection.forDocumentReadonly(documentPath, document -> {
if (document.isNew()) {
return ImmutableList.of();
}
final DocumentAsZoomSource zoomSource = new DocumentAsZoomSource(document);
final ITranslatableString filterCaption = extractFilterCaption(document);
return ZoomInfoFactory.get().streamZoomInfos(zoomSource).map(zoomInfo -> createDocumentReference(zoomInfo, filterCaption)).collect(ImmutableList.toImmutableList());
});
}
use of de.metas.i18n.ITranslatableString in project metasfresh-webui-api by metasfresh.
the class DocumentReferencesService method extractFilterCaption.
private final ITranslatableString extractFilterCaption(final Document sourceDocument) {
//
// Window caption
final ITranslatableString windowCaption = sourceDocument.getEntityDescriptor().getCaption();
//
// Document info
// TODO: i think we shall use lookup to fetch the document description
final ITranslatableString documentSummary;
if (sourceDocument.hasField(WindowConstants.FIELDNAME_DocumentSummary)) {
final String documentSummaryStr = sourceDocument.getFieldView(WindowConstants.FIELDNAME_DocumentSummary).getValueAs(String.class);
documentSummary = ImmutableTranslatableString.constant(documentSummaryStr);
} else if (sourceDocument.hasField(WindowConstants.FIELDNAME_DocumentNo)) {
final String documentNoStr = sourceDocument.getFieldView(WindowConstants.FIELDNAME_DocumentNo).getValueAs(String.class);
documentSummary = ImmutableTranslatableString.constant(documentNoStr);
} else if (sourceDocument.hasField(WindowConstants.FIELDNAME_Name)) {
final String nameStr = sourceDocument.getFieldView(WindowConstants.FIELDNAME_Name).getValueAs(String.class);
documentSummary = ImmutableTranslatableString.constant(nameStr);
} else {
documentSummary = ImmutableTranslatableString.constant(sourceDocument.getDocumentId().toString());
}
// Window caption + document info
return ITranslatableString.compose(" ", windowCaption, documentSummary);
}
use of de.metas.i18n.ITranslatableString in project metasfresh-webui-api by metasfresh.
the class JSONLookupValue method integerLookupValueFromJsonMap.
public static final IntegerLookupValue integerLookupValueFromJsonMap(final Map<String, Object> map) {
final Object keyObj = map.get(PROPERTY_Key);
if (keyObj == null) {
return null;
}
final String keyStr = keyObj.toString().trim();
if (keyStr.isEmpty()) {
return null;
}
final int keyInt = Integer.parseInt(keyStr);
final Object captionObj = map.get(PROPERTY_Caption);
final String caption = captionObj != null ? captionObj.toString() : "";
final ITranslatableString displayName = ImmutableTranslatableString.anyLanguage(caption);
@SuppressWarnings("unchecked") final Map<String, Object> attributes = (Map<String, Object>) map.get(PROPERTY_Attributes);
if (attributes == null || attributes.isEmpty()) {
return IntegerLookupValue.of(keyInt, displayName);
}
return IntegerLookupValue.builder().id(keyInt).displayName(displayName).attributes(attributes).build();
}
Aggregations