Search in sources :

Example 6 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class AdvancedExportServiceImpl method createQueryParts.

/**
 * This method create query parts based on field.
 *
 * @param splitField
 * @param parentIndex
 * @param metaModel
 * @throws ClassNotFoundException
 */
private void createQueryParts(String[] splitField, int parentIndex, MetaModel metaModel) throws ClassNotFoundException {
    while (parentIndex <= splitField.length - 1) {
        MetaField relationalField = metaFieldRepo.all().filter("self.name = ?1 and self.metaModel = ?2", splitField[parentIndex], metaModel).fetchOne();
        MetaModel subMetaModel = metaModelRepo.all().filter("self.name = ?1", relationalField.getTypeName()).fetchOne();
        if (!Strings.isNullOrEmpty(relationalField.getRelationship())) {
            checkRelationalField(splitField, parentIndex);
        } else {
            checkSelectionField(splitField, parentIndex, metaModel);
            checkNormalField(splitField, parentIndex);
        }
        parentIndex += 1;
        metaModel = subMetaModel;
    }
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField)

Example 7 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class AdvancedExportServiceImpl method createQueryBuilder.

/**
 * This method build a dynamic query using <i>StringBuilder</i>.
 *
 * @param metaModel
 * @param selectFieldBuilder
 * @param selectJoinFieldBuilder
 * @param selectionFieldBuilder
 * @param criteria
 * @param orderByFieldBuilder
 * @return
 */
private StringBuilder createQueryBuilder(AdvancedExport advancedExport, StringBuilder selectFieldBuilder, List<Long> recordIds, StringBuilder orderByFieldBuilder) {
    String joinField = "", selectionJoinField = "", orderByCol = "";
    joinField = String.join(" ", joinFieldSet);
    selectionJoinField = String.join(" ", selectionJoinFieldSet);
    params = null;
    MetaModel metaModel = advancedExport.getMetaModel();
    String criteria = getCriteria(metaModel, recordIds);
    if (!orderByFieldBuilder.toString().equals(""))
        orderByCol = " ORDER BY " + orderByFieldBuilder.substring(0, orderByFieldBuilder.length() - 1);
    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("SELECT NEW List(");
    queryBuilder.append(selectFieldBuilder.substring(0, selectFieldBuilder.length() - 1));
    queryBuilder.append(") FROM " + metaModel.getName() + " self ");
    queryBuilder.append((!Strings.isNullOrEmpty(joinField)) ? joinField + " " : "");
    queryBuilder.append((!Strings.isNullOrEmpty(selectionJoinField)) ? selectionJoinField + " " : "");
    queryBuilder.append((!Strings.isNullOrEmpty(criteria)) ? criteria : "");
    if (!advancedExport.getIncludeArchivedRecords()) {
        queryBuilder.append("WHERE self.archived = 'f' OR self.archived IS NULL");
    }
    queryBuilder.append((!Strings.isNullOrEmpty(orderByCol)) ? orderByCol : "");
    return queryBuilder;
}
Also used : MetaModel(com.axelor.meta.db.MetaModel)

Example 8 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class StudioMetaService method trackJsonField.

@Transactional
public void trackJsonField(MetaJsonField metaJsonField) {
    MetaModel metaModel = metaModelRepo.all().filter("self.fullName = ?1", metaJsonField.getModel()).fetchOne();
    trackingFields(metaModel, metaJsonField.getName(), "Field added");
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) Transactional(com.google.inject.persist.Transactional)

Example 9 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class ActionEmailBuilderService method build.

public MetaAction build(ActionBuilder builder) {
    String name = builder.getName();
    Object model = builder.getIsJson() ? metaJsonModelRepo.all().filter("self.name = ?", builder.getModel()).fetchOne() : metaModelRepo.all().filter("self.fullName = ?", builder.getModel()).fetchOne();
    int sendOption = builder.getEmailSendOptionSelect();
    Template template = builder.getEmailTemplate();
    String xml = "<action-method name=\"" + name + "\" id=\"" + builder.getXmlId() + "\">\n\t" + "<call class=\"com.axelor.studio.service.builder.ActionEmailBuilderService\" method=\"sendEmail(id, '" + (builder.getIsJson() ? ((MetaJsonModel) model).getName() : ((MetaModel) model).getFullName()) + "', '" + (builder.getIsJson() ? ((MetaJsonModel) model).getName() : ((MetaModel) model).getName()) + "', '" + template.getId() + "', '" + sendOption + "')\" " + "if=\"id != null\"/>\n" + "</action-method>";
    return studioMetaService.updateMetaAction(name, "action-method", xml, null, builder.getXmlId());
}
Also used : MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModel(com.axelor.meta.db.MetaModel) Template(com.axelor.apps.message.db.Template)

Example 10 with MetaModel

use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.

the class ChartBuilderService method getTable.

private String getTable(String model) {
    String[] models = model.split("\\.");
    MetaModel metaModel = metaModelRepo.findByName(models[models.length - 1]);
    if (metaModel != null) {
        return metaModel.getTableName();
    }
    return null;
}
Also used : MetaModel(com.axelor.meta.db.MetaModel)

Aggregations

MetaModel (com.axelor.meta.db.MetaModel)41 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)12 AxelorException (com.axelor.exception.AxelorException)9 MetaField (com.axelor.meta.db.MetaField)9 ArrayList (java.util.ArrayList)8 Model (com.axelor.db.Model)7 Mapper (com.axelor.db.mapper.Mapper)6 IOException (java.io.IOException)6 Transactional (com.google.inject.persist.Transactional)5 List (java.util.List)5 App (com.axelor.apps.base.db.App)4 Property (com.axelor.db.mapper.Property)4 MetaJsonModel (com.axelor.meta.db.MetaJsonModel)4 Context (com.axelor.rpc.Context)4 AuditableModel (com.axelor.auth.db.AuditableModel)3 CSVInput (com.axelor.data.csv.CSVInput)3 MetaFile (com.axelor.meta.db.MetaFile)3 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)3 AppFilter (com.axelor.app.internal.AppFilter)2 AdvancedExport (com.axelor.apps.base.db.AdvancedExport)2