Class EntityImportExportImpl
- All Implemented Interfaces:
EntityImportExport
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected AccessConstraintsRegistry
protected AccessManager
protected org.springframework.context.ApplicationContext
protected CoreProperties
protected UnconstrainedDataManager
protected EntitySerialization
protected EntityStates
protected EntityAttributeImportExtensionResolver
protected FetchPlanRepository
protected FetchPlans
protected Metadata
protected MetadataTools
protected ReferenceToEntitySupport
protected Stores
protected jakarta.validation.Validator
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
assertToken
(Object entity, FetchPlan fetchPlan) protected FetchPlanBuilder
constructFetchPlanFromImportPlan
(EntityImportPlan importPlan) protected Collection<Object>
createNewCollection
(MetaProperty metaProperty) exportEntitiesToJSON
(Collection<Object> entities) Serializes a collection of entities to JSON usingEntitySerialization
.exportEntitiesToJSON
(Collection<Object> entities, FetchPlan fetchPlan) Serializes a collection of entities to JSON usingEntitySerialization
.byte[]
exportEntitiesToZIP
(Collection<Object> entities) Serializes a collection of entities to JSON usingEntitySerialization
and packs the JSON file into ZIP archive.byte[]
exportEntitiesToZIP
(Collection<Object> entities, FetchPlan fetchPlan) Serializes a collection of entities to JSON usingEntitySerialization
and packs the JSON file into ZIP archive.protected Object
findReferenceEntity
(Object entity, EntityImportPlanProperty importPlanProperty, SaveContext saveContext, Set<Object> loadedEntities) protected Collection<Object>
getFilteredIds
(SecurityState securityState, String propertyName) protected Object
importEmbeddedAttribute
(Object srcEntity, Object dstEntity, boolean createOp, EntityImportPlanProperty importPlanProperty, FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLock) importEntities
(Collection<Object> entities, EntityImportPlan importPlan, boolean validate, boolean optimisticLocking, boolean additionComposition) importEntities
(Collection entities, EntityImportPlan importPlan) importEntities
(Collection entities, EntityImportPlan importPlan, boolean validate) Persists entities according to the rules, described by theimportPlan
parameter.importEntities
(Collection entities, EntityImportPlan importPlan, boolean validate, boolean optimisticLocking) Persists entities according to the rules, described by theimportPlan
parameter.importEntitiesFromJson
(String json, EntityImportPlan importPlan) Deserializes the JSON and persists deserialized entities according to the rules, described by theimportPlan
parameter.importEntitiesFromZIP
(byte[] zipBytes, EntityImportPlan importPlan) Reads a zip archive that contains a JSON file, deserializes the JSON and persists deserialized entities according to the rules, described by theimportPlan
parameter.protected Object
importEntity
(Object srcEntity, Object dstEntity, EntityImportPlan importPlan, FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLocking, boolean additionComposition) Method imports the entity.void
importEntityIntoSaveContext
(SaveContext saveContext, Object srcEntity, EntityImportPlan importPlan, boolean validate) void
importEntityIntoSaveContext
(SaveContext saveContext, Object srcEntity, EntityImportPlan importPlan, boolean validate, boolean optimisticLocking) void
importEntityIntoSaveContext
(SaveContext saveContext, Object srcEntity, EntityImportPlan importPlan, boolean validate, boolean optimisticLocking, boolean additionComposition) protected void
importManyToManyCollectionAttribute
(Object srcEntity, Object dstEntity, EntityImportPlanProperty importPlanProperty, FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLocking) protected void
importOneToManyCollectionAttribute
(Object srcEntity, Object dstEntity, EntityImportPlanProperty importPlanProperty, FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLocking, boolean additionalComposition) protected void
importReference
(Object srcEntity, Object dstEntity, EntityImportPlanProperty importPlanProperty, FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLocking) protected org.apache.commons.compress.archivers.ArchiveEntry
newStoredEntry
(String name, byte[] data) protected void
processReferenceInfo
(EntityImportExportImpl.ReferenceInfo referenceInfo, SaveContext saveContext, Set<Object> loadedEntities) Method finds and set a reference value to the entity or throws EntityImportException if ERROR_ON_MISSING policy is violatedprotected byte[]
readBytesFromEntry
(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream archiveReader) protected Collection
reloadEntities
(Collection<Object> entities, FetchPlan fetchPlan) protected void
validateEntities
(Collection<Object> entitiesToValidate)
-
Field Details
-
entitySerialization
-
metadata
-
dataManager
-
metadataTools
-
fetchPlans
-
validator
@Autowired protected jakarta.validation.Validator validator -
stores
-
applicationContext
@Autowired protected org.springframework.context.ApplicationContext applicationContext -
fetchPlanRepository
-
referenceToEntitySupport
-
entityStates
-
accessConstraintsRegistry
-
accessManager
-
coreProperties
-
extensionResolver
-
-
Constructor Details
-
EntityImportExportImpl
public EntityImportExportImpl()
-
-
Method Details
-
exportEntitiesToZIP
Description copied from interface:EntityImportExport
Serializes a collection of entities to JSON using
EntitySerialization
and packs the JSON file into ZIP archive. Before the serialization entities will be reloaded with the fetch plan passed as method parameter.Serialization is described in the
EntitySerialization.toJson(Collection)
method documentation- Specified by:
exportEntitiesToZIP
in interfaceEntityImportExport
- Parameters:
entities
- a collection of entities to exportfetchPlan
- before serialization to JSON entities will be reloaded with this fetch plan- Returns:
- a byte array of zipped JSON file
-
exportEntitiesToZIP
Description copied from interface:EntityImportExport
Serializes a collection of entities to JSON using
EntitySerialization
and packs the JSON file into ZIP archive.Serialization is described in the
EntitySerialization.toJson(Collection)
method documentation- Specified by:
exportEntitiesToZIP
in interfaceEntityImportExport
- Parameters:
entities
- a collection of entities to export- Returns:
- a byte array of zipped JSON file
-
exportEntitiesToJSON
Description copied from interface:EntityImportExport
Serializes a collection of entities to JSON using
EntitySerialization
. Before the serialization entities will be reloaded with the fetch plan passed as method parameter.Serialization is described in the
EntitySerialization.toJson(Collection)
method documentation- Specified by:
exportEntitiesToJSON
in interfaceEntityImportExport
- Parameters:
entities
- a collection of entities to exportfetchPlan
- before serialization to JSON entities will be reloaded with this fetch plan- Returns:
- a JSON string
-
exportEntitiesToJSON
Description copied from interface:EntityImportExport
Serializes a collection of entities to JSON using
EntitySerialization
.Serialization is described in the
EntitySerialization.toJson(Collection)
method documentation- Specified by:
exportEntitiesToJSON
in interfaceEntityImportExport
- Parameters:
entities
- a collection of entities to export- Returns:
- a JSON string
-
reloadEntities
-
newStoredEntry
protected org.apache.commons.compress.archivers.ArchiveEntry newStoredEntry(String name, byte[] data) -
importEntitiesFromJson
Description copied from interface:EntityImportExport
Deserializes the JSON and persists deserialized entities according to the rules, described by theimportPlan
parameter. If the entity is not present in the database, it will be saved. Otherwise the fields of the existing entity that are in theimportPlan
will be updated.- Specified by:
importEntitiesFromJson
in interfaceEntityImportExport
- Parameters:
json
- JSON file containing entitiesimportPlan
-EntityImportPlan
with the rules that describes how entities should be persisted.- Returns:
- a collection of entities that have been imported
- See Also:
-
importEntitiesFromZIP
Description copied from interface:EntityImportExport
Reads a zip archive that contains a JSON file, deserializes the JSON and persists deserialized entities according to the rules, described by theimportPlan
parameter. If the entity is not present in the database, it will be saved. Otherwise the fields of the existing entity that are in theimportPlan
will be updated.- Specified by:
importEntitiesFromZIP
in interfaceEntityImportExport
- Parameters:
zipBytes
- byte array of ZIP archive with JSON fileimportPlan
-EntityImportPlan
with the rules that describes how entities should be persisted.- Returns:
- a collection of entities that have been imported
- See Also:
-
readBytesFromEntry
protected byte[] readBytesFromEntry(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream archiveReader) throws IOException - Throws:
IOException
-
importEntities
Description copied from interface:EntityImportExport
SeeEntityImportExport.importEntities(Collection, EntityImportPlan, boolean)
. The current method doesn't perform bean validation- Specified by:
importEntities
in interfaceEntityImportExport
-
importEntities
public Collection importEntities(Collection entities, EntityImportPlan importPlan, boolean validate) Description copied from interface:EntityImportExport
Persists entities according to the rules, described by theimportPlan
parameter. If the entity is not present in the database, it will be saved. Otherwise the fields of the existing entity that are in theimportPlan
will be updated.If the import plan contains a property for composition attribute then all composition collection members that are absent in the passed entity will be removed.
- Specified by:
importEntities
in interfaceEntityImportExport
importPlan
-EntityImportPlan
with the rules that describes how entities should be persisted.validate
- whether the passed entities should be validated by the bean validation mechanism before entities are persisted- Returns:
- a collection of entities that have been imported
-
importEntities
public Collection importEntities(Collection entities, EntityImportPlan importPlan, boolean validate, boolean optimisticLocking) Description copied from interface:EntityImportExport
Persists entities according to the rules, described by theimportPlan
parameter. If the entity is not present in the database, it will be saved. Otherwise the fields of the existing entity that are in theimportPlan
will be updated.If the import plan contains a property for composition attribute then all composition collection members that are absent in the passed entity will be removed.
- Specified by:
importEntities
in interfaceEntityImportExport
importPlan
-EntityImportPlan
with the rules that describes how entities should be persisted.validate
- whether the passed entities should be validated by the bean validation mechanism before entities are persistedoptimisticLocking
- whether the passed entities versions should be validated before entities are persisted- Returns:
- a collection of entities that have been imported
-
importEntities
public Collection<Object> importEntities(Collection<Object> entities, EntityImportPlan importPlan, boolean validate, boolean optimisticLocking, boolean additionComposition) - Specified by:
importEntities
in interfaceEntityImportExport
-
importEntityIntoSaveContext
public void importEntityIntoSaveContext(SaveContext saveContext, Object srcEntity, EntityImportPlan importPlan, boolean validate) - Specified by:
importEntityIntoSaveContext
in interfaceEntityImportExport
-
importEntityIntoSaveContext
public void importEntityIntoSaveContext(SaveContext saveContext, Object srcEntity, EntityImportPlan importPlan, boolean validate, boolean optimisticLocking) - Specified by:
importEntityIntoSaveContext
in interfaceEntityImportExport
-
importEntityIntoSaveContext
public void importEntityIntoSaveContext(SaveContext saveContext, Object srcEntity, EntityImportPlan importPlan, boolean validate, boolean optimisticLocking, boolean additionComposition) - Specified by:
importEntityIntoSaveContext
in interfaceEntityImportExport
-
validateEntities
-
importEntity
protected Object importEntity(Object srcEntity, @Nullable Object dstEntity, EntityImportPlan importPlan, FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLocking, boolean additionComposition) Method imports the entity.- Parameters:
srcEntity
- entity that came to theEntityImportExport
beandstEntity
- reloaded srcEntity or null if entity doesn't exist in the databaseimportPlan
- importPlan used for importing the entityfetchPlan
- fetchPlan that was used for loading dstEntitysaveContext
- entities that must be commited or deleted will be set to the saveContextreferenceInfoList
- list of referenceInfos for further processingoptimisticLocking
- whether the passed entity version should be validated before entity is persisted- Returns:
- dstEntity that has fields values from the srcEntity
-
importReference
protected void importReference(Object srcEntity, Object dstEntity, EntityImportPlanProperty importPlanProperty, @Nullable FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLocking) -
importOneToManyCollectionAttribute
protected void importOneToManyCollectionAttribute(Object srcEntity, Object dstEntity, EntityImportPlanProperty importPlanProperty, @Nullable FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLocking, boolean additionalComposition) -
importManyToManyCollectionAttribute
protected void importManyToManyCollectionAttribute(Object srcEntity, Object dstEntity, EntityImportPlanProperty importPlanProperty, @Nullable FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLocking) -
importEmbeddedAttribute
@Nullable protected Object importEmbeddedAttribute(Object srcEntity, Object dstEntity, boolean createOp, EntityImportPlanProperty importPlanProperty, FetchPlan fetchPlan, SaveContext saveContext, Collection<EntityImportExportImpl.ReferenceInfo> referenceInfoList, boolean optimisticLock) -
processReferenceInfo
protected void processReferenceInfo(EntityImportExportImpl.ReferenceInfo referenceInfo, SaveContext saveContext, Set<Object> loadedEntities) Method finds and set a reference value to the entity or throws EntityImportException if ERROR_ON_MISSING policy is violated -
constructFetchPlanFromImportPlan
Method constructsFetchPlanBuilder
for a regularFetchPlan
from theEntityImportPlan
. The regular fetchPlan will include all properties defined in the import plan. -
getFilteredIds
protected Collection<Object> getFilteredIds(@Nullable SecurityState securityState, String propertyName) -
createNewCollection
-
findReferenceEntity
@Nullable protected Object findReferenceEntity(Object entity, EntityImportPlanProperty importPlanProperty, SaveContext saveContext, Set<Object> loadedEntities) -
assertToken
-