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;
}
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 ");
}
}
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);
}
}
}
}
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());
}
}
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");
}
}
Aggregations