use of org.obiba.mica.access.DataAccessRequestGenerationException in project mica2 by obiba.
the class DataAccessEntityService method generateId.
protected String generateId() {
DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
Object exclusions = YamlClassPathResourceReader.read(EXCLUSION_IDS_YAML_RESOURCE_PATH, Map.class).get("exclusions");
IdentifierGenerator.Builder builder = IdentifierGenerator.newBuilder().prefix(dataAccessConfig.getIdPrefix()).size(dataAccessConfig.getIdLength());
if (dataAccessConfig.isAllowIdWithLeadingZeros()) {
builder.zeros();
}
if (exclusions instanceof List) {
log.info("Using exclusions {} to generate DAR id", exclusions.toString());
builder.exclusions((List) exclusions);
}
IdentifierGenerator idGenerator = builder.build();
int tries = 0;
while (tries < 100) {
tries++;
String id = idGenerator.generateIdentifier();
if (getRepository().findOne(id) == null)
return id;
}
throw new DataAccessRequestGenerationException("Exceeded 100 id generation tries");
}
Aggregations