StoredConfigurationModifier { public void copyProfileID( final PwmSettingCategory category, final String sourceID, final String destinationID, final UserIdentity userIdentity ) throws PwmUnrecoverableException { if ( !category.hasProfiles() ) { throw PwmUnrecoverableException.newException( PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category " + category + ", category does not have profiles" ); } update( ( storedConfigData ) -> { final StoredConfiguration oldStoredConfiguration = new StoredConfigurationImpl( storedConfigData ); final PwmSetting profileSetting = category.getProfileSetting().orElseThrow( IllegalStateException::new ); final List<String> existingProfiles = StoredConfigurationUtil.profilesForSetting( profileSetting, oldStoredConfiguration ); if ( !existingProfiles.contains( sourceID ) ) { throw PwmUnrecoverableException.newException( PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category, source profileID '" + sourceID + "' does not exist" ); } if ( existingProfiles.contains( destinationID ) ) { throw PwmUnrecoverableException.newException( PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category, destination profileID '" + destinationID + "' already exists" ); } final Collection<PwmSettingCategory> interestedCategories = PwmSettingCategory.associatedProfileCategories( category ); final Map<StoredConfigItemKey, StoredValue> newValues = new LinkedHashMap<>(); for ( final PwmSettingCategory interestedCategory : interestedCategories ) { for ( final PwmSetting pwmSetting : interestedCategory.getSettings() ) { if ( !oldStoredConfiguration.isDefaultValue( pwmSetting, sourceID ) ) { final StoredValue value = oldStoredConfiguration.readSetting( pwmSetting, sourceID ); final StoredConfigItemKey key = StoredConfigItemKey.fromSetting( pwmSetting, destinationID ); newValues.put( key, value ); } } } { final List<String> newProfileIDList = new ArrayList<>( existingProfiles ); newProfileIDList.add( destinationID ); final StoredConfigItemKey key = StoredConfigItemKey.fromSetting( profileSetting, null ); final StoredValue value = new StringArrayValue( newProfileIDList ); newValues.put( key, value ); } final StoredConfigItemKey key = StoredConfigItemKey.fromSetting( category.getProfileSetting().orElseThrow( IllegalStateException::new ), null ); final ValueMetaData valueMetaData = new ValueMetaData( Instant.now(), userIdentity ); return storedConfigData.toBuilder() .storedValues( newValues ) .metaData( key, valueMetaData ) .build(); } ); } private  StoredConfigurationModifier( final StoredConfiguration storedConfiguration ); static StoredConfigurationModifier newModifier( final StoredConfiguration storedConfiguration ); StoredConfiguration newStoredConfiguration(); void writeSetting(
            final PwmSetting setting,
            final String profileID,
            final StoredValue value,
            final UserIdentity userIdentity
    ); void writeConfigProperty(
            final ConfigurationProperty propertyName,
            final String value
    ); void resetLocaleBundleMap( final PwmLocaleBundle pwmLocaleBundle, final String keyName ); void resetSetting( final PwmSetting setting, final String profileID, final UserIdentity userIdentity ); void deleteKey( final StoredConfigItemKey key ); void writeLocaleBundleMap(
            final PwmLocaleBundle pwmLocaleBundle,
            final String keyName,
            final Map<String, String> localeMap
    ); void copyProfileID(
            final PwmSettingCategory category,
            final String sourceID,
            final String destinationID,
            final UserIdentity userIdentity
    ); void setPassword( final String password );  }
@Test public void testCopyProfileID() throws PwmUnrecoverableException { final StoredConfiguration storedConfiguration = StoredConfigurationFactory.newConfig(); final StoredConfigurationModifier modifier = StoredConfigurationModifier.newModifier( storedConfiguration ); modifier.writeSetting( PwmSetting.HELPDESK_RESULT_LIMIT, "default", new NumericValue( 19 ), null ); modifier.copyProfileID( PwmSetting.HELPDESK_RESULT_LIMIT.getCategory(), "default", "newProfile", null ); final StoredConfiguration newConfig = modifier.newStoredConfiguration(); final List<String> profileNames = newConfig.profilesForSetting( PwmSetting.HELPDESK_RESULT_LIMIT ); Assert.assertEquals( profileNames.size(), 2 ); Assert.assertTrue( profileNames.contains( "default" ) ); Assert.assertTrue( profileNames.contains( "newProfile" ) ); final long copiedResultLimit = ( ( long ) newConfig.readSetting( PwmSetting.HELPDESK_RESULT_LIMIT, "default" ).toNativeObject() ); Assert.assertEquals( copiedResultLimit, 19 ); }