3434import org .apache .syncope .common .lib .to .PlainSchemaTO ;
3535import org .apache .syncope .common .lib .types .AttrSchemaType ;
3636import org .apache .syncope .common .lib .types .ClientExceptionType ;
37+ import org .apache .syncope .common .lib .types .ConnConfProperty ;
3738import org .apache .syncope .common .lib .types .IdMEntitlement ;
3839import org .apache .syncope .core .persistence .api .dao .ConnInstanceDAO ;
3940import org .apache .syncope .core .persistence .api .dao .ExternalResourceDAO ;
@@ -109,7 +110,7 @@ public ConnInstanceTO create(final ConnInstanceTO connInstanceTO) {
109110 connInstanceTO .getAdminRealm ());
110111 securityChecks (effectiveRealms , connInstanceTO .getAdminRealm (), null );
111112
112- return binder .getConnInstanceTO (doSave (binder .getConnInstance (connInstanceTO )));
113+ return binder .getConnInstanceTO (doSave (binder .create (connInstanceTO )));
113114 }
114115
115116 @ PreAuthorize ("hasRole('" + IdMEntitlement .CONNECTOR_UPDATE + "')" )
@@ -163,10 +164,8 @@ public List<ConnInstanceTO> list(final String lang) {
163164 public ConnInstanceTO read (final String key , final String lang ) {
164165 CurrentLocale .set (StringUtils .isBlank (lang ) ? Locale .ENGLISH : Locale .of (lang ));
165166
166- ConnInstance connInstance = connInstanceDAO .authFind (key );
167- if (connInstance == null ) {
168- throw new NotFoundException ("Connector '" + key + '\'' );
169- }
167+ ConnInstance connInstance = Optional .ofNullable (connInstanceDAO .authFind (key )).
168+ orElseThrow (() -> new NotFoundException ("Connector '" + key + '\'' ));
170169
171170 return binder .getConnInstanceTO (connInstance );
172171 }
@@ -195,7 +194,7 @@ public List<ConnIdBundle> getBundles(final String lang) {
195194
196195 ConfigurationProperties properties = connIdBundleManager .getConfigurationProperties (bundle );
197196 connBundleTO .getProperties ().addAll (properties .getPropertyNames ().stream ().
198- map (propName -> binder .build (properties .getProperty (propName ))).
197+ map (propName -> ConnInstanceDataBinder .build (properties .getProperty (propName ))).
199198 toList ());
200199
201200 return connBundleTO ;
@@ -208,13 +207,12 @@ public List<ConnIdBundle> getBundles(final String lang) {
208207 public List <ConnIdObjectClass > buildObjectClassInfo (
209208 final ConnInstanceTO connInstanceTO , final boolean includeSpecial ) {
210209
211- ConnInstanceTO actual = connInstanceDAO .findById (connInstanceTO .getKey ()).
212- map (binder ::getConnInstanceTO ).
213- orElse (connInstanceTO );
210+ ConnInstance connInstance = Optional .ofNullable (connInstanceDAO .authFind (connInstanceTO .getKey ())).
211+ orElseThrow (() -> new NotFoundException ("Connector '" + connInstanceTO .getKey () + '\'' ));
214212
215213 Set <ObjectClassInfo > objectClassInfo = connectorManager .createConnector (
216214 connectorManager .buildConnInstanceOverride (
217- actual , Optional .of (connInstanceTO .getConf ()), Optional .empty ())).
215+ connInstance , Optional .of (connInstanceTO .getConf ()), Optional .empty ())).
218216 getObjectClassInfo ();
219217
220218 return objectClassInfo .stream ().map (info -> {
@@ -244,24 +242,22 @@ public List<ConnIdObjectClass> buildObjectClassInfo(
244242 + "or hasRole('" + IdMEntitlement .CONNECTOR_UPDATE + "'))" )
245243 @ Transactional (readOnly = true )
246244 public void check (final ConnInstanceTO connInstanceTO ) {
247- if (connInstanceTO .getAdminRealm () == null ) {
248- throw SyncopeClientException .build (ClientExceptionType .InvalidRealm );
249- }
245+ Optional .ofNullable (connInstanceTO .getKey ()).flatMap (connInstanceDAO ::findById ).ifPresent (connInstance -> {
246+ List <ConnConfProperty > newConf =
247+ ConnInstanceDataBinder .newConf (connInstance .getConf (), connInstanceTO .getConf ());
248+ connInstanceTO .getConf ().clear ();
249+ connInstanceTO .getConf ().addAll (newConf );
250+ });
250251
251- connectorManager .createConnector (binder .getConnInstance (connInstanceTO )).test ();
252+ connectorManager .createConnector (binder .create (connInstanceTO )).test ();
252253 }
253254
254255 @ PreAuthorize ("hasRole('" + IdMEntitlement .CONNECTOR_READ + "')" )
255256 @ Transactional (readOnly = true )
256257 public ConnInstanceTO readByResource (final String resourceName , final String lang ) {
257- CurrentLocale .set (StringUtils .isBlank (lang ) ? Locale .ENGLISH : Locale .of (lang ));
258-
259258 ExternalResource resource = resourceDAO .findById (resourceName ).
260259 orElseThrow (() -> new NotFoundException ("Resource " + resourceName ));
261- ConnInstanceTO connInstance = binder .getConnInstanceTO (
262- connectorManager .getConnector (resource ).getConnInstance ());
263- connInstance .setKey (resource .getConnector ().getKey ());
264- return connInstance ;
260+ return read (resource .getConnector ().getKey (), lang );
265261 }
266262
267263 @ PreAuthorize ("hasRole('" + IdMEntitlement .CONNECTOR_RELOAD + "')" )
0 commit comments