Search in sources :

Example 16 with Property

use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.

the class WkfModelServiceImpl method getMetaModelRecords.

@SuppressWarnings("unchecked")
private List<Model> getMetaModelRecords(WkfTaskConfig config, List<String> processInstanceIds, String modelName, User user, String type) {
    LocalDate toDate = LocalDate.now();
    Object[] obj = this.getMetaModelRecordFilter(config, modelName, user);
    Class<Model> klass = (Class<Model>) obj[0];
    String filter = (String) obj[1];
    if (type != null) {
        String deadLinePath = config.getDeadlineFieldPath();
        if (Strings.isNullOrEmpty(deadLinePath)) {
            return new ArrayList<>();
        }
        Property property = Mapper.of(klass).getProperty(deadLinePath.split("\\.")[0]);
        if (property == null) {
            filter += " AND self.attrs." + deadLinePath;
            if (type.equals(TASK_NEXT)) {
                filter += " > '" + toDate + "' AND self.attrs." + deadLinePath + " < '" + toDate.plusDays(7) + "'";
            }
        } else {
            filter += " AND self." + deadLinePath;
            if (type.equals(TASK_NEXT)) {
                filter += " > '" + toDate + "' AND self." + deadLinePath + " < '" + toDate.plusDays(7) + "'";
            }
        }
        if (type.equals(TASK_TODAY)) {
            filter += " = '" + toDate + "'";
        } else if (type.equals(LATE_TASK)) {
            filter += " < '" + toDate + "'";
        }
    }
    return JPA.all(klass).filter(filter).bind("processInstanceIds", processInstanceIds).fetch();
}
Also used : WkfModel(com.axelor.apps.bpm.db.WkfModel) MetaModel(com.axelor.meta.db.MetaModel) Model(com.axelor.db.Model) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) Property(com.axelor.db.mapper.Property)

Example 17 with Property

use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.

the class ObjectDataAnonymizeServiceImpl method replaceLink.

