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