use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class IdentitySyncTest method testSynchronizationCache.
@Test
public void testSynchronizationCache() {
SysSystemDto system = initData();
SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
IdmRoleDto defaultRole = helper.createRole();
// Set default role to sync configuration
config.setDefaultRole(defaultRole.getId());
config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
this.getBean().deleteAllResourceData();
String testLastName = "test-last-name-same-" + System.currentTimeMillis();
String testFirstName = "test-first-name";
String userOne = "test-1-" + System.currentTimeMillis();
this.getBean().setTestData(userOne, testFirstName, testLastName);
String userTwo = "test-2-" + System.currentTimeMillis();
this.getBean().setTestData(userTwo, testFirstName, testLastName);
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setEntityType(SystemEntityType.IDENTITY);
mappingFilter.setSystemId(system.getId());
mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent();
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto defaultMapping = mappings.get(0);
SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
attributeMappingFilter.setSystemMappingId(defaultMapping.getId());
List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
return attribute.getIdmPropertyName().equals(IdmIdentity_.firstName.getName());
}).findFirst().orElse(null);
Assert.assertNotNull(firstNameAttribute);
StringBuilder scriptGenerateUuid = new StringBuilder();
scriptGenerateUuid.append("import java.util.UUID;");
scriptGenerateUuid.append(System.lineSeparator());
scriptGenerateUuid.append("return UUID.randomUUID();");
String scriptName = "generateUuid";
IdmScriptDto scriptUuid = new IdmScriptDto();
scriptUuid.setCategory(IdmScriptCategory.TRANSFORM_FROM);
scriptUuid.setCode(scriptName);
scriptUuid.setName(scriptName);
scriptUuid.setScript(scriptGenerateUuid.toString());
scriptUuid = scriptService.save(scriptUuid);
IdmScriptAuthorityDto scriptAuth = new IdmScriptAuthorityDto();
scriptAuth.setClassName("java.util.UUID");
scriptAuth.setType(ScriptAuthorityType.CLASS_NAME);
scriptAuth.setScript(scriptUuid.getId());
scriptAuth = scriptAuthrotityService.save(scriptAuth);
// we must call script
StringBuilder transformationScript = new StringBuilder();
transformationScript.append("return scriptEvaluator.evaluate(");
transformationScript.append(System.lineSeparator());
transformationScript.append("scriptEvaluator.newBuilder()");
transformationScript.append(System.lineSeparator());
transformationScript.append(".setScriptCode('" + scriptName + "')");
transformationScript.append(System.lineSeparator());
transformationScript.append(".build());");
transformationScript.append(System.lineSeparator());
firstNameAttribute.setTransformFromResourceScript(transformationScript.toString());
firstNameAttribute.setCached(true);
firstNameAttribute = schemaAttributeMappingService.save(firstNameAttribute);
synchornizationService.setSynchronizationConfigId(config.getId());
synchornizationService.process();
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.WARNING);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
IdmIdentityFilter filter = new IdmIdentityFilter();
filter.setLastName(testLastName);
List<IdmIdentityDto> identities = identityService.find(filter, null).getContent();
assertEquals(2, identities.size());
//
IdmIdentityDto identityOne = identities.get(0);
IdmIdentityDto identityTwo = identities.get(1);
//
assertNotEquals(identityOne.getFirstName(), identityTwo.getFirstName());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class IdmScriptController method redeploy.
@ResponseBody
@RequestMapping(value = "/{backendId}/redeploy", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.SCRIPT_READ + "')")
@ApiOperation(value = "Redeploy script", nickname = "redeployScript", response = IdmScriptDto.class, tags = { IdmScriptController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCRIPT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCRIPT_READ, description = "") }) }, notes = "Redeploy script. Redeployed will be only scripts, that has pattern in resource." + " Before save newly loaded DO will be backup the old script into backup directory.")
public ResponseEntity<?> redeploy(@ApiParam(value = "Script's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
IdmScriptDto script = service.get(backendId);
if (script == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, backendId);
}
script = service.redeploy(script);
return new ResponseEntity<>(toResource(script), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptServiceIntegrationTest method deleteScriptRedeploy.
@Test
public void deleteScriptRedeploy() {
IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
IdmScriptDto script2 = scriptService.getByCode(TEST_SCRIPT_CODE_2);
assertNotNull(script1);
assertNotNull(script2);
scriptService.delete(script1);
scriptService.delete(script2);
script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
script2 = scriptService.getByCode(TEST_SCRIPT_CODE_2);
assertNull(script1);
assertNull(script2);
scriptService.init();
script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
script2 = scriptService.getByCode(TEST_SCRIPT_CODE_2);
assertNotNull(script1);
assertNotNull(script2);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptServiceIntegrationTest method backupMissingFolderExistEntity.
@Test
public void backupMissingFolderExistEntity() {
configurationService.setValue(Recoverable.BACKUP_FOLDER_CONFIG, null);
IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
assertNotNull(script1);
try {
scriptService.backup(script1);
fail();
} catch (ResultCodeException e) {
ResultCodeException resultCode = (ResultCodeException) e;
assertEquals(resultCode.getError().getError().getStatusEnum(), CoreResultCode.BACKUP_FOLDER_NOT_FOUND.name());
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto 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);
assertNotNull(script1);
assertNotNull(script2);
assertEquals(TEST_SCRIPT_CODE_1, script1.getCode());
assertEquals(TEST_SCRIPT_CODE_2, script2.getCode());
IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
filter.setScriptId(script1.getId());
List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(filter, null).getContent();
assertEquals(4, authorities.size());
filter.setScriptId(script2.getId());
authorities = scriptAuthorityService.find(filter, null).getContent();
assertEquals(0, authorities.size());
}
Aggregations