Search in sources :

Example 66 with ModelId

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;
}
Also used : Injector(com.google.inject.Injector) List(java.util.List) Collection(java.util.Collection) MappingStandaloneSetup(org.eclipse.vorto.editor.mapping.MappingStandaloneSetup) Collectors(java.util.stream.Collectors) ModelId(org.eclipse.vorto.model.ModelId) IModelRepositoryFactory(org.eclipse.vorto.repository.core.IModelRepositoryFactory) ArrayList(java.util.ArrayList) Model(org.eclipse.vorto.core.api.model.model.Model) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ArrayList(java.util.ArrayList) ModelId(org.eclipse.vorto.model.ModelId)

Example 67 with ModelId

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);
}
Also used : ModelId(org.eclipse.vorto.model.ModelId)

Example 68 with 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);
}
Also used : ArrayList(java.util.ArrayList) ModelId(org.eclipse.vorto.model.ModelId)

Example 69 with ModelId

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;
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelContent(org.eclipse.vorto.model.ModelContent) AbstractModel(org.eclipse.vorto.model.AbstractModel) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) ModelId(org.eclipse.vorto.model.ModelId)

Example 70 with ModelId

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();
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) ArrayList(java.util.ArrayList) ModelProperty(org.eclipse.vorto.model.ModelProperty) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

ModelId (org.eclipse.vorto.model.ModelId)124 Test (org.junit.Test)48 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)29 IOException (java.io.IOException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)19 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ResponseEntity (org.springframework.http.ResponseEntity)14 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)13 ModelType (org.eclipse.vorto.model.ModelType)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 Optional (java.util.Optional)10 List (java.util.List)9 IOUtils (org.apache.commons.io.IOUtils)9 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)9 ModelLink (org.eclipse.vorto.repository.web.api.v1.dto.ModelLink)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ApiOperation (io.swagger.annotations.ApiOperation)8