Package org.wso2.carbon.registry.core

Examples of org.wso2.carbon.registry.core.Comment


        Resource r1 = registry.newResource();
        r1.setProperty("test", "t2");
        r1.setContent("some content");
        registry.put("/t2/r1", r1);

        registry.addComment("/t2/r1", new Comment("this is a good one"));

        registry.rateResource("/t2/r1", 3);

        registry.applyTag("/t2/r1", "cool");
View Full Code Here


        Resource r1 = registry.newResource();
        r1.setProperty("test", "t2");
        r1.setContent("some content");
        registry.put("/t3/r1", r1);

        registry.addComment("/t3/r1", new Comment("this is a good one"));

        registry.rateResource("/t3/r1", 3);

        registry.applyTag("/t3/r1", "cool");
View Full Code Here

        r1.setProperty("test", "t2");
        r1.setContent("some content");
        registry.put("t2/r1", r1);

        registry.beginTransaction();
        registry.addComment("/t2/r1", new Comment("this is a good one"));

        registry.rateResource("/t2/r1", 3);
        registry.commitTransaction();

        registry.applyTag("/t2/r1", "cool");
View Full Code Here

        r1.setProperty("test", "t2");
        r1.setContent("some content");
        registry.put("/t32/r1", r1);
        registry.beginTransaction();

        registry.addComment("/t32/r1", new Comment("this is a good one"));

        registry.commitTransaction();
        registry.rateResource("/t32/r1", 3);

        registry.applyTag("/t32/r1", "cool");
