AnsweredAssumed Answered

Display metadata

Question asked by dcrossma on Mar 1, 2007
Latest reply on Mar 1, 2007 by dcrossma
I am using Alfresco 1.4

I have the following code which gets a piece of content from my repository, I use junit to run TestGetGuestDocument()… First off I would like to display the metadata for this content such as description and size and then hopefully the custom aspects I have applied to it.Is this possible ? How is it done?

Secondly I would like generate a list of documents based on a query. I would prefer to use xpath as we have used that before, but most examples seem to be for lucene and are not complete . Any help would be appreciated

Dave

 protected static final String USERNAME = ""
    protected static final String PASSWORD = "";

    protected static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");

    protected static final Reference SAMPLE_FOLDER = new Reference(STORE, null, "/app:company_home/cm:guest_home");

    // node ref 9b2469fe-ba26-11db-8e3a-43f788d364ed

    public void testGetGuestDocument() {

        printStores();

        getGuestDocument();
    }

    private void getGuestDocument() {


        try {
            AuthenticationUtils.startSession(USERNAME, PASSWORD);
        } catch (AuthenticationFault authenticationFault) {
            authenticationFault.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }


        ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
        System.out.println("testtt"+contentService.getClass());
        if (contentService == null) {
            System.out.println("content service not available");
        }

        Reference ref = new Reference();
        ref.setUuid("9b2469fe-ba26-11db-8e3a-43f788d364ed");
        ref.setStore(STORE);

        Predicate predicate = new Predicate();
        predicate.setNodes(new Reference[]{ref});

        // call the service and make sure we get some details back
        NodeDefinition[] nodeDefs = new NodeDefinition[0];
        try {
            nodeDefs = WebServiceFactory.getRepositoryService().describe(predicate);
           
        } catch (RemoteException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        Assert.assertNotNull("nodeDefs should not be null", nodeDefs);
        Assert.assertTrue("There should be at least one result", nodeDefs.length > 0);

        NodeDefinition nodeDef = nodeDefs[0];
        Assert.assertNotNull("The nodeDef should not be null", nodeDef);
        ClassDefinition typeDef = nodeDef.getType();
        Assert.assertNotNull("Type definition should not be null", typeDef);
        System.out.println("type name = " + typeDef.getName());
        for(PropertyDefinition def:typeDef.getProperties()){
            System.out.println(""+def.getName() );
        }
       

        // Read the newly added content from the respository
        Content[] readResult = new Content[0];
        try {
            readResult = contentService.read(new Predicate(new Reference[]{ref}, STORE, null), Constants.PROP_CONTENT);
        } catch (RemoteException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        Content content = readResult[0];

        System.out.println("content url " + content.getUrl());

        ContentUtils.copyContentToFile(content, new File("/home/dcrossma/Desktop/guest.pdf"));

        AuthenticationUtils.endSession();

    }

    private void printStores() {

        // Start the session
        try {
            AuthenticationUtils.startSession(USERNAME, PASSWORD);
        } catch (AuthenticationFault authenticationFault) {
            authenticationFault.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

        try {
            // Get the respoitory service
            RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();

            // Get array of stores available in the repository
            Store[] stores = new Store[0];
            try {
                stores = repositoryService.getStores();
            } catch (RemoteException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
            if (stores == null) {
                // NOTE: empty array are returned as a null object, this is a issue with the generated web service code.
                System.out.println("There are no stores avilable in the repository.");
            } else {
                // Output the names of all the stores available in the repository
                System.out.println("The following stores are available in the repository:");
                for (Store store : stores) {

                    System.out.println(store.getScheme() + "://" + store.getAddress());
                }
            }
        }
        finally {
            // End the session
            AuthenticationUtils.endSession();
        }

    }
}

Outcomes