1111import org .apache .cayenne .ObjectContext ;
1212import org .apache .cayenne .configuration .server .ServerRuntime ;
1313import org .apache .commons .collections .CollectionUtils ;
14+ import org .apache .commons .lang3 .ObjectUtils ;
1415import org .apache .commons .lang3 .StringUtils ;
1516import org .haiku .driversettings .DriverSettings ;
1617import org .haiku .driversettings .DriverSettingsException ;
18+ import org .haiku .driversettings .Parameter ;
1719import org .haiku .haikudepotserver .dataobjects .Repository ;
1820import org .haiku .haikudepotserver .dataobjects .RepositorySource ;
1921import org .haiku .haikudepotserver .job .AbstractJobRunner ;
3335
3436import java .io .*;
3537import java .net .URL ;
38+ import java .util .List ;
3639import java .util .Objects ;
40+ import java .util .Optional ;
3741import java .util .Set ;
3842import java .util .concurrent .TimeUnit ;
43+ import java .util .stream .Stream ;
3944
4045/**
4146 * <p>This object is responsible for migrating a HPKR file from a remote repository into the Haiku Depot Server
@@ -53,7 +58,9 @@ public class RepositoryHpkrIngressJobRunner extends AbstractJobRunner<Repository
5358
5459 private final static long TIMEOUT_REPOSITORY_SOURCE_FETCH = TimeUnit .SECONDS .toMillis (30 );
5560
61+ @ Deprecated // replaced with "identifier"
5662 private final static String PARAMETER_NAME_URL = "url" ;
63+ private final static String PARAMETER_NAME_IDENTIFIER = "identifier" ;
5764
5865 private final ServerRuntime serverRuntime ;
5966 private final PkgService pkgService ;
@@ -142,24 +149,23 @@ private void runImportInfoForRepositorySource(
142149 InputStreamReader inputStreamReader = new InputStreamReader (inputStream , Charsets .UTF_8 );
143150 BufferedReader reader = new BufferedReader (inputStreamReader )
144151 ) {
145- String urlParameterValue = DriverSettings .parse (reader )
146- .stream ()
147- .filter (p -> p .getName ().equals (PARAMETER_NAME_URL ))
148- .filter (p -> CollectionUtils .isNotEmpty (p .getValues ()))
149- .findAny ()
150- .map (v -> StringUtils .trimToNull (v .getValues ().get (0 )))
151- .orElseThrow (() -> new DriverSettingsException ("the 'repo.info' file is expected to have "
152- + "a [" + PARAMETER_NAME_URL + "] entry as identifier, but this appears to be "
153- + "missing" ));
154-
155- if (!Objects .equals (urlParameterValue , repositorySource .getUrl ())) {
156- LOGGER .info ("updated the repo info url to [{}] for repository source [{}]" ,
157- urlParameterValue , repositorySource .getCode ());
158- repositorySource .setUrl (urlParameterValue );
159- repositorySource .getRepository ().setModifyTimestamp ();
160- mainContext .commitChanges ();
161- }
152+ List <Parameter > parameters = DriverSettings .parse (reader );
153+ String urlParameterValue = ObjectUtils .firstNonNull (
154+ tryGetParameterValue (parameters , PARAMETER_NAME_IDENTIFIER ).orElse (null ),
155+ tryGetParameterValue (parameters , PARAMETER_NAME_URL ).orElse (null ) );
156+
157+ if (StringUtils .isEmpty (urlParameterValue )) {
158+ throw new DriverSettingsException ("expected to find the parameter [" + PARAMETER_NAME_IDENTIFIER
159+ + "] or [" + PARAMETER_NAME_URL + "]" );
160+ }
162161
162+ if (!Objects .equals (urlParameterValue , repositorySource .getUrl ())) {
163+ LOGGER .info ("updated the repo info url to [{}] for repository source [{}]" ,
164+ urlParameterValue , repositorySource .getCode ());
165+ repositorySource .setUrl (urlParameterValue );
166+ repositorySource .getRepository ().setModifyTimestamp ();
167+ mainContext .commitChanges ();
168+ }
163169 }
164170 } catch (IOException | DriverSettingsException e ) {
165171 throw new RepositoryHpkrIngressException (
@@ -170,9 +176,22 @@ private void runImportInfoForRepositorySource(
170176 LOGGER .error ("unable to delete the file; {}" + temporaryFile .getAbsolutePath ());
171177 }
172178 }
173-
174179 }
180+ }
181+
182+ private Optional <String > tryGetParameterValue (List <Parameter > parameters , String parameterName ) {
183+ return tryGetParameter (parameters , parameterName )
184+ .map (Parameter ::getValues )
185+ .filter (org .apache .commons .collections4 .CollectionUtils ::isNotEmpty ).flatMap (vs -> vs .stream ()
186+ .filter (StringUtils ::isNotBlank )
187+ .findFirst ());
188+ }
175189
190+ private Optional <Parameter > tryGetParameter (List <Parameter > parameters , String parameterName ) {
191+ return org .apache .commons .collections4 .CollectionUtils .emptyIfNull (parameters )
192+ .stream ()
193+ .filter (p -> p .getName ().equals (parameterName ))
194+ .findFirst ();
176195 }
177196
178197 private void runImportHpkrForRepositorySource (
0 commit comments