Create placeholders for parent categories that have not been imported
when a child category is imported, and update them when that category is imported.deploy_packages_to_gitea
parent
bf0a449419
commit
4e8d1929b8
|
|
@ -23,7 +23,9 @@ import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by the {@link CategorizationImExporter} to resolve categories based on
|
* Used by the {@link CategorizationImExporter} to resolve categories based on
|
||||||
|
|
@ -49,18 +51,41 @@ public class CategoryIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
return CdiUtil
|
final Optional<Category> result = CdiUtil
|
||||||
.createCdiUtil()
|
.createCdiUtil()
|
||||||
.findBean(CategoryRepository.class)
|
.findBean(CategoryRepository.class)
|
||||||
.findByUuid(id.key.toString())
|
.findByUuid(id.key.toString());
|
||||||
.orElseThrow(
|
if (result.isPresent()) {
|
||||||
() -> new IllegalArgumentException(
|
return result.get();
|
||||||
|
} else {
|
||||||
|
final Category category = new Category();
|
||||||
|
category.setUuid(id.key.toString());
|
||||||
|
category.setUniqueId(id.key.toString());
|
||||||
|
category.setName(
|
||||||
String.format(
|
String.format(
|
||||||
"No Category with UUID %s in the database.",
|
"placeholder-%s",
|
||||||
id.key.toString()
|
id.key.toString()
|
||||||
)
|
)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(CategoryRepository.class)
|
||||||
|
.save(category);
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// return CdiUtil
|
||||||
|
// .createCdiUtil()
|
||||||
|
// .findBean(CategoryRepository.class)
|
||||||
|
// .findByUuid(id.key.toString())
|
||||||
|
// .orElseThrow(
|
||||||
|
// () -> new IllegalArgumentException(
|
||||||
|
// String.format(
|
||||||
|
// "No Category with UUID %s in the database.",
|
||||||
|
// id.key.toString()
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,15 @@ import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import static com.ctc.wstx.shaded.msv_core.datatype.xsd.NumberType.save;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporter/Importer for {@link Category} entities.
|
* Exporter/Importer for {@link Category} entities.
|
||||||
*
|
*
|
||||||
|
|
@ -58,7 +61,29 @@ public class CategoryImExporter extends AbstractEntityImExporter<Category> {
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final Category entity) {
|
protected void saveImportedEntity(final Category entity) {
|
||||||
categoryRepository.save(entity);
|
final Optional<Category> result = categoryRepository.findByUuid(
|
||||||
|
entity.getUuid()
|
||||||
|
);
|
||||||
|
|
||||||
|
final Category category;
|
||||||
|
if (result.isPresent()) {
|
||||||
|
category = result.get();
|
||||||
|
category.setAbstractCategory(entity.isAbstractCategory());
|
||||||
|
category.setCategoryOrder(entity.getCategoryOrder());
|
||||||
|
category.setDescription(entity.getDescription());
|
||||||
|
category.setDisplayName(entity.getDisplayName());
|
||||||
|
category.setEnabled(entity.isEnabled());
|
||||||
|
category.setName(entity.getName());
|
||||||
|
category.setObjects(entity.getObjects());
|
||||||
|
category.setParentCategory(entity.getParentCategory());
|
||||||
|
category.setSubCategories(entity.getSubCategories());
|
||||||
|
category.setTitle(entity.getTitle());
|
||||||
|
category.setUniqueId(entity.getUniqueId());
|
||||||
|
category.setVisible(entity.isVisible());
|
||||||
|
} else {
|
||||||
|
category = entity;
|
||||||
|
}
|
||||||
|
categoryRepository.save(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue