use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class UpgradeUtils method getAttributeValue.
/**
* Returns a set of values of an attribute.
*
* @param serviceName name of the service.
* @param attributeName the attribute name.
* @param schemaType the schema type.
* @param isOrgAttrSchema boolean value indicating whether
* the attribute is to be retrieved from
* <OrganizationAttributeSchema>
* @return a set of values for the attribute.
* @throws UpgradeException if there is an error.
*/
public static Set getAttributeValue(String serviceName, String attributeName, String schemaType, boolean isOrgAttrSchema) throws UpgradeException {
String classMethod = "UpgradeUtils:getAttributeValue : ";
Set attrValues = Collections.EMPTY_SET;
try {
ServiceSchemaManager sm = getServiceSchemaManager(serviceName);
ServiceSchema ss = null;
if (isOrgAttrSchema) {
ss = sm.getOrganizationCreationSchema();
} else {
ss = sm.getSchema(schemaType);
}
Map attributeDefaults = ss.getAttributeDefaults();
if (attributeDefaults.containsKey(attributeName)) {
attrValues = (Set) attributeDefaults.get(attributeName);
}
} catch (SMSException sme) {
debug.error(classMethod + "Error retreiving attribute values : ", sme);
throw new UpgradeException("Unable to get attribute values : " + sme.getMessage());
}
return attrValues;
}
use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class UpgradeUtils method addNewSubSchemas.
public static void addNewSubSchemas(String serviceName, Map<String, SubSchemaUpgradeWrapper> subSchemaChanges, SSOToken adminToken) throws UpgradeException {
for (Map.Entry<String, SubSchemaUpgradeWrapper> subSchemaAdds : subSchemaChanges.entrySet()) {
SubSchemaUpgradeWrapper ssAdd = subSchemaAdds.getValue();
if (ssAdd != null) {
if (ssAdd.getSubSchemasAdded() != null && ssAdd.getSubSchemasAdded().subSchemaChanged()) {
ServiceSchema ss = getServiceSchema(serviceName, null, subSchemaAdds.getKey(), adminToken);
addNewSubSchema(serviceName, ssAdd.getSubSchemasAdded(), ss, adminToken);
}
}
}
}
use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class UpgradeUtils method getSubSchemaAttributeValue.
/**
* Returns a value of an attribute.
* This method assumes that the attribute is single valued.
*
* @param serviceName name of the service.
* @param attributeName name of the attribute.
* @param schemaType the schema type.
* @param subSchemaName the sub schema name.
* @return the value of the attribute
*/
public static String getSubSchemaAttributeValue(String serviceName, String schemaType, String attributeName, String subSchemaName) {
String classMethod = "UpgradeUtils:getSubSchemaAttributeValue :";
ServiceSchema ss = null;
String value = null;
try {
ss = getServiceSchema(serviceName, subSchemaName, schemaType);
AttributeSchema attrSchema = ss.getAttributeSchema(attributeName);
Set defaultVal = attrSchema.getDefaultValues();
value = (String) (defaultVal.iterator().next());
} catch (Exception e) {
debug.error(classMethod + "cannot retrieve attribute value for " + attributeName);
}
return value;
}
use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class UpgradeUtils method modifyAttributesInExistingSchema.
protected static void modifyAttributesInExistingSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
modifyAttributeInExistingSchema(serviceName, null, schemaType, attrs.getName(), attrs.getAttributeSchemaNode(), adminToken);
}
if (schemaMods.hasSubSchema()) {
for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
ServiceSchema subSchema = null;
try {
subSchema = serviceSchema.getSubSchema(schema.getKey());
} catch (SMSException smse) {
debug.error("Unable to modify attributes in schema", smse);
throw new UpgradeException(smse);
}
modifyAttributeInExistingSchema(subSchema, attrs.getName(), attrs.getAttributeSchemaNode());
}
if (schema.getValue().hasSubSchema()) {
ServiceSchema ss = null;
try {
ss = serviceSchema.getSubSchema(schema.getKey());
} catch (SMSException smse) {
debug.error("Unable to modify attributes in schema", smse);
throw new UpgradeException(smse);
}
modifyAttributesInExistingSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
}
}
}
}
use of com.sun.identity.sm.ServiceSchema in project OpenAM by OpenRock.
the class UpgradeUtils method addAttributeToSubSchema.
/**
* Adds new attribute schema to a sub schema in an existing service.
*
* @param serviceName the service name.
* @param subSchemaName the sub schema name.
* @param schemaType the schema type.
* @param attributeSchemaFile
* XML file containing attribute schema definition.
* @throws UpgradeException if there is an error adding the
* attribute schema.
* @supported.api
*/
public static void addAttributeToSubSchema(String serviceName, String subSchemaName, String schemaType, String attributeSchemaFile) throws UpgradeException {
String classMethod = "UpgradeUtils:addAttributeToSubSchema : ";
if (debug.messageEnabled()) {
debug.message(classMethod + "Adding attribute schema : " + attributeSchemaFile);
debug.message(" to subSchema " + subSchemaName + " to service " + serviceName);
}
FileInputStream fis = null;
ServiceSchema ss = getServiceSchema(serviceName, subSchemaName, schemaType);
try {
fis = new FileInputStream(attributeSchemaFile);
ss.addAttributeSchema(fis);
} catch (IOException ioe) {
debug.error(classMethod + "File not found " + attributeSchemaFile);
throw new UpgradeException(ioe.getMessage());
} catch (SMSException sme) {
debug.error(classMethod + "Cannot add attribute schema to : " + serviceName, sme);
throw new UpgradeException(sme.getMessage());
} catch (SSOException ssoe) {
debug.error(classMethod + "Invalid SSOToken : ", ssoe);
throw new UpgradeException(ssoe.getMessage());
} catch (Exception e) {
debug.error(classMethod + "Error setting attribute schema : ", e);
throw new UpgradeException(e.getMessage());
}
}
Aggregations