Search in sources :

Example 6 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 7 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 8 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 9 with ResultCodeException

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());
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 10 with ResultCodeException

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());
    }
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOException(java.io.IOException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)430 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)107 ApiOperation (io.swagger.annotations.ApiOperation)104 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)101 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)99 UUID (java.util.UUID)90 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)89 Test (org.junit.Test)70 Transactional (org.springframework.transaction.annotation.Transactional)54 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)53 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)53 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)49 IOException (java.io.IOException)48 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)47 ResponseEntity (org.springframework.http.ResponseEntity)43 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)38 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)31 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)27 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)26