use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.
the class ModelRepositoryController method makeModelPublic.
@PreAuthorize("isAuthenticated()")
@PostMapping(value = "/{modelId:.+}/makePublic", produces = "application/json")
public ResponseEntity<Status> makeModelPublic(@PathVariable final String modelId) {
IUserContext user = UserContext.user(SecurityContextHolder.getContext().getAuthentication(), getWorkspaceId(ControllerUtils.sanitize(modelId)));
ModelId modelID = ModelId.fromPrettyFormat(modelId);
try {
if (!userRepositoryRoleService.isSysadmin(user.getUsername()) && !userNamespaceRoleService.hasRole(user.getUsername(), modelID.getNamespace(), "model_publisher")) {
return new ResponseEntity<>(Status.fail("Only users with Publisher roles are allowed to make models public"), HttpStatus.UNAUTHORIZED);
}
} catch (DoesNotExistException dnee) {
return new ResponseEntity<>(Status.fail(dnee.getMessage()), HttpStatus.NOT_FOUND);
}
if (modelID.getNamespace().startsWith(Namespace.PRIVATE_NAMESPACE_PREFIX)) {
return new ResponseEntity<>(Status.fail("Only models with official namespace can be made public"), HttpStatus.FORBIDDEN);
}
try {
LOGGER.info("Making the model '" + ControllerUtils.sanitize(modelId) + "' public.");
modelService.makeModelPublic(ModelId.fromPrettyFormat(ControllerUtils.sanitize(modelId)));
} catch (ModelNotReleasedException | ModelNamespaceNotOfficialException e) {
return new ResponseEntity<>(Status.fail(e.getMessage()), HttpStatus.FORBIDDEN);
}
return new ResponseEntity<>(Status.success(), HttpStatus.OK);
}
use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.
the class ModelRepositoryController method refactorModelId.
@PutMapping(value = "/refactorings/{oldId:.+}/{newId:.+}", produces = "application/json")
@PreAuthorize("hasAuthority('sysadmin') or " + "hasPermission(T(org.eclipse.vorto.model.ModelId).fromPrettyFormat(#oldId)," + "T(org.eclipse.vorto.repository.core.PolicyEntry.Permission).MODIFY)")
public ResponseEntity<ModelInfo> refactorModelId(@PathVariable String oldId, @PathVariable String newId) {
final ModelId oldModelId = ModelId.fromPrettyFormat(oldId);
final ModelId newModelId = ModelId.fromPrettyFormat(newId);
IUserContext userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication(), getWorkspaceId(oldId));
ModelInfo result = this.modelRepositoryFactory.getRepositoryByModel(oldModelId).rename(oldModelId, newModelId, userContext);
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of org.eclipse.vorto.repository.core.IUserContext 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);
}
}
use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.
the class PayloadMappingController method saveMappingSpecification.
@PutMapping(value = "/{modelId:.+}")
@PreAuthorize("hasAuthority('model_creator')")
public void saveMappingSpecification(@RequestBody MappingSpecification mappingSpecification, @PathVariable String modelId) {
try {
String namespaceName = ModelId.fromPrettyFormat(modelId).getNamespace();
Namespace namespace = namespaceService.getByName(namespaceName);
if (null == namespace) {
LOGGER.error(String.format("Namespace [%s] not found", namespaceName));
return;
}
IUserContext userContext;
if (namespace != null) {
userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication(), namespace.getWorkspaceId());
} else {
userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication());
}
this.mappingService.saveSpecification(mappingSpecification, userContext);
} catch (DoesNotExistException dnee) {
LOGGER.error(dnee);
}
}
use of org.eclipse.vorto.repository.core.IUserContext in project vorto by eclipse.
the class ModelRepositoryEventListener method createWorkspace.
private void createWorkspace(AppEvent event) {
IUserContext userContext = event.getUserContext();
IRepositoryManager repoMgr = repositoryFactory.getRepositoryManager(userContext.getWorkspaceId(), userContext.getAuthentication());
repoMgr.createWorkspace(userContext.getWorkspaceId());
}
Aggregations