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;
}
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());
}
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();
}
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);
}
}
Aggregations