Search in sources :

Example 46 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class IndexingEventListener method onApplicationEvent.

@Override
public void onApplicationEvent(AppEvent event) {
    if (event.getEventType() == EventType.MODEL_CREATED) {
        ModelInfo modelInfo = (ModelInfo) event.getSubject();
        indexingService.indexModel(modelInfo, event.getUserContext().getWorkspaceId());
    } else if (event.getEventType() == EventType.MODEL_UPDATED) {
        ModelInfo modelInfo = (ModelInfo) event.getSubject();
        indexingService.updateIndex(modelInfo);
    } else if (event.getEventType() == EventType.MODEL_DELETED) {
        ModelId modelId = (ModelId) event.getSubject();
        indexingService.deleteIndex(modelId);
    } else if (event.getEventType() == EventType.NAMESPACE_DELETED) {
        indexingService.deleteIndexForWorkspace(event.getUserContext().getWorkspaceId());
    }
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelId(org.eclipse.vorto.model.ModelId)

Example 47 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class DefaultPayloadMappingService method getWorkspaceForModel.

private IModelWorkspace getWorkspaceForModel(final ModelId modelId) {
    List<ModelInfo> allModels = getModelWithAllDependencies(modelId);
    DependencyManager dm = new DependencyManager(new HashSet<>(allModels));
    allModels = dm.getSorted();
    ModelWorkspaceReader workspaceReader = IModelWorkspace.newReader();
    for (ModelInfo model : allModels) {
        FileContent modelContent = this.modelRepositoryFactory.getRepositoryByModel(model.getId()).getFileContent(model.getId(), Optional.of(model.getFileName())).get();
        workspaceReader.addFile(new ByteArrayInputStream(modelContent.getContent()), model.getType());
    }
    return workspaceReader.read();
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) ByteArrayInputStream(java.io.ByteArrayInputStream) DependencyManager(org.eclipse.vorto.repository.core.impl.utils.DependencyManager)

Example 48 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class DefaultPayloadMappingService method getModelContentByModelAndMappingId.

private IModel getModelContentByModelAndMappingId(final String _modelId, @PathVariable final String mappingId) {
    final ModelId modelId = ModelId.fromPrettyFormat(_modelId);
    final ModelId mappingModelId = ModelId.fromPrettyFormat(mappingId);
    IModelRepository repository = this.modelRepositoryFactory.getRepositoryByModel(modelId);
    ModelInfo vortoModelInfo = repository.getById(modelId);
    ModelInfo mappingModelInfo = this.modelRepositoryFactory.getRepositoryByModel(mappingModelId).getById(mappingModelId);
    if (vortoModelInfo == null) {
        throw new ModelNotFoundException(String.format("Could not find vorto model with ID: %s", modelId));
    } else if (mappingModelInfo == null) {
        throw new ModelNotFoundException(String.format("Could not find mapping with ID: %s", mappingId));
    }
    IModelWorkspace mappingWorkspace = getWorkspaceForModel(mappingModelInfo.getId());
    Optional<Model> model = mappingWorkspace.get().stream().filter(_model -> ModelUtils.fromEMFModelId(ModelIdFactory.newInstance(_model)).equals(vortoModelInfo.getId())).findFirst();
    if (model.isPresent()) {
        final Model flattenedModel = ModelConversionUtils.convertToFlatHierarchy(model.get());
        return ModelDtoFactory.createResource(flattenedModel, Optional.of((MappingModel) mappingWorkspace.get().stream().filter(_model -> _model instanceof MappingModel && mappingMatchesModelId((MappingModel) _model, vortoModelInfo)).findFirst().get()));
    } else {
        return null;
    }
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) PathVariable(org.springframework.web.bind.annotation.PathVariable) ModelIdFactory(org.eclipse.vorto.core.api.model.model.ModelIdFactory) DependencyManager(org.eclipse.vorto.repository.core.impl.utils.DependencyManager) IPayloadMappingService(org.eclipse.vorto.repository.mapping.IPayloadMappingService) MappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.MappingSpecification) IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Infomodel(org.eclipse.vorto.model.Infomodel) ModelIdToModelContentConverter(org.eclipse.vorto.repository.conversion.ModelIdToModelContentConverter) ArrayList(java.util.ArrayList) ModelConversionUtils(org.eclipse.vorto.core.api.model.ModelConversionUtils) Model(org.eclipse.vorto.core.api.model.model.Model) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) IWorkflowService(org.eclipse.vorto.repository.workflow.IWorkflowService) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityModel(org.eclipse.vorto.model.EntityModel) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) Service(org.springframework.stereotype.Service) Map(java.util.Map) IModelRepositoryFactory(org.eclipse.vorto.repository.core.IModelRepositoryFactory) MappingSpecificationSerializer(org.eclipse.vorto.mapping.engine.serializer.MappingSpecificationSerializer) ModelProperty(org.eclipse.vorto.model.ModelProperty) IModel(org.eclipse.vorto.model.IModel) FileContent(org.eclipse.vorto.repository.core.FileContent) MappingEngine(org.eclipse.vorto.mapping.engine.MappingEngine) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) ModelDtoFactory(org.eclipse.vorto.repository.web.core.ModelDtoFactory) ModelId(org.eclipse.vorto.model.ModelId) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Stereotype(org.eclipse.vorto.model.Stereotype) List(java.util.List) ModelContent(org.eclipse.vorto.model.ModelContent) EnumModel(org.eclipse.vorto.model.EnumModel) ModelWorkspaceReader(org.eclipse.vorto.utilities.reader.ModelWorkspaceReader) Optional(java.util.Optional) ModelUtils(org.eclipse.vorto.repository.utils.ModelUtils) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Model(org.eclipse.vorto.core.api.model.model.Model) EntityModel(org.eclipse.vorto.model.EntityModel) IModel(org.eclipse.vorto.model.IModel) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) EnumModel(org.eclipse.vorto.model.EnumModel) ModelId(org.eclipse.vorto.model.ModelId) IModelWorkspace(org.eclipse.vorto.utilities.reader.IModelWorkspace) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 49 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class ModelRetrievalService method getModelsReferencing.

