use of org.apache.syncope.core.persistence.api.entity.EntityFactory in project syncope by apache.
the class ConnectorManager method buildConnInstanceOverride.
@Override
public ConnInstance buildConnInstanceOverride(final ConnInstanceTO connInstance, final Collection<ConnConfProperty> confOverride, final Collection<ConnectorCapability> capabilitiesOverride) {
synchronized (this) {
if (entityFactory == null) {
entityFactory = ApplicationContextProvider.getApplicationContext().getBean(EntityFactory.class);
}
}
ConnInstance override = entityFactory.newEntity(ConnInstance.class);
override.setAdminRealm(realmDAO.findByFullPath(connInstance.getAdminRealm()));
override.setConnectorName(connInstance.getConnectorName());
override.setDisplayName(connInstance.getDisplayName());
override.setBundleName(connInstance.getBundleName());
override.setVersion(connInstance.getVersion());
override.setLocation(connInstance.getLocation());
override.setConf(connInstance.getConf());
override.getCapabilities().addAll(connInstance.getCapabilities());
override.setConnRequestTimeout(connInstance.getConnRequestTimeout());
Map<String, ConnConfProperty> overridable = new HashMap<>();
Set<ConnConfProperty> conf = new HashSet<>();
for (ConnConfProperty prop : override.getConf()) {
if (prop.isOverridable()) {
overridable.put(prop.getSchema().getName(), prop);
} else {
conf.add(prop);
}
}
// add override properties
for (ConnConfProperty prop : confOverride) {
if (overridable.containsKey(prop.getSchema().getName()) && !prop.getValues().isEmpty()) {
conf.add(prop);
overridable.remove(prop.getSchema().getName());
}
}
// add override properties not substituted
conf.addAll(overridable.values());
override.setConf(conf);
// replace capabilities
if (capabilitiesOverride != null) {
override.getCapabilities().clear();
override.getCapabilities().addAll(capabilitiesOverride);
}
return override;
}
Aggregations