Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
senthuran16 committed Mar 27, 2024
1 parent 556f73e commit dad077e
Showing 1 changed file with 13 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,24 @@ public AttributeSchema getExtensionSchema() {
* @throws CharonException
*/
public void buildUserSchemaExtension(String configFilePath) throws CharonException, InternalErrorException {

readConfiguration(configFilePath);
buildExtensionSchema();
File provisioningConfig = new File(configFilePath);
try (InputStream configFilePathInputStream = new FileInputStream(provisioningConfig)) {
buildUserSchemaExtension(configFilePathInputStream);
} 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);
}
}

public void buildUserSchemaExtension(InputStream inputStream) throws CharonException, InternalErrorException {

readConfiguration(inputStream);
buildExtensionSchema();
}

private void buildExtensionSchema() throws InternalErrorException {
for (Map.Entry<String, ExtensionAttributeSchemaConfig> attributeSchemaConfig : extensionConfig.entrySet()) {
// if there are no children its a simple attribute, build it
if (!attributeSchemaConfig.getValue().hasChildren()) {
Expand All @@ -90,30 +96,6 @@ private void buildExtensionSchema() throws InternalErrorException {
extensionSchema = attributeSchemas.get(extensionRootAttributeURI);
}

/*
* This method reads configuration file and stores in the memory as an
* configuration map
*
* @param configFilePath
* @throws CharonException
*/
private void readConfiguration(String configFilePath) throws CharonException {

File provisioningConfig = new File(configFilePath);
try (InputStream inputStream = new FileInputStream(provisioningConfig)) {
readConfiguration(inputStream);
} 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);
}
}

public void readConfiguration(InputStream inputStream) throws CharonException {
//Scanner scanner = new Scanner(new FileInputStream(provisioningConfig));
Scanner scanner = new Scanner(inputStream, "utf-8").useDelimiter("\\A");
Expand Down

0 comments on commit dad077e

Please sign in to comment.