@Override
public Map<String, List<ModelInfo>> getModelsReferencing(ModelId modelId) {
    Map<String, List<ModelInfo>> modelReferencesMap = new HashMap<>();
    for (String tenant : tenantsSupplier.get()) {
        IModelRepository modelRepo = modelRepoSource.apply(tenant);
        List<ModelInfo> modelsReferencing = modelRepo.getModelsReferencing(modelId);
        if (modelsReferencing != null && !modelsReferencing.isEmpty()) {
            modelReferencesMap.put(tenant, modelsReferencing);
        }
    }
    return modelReferencesMap;
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) HashMap(java.util.HashMap) List(java.util.List)

Example 50 with ModelInfo

use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.

the class ModelSequencerOld method execute.

@Override
public boolean execute(Property inputProperty, Node outputNode, Context context) throws Exception {
    Binary binaryValue = inputProperty.getBinary();
    CheckArg.isNotNull(binaryValue, "binary");
    ModelInfo modelResource = null;
    try {
        IModelParser parser = ModelParserFactory.instance().getParser(outputNode.getPath());
        modelResource = parser.parse(binaryValue.getStream());
        outputNode.setProperty("vorto:description", modelResource.getDescription() != null ? modelResource.getDescription() : "");
        outputNode.setProperty("vorto:type", modelResource.getType().name());
        outputNode.setProperty("vorto:displayname", modelResource.getDisplayName());
        outputNode.setProperty("vorto:version", modelResource.getId().getVersion());
        outputNode.setProperty("vorto:namespace", modelResource.getId().getNamespace());
        outputNode.setProperty("vorto:name", modelResource.getId().getName());
        if (outputNode.hasProperty("vorto:references")) {
            // first remove any previous references of the node.
            outputNode.getProperty("vorto:references").remove();
            outputNode.getSession().save();
        }
        ModelReferencesHelper referencesHelper = new ModelReferencesHelper(modelResource.getReferences());
        if (referencesHelper.hasReferences()) {
            List<Value> references = new ArrayList<Value>();
            for (ModelId modelId : referencesHelper.getReferences()) {
                ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
                Node referencedFolder = outputNode.getSession().getNode(modelIdHelper.getFullPath());
                Node reference = referencedFolder.getNodes().nextNode();
                references.add(context.valueFactory().createValue(reference));
            }
            outputNode.setProperty("vorto:references", references.toArray(new Value[references.size()]));
        }
    } catch (Throwable couldNotParse) {
        outputNode.setProperty("vorto:description", "Erronous Model !!!!");
        outputNode.setProperty("vorto:type", ModelType.create(outputNode.getPath()).name());
        outputNode.setProperty("vorto:displayname", "");
        outputNode.setProperty("vorto:version", "1.0.0");
        outputNode.setProperty("vorto:namespace", "erronous");
        outputNode.setProperty("vorto:name", outputNode.getName());
    }
    return true;
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) IModelParser(org.eclipse.vorto.repository.core.impl.parser.IModelParser) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) ModelReferencesHelper(org.eclipse.vorto.repository.core.impl.utils.ModelReferencesHelper) Node(javax.jcr.Node) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) Binary(javax.jcr.Binary) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)89 Test (org.junit.Test)33 IUserContext (org.eclipse.vorto.repository.core.IUserContext)32 ModelId (org.eclipse.vorto.model.ModelId)28 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)21 FileContent (org.eclipse.vorto.repository.core.FileContent)11 ClassPathResource (org.springframework.core.io.ClassPathResource)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ModelNotFoundException (org.eclipse.vorto.repository.core.ModelNotFoundException)8 WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)8 BeforeClass (org.junit.BeforeClass)7 ResponseEntity (org.springframework.http.ResponseEntity)7 List (java.util.List)6 Optional (java.util.Optional)6 ModelAlreadyExistsException (org.eclipse.vorto.repository.core.ModelAlreadyExistsException)6 NotAuthorizedException (org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)6 DependencyManager (org.eclipse.vorto.repository.core.impl.utils.DependencyManager)5