use of org.eclipse.vorto.repository.importer.IModelImporter in project vorto by eclipse.
the class ImportController method uploadModel.
@RequestMapping(method = RequestMethod.POST)
@PreAuthorize("hasAuthority('model_creator')")
public ResponseEntity<UploadModelResult> uploadModel(@ApiParam(value = "The vorto model file to upload", required = true) @RequestParam("file") MultipartFile file, @RequestParam("key") String key, @RequestParam(required = true, value = "targetNamespace") String targetNamespace) {
if (file.getSize() > maxModelSize) {
throw new UploadTooLargeException("model", maxModelSize);
}
LOGGER.info(String.format("uploadModel: [%s]", file.getOriginalFilename()));
try {
IModelImporter importer = importerService.getImporterByKey(key).get();
UploadModelResult result = importer.upload(FileUpload.create(file.getOriginalFilename(), file.getBytes()), Context.create(getUserContext(targetNamespace), Optional.of(targetNamespace)));
if (!result.isValid()) {
result.setMessage(String.format(UPLOAD_FAIL, file.getOriginalFilename()));
} else {
if (result.hasWarnings()) {
result.setMessage(String.format(UPLOAD_WARNING, file.getOriginalFilename()));
} else {
result.setMessage(String.format(UPLOAD_VALID, file.getOriginalFilename()));
}
}
return new ResponseEntity<>(result, HttpStatus.OK);
} catch (IOException e) {
return new ResponseEntity<>(new UploadModelResult(null, e.getMessage(), Collections.emptyList()), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.eclipse.vorto.repository.importer.IModelImporter 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