Search in sources :

Example 6 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList in project metasfresh-webui-api by metasfresh.

the class MailRestController method changeEmail.

private void changeEmail(final WebuiEmail email, final WebuiEmailBuilder newEmailBuilder, final JSONDocumentChangedEvent event) {
    if (!event.isReplace()) {
        throw new AdempiereException("Unsupported event").setParameter("event", event);
    }
    final String fieldName = event.getPath();
    if (PATCH_FIELD_To.equals(fieldName)) {
        @SuppressWarnings("unchecked") final List<Object> jsonTo = (List<Object>) event.getValue();
        @SuppressWarnings("unchecked") final LookupValuesList to = jsonTo.stream().map(mapObj -> (Map<String, Object>) mapObj).map(map -> JSONLookupValue.integerLookupValueFromJsonMap(map)).collect(LookupValuesList.collect());
        newEmailBuilder.to(to);
    } else if (PATCH_FIELD_Subject.equals(fieldName)) {
        final String subject = (String) event.getValue();
        newEmailBuilder.subject(subject);
    } else if (PATCH_FIELD_Message.equals(fieldName)) {
        final String message = (String) event.getValue();
        newEmailBuilder.message(message);
    } else if (PATCH_FIELD_Attachments.equals(fieldName)) {
        @SuppressWarnings("unchecked") final List<Object> jsonAttachments = (List<Object>) event.getValue();
        @SuppressWarnings("unchecked") final LookupValuesList attachments = jsonAttachments.stream().map(mapObj -> (Map<String, Object>) mapObj).map(map -> JSONLookupValue.stringLookupValueFromJsonMap(map)).collect(LookupValuesList.collect());
        newEmailBuilder.attachments(attachments);
    } else if (PATCH_FIELD_TemplateId.equals(fieldName)) {
        @SuppressWarnings("unchecked") final LookupValue templateId = JSONLookupValue.integerLookupValueFromJsonMap((Map<String, Object>) event.getValue());
        applyTemplate(email, newEmailBuilder, templateId);
    } else {
        throw new AdempiereException("Unsupported event path").setParameter("event", event).setParameter("fieldName", fieldName).setParameter("availablePaths", PATCH_FIELD_ALL);
    }
}
Also used : FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebuiEmailRemovedEvent(de.metas.ui.web.mail.WebuiMailRepository.WebuiEmailRemovedEvent) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) UnaryOperator(java.util.function.UnaryOperator) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) ApiOperation(io.swagger.annotations.ApiOperation) Map(java.util.Map) JSONEmail(de.metas.ui.web.mail.json.JSONEmail) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImmutableSet(com.google.common.collect.ImmutableSet) EMail(de.metas.email.EMail) NonNull(lombok.NonNull) Set(java.util.Set) EventListener(org.springframework.context.event.EventListener) RestController(org.springframework.web.bind.annotation.RestController) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) UserSession(de.metas.ui.web.session.UserSession) Services(org.adempiere.util.Services) List(java.util.List) I_AD_Client(org.compiere.model.I_AD_Client) Stream(java.util.stream.Stream) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) IMailBL(de.metas.email.IMailBL) ApiModel(io.swagger.annotations.ApiModel) LogManager(de.metas.logging.LogManager) EMailSentStatus(de.metas.email.EMailSentStatus) WebConfig(de.metas.ui.web.config.WebConfig) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) Supplier(com.google.common.base.Supplier) IUserBL(org.adempiere.user.api.IUserBL) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) IUserDAO(org.adempiere.user.api.IUserDAO) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) RequestBody(org.springframework.web.bind.annotation.RequestBody) ImmutableList(com.google.common.collect.ImmutableList) GetMapping(org.springframework.web.bind.annotation.GetMapping) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) I_AD_User(org.compiere.model.I_AD_User) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) Properties(java.util.Properties) Logger(org.slf4j.Logger) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) IOException(java.io.IOException) WebuiEmailBuilder(de.metas.ui.web.mail.WebuiEmail.WebuiEmailBuilder) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) AdempiereException(org.adempiere.exceptions.AdempiereException) IClientDAO(org.adempiere.service.IClientDAO) Check(de.metas.printing.esb.base.util.Check) EMailAttachment(de.metas.email.EMailAttachment) JSONEmailRequest(de.metas.ui.web.mail.json.JSONEmailRequest) MultipartFile(org.springframework.web.multipart.MultipartFile) AdempiereException(org.adempiere.exceptions.AdempiereException) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) Map(java.util.Map) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 7 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList in project metasfresh-webui-api by metasfresh.

the class WebuiHUTransformParametersFiller method getTUsLookupValues_All.

private LookupValuesList getTUsLookupValues_All(final LookupDataSourceContext context) {
    final ActionType actionType = getActionType();
    if (actionType == ActionType.CU_To_ExistingTU) {
        // TODO: cache the descriptor
        // TODO: filter by TUs
        // TODO: search by barcode too
        final LookupDescriptor lookupDescriptor = SqlLookupDescriptor.builder().setCtxTableName(// ctxTableName
        null).setCtxColumnName("M_HU_ID").setDisplayType(DisplayType.Search).buildForDefaultScope();
        LookupDataSource dataSource = LookupDataSourceFactory.instance.getLookupDataSource(lookupDescriptor);
        final LookupValuesList result = dataSource.findEntities(context, context.getFilter(), context.getOffset(0), context.getLimit(10));
        return result;
    }
    return LookupValuesList.EMPTY;
}
Also used : ActionType(de.metas.ui.web.handlingunits.process.WebuiHUTransformCommand.ActionType) LookupDataSource(de.metas.ui.web.window.model.lookup.LookupDataSource) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 8 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList in project metasfresh-webui-api by metasfresh.

