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