Optimized ImExporter entity handling
parent
a9f10cf0ab
commit
2c7c9e302c
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2023-01-19T185030",
|
||||
"version": "7.0.0-SNAPSHOT.2023-01-28T095804",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2023-01-19T185030",
|
||||
"version": "7.0.0-SNAPSHOT.2023-01-28T095804",
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@tiptap/core": "^2.0.0-beta.127",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2023-01-19T185030",
|
||||
"version": "7.0.0-SNAPSHOT.2023-01-28T095804",
|
||||
"description": "JavaScript stuff for ccm-cms",
|
||||
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
|
||||
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -50,6 +52,10 @@ import javax.transaction.Transactional;
|
|||
*/
|
||||
public abstract class AbstractEntityImExporter<T extends Exportable> {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
AbstractEntityImExporter.class
|
||||
);
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
|
|
@ -153,7 +159,7 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
* org.libreccm.imexport.Exportable)
|
||||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRES_NEW)
|
||||
public T importEntity(final String data) throws ImportExpection {
|
||||
public void importEntity(final String data) throws ImportExpection {
|
||||
try {
|
||||
final T importedEntity = objectMapper.readValue(data,
|
||||
getEntityClass());
|
||||
|
|
@ -165,12 +171,17 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
updateExistingEntity(existingEntity, importedEntity);
|
||||
|
||||
entityManager.flush();
|
||||
return existingEntity;
|
||||
LOGGER.info(
|
||||
"Entity {} already existed. Updated entity with property "
|
||||
+ "values from import: {}",
|
||||
existingEntity.getUuid(),
|
||||
existingEntity.toString()
|
||||
);
|
||||
} else {
|
||||
saveImportedEntity(importedEntity);
|
||||
|
||||
entityManager.flush();
|
||||
return importedEntity;
|
||||
LOGGER.info("Imported entity {}", importedEntity.toString());
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new ImportExpection(ex);
|
||||
|
|
@ -255,7 +266,7 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
/**
|
||||
* Reloads the entity to export. Entities become detacted for several
|
||||
* reasons before they are passed to the null null null null null null null
|
||||
* null null null null null null null null {@link #exportEntity(org.libreccm.imexport.Exportable) method. The
|
||||
* null null null null null null null null null {@link #exportEntity(org.libreccm.imexport.Exportable) method. The
|
||||
* implementation of this should reload the passed entity.
|
||||
*
|
||||
* @param entity The entity to reload.
|
||||
|
|
|
|||
|
|
@ -300,7 +300,6 @@ public class ImportExport {
|
|||
}
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
private void importEntity(
|
||||
final String importName,
|
||||
final String type,
|
||||
|
|
@ -321,8 +320,7 @@ public class ImportExport {
|
|||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
final Exportable entity = imExporter.importEntity(data);
|
||||
LOGGER.info("Imported entity {}", entity.toString());
|
||||
imExporter.importEntity(data);
|
||||
} catch (IOException
|
||||
| FileDoesNotExistException
|
||||
| FileAccessException
|
||||
|
|
|
|||
Loading…
Reference in New Issue