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

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


    }

    public void invokeAspect(String resourcePath, String aspectName, String action)
            throws RegistryException {
        boolean transactionSucceeded = false;
        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));
            context.setResource(resource);

            //        List aspectNames = resource.getPropertyValues(Aspect.AVAILABLE_ASPECTS);
            //        if (aspectNames == null) {
            //            throw new RegistryException("No aspect are associated with the resource");
            //        }
            context.setAspect(aspect);
            context.setAction(action);
            registryContext.getHandlerManager().invokeAspect(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    aspect.invoke(context, action);
                }
                resource.discard();

                // transaction succeeded
View Full Code Here


    public void invokeAspect(String resourcePath, String aspectName, String action,
                             Map<String, String> parameters)
            throws RegistryException {
        boolean transactionSucceeded = false;
        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));
            context.setResource(resource);

            for (Map.Entry<String, String> e : parameters.entrySet()) {
                context.setProperty(e.getKey(), e.getValue());
            }

            context.setProperty("parameterNames",
                    Collections.unmodifiableSet(parameters.keySet()));

            //        List aspectNames = resource.getPropertyValues(Aspect.AVAILABLE_ASPECTS);
            //        if (aspectNames == null) {
            //            throw new RegistryException("No aspect are associated with the resource");
            //        }
            context.setAspect(aspect);
            context.setAction(action);
            registryContext.getHandlerManager().invokeAspect(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    aspect.invoke(context, action, parameters);
                }
                resource.discard();

                // transaction succeeded
View Full Code Here

    }

    public String[] getAspectActions(String resourcePath, String aspectName)
            throws RegistryException {
        boolean transactionSucceeded = false;
        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);
            String[] actions = aspect.getAvailableActions(context);

            // transaction succeeded
            transactionSucceeded = true;
View Full Code Here

        return null;
    }

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

            if (path.equals(target)) {
                String msg = "Path and target are same, path = target = " + path +
                        ". You can't create a symbolic link to itself.";
                log.error(msg);
                throw new RegistryException(msg);
            }
            // first put the data..
            Resource oldResource = repository.getMetaData(target);
            Resource resource;
            if (repository.resourceExists(path)) {
                resource = repository.get(path);
                resource.addProperty(RegistryConstants.REGISTRY_EXISTING_RESOURCE, "true");
            } else if (oldResource != null) {
                if (oldResource instanceof Collection) {
                    resource = new CollectionImpl();
                } else {
                    resource = new ResourceImpl();
                }
            } else {
                resource = new CollectionImpl();
            }
            resource.addProperty(RegistryConstants.REGISTRY_NON_RECURSIVE, "true");
                resource.addProperty(RegistryConstants.REGISTRY_LINK_RESTORATION,
                        path + RegistryConstants.URL_SEPARATOR + target +
                                RegistryConstants.URL_SEPARATOR + CurrentSession.getUser());
            try {
                CurrentSession.setAttribute(Repository.IS_LOGGING_ACTIVITY, false);
                repository.put(path, resource);
            } finally {
                CurrentSession.removeAttribute(Repository.IS_LOGGING_ACTIVITY);
            }
            resource.discard();
            HandlerManager hm = registryContext.getHandlerManager();

            ResourcePath resourcePath = new ResourcePath(path);
            context.setResourcePath(resourcePath);
            context.setTargetPath(target);
            hm.createLink(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    RegistryUtils.registerHandlerForSymbolicLinks(registryContext, path, target,
                            CurrentSession.getUser());

                    String author = CurrentSession.getUser();
                    RegistryUtils.addMountEntry(this, registryContext, path, target,
                            false, author);


                    if (context.isLoggingActivity()) {
                        registryContext.getLogWriter().addLog(path, CurrentSession.getUser(),
                                LogEntry.CREATE_SYMBOLIC_LINK,
                                target);
                    }
                }
View Full Code Here

    }

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

            Resource resource;

            if (repository.resourceExists(path)) {
                resource = repository.get(path);
                resource.addProperty(RegistryConstants.REGISTRY_EXISTING_RESOURCE, "true");
            } else {
                resource = new CollectionImpl();
            }
            resource.addProperty(RegistryConstants.REGISTRY_NON_RECURSIVE, "true");
            resource.addProperty(RegistryConstants.REGISTRY_LINK_RESTORATION,
                    path + RegistryConstants.URL_SEPARATOR + target +
                            RegistryConstants.URL_SEPARATOR + targetSubPath +
                            RegistryConstants.URL_SEPARATOR + CurrentSession.getUser());
            try {
                CurrentSession.setAttribute(Repository.IS_LOGGING_ACTIVITY, false);
                repository.put(path, resource);
            } finally {
                CurrentSession.removeAttribute(Repository.IS_LOGGING_ACTIVITY);
            }
            resource.discard();

            HandlerManager hm = registryContext.getHandlerManager();

            ResourcePath resourcePath = new ResourcePath(path);
            context.setResourcePath(resourcePath);
            context.setTargetPath(target);
            context.setTargetSubPath(targetSubPath);
            hm.createLink(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    RegistryUtils.registerHandlerForRemoteLinks(registryContext, path, target,
                            targetSubPath, CurrentSession.getUser());

                    String author = CurrentSession.getUser();
                    RegistryUtils.addMountEntry(this, registryContext, path, target, targetSubPath,
                            author);

                    if (context.isLoggingActivity()) {
                        registryContext.getLogWriter().addLog(
                                path, CurrentSession.getUser(), LogEntry.CREATE_REMOTE_LINK,
                                target + ";" + targetSubPath);
                    }
                }
