Search in sources :

Example 1 with DuplicateObjectsService

use of com.axelor.apps.base.service.DuplicateObjectsService 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)

Aggregations

Wizard (com.axelor.apps.base.db.Wizard)1 DuplicateObjectsService (com.axelor.apps.base.service.DuplicateObjectsService)1 Property (com.axelor.db.mapper.Property)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1