From 22cb943fb88ebea22d39545ba7014e732228ea43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Tue, 24 Sep 2024 09:11:24 +0200 Subject: [PATCH] Reflow --- .../impl/serializer/CommonObjectHandlers.java | 281 +++++++----------- .../api/ConnectorInfoManagerTestBase.java | 13 +- .../common/objects/AttributeInfo.java | 148 ++++----- .../common/objects/AttributeInfoBuilder.java | 97 +++--- .../common/objects/BaseConnectorObject.java | 8 +- .../common/objects/ConnectorObject.java | 3 +- .../objects/ConnectorObjectBuilder.java | 11 +- .../ConnectorObjectIdentification.java | 4 +- .../objects/ConnectorObjectReference.java | 33 +- .../common/objects/ObjectClassInfo.java | 45 +-- .../objects/ObjectClassInfoBuilder.java | 41 +-- .../testconnector/TstConnector.java | 103 ++++--- .../testconnector/TstConnector.java | 12 +- 13 files changed, 398 insertions(+), 401 deletions(-) diff --git a/java/connector-framework-internal/src/main/java/org/identityconnectors/framework/impl/serializer/CommonObjectHandlers.java b/java/connector-framework-internal/src/main/java/org/identityconnectors/framework/impl/serializer/CommonObjectHandlers.java index 28e31335..b116d501 100644 --- a/java/connector-framework-internal/src/main/java/org/identityconnectors/framework/impl/serializer/CommonObjectHandlers.java +++ b/java/connector-framework-internal/src/main/java/org/identityconnectors/framework/impl/serializer/CommonObjectHandlers.java @@ -27,10 +27,12 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; import org.identityconnectors.common.script.Script; import org.identityconnectors.common.script.ScriptBuilder; @@ -61,10 +63,9 @@ */ class CommonObjectHandlers { - public static final List HANDLERS = new ArrayList(); + public static final List HANDLERS = new ArrayList<>(); - private static abstract class AttributeHandler extends - AbstractObjectSerializationHandler { + private static abstract class AttributeHandler extends AbstractObjectSerializationHandler { protected AttributeHandler(final Class clazz, final String typeName) { super(clazz, typeName); @@ -74,7 +75,7 @@ protected AttributeHandler(final Class clazz, final String typeName) { public final Object deserialize(final ObjectDecoder decoder) { final String name = decoder.readStringField("name", null); @SuppressWarnings("unchecked") - final List value = (List) decoder.readObjectField("Values", List.class, null); + final List value = (List) decoder.readObjectField("Values", List.class, null); return createAttribute(name, value); } @@ -117,8 +118,8 @@ public boolean isMatchSubclasses() { static { - HANDLERS.add(new ThrowableHandler(AlreadyExistsException.class, - "AlreadyExistsException") { + HANDLERS.add(new ThrowableHandler( + AlreadyExistsException.class, "AlreadyExistsException") { @Override protected AlreadyExistsException createException(final String message) { @@ -126,8 +127,8 @@ protected AlreadyExistsException createException(final String message) { } }); - HANDLERS.add(new ThrowableHandler(ConfigurationException.class, - "ConfigurationException") { + HANDLERS.add(new ThrowableHandler( + ConfigurationException.class, "ConfigurationException") { @Override protected ConfigurationException createException(final String message) { @@ -153,8 +154,8 @@ protected ConnectionFailedException createException(final String message) { } }); - HANDLERS.add(new ThrowableHandler(ConnectorIOException.class, - "ConnectorIOException") { + HANDLERS.add(new ThrowableHandler( + ConnectorIOException.class, "ConnectorIOException") { @Override protected ConnectorIOException createException(final String message) { @@ -162,8 +163,8 @@ protected ConnectorIOException createException(final String message) { } }); - HANDLERS.add(new ThrowableHandler(PasswordExpiredException.class, - "PasswordExpiredException") { + HANDLERS.add(new ThrowableHandler( + PasswordExpiredException.class, "PasswordExpiredException") { @Override public Object deserialize(final ObjectDecoder decoder) { @@ -186,8 +187,8 @@ protected PasswordExpiredException createException(final String message) { } }); - HANDLERS.add(new ThrowableHandler(InvalidPasswordException.class, - "InvalidPasswordException") { + HANDLERS.add(new ThrowableHandler( + InvalidPasswordException.class, "InvalidPasswordException") { @Override protected InvalidPasswordException createException(final String message) { @@ -195,8 +196,7 @@ protected InvalidPasswordException createException(final String message) { } }); - HANDLERS.add(new ThrowableHandler(UnknownUidException.class, - "UnknownUidException") { + HANDLERS.add(new ThrowableHandler(UnknownUidException.class, "UnknownUidException") { @Override protected UnknownUidException createException(final String message) { @@ -267,8 +267,7 @@ protected PreconditionRequiredException createException(final String message) { } }); - HANDLERS.add(new ThrowableHandler(RetryableException.class, - "RetryableException") { + HANDLERS.add(new ThrowableHandler(RetryableException.class, "RetryableException") { @Override protected RetryableException createException(final String message) { @@ -276,21 +275,16 @@ protected RetryableException createException(final String message) { } }); - HANDLERS.add(new AbstractObjectSerializationHandler(RemoteWrappedException.class, - "RemoteWrappedException") { + HANDLERS.add(new AbstractObjectSerializationHandler(RemoteWrappedException.class, "RemoteWrappedException") { @Override public Object deserialize(final ObjectDecoder decoder) { - String throwableClass = - decoder.readStringField(RemoteWrappedException.FIELD_CLASS, - ConnectorException.class.getName()); - String message = - decoder.readStringField(RemoteWrappedException.FIELD_MESSAGE, null); - RemoteWrappedException cause = - (RemoteWrappedException) decoder.readObjectField("RemoteWrappedException", - RemoteWrappedException.class, null); - String stackTrace = - decoder.readStringField(RemoteWrappedException.FIELD_STACK_TRACE, null); + String throwableClass = decoder.readStringField( + RemoteWrappedException.FIELD_CLASS, ConnectorException.class.getName()); + String message = decoder.readStringField(RemoteWrappedException.FIELD_MESSAGE, null); + RemoteWrappedException cause = (RemoteWrappedException) decoder. + readObjectField("RemoteWrappedException", RemoteWrappedException.class, null); + String stackTrace = decoder.readStringField(RemoteWrappedException.FIELD_STACK_TRACE, null); return new RemoteWrappedException(throwableClass, message, cause, stackTrace); } @@ -298,17 +292,14 @@ public Object deserialize(final ObjectDecoder decoder) { @Override public void serialize(final Object object, final ObjectEncoder encoder) { final RemoteWrappedException val = (RemoteWrappedException) object; - encoder.writeStringField(RemoteWrappedException.FIELD_CLASS, val - .getExceptionClass()); + encoder.writeStringField(RemoteWrappedException.FIELD_CLASS, val.getExceptionClass()); encoder.writeStringField(RemoteWrappedException.FIELD_MESSAGE, val.getMessage()); encoder.writeObjectField("RemoteWrappedException", val.getCause(), true); - encoder.writeStringField(RemoteWrappedException.FIELD_STACK_TRACE, val - .readStackTrace()); + encoder.writeStringField(RemoteWrappedException.FIELD_STACK_TRACE, val.readStackTrace()); } }); - HANDLERS.add(new ThrowableHandler(ConnectorException.class, - "ConnectorException") { + HANDLERS.add(new ThrowableHandler(ConnectorException.class, "ConnectorException") { @Override protected ConnectorException createException(final String message) { @@ -316,8 +307,8 @@ protected ConnectorException createException(final String message) { } }); - HANDLERS.add(new ThrowableHandler(IllegalArgumentException.class, - "IllegalArgumentException") { + HANDLERS.add(new ThrowableHandler( + IllegalArgumentException.class, "IllegalArgumentException") { @Override protected IllegalArgumentException createException(final String message) { @@ -325,8 +316,7 @@ protected IllegalArgumentException createException(final String message) { } }); - HANDLERS.add(new ThrowableHandler(RuntimeException.class, - "RuntimeException") { + HANDLERS.add(new ThrowableHandler(RuntimeException.class, "RuntimeException") { @Override protected RuntimeException createException(final String message) { @@ -364,9 +354,8 @@ protected Attribute createAttribute(final String name, final List value) @Override public Object deserialize(final ObjectDecoder decoder) { - final AttributeInfoBuilder builder = - new AttributeInfoBuilder(decoder.readStringField("name", null), decoder - .readClassField("type", null)); + final AttributeInfoBuilder builder = new AttributeInfoBuilder( + decoder.readStringField("name", null), decoder.readClassField("type", null)); final Set flags = EnumSet.noneOf(Flags.class); final int count = decoder.getNumSubObjects(); for (int i = 0; i < count; i++) { @@ -388,8 +377,7 @@ public void serialize(final Object object, final ObjectEncoder encoder) { final AttributeInfo val = (AttributeInfo) object; encoder.writeStringField("name", val.getName()); encoder.writeClassField("type", val.getType()); - final Set flags = val.getFlags(); - for (Flags flag : flags) { + for (Flags flag : val.getFlags()) { encoder.writeObjectContents(flag); } encoder.writeStringField("nativeName", val.getNativeName()); @@ -399,17 +387,15 @@ public void serialize(final Object object, final ObjectEncoder encoder) { } }); - HANDLERS.add(new AbstractObjectSerializationHandler(ConnectorObject.class, - "ConnectorObject") { + HANDLERS.add(new AbstractObjectSerializationHandler(ConnectorObject.class, "ConnectorObject") { @Override public Object deserialize(ObjectDecoder decoder) { - final ObjectClass objectClass = - (ObjectClass) decoder.readObjectField("ObjectClass", ObjectClass.class, - null); + final ObjectClass objectClass = (ObjectClass) decoder. + readObjectField("ObjectClass", ObjectClass.class, null); @SuppressWarnings("unchecked") - Set atts = - (Set) decoder.readObjectField("Attributes", Set.class, null); + Set atts = (Set) decoder. + readObjectField("Attributes", Set.class, null); return new ConnectorObject(objectClass, atts); } @@ -421,8 +407,8 @@ public void serialize(final Object object, final ObjectEncoder encoder) { } }); - HANDLERS.add(new AbstractObjectSerializationHandler(ConnectorObjectIdentification.class, - "ConnectorObjectIdentification") { + HANDLERS.add(new AbstractObjectSerializationHandler( + ConnectorObjectIdentification.class, "ConnectorObjectIdentification") { @SuppressWarnings("unchecked") @Override @@ -486,8 +472,7 @@ public void serialize(final Object object, final ObjectEncoder encoder) { } }); - HANDLERS.add(new AbstractObjectSerializationHandler(ObjectClassInfo.class, - "ObjectClassInfo") { + HANDLERS.add(new AbstractObjectSerializationHandler(ObjectClassInfo.class, "ObjectClassInfo") { @Override public Object deserialize(final ObjectDecoder decoder) { @@ -497,8 +482,7 @@ public Object deserialize(final ObjectDecoder decoder) { final boolean embedded = decoder.readBooleanField("embedded", false); @SuppressWarnings("unchecked") - final Set attrInfo = - (Set) decoder.readObjectField("AttributeInfos", Set.class, null); + final Set attrInfo = (Set) decoder.readObjectField("AttributeInfos", Set.class, null); return new ObjectClassInfo(type, attrInfo, container, auxiliary, embedded); } @@ -521,57 +505,42 @@ public void serialize(final Object object, final ObjectEncoder encoder) { public Object deserialize(final ObjectDecoder decoder) { @SuppressWarnings("unchecked") final Set objectClasses = - (Set) decoder.readObjectField("ObjectClassInfos", Set.class, null); - final Map objectClassesByName = - new HashMap(); - for (ObjectClassInfo info : objectClasses) { - objectClassesByName.put(info.getType(), info); - } + (Set) decoder.readObjectField("ObjectClassInfos", Set.class, null); + final Map objectClassesByName = objectClasses.stream(). + collect(Collectors.toMap(ObjectClassInfo::getType, Function.identity())); + @SuppressWarnings("unchecked") final Set operationOptions = - (Set) decoder.readObjectField("OperationOptionInfos", Set.class, null); - final Map optionsByName = - new HashMap(); - for (OperationOptionInfo info : operationOptions) { - optionsByName.put(info.getName(), info); - } + (Set) decoder.readObjectField("OperationOptionInfos", Set.class, null); + final Map optionsByName = operationOptions.stream(). + collect(Collectors.toMap(OperationOptionInfo::getName, Function.identity())); + @SuppressWarnings("unchecked") final Map, Set> objectClassNamesByOperation = - (Map) decoder.readObjectField("objectClassesByOperation", null, null); + (Map, Set>) decoder. + readObjectField("objectClassesByOperation", null, null); @SuppressWarnings("unchecked") final Map, Set> optionsNamesByOperation = - (Map) decoder.readObjectField("optionsByOperation", null, null); + (Map, Set>) decoder. + readObjectField("optionsByOperation", null, null); final Map, Set> objectClassesByOperation = - new HashMap, Set>(); - for (Map.Entry, Set> entry : objectClassNamesByOperation - .entrySet()) { - final Set names = entry.getValue(); - final Set infos = new HashSet(); - for (String name : names) { - final ObjectClassInfo objectClass = objectClassesByName.get(name); - if (objectClass != null) { - infos.add(objectClass); - } - } + new HashMap<>(); + for (var entry : objectClassNamesByOperation.entrySet()) { + Set infos = entry.getValue().stream(). + map(objectClassesByName::get).filter(Objects::nonNull). + collect(Collectors.toSet()); objectClassesByOperation.put(entry.getKey(), infos); } final Map, Set> optionsByOperation = - new HashMap, Set>(); - for (Map.Entry, Set> entry : optionsNamesByOperation - .entrySet()) { - final Set names = entry.getValue(); - final Set infos = new HashSet(); - for (String name : names) { - final OperationOptionInfo info = optionsByName.get(name); - if (info != null) { - infos.add(info); - } - } + new HashMap<>(); + for (var entry : optionsNamesByOperation.entrySet()) { + Set infos = entry.getValue().stream(). + map(optionsByName::get).filter(Objects::nonNull). + collect(Collectors.toSet()); optionsByOperation.put(entry.getKey(), infos); } - return new Schema(objectClasses, operationOptions, objectClassesByOperation, - optionsByOperation); + return new Schema(objectClasses, operationOptions, objectClassesByOperation, optionsByOperation); } @Override @@ -580,34 +549,22 @@ public void serialize(final Object object, final ObjectEncoder encoder) { encoder.writeObjectField("ObjectClassInfos", val.getObjectClassInfo(), true); encoder.writeObjectField("OperationOptionInfos", val.getOperationOptionInfo(), true); - final Map, Set> objectClassNamesByOperation = - new HashMap, Set>(); + final Map, Set> objectClassNamesByOperation = new HashMap<>(); - final Map, Set> optionNamesByOperation = - new HashMap, Set>(); + final Map, Set> optionNamesByOperation = new HashMap<>(); - for (Map.Entry, Set> entry : val - .getSupportedObjectClassesByOperation().entrySet()) { - final Set value = entry.getValue(); - final Set names = new HashSet(); - for (ObjectClassInfo info : value) { - names.add(info.getType()); - } + for (var entry : val.getSupportedObjectClassesByOperation().entrySet()) { + Set names = entry.getValue().stream(). + map(ObjectClassInfo::getType).collect(Collectors.toSet()); objectClassNamesByOperation.put(entry.getKey(), names); } - for (Map.Entry, Set> entry : val - .getSupportedOptionsByOperation().entrySet()) { - - final Set value = entry.getValue(); - final Set names = new HashSet(); - for (OperationOptionInfo info : value) { - names.add(info.getName()); - } + for (var entry : val.getSupportedOptionsByOperation().entrySet()) { + Set names = entry.getValue().stream(). + map(OperationOptionInfo::getName).collect(Collectors.toSet()); optionNamesByOperation.put(entry.getKey(), names); } - encoder.writeObjectField("objectClassesByOperation", objectClassNamesByOperation, - false); + encoder.writeObjectField("objectClassesByOperation", objectClassNamesByOperation, false); encoder.writeObjectField("optionsByOperation", optionNamesByOperation, false); } }); @@ -620,11 +577,9 @@ public Object deserialize(final ObjectDecoder decoder) { final String revision = decoder.readStringField("revision", null); final Name nameHint = (Name) decoder.readObjectField("nameHint", Name.class, null); // revision parameter is not-null checked, nameHint is nullable - if (revision == null) { - return new Uid(val, nameHint); - } else { - return new Uid(val, revision, nameHint); - } + return revision == null + ? new Uid(val, nameHint) + : new Uid(val, revision, nameHint); } @Override @@ -662,12 +617,10 @@ public void serialize(final Object object, final ObjectEncoder encoder) { public Object deserialize(final ObjectDecoder decoder) { final String scriptLanguage = decoder.readStringField("scriptLanguage", null); @SuppressWarnings("unchecked") - final Map arguments = - (Map) decoder - .readObjectField("scriptArguments", null, null); + final Map arguments = (Map) decoder. + readObjectField("scriptArguments", null, null); // don't used string field - don't want it to be an attribute - final String scriptText = - (String) decoder.readObjectField("scriptText", String.class, null); + final String scriptText = (String) decoder.readObjectField("scriptText", String.class, null); return new ScriptContext(scriptLanguage, scriptText, arguments); } @@ -680,15 +633,13 @@ public void serialize(final Object object, final ObjectEncoder encoder) { } }); - HANDLERS.add( - - new AbstractObjectSerializationHandler(OperationOptions.class, "OperationOptions") { + HANDLERS.add(new AbstractObjectSerializationHandler(OperationOptions.class, "OperationOptions") { @Override public Object deserialize(final ObjectDecoder decoder) { @SuppressWarnings("unchecked") - final Map options = - (Map) decoder.readObjectField("options", null, null); + final Map options = (Map) decoder. + readObjectField("options", null, null); return new OperationOptions(options); } @@ -699,9 +650,7 @@ public void serialize(final Object object, final ObjectEncoder encoder) { } }); - HANDLERS.add( - - new AbstractObjectSerializationHandler(SearchResult.class, "SearchResult") { + HANDLERS.add(new AbstractObjectSerializationHandler(SearchResult.class, "SearchResult") { @Override public Object deserialize(final ObjectDecoder decoder) { @@ -717,14 +666,12 @@ public void serialize(final Object object, final ObjectEncoder encoder) { } }); - HANDLERS.add( - - new AbstractObjectSerializationHandler(SortKey.class, "SortKey") { + HANDLERS.add(new AbstractObjectSerializationHandler(SortKey.class, "SortKey") { @Override public Object deserialize(final ObjectDecoder decoder) { - return new SortKey(decoder.readStringField("field", null), decoder - .readBooleanField("isAscending", true)); + return new SortKey( + decoder.readStringField("field", null), decoder.readBooleanField("isAscending", true)); } @Override @@ -735,9 +682,7 @@ public void serialize(final Object object, final ObjectEncoder encoder) { } }); - - HANDLERS.add(new AbstractObjectSerializationHandler(OperationOptionInfo.class, - "OperationOptionInfo") { + HANDLERS.add(new AbstractObjectSerializationHandler(OperationOptionInfo.class, "OperationOptionInfo") { @Override public Object deserialize(final ObjectDecoder decoder) { @@ -775,18 +720,17 @@ public void serialize(final Object object, final ObjectEncoder encoder) { @Override public Object deserialize(final ObjectDecoder decoder) { - final SyncDeltaBuilder builder = new SyncDeltaBuilder(); - builder.setDeltaType((SyncDeltaType) decoder.readObjectField("SyncDeltaType", - SyncDeltaType.class, null)); - builder.setToken((SyncToken) decoder.readObjectField("SyncToken", SyncToken.class, - null)); - builder.setPreviousUid((Uid) decoder - .readObjectField("PreviousUid", Uid.class, null)); - builder.setObjectClass((ObjectClass) decoder.readObjectField("ObjectClass", ObjectClass.class, null)); - builder.setUid((Uid) decoder.readObjectField("Uid", Uid.class, null)); - builder.setObject((ConnectorObject) decoder.readObjectField("ConnectorObject", - ConnectorObject.class, null)); - return builder.build(); + return new SyncDeltaBuilder(). + setDeltaType((SyncDeltaType) decoder. + readObjectField("SyncDeltaType", SyncDeltaType.class, null)). + setToken((SyncToken) decoder.readObjectField("SyncToken", SyncToken.class, null)). + setPreviousUid((Uid) decoder. + readObjectField("PreviousUid", Uid.class, null)). + setObjectClass((ObjectClass) decoder.readObjectField("ObjectClass", ObjectClass.class, null)). + setUid((Uid) decoder.readObjectField("Uid", Uid.class, null)). + setObject((ConnectorObject) decoder. + readObjectField("ConnectorObject", ConnectorObject.class, null)). + build(); } @Override @@ -806,15 +750,16 @@ public void serialize(final Object object, final ObjectEncoder encoder) { @Override public Object deserialize(final ObjectDecoder decoder) { final AttributeDeltaBuilder builder = new AttributeDeltaBuilder(); - builder.setName((String) decoder.readObjectField("Name", - String.class, null)); + builder.setName((String) decoder.readObjectField("Name", String.class, null)); - List addList = (List) decoder.readObjectField("ValuesToAdd", List.class, null); - List removeList = (List) decoder.readObjectField("ValuesToRemove", List.class, null); - List replaceList =(List) decoder.readObjectField("ValuesToReplace", List.class, null); + @SuppressWarnings("unchecked") + List addList = (List) decoder.readObjectField("ValuesToAdd", List.class, null); + @SuppressWarnings("unchecked") + List removeList = (List) decoder.readObjectField("ValuesToRemove", List.class, null); + @SuppressWarnings("unchecked") + List replaceList = (List) decoder.readObjectField("ValuesToReplace", List.class, null); if ((addList != null || removeList != null)) { - builder.addValueToAdd(addList); builder.addValueToRemove(removeList); } else { @@ -838,9 +783,8 @@ public void serialize(final Object object, final ObjectEncoder encoder) { @Override public Object deserialize(final ObjectDecoder decoder) { - final ObjectClass objectClass = - (ObjectClass) decoder.readObjectField("ObjectClass", ObjectClass.class, - null); + final ObjectClass objectClass = (ObjectClass) decoder. + readObjectField("ObjectClass", ObjectClass.class, null); final Uid uid = (Uid) decoder.readObjectField("Uid", Uid.class, null); return new QualifiedUid(objectClass, uid); } @@ -859,13 +803,14 @@ public void serialize(final Object object, final ObjectEncoder encoder) { public Object deserialize(final ObjectDecoder decoder) { final SuggestedValuesBuilder builder = new SuggestedValuesBuilder(); - List values = (List) decoder.readObjectField("Values", List.class, null); + @SuppressWarnings("unchecked") + List values = (List) decoder.readObjectField("Values", List.class, null); if (values != null) { builder.addValues(values); } - builder.setOpenness((ValueListOpenness) decoder.readObjectField("ValueListOpenness", - ValueListOpenness.class, ValueListOpenness.CLOSED)); + builder.setOpenness((ValueListOpenness) decoder. + readObjectField("ValueListOpenness", ValueListOpenness.class, ValueListOpenness.CLOSED)); return builder.build(); } diff --git a/java/connector-framework-internal/src/test/java/org/identityconnectors/framework/impl/api/ConnectorInfoManagerTestBase.java b/java/connector-framework-internal/src/test/java/org/identityconnectors/framework/impl/api/ConnectorInfoManagerTestBase.java index ebe788f3..76340560 100644 --- a/java/connector-framework-internal/src/test/java/org/identityconnectors/framework/impl/api/ConnectorInfoManagerTestBase.java +++ b/java/connector-framework-internal/src/test/java/org/identityconnectors/framework/impl/api/ConnectorInfoManagerTestBase.java @@ -23,6 +23,13 @@ */ package org.identityconnectors.framework.impl.api; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.net.URISyntaxException; import java.net.URL; @@ -33,7 +40,6 @@ import java.util.ResourceBundle; import java.util.Set; import org.identityconnectors.common.CollectionUtil; -import org.identityconnectors.common.IOUtil; import org.identityconnectors.common.Version; import org.identityconnectors.common.l10n.CurrentLocale; import org.identityconnectors.common.security.GuardedString; @@ -75,8 +81,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; -import static org.junit.jupiter.api.Assertions.*; - public abstract class ConnectorInfoManagerTestBase { private static ConnectorInfo findConnectorInfo(ConnectorInfoManager manager, String version, String connectorName) { @@ -670,7 +674,8 @@ final File getTestBundlesDir() throws URISyntaxException { return testBundlesDir; } - // Originally, this method used getTestBundlesDir. We stopped doing that in order to allow tests to be run directly from IDE. + // Originally, this method used getTestBundlesDir. + // We stopped doing that in order to allow tests to be run directly from IDE. List getTestBundles() { List rv = new ArrayList<>(); rv.add(getTestBundleUrl("testbundlev1.jar")); diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/AttributeInfo.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/AttributeInfo.java index b52dec28..988c0ef7 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/AttributeInfo.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/AttributeInfo.java @@ -53,11 +53,17 @@ public final class AttributeInfo { private final String name; + private final Class type; + private final String subtype; + private final String nativeName; + private final Set flags; + private final String referencedObjectClassName; + private final String roleInReference; /** @@ -74,53 +80,59 @@ public final class AttributeInfo { * */ public static enum Flags { - REQUIRED, MULTIVALUED, NOT_CREATABLE, NOT_UPDATEABLE, NOT_READABLE, NOT_RETURNED_BY_DEFAULT + REQUIRED, + MULTIVALUED, + NOT_CREATABLE, + NOT_UPDATEABLE, + NOT_READABLE, + NOT_RETURNED_BY_DEFAULT + } /** * Enumeration of pre-defined attribute subtypes. */ public static enum Subtypes { - /** - * Case-ignore (case-insensitive) string. - */ - STRING_CASE_IGNORE(AttributeUtil.createSpecialName("STRING_CASE_IGNORE")), - - /** - * Unique Resource Identifier (RFC 3986) - */ - STRING_URI(AttributeUtil.createSpecialName("STRING_URI")), - - /** - * LDAP Distinguished Name (RFC 4511) - */ - STRING_LDAP_DN(AttributeUtil.createSpecialName("STRING_LDAP_DN")), - - /** - * Universally unique identifier (UUID) - */ - STRING_UUID(AttributeUtil.createSpecialName("STRING_UUID")), - - /** - * XML-formatted string (https://www.w3.org/TR/REC-xml/) - */ - STRING_XML(AttributeUtil.createSpecialName("STRING_XML")), - - /** - * JSON-formatted string - */ - STRING_JSON(AttributeUtil.createSpecialName("STRING_JSON")); - - private final String value; - - private Subtypes(String value) { - this.value = value; - } - - @Override - public String toString() { - return value; - } + /** + * Case-ignore (case-insensitive) string. + */ + STRING_CASE_IGNORE(AttributeUtil.createSpecialName("STRING_CASE_IGNORE")), + + /** + * Unique Resource Identifier (RFC 3986) + */ + STRING_URI(AttributeUtil.createSpecialName("STRING_URI")), + + /** + * LDAP Distinguished Name (RFC 4511) + */ + STRING_LDAP_DN(AttributeUtil.createSpecialName("STRING_LDAP_DN")), + + /** + * Universally unique identifier (UUID) + */ + STRING_UUID(AttributeUtil.createSpecialName("STRING_UUID")), + + /** + * XML-formatted string (https://www.w3.org/TR/REC-xml/) + */ + STRING_XML(AttributeUtil.createSpecialName("STRING_XML")), + + /** + * JSON-formatted string + */ + STRING_JSON(AttributeUtil.createSpecialName("STRING_JSON")); + + private final String value; + + private Subtypes(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } } /** @@ -159,17 +171,15 @@ public String toString() { return value; } } - - AttributeInfo(final String name, final Class type, final Set flags) { - this(name, type, null, null, flags); - } - AttributeInfo(final String name, final Class type, final String subtype, final String nativeName, final Set flags) { + AttributeInfo(final String name, final Class type, final String subtype, final String nativeName, + final Set flags) { this(name, type, subtype, nativeName, flags, null, null); } - AttributeInfo(final String name, final Class type, final String subtype, final String nativeName, final Set flags, - String referencedObjectClassName, String roleInReference) { + AttributeInfo(final String name, final Class type, final String subtype, final String nativeName, + final Set flags, + String referencedObjectClassName, String roleInReference) { if (StringUtil.isBlank(name)) { throw new IllegalStateException("Name must not be blank!"); } @@ -190,10 +200,12 @@ public String toString() { if (!isReadable() && isReturnedByDefault()) { throw new IllegalArgumentException( "Attribute " - + name - + " is flagged as not-readable, so it should also be as not-returned-by-default."); + + name + + " is flagged as not-readable, so it should also be as not-returned-by-default."); } - if ((referencedObjectClassName != null || roleInReference != null) && !ConnectorObjectReference.class.equals(type)) { + if ((referencedObjectClassName != null || roleInReference != null) + && !ConnectorObjectReference.class.equals(type)) { + throw new IllegalArgumentException( "Referenced object class name and/or role in reference can be set only for reference attributes."); } @@ -221,14 +233,14 @@ public String getName() { public Class getType() { return type; } - + /** * Optional subtype of the attribute. This defines a subformat or provides * more specific definition what the attribute contains. E.g. it may define * that the attribute contains case-insensitive string, URL, LDAP distinguished * name and so on. - * - * The subtype may contain one of the pre-defined subtypes + * + * The subtype may contain one of the pre-defined subtypes * (a value form the Subtype enumeration). The subtype may also contain an URI * that specifies a custom subtype that the connector recognizes and it is not * defined in the pre-defined subtype enumeration. @@ -244,10 +256,10 @@ public Class getType() { * @return attribute subtype. */ public String getSubtype() { - return subtype; - } + return subtype; + } - /** + /** * The native name of the attribute. This is the attribute name as it is * known by the resource. It is especially useful for attributes with * special names such as __NAME__ or __PASSWORD__. In this case the @@ -258,10 +270,10 @@ public String getSubtype() { * @return the native name of the attribute its describing. */ public String getNativeName() { - return nativeName; - } + return nativeName; + } - /** + /** * Returns the set of flags associated with the attribute. * * @return the set of flags associated with the attribute @@ -335,16 +347,17 @@ public boolean isReturnedByDefault() { /** * For reference attributes, this method returns the object class of referenced objects. * - * It is optional: the connector may not have this information, or sometimes, there may be more than a single object class - * that can be referenced by the attribute. (For example, {@code member} attribute on the {@code group} object can reference - * accounts, groups, and other kinds of objects.) + * It is optional: the connector may not have this information, or sometimes, there may be more than a single object + * class that can be referenced by the attribute. (For example, {@code member} attribute on the + * {@code group} object can reference accounts, groups, and other kinds of objects.) */ public String getReferencedObjectClassName() { return referencedObjectClassName; } /** - * For reference attributes, this method provides an indication of the role the holding object plays in the reference. + * For reference attributes, this method provides an indication of the role the holding object plays in the + * reference. * The standard roles are described in {@link RoleInReference} enumeration. * * May be null if not known or not supported. @@ -367,7 +380,6 @@ public boolean is(String name) { // ======================================================================= // Object Overrides // ======================================================================= - @Override public boolean equals(Object obj) { boolean ret = false; @@ -385,10 +397,7 @@ public boolean equals(Object obj) { if (!Objects.equals(referencedObjectClassName, other.referencedObjectClassName)) { return false; } - if (!Objects.equals(roleInReference, other.roleInReference)) { - return false; - } - return true; + return Objects.equals(roleInReference, other.roleInReference); } return ret; } @@ -402,5 +411,4 @@ public int hashCode() { public String toString() { return SerializerUtil.serializeXmlObject(this, false); } - } diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/AttributeInfoBuilder.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/AttributeInfoBuilder.java index d85d0c76..7bd8ed3e 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/AttributeInfoBuilder.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/AttributeInfoBuilder.java @@ -47,12 +47,17 @@ public final class AttributeInfoBuilder { private String name; + private Class type; + private String subtype; + private String nativeName; + private final EnumSet flags; private String referencedObjectClassName; + private String roleInReference; /** @@ -128,8 +133,7 @@ public AttributeInfo build() { /** * Sets the unique name of the {@link AttributeInfo} object. * - * @param name - * unique name of the {@link AttributeInfo} object. + * @param name unique name of the {@link AttributeInfo} object. */ public AttributeInfoBuilder setName(final String name) { if (StringUtil.isBlank(name)) { @@ -143,48 +147,44 @@ public AttributeInfoBuilder setName(final String name) { * Please see {@link FrameworkUtil#checkAttributeType(Class)} for the * definitive list of supported types. * - * @param value - * type for an {@link Attribute}'s value. - * @throws IllegalArgumentException - * if the Class is not a supported type. + * @param value type for an {@link Attribute}'s value. + * @throws IllegalArgumentException if the Class is not a supported type. */ public AttributeInfoBuilder setType(final Class value) { FrameworkUtil.checkAttributeType(value); type = value; return this; } - + /** * Optional subtype of the attribute. This defines a subformat or provides * more specific definition what the attribute contains. E.g. it may define * that the attribute contains case-insensitive string, URL, LDAP distinguished * name and so on. - * - * The subtype may contain one of the pre-defined subtypes + * + * The subtype may contain one of the pre-defined subtypes * (a value form the Subtype enumeration). The subtype may also contain an URI * that specifies a custom subtype that the connector recognizes and it is not * defined in the pre-defined subtype enumeration. - * + * * See {@link AttributeInfo#Subtypes} for the list of pre-defined subtypes. - * - * @param subtype - * subtype for an {@link Attribute}'s value. + * + * @param subtype subtype for an {@link Attribute}'s value. */ public AttributeInfoBuilder setSubtype(String subtype) { - this.subtype = subtype; - return this; - } - + this.subtype = subtype; + return this; + } + public AttributeInfoBuilder setSubtype(AttributeInfo.Subtypes subtype) { - this.subtype = subtype.toString(); - return this; - } + this.subtype = subtype.toString(); + return this; + } - /** + /** * Sets the native name of the {@link AttributeInfo} object. * - * @param nativeName - * native name of the {@link AttributeInfo} object. + * @param nativeName native name of the {@link AttributeInfo} object. */ public AttributeInfoBuilder setNativeName(final String nativeName) { this.nativeName = nativeName; @@ -240,18 +240,18 @@ public AttributeInfoBuilder setReturnedByDefault(final boolean value) { * Sets all of the flags for this builder. * * @param flags - * The set of attribute info flags. Null means clear all flags. - *

- * NOTE: EnumSet.noneOf(AttributeInfo.Flags.class) results in an - * attribute with the default behavior: - *

    - *
  • updateable
  • - *
  • creatable
  • - *
  • returned by default
  • - *
  • readable
  • - *
  • single-valued
  • - *
  • optional
  • - *
+ * The set of attribute info flags. Null means clear all flags. + *

+ * NOTE: EnumSet.noneOf(AttributeInfo.Flags.class) results in an + * attribute with the default behavior: + *

    + *
  • updateable
  • + *
  • creatable
  • + *
  • returned by default
  • + *
  • readable
  • + *
  • single-valued
  • + *
  • optional
  • + *
*/ public AttributeInfoBuilder setFlags(Set flags) { this.flags.clear(); @@ -284,12 +284,9 @@ public AttributeInfoBuilder setRoleInReference(String value) { * new AttributeInfoBuilder(name,type).setFlags(flags).build() * * - * @param name - * The name of the attribute - * @param type - * The type of the attribute - * @param flags - * The flags for the attribute. Null means clear all flags + * @param name The name of the attribute + * @param type The type of the attribute + * @param flags The flags for the attribute. Null means clear all flags * @return The attribute info */ public static AttributeInfo build(String name, Class type, Set flags) { @@ -301,10 +298,8 @@ public static AttributeInfo build(String name, Class type, Set flags) * AttributeInfoBuilder.build(name,type,null) * * - * @param name - * The name of the attribute - * @param type - * The type of the attribute + * @param name The name of the attribute + * @param type The type of the attribute * @return The attribute info */ public static AttributeInfo build(String name, Class type) { @@ -316,8 +311,7 @@ public static AttributeInfo build(String name, Class type) { * AttributeInfoBuilder.build(name, String.class) * * - * @param name - * The name of the attribute + * @param name The name of the attribute * @return The attribute info */ public static AttributeInfo build(String name) { @@ -329,8 +323,7 @@ public static AttributeInfo build(String name) { * * Equivalent to: new AttributeInfoBuilder(name, String.class) * - * @param name - * The name of the attribute + * @param name The name of the attribute * @return The attribute info builder with predefined name and type value. * @since 1.4 */ @@ -343,10 +336,8 @@ public static AttributeInfoBuilder define(String name) { * * Equivalent to: new AttributeInfoBuilder(name, type) * - * @param name - * The name of the attribute - * @param type - * The type of the attribute + * @param name The name of the attribute + * @param type The type of the attribute * @return The attribute info builder with predefined name and type value. * @since 1.4 */ diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/BaseConnectorObject.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/BaseConnectorObject.java index 16ac3a9d..9e9e7cd4 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/BaseConnectorObject.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/BaseConnectorObject.java @@ -34,14 +34,15 @@ public abstract class BaseConnectorObject { private final ObjectClass objectClass; - final Map attributeMap; + + protected final Map attributeMap; BaseConnectorObject(ObjectClass objectClass, Set attributes) { // For connector object identification, it is legal to have no object class information. if (ObjectClass.ALL.equals(objectClass)) { throw new IllegalArgumentException("Connector object class can not be type of __ALL__"); } - if (attributes == null || attributes.isEmpty()) { + if (CollectionUtil.isEmpty(attributes)) { throw new IllegalArgumentException("The set can not be null or empty."); } this.objectClass = objectClass; @@ -77,7 +78,8 @@ public ObjectClass getObjectClass() { } /** - * Returns the identification of this object. For full objects it means providing {@link Name} and {@link Uid} attributes. + * Returns the identification of this object. For full objects it means providing {@link Name} and {@link Uid} + * attributes. * (We have no other way of telling what attributes are the identifiers.) */ public abstract ConnectorObjectIdentification getIdentification(); diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObject.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObject.java index ddc2530f..0bc82a79 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObject.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObject.java @@ -41,8 +41,7 @@ public final class ConnectorObject extends BaseConnectorObject { /** * Public only for serialization; please use {@link ConnectorObjectBuilder}. * - * @throws IllegalArgumentException - * if {@link Name} or {@link Uid} is missing from the set. + * @throws IllegalArgumentException if {@link Name} or {@link Uid} is missing from the set. */ public ConnectorObject(ObjectClass objectClass, Set attributes) { super(objectClass, attributes); diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectBuilder.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectBuilder.java index 2cfb4b38..552a5d15 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectBuilder.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectBuilder.java @@ -42,13 +42,14 @@ public final class ConnectorObjectBuilder { private ObjectClass objectClass; + private Map attributeMap; // ======================================================================= // Constructors // ======================================================================= public ConnectorObjectBuilder() { - attributeMap = new HashMap(); + attributeMap = new HashMap<>(); // default always add the account object class.. setObjectClass(ObjectClass.ACCOUNT); } @@ -146,17 +147,16 @@ public ConnectorObjectBuilder addAttribute(String name, Collection obj) { addAttribute(AttributeBuilder.build(name, obj)); return this; } - + // ======================================================================= // Build Out.. // ======================================================================= - /** * Builds a 'ConnectorObject' based on the attributes and Uid provided. */ public ConnectorObject build() { // check that there are attributes to return.. - if (attributeMap.size() == 0) { + if (attributeMap.isEmpty()) { throw new IllegalStateException("No attributes set!"); } Set attrs = CollectionUtil.newReadOnlySet(attributeMap.values()); @@ -164,7 +164,6 @@ public ConnectorObject build() { } public ConnectorObjectIdentification buildIdentification() { - return new ConnectorObjectIdentification( - objectClass, CollectionUtil.newReadOnlySet(attributeMap.values())); + return new ConnectorObjectIdentification(objectClass, CollectionUtil.newReadOnlySet(attributeMap.values())); } } diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectIdentification.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectIdentification.java index 1fc0b978..7665cdc2 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectIdentification.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectIdentification.java @@ -28,7 +28,7 @@ * Represents an identification of a object (e.g., an Account or a Group) on the target resource. * Contains one or more attributes that should identify the object. (E.g. {@link Name} but not necessarily that one.) * - * The developer of a Connector will use a {@link ConnectorObjectBuilder} to + * The developer of a Connector will use a {@link ConnectorObjectBuilder} to * construct instances of ConnectorObjectIdentification. * * Similar to {@link ConnectorObject} but with no requirements about object class information @@ -39,7 +39,7 @@ public final class ConnectorObjectIdentification extends BaseConnectorObject { /** * Public only for serialization; please use {@link ConnectorObjectBuilder}. */ - public ConnectorObjectIdentification(ObjectClass objectClass, Set attributes) { + public ConnectorObjectIdentification(final ObjectClass objectClass, final Set attributes) { super(objectClass, attributes); } diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectReference.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectReference.java index 6ee9dfc5..6c85bb28 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectReference.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ConnectorObjectReference.java @@ -27,15 +27,16 @@ /** * Reference to a connector object. * - * It may contain the identifier/identifiers only (e.g. {@link Uid}, {@link Name}, or other attributes), or it may contain - * the whole object, fetched partially or fully. + * It may contain the identifier/identifiers only (e.g. {@link Uid}, {@link Name}, or other attributes), or it may + * contain the whole object, fetched partially or fully. * * Typical use case: * - * A user in Active Directory has a multivalued reference attribute {@code group} that points to groups the user is a member of. - * The attribute is similar to {@code memberOf} attribute, but instead of holding string DNs of the groups, it holds these - * references as {@link ConnectorObjectReference}s (which may contain DNs, UUIDs, or even partially or fully fetched group - * objects, depending on the situation). + * A user in Active Directory has a multivalued reference attribute {@code group} that points to groups the user is a + * member of. + * The attribute is similar to {@code memberOf} attribute, but instead of holding string DNs of the groups, it holds + * these references as {@link ConnectorObjectReference}s (which may contain DNs, UUIDs, or even partially or fully + * fetched group objects, depending on the situation). * * Other use cases: * @@ -48,23 +49,29 @@ */ public class ConnectorObjectReference { - /** The referenced object or its identification. */ + /** + * The referenced object or its identification. + */ private final BaseConnectorObject value; - public ConnectorObjectReference(BaseConnectorObject value) { - if (!(value instanceof ConnectorObject) - && !(value instanceof ConnectorObjectIdentification)) { - throw new IllegalArgumentException("Referenced object must be either ConnectorObject or ConnectorObjectIdentification"); + public ConnectorObjectReference(final BaseConnectorObject value) { + if (!(value instanceof ConnectorObject) && !(value instanceof ConnectorObjectIdentification)) { + throw new IllegalArgumentException( + "Referenced object must be either ConnectorObject or ConnectorObjectIdentification"); } this.value = value; } - /** True if the object is present. False if only the identifiers are. */ + /** + * True if the object is present. False if only the identifiers are. + */ public boolean hasObject() { return value instanceof ConnectorObject; } - /** Returns the value of the reference (the referenced object or its identification). */ + /** + * Returns the value of the reference (the referenced object or its identification) + */ public BaseConnectorObject getValue() { return Objects.requireNonNull(value); } diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ObjectClassInfo.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ObjectClassInfo.java index 995fd504..3d624902 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ObjectClassInfo.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ObjectClassInfo.java @@ -42,26 +42,32 @@ public final class ObjectClassInfo { private final String type; + private final Set attributeInfos; + private final boolean isContainer; + private final boolean isAuxiliary; + private final boolean isEmbedded; /** * Public only for serialization; Use ObjectClassInfoBuilder instead. * - * @param type - * The name of the object class - * @param attrInfo - * The attributes of the object class. - * @param isContainer - * True if this can contain other object classes. + * @param type The name of the object class + * @param attrInfo The attributes of the object class. + * @param isContainer True if this can contain other object classes. */ public ObjectClassInfo( - String type, Set attrInfo, boolean isContainer, boolean isAuxiliary, boolean isEmbedded) { + final String type, + final Set attrInfo, + final boolean isContainer, + final boolean isAuxiliary, + final boolean isEmbedded) { + Assertions.nullCheck(type, "type"); this.type = type; - attributeInfos = CollectionUtil.newReadOnlySet(attrInfo); + this.attributeInfos = CollectionUtil.newReadOnlySet(attrInfo); this.isContainer = isContainer; this.isAuxiliary = isAuxiliary; this.isEmbedded = isEmbedded; @@ -81,8 +87,8 @@ public boolean isContainer() { * Auxiliary object classes define additional characteristics of the object. */ public boolean isAuxiliary() { - return isAuxiliary; - } + return isAuxiliary; + } /** * If {@code true}, objects of this class are meant to be embedded in other objects. @@ -96,7 +102,7 @@ public boolean isEmbedded() { return isEmbedded; } - public Set getAttributeInfo() { + public Set getAttributeInfo() { return CollectionUtil.newReadOnlySet(attributeInfos); } @@ -107,18 +113,16 @@ public String getType() { /** * Determines if the 'name' matches this {@link ObjectClassInfo}. * - * @param name - * case-insensitive string representation of the - * ObjectClassInfo's type. - * @return true if the case insensitive type is equal to that - * of the one in this {@link ObjectClassInfo}. + * @param name case-insensitive string representation of the ObjectClassInfo's type. + * @return true if the case insensitive type is equal to that of the one in this + * {@link ObjectClassInfo}. */ - public boolean is(String name) { + public boolean is(final String name) { return namesEqual(type, name); } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { // test identity if (this == obj) { return true; @@ -146,10 +150,7 @@ public boolean equals(Object obj) { if (!isAuxiliary == other.isAuxiliary) { return false; } - if (!isEmbedded == other.isEmbedded) { - return false; - } - return true; + return !isEmbedded != other.isEmbedded; } @Override diff --git a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ObjectClassInfoBuilder.java b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ObjectClassInfoBuilder.java index ab8c0cd6..d76eb108 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ObjectClassInfoBuilder.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/framework/common/objects/ObjectClassInfoBuilder.java @@ -35,14 +35,18 @@ public final class ObjectClassInfoBuilder { private boolean isContainer; + private boolean isAuxiliary; + private boolean isEmbedded; + private String type; - private Map attributeInfoMap; + + private final Map attributeInfoMap; public ObjectClassInfoBuilder() { type = ObjectClass.ACCOUNT_NAME; - attributeInfoMap = new HashMap(); + attributeInfoMap = new HashMap<>(); } /** @@ -57,7 +61,7 @@ public ObjectClassInfoBuilder() { * @see ObjectClassInfo#getType() * @see ObjectClass#ACCOUNT_NAME */ - public ObjectClassInfoBuilder setType(String type) { + public ObjectClassInfoBuilder setType(final String type) { this.type = type; return this; } @@ -68,10 +72,9 @@ public ObjectClassInfoBuilder setType(String type) { * Add the specified {@link AttributeInfo} object to the * {@link ObjectClassInfo} that is being built. */ - public ObjectClassInfoBuilder addAttributeInfo(AttributeInfo info) { + public ObjectClassInfoBuilder addAttributeInfo(final AttributeInfo info) { if (attributeInfoMap.containsKey(info.getName())) { - throw new IllegalArgumentException(String.format( - FORMAT, info.getName())); + throw new IllegalArgumentException(String.format(FORMAT, info.getName())); } attributeInfoMap.put(info.getName(), info); return this; @@ -81,7 +84,7 @@ public ObjectClassInfoBuilder addAttributeInfo(AttributeInfo info) { * Add to the {@link ObjectClassInfo} that is being built each * {@link AttributeInfo} in the specified collection. */ - public ObjectClassInfoBuilder addAllAttributeInfo(Collection c) { + public ObjectClassInfoBuilder addAllAttributeInfo(final Collection c) { for (AttributeInfo info : c) { addAttributeInfo(info); } @@ -91,18 +94,17 @@ public ObjectClassInfoBuilder addAllAttributeInfo(Collection c) { /** * Set to true to indicate this is a container type. * - * @param container - * True if this is a container type. + * @param container True if this is a container type. */ - public void setContainer(boolean container) { + public void setContainer(final boolean container) { isContainer = container; } - - public void setAuxiliary(boolean isAuxiliary) { - this.isAuxiliary = isAuxiliary; - } - public ObjectClassInfoBuilder setEmbedded(boolean embedded) { + public void setAuxiliary(final boolean isAuxiliary) { + this.isAuxiliary = isAuxiliary; + } + + public ObjectClassInfoBuilder setEmbedded(final boolean embedded) { isEmbedded = embedded; return this; } @@ -112,7 +114,7 @@ public ObjectClassInfoBuilder setEmbedded(boolean embedded) { * characteristics that were previously specified using this builder. * * @return an instance of {@link ObjectClassInfo} with the characteristics - * previously specified. + * previously specified. */ public ObjectClassInfo build() { // determine if name is missing and add it by default @@ -120,7 +122,10 @@ public ObjectClassInfo build() { attributeInfoMap.put(Name.NAME, Name.INFO); } return new ObjectClassInfo( - type, CollectionUtil.newSet(attributeInfoMap.values()), - isContainer, isAuxiliary, isEmbedded); + type, + CollectionUtil.newSet(attributeInfoMap.values()), + isContainer, + isAuxiliary, + isEmbedded); } } diff --git a/java/testbundlev1/src/main/java/org/identityconnectors/testconnector/TstConnector.java b/java/testbundlev1/src/main/java/org/identityconnectors/testconnector/TstConnector.java index 749f4cb1..4c5bfdc1 100644 --- a/java/testbundlev1/src/main/java/org/identityconnectors/testconnector/TstConnector.java +++ b/java/testbundlev1/src/main/java/org/identityconnectors/testconnector/TstConnector.java @@ -60,37 +60,52 @@ import org.identityconnectors.testcommon.TstCommon; @ConnectorClass( - displayNameKey="TestConnector", - categoryKey="TestConnector.category", - configurationClass=TstConnectorConfig.class) + displayNameKey = "TestConnector", + categoryKey = "TestConnector.category", + configurationClass = TstConnectorConfig.class) public class TstConnector implements CreateOp, PoolableConnector, SchemaOp, SearchOp, SyncOp { public static final String USER_CLASS_NAME = "user"; + public static final String GROUP_CLASS_NAME = "group"; + public static final String ACCESS_CLASS_NAME = "access"; + public static final String MEMBER_OF_ATTR_NAME = "memberOf"; + public static final String MEMBERS_ATTR_NAME = "members"; + public static final String ACCESS_ATTR_NAME = "access"; + public static final String GROUP_ATTR_NAME = "group"; + public static final String GROUP_MEMBERSHIP_REFERENCE_TYPE_NAME = "groupMembership"; // test objects public static final String USER_100_UID = "b2ca2464-8aff-4bc4-9b7f-e68ad27d9f3d"; + public static final String USER_101_UID = "96010a29-aad5-43eb-b583-d5b897e3243c"; + public static final String USER_100_NAME = "user100"; + public static final String USER_101_NAME = "user101"; + public static final String GROUP_1_UID = "0a4be7af-157d-49fc-985f-f782ab4eef5e"; + public static final String GROUP_2_UID = "84fe911a-2e5c-4b67-9423-048e82445961"; + public static final String GROUP_1_NAME = "group1"; + public static final String GROUP_2_NAME = "group2"; private static int _connectionCount = 0; + private MyTstConnection _myConnection; + private TstConnectorConfig _config; public static void checkClassLoader() { - if (Thread.currentThread().getContextClassLoader() != - TstConnector.class.getClassLoader()) { + if (Thread.currentThread().getContextClassLoader() != TstConnector.class.getClassLoader()) { throw new IllegalStateException("Unexpected classloader"); } } @@ -102,27 +117,31 @@ public TstConnector() { @Override public Uid create(ObjectClass objectClass, Set createAttributes, OperationOptions options) { checkClassLoader(); - Integer delay = (Integer)options.getOptions().get("delay"); - if ( delay != null ) { - try { Thread.sleep(delay.intValue()); } catch (Exception e) {} + Integer delay = (Integer) options.getOptions().get("delay"); + if (delay != null) { + try { + Thread.sleep(delay); + } catch (Exception e) { + } } - if ( options.getOptions().get("testPooling") != null) { + if (options.getOptions().get("testPooling") != null) { return new Uid(String.valueOf(_myConnection.getConnectionNumber())); - } - else { + } else { String version = TstCommon.getVersion(); return new Uid(version); } } + @Override public void init(Configuration cfg) { checkClassLoader(); - _config = (TstConnectorConfig)cfg; + _config = (TstConnectorConfig) cfg; if (_config.getResetConnectionCount()) { _connectionCount = 0; } _myConnection = new MyTstConnection(_connectionCount++); } + @Override public Configuration getConfiguration() { return _config; @@ -148,15 +167,17 @@ public void checkAlive() { */ public String concat(String s1, String s2) { checkClassLoader(); - return s1+s2; + return s1 + s2; } @Override public FilterTranslator createFilterTranslator(ObjectClass objectClass, OperationOptions options) { - checkClassLoader(); - //no translation - ok since this is just for tests - return new AbstractFilterTranslator(){}; + checkClassLoader(); + //no translation - ok since this is just for tests + return new AbstractFilterTranslator() { + }; } + @Override public void executeQuery(ObjectClass objectClass, String query, ResultsHandler handler, OperationOptions options) { checkClassLoader(); @@ -167,18 +188,21 @@ public void executeQuery(ObjectClass objectClass, String query, ResultsHandler h } int remaining = _config.getNumResults(); - for (int i = 0; i < _config.getNumResults(); i++ ) { - Integer delay = (Integer)options.getOptions().get("delay"); - if ( delay != null ) { - try { Thread.sleep(delay.intValue()); } catch (Exception e) {} + for (int i = 0; i < _config.getNumResults(); i++) { + Integer delay = (Integer) options.getOptions().get("delay"); + if (delay != null) { + try { + Thread.sleep(delay); + } catch (Exception e) { + } } ConnectorObjectBuilder builder = - new ConnectorObjectBuilder(); + new ConnectorObjectBuilder(); builder.setUid(Integer.toString(i)); builder.setName(Integer.toString(i)); builder.setObjectClass(objectClass); - for ( int j = 0; j < 50; j++ ) { - builder.addAttribute("myattribute"+j,"myvaluevaluevalue"+j); + for (int j = 0; j < 50; j++) { + builder.addAttribute("myattribute" + j, "myvaluevaluevalue" + j); } ConnectorObject rv = builder.build(); @@ -190,7 +214,7 @@ public void executeQuery(ObjectClass objectClass, String query, ResultsHandler h } if (handler instanceof SearchResultsHandler) { - ((SearchResultsHandler) handler).handleResult(new SearchResult("",remaining)); + ((SearchResultsHandler) handler).handleResult(new SearchResult("", remaining)); } } @@ -198,7 +222,8 @@ private void executeUsersQuery(ResultsHandler handler) { ConnectorObjectReference user100Ref = createUserIdOnlyReference(USER_100_NAME); ConnectorObjectReference user101Ref = createUserIdOnlyReference(USER_101_NAME); - ConnectorObjectReference group1Ref = createGroupFullReference(GROUP_1_UID, GROUP_1_NAME, user100Ref, user101Ref); + ConnectorObjectReference group1Ref = + createGroupFullReference(GROUP_1_UID, GROUP_1_NAME, user100Ref, user101Ref); ConnectorObjectReference group2Ref = createGroupFullReference(GROUP_2_UID, GROUP_2_NAME, user100Ref); ConnectorObject user100 = createUser(USER_100_UID, USER_100_NAME, group1Ref, group2Ref); @@ -226,7 +251,9 @@ private ConnectorObject createUser(String uid, String name, ConnectorObjectRefer .build(); } - private ConnectorObjectReference createGroupFullReference(String uid, String name, ConnectorObjectReference... members) { + private ConnectorObjectReference createGroupFullReference( + String uid, String name, ConnectorObjectReference... members) { + return new ConnectorObjectReference( new ConnectorObjectBuilder() .setUid(uid) @@ -237,20 +264,23 @@ private ConnectorObjectReference createGroupFullReference(String uid, String nam } @Override - public void sync(ObjectClass objectClass, SyncToken token, - SyncResultsHandler handler, - OperationOptions options) { + public void sync( + ObjectClass objectClass, + SyncToken token, + SyncResultsHandler handler, + OperationOptions options) { + checkClassLoader(); int remaining = _config.getNumResults(); - for (int i = 0; i < _config.getNumResults(); i++ ) { + for (int i = 0; i < _config.getNumResults(); i++) { ConnectorObjectBuilder obuilder = - new ConnectorObjectBuilder(); + new ConnectorObjectBuilder(); obuilder.setUid(Integer.toString(i)); obuilder.setName(Integer.toString(i)); obuilder.setObjectClass(objectClass); SyncDeltaBuilder builder = - new SyncDeltaBuilder(); + new SyncDeltaBuilder(); builder.setObject(obuilder.build()); builder.setDeltaType(SyncDeltaType.CREATE_OR_UPDATE); builder.setToken(new SyncToken("mytoken")); @@ -265,6 +295,7 @@ public void sync(ObjectClass objectClass, SyncToken token, ((SyncTokenResultsHandler) handler).handleResult(new SyncToken(remaining)); } } + @Override public SyncToken getLatestSyncToken(ObjectClass objectClass) { checkClassLoader(); @@ -275,11 +306,11 @@ public SyncToken getLatestSyncToken(ObjectClass objectClass) { public Schema schema() { checkClassLoader(); SchemaBuilder schemaBuilder = new SchemaBuilder(TstConnector.class); - for ( int i = 0 ; i < 2; i++ ) { + for (int i = 0; i < 2; i++) { ObjectClassInfoBuilder classBuilder = new ObjectClassInfoBuilder(); - classBuilder.setType("class"+i); - for ( int j = 0; j < 200; j++) { - classBuilder.addAttributeInfo(AttributeInfoBuilder.build("attributename"+j, String.class)); + classBuilder.setType("class" + i); + for (int j = 0; j < 200; j++) { + classBuilder.addAttributeInfo(AttributeInfoBuilder.build("attributename" + j, String.class)); } schemaBuilder.defineObjectClass(classBuilder.build()); } diff --git a/java/testbundlev2/src/main/java/org/identityconnectors/testconnector/TstConnector.java b/java/testbundlev2/src/main/java/org/identityconnectors/testconnector/TstConnector.java index ff3aad78..5804c361 100644 --- a/java/testbundlev2/src/main/java/org/identityconnectors/testconnector/TstConnector.java +++ b/java/testbundlev2/src/main/java/org/identityconnectors/testconnector/TstConnector.java @@ -37,17 +37,19 @@ import org.identityconnectors.framework.spi.operations.CreateOp; import org.identityconnectors.testcommon.TstCommon; -@ConnectorClass(configurationClass=TstConnectorConfig.class, - displayNameKey="TestConnector") +@ConnectorClass(configurationClass = TstConnectorConfig.class, + displayNameKey = "TestConnector") public class TstConnector implements CreateOp, AuthenticateOp, Connector { private Configuration _config; - + + @Override public Uid create(ObjectClass objectClass, Set createAttributes, OperationOptions options) { String version = TstCommon.getVersion(); return new Uid(version); } + @Override public Uid authenticate(ObjectClass oclass, String username, GuardedString password, OperationOptions options) { // The native library is an empty file, so this should fail (and tests expect it). System.loadLibrary("native"); @@ -55,16 +57,18 @@ public Uid authenticate(ObjectClass oclass, String username, GuardedString passw throw new AssertionError("The loadLibrary call did not fail"); } + @Override public void init(Configuration cfg) { _config = cfg; } + @Override public Configuration getConfiguration() { return _config; } + @Override public void dispose() { - } public Schema getSchema() {