88import static java .nio .charset .StandardCharsets .UTF_8 ;
99
1010import java .io .ByteArrayInputStream ;
11- import java .io .File ;
1211import java .io .InputStream ;
1312import java .io .InputStreamReader ;
1413import java .io .Reader ;
2019import java .util .HashMap ;
2120import java .util .List ;
2221import java .util .Map ;
23- import java .util .Optional ;
2422import java .util .function .Function ;
2523import java .util .stream .Collectors ;
2624
@@ -77,23 +75,23 @@ class EntityModelLoader {
7775 }
7876
7977 /**
80- * Load models from model directory and classpath and returns a future to an unmodifiable map of all loaded models.
78+ * Load models from model directory and class path and return a future to a map of all loaded models.
8179 *
82- * @return a unmodifiable map of all loaded models
80+ * @return a map of all loaded models
8381 */
8482 public static Future <Map <String , EntityModel >> load (Vertx vertx ) {
85- return new EntityModelLoader (vertx ).loadModelsFromModelDirectoryAndClasspath ()
83+ return new EntityModelLoader (vertx ).loadModelsFromModelDirectoryAndClassPath ()
8684 .map (EntityModelLoader ::getModels );
8785 }
8886
8987 /**
90- * Load models from model directory and classpath , as well as from the maps provided and returns a future to an
91- * unmodifiable map of all loaded models.
88+ * Load models from model directory and class path , as well as from the maps provided and return a future to a map
89+ * of all loaded models.
9290 *
93- * @return a unmodifiable map of all loaded models
91+ * @return a map of all loaded models
9492 */
9593 public static Future <Map <String , EntityModel >> load (Vertx vertx , Collection <EntityModelDefinition > definitions ) {
96- return new EntityModelLoader (vertx ).loadModelsFromModelDirectoryAndClasspath ().compose (loader -> {
94+ return new EntityModelLoader (vertx ).loadModelsFromModelDirectoryAndClassPath ().compose (loader -> {
9795 return CompositeFuture
9896 .all (definitions .stream ().map (loader ::loadModelsFromDefinition ).collect (Collectors .toList ()))
9997 .map (loader );
@@ -103,18 +101,18 @@ public static Future<Map<String, EntityModel>> load(Vertx vertx, Collection<Enti
103101 /**
104102 * Returns a map of all loaded models.
105103 *
106- * @return a unmodifiable map of all loaded models
104+ * @return a map of all loaded models
107105 */
108106 public Map <String , EntityModel > getModels () {
109- return Collections . unmodifiableMap ( models ) ;
107+ return models ;
110108 }
111109
112110 /**
113- * Load models from model directory and classpath .
111+ * Load models from model directory and class path .
114112 *
115113 * @return a future to the {@link EntityModelLoader} instance
116114 */
117- public Future <EntityModelLoader > loadModelsFromModelDirectoryAndClasspath () {
115+ public Future <EntityModelLoader > loadModelsFromModelDirectoryAndClassPath () {
118116 NeonBeeOptions options = NeonBee .get (vertx ).getOptions ();
119117 return CompositeFuture .all (scanDir (options .getModelsDirectory ()),
120118 options .shouldIgnoreClassPath () ? succeededFuture () : scanClassPath ()).map (this );
@@ -165,7 +163,7 @@ Future<Void> scanClassPath() {
165163 Future <List <String >> modelFiles = scanner .scanManifestFiles (vertx , NEONBEE_MODELS );
166164
167165 return CompositeFuture .all (csnFiles , modelFiles ).compose (scanResult -> CompositeFuture
168- // Use distinct because models mentioned in the manifest could also exists as file.
166+ // use distinct because models mentioned in the manifest could also exists as file.
169167 .all (Streams .concat (csnFiles .result ().stream (), modelFiles .result ().stream ()).distinct ()
170168 .map (name -> loadModel (Path .of (name )).otherwise (throwable -> {
171169 // models loaded from the class path are non-vital for NeonBee so continue anyways
@@ -180,25 +178,26 @@ Future<Void> loadModel(Path csnFile) {
180178 return succeededFuture ();
181179 }
182180
183- return readCsnModel (csnFile )
184- .compose (
185- cdsModel -> CompositeFuture
186- .all (EntityModelDefinition .resolveEdmxPaths (csnFile , cdsModel ).stream ()
187- .map (this ::loadEdmxModel ).collect (Collectors .toList ()))
188- .onSuccess (compositeFuture -> {
189- buildModelMap (cdsModel , compositeFuture .<ServiceMetadata >list ());
190- }))
191- .mapEmpty ();
181+ return readCsnModel (csnFile ).compose (cdsModel -> {
182+ return CompositeFuture .all (EntityModelDefinition .resolveEdmxPaths (csnFile , cdsModel ).stream ()
183+ .map (this ::loadEdmxModel ).collect (Collectors .toList ())).onSuccess (compositeFuture -> {
184+ buildModelMap (cdsModel , compositeFuture .<ServiceMetadata >list ());
185+ });
186+ }).mapEmpty ();
192187 }
193188
194- Future <Void > parseModel (String csnFile , byte [] csnPayload , Map <String , byte []> extensionModels ) {
195- return parseCsnModel (csnPayload ).compose (cdsModel -> CompositeFuture .all (EntityModelDefinition
196- .resolveEdmxPaths (Path .of (csnFile ), cdsModel ).stream ().map (Path ::toString ).map (path -> {
197- return Optional .ofNullable (extensionModels .get (path )).orElse (extensionModels
198- .get (path .replace (File .separatorChar , File .separatorChar == '/' ? '\\' : '/' )));
199- }).map (this ::parseEdmxModel ).collect (Collectors .toList ())).onSuccess (compositeFuture -> {
200- buildModelMap (cdsModel , compositeFuture .<ServiceMetadata >list ());
201- })).mapEmpty ();
189+ Future <Void > parseModel (String csnFile , byte [] csnPayload , Map <String , byte []> associatedModels ) {
190+ return parseCsnModel (csnPayload )
191+ .compose (cdsModel -> CompositeFuture
192+ .all (EntityModelDefinition .resolveEdmxPaths (Path .of (csnFile ), cdsModel ).stream ()
193+ .map (Path ::toString ).map (path -> {
194+ // we do not know if the path uses windows / unix path separators, try both!
195+ return FileSystemHelper .getPathFromMap (associatedModels , path );
196+ }).map (this ::parseEdmxModel ).collect (Collectors .toList ()))
197+ .onSuccess (compositeFuture -> {
198+ buildModelMap (cdsModel , compositeFuture .<ServiceMetadata >list ());
199+ }))
200+ .mapEmpty ();
202201 }
203202
204203 private void buildModelMap (CdsModel cdsModel , List <ServiceMetadata > edmxModels ) {
0 commit comments