Don't use placeholders when importing categories and folders.
parent
69c5d4a71f
commit
b5761464eb
|
|
@ -49,26 +49,38 @@ public class OrganizationIdResolver implements Serializable, ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final Optional<Organization> result = cdiUtil
|
||||
return CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(AssetRepository.class)
|
||||
.findByUuidAndType(id.key.toString(), Organization.class);
|
||||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
} else {
|
||||
final Organization organization = new Organization();
|
||||
organization.setName(
|
||||
String.format("Placeholder %s", id.key.toString())
|
||||
.findByUuidAndType(id.key.toString(), Organization.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No Organization with UUID %s found in the database.",
|
||||
id.key.toString()
|
||||
)
|
||||
)
|
||||
);
|
||||
final AssetRepository assetRepo = cdiUtil.findBean(
|
||||
AssetRepository.class
|
||||
);
|
||||
assetRepo.save(organization);
|
||||
organization.setUuid(id.key.toString());
|
||||
assetRepo.save(organization);
|
||||
|
||||
return organization;
|
||||
}
|
||||
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
// final Optional<Organization> result = cdiUtil
|
||||
// .findBean(AssetRepository.class)
|
||||
// .findByUuidAndType(id.key.toString(), Organization.class);
|
||||
// if (result.isPresent()) {
|
||||
// return result.get();
|
||||
// } else {
|
||||
// final Organization organization = new Organization();
|
||||
// organization.setName(
|
||||
// String.format("Placeholder %s", id.key.toString())
|
||||
// );
|
||||
// final AssetRepository assetRepo = cdiUtil.findBean(
|
||||
// AssetRepository.class
|
||||
// );
|
||||
// assetRepo.save(organization);
|
||||
// organization.setUuid(id.key.toString());
|
||||
// assetRepo.save(organization);
|
||||
//
|
||||
// return organization;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -45,30 +45,42 @@ public class FolderIdResolver implements Serializable, ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
final Optional<Folder> result = CdiUtil
|
||||
return CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(FolderRepository.class)
|
||||
.findByUuid(id.key.toString());
|
||||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
} else {
|
||||
final Folder folder = new Folder();
|
||||
folder.setUuid(id.key.toString());
|
||||
folder.setUniqueId(id.key.toString());
|
||||
folder.setName(
|
||||
String.format(
|
||||
"placeholder-%s",
|
||||
id.key.toString()
|
||||
.findByUuid(id.key.toString())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No Folder with UUID %s in the database.",
|
||||
id.key.toString()
|
||||
)
|
||||
)
|
||||
);
|
||||
folder.setType(FolderType.DOCUMENTS_FOLDER);
|
||||
CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(FolderRepository.class)
|
||||
.save(folder);
|
||||
|
||||
return folder;
|
||||
}
|
||||
// final Optional<Folder> result = CdiUtil
|
||||
// .createCdiUtil()
|
||||
// .findBean(FolderRepository.class)
|
||||
// .findByUuid(id.key.toString());
|
||||
// if (result.isPresent()) {
|
||||
// return result.get();
|
||||
// } else {
|
||||
// final Folder folder = new Folder();
|
||||
// folder.setUuid(id.key.toString());
|
||||
// folder.setUniqueId(id.key.toString());
|
||||
// folder.setName(
|
||||
// String.format(
|
||||
// "placeholder-%s",
|
||||
// id.key.toString()
|
||||
// )
|
||||
// );
|
||||
// folder.setType(FolderType.DOCUMENTS_FOLDER);
|
||||
// CdiUtil
|
||||
// .createCdiUtil()
|
||||
// .findBean(FolderRepository.class)
|
||||
// .save(folder);
|
||||
//
|
||||
// return folder;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.librecms.contentsection;
|
|||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryManager;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.categorization.Domain;
|
||||
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||
import org.libreccm.imexport.Processes;
|
||||
|
|
@ -42,6 +43,9 @@ public class FolderImExporter extends AbstractEntityImExporter<Folder> {
|
|||
|
||||
@Inject
|
||||
private CategoryManager categoryManager;
|
||||
|
||||
@Inject
|
||||
private CategoryRepository categoryRepo;
|
||||
|
||||
@Inject
|
||||
private FolderRepository folderRepo;
|
||||
|
|
@ -66,6 +70,26 @@ public class FolderImExporter extends AbstractEntityImExporter<Folder> {
|
|||
@Override
|
||||
protected Optional<Folder> findExistingEntity(final String uuid) {
|
||||
return folderRepo.findByUuid(uuid);
|
||||
// final Optional<Folder> result = folderRepo.findByUuid(uuid);
|
||||
// if (result.isPresent()) {
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// final Optional<Category> placeholderResult = categoryRepo.findByUuid(
|
||||
// uuid
|
||||
// );
|
||||
// if (placeholderResult.isPresent()) {
|
||||
// // Found a placeholder category. Replace with real folder.
|
||||
//
|
||||
// final Category placeholder = placeholderResult.get();
|
||||
//
|
||||
//
|
||||
//
|
||||
// return folder;
|
||||
// }
|
||||
//
|
||||
// return Optional.empty();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -51,28 +51,40 @@ public class CategoryIdResolver implements Serializable, ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
final Optional<Category> result = CdiUtil
|
||||
return CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(CategoryRepository.class)
|
||||
.findByUuid(id.key.toString());
|
||||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
} else {
|
||||
final Category category = new Category();
|
||||
category.setUuid(id.key.toString());
|
||||
category.setUniqueId(id.key.toString());
|
||||
category.setName(
|
||||
String.format(
|
||||
"placeholder-%s",
|
||||
id.key.toString()
|
||||
.findByUuid(id.key.toString())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No Category with UUID %s in the database.",
|
||||
id.key.toString()
|
||||
)
|
||||
)
|
||||
);
|
||||
CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(CategoryRepository.class)
|
||||
.save(category);
|
||||
return category;
|
||||
}
|
||||
// final Optional<Category> result = CdiUtil
|
||||
// .createCdiUtil()
|
||||
// .findBean(CategoryRepository.class)
|
||||
// .findByUuid(id.key.toString());
|
||||
// if (result.isPresent()) {
|
||||
// return result.get();
|
||||
// } else {
|
||||
// final Category category = new Category();
|
||||
// category.setUuid(id.key.toString());
|
||||
// category.setUniqueId(id.key.toString());
|
||||
// category.setName(
|
||||
// String.format(
|
||||
// "placeholder-%s",
|
||||
// id.key.toString()
|
||||
// )
|
||||
// );
|
||||
// CdiUtil
|
||||
// .createCdiUtil()
|
||||
// .findBean(CategoryRepository.class)
|
||||
// .save(category);
|
||||
// return category;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue