11/*
2- * Copyright (C) 2017-2025 HERE Europe B.V.
2+ * Copyright (C) 2017-2026 HERE Europe B.V.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1919
2020package com .here .xyz .jobs .steps .compiler ;
2121
22- import static com .here .xyz .jobs .steps .Step .InputSet .USER_INPUTS ;
23- import static com .here .xyz .jobs .steps .impl .transport .ImportFilesToSpace .Format .CSV_GEOJSON ;
24- import static com .here .xyz .jobs .steps .impl .transport .ImportFilesToSpace .Format .CSV_JSON_WKB ;
25- import static com .here .xyz .jobs .steps .impl .transport .ImportFilesToSpace .Format .GEOJSON ;
26- import static com .here .xyz .util .db .pg .IndexHelper .SystemIndex .NEXT_VERSION ;
27- import static com .here .xyz .util .db .pg .IndexHelper .SystemIndex .OPERATION ;
28- import static com .here .xyz .util .db .pg .IndexHelper .SystemIndex .VERSION_ID ;
29-
3022import com .google .common .collect .Lists ;
3123import com .here .xyz .jobs .Job ;
3224import com .here .xyz .jobs .datasets .DatasetDescription .Space ;
4234import com .here .xyz .jobs .steps .impl .AnalyzeSpaceTable ;
4335import com .here .xyz .jobs .steps .impl .CreateIndex ;
4436import com .here .xyz .jobs .steps .impl .DropIndexes ;
45- import com .here .xyz .jobs .steps .impl .transport .ImportFilesToSpace ;
46- import com .here .xyz .jobs .steps .impl .transport .ImportFilesToSpace .EntityPerLine ;
47- import com .here .xyz .jobs .steps .impl .transport .ImportFilesToSpace .Format ;
4837import com .here .xyz .jobs .steps .impl .transport .TaskedImportFilesToSpace ;
4938import com .here .xyz .models .hub .Ref ;
5039import com .here .xyz .util .db .pg .IndexHelper .Index ;
5140import com .here .xyz .util .db .pg .IndexHelper .SystemIndex ;
5241import com .here .xyz .util .web .HubWebClient ;
5342import com .here .xyz .util .web .XyzWebClient .ErrorResponseException ;
5443import com .here .xyz .util .web .XyzWebClient .WebClientException ;
44+
5545import java .util .HashSet ;
5646import java .util .List ;
5747import java .util .Set ;
5848import java .util .stream .Collectors ;
5949import java .util .stream .Stream ;
6050
61- public class ImportFromFiles implements JobCompilationInterceptor {
62- public boolean useNewTaskedImportStep = true ;
51+ import static com .here .xyz .jobs .steps .Step .InputSet .USER_INPUTS ;
52+ import static com .here .xyz .util .db .pg .IndexHelper .SystemIndex .NEXT_VERSION ;
53+ import static com .here .xyz .util .db .pg .IndexHelper .SystemIndex .OPERATION ;
54+ import static com .here .xyz .util .db .pg .IndexHelper .SystemIndex .VERSION_ID ;
6355
56+ public class ImportFromFiles implements JobCompilationInterceptor {
6457 public static Set <Class <? extends Space >> allowedTargetTypes = new HashSet <>(Set .of (Space .class ));
6558
66- public void setUseNewTaskedImportStep (boolean useNewTaskedImportStep ) {
67- this .useNewTaskedImportStep = useNewTaskedImportStep ;
68- }
69- public ImportFromFiles withUseNewTaskedImportStep (boolean useNewTaskedImportStep ) {
70- setUseNewTaskedImportStep (useNewTaskedImportStep );
71- return this ;
72- }
73-
7459 @ Override
7560 public boolean chooseMe (Job job ) {
7661 return job .getProcess () == null && job .getSource () instanceof Files files && isSupportedFormat (files )
@@ -87,52 +72,31 @@ public CompilationStepGraph compile(Job job) {
8772 String spaceId = target .getId ();
8873
8974 final FileFormat sourceFormat = ((Files ) job .getSource ()).getInputSettings ().getFormat ();
90- Format importStepFormat ;
91- if (sourceFormat instanceof GeoJson )
92- importStepFormat = GEOJSON ;
93- else if (sourceFormat instanceof Csv csvFormat )
94- importStepFormat = csvFormat .isGeometryAsExtraWkbColumn () ? CSV_JSON_WKB : CSV_GEOJSON ;
95- else
96- throw new CompilationError ("Unsupported import file format: " + sourceFormat .getClass ().getSimpleName ());
9775
98- EntityPerLine entityPerLine = getEntityPerLine (sourceFormat );
76+ if (!(sourceFormat instanceof GeoJson ))
77+ throw new CompilationError ("Unsupported import file format: " + sourceFormat .getClass ().getSimpleName ());
9978
10079 //This validation check is necessary to deliver a constructive error to the user - otherwise keepIndices will throw a runtime error.
10180 checkIfSpaceIsAccessible (spaceId );
10281
103- if (useNewTaskedImportStep ) {
104- if (!entityPerLine .equals (EntityPerLine .Feature ))
105- throw new CompilationError ("TaskedImportStep - Unsupported entityPerLine configuration: " + entityPerLine .name ());
106- if (!(sourceFormat instanceof GeoJson ))
107- throw new CompilationError ("TaskedImportStep - Unsupported format configuration: " + sourceFormat .getClass ().getSimpleName ());
108-
109- TaskedImportFilesToSpace importFilesStep = new TaskedImportFilesToSpace () //Perform import
110- .withSpaceId (spaceId )
111- .withVersionRef (new Ref (Ref .HEAD ))
112- .withJobId (job .getId ())
113- .withInputSets (List .of (USER_INPUTS .get ()));
114- if (importFilesStep .keepIndices ())
115- //Perform only the import Step
116- return (CompilationStepGraph ) new CompilationStepGraph ()
117- .addExecution (importFilesStep );
82+ TaskedImportFilesToSpace importFilesStep = new TaskedImportFilesToSpace () //Perform import
83+ .withEntityPerLine (getEntityPerLine (sourceFormat ))
84+ .withSpaceId (spaceId )
85+ .withVersionRef (new Ref (Ref .HEAD ))
86+ .withJobId (job .getId ())
87+ .withInputSets (List .of (USER_INPUTS .get ()));
11888
119- //perform full Import with all 11 Steps (IDX deletion/creation..)
120- return compileTaskedImportSteps (importFilesStep );
121- }else {
122- ImportFilesToSpace importFilesStep = new ImportFilesToSpace () //Perform import
123- .withSpaceId (spaceId )
124- .withFormat (importStepFormat )
125- .withEntityPerLine (entityPerLine )
126- .withJobId (job .getId ())
127- .withInputSets (List .of (USER_INPUTS .get ()));
128- if (importFilesStep .keepIndices ())
89+ try {
90+ if (importFilesStep .useFeatureWriter ())
12991 //Perform only the import Step
13092 return (CompilationStepGraph ) new CompilationStepGraph ()
13193 .addExecution (importFilesStep );
132-
133- //perform full Import with all 11 Steps (IDX deletion/creation..)
134- return compileImportSteps (importFilesStep );
94+ } catch (WebClientException e ) {
95+ throw new CompilationError ("Error retrieving statistics for target resource during compilation!" , e );
13596 }
97+
98+ //perform full Import with all 11 Steps (IDX deletion/creation..)
99+ return compileTaskedImportSteps (importFilesStep );
136100 }
137101
138102 public static CompilationStepGraph compileWrapWithDropRecreateIndices (String spaceId , StepExecution stepExecution ) {
@@ -179,20 +143,10 @@ public static CompilationStepGraph compileTaskedImportSteps(TaskedImportFilesToS
179143 }
180144 }
181145
182- public static CompilationStepGraph compileImportSteps (ImportFilesToSpace importFilesStep ) {
183- try {
184- //Keep these indices if FeatureWriter is used
185- List <Index > whiteListIndex = importFilesStep .useFeatureWriter () ? List .of (VERSION_ID , NEXT_VERSION , OPERATION ) : null ;
186- return compileWrapWithDropRecreateIndices (importFilesStep .getSpaceId (), importFilesStep , whiteListIndex );
187- } catch (WebClientException e ) {
188- throw new CompilationError ("Unexpected error occurred during compilation" , e );
189- }
190- }
191-
192- private EntityPerLine getEntityPerLine (FileFormat format ) {
193- return EntityPerLine .valueOf ((format instanceof GeoJson geoJson
194- ? geoJson .getEntityPerLine ()
195- : ((Csv ) format ).getEntityPerLine ()).toString ());
146+ private TaskedImportFilesToSpace .EntityPerLine getEntityPerLine (FileFormat format ) {
147+ return TaskedImportFilesToSpace .EntityPerLine .valueOf ((format instanceof GeoJson geoJson
148+ ? geoJson .getEntityPerLine ()
149+ : ((Csv ) format ).getEntityPerLine ()).toString ());
196150 }
197151
198152 private static List <StepExecution > toSequentialSteps (String spaceId , List <SystemIndex > indices ) {
0 commit comments