Search in sources :

Example 1 with Recoverable

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;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) DefaultErrorModel(eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) Recoverable(eu.bcvsolutions.idm.core.api.service.Recoverable)

Example 2 with Recoverable

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();
    }
}
Also used : Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) File(java.io.File) IOException(java.io.IOException) Recoverable(eu.bcvsolutions.idm.core.api.service.Recoverable)

Aggregations

Recoverable (eu.bcvsolutions.idm.core.api.service.Recoverable)2 Codeable (eu.bcvsolutions.idm.core.api.domain.Codeable)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)1 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)1 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 DefaultErrorModel (eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)1 File (java.io.File)1 IOException (java.io.IOException)1