use of org.eclipse.vorto.repository.core.ModelInfo 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.repository.core.ModelInfo in project vorto by eclipse.
the class AbstractModelImporter method sortAndSaveToRepository.
private List<ModelInfo> sortAndSaveToRepository(List<ModelResource> resources, FileUpload extractedFile, Context context) {
final IUserContext user = context.getUser();
List<ModelInfo> savedModels = new ArrayList<>();
DependencyManager dm = new DependencyManager();
for (ModelResource resource : resources) {
dm.addResource(resource);
}
dm.getSorted().forEach(resource -> {
try {
IModelRepository modelRepository = modelRepoFactory.getRepositoryByModel(resource.getId());
ModelInfo importedModel = modelRepository.save((ModelResource) resource, user);
savedModels.add(importedModel);
postProcessImportedModel(importedModel, new FileContent(extractedFile.getFileName(), extractedFile.getContent()), user);
} catch (Exception e) {
logger.error("Problem importing model", e);
throw new ModelImporterException("Problem importing model", e);
}
});
return savedModels;
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class AbstractModelImporter method doImport.
@Override
public List<ModelInfo> doImport(String uploadHandleId, Context context) {
StorageItem uploadedItem = this.uploadStorage.get(uploadHandleId);
if (uploadedItem == null) {
throw new ModelImporterException(String.format("No uploaded file found for handleId '%s'", uploadHandleId));
}
List<ModelInfo> importedModels = new ArrayList<>();
try {
if (handleZipUploads() && isZipFile(uploadedItem.getValue())) {
getUploadedFilesFromZip(uploadedItem.getValue().getContent()).stream().forEach(extractedFile -> {
List<ModelResource> resources = this.convert(extractedFile, context);
importedModels.addAll(sortAndSaveToRepository(resources, extractedFile, context));
});
} else {
List<ModelResource> resources = this.convert(uploadedItem.getValue(), context);
importedModels.addAll(sortAndSaveToRepository(resources, uploadedItem.getValue(), context));
}
} finally {
this.uploadStorage.remove(uploadHandleId);
}
return importedModels;
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ElasticSearchService method fromSearchHit.
private ModelInfo fromSearchHit(SearchHit searchHit) {
ModelInfo modelInfo = new ModelInfo();
Map<String, Object> sourceAsMap = searchHit.getSourceAsMap();
modelInfo.setId(ModelId.fromPrettyFormat((String) sourceAsMap.get(BasicIndexFieldExtractor.MODEL_ID)));
modelInfo.setType(ModelType.valueOf((String) sourceAsMap.get(BasicIndexFieldExtractor.MODEL_TYPE)));
modelInfo.setState((String) sourceAsMap.get(BasicIndexFieldExtractor.STATE));
modelInfo.setVisibility((String) sourceAsMap.get(BasicIndexFieldExtractor.VISIBILITY));
modelInfo.setAuthor((String) sourceAsMap.get(BasicIndexFieldExtractor.AUTHOR));
modelInfo.setDescription((String) sourceAsMap.get(BasicIndexFieldExtractor.DESCRIPTION));
modelInfo.setDisplayName((String) sourceAsMap.get(BasicIndexFieldExtractor.DISPLAY_NAME));
modelInfo.setHasImage(Boolean.parseBoolean((String) sourceAsMap.get(BasicIndexFieldExtractor.MODEL_HASIMAGE)));
String createdOn = (String) sourceAsMap.get(BasicIndexFieldExtractor.MODEL_CREATIONDATE);
modelInfo.setCreationDate(new Date(Long.parseLong(createdOn)));
return modelInfo;
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ElasticSearchService method reindexAllModels.
@Override
public IndexingResult reindexAllModels() {
IndexingResult result = new IndexingResult();
// (1) Delete all models in the index
deleteAllModels(VORTO_INDEX);
// (2) Index all models in all the tenants
namespaceRepository.findAll().stream().forEach(namespace -> {
IModelRepository repo = this.repositoryFactory.getRepository(namespace.getWorkspaceId());
List<ModelInfo> modelsToIndex = repo.search("");
if (!modelsToIndex.isEmpty()) {
BulkRequest bulkRequest = new BulkRequest();
modelsToIndex.forEach(model -> {
bulkRequest.add(createIndexRequest(model, repo.getWorkspaceId()));
});
try {
BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);
// temporary fix: getting namespace name instead of tenant ID here
// in the long run, once the tenant service is gone we can normalize
result.addIndexedNamespace(namespace.getName(), modelsToIndex.size());
logger.info(String.format("Received %d replies for workspace '%s' with %d models", bulkResponse.getItems().length, repo.getWorkspaceId(), modelsToIndex.size()));
} catch (IOException e) {
throw new IndexingException(String.format("Error trying to index all models in '%s' workspace.", repo.getWorkspaceId()), e);
}
}
});
return result;
}
Aggregations