Search in sources :

Example 16 with IcAttribute

use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method overwriteAttributesByUnresolvedRequests.

/**
 * Overwrite attributes form VS account with attributes from unresloved requests
 *
 * @param account
 *
 * @param account
 * @param vsAttributes
 * @return
 */
private List<IcAttribute> overwriteAttributesByUnresolvedRequests(VsAccountDto account, String uid, List<IcAttribute> vsAttributes) {
    Map<String, IcAttribute> attributesMap = new HashMap<>();
    List<VsRequestDto> unresolvedRequests = requestService.findDuplicities(uid, this.systemId);
    vsAttributes.forEach(attribute -> {
        attributesMap.put(attribute.getName(), attribute);
    });
    if (unresolvedRequests != null) {
        unresolvedRequests = Lists.reverse(unresolvedRequests);
        boolean deleteAccount = false;
        boolean createAccount = false;
        for (VsRequestDto request : unresolvedRequests) {
            if (VsOperationType.DELETE == request.getOperationType()) {
                deleteAccount = true;
                createAccount = false;
                continue;
            }
            if (VsOperationType.CREATE == request.getOperationType()) {
                deleteAccount = false;
                createAccount = true;
            }
            // VsRequestDto fullRequest =
            // requestService.get(request.getId());
            VsRequestDto fullRequest = request;
            if (fullRequest.getConnectorObject() != null && fullRequest.getConnectorObject().getAttributes() != null) {
                fullRequest.getConnectorObject().getAttributes().forEach(attribute -> {
                    attributesMap.put(attribute.getName(), attribute);
                });
            }
        }
        // return null
        if (deleteAccount) {
            return null;
        }
        // return null
        if (account == null && !createAccount) {
            return null;
        }
    }
    return new ArrayList<>(attributesMap.values());
}
Also used : IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto)

Example 17 with IcAttribute

use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method internalCreate.

@Override
public IcUidAttribute internalCreate(IcObjectClass objectClass, List<IcAttribute> attributes) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(attributes, "Attributes cannot be null!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    IcAttribute uidAttribute = geAttribute(attributes, IcAttributeInfo.NAME);
    if (uidAttribute == null) {
        throw new IcException("UID attribute was not found!");
    }
    Object uidValue = uidAttribute.getValue();
    if (!(uidValue instanceof String)) {
        throw new IcException(MessageFormat.format("UID attribute value [{0}] must be String!", uidValue));
    }
    String uid = (String) uidValue;
    // Find account by UID and System ID - If will be found, then we will do
    // update instead create
    VsAccountDto account = accountService.findByUidSystem(uid, systemId);
    if (account != null) {
        LOG.info("Create account - Virtual system account for UID [{}] already exist. We will execute update!", uidValue);
        return this.internalUpdate(new IcUidAttributeImpl(null, uid, null), objectClass, attributes);
    }
    account = new VsAccountDto();
    // Set ENABLE - if is supported
    IcAttribute enableAttribute = geAttribute(attributes, IcAttributeInfo.ENABLE);
    if (enableAttribute != null && this.virtualConfiguration.isDisableSupported()) {
        Object attributeEnableValue = enableAttribute.getValue();
        if (!(attributeEnableValue instanceof Boolean)) {
            throw new IcException(MessageFormat.format("ENABLE attribute value [{0}] must be Boolean!", attributeEnableValue));
        }
        account.setEnable((Boolean) attributeEnableValue);
    }
    account.setUid(uid);
    account.setSystemId(this.systemId);
    account.setConnectorKey(connectorKey);
    account = accountService.save(account);
    UUID accountId = account.getId();
    // Attributes from definition and configuration
    Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
        updateFormAttributeValue(uidValue, virtualAttirbute, accountId, attributes);
    });
    // We have to change system entity directly (set wish=false!!!) from VS module
    // (request can be started/executed async => standard
    // process update UID in system entity (ACC module) will not
    // works!)
    updateSystemEntity(uid, uid, false);
    return new IcUidAttributeImpl(IcAttributeInfo.NAME, account.getUid(), null);
}
Also used : IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) UUID(java.util.UUID)

Example 18 with IcAttribute

use of eu.bcvsolutions.idm.ic.api.IcAttribute 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;
}
Also used : IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) ArrayList(java.util.ArrayList) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)

Example 19 with IcAttribute

use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestService method getVsConnectorObject.

@Override
public IcConnectorObject getVsConnectorObject(VsRequestDto request) {
    LOG.info(MessageFormat.format("Start read vs connector object [{0}].", request));
    Assert.notNull(request, "VS request cannot be null!");
    Assert.notNull(request.getConnectorObject(), "Connector object in request cannot be null!");
    // Find account by UID and System ID
    VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
    if (account == null) {
        return null;
    }
    BasicVirtualConfiguration configuration = getVirtualConnector(request).getVirtualConfiguration();
    List<IcAttribute> attributes = accountService.getIcAttributes(account);
    // result list
    if (!configuration.isDisableSupported()) {
        IcAttribute enableAttribute = attributes.stream().filter(attribute -> attribute.getName().equals(IcAttributeInfo.ENABLE)).findFirst().orElse(null);
        if (enableAttribute != null) {
            attributes.remove(enableAttribute);
        }
    }
    IcConnectorObjectImpl connectorObject = new IcConnectorObjectImpl();
    connectorObject.setUidValue(account.getUid());
    connectorObject.setObjectClass(request.getConnectorObject().getObjectClass());
    connectorObject.setAttributes(attributes);
    return connectorObject;
}
Also used : IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration)