View Full Code Here

        }
    }

    public void removeLink(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().removeLink(context);

            // we will be removing the symlink handlers to remove
            Handler handlerToRemove = (Handler)context.getProperty(
                    RegistryConstants.SYMLINK_TO_REMOVE_PROPERTY_NAME);
            if (handlerToRemove != null) {
                registryContext.getHandlerManager().removeHandler(handlerToRemove,
                        HandlerLifecycleManager.TENANT_SPECIFIC_SYSTEM_HANDLER_PHASE);
            }

            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    Collection mountCollection = (Collection) get(
                            RegistryUtils.getAbsolutePath(registryContext,
                                    RegistryConstants.LOCAL_REPOSITORY_BASE_PATH +
                                            RegistryConstants.SYSTEM_MOUNT_PATH));
                    String[] mountResources = mountCollection.getChildren();
                    Resource resource = null;
                    for (String mountResource : mountResources) {
                        String mountResName =
                                mountResource.substring(mountResource.lastIndexOf("/") + 1);
                        String relativePath = RegistryUtils.getRelativePath(registryContext,
                                path);
                        if (mountResName.equals(relativePath.replace("/", "-"))) {
                            resource = get(mountResource);
                            break;
                        }
                    }

                    if (resource == null) {
                        String msg = "Couldn't find the mount point to remove. ";
                        log.error(msg);
                        throw new RegistryException(msg);
                    }

                    delete(resource.getPath());
                    if (repository.resourceExists(path)) {
                        Resource r = repository.get(path);
                        if (!Boolean.toString(true).equals(
                                r.getProperty(RegistryConstants.REGISTRY_EXISTING_RESOURCE))) {
                            repository.delete(path);
                        }
                    }

                    if (context.isLoggingActivity()) {
                        registryContext.getLogWriter().addLog(
                                path, CurrentSession.getUser(), LogEntry.REMOVE_LINK, null);
                    }
                }
                transactionSucceeded = true;
View Full Code Here

    // check in, check out functionality

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

            context.setDumpingReader(reader);
            context.setResourcePath(new ResourcePath(path));
            registryContext.getHandlerManager().restore(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    try {
                        CurrentSession.setAttribute(Repository.IS_LOGGING_ACTIVITY,
                                context.isLoggingActivity());
                        repository.restore(path, reader);
                    } finally {
                        CurrentSession.removeAttribute(Repository.IS_LOGGING_ACTIVITY);
                    }
                    if (context.isLoggingActivity()) {
                        registryContext.getLogWriter().addLog(
                                path, CurrentSession.getUser(), LogEntry.RESTORE, null);
                    }
                }
                // transaction succeeded
View Full Code Here

        }
    }

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

            context.setResourcePath(new ResourcePath(path));
            context.setDumpingWriter(writer);
            registryContext.getHandlerManager().dump(context);
            if (!context.isSimulation()) {
                if (!context.isProcessingComplete()) {
                    repository.dump(path, writer);
                }

                // transaction succeeded
                transactionSucceeded = true;
View Full Code Here

    }

    public boolean addAspect(String name, Aspect aspect)
            throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();
            // we are using CallerTenantId instead of tenantId to preserve the tenant information
            // even this is called from a system registry, which anyway makes tenantId always = 0,
            // but keep the callerTenantId value to it is callers real tenant id
            registryContext.addAspect(name, aspect, CurrentSession.getCallerTenantId());
            if (!context.isProcessingComplete()) {
                // transaction succeeded
                transactionSucceeded = true;
                return true;
            }
            return false;
View Full Code Here

    }

    public boolean removeAspect(String name)
            throws RegistryException {
        boolean transactionSucceeded = false;
        RequestContext context = new RequestContext(this, repository, versionRepository);
        try {
            // start the transaction
            beginTransaction();
            // we are using CallerTenantId instead of tenantId to preserve the tenant information
            // even this is called from a system registry, which anyway makes tenantId always = 0,
            // but keep the callerTenantId value to it is callers real tenant id
            registryContext.removeAspect(name, CurrentSession.getCallerTenantId());
            if (!context.isProcessingComplete()) {
                // transaction succeeded
                transactionSucceeded = true;
                return true;
            }
            return false;
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.