use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class MappingModelParser method getReferences.
/**
* Adds inherited types of references
* Why? Because mapping models can also define mapping rules of Function Blocks / or Entities for inherited properties
*/
@Override
protected Collection<ModelId> getReferences(Model model) {
List<ModelId> result = new ArrayList<>();
model.getReferences().stream().map(modelRef -> ModelId.fromReference(modelRef.getImportedNamespace(), modelRef.getVersion())).collect(Collectors.toList()).stream().forEach(modelId -> {
result.add(modelId);
ModelInfo _model = this.modelRepoFactory.getRepositoryByModel(modelId).getById(modelId);
if (_model != null) {
result.addAll(_model.getReferences());
}
});
return result;
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelReferencesHelper method addModelReference.
public void addModelReference(ModelReference reference) {
ModelId modelId = ModelId.fromReference(reference.getImportedNamespace(), reference.getVersion());
references.add(modelId);
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class BulkModelReferencesValidation method validateInZipFiles.
private void validateInZipFiles(ModelInfo modelResource, InvocationContext context) {
List<ModelId> references = modelResource.getReferences();
List<ModelId> missingReferences = new ArrayList<ModelId>();
for (ModelId modelId : references) {
if (!zipModelIds.contains(modelId) && isNotInRepository(modelId, context.getUserContext())) {
missingReferences.add(modelId);
}
}
if (missingReferences.size() > 0)
throw new CouldNotResolveReferenceException(modelResource, missingReferences);
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class ModelIdToModelContentConverter method convert.
@Override
public ModelContent convert(ModelId modelId, Optional<String> platformKey) {
modelId = repositoryFactory.getRepositoryByNamespace(modelId.getNamespace()).getLatestModelVersionIfLatestTagIsSet(modelId);
if (!repositoryFactory.getRepositoryByModel(modelId).exists(modelId)) {
throw new ModelNotFoundException(String.format("Model [%s] does not exist", modelId.getPrettyFormat()), null);
}
ModelWorkspaceReader workspaceReader = getWorkspaceForModel(modelId);
ModelContent result = new ModelContent();
result.setRoot(modelId);
if (platformKey.isPresent()) {
final List<ModelInfo> mappingResources = repositoryFactory.getRepositoryByModel(modelId).getMappingModelsForTargetPlatform(modelId, platformKey.get(), Optional.empty());
if (!mappingResources.isEmpty()) {
// adding to workspace reader in order to resolve cross linking between mapping models correctly
mappingResources.forEach(mapping -> workspaceReader.addFile(new ByteArrayInputStream(repositoryFactory.getRepositoryByModel(mapping.getId()).getFileContent(mapping.getId(), Optional.empty()).get().getContent()), org.eclipse.vorto.model.ModelType.Mapping));
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
Optional<MappingModel> mappingModel = getMappingModelForModel(mappingResources, model);
if (mappingModel.isPresent()) {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), mappingModel);
createdModel.setTargetPlatformKey(platformKey.get());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
} else {
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty()));
}
});
} else {
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty());
createdModel.setTargetPlatformKey(platformKey.get());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
});
}
} else {
final IModelWorkspace workspace = workspaceReader.read();
workspace.get().forEach(model -> {
AbstractModel createdModel = ModelDtoFactory.createResource(flattenHierarchy(model), Optional.empty());
result.getModels().put(new ModelId(model.getName(), model.getNamespace(), model.getVersion()), createdModel);
});
}
return result;
}
use of org.eclipse.vorto.model.ModelId in project vorto by eclipse.
the class MappingSpecificationSerializer method iterator.
public Iterator<IMappingSerializer> iterator() {
ModelId rootMappingId = MappingIdUtils.getIdForInfoModel(specification.getInfoModel());
List<IMappingSerializer> serializers = new ArrayList<IMappingSerializer>();
for (ModelProperty fbProperty : specification.getInfoModel().getFunctionblocks()) {
FunctionblockModel fbm = specification.getFunctionBlock(fbProperty.getName());
ModelId mappingId = MappingIdUtils.getIdForProperty(rootMappingId, fbProperty);
addSerializerRecursive(mappingId, fbm, fbm.getProperties(), serializers);
serializers.add(new FunctionblockMappingSerializer(specification, mappingId, targetPlatform, fbProperty.getName()));
}
serializers.add(new InformationModelMappingSerializer(specification, rootMappingId, targetPlatform));
return serializers.iterator();
}
Aggregations