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