use of org.eclipse.vorto.repository.services.exceptions.DoesNotExistException in project vorto by eclipse.
the class ModelRepositoryController method getUserModels.
// ##################### Downloads ################################
@GetMapping(value = { "/mine/download" })
public void getUserModels(Principal principal, final HttpServletResponse response) {
List<ModelId> userModels = Lists.newArrayList();
User user = accountService.getUser(principal.getName());
Collection<Namespace> namespaces = null;
try {
namespaces = userNamespaceRoleService.getNamespaces(user, user);
} catch (OperationForbiddenException | DoesNotExistException e) {
LOGGER.error(e.getMessage(), e);
}
for (Namespace namespace : namespaces) {
IModelRepository modelRepo = getModelRepository(namespace.getWorkspaceId());
List<ModelInfo> modelInfos = modelRepo.search(String.format("author:%s", user.getUsername()));
List<ModelId> modelIds = modelInfos.stream().map(modelInfo -> modelInfo.getId()).collect(Collectors.toList());
userModels.addAll(modelIds);
}
LOGGER.info("Exporting information models for user - results: " + userModels.size());
sendAsZipFile(response, user.getUsername() + "-models.zip", getModelsAndDependencies(userModels));
}
use of org.eclipse.vorto.repository.services.exceptions.DoesNotExistException 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.services.exceptions.DoesNotExistException 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.services.exceptions.DoesNotExistException in project vorto by eclipse.
the class NamespaceController method getCollaboratorsByNamespace.
/**
* @param namespace
* @return all users of a given namespace, if the user acting the call has either administrative rights on the namespace, or on the repository.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{namespace:.+}/users")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<Collection<Collaborator>> getCollaboratorsByNamespace(@ApiParam(value = "namespace", required = true) @PathVariable String namespace) {
Collection<Collaborator> collaborators = new HashSet<>();
try {
IUserContext userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication());
collaborators = EntityDTOConverter.createCollaborators(userNamespaceRoleService.getRolesByUser(userContext.getUsername(), namespace));
return new ResponseEntity<>(collaborators, HttpStatus.OK);
} catch (OperationForbiddenException ofe) {
return new ResponseEntity<>(collaborators, HttpStatus.FORBIDDEN);
} catch (DoesNotExistException d) {
return new ResponseEntity<>(collaborators, HttpStatus.NOT_FOUND);
}
}
use of org.eclipse.vorto.repository.services.exceptions.DoesNotExistException in project vorto by eclipse.
the class NamespaceController method getAllNamespacesForLoggedUser.
/**
* @return all namespaces the logged on user has access to.
*/
@RequestMapping(method = RequestMethod.GET, value = "/all")
@PreAuthorize("isAuthenticated()")
public ResponseEntity<Collection<NamespaceDto>> getAllNamespacesForLoggedUser() {
IUserContext userContext = UserContext.user(SecurityContextHolder.getContext().getAuthentication());
Collection<NamespaceDto> namespaces = new TreeSet<>(Comparator.comparing(NamespaceDto::getName));
try {
for (Map.Entry<Namespace, Map<User, Collection<IRole>>> entry : userNamespaceRoleService.getNamespacesCollaboratorsAndRoles(userContext.getUsername(), userContext.getUsername(), "namespace_admin").entrySet()) {
namespaces.add(EntityDTOConverter.createNamespaceDTO(entry.getKey(), entry.getValue()));
}
} catch (OperationForbiddenException ofe) {
return new ResponseEntity<>(namespaces, HttpStatus.FORBIDDEN);
} catch (DoesNotExistException d) {
return new ResponseEntity<>(namespaces, HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(namespaces, HttpStatus.OK);
}
Aggregations