@Test public void loadModelsPMMLFile() { final PMMLDocumentMetadata pmmlDocumentMetadata = new PMMLDocumentMetadata(PMML_PATH, PMML_FILE, PMML.getDefaultNamespace(), Collections.emptyList()); when(dmnImportsContentService.getModelsURIs()).thenReturn(promises.resolve(new String[]{PMML_PATH})); when(dmnImportsContentService.loadFile(PMML_PATH)).thenReturn(promises.resolve(PMML_CONTENT)); when(dmnImportsContentService.loadFile(PMML_PATH)).thenReturn(promises.resolve(PMML_CONTENT)); doReturn(promises.resolve(pmmlDocumentMetadata)).when(dmnImportsContentService).getPMMLDocumentMetadata(PMML_PATH); importsHelper.loadModels(includedModelServiceCallback); verify(includedModelServiceCallback).onSuccess(modelsCapture.capture()); assertEquals(1, modelsCapture.getValue().size()); assertEquals(PMML_FILE, modelsCapture.getValue().get(0).getPath()); assertEquals(PMML_FILE, modelsCapture.getValue().get(0).getModelName()); assertEquals(PMML.getDefaultNamespace(), modelsCapture.getValue().get(0).getImportType()); assertEquals(0, ((PMMLIncludedModel) modelsCapture.getValue().get(0)).getModelCount().intValue()); }
public void loadModels(final ServiceCallback<List<IncludedModel>> callback) { final List<IncludedModel> models = new ArrayList<>(); dmnImportsContentService.getModelsURIs() .then(items -> promises.all(Arrays.asList(items), file -> { final String fileName = FileUtils.getFileName(file); if (fileName.endsWith("." + DMNImportTypes.DMN.getFileExtension())) { return dmnImportsContentService.loadFile(file) .then(fileContent -> promises.create((success, failed) -> dmnImportsService.getWbDefinitions(fileContent, new ServiceCallback<Definitions>() { @Override public void onSuccess(final Definitions definitions) { final String modelPackage = ""; final String namespace = definitions.getNamespace().getValue(); final String importType = DMNImportTypes.DMN.getDefaultNamespace(); final int drgElementCount = definitions.getDrgElement().size(); final int itemDefinitionCount = definitions.getItemDefinition().size(); models.add(new DMNIncludedModel(fileName, modelPackage, fileName, namespace, importType, drgElementCount, itemDefinitionCount)); success.onInvoke(promises.resolve()); } @Override public void onError(final ClientRuntimeError error) { success.onInvoke(promises.resolve()); } }))); } if (fileName.endsWith("." + DMNImportTypes.PMML.getFileExtension())) { return dmnImportsContentService.getPMMLDocumentMetadata(file) .then(pmmlDocumentMetadata -> { int modelCount = pmmlDocumentMetadata.getModels() != null ? pmmlDocumentMetadata.getModels().size() : 0; models.add(new PMMLIncludedModel(fileName, "", fileName, DMNImportTypes.PMML.getDefaultNamespace(), modelCount)); return promises.resolve(); }); } return promises.reject("Error: " + fileName + " is an invalid file. Only *.dmn and *.pmml are supported"); }).then(v -> { callback.onSuccess(models); return promises.resolve(); })); }
DMNMarshallerImportsClientHelper implements DMNMarshallerImportsHelper<JSITImport, JSITDefinitions, JSITDRGElement, JSITItemDefinition> { public void loadModels(final ServiceCallback<List<IncludedModel>> callback) { final List<IncludedModel> models = new ArrayList<>(); dmnImportsContentService.getModelsURIs() .then(items -> promises.all(Arrays.asList(items), file -> { final String fileName = FileUtils.getFileName(file); if (fileName.endsWith("." + DMNImportTypes.DMN.getFileExtension())) { return dmnImportsContentService.loadFile(file) .then(fileContent -> promises.create((success, failed) -> dmnImportsService.getWbDefinitions(fileContent, new ServiceCallback<Definitions>() { @Override public void onSuccess(final Definitions definitions) { final String modelPackage = ""; final String namespace = definitions.getNamespace().getValue(); final String importType = DMNImportTypes.DMN.getDefaultNamespace(); final int drgElementCount = definitions.getDrgElement().size(); final int itemDefinitionCount = definitions.getItemDefinition().size(); models.add(new DMNIncludedModel(fileName, modelPackage, fileName, namespace, importType, drgElementCount, itemDefinitionCount)); success.onInvoke(promises.resolve()); } @Override public void onError(final ClientRuntimeError error) { success.onInvoke(promises.resolve()); } }))); } if (fileName.endsWith("." + DMNImportTypes.PMML.getFileExtension())) { return dmnImportsContentService.getPMMLDocumentMetadata(file) .then(pmmlDocumentMetadata -> { int modelCount = pmmlDocumentMetadata.getModels() != null ? pmmlDocumentMetadata.getModels().size() : 0; models.add(new PMMLIncludedModel(fileName, "", fileName, DMNImportTypes.PMML.getDefaultNamespace(), modelCount)); return promises.resolve(); }); } return promises.reject("Error: " + fileName + " is an invalid file. Only *.dmn and *.pmml are supported"); }).then(v -> { callback.onSuccess(models); return promises.resolve(); })); } }
DMNMarshallerImportsClientHelper implements DMNMarshallerImportsHelper<JSITImport, JSITDefinitions, JSITDRGElement, JSITItemDefinition> { public void loadModels(final ServiceCallback<List<IncludedModel>> callback) { final List<IncludedModel> models = new ArrayList<>(); dmnImportsContentService.getModelsURIs() .then(items -> promises.all(Arrays.asList(items), file -> { final String fileName = FileUtils.getFileName(file); if (fileName.endsWith("." + DMNImportTypes.DMN.getFileExtension())) { return dmnImportsContentService.loadFile(file) .then(fileContent -> promises.create((success, failed) -> dmnImportsService.getWbDefinitions(fileContent, new ServiceCallback<Definitions>() { @Override public void onSuccess(final Definitions definitions) { final String modelPackage = ""; final String namespace = definitions.getNamespace().getValue(); final String importType = DMNImportTypes.DMN.getDefaultNamespace(); final int drgElementCount = definitions.getDrgElement().size(); final int itemDefinitionCount = definitions.getItemDefinition().size(); models.add(new DMNIncludedModel(fileName, modelPackage, fileName, namespace, importType, drgElementCount, itemDefinitionCount)); success.onInvoke(promises.resolve()); } @Override public void onError(final ClientRuntimeError error) { success.onInvoke(promises.resolve()); } }))); } if (fileName.endsWith("." + DMNImportTypes.PMML.getFileExtension())) { return dmnImportsContentService.getPMMLDocumentMetadata(file) .then(pmmlDocumentMetadata -> { int modelCount = pmmlDocumentMetadata.getModels() != null ? pmmlDocumentMetadata.getModels().size() : 0; models.add(new PMMLIncludedModel(fileName, "", fileName, DMNImportTypes.PMML.getDefaultNamespace(), modelCount)); return promises.resolve(); }); } return promises.reject("Error: " + fileName + " is an invalid file. Only *.dmn and *.pmml are supported"); }).then(v -> { callback.onSuccess(models); return promises.resolve(); })); } @Inject  DMNMarshallerImportsClientHelper(final DMNMarshallerImportsService dmnImportsService,
                                            final DMNMarshallerImportsContentService dmnImportsContentService,
                                            final Promises promises,
                                            final DMNIncludedNodeFactory includedModelFactory); }
