Commit 2bcfc928 authored by Matija Obreza's avatar Matija Obreza
Browse files

Method#unit nullable, Method#fieldSize required for type=0 (VARCHAR)

parent 223063a7
......@@ -47,7 +47,7 @@ public class Method extends BusinessModel implements AclAwareModel {
@Lob
private String method;
@Column(length = 32)
@Column(length = 32, nullable = true)
private String unit;
@Lob
......@@ -75,7 +75,7 @@ public class Method extends BusinessModel implements AclAwareModel {
this.uuid = UUID.nameUUIDFromBytes(method.getBytes()).toString();
}
}
public String getMethod() {
return this.method;
}
......@@ -207,7 +207,6 @@ public class Method extends BusinessModel implements AclAwareModel {
public void setParameter(final Parameter parameter) {
this.parameter = parameter;
}
public String getUuid() {
return uuid;
......
......@@ -59,6 +59,7 @@ public interface TraitService {
* @param unit
* @param fieldName
* @param fieldType
* @param fieldSize required for Strings
* @param options
* @param range
* @param parameter
......@@ -66,7 +67,7 @@ public interface TraitService {
* @return
*/
@PreAuthorize("isAuthenticated()")
Method addMethod(String description, String unit, String fieldName, int fieldType, String options, String range, Parameter parameter);
Method addMethod(String description, String unit, String fieldName, int fieldType, Integer fieldSize, String options, String range, Parameter parameter);
/**
* List user's methods
......
......@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Accession;
......@@ -425,25 +426,29 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = false)
public Method addMethod(String description, String unit, String fieldName, int fieldType, String options, String range, Parameter parameter) {
public Method addMethod(String description, String unit, String fieldName, int fieldType, Integer fieldSize, String options, String range,
Parameter parameter) {
Method method = new Method();
method.setMethod(htmlSanitizer.sanitize(description));
method.setUnit(unit);
method.setFieldName(fieldName);
method.setUnit(StringUtils.defaultIfBlank(StringUtils.trimToNull(unit), null));
method.setFieldName(StringUtils.trimToNull(fieldName));
method.setFieldType(fieldType);
method.setOptions(options);
method.setRange(range);
if (fieldType == 0) {
// Will throw NPE if not provided!
method.setFieldSize(fieldSize.toString());
}
method.setOptions(StringUtils.defaultIfBlank(StringUtils.trimToNull(options), null));
method.setRange(StringUtils.defaultIfBlank(StringUtils.trimToNull(range), null));
method.setParameter(parameter);
methodRepository.save(method);
// Ensure table for method!
genesysLowlevelRepository.ensureMethodTable(method);
return method;
}
/**
* Returns datasets to which current user has 'WRITE'
......
......@@ -22,6 +22,7 @@ import javax.xml.bind.ValidationException;
import net.sf.oval.ConstraintViolation;
import net.sf.oval.Validator;
import net.sf.oval.constraint.MatchPattern;
import net.sf.oval.constraint.MinLength;
import net.sf.oval.constraint.NotBlank;
import net.sf.oval.constraint.NotNull;
......@@ -90,7 +91,6 @@ public class TraitsController extends RestController {
return OAuth2Cleanup.clean(methods);
}
@RequestMapping(value = "/mymethods", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
Object listMyMethods() {
......@@ -115,8 +115,8 @@ public class TraitsController extends RestController {
// TODO We could do better messages on validation error
throw new ModelValidationException("Validation problem", violations);
}
Method method = traitService.addMethod(methodJson.description, methodJson.unit, methodJson.fieldName, methodJson.fieldType, methodJson.options,
methodJson.range, null);
Method method = traitService.addMethod(methodJson.description, methodJson.unit, methodJson.fieldName, methodJson.fieldType, methodJson.fieldSize,
methodJson.options, methodJson.range, null);
return method;
}
......@@ -131,10 +131,14 @@ public class TraitsController extends RestController {
@NotNull
@NotBlank
@MatchPattern(pattern = { "[a-zA-Z0-9]+" })
public String fieldName;
public int fieldType;
public Integer fieldSize;
@NotBlank
public String options;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment