Search in sources :

Example 1 with EntityFactory

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;
}
Also used : HashMap(java.util.HashMap) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) HashSet(java.util.HashSet)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConnConfProperty (org.apache.syncope.common.lib.types.ConnConfProperty)1 ConnInstance (org.apache.syncope.core.persistence.api.entity.ConnInstance)1 EntityFactory (org.apache.syncope.core.persistence.api.entity.EntityFactory)1