Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Small rm changes #18

Merged
merged 1 commit into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.nedap.archie.rminfo.RMAttributeInfo;
import com.nedap.archie.rminfo.RMTypeInfo;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -61,7 +60,7 @@ public ReflectionConstraintImposer(ModelInfoLookup classLookup) {
attribute.setCardinality(new Cardinality(0,1));
}

if(attributeInfo.getType() instanceof Class && Collection.class.isAssignableFrom(attributeInfo.getType())) {
if(attributeInfo.isMultipleValued()) {
attribute.setCardinality(Cardinality.unbounded());
attribute.setMultiple(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nedap/archie/aom/AuthoredResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
@XmlType(name="AUTHORED_RESOURCE")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AuthoredResource extends ArchetypeModelObject {
public abstract class AuthoredResource extends ArchetypeModelObject {

private Boolean controlled;
private String uid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void set(Object object, String rmAttributeName, List<Object> values) {
Type type = attributeInfo.getType();
if(type instanceof Class) {
Class clazz = (Class) type;
if(Collection.class.isAssignableFrom(clazz)) {
if(attributeInfo.isMultipleValued()) {
Collection collection = (Collection) newInstance(attributeInfo);
if(values != null) {
collection.addAll(values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"archetypeDetails",
"feederAudit"
})
public class Locatable extends Pathable {
public abstract class Locatable extends Pathable {

@XmlElement
private DvText name;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nedap/archie/rm/archetyped/Pathable.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Created by pieter.bos on 04/11/15.
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class Pathable extends RMObject {
public abstract class Pathable extends RMObject {
//TODO: implement according to spec: pathExists(path), pathUnique(path), pathOfItem(pathable)

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"protocol",
"guidelineId"
})
public class CareEntry extends Entry {
public abstract class CareEntry extends Entry {

@Nullable
private ItemStructure protocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CONTENT_ITEM")
public class ContentItem extends Locatable {
public abstract class ContentItem extends Locatable {

}
2 changes: 1 addition & 1 deletion src/main/java/com/nedap/archie/rm/composition/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"otherParticipations",
"workFlowId"
})
public class Entry extends ContentItem {
public abstract class Entry extends ContentItem {

private CodePhrase language;
private CodePhrase encoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
/**
* Created by pieter.bos on 04/11/15.
*/
public class DataStructure extends Locatable {
public abstract class DataStructure extends Locatable {
}
2 changes: 1 addition & 1 deletion src/main/java/com/nedap/archie/rm/datastructures/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ITEM")
public class Item extends Locatable {
public abstract class Item extends Locatable {
}
2 changes: 1 addition & 1 deletion src/main/java/com/nedap/archie/rm/demographic/Actor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="ACTOR")
public class Actor extends Party {
public abstract class Actor extends Party {

private List<DvText> languages = new ArrayList<>();
private List<PartyRef> roles = new ArrayList();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nedap/archie/rm/generic/PartyProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@XmlType(name = "PARTY_PROXY", propOrder = {
"externalRef"
})
public class PartyProxy extends RMObject {
public abstract class PartyProxy extends RMObject {

@Nullable
@XmlElement(name = "external_ref")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@XmlType(name = "OBJECT_ID", propOrder = {
"value"
})
public class ObjectId extends RMObject {
public abstract class ObjectId extends RMObject {

private String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by pieter.bos on 08/07/16.
*/
public class UID extends RMObject {
public abstract class UID extends RMObject {

String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UID_BASED_ID")
public class UIDBasedId extends ObjectId {
public abstract class UIDBasedId extends ObjectId {

private UID root;
@Nullable
Expand Down
51 changes: 32 additions & 19 deletions src/main/java/com/nedap/archie/rminfo/ModelInfoLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,22 @@ private void addAttributeInfo(Class clazz, RMTypeInfo typeInfo) {
String javaFieldNameUpperCased = upperCaseFirstChar(javaFieldName);
Method getMethod = getMethod(clazz, "get" + javaFieldNameUpperCased);
Method setMethod = null, addMethod = null;
if(getMethod == null) {
if (getMethod == null) {
getMethod = getMethod(clazz, "is" + javaFieldNameUpperCased);
}
if(getMethod != null) {
if (getMethod != null) {
setMethod = getMethod(clazz, "set" + javaFieldNameUpperCased, getMethod.getReturnType());
if(Collection.class.isAssignableFrom(getMethod.getReturnType())) {
if (Collection.class.isAssignableFrom(getMethod.getReturnType())) {
Type[] typeArguments = ((ParameterizedType) getMethod.getGenericReturnType()).getActualTypeArguments();
if(typeArguments.length == 1) {
if (typeArguments.length == 1) {
TypeToken singularParameter = typeToken.resolveType(typeArguments[0]);
//TODO: does this work or should we use the typeArguments[0].getSomething?
String addMethodName = "add" + toSingular(javaFieldNameUpperCased);
addMethod = getMethod(clazz, addMethodName, singularParameter.getRawType());
if(addMethod == null) {
if (addMethod == null) {
//Due to generics, this does not always work
Set<Method> allAddMethods = ReflectionUtils.getAllMethods(clazz, ReflectionUtils.withName(addMethodName));
if(allAddMethods.size() == 1) {
if (allAddMethods.size() == 1) {
addMethod = allAddMethods.iterator().next();
} else {
logger.warn("strange number of add methods for field {} on class {}", field.getName(), clazz.getSimpleName());
Expand All @@ -144,26 +144,39 @@ private void addAttributeInfo(Class clazz, RMTypeInfo typeInfo) {
}

TypeToken fieldType = null;
if(getMethod != null) {
if (getMethod != null) {
fieldType = typeToken.resolveType(getMethod.getGenericReturnType());
} else {
fieldType = typeToken.resolveType(field.getGenericType());
}

Class rawFieldType = fieldType.getRawType();
Class typeInCollection = rawFieldType;
if (Collection.class.isAssignableFrom(rawFieldType)) {
Type[] actualTypeArguments = ((ParameterizedType) fieldType.getType()).getActualTypeArguments();
if (actualTypeArguments.length == 1) {
if (actualTypeArguments[0] instanceof Class) {
typeInCollection = (Class) actualTypeArguments[0];
}
}
}


RMAttributeInfo attributeInfo = new RMAttributeInfo(
attributeName,
field,
fieldType.getRawType(),
field.getAnnotation(Nullable.class) != null,
getMethod,
setMethod,
addMethod
);
typeInfo.addAttribute(attributeInfo);
if (setMethod != null) {
RMAttributeInfo attributeInfo = new RMAttributeInfo(
attributeName,
field,
rawFieldType,
typeInCollection,
field.getAnnotation(Nullable.class) != null,
getMethod,
setMethod,
addMethod
);
typeInfo.addAttribute(attributeInfo);
} else {
logger.info("property without a set method ignored for field {} on class {}", field.getName(), clazz.getSimpleName());
}
}

}

private String toSingular(String javaFieldNameUpperCased) {
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/nedap/archie/rminfo/RMAttributeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;

/**
* Created by pieter.bos on 25/03/16.
Expand All @@ -10,19 +11,23 @@ public class RMAttributeInfo {
private final String name;
private final Field field;
private final Class type;
private final Class typeInCollection;
private final boolean isMultipleValued;
private final Method getMethod;
private final Method setMethod;
private final Method addMethod;
private final boolean nullable;

public RMAttributeInfo(String name, Field field, Class type, boolean nullable, Method getMethod, Method setMethod, Method addMethod) {
public RMAttributeInfo(String name, Field field, Class type, Class typeInCollection, boolean nullable, Method getMethod, Method setMethod, Method addMethod) {
this.name = name;
this.field = field;
this.type = type;
this.nullable = nullable;
this.getMethod = getMethod;
this.setMethod = setMethod;
this.addMethod = addMethod;
this.isMultipleValued = type instanceof Class && Collection.class.isAssignableFrom(type);
this.typeInCollection = typeInCollection;
}

public String getRmName() {
Expand All @@ -45,6 +50,10 @@ public Field getField() {
return field;
}

public boolean isMultipleValued() {
return isMultipleValued;
}

public Class getType() {
return type;
}
Expand All @@ -53,4 +62,11 @@ public boolean isNullable() {
return nullable;
}

/**
* If isMultipleValued == true, this will return the type used in the collection, eg if the the collection is List<String>, this will return String.class
* @return
*/
public Class getTypeInCollection() {
return typeInCollection;
}
}