Example 20 with IcAttribute

use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestService method getWishConnectorObject.

@Override
public VsConnectorObjectDto getWishConnectorObject(VsRequestDto request) {
    LOG.info(MessageFormat.format("Start read wish connector object [{0}].", request));
    Assert.notNull(request, "VS request cannot be null!");
    List<VsAttributeDto> resultAttributes = new ArrayList<>();
    IcConnectorObject realConnectorObject = this.getVsConnectorObject(request);
    IcConnectorObject currentObject = realConnectorObject != null ? realConnectorObject : new IcConnectorObjectImpl();
    IcConnectorObject changeObject = request.getConnectorObject() != null ? request.getConnectorObject() : new IcConnectorObjectImpl();
    List<IcAttribute> currentAttributes = currentObject.getAttributes();
    List<IcAttribute> changedAttributes = request.getConnectorObject().getAttributes();
    // First add all new attributes
    changedAttributes.forEach(changedAttribute -> {
        if (currentObject.getAttributeByName(changedAttribute.getName()) == null) {
            VsAttributeDto vsAttribute = new VsAttributeDto(changedAttribute.getName(), changedAttribute.isMultiValue(), true);
            if (changedAttribute.isMultiValue()) {
                if (changedAttribute.getValues() != null) {
                    changedAttribute.getValues().forEach(value -> {
                        vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
                    });
                }
            } else {
                vsAttribute.setValue(new VsAttributeValueDto(changedAttribute.getValue(), null, VsValueChangeType.ADDED));
            }
            resultAttributes.add(vsAttribute);
        }
    });
    // Second add all already exists attributes
    currentAttributes.forEach(currentAttribute -> {
        VsAttributeDto vsAttribute;
        // Attribute was changed
        if (changeObject.getAttributeByName(currentAttribute.getName()) != null) {
            vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), true);
            IcAttribute changedAttribute = changeObject.getAttributeByName(currentAttribute.getName());
            if (changedAttribute.isMultiValue()) {
                if (changedAttribute.getValues() != null) {
                    changedAttribute.getValues().forEach(value -> {
                        if (currentAttribute.getValues() != null && currentAttribute.getValues().contains(value)) {
                            vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
                        } else {
                            vsAttribute.getValues().add(new VsAttributeValueDto(value, null, VsValueChangeType.ADDED));
                        }
                    });
                }
                if (currentAttribute.getValues() != null) {
                    currentAttribute.getValues().forEach(value -> {
                        if (changedAttribute.getValues() == null || !changedAttribute.getValues().contains(value)) {
                            vsAttribute.getValues().add(new VsAttributeValueDto(value, value, VsValueChangeType.REMOVED));
                        }
                    });
                }
            } else {
                Object changedValue = changedAttribute.getValue();
                Object currentValue = currentAttribute.getValue();
                if ((changedValue == null && currentValue == null) || (changedValue != null && changedValue.equals(currentObject)) || (currentValue != null && currentValue.equals(changedValue))) {
                    vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, null));
                } else {
                    vsAttribute.setValue(new VsAttributeValueDto(changedValue, currentValue, VsValueChangeType.UPDATED));
                }
            }
        } else {
            // Attribute was not changed
            vsAttribute = new VsAttributeDto(currentAttribute.getName(), currentAttribute.isMultiValue(), false);
            if (currentAttribute.isMultiValue()) {
                if (currentAttribute.getValues() != null) {
                    currentAttribute.getValues().forEach(value -> {
                        vsAttribute.getValues().add(new VsAttributeValueDto(value, value, null));
                    });
                }
            } else {
                vsAttribute.setValue(new VsAttributeValueDto(currentAttribute.getValue(), currentAttribute.getValue(), null));
            }
        }
        resultAttributes.add(vsAttribute);
    });
    BasicVirtualConfiguration configuration = getVirtualConnector(request).getVirtualConfiguration();
    // result list
    if (!configuration.isDisableSupported()) {
        VsAttributeDto enableAttribute = resultAttributes.stream().filter(attribute -> attribute.getName().equals(IcAttributeInfo.ENABLE)).findFirst().orElse(null);
        if (enableAttribute != null) {
            resultAttributes.remove(enableAttribute);
        }
    }
    VsConnectorObjectDto wishObject = new VsConnectorObjectDto();
    wishObject.setUid(request.getUid());
    wishObject.setAttributes(resultAttributes);
    return wishObject;
}
Also used : VsAttributeDto(eu.bcvsolutions.idm.vs.dto.VsAttributeDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ArrayList(java.util.ArrayList) VsAttributeValueDto(eu.bcvsolutions.idm.vs.dto.VsAttributeValueDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration)

Aggregations

IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)36 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)19 ArrayList (java.util.ArrayList)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)13 UUID (java.util.UUID)12 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)11 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)11 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)10 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)10 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)10 IcConnectorFacade (eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade)10 List (java.util.List)10 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)9 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)9 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)9 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)9 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)8