use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationConfigurationService method save.
@Override
@Transactional
public NotificationConfigurationDto save(NotificationConfigurationDto dto, BasePermission... permission) {
Assert.notNull(dto);
//
// check duplicity
IdmNotificationConfiguration duplicitEntity = repository.findByTopicAndLevelAndNotificationType(dto.getTopic(), dto.getLevel(), dto.getNotificationType());
if (duplicitEntity != null && !duplicitEntity.getId().equals(dto.getId())) {
throw new ResultCodeException(CoreResultCode.NOTIFICATION_TOPIC_AND_LEVEL_EXISTS, ImmutableMap.of("topic", dto.getTopic()));
}
return super.save(dto);
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateService method backup.
@Override
public void backup(IdmNotificationTemplateDto dto) {
String directory = getDirectoryForBackup();
//
Marshaller jaxbMarshaller = initJaxbMarshaller();
//
File backupFolder = new File(directory);
if (!backupFolder.exists()) {
boolean success = backupFolder.mkdirs();
// if make dir after check if exist, throw error.
if (!success) {
LOG.error("Backup for template: {} failed, backup folder path: [{}] can't be created.", dto.getCode(), backupFolder.getAbsolutePath());
throw new ResultCodeException(CoreResultCode.BACKUP_FAIL, ImmutableMap.of("code", dto.getCode()));
}
}
//
IdmNotificationTemplateType type = dtoToType(dto);
//
File file = new File(getBackupFileName(directory, dto));
try {
jaxbMarshaller.marshal(type, file);
} catch (JAXBException e) {
LOG.error("Backup for template: {} failed", dto.getCode());
throw new ResultCodeException(CoreResultCode.BACKUP_FAIL, ImmutableMap.of("code", dto.getCode()), e);
}
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateService method initJaxbMarshaller.
/**
* Create instance of JaxbMarshaller and set required properties to him.
*
* @return
*/
private Marshaller initJaxbMarshaller() {
Marshaller jaxbMarshaller = null;
try {
jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
jaxbMarshaller.setProperty(ENCODING_HANDLER, new JaxbCharacterEscapeEncoder());
} catch (JAXBException e) {
throw new ResultCodeException(CoreResultCode.XML_JAXB_INIT_ERROR, e);
}
return jaxbMarshaller;
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptServiceIntegrationTest method backupMissingFolderNewEntity.
@Test
public void backupMissingFolderNewEntity() {
configurationService.setValue(Recoverable.BACKUP_FOLDER_CONFIG, null);
IdmScriptDto script = new IdmScriptDto();
script.setCategory(IdmScriptCategory.SYSTEM);
script.setCode("test_" + System.currentTimeMillis());
script.setName("test_" + System.currentTimeMillis());
script = scriptService.save(script);
assertNotNull(script);
assertNotNull(script.getId());
try {
scriptService.backup(script);
fail();
} catch (ResultCodeException e) {
ResultCodeException resultCode = (ResultCodeException) e;
assertEquals(resultCode.getError().getError().getStatusEnum(), CoreResultCode.BACKUP_FOLDER_NOT_FOUND.name());
}
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultIdmNotificationTemplateServiceIntegrationTest method redeployWithoutBackupFolder.
@Test
public void redeployWithoutBackupFolder() {
String backupPath = configurationService.getValue(DefaultIdmNotificationTemplateService.BACKUP_FOLDER_CONFIG);
if (backupPath != null) {
configurationService.setValue(DefaultIdmNotificationTemplateService.BACKUP_FOLDER_CONFIG, null);
}
//
IdmNotificationTemplateDto testTemplate = notificationTemplateService.getByCode(TEST_TEMPLATE);
Assert.assertNotNull(testTemplate);
assertEquals(TEST_TEMPLATE, testTemplate.getCode());
//
try {
notificationTemplateService.redeploy(testTemplate);
fail();
} catch (Exception e) {
assertTrue(e instanceof ResultCodeException);
ResultCodeException resultCode = (ResultCodeException) e;
assertEquals(resultCode.getError().getError().getStatusEnum(), CoreResultCode.BACKUP_FOLDER_NOT_FOUND.name());
}
}
Aggregations