Commit 3a041ece authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unused methods removed

parent 6224f7fb
......@@ -3,7 +3,6 @@ package lcsb.mapviewer.api.users;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
......@@ -24,22 +23,13 @@ import org.springframework.util.MultiValueMap;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.UpdateConflictException;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.AnnotatorParamDefinition;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema;
import lcsb.mapviewer.model.user.UserClassAnnotators;
import lcsb.mapviewer.model.user.UserClassRequiredAnnotations;
import lcsb.mapviewer.model.user.UserClassValidAnnotations;
import lcsb.mapviewer.model.user.UserGuiPreference;
import lcsb.mapviewer.model.user.annotator.AnnotatorConfigParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorData;
import lcsb.mapviewer.model.user.annotator.AnnotatorInputParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorOutputParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorParameter;
import lcsb.mapviewer.model.user.annotator.BioEntityField;
import lcsb.mapviewer.services.ObjectExistsException;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
......@@ -146,172 +136,6 @@ public class UserRestImpl extends BaseRestImpl {
}
}
private AnnotatorData parseAnnotator(Map<String, Object> map) throws QueryException {
try {
if (map.get("annotatorClass") == null) {
throw new QueryException("annotatorClass for annotator must be defined");
}
AnnotatorData result = new AnnotatorData((String) map.get("annotatorClass"));
for (String key : map.keySet()) {
Object value = map.get(key);
if (key.equalsIgnoreCase("annotatorClass") || key.equalsIgnoreCase("id")) {
continue;
} else if (key.equalsIgnoreCase("order")) {
if (value instanceof Integer) {
result.setOrderIndex((Integer) value);
} else {
result.setOrderIndex(Integer.valueOf((String) map.get("order")));
}
} else if (key.equalsIgnoreCase("parameters")) {
result.addAnnotatorParameters(parseAnnotatorParameters((List<Map<String, Object>>) value));
} else {
throw new InvalidArgumentException("Unknown annotator property: " + key);
}
}
return result;
} catch (ClassNotFoundException e) {
throw new QueryException(e);
}
}
private List<AnnotatorParameter> parseAnnotatorParameters(List<Map<String, Object>> data) {
List<AnnotatorParameter> result = new ArrayList<>();
for (Map<String, Object> entry : data) {
if (entry.get("type").equals("INPUT")) {
result.add(parseInputParameter(entry));
} else if (entry.get("type").equals("OUTPUT")) {
result.add(parseOutputParameter(entry));
} else if (entry.get("type").equals("CONFIG")) {
result.add(parseConfigParameter(entry));
} else {
throw new InvalidArgumentException("Unknown parameter type: " + entry.get("type"));
}
}
Collections.sort(result);
return result;
}
AnnotatorConfigParameter parseConfigParameter(Map<String, Object> entry) {
AnnotatorParamDefinition type = null;
String parameterValue = null;
int order = 0;
for (String key : entry.keySet()) {
Object value = entry.get(key);
if (key.equalsIgnoreCase("name")) {
type = AnnotatorParamDefinition.valueOf((String) value);
} else if (key.equalsIgnoreCase("value")) {
parameterValue = (String) value;
} else if (key.equalsIgnoreCase("type")) {
continue;
} else if (key.equalsIgnoreCase("commonName")) {
continue;
} else if (key.equalsIgnoreCase("inputType")) {
continue;
} else if (key.equalsIgnoreCase("description")) {
continue;
} else if (key.equalsIgnoreCase("order")) {
if (value instanceof Integer) {
order = (Integer) value;
} else {
order = Integer.valueOf((String) value);
}
} else {
throw new InvalidArgumentException("Unknown annotator property: " + key);
}
}
AnnotatorConfigParameter result = new AnnotatorConfigParameter(type, parameterValue);
result.setOrderPosition(order);
return result;
}
AnnotatorParameter parseOutputParameter(Map<String, Object> entry) {
BioEntityField field = null;
MiriamType annotationType = null;
AnnotatorParameter result;
int order = 0;
for (String key : entry.keySet()) {
Object value = entry.get(key);
if (key.equalsIgnoreCase("field")) {
field = parseBioEntityField(value);
} else if (key.equalsIgnoreCase("annotation_type")) {
annotationType = extractMiriamType(value);
} else if (key.equalsIgnoreCase("type")) {
continue;
} else if (key.equalsIgnoreCase("order")) {
if (value instanceof Integer) {
order = (Integer) value;
} else {
order = Integer.valueOf((String) value);
}
} else {
throw new InvalidArgumentException("Unknown annotator property: " + key);
}
}
if (field != null && annotationType != null) {
throw new InvalidArgumentException("Either field or annotation_type must be defined (both found)");
} else if (field == null && annotationType == null) {
throw new InvalidArgumentException("Either field or annotation_type must be defined (none found)");
} else if (field != null) {
result = new AnnotatorOutputParameter(field);
} else {
result = new AnnotatorOutputParameter(annotationType);
}
result.setOrderPosition(order);
return result;
}
private MiriamType extractMiriamType(Object value) {
if (value == null) {
return null;
}
if (value instanceof MiriamType) {
return (MiriamType) value;
}
return MiriamType.valueOf((String) value);
}
private BioEntityField parseBioEntityField(Object value) {
if (value == null) {
return null;
}
if (value instanceof BioEntityField) {
return (BioEntityField) value;
}
return BioEntityField.valueOf((String) value);
}
AnnotatorInputParameter parseInputParameter(Map<String, Object> entry) {
BioEntityField field = null;
MiriamType annotationType = null;
int order = 0;
for (String key : entry.keySet()) {
Object value = entry.get(key);
if (key.equalsIgnoreCase("field")) {
field = parseBioEntityField(value);
} else if (key.equalsIgnoreCase("annotation_type")) {
annotationType = extractMiriamType(value);
} else if (key.equalsIgnoreCase("order")) {
if (value instanceof Integer) {
order = (Integer) value;
} else if (value != null) {
order = Integer.valueOf((String) value);
}
} else if (key.equalsIgnoreCase("type")) {
continue;
} else {
throw new InvalidArgumentException("Unknown annotator property: " + key);
}
}
AnnotatorInputParameter result = new AnnotatorInputParameter(field, annotationType);
result.setOrderPosition(order);
return result;
}
private void updateElementAnnotators(UserAnnotationSchema schema, UserAnnotationSchema newData) throws QueryException {
for (UserClassAnnotators newClassAnnotator : newData.getClassAnnotators()) {
UserClassAnnotators annotator = null;
......@@ -444,30 +268,6 @@ public class UserRestImpl extends BaseRestImpl {
}
}
private void updateUploadPreferences(UserAnnotationSchema schema, Map<String, Object> data) throws QueryException {
for (String key : data.keySet()) {
Boolean value = (Boolean) data.get(key);
if (value != null) {
if (key.equals("validate-miriam")) {
schema.setValidateMiriamTypes(value);
} else if (key.equals("annotate-model")) {
schema.setAnnotateModel(value);
} else if (key.equals("cache-data")) {
schema.setCacheData(value);
} else if (key.equals("auto-resize")) {
schema.setAutoResizeMap(value);
} else if (key.equals("semantic-zooming-contains-multiple-overlays")) {
schema.setSemanticZoomContainsMultipleOverlays(value);
} else if (key.equals("sbgn")) {
schema.setSbgnFormat(value);
} else {
throw new QueryException("Unknown upload preference field: " + key);
}
}
}
}
public UserDTO updateUser(String login, Map<String, Object> userData,
Collection<? extends GrantedAuthority> authorities)
throws QueryException {
......
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