DMNMarshallerImportsClientHelper implements DMNMarshallerImportsHelper<JSITImport, JSITDefinitions, JSITDRGElement, JSITItemDefinition> { public void loadModels(final ServiceCallback<List<IncludedModel>> callback) { final List<IncludedModel> models = new ArrayList<>(); dmnImportsContentService.getModelsURIs() .then(items -> promises.all(Arrays.asList(items), file -> { final String fileName = FileUtils.getFileName(file); if (fileName.endsWith("." + DMNImportTypes.DMN.getFileExtension())) { return dmnImportsContentService.loadFile(file) .then(fileContent -> promises.create((success, failed) -> dmnImportsService.getWbDefinitions(fileContent, new ServiceCallback<Definitions>() { @Override public void onSuccess(final Definitions definitions) { final String modelPackage = ""; final String namespace = definitions.getNamespace().getValue(); final String importType = DMNImportTypes.DMN.getDefaultNamespace(); final int drgElementCount = definitions.getDrgElement().size(); final int itemDefinitionCount = definitions.getItemDefinition().size(); models.add(new DMNIncludedModel(fileName, modelPackage, fileName, namespace, importType, drgElementCount, itemDefinitionCount)); success.onInvoke(promises.resolve()); } @Override public void onError(final ClientRuntimeError error) { success.onInvoke(promises.resolve()); } }))); } if (fileName.endsWith("." + DMNImportTypes.PMML.getFileExtension())) { return dmnImportsContentService.getPMMLDocumentMetadata(file) .then(pmmlDocumentMetadata -> { int modelCount = pmmlDocumentMetadata.getModels() != null ? pmmlDocumentMetadata.getModels().size() : 0; models.add(new PMMLIncludedModel(fileName, "", fileName, DMNImportTypes.PMML.getDefaultNamespace(), modelCount)); return promises.resolve(); }); } return promises.reject("Error: " + fileName + " is an invalid file. Only *.dmn and *.pmml are supported"); }).then(v -> { callback.onSuccess(models); return promises.resolve(); })); } @Inject  DMNMarshallerImportsClientHelper(final DMNMarshallerImportsService dmnImportsService,
                                            final DMNMarshallerImportsContentService dmnImportsContentService,
                                            final Promises promises,
                                            final DMNIncludedNodeFactory includedModelFactory); Promise<Map<JSITImport, JSITDefinitions>> getImportDefinitionsAsync(final Metadata metadata,
                                                                               final List<JSITImport> imports); void loadNodesFromModels(final List<DMNIncludedModel> includedModels,
                                    final ServiceCallback<List<DMNIncludedNode>> callback); void loadModels(final ServiceCallback<List<IncludedModel>> callback); Promise<Map<JSITImport, PMMLDocumentMetadata>> getPMMLDocumentsAsync(final Metadata metadata,
                                                                                final List<JSITImport> imports); @Override Map<JSITImport, String> getImportXML(final Metadata metadata,
                                                final List<JSITImport> imports); @Override List<JSITDRGElement> getImportedDRGElements(final Map<JSITImport, JSITDefinitions> importDefinitions); @Override List<JSITItemDefinition> getImportedItemDefinitions(final Map<JSITImport, JSITDefinitions> importDefinitions); void getPMMLDocumentsMetadataFromFiles(final List<PMMLIncludedModel> includedModels,
                                                  final ServiceCallback<List<PMMLDocumentMetadata>> callback); void getImportedItemDefinitionsByNamespaceAsync(final String modelName,
                                                           final String namespace,
                                                           final ServiceCallback<List<ItemDefinition>> callback); }
DMNMarshallerImportsClientHelper implements DMNMarshallerImportsHelper<JSITImport, JSITDefinitions, JSITDRGElement, JSITItemDefinition> { public void loadModels(final ServiceCallback<List<IncludedModel>> callback) { final List<IncludedModel> models = new ArrayList<>(); dmnImportsContentService.getModelsURIs() .then(items -> promises.all(Arrays.asList(items), file -> { final String fileName = FileUtils.getFileName(file); if (fileName.endsWith("." + DMNImportTypes.DMN.getFileExtension())) { return dmnImportsContentService.loadFile(file) .then(fileContent -> promises.create((success, failed) -> dmnImportsService.getWbDefinitions(fileContent, new ServiceCallback<Definitions>() { @Override public void onSuccess(final Definitions definitions) { final String modelPackage = ""; final String namespace = definitions.getNamespace().getValue(); final String importType = DMNImportTypes.DMN.getDefaultNamespace(); final int drgElementCount = definitions.getDrgElement().size(); final int itemDefinitionCount = definitions.getItemDefinition().size(); models.add(new DMNIncludedModel(fileName, modelPackage, fileName, namespace, importType, drgElementCount, itemDefinitionCount)); success.onInvoke(promises.resolve()); } @Override public void onError(final ClientRuntimeError error) { success.onInvoke(promises.resolve()); } }))); } if (fileName.endsWith("." + DMNImportTypes.PMML.getFileExtension())) { return dmnImportsContentService.getPMMLDocumentMetadata(file) .then(pmmlDocumentMetadata -> { int modelCount = pmmlDocumentMetadata.getModels() != null ? pmmlDocumentMetadata.getModels().size() : 0; models.add(new PMMLIncludedModel(fileName, "", fileName, DMNImportTypes.PMML.getDefaultNamespace(), modelCount)); return promises.resolve(); }); } return promises.reject("Error: " + fileName + " is an invalid file. Only *.dmn and *.pmml are supported"); }).then(v -> { callback.onSuccess(models); return promises.resolve(); })); } @Inject  DMNMarshallerImportsClientHelper(final DMNMarshallerImportsService dmnImportsService,
                                            final DMNMarshallerImportsContentService dmnImportsContentService,
                                            final Promises promises,
                                            final DMNIncludedNodeFactory includedModelFactory); Promise<Map<JSITImport, JSITDefinitions>> getImportDefinitionsAsync(final Metadata metadata,
                                                                               final List<JSITImport> imports); void loadNodesFromModels(final List<DMNIncludedModel> includedModels,
                                    final ServiceCallback<List<DMNIncludedNode>> callback); void loadModels(final ServiceCallback<List<IncludedModel>> callback); Promise<Map<JSITImport, PMMLDocumentMetadata>> getPMMLDocumentsAsync(final Metadata metadata,
                                                                                final List<JSITImport> imports); @Override Map<JSITImport, String> getImportXML(final Metadata metadata,
                                                final List<JSITImport> imports); @Override List<JSITDRGElement> getImportedDRGElements(final Map<JSITImport, JSITDefinitions> importDefinitions); @Override List<JSITItemDefinition> getImportedItemDefinitions(final Map<JSITImport, JSITDefinitions> importDefinitions); void getPMMLDocumentsMetadataFromFiles(final List<PMMLIncludedModel> includedModels,
                                                  final ServiceCallback<List<PMMLDocumentMetadata>> callback); void getImportedItemDefinitionsByNamespaceAsync(final String modelName,
                                                           final String namespace,
                                                           final ServiceCallback<List<ItemDefinition>> callback);  }