use of com.google.api.pathtemplate.ValidationException in project toolkit by googleapis.
the class SingleResourceNameConfig method createSingleResourceName.
/**
* Creates an instance of SingleResourceNameConfig based on CollectionConfigProto. On errors, null
* will be returned, and diagnostics are reported to the diag collector.
*/
@Nullable
public static SingleResourceNameConfig createSingleResourceName(DiagCollector diagCollector, ConfigProto configProto, CollectionConfigProto collectionConfigProto, ProtoFile file) {
String namePattern = collectionConfigProto.getNamePattern();
PathTemplate nameTemplate;
try {
nameTemplate = PathTemplate.create(namePattern);
} catch (ValidationException e) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, e.getMessage()));
return null;
}
String entityId = collectionConfigProto.getEntityName();
String entityName = entityId;
String language = configProto.getLanguage();
if (language != null) {
for (CollectionLanguageOverridesProto override : collectionConfigProto.getLanguageOverridesList()) {
if (language.equals(override.getLanguage())) {
entityName = override.getEntityName();
}
}
}
return new AutoValue_SingleResourceNameConfig(namePattern, nameTemplate, entityId, entityName, file);
}
Aggregations