Create placehoders for organizations not found in the database
parent
347f614c2d
commit
28f5fd53f5
|
|
@ -24,6 +24,7 @@ import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.librecms.contentsection.AssetRepository;
|
import org.librecms.contentsection.AssetRepository;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
|
|
@ -48,18 +49,26 @@ public class OrganizationIdResolver implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||||
return CdiUtil
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
.createCdiUtil()
|
final Optional<Organization> result = cdiUtil
|
||||||
.findBean(AssetRepository.class)
|
.findBean(AssetRepository.class)
|
||||||
.findByUuidAndType(id.key.toString(), Organization.class)
|
.findByUuidAndType(id.key.toString(), Organization.class);
|
||||||
.orElseThrow(
|
if (result.isPresent()) {
|
||||||
() -> new IllegalArgumentException(
|
return result.get();
|
||||||
String.format(
|
} else {
|
||||||
"No Organization with UUID %s found in the database",
|
final Organization organization = new Organization();
|
||||||
id.key.toString()
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue