Search in sources :

Example 16 with ITranslatableString

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);
    });
}
Also used : ITranslatableString(de.metas.i18n.ITranslatableString) ZoomInfo(org.adempiere.model.ZoomInfoFactory.ZoomInfo)

Example 17 with ITranslatableString

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);
    }
}
Also used : ITranslatableString(de.metas.i18n.ITranslatableString) ITranslatableString(de.metas.i18n.ITranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString)

Example 18 with ITranslatableString

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());
    });
}
Also used : IZoomSource(org.adempiere.model.ZoomInfoFactory.IZoomSource) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) Getter(lombok.Getter) ITrx(org.adempiere.ad.trx.api.ITrx) Autowired(org.springframework.beans.factory.annotation.Autowired) Evaluatee(org.compiere.util.Evaluatee) ImmutableList(com.google.common.collect.ImmutableList) Service(org.springframework.stereotype.Service) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Nullable(javax.annotation.Nullable) Properties(java.util.Properties) WindowConstants(de.metas.ui.web.window.WindowConstants) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) MoreObjects(com.google.common.base.MoreObjects) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) ZoomInfoFactory(org.adempiere.model.ZoomInfoFactory) Services(org.adempiere.util.Services) I_AD_Column(org.compiere.model.I_AD_Column) List(java.util.List) ZoomInfo(org.adempiere.model.ZoomInfoFactory.ZoomInfo) MQueryDocumentFilterHelper(de.metas.ui.web.document.filter.MQueryDocumentFilterHelper) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) ITranslatableString(de.metas.i18n.ITranslatableString)

Example 19 with ITranslatableString

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);
}
Also used : ITranslatableString(de.metas.i18n.ITranslatableString) ITranslatableString(de.metas.i18n.ITranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString)

Example 20 with ITranslatableString

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();
}
Also used : ITranslatableString(de.metas.i18n.ITranslatableString) ITranslatableString(de.metas.i18n.ITranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

ITranslatableString (de.metas.i18n.ITranslatableString)26 ImmutableTranslatableString (de.metas.i18n.ImmutableTranslatableString)9 IMsgBL (de.metas.i18n.IMsgBL)8 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)5 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)4 NumberTranslatableString (de.metas.i18n.NumberTranslatableString)3 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)3 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 DateTimeTranslatableString (de.metas.i18n.DateTimeTranslatableString)2 BoardFieldLoader (de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader)2 WindowConstants (de.metas.ui.web.window.WindowConstants)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)2 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)2 WindowId (de.metas.ui.web.window.datatypes.WindowId)2 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)2