use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class SystemDeleteProcessor method process.
@Override
public EventResult<SysSystemDto> process(EntityEvent<SysSystemDto> event) {
SysSystemDto system = event.getContent();
Assert.notNull(system);
//
// If exists unresolved vs request, then is not possible to delete
// system
VsRequestFilter requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setState(VsRequestState.IN_PROGRESS);
if (requestService.find(requestFilter, null).getTotalElements() > 0) {
throw new ResultCodeException(VsResultCode.VS_SYSTEM_DELETE_FAILED_HAS_REQUEST, ImmutableMap.of("system", system.getName()));
}
// Delete archived vs requests
requestFilter = new VsRequestFilter();
requestFilter.setSystemId(system.getId());
requestFilter.setOnlyArchived(Boolean.TRUE);
requestService.find(requestFilter, null).forEach(entity -> {
requestService.delete(entity);
});
// Delete vs account
VsAccountFilter accountFilter = new VsAccountFilter();
accountFilter.setSystemId(system.getId());
accountService.find(accountFilter, null).forEach(entity -> {
accountService.delete(entity);
});
// Delete vs account form definition
if (system.getConnectorKey() != null) {
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId());
IdmFormDefinitionDto definition = this.formDefinitionService.findOneByTypeAndCode(VsAccount.class.getName(), virtualSystemKey);
if (definition != null) {
formDefinitionService.delete(definition);
}
}
// Delete vs implementers
VsSystemImplementerFilter implementerFilter = new VsSystemImplementerFilter();
implementerFilter.setSystemId(system.getId());
systemImplementerService.find(implementerFilter, null).forEach(entity -> {
systemImplementerService.delete(entity);
});
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultVsAccountService method getIcAttributes.
@Override
public List<IcAttribute> getIcAttributes(VsAccountDto account) {
Assert.notNull(account);
List<IcAttribute> attributes = new ArrayList<>();
// Create uid attribute
IcAttributeImpl uidAttribute = new IcAttributeImpl(IcAttributeInfo.NAME, account.getUid());
attributes.add(uidAttribute);
// Create enable attribute
IcAttributeImpl enableAttribute = new IcAttributeImpl(IcAttributeInfo.ENABLE, account.isEnable());
attributes.add(enableAttribute);
String connectorKey = account.getConnectorKey();
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", connectorKey, account.getSystemId().toString());
String type = VsAccount.class.getName();
IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
if (definition == null) {
return attributes;
}
definition.getFormAttributes().forEach(formAttribute -> {
attributes.add(this.getIcAttribute(account.getId(), formAttribute.getName(), definition));
});
return attributes;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultVsSystemService method create.
@Override
public SysSystemDto create(VsSystemDto vsSystem) {
Assert.notNull(vsSystem, "Vs system dto cannot be null (for create new virtual system)");
Assert.notNull(vsSystem.getName(), "Vs system name cannot be null (for create new virtual system)");
LOG.info("Create new virtual system with name [{}].", vsSystem.getName());
SysSystemDto system = new SysSystemDto();
// Find connector for VS
Class<? extends VsVirtualConnector> defaultVirtualConnector = BasicVirtualConnector.class;
IcConnectorClass connectorAnnotation = defaultVirtualConnector.getAnnotation(IcConnectorClass.class);
IcConnectorInfo info = CzechIdMIcConvertUtil.convertConnectorClass(connectorAnnotation, (Class<? extends IcConnector>) defaultVirtualConnector);
// Set connector key for VS
system.setConnectorKey(new SysConnectorKeyDto(info.getConnectorKey()));
system.setName(vsSystem.getName());
// Create system
system = this.systemService.save(system, IdmBasePermission.CREATE);
// Find and update attributes for implementers
IdmFormDefinitionDto connectorFormDef = this.systemService.getConnectorFormDefinition(system.getConnectorInstance());
IdmFormAttributeDto implementersFormAttr = connectorFormDef.getMappedAttributeByCode(IMPLEMENTERS_PROPERTY);
formService.saveValues(system, implementersFormAttr, new ArrayList<>(vsSystem.getImplementers()));
IdmFormAttributeDto implementerRolesFormAttr = connectorFormDef.getMappedAttributeByCode(IMPLEMENTER_ROLES_PROPERTY);
formService.saveValues(system, implementerRolesFormAttr, new ArrayList<>(vsSystem.getImplementerRoles()));
IdmFormAttributeDto attributesFormAttr = connectorFormDef.getMappedAttributeByCode(ATTRIBUTES_PROPERTY);
if (!vsSystem.getAttributes().isEmpty()) {
formService.saveValues(system, attributesFormAttr, new ArrayList<>(vsSystem.getAttributes()));
} else {
List<Serializable> defaultAttributes = Lists.newArrayList((Serializable[]) BasicVirtualConfiguration.DEFAULT_ATTRIBUTES);
defaultAttributes.add(RIGHTS_ATTRIBUTE);
formService.saveValues(system, attributesFormAttr, defaultAttributes);
}
this.systemService.checkSystem(system);
// Search attribute definition for rights and set him to multivalue
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId().toString());
String type = VsAccount.class.getName();
IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
IdmFormAttributeDto rightsFormAttr = formAttributeService.findAttribute(type, definition.getCode(), RIGHTS_ATTRIBUTE);
if (rightsFormAttr != null) {
rightsFormAttr.setMultiple(true);
formService.saveAttribute(rightsFormAttr);
}
// Generate schema
List<SysSchemaObjectClassDto> schemas = this.systemService.generateSchema(system);
SysSchemaObjectClassDto schemaAccount = schemas.stream().filter(schema -> IcObjectClassInfo.ACCOUNT.equals(schema.getObjectClassName())).findFirst().orElse(null);
Assert.notNull(schemaAccount, "We cannot found schema for ACCOUNT!");
// Create mapping by default attributes
this.createDefaultMapping(system, schemaAccount, vsSystem);
return this.systemService.get(system.getId());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityServiceIntegrationTest method testReferentialIntegrity.
@Test
public void testReferentialIntegrity() {
IdmIdentityDto identity = helper.createIdentity();
String username = identity.getUsername();
// eav
IdmFormDefinitionDto formDefinition = formService.getDefinition(IdmIdentity.class);
IdmFormValueDto value1 = new IdmFormValueDto(formDefinition.getMappedAttributeByCode(InitDemoData.FORM_ATTRIBUTE_PASSWORD));
value1.setValue("one");
formService.saveValues(identity.getId(), IdmIdentity.class, formDefinition, Lists.newArrayList(value1));
// role with guarantee
IdmRoleDto role = new IdmRoleDto();
String roleName = "test_r_" + System.currentTimeMillis();
role.setName(roleName);
IdmRoleGuaranteeDto roleGuarantee = new IdmRoleGuaranteeDto();
roleGuarantee.setRole(role.getId());
roleGuarantee.setGuarantee(identity.getId());
role.setGuarantees(Lists.newArrayList(roleGuarantee));
role = roleService.save(role);
// contract
IdmIdentityContractDto contract = helper.createIdentityContact(identity);
// contract guarantee
IdmIdentityContractDto contract2 = helper.createIdentityContact(identityService.getByUsername(InitTestData.TEST_USER_1));
contractGuaranteeService.save(new IdmContractGuaranteeDto(contract2.getId(), identity.getId()));
// assigned role
helper.createIdentityRole(contract, role);
IdmIdentityRoleFilter identityRolefilter = new IdmIdentityRoleFilter();
identityRolefilter.setIdentityId(identity.getId());
assertEquals(1, role.getGuarantees().size());
assertNotNull(identityService.getByUsername(username));
assertNotNull(passwordService.findOneByIdentity(identity.getId()));
assertEquals(1, formService.getValues(identity).size());
assertEquals(username, roleGuaranteeRepository.findAllByRole_Id(role.getId()).get(0).getGuarantee().getUsername());
assertEquals(1, identityRoleService.find(identityRolefilter, null).getTotalElements());
// + default contract is created
assertEquals(2, identityContractService.findAllByIdentity(identity.getId()).size());
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contract2.getId());
List<IdmContractGuaranteeDto> guarantees = contractGuaranteeService.find(filter, null).getContent();
assertEquals(1, guarantees.size());
assertEquals(identity.getId(), guarantees.get(0).getGuarantee());
//
identityService.delete(identity);
role = roleService.get(role.getId());
//
assertEquals(0, role.getGuarantees().size());
assertNull(identityService.getByUsername(username));
assertNull(passwordService.findOneByIdentity(identity.getId()));
assertEquals(0, identityContractService.findAllByIdentity(identity.getId()).size());
assertEquals(0, identityRoleService.find(identityRolefilter, null).getTotalElements());
assertEquals(0, contractGuaranteeService.find(filter, null).getTotalElements());
// TODO: transactions?
// assertEquals(0, roleGuaranteeRepository.findAllByRole_Id(role.getId()).size());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto in project CzechIdMng by bcvsolutions.
the class DefaultCommonFormServiceIntegrationTest method createDefinition.
private IdmFormAttributeDto createDefinition() {
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(helper.createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), helper.createName(), Lists.newArrayList(attributeDefinitionOne));
return formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
}
Aggregations