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 java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
|
|
@ -48,18 +49,26 @@ public class OrganizationIdResolver implements Serializable, ObjectIdResolver {
|
|||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
return CdiUtil
|
||||
.createCdiUtil()
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final Optional<Organization> result = cdiUtil
|
||||
.findBean(AssetRepository.class)
|
||||
.findByUuidAndType(id.key.toString(), Organization.class)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"No Organization with UUID %s found in the database",
|
||||
id.key.toString()
|
||||
)
|
||||
)
|
||||
.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
|
||||
|
|
|
|||
Loading…
Reference in New Issue