cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving metadata from repository

yogesh_prabhu
Champ in-the-making
Champ in-the-making
Hi,

I am working with alfresco 3.3 EE..
I have searched many results but i have not got a satisfying answer for this..
I want to access the custom metadata that i store..
i can view it in share in the metadata section and also the properties in 'view details' section of alfresco web client..
but i want to access that data..can i do it?
i believe for that i need to know where and how is the custom metadata stored..
In a post, mike had said "metadata is stored in the repository"..so can i access that data..??

Any kind of suggestions are welcome..

Thanks in advance..
3 REPLIES 3

mrogers
Star Contributor
Star Contributor
There are many interfaces to see your metadata.

You can see it through one of the UIs (Alfresco Explorer, Share or Mobile)
In the JavaApi look at the NodeService.
In the JavaScript api look at Script Node.
Or you can use the CMIS interfaces, WebScripts, WebServices, JCR or RMI.

yogesh_prabhu
Champ in-the-making
Champ in-the-making
Hi mrogers,

Thanks for your quick reply..
Sorry, i believe i had not put my question that clear in my post..

Here's the Query2.java code which when run as a java application returns me metadata values..


import java.util.ArrayList;
import java.util.List;

import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.Node;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.ResultSet;
import org.alfresco.webservice.types.ResultSetRow;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.WebServiceFactory;

public class Query2 extends SamplesBase
{   
    /**
     * Main method
     *
     * @param args
     */
    public static void main(String[] args)
    {
        Query2 sample = new Query2();
        List<ContentResult> results = sample.getRankedContent("Web Service Sample Folder", "Alfresco Development Team");
       
        // Output the results for visual inspection
        int iCount = 1;
        for (ContentResult result : results)
        {
            System.out.println("Result " + iCount + ": " + result.toString());
            iCount ++;
        }
    }
   
    /**
     * Get a list of ordered results of documents in the space specified matching the search
     * text provided.
     *
     * @param spaceName     the name of the space (immediatly beneth the company home space) to search
     * @param searchValue   the FTS search value
     * @return              list of results
     */
    public List<ContentResult> getRankedContent(String spaceName, String searchValue)
    {
        List<ContentResult> results = new ArrayList<ContentResult>();
       
        try
        {
            AuthenticationUtils.startSession(USERNAME, PASSWORD);
            try
            {           
                RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();      
               
                // Get a reference to the space we have named
                Reference reference = new Reference(STORE, null, "/app:company_home/*[@cm:name=\"" + spaceName + "\"]");
                Predicate predicate = new Predicate(new Reference[]{reference}, null, null);       
                Node[] nodes = repositoryService.get(predicate);
               
                // Create a query object, looking for all items with alfresco in the name of text
                Query query = new Query(
                        Constants.QUERY_LANG_LUCENE,
                        "+PARENT:\"workspace://SpacesStore/"+ nodes[0].getReference().getUuid() + "\" +TEXT:\"" + searchValue + "\"");
               
                // Execute the query
                QueryResult queryResult = repositoryService.query(STORE, query, false);
               
                // Display the results
                ResultSet resultSet = queryResult.getResultSet();
                ResultSetRow[] rows = resultSet.getRows();
               
                if (rows != null)
                {
                    // Get the infomation from the result set
                    for(ResultSetRow row : rows)
                    {
                        String nodeId = row.getNode().getId();
                        ContentResult contentResult = new ContentResult(nodeId);
                       
                        for (NamedValue namedValue : row.getColumns())
                        {
                            if (namedValue.getName().endsWith(Constants.PROP_CREATED) == true)
                            {
                                contentResult.setCreateDate(namedValue.getValue());
                            }
                            else if (namedValue.getName().endsWith(Constants.PROP_NAME) == true)
                            {
                                contentResult.setName(namedValue.getValue());
                            }
                            else if (namedValue.getName().endsWith(Constants.PROP_DESCRIPTION) == true)
                            {
                                contentResult.setDescription(namedValue.getValue());  
                            }
                            else if (namedValue.getName().endsWith(Constants.PROP_CONTENT) == true)
                            {
                                // We could go to the content service and ask for the content to get the URL but to save time we
                                // might as well dig the content URL out of the results.                       
                                String contentString = namedValue.getValue();
                                String[] values = contentString.split("[|=]");
                                contentResult.setUrl(values[1]);
                            }
                        }
                       
                        results.add(contentResult);
                    }
                }
            }
            finally
            {           
                // End the session
                AuthenticationUtils.endSession();
            }
        }
        catch (Exception serviceException)
        {
            throw new RuntimeException("Unable to perform search.", serviceException);
        }
       
        return results;
    }
   
    /**
     * Class to contain the information about the result from the query
     */
    public class ContentResult
    {
        private String id;
        private String name;
        private String description;
        private String url;      
        private String createDate;
       
        public ContentResult(String id)
        {
            this.id = id;
        }
       
        public String getCreateDate()
        {
            return createDate;
        }
       
        public void setCreateDate(String createDate)
        {
            this.createDate = createDate;
        }
       
        public String getDescription()
        {
            return description;
        }
       
        public void setDescription(String description)       
        {
            this.description = description;
        }
       
        public String getId()
        {
            return id;
        }

        public String getName()
        {
            return name;
        }
       
        public void setName(String name)
        {
            this.name = name;
        }
       
        public String getUrl()
        {
            return url;
        }
       
        public void setUrl(String url)
        {
            this.url = url;
        }     

        @Override
        public String toString()
        {
            return "id=" + this.id +
                   "; name=" + this.name +
                   "; description=" + this.description +
                   "; created=" + this.createDate +
                   "; url=" + this.url;
        }
    }
}

But these values are those which are inbuilt..For example: Constants.PROP_DESCRIPTION

Now, in the same way i want to access the custom metadata that i created..is it possible?

I hope i am clear in explaining my question this time..

anndrewtr
Champ in-the-making
Champ in-the-making
The inbuilt values are also null for me. Except UUID I am not able to retrieve any values. Every if condition is skipped.