View Full Code Here

            s.setInt(2, CurrentSession.getTenantId());
            s.setInt(3, CurrentSession.getTenantId());

            results = s.executeQuery();
            while (results.next()) {
                Comment comment = new Comment();
                comment.setText(results.getString(DatabaseConstants.COMMENT_TEXT_FIELD));
                comment.setUser(results.getString(DatabaseConstants.USER_ID_FIELD));
                comment.setCreatedTime(
                        results.getTimestamp(DatabaseConstants.COMMENTED_TIME_FIELD));
                comment.setResourcePath(path);
                String commentPath = path + RegistryConstants.URL_SEPARATOR + "comments:" +
                        results.getInt(DatabaseConstants.ID_FIELD);
                comment.setPath(commentPath);
                comment.setCommentPath(commentPath);
                comment.setParentPath(path + RegistryConstants.URL_SEPARATOR + "comments");
                comment.setCommentID(results.getLong(DatabaseConstants.ID_FIELD));
                commentList.add(comment);
            }

        } catch (SQLException e) {
View Full Code Here

        r2.setContent("r2 content");
        adminReg.put("/CRTest/r2", r2);

        String c1 =
                adminReg.addComment("/CRTest/r1",
                        new Comment("administrator's comment on /CRTest/r1"));
        assertTrue(adminRealm.getAuthorizationManager()
                .isUserAuthorized("cu1", "/CRTest/r1", ActionConstants.PUT));

        String c2 =
                adminReg.addComment("/CRTest/r2",
                        new Comment("administrator's comment on /CRTest/r2"));

        String c3 =
                cu1Reg.addComment("/CRTest/r1", new Comment("cu1's comment on /CRTest/r1"));

        String c4 =
                cu1Reg.addComment("/CRTest/r2", new Comment("cu1's comment on /CRTest/r2"));

        cu1Reg.delete(c1);

        boolean failed = false;
        try {
View Full Code Here

                // URL form, which contains strings after "comment".
                // it is just that it is not the URL we expect here
                return null;
            }

            Comment comment = commentsDAO.getComment(cID, resourcePath.getPath());

            if (comment == null) {
                String msg = "Requested comment with ID: " + cID + " is not available.";
                log.error(msg);
                throw new RegistryException(msg);
View Full Code Here

            String userID = CurrentSession.getUser();
            String authorizationPath =
                    AuthorizationUtils.getAuthorizationPath(resourcePath.getPath());
            String commentAuthor;

            Comment comment = commentsDAO.getComment(cID, resourcePath.getPath());
            commentAuthor = comment.getUser();

            // check if the current user has permission to delete this comment.
            // users who have PUT permission on the commented resource can delete any comment on
            // that resource. Any user can delete his own comment.
View Full Code Here

            // start the transaction
            beginTransaction();

            ResourcePath processedPath = new ResourcePath(commentPath);

            Comment comment = new Comment();
            comment.setCommentPath(commentPath);
            comment.setText(text);

            context.setResourcePath(processedPath);
            context.setComment(comment);
            context.setOldComments(getComments(commentPath));
            registryContext.getHandlerManager().editComment(context);
View Full Code Here

            // start the transaction
            beginTransaction();

            ResourcePath processedPath = new ResourcePath(commentPath);

            Comment comment = new Comment();
            comment.setCommentPath(commentPath);

            context.setResourcePath(processedPath);
            context.setComment(comment);
            context.setOldComments(getComments(commentPath));
            registryContext.getHandlerManager().removeComment(context);

            if (!context.isProcessingComplete()) {

                if (!processedPath.isCurrentVersion()) {
                    String msg = "Failed to remove tag from the resource " + processedPath +
                            ". Given path refers to an archived version of the resource.";
                    log.error(msg);
                    throw new RegistryException(msg);
                }

                String user = CurrentSession.getUser();
                UserRealm userRealm = CurrentSession.getUserRealm();

                boolean adminUser = false;
                // getting the realm config to get admin role, user details
                RealmConfiguration realmConfig;
                try {
                    realmConfig = userRealm.getRealmConfiguration();
                } catch (UserStoreException e) {
                    String msg = "Failed to retrieve realm configuration.";
                    log.error(msg, e);
                    throw new RegistryException(msg, e);
                }

                // check is the user belongs to the admin role
                try {
                    String[] roles = userRealm.getUserStoreManager().getRoleListOfUser(user);
                    String adminRoleName = realmConfig.getAdminRoleName();
                    if (RegistryUtils.containsString(adminRoleName, roles)) {
                        adminUser = true;
                    }

                } catch (UserStoreException e) {

                    String msg = "Failed to get roles of the current user. " +
                            "User will be considered as non-admin user.\n" + e.getMessage();
                    log.error(msg, e);
                    adminUser = false;
                }

                // check if the user is the admin user
                // TODO - do we really need to do this check?  Won't this user always be in the
                // admin role?

                String adminUsername = realmConfig.getAdminUserName();
                if (adminUsername.equals(user)) {
                    adminUser = true;
                }

                String[] parts = commentPath.split(RegistryConstants.URL_SEPARATOR);
                String commentPart = parts[1];
                String commentId = null;
                if (parts.length == 2 && commentPart.startsWith("comments:")) {
                    commentId = parts[1].substring(9);
                }

                Comment temp = commentsDAO.getComment(Long.parseLong(commentId),
                        processedPath.getPath());
                if (adminUser) {
                    commentsDAO.deleteComment(Long.parseLong(commentId));
                } else {
                    ResourceImpl resource =
                            (ResourceImpl) repository.getMetaData(processedPath.getPath());

                    String author = resource.getAuthorUserName();
                    if (user.equals(author)) {
                        commentsDAO.deleteComment(Long.parseLong(commentId));
                    } else {
                        if (temp != null && user.equals(temp.getUser())) {
                            commentsDAO.deleteComment(Long.parseLong(commentId));
                        } else {
                            String msg = "User: " + user +
                                    " is not authorized to delete the comment on the resource: " +
                                    processedPath.getPath();
                            log.warn(msg);
                            throw new AuthorizationFailedException(msg);
                        }
                    }
                }
                if (context.isLoggingActivity()) {
                    if (temp != null) {
                        registryContext.getLogWriter().addLog(processedPath.getPath(),
                                user, LogEntry.DELETE_COMMENT, temp.getText());
                    } else {
                        registryContext.getLogWriter().addLog(processedPath.getPath(),
                                user, LogEntry.DELETE_COMMENT, commentPath);
                    }
                }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.core.Comment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.