Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable loading the UserSchemaExtension from a classpath resource #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,30 @@ public AttributeSchema getExtensionSchema() {
return extensionSchema;
}

public void buildUserSchemaExtension(String configFilePath) throws CharonException, InternalErrorException {

File provisioningConfig = new File(configFilePath);

try (InputStream inputStream = new FileInputStream(provisioningConfig)) {

buildUserSchemaExtension(inputStream);

} catch (FileNotFoundException e) {
throw new CharonException(SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file not found!",
e);
} catch (IOException e) {
throw new CharonException("Error while closing " +
SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e);
}
}

/*
* Logic goes here
* @throws CharonException
*/
public void buildUserSchemaExtension(String configFilePath) throws CharonException, InternalErrorException {
public void buildUserSchemaExtension(InputStream inputStream) throws CharonException, InternalErrorException {

readConfiguration(configFilePath);
readConfiguration(inputStream);

for (Map.Entry<String, ExtensionAttributeSchemaConfig> attributeSchemaConfig : extensionConfig.entrySet()) {
// if there are no children its a simple attribute, build it
Expand All @@ -88,11 +105,9 @@ public void buildUserSchemaExtension(String configFilePath) throws CharonExcepti
* @param configFilePath
* @throws CharonException
*/
private void readConfiguration(String configFilePath) throws CharonException {
private void readConfiguration(InputStream inputStream) throws CharonException {

File provisioningConfig = new File(configFilePath);
try (InputStream inputStream = new FileInputStream(provisioningConfig)) {
//Scanner scanner = new Scanner(new FileInputStream(provisioningConfig));
try {
Scanner scanner = new Scanner(inputStream, "utf-8").useDelimiter("\\A");
String jsonString = scanner.hasNext() ? scanner.next() : "";

Expand All @@ -112,15 +127,9 @@ private void readConfiguration(String configFilePath) throws CharonException {
extensionRootAttributeName = schemaAttributeConfig.getName();
}
}
} catch (FileNotFoundException e) {
throw new CharonException(SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file not found!",
e);
} catch (JSONException e) {
throw new CharonException("Error while parsing " +
SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e);
} catch (IOException e) {
throw new CharonException("Error while closing " +
SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG + " file!", e);
}
}

Expand Down