You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2015/10/30 12:34:42 UTC
[03/50] [abbrv] syncope git commit: [SYNCOPE-714] Preliminary changes
+ small refactoring of ConnectorService
[SYNCOPE-714] Preliminary changes + small refactoring of ConnectorService
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/93439817
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/93439817
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/93439817
Branch: refs/heads/SYNCOPE-156
Commit: 934398172f91b1128a0d3bac12c4a0ac2e1dea55
Parents: 7f584fb
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Fri Oct 23 11:04:39 2015 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Mon Oct 26 08:26:45 2015 +0100
----------------------------------------------------------------------
.../console/panels/ResourceConnConfPanel.java | 2 +-
.../console/rest/ConnectorRestClient.java | 23 +----------
.../rest/api/service/ConnectorService.java | 36 ++++++------------
.../syncope/core/logic/ConnectorLogic.java | 40 ++++++++++----------
.../java/data/ConnInstanceDataBinderImpl.java | 9 +++--
.../rest/cxf/service/ConnectorServiceImpl.java | 34 ++---------------
.../fit/core/reference/ConnectorITCase.java | 12 +++---
7 files changed, 50 insertions(+), 106 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/93439817/client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceConnConfPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceConnConfPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceConnConfPanel.java
index 1b536c4..246e0eb 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceConnConfPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/ResourceConnConfPanel.java
@@ -116,7 +116,7 @@ public class ResourceConnConfPanel extends Panel {
List<ConnConfProperty> props = new ArrayList<>();
Long connectorKey = resourceTO.getConnector();
if (connectorKey != null && connectorKey > 0) {
- for (ConnConfProperty property : restClient.getConnectorProperties(connectorKey)) {
+ for (ConnConfProperty property : restClient.read(connectorKey).getConfiguration()) {
if (property.isOverridable()) {
props.add(property);
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/93439817/client/console/src/main/java/org/apache/syncope/client/console/rest/ConnectorRestClient.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/rest/ConnectorRestClient.java b/client/console/src/main/java/org/apache/syncope/client/console/rest/ConnectorRestClient.java
index d3d18c8..8c84993 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/rest/ConnectorRestClient.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/rest/ConnectorRestClient.java
@@ -108,24 +108,6 @@ public class ConnectorRestClient extends BaseRestClient {
return bundles;
}
- /**
- * Get all configuration properties for the given connector instance.
- *
- * @param connectorId the connector id
- * @return List of ConnConfProperty, or an empty list in case none found
- */
- public List<ConnConfProperty> getConnectorProperties(final Long connectorId) {
- List<ConnConfProperty> properties = null;
-
- try {
- properties = getService(ConnectorService.class).getConfigurationProperties(connectorId);
- } catch (SyncopeClientException e) {
- LOG.error("While getting connector configuration properties", e);
- }
-
- return properties;
- }
-
private Set<ConnConfProperty> filterProperties(final Set<ConnConfProperty> properties) {
Set<ConnConfProperty> newProperties = new HashSet<>();
@@ -185,8 +167,7 @@ public class ConnectorRestClient extends BaseRestClient {
public List<String> getSchemaNames(final ConnInstanceTO connectorTO) {
List<String> schemaNames = new ArrayList<>();
try {
- List<PlainSchemaTO> response = getService(ConnectorService.class).
- getSchemaNames(connectorTO.getKey(), connectorTO, false);
+ List<PlainSchemaTO> response = getService(ConnectorService.class).buildSchemaNames(connectorTO, false);
for (PlainSchemaTO schema : response) {
schemaNames.add(schema.getKey());
}
@@ -203,7 +184,7 @@ public class ConnectorRestClient extends BaseRestClient {
public List<ConnIdObjectClass> getSupportedObjectClasses(final ConnInstanceTO connectorTO) {
List<ConnIdObjectClass> result = Collections.emptyList();
try {
- result = getService(ConnectorService.class).getSupportedObjectClasses(connectorTO.getKey(), connectorTO);
+ result = getService(ConnectorService.class).buildSupportedObjectClasses(connectorTO);
} catch (Exception e) {
LOG.error("While getting supported object classes", e);
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/93439817/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/ConnectorService.java
----------------------------------------------------------------------
diff --git a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/ConnectorService.java b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/ConnectorService.java
index 686d373..ea63718 100644
--- a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/ConnectorService.java
+++ b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/ConnectorService.java
@@ -37,7 +37,6 @@ import org.apache.syncope.common.lib.to.BulkActionResult;
import org.apache.syncope.common.lib.to.ConnBundleTO;
import org.apache.syncope.common.lib.to.ConnInstanceTO;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
-import org.apache.syncope.common.lib.types.ConnConfProperty;
import org.apache.syncope.common.lib.wrap.ConnIdObjectClass;
/**
@@ -58,47 +57,36 @@ public interface ConnectorService extends JAXRSService {
List<ConnBundleTO> getBundles(@QueryParam("lang") String lang);
/**
- * Returns configuration for given connector instance.
+ * Builds the list of schema names managed by the connector bundle matching the given connector instance key, with
+ * the provided configuration.
*
- * @param key connector instance key to read configuration from
- * @return configuration for given connector instance
- */
- @GET
- @Path("{key}/configuration")
- @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
- List<ConnConfProperty> getConfigurationProperties(@NotNull @PathParam("key") Long key);
-
- /**
- * Returns schema names for connector bundle matching the given connector instance key.
- *
- * @param key connector instance key to be used for schema lookup
- * @param connInstanceTO connector instance object to provide special configuration properties
+ * @param connInstanceTO connector instance object providing configuration properties
* @param includeSpecial if set to true, special schema names (like '__PASSWORD__') will be included;
* default is false
- * @return schema names for connector bundle matching the given connector instance key
+ * @return schema names for the connector bundle matching the given connector instance key, with the provided
+ * configuration
*/
@POST
@Path("{key}/schemaNames")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
- List<PlainSchemaTO> getSchemaNames(@NotNull @PathParam("key") Long key,
+ List<PlainSchemaTO> buildSchemaNames(
@NotNull ConnInstanceTO connInstanceTO,
@QueryParam("includeSpecial") @DefaultValue("false") boolean includeSpecial);
/**
- * Returns supported object classes for connector bundle matching the given connector instance key.
+ * Builds the list of supported ConnId object classes for the connector bundle matching the given connector instance
+ * key, with the provided configuration.
*
- * @param key connector instance key to be used for schema lookup
- * @param connInstanceTO connector instance object to provide special configuration properties
- * @return supported object classes for connector bundle matching the given connector instance key
+ * @param connInstanceTO connector instance object providing configuration properties
+ * @return supported object classes for the connector bundle matching the given connector instance key, with the
+ * provided configuration
*/
@POST
@Path("{key}/supportedObjectClasses")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
- List<ConnIdObjectClass> getSupportedObjectClasses(
- @NotNull @PathParam("key") Long key,
- @NotNull ConnInstanceTO connInstanceTO);
+ List<ConnIdObjectClass> buildSupportedObjectClasses(@NotNull ConnInstanceTO connInstanceTO);
/**
* Returns connector instance with matching key.
http://git-wip-us.apache.org/repos/asf/syncope/blob/93439817/core/logic/src/main/java/org/apache/syncope/core/logic/ConnectorLogic.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/ConnectorLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/ConnectorLogic.java
index 870a4d0..cc6aaed 100644
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/ConnectorLogic.java
+++ b/core/logic/src/main/java/org/apache/syncope/core/logic/ConnectorLogic.java
@@ -33,6 +33,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.syncope.common.lib.to.ConnBundleTO;
import org.apache.syncope.common.lib.to.ConnInstanceTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.ConnConfProperty;
import org.apache.syncope.common.lib.types.Entitlement;
@@ -204,7 +205,7 @@ public class ConnectorLogic extends AbstractTransactionalLogic<ConnInstanceTO> {
@PreAuthorize("hasRole('" + Entitlement.CONNECTOR_READ + "')")
@Transactional(readOnly = true)
- public List<String> getSchemaNames(final ConnInstanceTO connInstanceTO, final boolean includeSpecial) {
+ public List<PlainSchemaTO> buildSchemaNames(final ConnInstanceTO connInstanceTO, final boolean includeSpecial) {
ConnInstance connInstance = connInstanceDAO.find(connInstanceTO.getKey());
if (connInstance == null) {
throw new NotFoundException("Connector '" + connInstanceTO.getKey() + "'");
@@ -217,12 +218,22 @@ public class ConnectorLogic extends AbstractTransactionalLogic<ConnInstanceTO> {
// We cannot use Spring bean because this method could be used during resource definition or modification:
// bean couldn't exist or couldn't be updated.
// This is the reason why we should take a "not mature" connector facade proxy to ask for schema names.
- return new ArrayList<>(connFactory.createConnector(connInstance, conf).getSchemaNames(includeSpecial));
+ Set<String> schemaNames = connFactory.createConnector(connInstance, conf).getSchemaNames(includeSpecial);
+
+ return CollectionUtils.collect(schemaNames, new Transformer<String, PlainSchemaTO>() {
+
+ @Override
+ public PlainSchemaTO transform(final String name) {
+ PlainSchemaTO schemaTO = new PlainSchemaTO();
+ schemaTO.setKey(name);
+ return schemaTO;
+ }
+ }, new ArrayList<PlainSchemaTO>());
}
@PreAuthorize("hasRole('" + Entitlement.CONNECTOR_READ + "')")
@Transactional(readOnly = true)
- public List<String> getSupportedObjectClasses(final ConnInstanceTO connInstanceTO) {
+ public List<String> buildSupportedObjectClasses(final ConnInstanceTO connInstanceTO) {
ConnInstance connInstance = connInstanceDAO.find(connInstanceTO.getKey());
if (connInstance == null) {
throw new NotFoundException("Connector '" + connInstanceTO.getKey() + "'");
@@ -237,24 +248,13 @@ public class ConnectorLogic extends AbstractTransactionalLogic<ConnInstanceTO> {
// This is the reason why we should take a "not mature" connector facade proxy to ask for object classes.
Set<ObjectClass> objectClasses = connFactory.createConnector(connInstance, conf).getSupportedObjectClasses();
- List<String> result = new ArrayList<>(objectClasses.size());
- for (ObjectClass objectClass : objectClasses) {
- result.add(objectClass.getObjectClassValue());
- }
-
- return result;
- }
-
- @PreAuthorize("hasRole('" + Entitlement.CONNECTOR_READ + "')")
- @Transactional(readOnly = true)
- public List<ConnConfProperty> getConfigurationProperties(final Long connInstanceKey) {
-
- ConnInstance connInstance = connInstanceDAO.find(connInstanceKey);
- if (connInstance == null) {
- throw new NotFoundException("Connector '" + connInstanceKey + "'");
- }
+ return CollectionUtils.collect(objectClasses, new Transformer<ObjectClass, String>() {
- return new ArrayList<>(connInstance.getConfiguration());
+ @Override
+ public String transform(final ObjectClass objectClass) {
+ return objectClass.getObjectClassValue();
+ }
+ }, new ArrayList<String>());
}
@PreAuthorize("hasRole('" + Entitlement.CONNECTOR_READ + "')")
http://git-wip-us.apache.org/repos/asf/syncope/blob/93439817/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ConnInstanceDataBinderImpl.java
----------------------------------------------------------------------
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ConnInstanceDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ConnInstanceDataBinderImpl.java
index 3666d8f..7c28b66 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ConnInstanceDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/ConnInstanceDataBinderImpl.java
@@ -58,13 +58,14 @@ public class ConnInstanceDataBinderImpl implements ConnInstanceDataBinder {
private EntityFactory entityFactory;
@Override
- public Set<ConnConfProperty> mergeConnConfProperties(final Set<ConnConfProperty> primary,
+ public Set<ConnConfProperty> mergeConnConfProperties(
+ final Set<ConnConfProperty> primary,
final Set<ConnConfProperty> secondary) {
- final Set<ConnConfProperty> conf = new HashSet<>();
+ Set<ConnConfProperty> conf = new HashSet<>();
// to be used to control managed prop (needed by overridden mechanism)
- final Set<String> propertyNames = new HashSet<>();
+ Set<String> propertyNames = new HashSet<>();
// get overridden connector configuration properties
for (ConnConfProperty prop : primary) {
@@ -232,7 +233,7 @@ public class ConnInstanceDataBinderImpl implements ConnInstanceDataBinder {
property = new ConnConfProperty();
connInstanceTO.getConfiguration().add(property);
}
-
+
property.setSchema(schema);
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/93439817/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/ConnectorServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/ConnectorServiceImpl.java b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/ConnectorServiceImpl.java
index a970827..ac0694d 100644
--- a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/ConnectorServiceImpl.java
+++ b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/ConnectorServiceImpl.java
@@ -19,17 +19,13 @@
package org.apache.syncope.core.rest.cxf.service;
import java.net.URI;
-import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Response;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.Transformer;
import org.apache.syncope.common.lib.to.BulkAction;
import org.apache.syncope.common.lib.to.BulkActionResult;
import org.apache.syncope.common.lib.to.ConnBundleTO;
import org.apache.syncope.common.lib.to.ConnInstanceTO;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
-import org.apache.syncope.common.lib.types.ConnConfProperty;
import org.apache.syncope.common.lib.wrap.ConnIdObjectClass;
import org.apache.syncope.common.rest.api.CollectionWrapper;
import org.apache.syncope.common.rest.api.RESTHeaders;
@@ -64,35 +60,13 @@ public class ConnectorServiceImpl extends AbstractServiceImpl implements Connect
}
@Override
- public List<ConnConfProperty> getConfigurationProperties(final Long key) {
- return logic.getConfigurationProperties(key);
+ public List<PlainSchemaTO> buildSchemaNames(final ConnInstanceTO connInstanceTO, final boolean includeSpecial) {
+ return logic.buildSchemaNames(connInstanceTO, includeSpecial);
}
@Override
- public List<PlainSchemaTO> getSchemaNames(final Long key, final ConnInstanceTO connInstanceTO,
- final boolean includeSpecial) {
-
- connInstanceTO.setKey(key);
-
- return CollectionUtils.collect(logic.getSchemaNames(connInstanceTO, includeSpecial),
- new Transformer<String, PlainSchemaTO>() {
-
- @Override
- public PlainSchemaTO transform(final String name) {
- PlainSchemaTO schemaTO = new PlainSchemaTO();
- schemaTO.setKey(name);
- return schemaTO;
- }
- }, new ArrayList<PlainSchemaTO>());
- }
-
- @Override
- public List<ConnIdObjectClass> getSupportedObjectClasses(final Long key,
- final ConnInstanceTO connInstanceTO) {
-
- connInstanceTO.setKey(key);
-
- return CollectionWrapper.wrap(logic.getSupportedObjectClasses(connInstanceTO), ConnIdObjectClass.class);
+ public List<ConnIdObjectClass> buildSupportedObjectClasses(final ConnInstanceTO connInstanceTO) {
+ return CollectionWrapper.wrap(logic.buildSupportedObjectClasses(connInstanceTO), ConnIdObjectClass.class);
}
@Override
http://git-wip-us.apache.org/repos/asf/syncope/blob/93439817/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ConnectorITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ConnectorITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ConnectorITCase.java
index cc97936..71859a7 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ConnectorITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ConnectorITCase.java
@@ -397,7 +397,7 @@ public class ConnectorITCase extends AbstractITCase {
@Test
public void getConnectorConfiguration() {
- List<ConnConfProperty> props = connectorService.getConfigurationProperties(104L);
+ Set<ConnConfProperty> props = connectorService.read(104L, Locale.ENGLISH.getLanguage()).getConfiguration();
assertNotNull(props);
assertFalse(props.isEmpty());
}
@@ -541,13 +541,13 @@ public class ConnectorITCase extends AbstractITCase {
public void getSchemaNames() {
ConnInstanceTO conn = connectorService.read(101L, Locale.ENGLISH.getLanguage());
- List<PlainSchemaTO> schemaNames = connectorService.getSchemaNames(conn.getKey(), conn, true);
+ List<PlainSchemaTO> schemaNames = connectorService.buildSchemaNames(conn, true);
assertNotNull(schemaNames);
assertFalse(schemaNames.isEmpty());
assertNotNull(schemaNames.get(0).getKey());
assertNull(schemaNames.get(0).getEnumerationValues());
- schemaNames = connectorService.getSchemaNames(conn.getKey(), conn, false);
+ schemaNames = connectorService.buildSchemaNames(conn, false);
assertNotNull(schemaNames);
assertEquals(1, schemaNames.size());
@@ -557,7 +557,7 @@ public class ConnectorITCase extends AbstractITCase {
// to be used with overridden properties
conn.getConfiguration().clear();
- schemaNames = connectorService.getSchemaNames(conn.getKey(), conn, true);
+ schemaNames = connectorService.buildSchemaNames(conn, true);
assertNotNull(schemaNames);
assertFalse(schemaNames.isEmpty());
}
@@ -567,7 +567,7 @@ public class ConnectorITCase extends AbstractITCase {
ConnInstanceTO ldap = connectorService.read(105L, Locale.ENGLISH.getLanguage());
assertNotNull(ldap);
- List<ConnIdObjectClass> objectClasses = connectorService.getSupportedObjectClasses(ldap.getKey(), ldap);
+ List<ConnIdObjectClass> objectClasses = connectorService.buildSupportedObjectClasses(ldap);
assertNotNull(objectClasses);
assertEquals(2, objectClasses.size());
assertTrue(objectClasses.contains(
@@ -578,7 +578,7 @@ public class ConnectorITCase extends AbstractITCase {
ConnInstanceTO csv = connectorService.read(104L, Locale.ENGLISH.getLanguage());
assertNotNull(csv);
- objectClasses = connectorService.getSupportedObjectClasses(csv.getKey(), csv);
+ objectClasses = connectorService.buildSupportedObjectClasses(csv);
assertNotNull(objectClasses);
assertEquals(1, objectClasses.size());
assertTrue(objectClasses.contains(