import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.core.CustomObject;
import com.filenet.api.core.Folder;
import com.filenet.api.core.ReferentialContainmentRelationship;
import com.filenet.api.util.RefreshMode;
import com.filenet.api.constants.AutoUniqueName;
import com.filenet.api.constants.DefineSecurityParentage;
public class CustomDocCreator {
public void createStudentRecord(Connection ceConnection) {
try {
// Fetch domain and target object store
Domain currentDomain = Factory.Domain.fetchInstance(ceConnection, null, null);
ObjectStore targetStore = Factory.ObjectStore.fetchInstance(currentDomain, "OSNAME", null);
// Create the custom document instance of type "StudentProfile"
CustomObject studentProfile = Factory.CustomObject.createInstance(targetStore, "StudentProfile");
// Populate the custom properties
com.filenet.api.property.Properties customProps = studentProfile.getProperties();
customProps.putValue("FullName", "StudentRecord022");
customProps.putValue("StudentID", "AX4321");
customProps.putValue("EmailAddress", "example@filenet.com");
customProps.putValue("StudentAge", 15);
DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
Date enrollmentDate = dateFormatter.parse("20/12/2015");
customProps.putValue("EnrollmentDate", enrollmentDate);
// Save the custom object
studentProfile.save(RefreshMode.REFRESH);
System.out.println("✔ Custom object created: " + studentProfile.get_Name());
// File the custom object into a predefined folder
String folderPath = "/StudentDocs";
Folder targetFolder = Factory.Folder.fetchInstance(targetStore, folderPath, null);
ReferentialContainmentRelationship folderRelation = targetFolder.file(
studentProfile,
AutoUniqueName.AUTO_UNIQUE,
null,
DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE
);
folderRelation.save(RefreshMode.REFRESH);
System.out.println("✔ Custom object filed under: " + folderPath);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}