Package org.wso2.carbon.registry.core

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


                String childResourceName = RegistryUtils.getResourceName(childSourcePath);
                String childTargetPath =
                        targetPath + RegistryConstants.PATH_SEPARATOR + childResourceName;


                ResourcePath childSourceResourcePath = new ResourcePath(childSourcePath);
                ResourcePath childTargetResourcePath = new ResourcePath(childTargetPath);

                recursionRepository.copy(childSourceResourcePath, childTargetResourcePath);
            }
        }
View Full Code Here


     *
     * @return the Resource Path.
     */
    public ResourcePath getResourcePath() {
        if (resourcePath == null && resource != null) {
            resourcePath = new ResourcePath(resource.getPath());
        }
        return resourcePath;
    }
View Full Code Here

     *         collections.
     * @throws RegistryException
     */
    public Resource get(RequestContext requestContext) throws RegistryException {

        ResourcePath resourcePath = requestContext.getResourcePath();
        Resource resource;
        if (resourcePath.parameterExists(RegistryConstants.BROWSE_PROPERTY)) {

            resource = generateBrowseView(resourcePath, requestContext);

        } else if (resourcePath.parameterExists(RegistryConstants.EDIT_PROPERTY)) {

            resource = generateEditView(resourcePath, requestContext);

        } else if (resourcePath.parameterExists(RegistryConstants.NEW_PROPERTY)) {

            resource = generateNewView(resourcePath, requestContext);

        } else {
            resource = getRawResource(requestContext);
View Full Code Here

        clearCache(requestContext, requestContext.getResourcePath().getPath(), true);
        super.restore(requestContext);
    }

    public void restoreVersion(RequestContext requestContext) throws RegistryException {
        clearCache(requestContext, new ResourcePath(requestContext.getVersionPath()).getPath(),
                true);
        super.restoreVersion(requestContext);
    }
View Full Code Here

            for (String version : versions) {
                VersionPath versionPath = new VersionPath();
                versionPath.setCompleteVersionPath(version);
                versionPath.setActiveResourcePath(path);

                ResourcePath resourcePath = new ResourcePath(version);
                if (!resourcePath.isCurrentVersion()) {
                    long versionNumber = Long.parseLong(resourcePath.
                            getParameterValue(RegistryConstants.VERSION_PARAMETER_NAME));
                    versionPath.setVersionNumber(versionNumber);
                }

                Resource versionResource = userRegistry.get(version);
                if (versionResource != null) {
                    versionPath.setUpdater(versionResource.getLastUpdaterUserName());
                    Calendar versionLastModified = Calendar.getInstance();
                    versionLastModified.setTime(versionResource.getLastModified());
                    versionPath.setUpdatedOn(versionLastModified);
                    versionResource.discard();
                }

                versionPaths.add(versionPath);
            }

            versionsBean.setVersionPaths(
                    versionPaths.toArray(new VersionPath[versionPaths.size()]));

            String userName = userRegistry.getUserName();
            versionsBean.setLoggedIn(!RegistryConstants.ANONYMOUS_USER.equals(userName));

            ResourcePath resourcePath = new ResourcePath(path);
            try {
                AuthorizationManager authorizer = userRegistry.getUserRealm().getAuthorizationManager();
                boolean putAllowed = authorizer.
                        isUserAuthorized(userName, resourcePath.getPath(), ActionConstants.PUT);
                versionsBean.setPutAllowed(putAllowed);

            } catch (UserStoreException e) {

                String msg = "Failed to check put permissions of user " + userName +
View Full Code Here

                    url = realPath.substring(0, realPath.indexOf("/resourceContent?path="));
                }
            }
        }
        SubscriptionBean subscriptionBean = new SubscriptionBean();
        ResourcePath resourcePath = new ResourcePath(path);
        try {
            if (url == null || userName == null) {
                if (Utils.getRegistryEventingService() == null) {
                    throw new IllegalStateException("Subscription Manager not found");
                }
            } else if (Utils.getRegistryEventingService() == null) {
                throw new IllegalStateException("Remote Subscription Manager not found at: " + url);
            }
            List<Subscription> subscriptions = null;
            if (url == null || userName == null) {
                subscriptions = Utils.getRegistryEventingService().getAllSubscriptions();
            } else {
                subscriptions = Utils.getRegistryEventingService().getAllSubscriptions(userName, url);
            }
            log.debug("Found " + subscriptions.size() + " subscriptions");
            List<SubscriptionInstance> subscriptionInstances = new LinkedList<SubscriptionInstance>();
            for (Subscription subscription : subscriptions) {
                String testPath;
                if (!recurse) {
                    testPath = path;
                } else {
                    testPath = subscription.getTopicName();
                    if (testPath == null || testPath.lastIndexOf(RegistryConstants.PATH_SEPARATOR) <= 0
                            || !testPath.contains(path)) {
                        log.debug("path (invalid): " + testPath);
                        continue;
                    }
                    testPath = testPath.substring(RegistryEventingConstants.TOPIC_PREFIX.length(),
                            testPath.lastIndexOf(RegistryConstants.PATH_SEPARATOR));
                }
                log.debug("path: " + testPath);
                String username = null;
                if (subscription.getProperties() != null) {
                    if (subscription.getTenantId() != userRegistry.getCallerTenantId()) {
                        log.debug("TenantId for subscription doesn't match with the logged-in tenant");
                        continue;
                    }
                    username = subscription.getOwner();
                    if (username.indexOf("@") > 0) {
                        username = username.split("@")[0];
                    }
                    log.debug("Current User is: " + userRegistry.getUserName() + ". Owner of subscription is: " + username + ".");

                    if (username == null || !username.equals(userRegistry.getUserName())) {
                        if (!isAuthorized(userRegistry, testPath, AccessControlConstants.AUTHORIZE)) {
                            log.debug("User does not have AUTHORIZE priviledge to see this subscription");
                            continue;
                        }
                    } else if (!isAuthorized(userRegistry, testPath, ActionConstants.GET)) {
                        log.debug("User does not have GET priviledge to see this subscription");
                        continue;
                    }
                }
                SubscriptionInstance subscriptionInstance = populate(testPath, subscription);
                if (subscriptionInstance != null) {
                    subscriptionInstance.setOwner(username);
                    subscriptionInstances.add(subscriptionInstance);
                }
            }
            subscriptionBean.setSubscriptionInstances(subscriptionInstances.toArray(new SubscriptionInstance[0]));
            log.debug("Returning " + subscriptionInstances.size() + " subscriptions");
            subscriptionBean.setPathWithVersion(resourcePath.getPathWithVersion());
            subscriptionBean.setVersionView(!resourcePath.isCurrentVersion());
            subscriptionBean.setLoggedIn(
                    !RegistryConstants.ANONYMOUS_USER.equals(userRegistry.getUserName()));
            subscriptionBean.setUserName(userRegistry.getUserName());
            subscriptionBean.setRoles(getRolesOfUser(userRegistry, userRegistry.getUserName()));
            if (isAuthorized(userRegistry, path, AccessControlConstants.AUTHORIZE)) {
View Full Code Here

                } else {
                    url = realPath.substring(0, realPath.indexOf("/resourceContent?path="));
                }
            }
        }
        ResourcePath resourcePath = new ResourcePath(path);
        try {
            subscriptionBean.setLoggedIn(!RegistryConstants.ANONYMOUS_USER.equals(userRegistry.getUserName()));
            List<SubscriptionInstance> subscriptionInstances = new LinkedList<SubscriptionInstance>();
            if (!subscriptionBean.getLoggedIn()) {
                throw new SecurityException("User is not logged in");
            } else if (!isAuthorized(userRegistry, path, ActionConstants.GET)) {
                throw new SecurityException("User does not have enough priviledges to subscribe");
            } else if (!hasPermissionToSubscribeViaEmail(userRegistry, path, endpoint)) {
                throw new SecurityException("User does not have enough priviledges to subscribe another user");
            } else if (Utils.getRegistryEventingService() == null) {
                throw new IllegalStateException("Registry Eventing Service Not Found");
            } else {
                Subscription subscription =
                        BuilderUtils.createSubscription(endpoint,
                                "http://wso2.org/registry/eventing/dialect/topicFilter",
                                RegistryEventingConstants.TOPIC_PREFIX + path +
                                        RegistryEvent.TOPIC_SEPARATOR + eventName);
                subscription.setEventDispatcherName(RegistryEventingConstants.TOPIC_PREFIX);
                int callerTenantId = userRegistry.getCallerTenantId();
                subscription.setTenantId(callerTenantId);
                String name = userRegistry.getUserName();
                if (callerTenantId != MultitenantConstants.SUPER_TENANT_ID &&
                        callerTenantId > -1) {
                    try {
                        SuperTenantCarbonContext.startTenantFlow();
                        SuperTenantCarbonContext currentContext =
                                SuperTenantCarbonContext.getCurrentContext();
                        currentContext.setTenantId(callerTenantId, true);
                        String tenantDomain = currentContext.getTenantDomain();
                        if (tenantDomain != null) {
                            name = name + "@" + tenantDomain;
                        }
                    } finally {
                        SuperTenantCarbonContext.endTenantFlow();
                    }
                }
                subscription.setOwner(name);
                Map<String, String> data = new HashMap<String, String>();
                if (doRest) {
                    data.put(RegistryEventingConstants.DO_REST, Boolean.toString(Boolean.TRUE));
                }
                subscription.setProperties(data);
                String subscriptionId;
                if (url == null || userName == null) {
                    subscriptionId =
                            Utils.getRegistryEventingService().subscribe(subscription);
                } else {
                    throw new UnsupportedOperationException("You cannot directly subscribe to a " +
                            "Remote Resource. Use the Registry Browser User Interface to add a " +
                            "Remote Subscription.");
                }
                if (subscriptionId == null) {
                    throw new IllegalStateException("Subscription Id invalid");
                }
                subscription.setId(subscriptionId);
                SubscriptionInstance subscriptionInstance = populate(path, subscription);
                if (subscriptionInstance != null) {
                    subscriptionInstance.setOwner(userRegistry.getUserName());
                    subscriptionInstances.add(subscriptionInstance);
                }
            }
            subscriptionBean.setSubscriptionInstances(subscriptionInstances.toArray(new SubscriptionInstance[0]));
            subscriptionBean.setPathWithVersion(resourcePath.getPathWithVersion());
            subscriptionBean.setVersionView(!resourcePath.isCurrentVersion());
            subscriptionBean.setUserName(userRegistry.getUserName());
            subscriptionBean.setRoles(getRolesOfUser(userRegistry, userRegistry.getUserName()));
            if (isAuthorized(userRegistry, path, AccessControlConstants.AUTHORIZE)) {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.AUTHORIZE);
            } else if (isAuthorized(userRegistry, path, ActionConstants.DELETE)) {
View Full Code Here

    private static final Log log = LogFactory.getLog(PermissionUtil.class);

    public static PermissionBean getPermissions(UserRegistry userRegistry, String path) throws Exception {

        ResourcePath resourcePath = new ResourcePath(path);
        String userName = userRegistry.getUserName();
        PermissionBean permissionsBean = new PermissionBean();
        permissionsBean.setPathWithVersion(resourcePath.getPathWithVersion());
        permissionsBean.setVersionView(!resourcePath.isCurrentVersion());

        UserRealm userRealm = userRegistry.getUserRealm();

        String[] userNames = userRealm.getUserStoreManager().listUsers("*", 100);

View Full Code Here

public class RatingBeanPopulator {

    public static RatingBean populate(UserRegistry userRegistry, String path) {

        RatingBean ratingBean = new RatingBean();
        ResourcePath resourcePath = new ResourcePath(path);
        try {
            float averageRating = userRegistry.getAverageRating(resourcePath.getCompletePath());
            ratingBean.setAverageRating(averageRating);

            // round the average rating to closest 3 decimal points
            float tempRating = averageRating * 1000;
            tempRating = Math.round(tempRating);
            tempRating = tempRating / 1000;
            averageRating = tempRating;

            int userRating = userRegistry.getRating(
                    resourcePath.getCompletePath(), userRegistry.getUserName());
            ratingBean.setUserRating(userRating);

            String[] userStars = new String[5];
            for (int i = 0; i < 5; i++) {

                if (userRating >= i + 1) {
                    userStars[i] = "04";

                } else if (userRating <= i) {
                    userStars[i] = "00";

                }
            }
            ratingBean.setUserStars(userStars);

            String[] averageStars = new String[5];
            for (int i = 0; i < 5; i++) {

                if (averageRating >= i + 1) {
                    averageStars[i] = "04";

                } else if (averageRating <= i) {
                    averageStars[i] = "00";

                } else {

                    float fraction = averageRating - i;

                    if (fraction <= 0.125) {
                        averageStars[i] = "00";

                    } else if (fraction > 0.125 && fraction <= 0.375) {
                        averageStars[i] = "01";

                    } else if (fraction > 0.375 && fraction <= 0.625) {
                        averageStars[i] = "02";

                    } else if (fraction > 0.625 && fraction <= 0.875) {
                        averageStars[i] = "03";

                    } else {
                        averageStars[i] = "04";

                    }
                }
            }
            ratingBean.setAverageStars(averageStars);

            ratingBean.setVersionView(!resourcePath.isCurrentVersion());
            ratingBean.setPathWithVersion(resourcePath.getPathWithVersion());
            ratingBean.setPutAllowed(UserUtil.isPutAllowed(userRegistry.getUserName(), path, userRegistry));
            ratingBean.setLoggedIn(!RegistryConstants.ANONYMOUS_USER.equals(userRegistry.getUserName()));
        } catch (RegistryException e) {
            String msg = "Failed to get ratings information of the resource " +
                    resourcePath + ". " + e.getMessage();
View Full Code Here

     * @throws RegistryException if there is an failure in populating properties.
     */
    public static PropertiesBean populate(UserRegistry registry, String path, String viewProps)
            throws RegistryException {
        Resource resource = registry.get(path);
        ResourcePath resourcePath = new ResourcePath(path);
        PropertiesBean propertiesBean = new PropertiesBean();
        boolean isPutAllowed = false;

        Properties properties = resource.getProperties();
        Set keySet = properties.keySet();
        Property [] propArray;
        if(keySet.size() != 0) {
        Object [] keys = keySet.toArray();

        List values;
        propArray = new Property [keys.length];
        for (int i=0; i<keys.length; i++) {
            Property prop = new Property();
            prop.setKey((String) keys[i]);
            values = (List) properties.get((String)keys[i]);
            prop.setValue((String) values.get(0));
            propArray[i] = prop;

            if (keys[i].equals("registry.link") &&
                    values.get(0).equals("true")) {
                 isPutAllowed = true;
            }
        }
        } else {
            propArray = new Property [0];
        }
        propertiesBean.setProperties(propArray);
        Boolean viewSysProps = false;
        if(viewProps.equalsIgnoreCase("yes")) {
            viewSysProps = true;
        }

        Iterator iTmpProps = resource.getProperties().keySet().iterator();

        List<String> sysProperties = new ArrayList<String>();
        List <String> validationProperties = new ArrayList <String> ();
        List <String> lifecycleProperties = new ArrayList <String> ();

        while (iTmpProps.hasNext()) {
            String name = (String) iTmpProps.next();

            if ((viewSysProps != null && viewSysProps) || !name.startsWith("registry.")) {
                sysProperties.add(name);
            }

            if (name.startsWith("registry.wsdl") || name.startsWith("registry.wsi")) {
                validationProperties.add(name);

            } else if (name.startsWith("registry.lifecycle.") ||
                    name.equals(Aspect.AVAILABLE_ASPECTS)) {

                lifecycleProperties.add(name);

            }
        }

        Collections.sort(sysProperties);

        String [] sysProps = new String [sysProperties.size()];
        for(int i=0; i<sysProperties.size(); i++) {
            sysProps[i] = sysProperties.get(i);
        }
        propertiesBean.setSysProperties(sysProps);
        String [] validationProps = new String [validationProperties.size()];
        for(int i=0; i<validationProperties.size(); i++) {
            validationProps[i] = validationProperties.get(i);
        }
        propertiesBean.setValidationProperties(validationProps);
        String [] lifecycleProps = new String [lifecycleProperties.size()];
        for(int i=0; i<lifecycleProperties.size(); i++) {
            lifecycleProps[i] = lifecycleProperties.get(i);
        }
        propertiesBean.setLifecycleProperties(lifecycleProps);

        propertiesBean.setVersionView(!resourcePath.isCurrentVersion());
        propertiesBean.setPathWithVersion(resourcePath.getPathWithVersion());
        if (!isPutAllowed) {
            isPutAllowed = UserUtil.isPutAllowed(registry.getUserName(), path, registry);
        }
        propertiesBean.setPutAllowed(isPutAllowed);
        propertiesBean.setLoggedIn(!RegistryConstants.ANONYMOUS_USER.equals(registry.getUserName()));
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.