3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
c8408fe9c4eb7f97ffa5b6aafcd4157afd478bc8Jon Branch * Copyright 2014-2015 ForgeRock AS
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * The contents of this file are subject to the terms
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * of the Common Development and Distribution License
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * (the License). You may not use this file except in
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * compliance with the License.
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * You can obtain a copy of the License at
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * See the License for the specific language governing
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * permission and limitations under the License.
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * When distributing Covered Code, include this CDDL
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * Header Notice in each file and include the License file
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * If applicable, add the following below the CDDL Header,
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * with the fields enclosed by brackets [] replaced by
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * your own identifying information:
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * "Portions Copyrighted [year] [name of copyright owner]"
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.forgerock.openicf.misc.crest.VisitorParameter
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.common.CollectionUtil
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.common.security.GuardedByteArray
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.common.security.GuardedString
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.exceptions.ConfigurationException
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.Attribute
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.AttributeInfo
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.AttributeInfoBuilder
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.AttributeUtil
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.Name
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.ObjectClass
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.QualifiedUid
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.Uid
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * A CRESTSchema parses the OpenIDM configuration and builds the schema from.
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * @author Laszlo Hordos
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String TYPE_STRING = "string";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String TYPE_NUMBER = "number";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String TYPE_INTEGER = "integer";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String TYPE_BOOLEAN = "boolean";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String TYPE_OBJECT = "object";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String TYPE_ARRAY = "array";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_BIGDECIMAL = "JAVA_TYPE_BIGDECIMAL";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_BIGINTEGER = "JAVA_TYPE_BIGINTEGER";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_PRIMITIVE_BOOLEAN = "JAVA_TYPE_PRIMITIVE_BOOLEAN";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_BYTE_ARRAY = "JAVA_TYPE_BYTE_ARRAY";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_CHAR = "JAVA_TYPE_CHAR";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_CHARACTER = "JAVA_TYPE_CHARACTER";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_DATE = "JAVA_TYPE_DATE";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_PRIMITIVE_DOUBLE = "JAVA_TYPE_PRIMITIVE_DOUBLE";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_DOUBLE = "JAVA_TYPE_DOUBLE";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_FILE = "JAVA_TYPE_FILE";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_PRIMITIVE_FLOAT = "JAVA_TYPE_PRIMITIVE_FLOAT";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_FLOAT = "JAVA_TYPE_FLOAT";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_GUARDEDBYTEARRAY = "JAVA_TYPE_GUARDEDBYTEARRAY";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_GUARDEDSTRING = "JAVA_TYPE_GUARDEDSTRING";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_INT = "JAVA_TYPE_INT";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_PRIMITIVE_LONG = "JAVA_TYPE_PRIMITIVE_LONG";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_LONG = "JAVA_TYPE_LONG";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_NAME = "JAVA_TYPE_NAME";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_OBJECTCLASS = "JAVA_TYPE_OBJECTCLASS";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_QUALIFIEDUID = "JAVA_TYPE_QUALIFIEDUID";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_SCRIPT = "JAVA_TYPE_SCRIPT";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_UID = "JAVA_TYPE_UID";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_URI = "JAVA_TYPE_URI";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_BYTE = "JAVA_TYPE_BYTE";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay public static final String JAVA_TYPE_PRIMITIVE_BYTE = "JAVA_TYPE_PRIMITIVE_BYTE";
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay static Map<String, Object> parse(URL jsonConfig) {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay throw new ConfigurationException("Schema of ${key} does not contain '__NAME__'")
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay Map<String, Class> typeMap = new HashMap<String, Class>(43);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_BIGDECIMAL, BigDecimal.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_BIGINTEGER, BigInteger.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_PRIMITIVE_BOOLEAN, boolean.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_BYTE_ARRAY, byte[].class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_CHARACTER, Character.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_PRIMITIVE_DOUBLE, double.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_PRIMITIVE_FLOAT, float.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_GUARDEDBYTEARRAY, GuardedByteArray.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_GUARDEDSTRING, GuardedString.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_PRIMITIVE_LONG, long.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_OBJECTCLASS, ObjectClass.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_QUALIFIEDUID, QualifiedUid.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_SCRIPT, org.identityconnectors.common.script.Script.class);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay typeMap.put(JAVA_TYPE_PRIMITIVE_BYTE, Byte.TYPE);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay //def url = getClass().getClassLoader().getResource("schema.json")
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay result.objectTypes.collectEntries(schema) { objectName, objectDefinition ->
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay objectDefinition.properties.collectEntries {String propertyName, Map propertyDefinition ->
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay if (AttributeUtil.namesEqual(Uid.NAME, propertyDefinition.nativeName)) {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay AttributeInfoBuilder builder = new AttributeInfoBuilder(propertyDefinition.nativeName);
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay } else if ("NOT_UPDATEABLE".equalsIgnoreCase(it)) {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay } else if ("NOT_READABLE".equalsIgnoreCase(it)) {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay } else if ("NOT_RETURNED_BY_DEFAULT".equalsIgnoreCase(it)) {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay builder.setType(typeMap[propertyDefinition.nativeType])
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay String getResourceContainer(ObjectClass objectClass) {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay for (Pair<String, String> pair : cache.keySet()) {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay throw new UnsupportedOperationException("Unsupported ObjectClass: " + objectClass.objectClassValue)
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay Map<String, Set<AttributeInfo>> getAttributeInfo() {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay private Map<String, VisitorParameter> visitorCache;
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay VisitorParameter getVisitorParameter(ObjectClass objectClass) {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay visitorCache = CollectionUtil.newCaseInsensitiveMap();
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay def parameter = visitorCache[key.second] = new org.forgerock.openicf.misc.crest.VisitorParameter() {
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay CRESTHelper.setAttributeValue(a.attributeInfo, it)
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay CRESTHelper.setAttributeValue(a.attributeInfo, AttributeUtil.getSingleValue(filter))
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay VisitorParameter p = visitorCache[objectClass.objectClassValue]
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay throw new UnsupportedOperationException("Unsupported ObjectClass: " + objectClass.objectClassValue)