Package org.wso2.carbon.registry.core

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


        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // 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);
                    }
                }
            }
            // transaction succeeded
View Full Code Here


        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            ResourcePath resourcePath = new ResourcePath(path);

            context.setResourcePath(resourcePath);
            Comment[] output = registryContext.getHandlerManager().getComments(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {

                    VersionedPath versionedPath = RegistryUtils.getVersionedPath(resourcePath);
                    ResourceImpl resourceImpl;
                    if (versionedPath.getVersion() == -1) {
                        resourceImpl =
                                commentsDAO.getResourceWithMinimumData(resourcePath.getPath());
                    } else {
                        resourceImpl = (ResourceImpl) versionRepository.getMetaData(versionedPath);
                    }

                    if (resourceImpl == null) {
View Full Code Here

            // start the transaction
            beginTransaction();

            String userName = CurrentSession.getUser();

            context.setResourcePath(new ResourcePath(resourcePath));
            context.setRating(rating);
            context.setOldRating(getRating(resourcePath, userName));
            context.setOldAverageRating(getAverageRating(resourcePath));
            registryContext.getHandlerManager().rateResource(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {

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

                    resourcePath = processedPath.getPath();

                    ResourceImpl resourceImpl = ratingsDAO.getResourceWithMinimumData(resourcePath);

                    if (resourceImpl != null) {
View Full Code Here

        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();
            ResourcePath resourcePath = new ResourcePath(path);

            context.setResourcePath(resourcePath);
            float rating = registryContext.getHandlerManager().getAverageRating(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {

                    VersionedPath versionedPath = RegistryUtils.getVersionedPath(resourcePath);
                    ResourceImpl resourceImpl;
                    if (versionedPath.getVersion() == -1) {
                        resourceImpl =
                                ratingsDAO.getResourceWithMinimumData(resourcePath.getPath());
                    } else {
                        resourceImpl = (ResourceImpl) versionRepository.getMetaData(versionedPath);
                    }

                    if (resourceImpl == null) {
View Full Code Here

        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();
            ResourcePath resourcePath = new ResourcePath(path);

            context.setResourcePath(resourcePath);
            context.setUserName(userName);
            int rating = registryContext.getHandlerManager().getRating(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {

                    VersionedPath versionedPath = RegistryUtils.getVersionedPath(resourcePath);
                    ResourceImpl resourceImpl;
                    if (versionedPath.getVersion() == -1) {
                        resourceImpl =
                                ratingsDAO.getResourceWithMinimumData(resourcePath.getPath());
                    } else {
                        resourceImpl = (ResourceImpl) versionRepository.getMetaData(versionedPath);
                    }
                    if (resourceImpl == null) {
                        String msg = "Rate on Null resource " + path;
View Full Code Here

        try {
            // start the transaction
            beginTransaction();*/

            if (path != null) {
                context.setResourcePath(new ResourcePath(path));
            }
            context.setResource(query);
            context.setQueryParameters(parameters);
            Collection output = registryContext.getHandlerManager().executeQuery(context);
            if (!context.isSimulation()) {
View Full Code Here

        boolean transactionSucceeded = false;
        try {
            // start the transaction
            beginTransaction();

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

            resourcePath = processedPath.getPath();

            //TODO need to do the security validation here
            Resource resource = get(resourcePath);
            if ((resource.getAspects() == null) || (!resource.getAspects().contains(aspectName))) {
                Aspect aspect = getAspect(aspectName);
View Full Code Here

        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            ResourcePath processedPath = new ResourcePath(resourcePath);
            if (!processedPath.isCurrentVersion()) {
                String msg = "Failed to invoke aspect of the resource " + processedPath +
                        ". Given path refers to an archived version of the resource.";
                log.error(msg);
                throw new RegistryException(msg);
            }
            resourcePath = processedPath.getPath();

            Resource resource = get(resourcePath);

            Aspect aspect = getResourceAspect(resource, aspectName);
            context.setOldResource(get(resourcePath));
View Full Code Here

        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            ResourcePath processedPath = new ResourcePath(resourcePath);
            if (!processedPath.isCurrentVersion()) {
                String msg = "Failed to invoke aspect of the resource " + processedPath +
                        ". Given path refers to an archived version of the resource.";
                log.error(msg);
                throw new RegistryException(msg);
            }
            resourcePath = processedPath.getPath();

            Resource resource = get(resourcePath);

            Aspect aspect = getResourceAspect(resource, aspectName);
            context.setOldResource(get(resourcePath));
View Full Code Here

        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            ResourcePath processedPath = new ResourcePath(resourcePath);
            if (!processedPath.isCurrentVersion()) {
                String msg = "Failed to get aspect actions of the resource " + processedPath +
                        ". Given path refers to an archived version of the resource.";
                log.error(msg);
                throw new RegistryException(msg);
            }
            resourcePath = processedPath.getPath();

            Resource resource = get(resourcePath);
            Aspect aspect = getResourceAspect(resource, aspectName);

            context.setResource(resource);
View Full Code Here

TOP

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

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.