use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ModelRepositoryController method getModelsAndDependencies.
private Map<ModelInfo, FileContent> getModelsAndDependencies(Collection<ModelId> modelIds) {
Map<ModelInfo, FileContent> modelsMap = new HashMap<>();
if (modelIds != null && !modelIds.isEmpty()) {
for (ModelId modelId : modelIds) {
IModelRepository modelRepo = getModelRepository(modelId);
ModelInfo modelInfo = modelRepo.getById(modelId);
Optional<FileContent> modelContent = modelRepo.getFileContent(modelId, Optional.empty());
if (modelContent.isPresent()) {
modelsMap.put(modelInfo, modelContent.get());
modelsMap.putAll(getModelsAndDependencies(modelInfo.getReferences()));
}
}
}
return modelsMap;
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class AbstractRepositoryController method addModelToZip.
protected void addModelToZip(ZipOutputStream zipOutputStream, ModelId modelId) throws Exception {
try {
FileContent modelFile = getModelRepository(modelId).getFileContent(modelId, Optional.empty()).get();
ModelInfo modelResource = getModelRepository(modelId).getById(modelId);
try {
ZipEntry zipEntry = new ZipEntry(modelResource.getId().getPrettyFormat() + modelResource.getType().getExtension());
zipOutputStream.putNextEntry(zipEntry);
zipOutputStream.write(modelFile.getContent());
zipOutputStream.closeEntry();
} catch (Exception ex) {
// entry possible exists already, so skipping TODO: ugly hack!!
}
for (ModelId reference : modelResource.getReferences()) {
addModelToZip(zipOutputStream, reference);
}
} catch (NotAuthorizedException notAuthorized) {
return;
}
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class TargetPlatformUpgradeTask method doUpgrade.
@Override
public void doUpgrade() throws UpgradeProblem {
setAdminUserContext();
List<ModelInfo> searchResult = modelSearchService.search("type:Mapping");
for (ModelInfo modelInfo : searchResult) {
logger.info("Upgrading " + modelInfo.toString() + " for target platform key attribute....");
ModelRepository modelRepository = (ModelRepository) repositoryFactory.getRepositoryByModel(modelInfo.getId());
ModelResource mappingModel = modelRepository.getEMFResource(modelInfo.getId());
modelRepository.save(mappingModel, UserContext.user(modelInfo.getAuthor(), modelRepository.getWorkspaceId()));
}
}
use of org.eclipse.vorto.repository.core.ModelInfo in project vorto by eclipse.
the class ImportController method doImport.
@RequestMapping(value = "/{handleId:.+}", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('model_creator')")
public ResponseEntity<List<ModelInfo>> doImport(@ApiParam(value = "The file name of uploaded model", required = true) @PathVariable final String handleId, @RequestParam("key") String key, @RequestParam(required = true, value = "targetNamespace") String targetNamespace) {
LOGGER.info(String.format("Importing Model with handleID %s", handleId));
try {
IModelImporter importer = importerService.getImporterByKey(key).get();
List<ModelInfo> importedModels = importer.doImport(handleId, Context.create(getUserContext(targetNamespace), Optional.of(targetNamespace)));
for (ModelInfo modelInfo : importedModels) {
workflowService.start(modelInfo.getId(), getUserContext(targetNamespace));
}
return new ResponseEntity<>(importedModels, HttpStatus.OK);
} catch (Exception e) {
LOGGER.error(String.format("Error Importing model. %s", handleId), e);
throw new IllegalArgumentException(String.format("Could not import with handle ID %s", handleId), e);
}
}
Aggregations