So in order to do this, you will have to import the DataObjects a different way. The dataService.upsertResources is sort of doing two things at once: it’s importing them from the file into memory and then upserting them via the dataService. You must remove that line and import the data a different way.
If you’re using LEAF 3.2.3, you can replace that code with the following:
Collection<DataObject> dataObjects = new ResourceLoader()
.loadDataObjects(
new ResourceConfigSource(<YOUR_APPLICATION>.class, "/dataobjects")
);
In older versions, you can use:
Collection<DataObject> dataObjects = this.resourceLoader.loadArbitraryJsonArrayElements(
new TypeReference<Collection<DataObject>>() {},
new ResourceConfigSource(<YOUR_APPLICATION>.class, "/dataobjects")
);
Kudos to @mark.a.alvaro for the above snippet ^.
Then process the DataObjects the way I described:
var dos = this.dataService.getDataObjectService();
var existingDOs = dos.load(
dataObjects.stream()
.map(dObj -> dObj.getId())
.collect(Collectors.toList()),
Context.makeSystemContext()
);
if (existingDOs.size() == 0) {
dos.addRoots(dataObjects, Context.makeSystemContext());
}
Since you have to remove the dataServices.upsertResources, you will most likely need to manually upsert the remaining beans that it was taking care of for you, as well:
Collection<BeanMetadata> beans = new ResourceLoader()
.loadBeanMetadata(
new ResourceConfigSource(<YOUR_APPLICATION>.class, "/beanmetadata"));
Collection<LookupList> lookupLists = new ResourceLoader()
.loadLookupLists(
new ResourceConfigSource(<YOUR_APPLICATION>.class, "/lookuplists"));
Collection<MetadataTemplate> metadataTemplates = new ResourceLoader()
.loadMetadataTemplates(
new ResourceConfigSource(<YOUR_APPLICATION>.class, "/metadatatemplates"));
this.dataService.getMetadataService()
.upsertBeanMetadata(beans, Context.makeSystemContext());
this.dataService.getLookupListService()
.upsert(lookupLists, Context.makeSystemContext());
this.dataService.getMetadataService()
.upsertTemplates(metadataTemplates, Context.makeSystemContext());