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 DefaultIdmNotificationConfigurationService method getSender.
@Override
public NotificationSender<?> getSender(String notificationType) {
if (!notificationSenders.hasPluginFor(notificationType)) {
return null;
}
//
// default plugin by ordered definition
NotificationSender<?> sender = notificationSenders.getPluginFor(notificationType);
String implName = sender.getConfigurationValue(ConfigurationService.PROPERTY_IMPLEMENTATION);
if (StringUtils.isBlank(implName)) {
// return default sender - configuration is empty
return sender;
}
//
try {
// returns bean by name from filter configuration
return (NotificationSender<?>) context.getBean(implName);
} catch (Exception ex) {
throw new ResultCodeException(CoreResultCode.NOTIFICATION_SENDER_IMPLEMENTATION_NOT_FOUND, ImmutableMap.of("implementation", implName, "notificationType", notificationType, "configurationProperty", sender.getConfigurationPropertyName(ConfigurationService.PROPERTY_IMPLEMENTATION)), ex);
}
}
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 SysSystemController method duplicate.
@ResponseBody
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_UPDATE + "')")
@RequestMapping(value = "/{backendId}/duplicate", method = RequestMethod.POST)
@ApiOperation(value = "Create system duplicate (copy)", nickname = "duplicateSystem", tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_UPDATE, description = "") }) }, notes = "Creates system duplicate with all configurations - connector, schemas, mappings etc.. Duplicate is disabled by default.")
public ResponseEntity<?> duplicate(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysSystemDto system = getDto(backendId);
if (system == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
SysSystemDto duplicate = systemService.duplicate(system.getId());
return new ResponseEntity<>(toResource(duplicate), HttpStatus.OK);
}
Aggregations