Search in sources :

Example 6 with FileTab

use of com.axelor.apps.base.db.FileTab in project axelor-open-suite by axelor.

the class FileTabController method validateActions.

public void validateActions(ActionRequest request, ActionResponse response) {
    FileTab fileTab = request.getContext().asType(FileTab.class);
    if (StringUtils.isEmpty(fileTab.getActions())) {
        return;
    }
    ActionService actionService = Beans.get(ActionService.class);
    if (!actionService.validate(fileTab.getActions())) {
        response.setError(String.format(IExceptionMessage.ADVANCED_IMPORT_LOG_10, fileTab.getMetaModel().getName()));
    }
}
Also used : FileTab(com.axelor.apps.base.db.FileTab) ActionService(com.axelor.apps.base.service.advanced.imports.ActionService)

Example 7 with FileTab

use of com.axelor.apps.base.db.FileTab in project axelor-open-suite by axelor.

the class FileTabController method compute.

public void compute(ActionRequest request, ActionResponse response) {
    try {
        FileTab fileTab = request.getContext().asType(FileTab.class);
        fileTab = Beans.get(FileTabService.class).compute(fileTab);
        response.setValues(fileTab);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : FileTab(com.axelor.apps.base.db.FileTab)

Example 8 with FileTab

use of com.axelor.apps.base.db.FileTab in project axelor-open-suite by axelor.

the class FileTabController method validateSearchCall.

public void validateSearchCall(ActionRequest request, ActionResponse response) {
    FileTab fileTab = request.getContext().asType(FileTab.class);
    SearchCallService searchCallService = Beans.get(SearchCallService.class);
    if (!searchCallService.validate(fileTab.getSearchCall())) {
        response.setError(String.format(IExceptionMessage.ADVANCED_IMPORT_LOG_11, fileTab.getMetaModel().getName()));
    }
}
Also used : SearchCallService(com.axelor.apps.base.service.advanced.imports.SearchCallService) FileTab(com.axelor.apps.base.db.FileTab)

Example 9 with FileTab

use of com.axelor.apps.base.db.FileTab in project axelor-open-suite by axelor.

the class FileTabController method updateFields.

public void updateFields(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Map<String, Object> map = context.getParent();
        if (map == null || (boolean) map.get("isConfigInFile") == true) {
            return;
        }
        FileTab fileTab = context.asType(FileTab.class);
        Beans.get(FileTabService.class).updateFields(fileTab);
        response.setValue("fileFieldList", fileTab.getFileFieldList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) FileTabService(com.axelor.apps.base.service.advanced.imports.FileTabService) FileTab(com.axelor.apps.base.db.FileTab)

Example 10 with FileTab

use of com.axelor.apps.base.db.FileTab in project axelor-open-suite by axelor.

the class ImportAdvancedImport method importGeneral.

@SuppressWarnings("unchecked")
public Object importGeneral(Object bean, Map<String, Object> values) throws ClassNotFoundException {
    if (bean == null) {
        return bean;
    }
    FileTab fileTab = fileTabRepo.find(Long.valueOf(values.get("fileTabId").toString()));
    ScriptHelper scriptHelper = new GroovyScriptHelper(new ScriptBindings(values));
    List<String> exprs = (List<String>) values.get("ifConditions" + fileTab.getId());
    if (!CollectionUtils.isEmpty(exprs)) {
        if ((boolean) scriptHelper.eval(String.join(" || ", exprs))) {
            return null;
        }
    }
    if (((Model) bean).getId() == null) {
        List<Property> propList = this.getProperties(bean);
        JPA.save((Model) bean);
        this.addJsonObjectRecord(bean, fileTab, fileTab.getMetaModel().getName(), values);
        int fieldSeq = 2;
        int btnSeq = 3;
        for (Property prop : propList) {
            validatorService.createCustomObjectSet(fileTab.getClass().getName(), prop.getTarget().getName(), fieldSeq);
            validatorService.createCustomButton(fileTab.getClass().getName(), prop.getTarget().getName(), btnSeq);
            this.addJsonObjectRecord(prop.get(bean), fileTab, StringUtils.substringAfterLast(prop.getTarget().getName(), "."), values);
            fieldSeq++;
            btnSeq++;
        }
    }
    final String ACTIONS_TO_APPLY = "actionsToApply" + fileTab.getId();
    if (!ObjectUtils.isEmpty(values.get(ACTIONS_TO_APPLY))) {
        bean = actionService.apply(values.get(ACTIONS_TO_APPLY).toString(), bean);
    }
    return bean;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) FileTab(com.axelor.apps.base.db.FileTab) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) ScriptHelper(com.axelor.script.ScriptHelper) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) ScriptBindings(com.axelor.script.ScriptBindings) Property(com.axelor.db.mapper.Property)

Aggregations

FileTab (com.axelor.apps.base.db.FileTab)14 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Model (com.axelor.db.Model)7 FileField (com.axelor.apps.base.db.FileField)6 FileFieldRepository (com.axelor.apps.base.db.repo.FileFieldRepository)5 Mapper (com.axelor.db.mapper.Mapper)5 Property (com.axelor.db.mapper.Property)5 Strings (com.google.common.base.Strings)5 Inject (com.google.inject.Inject)5 AdvancedImport (com.axelor.apps.base.db.AdvancedImport)4 DataReaderFactory (com.axelor.apps.tool.reader.DataReaderFactory)4 DataReaderService (com.axelor.apps.tool.reader.DataReaderService)4 Inflector (com.axelor.common.Inflector)4 AxelorException (com.axelor.exception.AxelorException)4 MetaField (com.axelor.meta.db.MetaField)4 MetaModel (com.axelor.meta.db.MetaModel)4 JsonContext (com.axelor.rpc.JsonContext)4 Files (com.google.common.io.Files)4 Arrays (java.util.Arrays)4