String customName = lng.generateName(l);
if (validateField(fieldName, customName)) {
return customName;
}
else {
throw new MisoNamingException("Custom naming generator '"+lng.getGeneratorName()+"' supplied for Library field '"+fieldName+"' generated an invalid name according to the validation scheme '"+validationMap.get(fieldName)+"'");
}
}
else {
if ("alias".equals(fieldName)) {
if (l.getSample() != null) {
Pattern samplePattern = Pattern.compile("([A-z0-9]+)_S([A-z0-9]+)_(.*)");
Matcher m = samplePattern.matcher(l.getSample().getAlias());
if (m.matches()) {
try {
int numLibs = requestManager.listAllLibrariesBySampleId(l.getSample().getId()).size();
String la = m.group(1) + "_" + "L" + m.group(2) + "-"+(numLibs+1)+"_" + m.group(3);
if (validateField("alias", la)) {
return la;
}
else {
throw new MisoNamingException("Generated invalid Library alias for: " + l.toString());
}
}
catch (IOException e) {
throw new MisoNamingException("Cannot generate Library alias for: " + l.toString(), e);
}
}
else {
throw new MisoNamingException("Cannot generate Library alias for: " + l.toString() + " from supplied sample alias: " + l.getSample().getAlias());
}
}
else {
throw new MisoNamingException("This alias generation scheme requires the Library to have a parent Sample set.");
}
}
else {
if (validationMap.keySet().contains(fieldName)) {
Method m = fieldCheck(fieldName);
if (m != null) {
log.info("Generating name for '"+fieldName+"' :: " + DefaultMisoEntityPrefix.get(Library.class.getSimpleName()).name() + l.getId());
return DefaultMisoEntityPrefix.get(Library.class.getSimpleName()).name() + l.getId();
}
else {
throw new MisoNamingException("No such nameable field.");
}
}
else {
throw new MisoNamingException("Generation of names on field '"+fieldName+"' not available.");
}
}
}
}