use of org.eclipse.vorto.repository.web.core.templates.InfomodelTemplate in project vorto by eclipse.
the class ModelRepositoryController method createModel.
@ApiOperation(value = "Creates a model in the repository with the given model ID and model type.")
@PostMapping(value = "/{modelId:.+}/{modelType}", produces = "application/json")
public ResponseEntity<ModelInfo> createModel(@ApiParam(value = "modelId", required = true) @PathVariable String modelId, @ApiParam(value = "modelType", required = true) @PathVariable ModelType modelType, @RequestBody(required = false) List<ModelProperty> properties) throws WorkflowException {
final ModelId modelID = ModelId.fromPrettyFormat(modelId);
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
IUserContext userContext = UserContext.user(authentication, getWorkspaceId(modelId));
IModelRepository modelRepo = getModelRepository(modelID);
if (modelRepo.exists(modelID)) {
throw new ModelAlreadyExistsException();
} else {
String modelTemplate = null;
if (modelType == ModelType.InformationModel && properties != null) {
modelTemplate = new InfomodelTemplate().createModelTemplate(modelID, properties);
} else {
modelTemplate = new ModelTemplate().createModelTemplate(modelID, modelType);
}
ModelInfo savedModel = modelRepo.save(modelID, modelTemplate.getBytes(), modelID.getName() + modelType.getExtension(), userContext);
this.workflowService.start(modelID, userContext);
return new ResponseEntity<>(savedModel, HttpStatus.CREATED);
}
}
Aggregations