Thursday, October 14, 2010

create content in specific loaction in the repository

Using DFS service  create content in specific loaction in the repository .



using this code i can able to create content in home cabinet ot the repository but how can i do in specific location
    File file = new File("E:\\filepath"+fileName);

IObjectService objectService=ServiceFactory.getInstance().getService(IObjectService.class,
                    context,
                    serviceModule,
                    contextRoot);
               ObjectIdentity objIdentity = new ObjectIdentity(repositoryName);
            DataObject dataObject = new DataObject(objIdentity,"dm_document");
            PropertySet properties = dataObject.getProperties();
            properties.set("object_name", fileName);
            FileContent fileContent = new FileContent();
            fileContent.setLocalPath(file.getAbsolutePath());
            dataObject.getContents().add(fileContent);
     
            PropertyProfile propertyProfile = new PropertyProfile();
            propertyProfile.setFilterMode(PropertyFilterMode.ALL);
            OperationOptions operationOptions = new OperationOptions();
            operationOptions.setProfile(propertyProfile);
            DataPackage newFilePropertiesInfo = objectService.create(new DataPackage(dataObject), operationOptions);


Sol--1--If you want to push content to a specific location pointed by file path, the standard way is to create a location object(dm_location) pointed by that file path,Then create file store pointing to that location object. Once it is done, you can push content either by setting a_storage_type attribute on each instance of dm_document or by creating an assignment policy with the appropriate rules to push content to that storage(create assingment with appropriate rules dones that automatically).


Sol--2--
I guess you are looking to create the content in specific cabinet/folder in docbase.
I am a newbie to DFS coding. So I will try.

I think you can add a relationship between document and folder dataObjects like this:


public void addChildObject(DataObject folder, DataObject childDoc)
    {
        folder.getRelationships().add(
            new ObjectRelationship(childDoc, Relationship.RELATIONSHIP_FOLDER, Relationship.ROLE_CHILD)
        );
    }

In case you dont have the folder DataObject, you can query for it as follows:

private DataObject queryFolderDataObject(String folderName) throws Exception
    {
        String query = "select r_object_id from dm_folder where any r_folder_path = 'folderName';           // Of the form'/" + cabinetName + "/<your_path>"' Take care of nasty single quotes in the folder name.
        PassthroughQuery query = new PassthroughQuery(Arrays.asList("YourDocbase"), queryString);
        QueryExecution execution = new QueryExecution();       
                                 //  create default OperationOptions using getQueryService().getServiceContext()
        QueryResult result = getQueryService().execute(query, execution, null);
        return result.getDataObjects().get(0);
       
    }


From DFC, You can achieve it through setRepeatingString call on the sysobject:
sysObject.setRepeatingString("r_folder_path",0,"your_path");

Or you can set it on the operation after doing above query if you are creating content through Import operation:
operation.setDestinationFolderId("folder_id_from_query");

1 comment:

  1. DFC is giving an error message "r_folder_path is not updateable'. Any ideas how to resolve it?

    ReplyDelete