当前位置: 首页>>代码示例>>Java>>正文


Java Resource.discard方法代码示例

本文整理汇总了Java中org.wso2.carbon.registry.core.Resource.discard方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.discard方法的具体用法?Java Resource.discard怎么用?Java Resource.discard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.wso2.carbon.registry.core.Resource的用法示例。


在下文中一共展示了Resource.discard方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProperty

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static String getProperty(UserRegistry registry,
                                 String resourcePath, String key) throws RegistryException {

    try {
        if (registry.resourceExists(resourcePath)) {
            
            Resource resource = registry.get(resourcePath);
            if (resource != null) {
                String value = resource.getProperty(key);
                resource.discard();
                return value;
            }
        }
        
    } catch (RegistryException e) {

        String msg = "Failed to get the resource information of resource " + resourcePath +
                " for retrieving a property with key : " + key + ". Error :" +
                ((e.getCause() instanceof SQLException) ?
                "" : e.getMessage());
        log.error(msg, e);
        throw e;
    }

    return "";
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:27,代码来源:GetPropertyUtil.java

示例2: testImportResource

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testImportResource() throws Exception {

        String[][] properties = new String[][]{{"key1", "val1"}, {"key2", "val2"}};


        String path = ImportResourceUtil.importResource("/test/2017/10", "25", "application/xml", "Sample description",
                                                        "http://blog.napagoda.com/", "test", (UserRegistry) registry,
                                                        properties);

        assertEquals("/test/2017/10/25", path);
        Resource resource = registry.get("/test/2017/10/25");
        assertEquals("application/xml", resource.getMediaType());
        assertEquals("Sample description", resource.getDescription());
        assertEquals("val1", resource.getPropertyValues("key1").get(0));
        assertEquals("val2", resource.getProperty("key2"));
        resource.discard();

    }
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:19,代码来源:ImportResourceUtilTest.java

示例3: setProperty

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
 * Method to add a property, if there already exist a property with the same name, this
 * will add the value to the existing property name. (So please remove the old property with
 * the same name before calling this method).
 *
 * @param path path of the resource.
 * @param name property name.
 * @param value property value.
 *
 * @throws RegistryException throws if there is an error.
 */
public void setProperty(String path, String name, String value) throws RegistryException {

    if(name != null && name.startsWith("registry.")) {
        throw new RegistryException("Property cannot start with the \"registry.\" prefix. " +
                "Property name " + name + ". Resource path = " + path);
    }
    UserRegistry registry = (UserRegistry) getRootRegistry();
    if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) {
        return;
    }
    Resource resource = registry.get(path);

    if(resource.getProperties().keySet().contains(name)) {
        throw new RegistryException("Cannot duplicate property name. Please choose a different name. " +
                "Property name " + name + ". Resource path = " + path);
    }

    resource.addProperty(name, value);
    registry.put(resource.getPath(), resource);
    resource.discard();
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:33,代码来源:PropertiesAdminService.java

示例4: provideChildAssociations

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private static List provideChildAssociations(
        String path, String assoType, UserRegistry registry)
        throws RegistryException {

    List tmpAssociations = new ArrayList();
    List associations = new ArrayList();
    ResourcePath resourcePath = new ResourcePath(path);
    Resource resource = registry.get(path);
    Association[] asso = CommonUtil.getAssociations(registry, (resourcePath.isCurrentVersion() ?
            resourcePath.getPath() : resourcePath.getPathWithVersion()));

    tmpAssociations.addAll(Arrays.asList(asso));

    Iterator iAssociations = tmpAssociations.iterator();
    while (iAssociations.hasNext()) {
        Association tmpAsso = (Association) iAssociations.next();
        //Get all associations filtered by it's association type
            if (tmpAsso.getAssociationType().equals(CommonConstants.ASSOCIATION_TYPE01)
                    && assoType.equals(CommonConstants.ASSOCIATION_TYPE01) && tmpAsso.getSourcePath().equals(path))
                associations.add(tmpAsso);
            if (!tmpAsso.getAssociationType().equals(CommonConstants.ASSOCIATION_TYPE01)
                    && !assoType.equals(CommonConstants.ASSOCIATION_TYPE01) && tmpAsso.getSourcePath().equals(path))
                associations.add(tmpAsso);
    }

    resource.discard();
    // if path is equal to the destination path, it is a backward association. we are only displaying
    // the forward associations here

    return associations;
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:32,代码来源:AssociationTreeBeanPopulator.java

示例5: setDescription

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static void setDescription(UserRegistry registry,
                                  String path, String description) throws Exception {

    Resource resource = registry.get(path);
    resource.setDescription(description);
    registry.put(path, resource);
    resource.discard();
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:9,代码来源:DescriptionUtil.java

示例6: testContinuousUpdate

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testContinuousUpdate() throws Exception {

        int iterations = 100;

        for (int i = 0; i < iterations; i++) {

            Resource res1 = registry.newResource();
            byte[] r1content = RegistryUtils.encodeString("R2 content");
            res1.setContent(r1content);
            String path = "/con-delete/test-update/" + i + 1;

            registry.put(path, res1);

            Resource resource1 = registry.get(path);

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

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

            registry.put(path, resource);

            Resource resource2 = registry.get(path);

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

            resource.discard();
            res1.discard();
            resource1.discard();
            resource2.discard();
            Thread.sleep(100);
        }
    }
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:38,代码来源:ContinuousOperations.java

示例7: addTextResource

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static void addTextResource(
        String parentPath,
        String resourceName,
        String mediaType,
        String description,
        String contentString,
        UserRegistry userRegistry) throws Exception {

    String resourcePath;
    if (RegistryConstants.ROOT_PATH.equals(parentPath)) {
        resourcePath = RegistryConstants.ROOT_PATH + resourceName;
    } else {
        resourcePath = parentPath + RegistryConstants.PATH_SEPARATOR + resourceName;
    }

    byte[] content = null;
    if (contentString != null) {
        content = RegistryUtils.encodeString(contentString);
    }

    try {
        Resource resource = userRegistry.newResource();
        resource.setProperty(CommonConstants.SOURCE_PROPERTY, CommonConstants.SOURCE_ADMIN_CONSOLE);
        resource.setMediaType(mediaType);
        resource.setDescription(description);
        resource.setContent(RegistryUtils.decodeBytes(content));

        userRegistry.put(resourcePath, resource);
        resource.discard();

    } catch (RegistryException e) {
        String msg = "Failed to add resource with text based content to path " +
                resourcePath + ". " + ((e.getCause() instanceof SQLException) ?
                "" : e.getMessage());
        log.error(msg, e);
        throw new RegistryException(msg, e);
    }
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:39,代码来源:AddTextResourceUtil.java

示例8: updateTextContent

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static void updateTextContent(String path, String contentText, Registry registry)
        throws Exception {

    try {
        Resource resource = registry.get(path);
        String mediaType = resource.getMediaType();
        if (resource.getProperty(RegistryConstants.REGISTRY_LINK) != null &&
                (CommonConstants.WSDL_MEDIA_TYPE.equals(mediaType) ||
                        CommonConstants.SCHEMA_MEDIA_TYPE.equals(mediaType))) {
            String description = resource.getDescription();
            Properties properties = (Properties) resource.getProperties().clone();
            resource = registry.newResource();
            resource.setMediaType(mediaType);
            resource.setDescription(description);
            resource.setProperties(properties);
        }
        resource.setContent(RegistryUtils.encodeString(contentText));
        registry.put(path, resource);
        resource.discard();

    } catch (RegistryException e) {

        String msg = "Could not update the content of the resource " +
                path + ". Caused by: " + ((e.getCause() instanceof SQLException) ?
                "" : e.getMessage());
        log.error(msg, e);
        throw new RegistryException(msg, e);
    }
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:30,代码来源:UpdateTextContentUtil.java

示例9: getTextContent

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public static String getTextContent(String path, Registry registry) throws Exception {

        try {
            if (path != null && path.contains("..")) {
                path = FilenameUtils.normalize(path);
            }

            Resource resource = registry.get(path);

            byte[] content = (byte[]) resource.getContent();
            String contentString = "";
            if (content != null) {
                contentString = RegistryUtils.decodeBytes(content);
            }
            resource.discard();

            return contentString;

        } catch (RegistryException e) {

            String msg = "Could not get the content of the resource " +
                    path + ". Caused by: " + ((e.getCause() instanceof SQLException) ?
                    "" : e.getMessage());
            log.error(msg, e);
            throw new RegistryException(msg, e);
        }
    }
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:28,代码来源:GetTextContentUtil.java

示例10: updateProperty

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
 * Method to update a property (This removes the old property with the oldName)
 *
 * @param path path of the resource.
 * @param name property name.
 * @param value property value.
 * @param oldName old name of the property.
 *
 * @throws RegistryException throws if there is an error.
 */
public void updateProperty(String path, String name, String value, String oldName) throws
        RegistryException {

    if(name != null && name.startsWith("registry.")) {
        throw new RegistryException("Property cannot start with the \"registry.\" prefix. " +
                "Property name " + name + ". Resource path = " + path);
    }

    UserRegistry registry = (UserRegistry) getRootRegistry();
    if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) {
        return;
    }
    Resource resource = registry.get(path);

    if(resource.getProperties().keySet().contains(name) && !name.equals(oldName)) {
        throw new RegistryException("Cannot duplicate property name. Please choose a different name. " +
                "Property name " + name + ". Resource path = " + path);
    }

    if (oldName.equals(name)) {
        resource.setProperty(name, value);
    } else {
        resource.setProperty(name, value);
        resource.removeProperty(oldName);
    }
    registry.put(resource.getPath(), resource);
    resource.discard();
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:39,代码来源:PropertiesAdminService.java

示例11: removeProperty

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
/**
 * Method to remove property.
 *
 * @param path path of the resource.
 * @param name property name.
 *
 * @throws RegistryException throws if there is an error.
 */
public void removeProperty(String path, String name) throws RegistryException {
    UserRegistry registry = (UserRegistry) getRootRegistry();
    if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) {
        return;
    }
    Resource resource = registry.get(path);
    resource.removeProperty(name);
    registry.put(resource.getPath(), resource);
    resource.discard();
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:19,代码来源:PropertiesAdminService.java

示例12: testGetCollectionoperation

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void testGetCollectionoperation() throws Exception {

        Resource r2 = registry.newCollection();
        String path = "/testk2/testa/testc";
        r2.setDescription("this is test desc");
        r2.setProperty("test2", "value2");
        registry.put(path, r2);

        r2.discard();

        Resource r3 = registry.get(path);

//        assertEquals("Author names are not Equal", "admin", r3.getAuthorUserName());
//        assertEquals("Author User names are not Equal", "admin", r3.getAuthorUserName());
        // System.out.println(r3.getCreatedTime());
        //assertNotNull("Created time is null", r3.getCreatedTime());
//        assertEquals("Author User names are not Equal", "admin", r3.getAuthorUserName());
        //System.out.println("Desc" + r3.getDescription());
        //assertEquals("Description is not Equal", "this is test desc", r3.getDescription());
        assertNotNull("Get Id is null", r3.getId());
        assertNotNull("LastModifiedDate is null", r3.getLastModified());
        assertEquals("Last Updated names are not Equal", "admin", r3.getLastUpdaterUserName());
        //System.out.println("Media Type:" + r3.getMediaType());
        //assertEquals("Media Type is not equal","unknown",r3.getMediaType());
        assertEquals("parent Path is not equal", "/testk2/testa", r3.getParentPath());
        assertEquals("Get stated wrong", 0, r3.getState());

        registry.createVersion(path);

//         System.out.println(r3.getParentPath());
//      System.out.println(r3.getPath());

        assertEquals("Permenent path doesn't contanin the string", "/testk2/testa", r3.getParentPath());
        assertEquals("Path doesn't contanin the string", path, r3.getPath());

//        String st = r3.getPermanentPath();
//        assertTrue("Permenent path contanin the string" + path +" verion", st.contains("/testk2/testa/testc;version:"));


    }
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:41,代码来源:ResourceHandling.java

示例13: run

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
public void run() {

        long time1 = System.nanoTime();
        long timePerThread = 0;
        //RemoteRegistry registry = null;
        Resource resource = null;
        try {
            //System.setProperty("javax.net.ssl.trustStore", "G:\\testing\\wso2registry-SNAPSHOT\\resources\\security\\client-truststore.jks");
            //System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
            //System.setProperty("javax.net.ssl.trustStoreType", "JKS");
            //registry = new RemoteRegistry(new URL("https://10.100.1.136:9443/registry/"), "admin", "admin");
            //registry = new RemoteRegistry(new URL("https://10.100.1.235:9443/registry/"), "admin", "admin");
            Resource resource1 = registry.newResource();
            resource1.setContent("ABC");
            registry.put("/ama/test/path", resource1);
            for (int i = 0; i < iterations; i++) {
                long start = System.nanoTime();
                Resource res = registry.newResource();
                res.setContent("abc");
                registry.put("/test/" + i, res);
                System.out.println("Updated " + i);
                resource = registry.get("/ama/test/path");
                resource.setContent("updated");
                resource.setProperty("abc", "abc");
                registry.put("/ama/test/path", resource);
                resource.discard();
                long end = System.nanoTime();
                timePerThread += (end - start);

                Thread.sleep(100);
            }
            long averageTime = timePerThread / (iterations * 1000000);
            System.out.println("CSV-avg-time-per-thread," + threadName + "," + averageTime);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:39,代码来源:Worker5.java

示例14: loadResourceByPath

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private ResourceData loadResourceByPath(UserRegistry registry, String path) throws RegistryException {
	ResourceData resourceData = new ResourceData();
	resourceData.setResourcePath(path);

	if (path != null) {
		if (RegistryConstants.ROOT_PATH.equals(path)) {
			resourceData.setName("root");
		} else {
			String[] parts = path.split(RegistryConstants.PATH_SEPARATOR);
			resourceData.setName(parts[parts.length - 1]);
		}
	}
       Resource child;
       //---------------------------------------------------------------------------------------------------------Ajith
       //This fix is to improve the performance of the artifact search
       //When we delete the artifacts that goes to activity logs and Solr indexer delete that resource from indexed
       //files as well. Therefore no need an extra ResourceExist() check for the result path which is returned
       //from Solr search.
       try {
           child = registry.get(path);
       } catch (RegistryException e) {
           log.debug("Failed to load resource from path which is returned from Solr search" + e.getMessage());
           return null;
       }
       //---------------------------------------------------------------------------------------------------------Ajith
	resourceData.setResourceType(child instanceof Collection ? "collection"
			: "resource");
	resourceData.setAuthorUserName(child.getAuthorUserName());
	resourceData.setDescription(child.getDescription());
	resourceData.setAverageRating(registry
			.getAverageRating(child.getPath()));
	Calendar createdDateTime = Calendar.getInstance();
	createdDateTime.setTime(child.getCreatedTime());
	resourceData.setCreatedOn(createdDateTime);
	CommonUtil.populateAverageStars(resourceData);

	String user = child.getProperty("registry.user");

	if (registry.getUserName().equals(user)) {
		resourceData.setPutAllowed(true);
		resourceData.setDeleteAllowed(true);
		resourceData.setGetAllowed(true);
	} else {
		resourceData.setPutAllowed(
			UserUtil.isPutAllowed(registry.getUserName(), path, registry));
		resourceData.setDeleteAllowed(
			UserUtil.isDeleteAllowed(registry.getUserName(), path, registry));
		resourceData.setGetAllowed(
			UserUtil.isGetAllowed(registry.getUserName(), path, registry));
	}

	child.discard();

	return resourceData;
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:56,代码来源:ContentBasedSearchService.java

示例15: searchByTags

import org.wso2.carbon.registry.core.Resource; //导入方法依赖的package包/类
private static ResourceData [] searchByTags(String tag, UserRegistry registry)
        throws RegistryException {

    ResourceData[] resourceDataList = new ResourceData[0];

    if (tag != null && tag.length() != 0) {
        TaggedResourcePath[] taggedPaths = registry.getResourcePathsWithTag(tag);
        resourceDataList = new ResourceData [taggedPaths.length];
        for (int i=0; i<taggedPaths.length; i++) {
            String resultPath = taggedPaths[i].getResourcePath();

            ResourceData resourceData = new ResourceData();
            resourceData.setResourcePath(resultPath);

            if (resultPath != null) {
                if (resultPath.equals(RegistryConstants.ROOT_PATH)) {
                    resourceData.setName(RegistryConstants.ROOT_PATH);
                } else {
                    String[] parts = resultPath.split(RegistryConstants.PATH_SEPARATOR);
                    resourceData.setName(parts[parts.length - 1]);
                }
            }

            try {
                Resource child = registry.get(resultPath);

                resourceData.setResourceType(child instanceof Collection ?
                        "collection" : "resource");
                resourceData.setAuthorUserName(child.getAuthorUserName());
                resourceData.setDescription(child.getDescription());
                resourceData.setAverageRating(registry.getAverageRating(child.getPath()));
                Calendar createdDateTime = Calendar.getInstance();
                createdDateTime.setTime(child.getCreatedTime());
                resourceData.setCreatedOn(createdDateTime);

                Map counts = taggedPaths[i].getTagCounts();
                Object [] keySet = counts.keySet().toArray();
                TagCount [] tagCounts = new TagCount [counts.size()];
                for(int j=0; j<counts.size(); j++) {
                    TagCount tagCount = new TagCount();
                    tagCount.setKey((String)keySet[j]);
                    tagCount.setValue((Long)counts.get(keySet[j]));
                    tagCounts[j] = tagCount;
                }
                resourceData.setTagCounts(tagCounts);
                
                CommonUtil.populateAverageStars(resourceData);

                child.discard();

                resourceDataList[i] = resourceData;

            } catch (AuthorizationFailedException e) {
                // do not show unauthorized resources in search results
            }
        }
    }
    return resourceDataList;
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:60,代码来源:SearchResultsBeanPopulator.java


注:本文中的org.wso2.carbon.registry.core.Resource.discard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。