Package org.wso2.carbon.registry.core.jdbc.handlers

Examples of org.wso2.carbon.registry.core.jdbc.handlers.RequestContext


        }
    }

    public String copy(String sourcePath, String targetPath) throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            ResourcePath sourceResourcePath = new ResourcePath(sourcePath);
            ResourcePath targetResourcePath = new ResourcePath(targetPath);
            context.setSourcePath(sourcePath);
            context.setTargetPath(targetPath);
            String copiedPath = registryContext.getHandlerManager().copy(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    try {
                        CurrentSession.setAttribute(Repository.IS_LOGGING_ACTIVITY,
                                context.isLoggingActivity());
                        copiedPath = repository.copy(sourceResourcePath, targetResourcePath);
                    } finally {
                        CurrentSession.removeAttribute(Repository.IS_LOGGING_ACTIVITY);
                    }
                }
                if (context.isLoggingActivity()) {
                    registryContext.getLogWriter().addLog(
                            sourcePath, CurrentSession.getUser(), LogEntry.COPY, targetPath);
                }

                // transaction successfully finished
View Full Code Here


        }
    }

    public void createVersion(String path) throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            ResourcePath resourcePath = new ResourcePath(path);

            context.setResourcePath(resourcePath);
            registryContext.getHandlerManager().createVersion(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    versionRepository.createSnapshot(resourcePath, true, true);
                }

                // transaction successfully finished
                transactionSucceeded = true;
View Full Code Here

        }
    }

    public String[] getVersions(String path) throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            context.setResourcePath(new ResourcePath(path));
            String[] output = registryContext.getHandlerManager().getVersions(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    output = versionRepository.getVersions(path);
                }

                // transaction successfully finished
                transactionSucceeded = true;
View Full Code Here

        }
    }

    public void restoreVersion(String versionPath) throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            context.setVersionPath(versionPath);
            ResourcePath versionedResourcePath = new ResourcePath(versionPath);
            String path = versionedResourcePath.getPath();
            if (repository.resourceExists(path)) {
                context.setOldResource(repository.get(path));
            }
            registryContext.getHandlerManager().restoreVersion(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    if (repository.resourceExists(path)) {
                        // if the target already have resources, delete them..
                        repository.prepareVersionRestore(path);
                    }
                    versionRepository.restoreVersion(versionedResourcePath);
                    VersionedPath versionedPath =
                            RegistryUtils.getVersionedPath(versionedResourcePath);
                    if (context.isLoggingActivity()) {
                        registryContext.getLogWriter().addLog(
                                path, CurrentSession.getUser(), LogEntry.RESTORE,
                                Long.toString(versionedPath.getVersion()));
                    }
                }
View Full Code Here

    ////////////////////////////////////////////////////////

    public void addAssociation(String sourcePath, String targetPath, String associationType)
            throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            // Source and target of associations may or may not be resources in the registry. If they
            // don't refer to a resource, they can contain any string value. But if they refer to
            // resources, values should be proper resource paths.

            ResourcePath sourceResourcePath = new ResourcePath(sourcePath);
            if (repository.resourceExists(sourceResourcePath.getPath())) {
                sourcePath = sourceResourcePath.getPathWithVersion();
            }

            ResourcePath targetResourcePath = new ResourcePath(targetPath);
            if (repository.resourceExists(targetResourcePath.getPath())) {
                targetPath = targetResourcePath.getPathWithVersion();
            }

            context.setSourcePath(sourcePath);
            context.setTargetPath(targetPath);
            context.setAssociationType(associationType);
            context.setOldAssociationsOnSource(getAllAssociations(sourcePath));
            context.setOldAssociationsOnTarget(getAllAssociations(targetPath));

            registryContext.getHandlerManager().addAssociation(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    associationDAO.addAssociation(sourcePath, targetPath, associationType);
                    if (context.isLoggingActivity()) {
                        registryContext.getLogWriter().addLog(
                                sourcePath, CurrentSession.getUser(), LogEntry.ADD_ASSOCIATION,
                                associationType + ";" + targetPath);
                    }
                }
View Full Code Here

    }

    public void removeAssociation(String sourcePath, String targetPath, String associationType)
            throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            // Source and target of associations may or may not be resources in the registry. If they
            // don't refer to a resource, they can contain any string value. But if they refer to
            // resources, values should be proper resource paths.

            ResourcePath sourceResourcePath = new ResourcePath(sourcePath);
            if (repository.resourceExists(sourceResourcePath.getPath())) {
                sourcePath = sourceResourcePath.getPathWithVersion();
            }

            ResourcePath targetResourcePath = new ResourcePath(targetPath);
            if (repository.resourceExists(targetResourcePath.getPath())) {
                targetPath = targetResourcePath.getPathWithVersion();
            }

            context.setSourcePath(sourcePath);
            context.setTargetPath(targetPath);
            context.setAssociationType(associationType);
            context.setOldAssociationsOnSource(getAllAssociations(sourcePath));
            context.setOldAssociationsOnTarget(getAllAssociations(targetPath));

            registryContext.getHandlerManager().removeAssociation(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    associationDAO.removeAssociation(sourcePath, targetPath, associationType);
                    if (context.isLoggingActivity()) {
                        registryContext.getLogWriter().addLog(
                                sourcePath, CurrentSession.getUser(), LogEntry.REMOVE_ASSOCIATION,
                                associationType + ";" + targetPath);
                    }
                }
View Full Code Here

        }
    }

    public Association[] getAllAssociations(String resourcePath) throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            // Source and target of associations may or may not be resources in the registry. If they
            // don't refer to a resource, they can contain any string value. But if they refer to
            // resources, values should be proper resource paths.

            ResourcePath processedPath = new ResourcePath(resourcePath);
            if (repository.resourceExists(processedPath.getPath())) {
                resourcePath = processedPath.getPathWithVersion();
            }

            context.setResourcePath(new ResourcePath(resourcePath));

            Association[] associations =
                    registryContext.getHandlerManager().getAllAssociations(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    associations = associationDAO.getAllAssociations(resourcePath);
                }
                // transaction successfully finished
                transactionSucceeded = true;
            }
View Full Code Here

    }

    public Association[] getAssociations(String resourcePath, String associationType)
            throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            // Source and target of associations may or may not be resources in the registry. If they
            // don't refer to a resource, they can contain any string value. But if they refer to
            // resources, values should be proper resource paths.

            ResourcePath processedPath = new ResourcePath(resourcePath);
            if (repository.resourceExists(processedPath.getPath())) {
                resourcePath = processedPath.getPathWithVersion();
            }

            context.setResourcePath(new ResourcePath(resourcePath));
            context.setAssociationType(associationType);

            Association[] associations =
                    registryContext.getHandlerManager().getAssociations(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    associations =
                            associationDAO.getAllAssociationsForType(resourcePath, associationType);
                }
                // transaction successfully finished
                transactionSucceeded = true;
View Full Code Here

        if (illegalCharactersPattern.matcher(tag).matches()) {  //"[~!@#$;%^*()+={}[]|\\<>\"\']"
            throw new RegistryException("The tag '" + tag + "' contains one or more illegal " +
                    "characters (~!@#$;%^*()+={}|\\<>\"\')");
        }
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {

            // start the transaction
            beginTransaction();

            ResourcePath processedPath = new ResourcePath(resourcePath);

            context.setResourcePath(processedPath);
            context.setTag(tag);
            context.setOldTags(getTags(processedPath.getPath()));

            registryContext.getHandlerManager().applyTag(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {

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

                    resourcePath = processedPath.getPath();

                    // break the comma separated words into multiple tags
                    String[] tags = tag.split(",");

                    ResourceImpl resource = tagsDAO.getResourceWithMinimumData(resourcePath);
                    if (resource == null) {
                        String msg = "Failed to apply tag " + tag + " on resource " + resourcePath +
                                ". Resource " + resourcePath + " does not exist.";
                        log.error(msg);
                        throw new RegistryException(msg);
                    }

                    String userName = CurrentSession.getUser();

                    if (!AuthorizationUtils.authorize(resource.getPath(), ActionConstants.GET)) {
                        String msg = "Failed to apply tag " + tag + " on resource " + resourcePath +
                                ". User " + userName + " is not authorized to read the resource.";
                        log.error(msg);
                        throw new RegistryException(msg);
                    }

                    for (int i = 0; i < tags.length; i++) {

                        tags[i] = tags[i].trim();

                        if (tags[i].length() == 0 || tags[i].equals(" ")) {
                            continue;
                        }

                        if (tagsDAO.taggingExists(tags[i], resource, userName)) {
                            // Already there, don't bother doing it again.
                            continue;
                        }

                        tagsDAO.addTagging(tags[i], resource, userName);
                        if (context.isLoggingActivity()) {
                            registryContext.getLogWriter().addLog(
                                    resourcePath, userName, LogEntry.TAG, tags[i]);
                        }
                    }
                }
View Full Code Here

        }
    }

    public TaggedResourcePath[] getResourcePathsWithTag(String tag) throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();

            context.setTag(tag);

            TaggedResourcePath[] output =
                    registryContext.getHandlerManager().getResourcePathsWithTag(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {

                    // break the tags from spaces
                    String[] tags = tag.trim().split(",");

                    for (int i = 0; i < tags.length; i++) {
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.core.jdbc.handlers.RequestContext

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.