@Transactional(rollbackOn = { Exception.class })
public void replaceLink(Mapper mapper, String path, List<? extends Model> data, String rootModel, Long recordValue) throws ClassNotFoundException, AxelorException {
    path = path.split("\\.")[0];
    Property property = mapper.getProperty(path);
    if (property == null) {
        return;
    }
    Class<? extends Model> klass = (Class<? extends Model>) Class.forName(rootModel);
    JpaRepository<? extends Model> repo = JpaRepository.of(klass);
    Model object = repo.all().filter("self.id = ?1", recordValue).fetchOne();
    if (object == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessages.OBJECT_DATA_REPLACE_MISSING), recordValue);
    }
    for (Model model : data) {
        mapper.set(model, path, object);
        JPA.save(model);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Model(com.axelor.db.Model) Property(com.axelor.db.mapper.Property) Transactional(com.google.inject.persist.Transactional)

Example 18 with Property

use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.

the class ObjectDataAnonymizeServiceImpl method deleteLink.

@Transactional
public void deleteLink(Mapper mapper, String path, List<? extends Model> data) {
    path = path.split("\\.")[0];
    Property property = mapper.getProperty(path);
    if (property == null || property.isRequired()) {
        return;
    }
    for (Model model : data) {
        mapper.set(model, path, null);
        JPA.save(model);
    }
}
Also used : Model(com.axelor.db.Model) Property(com.axelor.db.mapper.Property) Transactional(com.google.inject.persist.Transactional)

Example 19 with Property

use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.

the class DuplicateObjectsController method defaultObjects.

public void defaultObjects(ActionRequest request, ActionResponse response) throws SecurityException {
    List<Long> selectedIds = new ArrayList<>();
    List<Object[]> duplicateObjects = new ArrayList<>();
    List<Wizard> wizardDataList = new ArrayList<>();
    DuplicateObjectsService duplicateObjectsService = Beans.get(DuplicateObjectsService.class);
    for (Integer id : (List<Integer>) request.getContext().get("_ids")) {
        selectedIds.add(Long.parseLong("" + id));
    }
    String modelName = request.getContext().get("_modelName").toString();
    List<Object> duplicateObj = duplicateObjectsService.getAllSelectedObject(selectedIds, modelName);
    for (Object object : duplicateObj) {
        Long id = (Long) Mapper.of(object.getClass()).get(object, "id");
        Property propertyNameColumn = Mapper.of(object.getClass()).getNameField();
        String nameColumn = propertyNameColumn == null ? null : propertyNameColumn.getName().toString();
        Property propertyCode = Mapper.of(object.getClass()).getProperty("code");
        String code = propertyCode == null ? null : propertyCode.getName().toString();
        String noColumn = null;
        if (nameColumn != null) {
            duplicateObjects.add((Object[]) duplicateObjectsService.getWizardValue(id, modelName, nameColumn));
        } else if (code != null) {
            duplicateObjects.add((Object[]) duplicateObjectsService.getWizardValue(id, modelName, code));
        } else {
            Object obj = duplicateObjectsService.getWizardValue(id, modelName, noColumn);
            Wizard wizard = new Wizard();
            wizard.setRecordId(obj.toString());
            wizard.setName(obj.toString());
            wizardDataList.add(wizard);
        }
    }
    for (Object[] obj : duplicateObjects) {
        String recordName = obj[1].toString();
        String recordId = obj[0].toString();
        Wizard wizard = new Wizard();
        wizard.setRecordId(recordId);
        wizard.setRecordName(recordName);
        wizard.setName(recordName);
        wizardDataList.add(wizard);
    }
    response.setAttr("$duplicateObjects", "value", wizardDataList);
}
Also used : ArrayList(java.util.ArrayList) DuplicateObjectsService(com.axelor.apps.base.service.DuplicateObjectsService) ArrayList(java.util.ArrayList) List(java.util.List) Wizard(com.axelor.apps.base.db.Wizard) Property(com.axelor.db.mapper.Property)

Example 20 with Property

use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.

the class ConvertWizardService method createObject.

@SuppressWarnings({ "rawtypes", "unchecked" })
public Object createObject(Map<String, Object> context, Object obj, Mapper mapper) throws AxelorException {
    if (context != null) {
        final int random = new Random().nextInt();
        for (final Property p : mapper.getProperties()) {
            if (p.isVirtual() || p.isPrimary() || p.isVersion()) {
                continue;
            }
            LOG.debug("Property name / Context value  : {} / {}", p.getName());
            Object value = context.get(p.getName());
            LOG.debug("Context value : {}", value);
            if (value != null) {
                if (value instanceof String && p.isUnique()) {
                    value = ((String) value) + " (" + random + ")";
                }
                if (value instanceof Map) {
                    LOG.debug("Map");
                    Map map = (Map) value;
                    Object id = map.get("id");
                    value = JPA.find((Class<Model>) p.getTarget(), Long.parseLong(id.toString()));
                }
                if (value instanceof List) {
                    LOG.debug("List");
                    List<Object> valueList = (List<Object>) value;
                    List<Object> resultList = Lists.newArrayList();
                    if (valueList != null) {
                        for (Object object : valueList) {
                            Map map = (Map) object;
                            Object id = map.get("id");
                            resultList.add(JPA.find((Class<Model>) p.getTarget(), Long.parseLong(id.toString())));
                        }
                    }
                    value = resultList;
                }
                p.set(obj, value);
            }
        }
        return obj;
    }
    return null;
}
Also used : Random(java.util.Random) List(java.util.List) Property(com.axelor.db.mapper.Property) Map(java.util.Map)

Aggregations

Property (com.axelor.db.mapper.Property)40 Mapper (com.axelor.db.mapper.Mapper)21 Model (com.axelor.db.Model)12 ArrayList (java.util.ArrayList)11 AxelorException (com.axelor.exception.AxelorException)10 MetaModel (com.axelor.meta.db.MetaModel)8 List (java.util.List)8 Transactional (com.google.inject.persist.Transactional)7 MetaField (com.axelor.meta.db.MetaField)6 FileField (com.axelor.apps.base.db.FileField)5 FileTab (com.axelor.apps.base.db.FileTab)4 Inflector (com.axelor.common.Inflector)4 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)4 I18n (com.axelor.i18n.I18n)4 Inject (com.google.inject.Inject)4 Arrays (java.util.Arrays)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 AdvancedImport (com.axelor.apps.base.db.AdvancedImport)3 FileFieldRepository (com.axelor.apps.base.db.repo.FileFieldRepository)3