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;
}
}
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;
}
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");
}
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());
}
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;
}
Aggregations