update
This commit is contained in:
parent
ca23f94e09
commit
70391906e2
|
@ -397,7 +397,7 @@ public class ItemHandler {
|
|||
handler.getContent().setStorageId(info.getStorageId());
|
||||
handler.getContent().setSize(info.getSize());
|
||||
handler.getContent().setRemotePath(info.getRemotePath());
|
||||
handler.getContent().setManagedBy(info.getRemotePath());
|
||||
handler.getContent().setManagedBy(info.getManagedBy());
|
||||
return handler;
|
||||
}catch (Exception e) {
|
||||
throw new BackendGenericError(e);
|
||||
|
|
|
@ -170,20 +170,7 @@ public class Node2ItemConverter {
|
|||
private <T> void setGenericFields(Node node, Class<T> classToHandle,List<String> excludes, T instance){
|
||||
for (Field field : retrieveAllFields(classToHandle)){
|
||||
if (field.isAnnotationPresent(Attribute.class)){
|
||||
Attribute attribute = field.getAnnotation(Attribute.class);
|
||||
field.setAccessible(true);
|
||||
try{
|
||||
Class<?> returnType = field.getType();
|
||||
Object propValue = getPropertyValue(returnType, node.getProperty(attribute.value()));
|
||||
if (!attribute.defaultValue().isEmpty() && propValue==null)
|
||||
propValue = returnType.cast(attribute.defaultValue());
|
||||
field.set(instance, propValue);
|
||||
logger.trace("retrieve item - added field {}",field.getName());
|
||||
}catch(PathNotFoundException e){
|
||||
logger.trace("the current node dosn't contain {} property",attribute.value());
|
||||
} catch (Exception e ) {
|
||||
logger.debug("error setting value for property {} ",attribute.value());
|
||||
}
|
||||
setAttributeFieldCheckingDefault(field, instance, node);
|
||||
} else if (field.isAnnotationPresent(NodeAttribute.class)){
|
||||
String fieldNodeName = field.getAnnotation(NodeAttribute.class).value();
|
||||
//for now it excludes only first level node
|
||||
|
@ -205,21 +192,12 @@ public class Node2ItemConverter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private <T> T iterateNodeAttributeFields(Class<T> clazz, Node node) throws Exception{
|
||||
T obj = clazz.newInstance();
|
||||
for (Field field : retrieveAllFields(clazz)){
|
||||
if (field.isAnnotationPresent(Attribute.class)){
|
||||
Attribute attribute = field.getAnnotation(Attribute.class);
|
||||
field.setAccessible(true);
|
||||
try{
|
||||
Class returnType = field.getType();
|
||||
field.set(obj, getPropertyValue(returnType, node.getProperty(attribute.value())));
|
||||
}catch(PathNotFoundException e){
|
||||
logger.trace("the current node dosn't contain {} property",attribute.value());
|
||||
} catch (Exception e ) {
|
||||
logger.debug("error setting value {}",e.getMessage());
|
||||
}
|
||||
setAttributeFieldCheckingDefault(field, obj, node);
|
||||
} else if (field.isAnnotationPresent(MapAttribute.class)){
|
||||
logger.trace("found field {} of type annotated as MapAttribute in class {} and node name {}", field.getName(), clazz.getName(), node.getName());
|
||||
field.setAccessible(true);
|
||||
|
@ -254,7 +232,6 @@ public class Node2ItemConverter {
|
|||
|
||||
if (!typeToSubtypeMap.containsKey(listType)) {
|
||||
|
||||
|
||||
Configuration config = new ConfigurationBuilder().forPackages(listType.getPackage().getName());
|
||||
Reflections reflections = new Reflections(config);
|
||||
Set<Class> subTypes = reflections.getSubTypesOf(listType);
|
||||
|
@ -301,6 +278,31 @@ public class Node2ItemConverter {
|
|||
return obj;
|
||||
}
|
||||
|
||||
private <T> void setAttributeFieldCheckingDefault(Field field, T instance, Node node) {
|
||||
Attribute attribute = field.getAnnotation(Attribute.class);
|
||||
field.setAccessible(true);
|
||||
try{
|
||||
Object propValue;
|
||||
Class<?> returnType = field.getType();
|
||||
if (node.hasProperty(attribute.value())) {
|
||||
propValue = getPropertyValue(returnType, node.getProperty(attribute.value()));
|
||||
if (!attribute.defaultValue().isEmpty() && propValue==null )
|
||||
propValue = returnType.cast(attribute.defaultValue());
|
||||
field.set(instance, propValue);
|
||||
logger.trace("retrieve item - added field {}",field.getName());
|
||||
} else if (!attribute.defaultValue().isEmpty()){
|
||||
propValue = returnType.cast(attribute.defaultValue());
|
||||
field.set(instance, propValue);
|
||||
logger.trace("retrieve item - setting default for field {}",field.getName());
|
||||
} else
|
||||
logger.debug("property non found for field {}",field.getName());
|
||||
|
||||
} catch (Exception e ) {
|
||||
logger.debug("error setting value for property {} ",attribute.value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
private Object getPropertyValue(Class returnType, Property prop) throws Exception{
|
||||
if (returnType.equals(String.class)) return prop.getString();
|
||||
|
|
Loading…
Reference in New Issue