use of eu.bcvsolutions.idm.core.api.service.Recoverable in project CzechIdMng by bcvsolutions.
the class AbstractBackupBulkAction method prevalidate.
@Override
@SuppressWarnings("unchecked")
public ResultModels prevalidate() {
ResultModels results = new ResultModels();
Recoverable<DTO> service = (Recoverable<DTO>) getService();
String backupFolder = service.getBackupFolder();
if (StringUtils.isEmpty(backupFolder)) {
ResultModel result = new DefaultErrorModel(CoreResultCode.BACKUP_FOLDER_NOT_FOUND, ImmutableMap.of("property", Recoverable.BACKUP_FOLDER_CONFIG));
results.addInfo(result);
} else {
ResultModel result = new DefaultErrorModel(CoreResultCode.BACKUP_FOLDER_FOUND, ImmutableMap.of("backupFolder", backupFolder));
results.addInfo(result);
}
return results;
}
use of eu.bcvsolutions.idm.core.api.service.Recoverable in project CzechIdMng by bcvsolutions.
the class AbstractBackupBulkAction method processDto.
@Override
@SuppressWarnings("unchecked")
protected OperationResult processDto(DTO dto) {
try {
Assert.notNull(dto, "Entity to backup is required!");
Assert.notNull(dto.getId(), "Id of entity to backup is required!");
Assert.isTrue(getService() instanceof Recoverable, "Entity service has to implement recoverable interface!");
Recoverable<DTO> service = (Recoverable<DTO>) getService();
// call backup
File backupFile = service.backup(dto);
// rename to zip folder
String fileName = dto.getId().toString();
if (dto instanceof Codeable) {
fileName = attachmentManager.getValidFileName(((Codeable) dto).getCode());
}
File targetFile = new File(zipFolder.toString(), String.format("%s.xml", fileName));
// and copy file
FileUtils.copyFile(backupFile, targetFile);
//
return new OperationResult(OperationState.EXECUTED);
} catch (Exception ex) {
return new //
OperationResult.Builder(//
OperationState.EXCEPTION).setCause(//
ex).build();
}
}
Aggregations