cancel
Showing results for 
Search instead for 
Did you mean: 

How to get parent space name dynamically from alfresco

ramprasad_g
Champ in-the-making
Champ in-the-making
Hi,

I have a requirement to get parent space name dynamically from Alfresco repository in my Java code.
Is there any API to get parent space name.

Note: Parent space means, when we go to repository from alfresco share, we can upload files to some folders which are called as spaces.

Kindly help me out on this issue please, as it needed urgently for me.
2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
I'm not sure if you seek local API or remote API.
If local API ,you can use

   ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(child);
/code>
If remote API,you can use webscript
<code>
        /alfresco/service/api/node/{store_type}/{store_id}/{id}/parents

hariprasad
Champ in-the-making
Champ in-the-making
HI,

I need a Java Class that connect to Alfresco with the below items

1.   Upload File along with Meta Data
         public void uploadFile( ) {

   }


2.   Download File along with Meta Data
         public void downloadFile( ) {

   }

3.   Search File By Name
   public void SearchFileByName( ) {

   }

4.   Search File with Meta Data
   public void SearchFileWithMetaData( ) {

   }
   
5.   List GUIDs for Files matching the criteria
   public void listOfGuids( ) {

   }
6.   Search File by GUID

   public void searchGuid( ) {

   }
……………………………..
I have implemented in the below class for uploading to Alfresco,
i need similarly in different methods for the other items mentioned above,
could you please help on this,
………………………………..
public class AlfrescoUtil {

   public static void main(String args[]) throws Exception {
      String fileName = "upload.jpg";
      WebServiceFactory.setEndpointAddress("http://localhost:8080/alfresco/soapapi");
      AuthenticationUtils.startSession("admin", "admin");
      ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
      RepositoryServiceSoapBindingStub repositoryService =WebServiceFactory.getRepositoryService();
      
      Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
      String parentSpace = "/app:company_home/cm:ACH_Space";
      ParentReference parentReference = new ParentReference (storeRef, null, parentSpace, Constants.ASSOC_CONTAINS, null);
      parentReference.setChildName("cm:"+ fileName);
      
      NamedValue[] contentProps = new NamedValue[3];
      contentProps[0] = Utils.createNamedValue(Constants.PROP_TITLE,fileName);
      contentProps[1] = Utils.createNamedValue(Constants.PROP_DESCRIPTION, fileName);
      contentProps[2] = Utils.createNamedValue(Constants.PROP_NAME, fileName);
      
      NamedValue[] aspectProps = new NamedValue[3];
      aspectProps[0] = Utils.createNamedValue("{mandate}UMRN","18062014_01");
      aspectProps[1] = Utils.createNamedValue("{mandate}IRN", "18062014_01");
      aspectProps[2] = Utils.createNamedValue("{mandate}status", "TDS");
      
      CMLAddAspect addAspect = new CMLAddAspect();
      addAspect.setAspect("{mandate}mandateImage");
      addAspect.setProperty(aspectProps);
      addAspect.setWhere(new Predicate(new Reference[] { parentReference }, null, null));
        addAspect.setWhere_id("1");
            
      CMLCreate create = new CMLCreate("1", parentReference, parentReference.getUuid(), Constants.ASSOC_CONTAINS,null, Constants.PROP_CONTENT, contentProps);
      
      CML cml = new CML();
      cml.setCreate(new CMLCreate[] { create });
      cml.setAddAspect(new CMLAddAspect[] { addAspect });   
      UpdateResult[] result1 = repositoryService.update(cml);      
      Reference content = result1[0].getDestination();
      FileInputStream is = new FileInputStream("C:\\Users\\0021083\\Desktop\\PostGoLive4.jpg");
      
      byte[] bytes = ContentUtils.convertToByteArray(is);
      
      ContentFormat format = new ContentFormat("image/jpeg", "UTF-8");            
      contentService.write(content, Constants.PROP_CONTENT, bytes,format);
      System.out.println("File Uploaded Successfully");
   }