Search in sources :

Example 46 with ResultCodeException

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);
}
Also used : IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with ResultCodeException

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);
    }
}
Also used : NotificationSender(eu.bcvsolutions.idm.core.notification.api.service.NotificationSender) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException)

Example 48 with ResultCodeException

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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) IdmNotificationTemplateType(eu.bcvsolutions.idm.core.notification.jaxb.IdmNotificationTemplateType) JAXBException(javax.xml.bind.JAXBException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) File(java.io.File)

Example 49 with ResultCodeException

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;
}
Also used : Marshaller(javax.xml.bind.Marshaller) JaxbCharacterEscapeEncoder(eu.bcvsolutions.idm.core.api.jaxb.JaxbCharacterEscapeEncoder) JAXBException(javax.xml.bind.JAXBException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 50 with ResultCodeException

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)162 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 ApiOperation (io.swagger.annotations.ApiOperation)47 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)47 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 Test (org.junit.Test)31 ResponseEntity (org.springframework.http.ResponseEntity)22 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)17 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 UUID (java.util.UUID)15 ArrayList (java.util.ArrayList)14 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)12 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)12 IOException (java.io.IOException)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)10