Search in sources :

Example 1 with Comment

use of org.eclipse.vorto.repository.domain.Comment in project vorto by eclipse.

the class CommentController method getCommentsforModelId.

@RequestMapping(method = RequestMethod.GET, value = "/{modelId:.+}", produces = "application/json")
@PreAuthorize("hasAuthority('model_viewer')")
public List<Comment> getCommentsforModelId(@ApiParam(value = "modelId", required = true) @PathVariable String modelId) {
    final ModelId modelID = ModelId.fromPrettyFormat(modelId);
    Optional<String> maybeWorkspaceId = namespaceService.resolveWorkspaceIdForNamespace(modelID.getNamespace());
    if (!maybeWorkspaceId.isPresent()) {
        LOGGER.error(String.format("Namespace [%s] does not exist.", modelID.getNamespace()));
        return Collections.emptyList();
    }
    return commentService.getCommentsforModelId(modelID).stream().map(comment -> ModelDtoFactory.createDto(comment, UserContext.user(SecurityContextHolder.getContext().getAuthentication().getName(), maybeWorkspaceId.get()))).collect(Collectors.toList());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) DoesNotExistException(org.eclipse.vorto.repository.services.exceptions.DoesNotExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Valid(javax.validation.Valid) RequestBody(org.springframework.web.bind.annotation.RequestBody) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Logger(org.slf4j.Logger) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ICommentService(org.eclipse.vorto.repository.comment.ICommentService) ModelDtoFactory(org.eclipse.vorto.repository.web.core.ModelDtoFactory) Collectors(java.util.stream.Collectors) ModelId(org.eclipse.vorto.model.ModelId) RestController(org.springframework.web.bind.annotation.RestController) NamespaceService(org.eclipse.vorto.repository.services.NamespaceService) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) Comment(org.eclipse.vorto.repository.domain.Comment) Collections(java.util.Collections) UserContext(org.eclipse.vorto.repository.core.impl.UserContext) ModelId(org.eclipse.vorto.model.ModelId) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Comment

use of org.eclipse.vorto.repository.domain.Comment in project vorto by eclipse.

the class ModelDtoFactoryTest method testCreateComment.

@Test
public void testCreateComment() {
    Comment comment = new Comment(ModelId.fromReference("org.eclipse.vorto.examples.type.Color", "1.0.0"), "erle", "test comment");
    Comment dto = ModelDtoFactory.createDto(comment, UserContext.user("anon", "playground"));
    assertEquals("erle", dto.getAuthor());
}
Also used : Comment(org.eclipse.vorto.repository.domain.Comment) Test(org.junit.Test)

Example 3 with Comment

use of org.eclipse.vorto.repository.domain.Comment in project vorto by eclipse.

the class DefaultCommentService method notifyAllCommentAuthors.

private void notifyAllCommentAuthors(Comment comment, ModelInfo model) {
    Set<String> recipients = new HashSet<>();
    recipients.add(model.getAuthor());
    List<Comment> existingComments = this.commentRepository.findByModelId(comment.getModelId());
    for (Comment c : existingComments) {
        recipients.add(c.getAuthor());
    }
    recipients.stream().filter(recipient -> !User.USER_ANONYMOUS.equalsIgnoreCase(recipient)).forEach(recipient -> {
        User user = accountService.getUser(recipient);
        if (user != null) {
            notificationService.sendNotification(new CommentReplyMessage(user, model, comment.getContent()));
        }
    });
}
Also used : DoesNotExistException(org.eclipse.vorto.repository.services.exceptions.DoesNotExistException) Date(java.util.Date) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) ICommentService(org.eclipse.vorto.repository.comment.ICommentService) User(org.eclipse.vorto.repository.domain.User) ModelId(org.eclipse.vorto.model.ModelId) IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) NamespaceService(org.eclipse.vorto.repository.services.NamespaceService) HashSet(java.util.HashSet) CommentReplyMessage(org.eclipse.vorto.repository.notification.message.CommentReplyMessage) List(java.util.List) PathNotFoundException(javax.jcr.PathNotFoundException) ModelRepositoryFactory(org.eclipse.vorto.repository.core.impl.ModelRepositoryFactory) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) INotificationService(org.eclipse.vorto.repository.notification.INotificationService) DefaultUserAccountService(org.eclipse.vorto.repository.account.impl.DefaultUserAccountService) Comment(org.eclipse.vorto.repository.domain.Comment) IModelRepositoryFactory(org.eclipse.vorto.repository.core.IModelRepositoryFactory) Comment(org.eclipse.vorto.repository.domain.Comment) User(org.eclipse.vorto.repository.domain.User) CommentReplyMessage(org.eclipse.vorto.repository.notification.message.CommentReplyMessage) HashSet(java.util.HashSet)

Aggregations

Comment (org.eclipse.vorto.repository.domain.Comment)3 List (java.util.List)2 Optional (java.util.Optional)2 ModelId (org.eclipse.vorto.model.ModelId)2 ICommentService (org.eclipse.vorto.repository.comment.ICommentService)2 NamespaceService (org.eclipse.vorto.repository.services.NamespaceService)2 DoesNotExistException (org.eclipse.vorto.repository.services.exceptions.DoesNotExistException)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ApiParam (io.swagger.annotations.ApiParam)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 Valid (javax.validation.Valid)1 DefaultUserAccountService (org.eclipse.vorto.repository.account.impl.DefaultUserAccountService)1 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)1 IModelRepositoryFactory (org.eclipse.vorto.repository.core.IModelRepositoryFactory)1 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)1