Search in sources :

Example 51 with ServiceSchema

use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.

the class UpgradeUtils method attributeExists.

/**
     * Checks the service scheam for existance of an attribute.
     *
     * @param serviceName name of the service.
     * @param attributeName the attribute name
     * @param schemaType the schema type
     * @return true if attrbute exist else false.
     * @throws UpgradeException if there is an error
     */
public static boolean attributeExists(String serviceName, String attributeName, String schemaType) throws UpgradeException {
    boolean isExists = false;
    try {
        ServiceSchemaManager sm = getServiceSchemaManager(serviceName);
        ServiceSchema ss = sm.getSchema(schemaType);
        Map attributeDefaults = ss.getAttributeDefaults();
        if (attributeDefaults.containsKey(attributeName)) {
            HashSet hashSet = (HashSet) attributeDefaults.get(attributeName);
            String value = (String) (hashSet.iterator().next());
            isExists = true;
        }
    } catch (SMSException sme) {
        throw new UpgradeException("Error getting attribute value");
    }
    return isExists;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) HashSet(java.util.HashSet)

Example 52 with ServiceSchema

use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.

the class UpgradeUtils method addAttributeChoiceValues.

/**
     * Add attribute choice values to an existing attribute.
     * The existing attribute values will be updated with new choice values.
     *
     * @param serviceName name of the service
     * @param subSchemaName name of the subschema
     * @param schemaType the schemaType
     * @param attributeName name of the attribute
     * @param choiceValuesMap a set of choice values values to
     *        be added to the attribute, the key is the i18NKey and
     *        the values it the choice value
     * @throws <code>UpgradeException</code> if there is an error.
     */
public static void addAttributeChoiceValues(String serviceName, String subSchemaName, String schemaType, String attributeName, Map choiceValuesMap) throws UpgradeException {
    String classMethod = "UpgradeUtils.addAttributeChoiceValues";
    try {
        ServiceSchema ss = getServiceSchema(serviceName, subSchemaName, schemaType);
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeName);
        addChoiceValues(attrSchema, choiceValuesMap);
    } catch (SSOException ssoe) {
        throw new UpgradeException(classMethod + " Error getting SSOToken ");
    } catch (SMSException sme) {
        throw new UpgradeException(classMethod + " Error updating choice values ");
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) AttributeSchema(com.sun.identity.sm.AttributeSchema) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString)

Example 53 with ServiceSchema

use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.

the class UpgradeUtils method removeAttributesFromSchema.

protected static void removeAttributesFromSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
    if (!(schemaMods.getAttributes().isEmpty())) {
        for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
            removeAttributeSchema(serviceName, null, schemaType, attrs.getName(), adminToken);
        }
    }
    if (schemaMods.hasSubSchema()) {
        for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
            if (!(schema.getValue().getAttributes().isEmpty())) {
                for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
                    ServiceSchema subSchema = null;
                    try {
                        subSchema = serviceSchema.getSubSchema(schema.getKey());
                    } catch (SMSException smse) {
                        debug.error("Unable to remove attributes from schema", smse);
                        throw new UpgradeException(smse);
                    }
                    removeAttributeSchema(subSchema, attrs.getName());
                }
            }
            if (schema.getValue().hasSubSchema()) {
                ServiceSchema ss = null;
                try {
                    ss = serviceSchema.getSubSchema(schema.getKey());
                } catch (SMSException smse) {
                    debug.error("Unable to remove attributes from schema", smse);
                    throw new UpgradeException(smse);
                }
                removeAttributesFromSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
            }
        }
    }
}
Also used : AttributeSchemaImpl(com.sun.identity.sm.AttributeSchemaImpl) ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with ServiceSchema

use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.

the class UpgradeUtils method setAttributeDefaultValues.

/**
     * Sets default values of an existing attribute.
     * The existing values will be overwritten with the new values.
     *
     * @param serviceName name of the service
     * @param subSchemaName name of the subschema
     * @param schemaType the type of schema.
     * @param attributeName name of the attribute
     * @param defaultValues a set of values to be added to the attribute
     * @throws UpgradeException if there is an error.
     * @supported.api
     */
public static void setAttributeDefaultValues(String serviceName, String subSchemaName, String schemaType, String attributeName, Set defaultValues) throws UpgradeException {
    String classMethod = "UpgradeUtils:setAttributeDefaultValues : ";
    if (debug.messageEnabled()) {
        debug.message(classMethod + " for attribute :" + attributeName + "in service :" + serviceName);
    }
    ServiceSchema ss = getServiceSchema(serviceName, subSchemaName, schemaType);
    try {
        ss.setAttributeDefaults(attributeName, defaultValues);
    } catch (SSOException ssoe) {
        debug.error(classMethod + "Invalid SSOToken", ssoe);
        throw new UpgradeException(bundle.getString("invalidSSOToken"));
    } catch (SMSException sme) {
        debug.error("Unable to set default values for attribute " + attributeName + " in service :" + serviceName, sme);
        throw new UpgradeException(sme.getMessage());
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString)

Example 55 with ServiceSchema

use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.

the class UpgradeUtils method modifyI18NKeyInSubSchema.

/**
     * Updates the values of the <code>i18NKey</code> attribute in the service`
     * subschema.
     *
     * @param serviceName the service name where the attribute exists.
     * @param subSchema the subschema name.
     * @param schemaType the schema type
     * @param i18NKeyValue the value of the <code>i18NKey</code> attribute
     * @throws UpgradeException if there is an error.
     */
public static void modifyI18NKeyInSubSchema(String serviceName, String subSchema, String schemaType, String i18NKeyValue) throws UpgradeException {
    String classMethod = "UpgradeUtils:modifyI18NKeyInSubSchema : ";
    try {
        ServiceSchema ss = getServiceSchema(serviceName, subSchema, schemaType);
        ss.setI18Nkey(i18NKeyValue);
    } catch (SSOException ssoe) {
        debug.error(classMethod + "Invalid SSOToken");
        throw new UpgradeException("Invalid SSOToken");
    } catch (SMSException sme) {
        debug.error(classMethod + "Error setting i18N key : " + serviceName, sme);
        throw new UpgradeException("Error setting i18NKey Value");
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString)

Aggregations

ServiceSchema (com.sun.identity.sm.ServiceSchema)216 SMSException (com.sun.identity.sm.SMSException)152 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)131 SSOException (com.iplanet.sso.SSOException)117 Set (java.util.Set)101 AttributeSchema (com.sun.identity.sm.AttributeSchema)76 HashSet (java.util.HashSet)71 Map (java.util.Map)70 HashMap (java.util.HashMap)57 Iterator (java.util.Iterator)56 CLIException (com.sun.identity.cli.CLIException)46 SSOToken (com.iplanet.sso.SSOToken)27 IOutput (com.sun.identity.cli.IOutput)26 BeforeTest (org.testng.annotations.BeforeTest)22 CLIRequest (com.sun.identity.cli.CLIRequest)21 ByteString (org.forgerock.opendj.ldap.ByteString)21 AfterTest (org.testng.annotations.AfterTest)21 Test (org.testng.annotations.Test)21 Parameters (org.testng.annotations.Parameters)18 TreeSet (java.util.TreeSet)15