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