My Oracle Support Banner

How To Move A Folder Using the Content DB WebServices SDK (Doc ID 1213643.1)

Last updated on SEPTEMBER 20, 2023

Applies to:

Oracle Content Services - Version 10.2.0.0.0 to 10.2.1.0.19 [Release AS10gR3]
Information in this document applies to any platform.

Goal

This note provides sample code to move a Content DB folder to a new destination.

Simply add the code below in a file called MoveFolder.java under <SDK_location>\cdb\src\oracle\ifs\examples\api and run it as a sample.

Update the folderToMove and destination strings below:
folderToMove is the full path of the folder you want to move to a location
folderToMoveTo is the path of the location where you want to move the folder to

-----------------<CUT>-------------------------

package oracle.ifs.examples.api;

import oracle.ifs.examples.api.util.CommonUtils;
import oracle.ifs.examples.api.util.SamplesConfiguration;

import oracle.ifs.fdk.AttributeRequest;
import oracle.ifs.fdk.Attributes;
import oracle.ifs.fdk.ClientUtils;
import oracle.ifs.fdk.FdkConstants;
import oracle.ifs.fdk.FdkCredential;
import oracle.ifs.fdk.Item;
import oracle.ifs.fdk.ManagersFactory;
import oracle.ifs.fdk.NamedValue;
import oracle.ifs.fdk.SimpleFdkCredential;
import oracle.ifs.fdk.SessionManager;
import oracle.ifs.fdk.FileManager;
import oracle.ifs.fdk.NamedValueSet;
import oracle.ifs.fdk.Options;

public class MoveFolder
{
private static SamplesConfiguration s_Config =
SamplesConfiguration.getInstance();

public static void main(String[] args)
{

System.out.println("MoveFolder: starting");

FdkCredential credential = new SimpleFdkCredential(
s_Config.getAdminUserName(), s_Config.getAdminUserPassword());

ManagersFactory session = null;
try
{
session = ManagersFactory.login(credential, s_Config.getCDBUrl());

AttributeRequest[] requestedAttributes = new AttributeRequest[]
{
ClientUtils.newAttributeRequest(Attributes.DOMAIN,
CommonUtils.newAttributeRequestArray(
new String[] { Attributes.PATH, Attributes.CAPABILITIES })
)
};

Item user = session.getUser(requestedAttributes);
System.out.println("Connected user: "+user.getName());

SessionManager sessionM = session.getSessionManager();
FileManager fileM = session.getFileManager();

sessionM.setSessionMode(FdkConstants.SESSION_MODE_DOMAIN_ADMINISTRATION, null);

// Here the action begins!

try{

String folderToMove = "/be/users/Users-O/orcladmin/child";
String folderToMoveTo = "/be/users/Users-O/orcladmin/parent";
Item sourceFolder = null;
Item destinationFolder = null;

//Read File Line By Line
System.out.println("Searching for source folder in ContentDB: "+folderToMove);

requestedAttributes = new AttributeRequest[] {
ClientUtils.newAttributeRequest(Attributes.LOCKS),
};

sourceFolder = fileM.resolvePath(folderToMove, requestedAttributes);

if (sourceFolder==null) System.out.println("ERROR: Folder not found at this path");
else
{
System.out.println("folder found (ID="+sourceFolder.getId()+")");

System.out.println("Searching for destination folder in ContentDB: "+folderToMoveTo);
destinationFolder = fileM.resolvePath(folderToMoveTo,requestedAttributes);

if (destinationFolder==null)
{ System.out.println("ERROR: Destination folder ("+folderToMoveTo+") does not exist"); }
else
{ System.out.println("folder found (ID="+destinationFolder.getId()+")");
System.out.println("Attempting to move folder");

long[] items = new long[]{ sourceFolder.getId() };

NamedValueSet[] namedValueSets = new NamedValueSet[] { new NamedValueSet() };
NamedValue[] namedvalues = new NamedValue[]
{ ClientUtils.newNamedValue( Attributes.NAME, sourceFolder.getName() ),
ClientUtils.newNamedValue( Options.DESTFOLDER, new Long(destinationFolder.getId()) ),
ClientUtils.newNamedValue( Options.OVERWRITE, Boolean.TRUE),
ClientUtils.newNamedValue( Options.UNIQUENAME, Boolean.FALSE ),
ClientUtils.newNamedValue( Options.NEWVERSION, Boolean.FALSE )
};
namedValueSets[0].setNamedValues( namedvalues );
try {
fileM.move( items , null, namedValueSets );
System.out.println("SUCCESS: Folder was moved!");
} catch ( Exception e) {
System.out.println("ERROR MOVING FOLDER");
e.printStackTrace();
}
}
}

}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}

}
catch (Throwable t)
{
System.out.println(t);
}
finally
{
CommonUtils.bestEffortLogout(session);
System.out.println("-----------------------------------------------------------");
System.out.println("DONE");
}
}

}

-----------------<CUT>-------------------------

Solution

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Goal
Solution
References


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.