Package org.wso2.carbon.registry.core

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


        RegistryProperty regProp = null;
        String prop = "";
        List<String> propList = null;
        String propName = tempArr[tempArr.length - 1];
        ResourceImpl res = null;
        boolean resFlag = false;

        try {

            regProp = new RegistryProperty((CollectionImpl) registrySession.getUserRegistry().get(tempPath), registrySession, tempArr[tempArr.length - 1]);

            if ((registrySession.getUserRegistry().resourceExists(absPath)) && (registrySession.getUserRegistry().get(absPath) != null)) {
                res = (ResourceImpl) registrySession.getUserRegistry().get(absPath);
                resFlag = true;

            }

            if ((!resFlag) && (registrySession.getUserRegistry().resourceExists(tempPath)) && (registrySession.getUserRegistry().get(tempPath) != null)) {


                propList = registrySession.getUserRegistry().get(tempPath).getPropertyValues(propName);

                if ((propList != null) && (propList.size() == 1)) {

                    prop = propList.get(0);
                    regProp.setValue(prop);
                } else {

                    if (propList != null) {

                        String[] arr = new String[propList.size()];
                        int i = 0;

                        for (Object ob : propList) {

                            arr[i] = ob.toString();
                            i++;
                        }
                        regProp.setValue(arr);
                    }

                }


            } else if (res != null) {

                if ((res.getProperty("registry.jcr.property.type") != null) && (res.getProperty("registry.jcr.property.type").equals("input_stream"))) {
                    regProp.setValue(res.getContentStream());

                } else if ((res.getProperty("registry.jcr.property.type") != null) && (res.getProperty("registry.jcr.property.type").equals("values_type"))) {
                    List<String> valuesProp = res.getPropertyValues(propName);
                    if (valuesProp != null) {
                        int i = 0;
                        Value[] values = new RegistryValue[valuesProp.size()];

                        for (int j = 0; j < values.length; j++) {

                            values[j] = new RegistryValue(valuesProp.get(j));

                        }

                        regProp.setValue(values);
                    }
                } else if (res.getContent() instanceof String) {
                    prop = res.getContent().toString();

                } else if (res.getContent() instanceof byte[]) {
                    prop = new String((byte[]) res.getContent());

                } else if (prop.equals("")) {

                    throw new PathNotFoundException();
                }


                regProp = RegistrySession.getRegistryProperty(res.getProperty("registry.jcr.property.type"), prop, regProp);

                resFlag = false;


            }
View Full Code Here


            String symlinkLocation, Registry registry)
            throws Exception {

        try {
            boolean isNew = !(registry.resourceExists(path));
            ResourceImpl resourceImpl = (ResourceImpl) (isNew ? registry.newResource() :
                    registry.get(path));
            if (resourceImpl.getProperty(RegistryConstants.REGISTRY_LINK) != null &&
                    (CommonConstants.WSDL_MEDIA_TYPE.equals(mediaType) ||
                            CommonConstants.SCHEMA_MEDIA_TYPE.equals(mediaType))) {
                resourceImpl = (ResourceImpl) registry.newResource();
            }
            resourceImpl.setMediaType(mediaType);
            resourceImpl.setDescription(description);
            resourceImpl.setContentStream(content.getInputStream());

            if (symlinkLocation != null && isNew) {
                if (!symlinkLocation.endsWith(RegistryConstants.PATH_SEPARATOR)) {
                    symlinkLocation += RegistryConstants.PATH_SEPARATOR;
                }
                resourceImpl.setProperty(RegistryConstants.SYMLINK_PROPERTY_NAME, symlinkLocation);
                // The symbolic link location is expected to be set only for WSDLs, Schemas and
                // Policies. Therefore, if this has been set, a symbolic link will be created at the
                // given location. However, if the symbolic link already exists, that means that the
                // content is being updated. In such a situation, the symbolic link will first be
                // removed before attempting to do the put operation. This will fix the issue
                // mentioned in CARBON-7350.
                if (registry.resourceExists(path)) {
                    Resource resource = registry.get(path);
                    if (resource != null) {
                        if (resource.getProperty("registry.link") != null) {
                            registry.removeLink(path);
                        }
                    }
                }
            }
            registry.put(path, resourceImpl);
            resourceImpl.discard();

        } catch (Exception e) {

            String msg = "Failed to add resource " + path + ". " + ((e.getCause() instanceof SQLException) ?
                    "" : e.getMessage());
View Full Code Here

    private Resource createResource(String path) {
        try {
            String resolvedPath = getCorrectPath(path);
            if (!registry.resourceExists(resolvedPath)) {
                ResourceImpl resource = new ResourceImpl();
                resource.setPath(resolvedPath);
                return resource;
            }
        } catch (RegistryException e) {
            handleException("Unable to create a Resource in path : " + path, e);
        }
View Full Code Here

        try {
            String path = requestContext.getResourcePath().getPath();
            UserStoreManager userStoreManager;
            String [] pathParts = path.split("/");
            String username = pathParts[pathParts.length - 2];
            ResourceImpl col = null;
            UserRealm realm = CurrentSession.getUserRealm();

            try{
                userStoreManager = realm.getUserStoreManager();
                /* check the existence of the user in the user manager */
                if(!userStoreManager.isExistingUser(username))
                {

                    if(username.equals("users")){
                        log.error("No user with the username:" +  username + " in the User Manager");
                    }
                    return null;
                }
                StringBuffer resourceContent = new StringBuffer();
                String[] profileNames = userStoreManager.getProfileNames(username);
                for (String temp : profileNames) {
                    Claim[] claimValues = userStoreManager.getUserClaimValues(username, temp);
                    if (claimValues.length != 0) {
                        resourceContent.append(temp).append("%");
                        for (Claim claim : claimValues) {
                            resourceContent.append(claim.getDisplayTag()).append(";").append(
                                    claim.getValue()).append(";");
                        }
                    }
                    resourceContent.append("#");
                }
                Registry registry = requestContext.getRegistry();
                if (registry.resourceExists(path)) {
                    col = (ResourceImpl) registry.get(path);
                    col.setContent(resourceContent.toString());
                }
            } catch (UserStoreException e) {
                log.error("An error occurred while reading profile details", e);
            }
            return col;
View Full Code Here

            Resource resource1 = registry.get(path);

            assertEquals("File content is not matching", new String((byte[]) resource1.getContent()),
                    new String((byte[]) res1.getContent()));

            Resource resource = new ResourceImpl();
            byte[] r1content1 = "R2 content updated".getBytes();
            resource.setContent(r1content1);
            resource.setProperty("abc", "abc");

            registry.put(path, resource);

            Resource resource2 = registry.get(path);

            assertEquals("File content is not matching", new String((byte[]) resource.getContent()),
                    new String((byte[]) resource2.getContent()));

            resource.discard();
            res1.discard();
            resource1.discard();
            resource2.discard();
            Thread.sleep(100);
        }
View Full Code Here

     *
     * @throws Exception if an error occurs.
     */
    public static void addConfig(Registry registry) throws Exception {

        Resource config = new ResourceImpl();
        String path = RegistryUtils.getAbsolutePath(
                registry.getRegistryContext(), RegistryConstants.CONFIG_REGISTRY_BASE_PATH +
                        RegistryConstants.GOVERNANCE_SERVICES_CONFIG_PATH + "service");
        if (RegistryUtils.systemResourceShouldBeAdded(registry, path)) {
            if (registry.getRegistryContext() != null && registry.getRegistryContext().isClone()) {
                return;
            }
            String serviceConfig = getConfigFile();
            if (serviceConfig != null) {
                config.setContent(serviceConfig.getBytes());
                registry.put(path, config);
            }
        }

    }
View Full Code Here

     *
     * @throws Exception if an error occurs.
     */
    public static void addConfigSchema(Registry registry) throws Exception {

        Resource config = new ResourceImpl();
        String path = RegistryUtils.getAbsolutePath(
                registry.getRegistryContext(), RegistryConstants.CONFIG_REGISTRY_BASE_PATH +
                        RegistryConstants.GOVERNANCE_SERVICES_CONFIG_PATH + "service-schema");
        if (RegistryUtils.systemResourceShouldBeAdded(registry, path)) {
            if (registry.getRegistryContext() != null && registry.getRegistryContext().isClone()) {
                return;
            }
            String serviceConfig = getConfigSchemaFile();
            if (serviceConfig != null) {
                config.setContent(serviceConfig.getBytes());
                registry.put(path, config);
            }
        }

    }
View Full Code Here

     * @throws RegistryException if the operation failed.
     */
    public void createSnapshot(Resource resource,
                               boolean isRenewing,
                               boolean keepProperties) throws RegistryException {
        ResourceImpl resourceImpl = (ResourceImpl) resource;
        // archiving the old root resource
        createVersionForResource(resourceImpl, isRenewing, keepProperties);

        long version = resourceImpl.getVersionNumber();
        boolean isCollection = resourceImpl instanceof CollectionImpl;
        ResourceIDImpl rootResourceID = resourceImpl.getResourceIDImpl();
        ArrayList<Long> versionList = new ArrayList<Long>();
        versionList.add(version);
        if (isCollection) {
            // for collection we have to iterate through children
            addDescendants(rootResourceID, versionList, isRenewing, keepProperties);
        }
        // wrap the array list into stream
        InputStream versionsInputStream = new VersionInputStream(versionList);

        int pathId = rootResourceID.getPathID();
        String resourceName = rootResourceID.getName();
        long snapshotID =
                resourceVersionDAO.createSnapshot(pathId, resourceName, versionsInputStream);
        // Associations can be created only once we have created the snapshot, since we need to know
        // the snapshotID.
        if (snapshotID != -1) {
            VersionedPath versionedPath = new VersionedPath();
            versionedPath.setVersion(snapshotID);
            versionedPath.setPath(resourceImpl.getPath());
            associationDAO.copyAssociations(resourceImpl.getPath(), versionedPath.toString());
        }
    }
View Full Code Here

            String msg = "Failed to get resource id to create a snapshot to the resource " +
                    path + ". ";
            throw new RegistryException(msg);

        }
        ResourceImpl resource = resourceDAO.getResourceMetaData(resourceID);
        createSnapshot(resource, isRenewing, keepProperties);
    }
View Full Code Here

                               boolean isRenewing,
                               boolean keepProperties) throws RegistryException {
        ArrayList<ResourceIDImpl> childIds = resourceDAO.getChildPathIds(resourceID);
        // immediate children will be added before others
        for (ResourceIDImpl childId : childIds) {
            ResourceImpl childResourceImpl = resourceDAO.getResourceWithNoUpdate(childId);
            long version = childResourceImpl.getVersionNumber();
            versionList.add(version);

            // we are archiving all the resources
            createVersionForResource(childResourceImpl, isRenewing, keepProperties);
        }
View Full Code Here

TOP

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

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.