use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.
the class ConnIdIcConnectorService method createObject.
@Override
public IcUidAttribute createObject(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, List<IcAttribute> attributes) {
Assert.notNull(connectorInstance);
Assert.notNull(connectorInstance.getConnectorKey());
Assert.notNull(connectorConfiguration);
Assert.notNull(attributes);
LOG.debug("Create object - ConnId ({} {})", connectorInstance.getConnectorKey().toString(), attributes.toString());
ConnectorFacade conn = getConnectorFacade(connectorInstance, connectorConfiguration);
Set<Attribute> connIdAttributes = new HashSet<>();
for (IcAttribute icAttribute : attributes) {
connIdAttributes.add(ConnIdIcConvertUtil.convertIcAttribute(icAttribute));
}
ObjectClass objectClassConnId = ConnIdIcConvertUtil.convertIcObjectClass(objectClass);
if (objectClassConnId == null) {
objectClassConnId = ObjectClass.ACCOUNT;
}
Uid uid = conn.create(objectClassConnId, connIdAttributes, null);
LOG.debug("Created object - ConnId ({} {}) Uid= {}", connectorInstance.getConnectorKey().toString(), attributes.toString(), uid);
return ConnIdIcConvertUtil.convertConnIdUid(uid);
}
use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.
the class IcComparableAttributeFilter method compare.
/**
* Call compareTo on the attribute values. If the attribute is not present
* in the {@link IcConnectorObject} return -1.
*/
public int compare(IcConnectorObject obj) {
int ret = -1;
IcAttribute attr = obj.getAttributeByName(getName());
if (attr != null && attr.getValues().size() == 1) {
// it must be a comparable because that's were testing against
if (!(attr.getValues().get(0) instanceof Comparable)) {
throw new IllegalArgumentException("Attribute value must be comparable!");
}
// grab this value and the on from the attribute an compare..
Object o1 = attr.getValues().get(0);
Object o2 = getValue();
ret = CollectionUtil.forceCompare(o1, o2);
}
return ret;
}
use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.
the class IcEqualsFilter method accept.
/**
* Determines whether the specified {@link IcConnectorObject} contains an
* attribute that has the same name and contains a value that is equals the
* value of the attribute that {@code IcFilterBuilder} placed into this
* filter.
* <p>
* Note that in the case of a multi-valued attribute, equality of values
* means that:
* <ul>
* <li>the value of the attribute in the connector object and the value of
* the attribute in the filter must contain
* <em>the same number of elements</em>; and that</li>
* <li>each element within the value of the attribute in the connector
* object must <em>equal the element that occupies the same position</em>
* within the value of the attribute in the filter.</li>
* </ul>
*
* @see IcFilter#accept(IcConnectorObject)
*/
@Override
public boolean accept(IcConnectorObject obj) {
boolean ret = false;
IcAttribute thisAttr = getAttribute();
IcAttribute attr = obj.getAttributeByName(thisAttr.getName());
if (attr != null) {
ret = thisAttr.equals(attr);
}
return ret;
}
use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method internalUpdate.
@Override
public IcUidAttribute internalUpdate(IcUidAttribute uid, IcObjectClass objectClass, List<IcAttribute> attributes) {
Assert.notNull(objectClass, "Object class cannot be null!");
Assert.notNull(attributes, "Attributes cannot be null!");
Assert.notNull(uid, "UID cannot be null!");
if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
throw new IcException("Only ACCOUNT object class is supported now!");
}
String uidValue = uid.getUidValue();
if (uidValue == null) {
throw new IcException("UID value cannot be null!");
}
// Find account by UID and System ID
VsAccountDto account = accountService.findByUidSystem(uidValue, systemId);
if (account == null) {
throw new IcException(MessageFormat.format("Vs account was not found for UID [{0}] and system ID [{1}]!", uidValue, systemId));
}
// Update UID - if is different
IcAttribute uidAttribute = geAttribute(attributes, IcAttributeInfo.NAME);
if (uidAttribute != null) {
Object attributeUidValue = uidAttribute.getValue();
if (!(attributeUidValue instanceof String)) {
throw new IcException(MessageFormat.format("UID attribute value [{0}] must be String!", attributeUidValue));
}
if (!uidValue.equals(attributeUidValue)) {
// TODO: Connector not supported more entity types!
LOG.info("Update account - UID is different (old: {} new: {})", uidValue, attributeUidValue);
account.setUid((String) attributeUidValue);
account = accountService.save(account);
// We have to change system entity directly from VS module
// (request can be started/executed async => standard
// process update UID in system entity (ACC module) will not
// works!)
updateSystemEntity(uidValue, attributeUidValue, true);
}
}
// Update ENABLE - if is different
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));
}
if (account.isEnable() != (Boolean) attributeEnableValue) {
account.setEnable((Boolean) attributeEnableValue);
account = accountService.save(account);
}
}
UUID accountId = account.getId();
// Update extended attributes
Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
updateFormAttributeValue(uidValue, virtualAttirbute, accountId, attributes);
});
return new IcUidAttributeImpl(IcAttributeInfo.NAME, account.getUid(), null);
}
use of eu.bcvsolutions.idm.ic.api.IcAttribute in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method updateFormAttributeValue.
private void updateFormAttributeValue(Object uidValue, String virtualAttirbute, UUID accountId, List<IcAttribute> attributes) {
IcAttribute attribute = geAttribute(attributes, virtualAttirbute);
if (attribute == null) {
return;
}
List<Object> values = attribute.getValues();
List<Serializable> serializableValues = new ArrayList<>();
if (values != null) {
values.forEach(value -> {
if (!(value instanceof Serializable)) {
throw new IcException(MessageFormat.format("Ic attribute value [{0}] is not Serializable! For account with UID [{1}].", value, uidValue));
}
serializableValues.add((Serializable) value);
});
}
formService.saveValues(accountId, VsAccount.class, this.formDefinition, virtualAttirbute, serializableValues);
}
Aggregations