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());
}
}
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();
}
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;
}
}
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;
}
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;
}
Aggregations