Search in sources :

Example 6 with IdmScriptAuthorityFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter in project CzechIdMng by bcvsolutions.

the class ScriptDuplicateBulkActionIntegrationTest method compareScriptAuthority.

/**
 * Temporary function for script authority comparison
 *
 * @param script1
 * @param script2
 * @return
 */
private boolean compareScriptAuthority(IdmScriptDto script1, IdmScriptDto script2) {
    IdmScriptAuthorityFilter filt = new IdmScriptAuthorityFilter();
    filt.setScriptId(script1.getId());
    List<IdmScriptAuthorityDto> script1Auth = scriptAuthorityService.find(filt, null).getContent();
    filt.setScriptId(script2.getId());
    List<IdmScriptAuthorityDto> script2Auth = scriptAuthorityService.find(filt, null).getContent();
    Assert.assertEquals(script1Auth.size(), script2Auth.size());
    for (IdmScriptAuthorityDto orig : script2Auth) {
        boolean exists = script1Auth.stream().filter(tested -> {
            return StringUtils.equals(orig.getService(), tested.getService()) && StringUtils.equals(orig.getClassName(), tested.getClassName()) && Objects.equals(orig.getType(), tested.getType());
        }).count() > 0;
        if (!exists) {
            return false;
        }
    }
    return true;
}
Also used : IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)

Example 7 with IdmScriptAuthorityFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptServiceIntegrationTest method initTest.

@Test
public void initTest() {
    IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
    IdmScriptDto script2 = scriptService.getByCode(TEST_SCRIPT_CODE_2);
    Assert.assertNotNull(script1);
    Assert.assertNotNull(script2);
    Assert.assertEquals(TEST_SCRIPT_CODE_1, script1.getCode());
    Assert.assertEquals(TEST_SCRIPT_CODE_2, script2.getCode());
    IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
    filter.setScriptId(script1.getId());
    List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(filter, null).getContent();
    Assert.assertEquals(4, authorities.size());
    filter.setScriptId(script2.getId());
    authorities = scriptAuthorityService.find(filter, null).getContent();
    Assert.assertEquals(0, authorities.size());
    filter = new IdmScriptAuthorityFilter();
    filter.setText(script1.getCode());
    authorities = scriptAuthorityService.find(filter, null).getContent();
    Assert.assertEquals(4, authorities.size());
    filter.setText(script2.getCode());
    authorities = scriptAuthorityService.find(filter, null).getContent();
    Assert.assertEquals(0, authorities.size());
}
Also used : IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 8 with IdmScriptAuthorityFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter in project CzechIdMng by bcvsolutions.

the class AbstractScriptEvaluator method getScriptAuthorityForScript.

/**
 * Method find {@link IdmScriptAuthority} for {@link IdmScript} id
 * @param scriptId
 * @return
 */
private List<IdmScriptAuthorityDto> getScriptAuthorityForScript(UUID scriptId) {
    IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
    filter.setScriptId(scriptId);
    return scriptAuthorityService.find(filter, null).getContent();
}
Also used : IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)

Example 9 with IdmScriptAuthorityFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptService method backup.

@Override
public void backup(IdmScriptDto 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 script: {} failed, backup folder path: [{}] can't be created.", dto.getCode(), backupFolder.getAbsolutePath());
            throw new ResultCodeException(CoreResultCode.BACKUP_FAIL, ImmutableMap.of("code", dto.getCode()));
        }
    }
    // 
    IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
    filter.setScriptId(dto.getId());
    IdmScriptType type = dtoToType(dto, this.scriptAuthorityService.find(filter, null).getContent());
    // 
    File file = new File(getBackupFileName(directory, dto));
    LOG.info("Backup for script code: [{}] to file: [{}]", dto.getCode(), file.getAbsolutePath());
    try {
        jaxbMarshaller.marshal(type, file);
    } catch (JAXBException e) {
        LOG.error("Backup for script: {} failed, error message: {}", dto.getCode(), e.getLocalizedMessage(), e);
        throw new ResultCodeException(CoreResultCode.BACKUP_FAIL, ImmutableMap.of("code", dto.getCode()), e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) IdmScriptType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptType) JAXBException(javax.xml.bind.JAXBException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) File(java.io.File) IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)

Aggregations

IdmScriptAuthorityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)9 IdmScriptAuthorityDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)6 IdmScriptDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 Test (org.junit.Test)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 IdmScriptType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptType)2 File (java.io.File)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 IdmScriptCategory (eu.bcvsolutions.idm.core.api.domain.IdmScriptCategory)1 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)1 IdmScriptAuthorityService (eu.bcvsolutions.idm.core.api.service.IdmScriptAuthorityService)1 Recoverable (eu.bcvsolutions.idm.core.api.service.Recoverable)1 ZipUtils (eu.bcvsolutions.idm.core.api.utils.ZipUtils)1 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)1 AttachableEntity (eu.bcvsolutions.idm.core.ecm.api.entity.AttachableEntity)1 AttachmentManager (eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager)1 IdmScriptAllowClassType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType)1 IdmScriptAllowClassesType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassesType)1