the class WebuiHUTransformParametersFiller method getLUsLookupValues_All.

private LookupValuesList getLUsLookupValues_All(final LookupDataSourceContext context) {
    final ActionType actionType = getActionType();
    if (actionType == ActionType.TU_To_ExistingLU) {
        // TODO: cache the descriptor
        // TODO: filter by LUs
        // TODO: search by barcode too
        final LookupDescriptor lookupDescriptor = SqlLookupDescriptor.builder().setCtxTableName(// ctxTableName
        null).setCtxColumnName("M_HU_ID").setDisplayType(DisplayType.Search).buildForDefaultScope();
        LookupDataSource dataSource = LookupDataSourceFactory.instance.getLookupDataSource(lookupDescriptor);
        final LookupValuesList result = dataSource.findEntities(context, context.getFilter(), context.getOffset(0), context.getLimit(10));
        return result;
    } else {
        return LookupValuesList.EMPTY;
    }
}
Also used : ActionType(de.metas.ui.web.handlingunits.process.WebuiHUTransformCommand.ActionType) LookupDataSource(de.metas.ui.web.window.model.lookup.LookupDataSource) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 9 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList in project metasfresh-webui-api by metasfresh.

the class GenericSqlLookupDataSourceFetcher method retrieveEntities.

/**
 * @param evalCtx
 * @return lookup values list
 * @see #getRetrieveEntriesParameters()
 */
@Override
public LookupValuesList retrieveEntities(final LookupDataSourceContext evalCtx) {
    final String sqlForFetching = sqlForFetchingExpression.evaluate(evalCtx, OnVariableNotFound.Fail);
    final String adLanguage = isTranslatable ? evalCtx.getAD_Language() : null;
    try (final SQLNamePairIterator data = new SQLNamePairIterator(sqlForFetching, numericKey, entityTypeIndex)) {
        Map<String, String> debugProperties = null;
        if (WindowConstants.isProtocolDebugging()) {
            debugProperties = new LinkedHashMap<>();
            debugProperties.put("debug-sql", sqlForFetching);
            debugProperties.put("debug-params", evalCtx.toString());
        }
        final LookupValuesList values = data.fetchAll().stream().filter(evalCtx::acceptItem).map(namePair -> LookupValue.fromNamePair(namePair, adLanguage)).collect(LookupValuesList.collect(debugProperties));
        logger.trace("Returning values={} (executed sql: {})", values, sqlForFetching);
        return values;
    }
}
Also used : LogManager(de.metas.logging.LogManager) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) ITrx(org.adempiere.ad.trx.api.ITrx) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) LinkedHashMap(java.util.LinkedHashMap) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) DB(org.compiere.util.DB) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) INamePairPredicate(org.adempiere.ad.validationRule.INamePairPredicate) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) Logger(org.slf4j.Logger) 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) CCacheStats(org.compiere.util.CCache.CCacheStats) SQLNamePairIterator(org.adempiere.ad.service.impl.LookupDAO.SQLNamePairIterator) List(java.util.List) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) SQLNamePairIterator(org.adempiere.ad.service.impl.LookupDAO.SQLNamePairIterator) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) ITranslatableString(de.metas.i18n.ITranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString)

Example 10 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList in project metasfresh-webui-api by metasfresh.

the class FullyCachedLookupDataSource method findById.

@Override
public LookupValue findById(final Object idObj) {
    final Object idNormalized = LookupValue.normalizeId(idObj, fetcher.isNumericKey());
    if (idNormalized == null) {
        return null;
    }
    final LookupValuesList partition = getLookupValuesList(Evaluatees.empty());
    return partition.getById(idNormalized);
}
Also used : LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList)

Aggregations

LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)20 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)8 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)8 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)7 LookupDataSource (de.metas.ui.web.window.model.lookup.LookupDataSource)7 List (java.util.List)7 NonNull (lombok.NonNull)7 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)6 ImmutableList (com.google.common.collect.ImmutableList)5 LogManager (de.metas.logging.LogManager)4 ActionType (de.metas.ui.web.handlingunits.process.WebuiHUTransformCommand.ActionType)4 LookupDataSourceContext (de.metas.ui.web.window.model.lookup.LookupDataSourceContext)4 Set (java.util.Set)4 Services (org.adempiere.util.Services)4 DisplayType (org.compiere.util.DisplayType)4 I_M_HU (de.metas.handlingunits.model.I_M_HU)3 Check (de.metas.printing.esb.base.util.Check)3 IProcessDefaultParametersProvider (de.metas.process.IProcessDefaultParametersProvider)3 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)3 LookupDataSourceFactory (de.metas.ui.web.window.model.lookup.LookupDataSourceFactory)3