Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split flattener into separate parts #7

Merged
merged 4 commits into from
Dec 3, 2017
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
2 changes: 1 addition & 1 deletion aom/src/main/java/com/nedap/archie/aom/CObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public MultiplicityInterval effectiveOccurrences(BiFunction<String, String, Mult
}
} else if(parent.getParent() != null) {
//TODO: this can be a (differential) path, but we don't support that yet.
return referenceModelPropMultiplicity.apply(parent.getParent().getRmTypeName(), parent.getRmAttributeName());
return referenceModelPropMultiplicity.apply(parent.getParent().getRmTypeName(), parent.getDifferentialPath() == null ? parent.getRmAttributeName() : parent.getDifferentialPath());
} else {
return MultiplicityInterval.createUpperUnbounded(occurrencesLower);
}
Expand Down
17 changes: 15 additions & 2 deletions aom/src/main/java/com/nedap/archie/rminfo/ModelInfoLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.nedap.archie.aom.CObject;
import com.nedap.archie.aom.CPrimitiveObject;
import com.nedap.archie.base.MultiplicityInterval;
import com.nedap.archie.paths.PathSegment;
import com.nedap.archie.query.APathQuery;

import java.lang.reflect.Field;
import java.util.Collection;
Expand Down Expand Up @@ -169,8 +171,19 @@ public interface ModelInfoLookup {
* @param rmAttributeName
* @return
*/
default MultiplicityInterval referenceModelPropMultiplicity(String rmTypeName, String rmAttributeName) {
RMAttributeInfo attributeInfo = getAttributeInfo(rmTypeName, rmAttributeName);
default MultiplicityInterval referenceModelPropMultiplicity(String rmTypeName, String rmAttributeNameOrPath) {
RMTypeInfo typeInfo = this.getTypeInfo(rmTypeName);
String rmAttributeName = rmAttributeNameOrPath;
if(rmAttributeNameOrPath.contains("[") || rmAttributeNameOrPath.contains("/")) {
APathQuery aPathQuery = new APathQuery(rmAttributeNameOrPath);
for(int i = 0; i < aPathQuery.getPathSegments().size()-1; i++) {
PathSegment segment = aPathQuery.getPathSegments().get(i);
RMAttributeInfo attributeInfo = typeInfo.getAttribute(segment.getNodeName());
typeInfo = this.getTypeInfo(attributeInfo.getTypeNameInCollection());
}
rmAttributeName = aPathQuery.getPathSegments().get(aPathQuery.getPathSegments().size()-1).getNodeName();
}
RMAttributeInfo attributeInfo = typeInfo.getAttribute(rmAttributeName);
if(attributeInfo.isMultipleValued()) {
return MultiplicityInterval.createUpperUnbounded(0);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ public class RMAttributeInfo {
private final Field field;
private final Class type;
private final Class typeInCollection;
private final String typeNameInCollection;
private final boolean isMultipleValued;
private final Method getMethod;
private final Method setMethod;
private final Method addMethod;
private final boolean nullable;
private final boolean computed;

public RMAttributeInfo(String name, Field field, Class type, Class typeInCollection, boolean nullable, Method getMethod, Method setMethod, Method addMethod) {
public RMAttributeInfo(String name, Field field, Class type, Class typeInCollection, String typeNameInCollection, boolean nullable, Method getMethod, Method setMethod, Method addMethod) {
this.name = name;
this.field = field;
this.type = type;
Expand All @@ -30,6 +31,7 @@ public RMAttributeInfo(String name, Field field, Class type, Class typeInCollect
this.computed = this.setMethod == null && this.addMethod == null;
this.isMultipleValued = type instanceof Class && Collection.class.isAssignableFrom(type);
this.typeInCollection = typeInCollection;
this.typeNameInCollection = typeNameInCollection;
}

public String getRmName() {
Expand Down Expand Up @@ -77,4 +79,7 @@ public boolean isComputed() {
}


public String getTypeNameInCollection() {
return typeNameInCollection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private void addRMAttributeInfo(Class clazz, RMTypeInfo typeInfo, TypeToken type
field,
rawFieldType,
typeInCollection,
this.namingStrategy.getTypeName(typeInCollection),
(field != null && field.getAnnotation(Nullable.class) != null) || getMethod.getAnnotation(Nullable.class) != null,
getMethod,
setMethod,
Expand Down Expand Up @@ -236,6 +237,7 @@ private void addRMAttributeInfo(Class clazz, RMTypeInfo typeInfo, TypeToken type
field,
rawFieldType,
typeInCollection,
namingStrategy.getTypeName(typeInCollection),
field.getAnnotation(Nullable.class) != null,
getMethod,
setMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private Set<String> getTupleAttributeNames(T cobj) {

private void buildAttribute(CAttribute cattr) {
builder.tryNewLine();
if (cattr.getRmAttributeName() != null) {
if (cattr.getDifferentialPath() == null) {
builder.append(cattr.getRmAttributeName());
} else {
builder.append(cattr.getDifferentialPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public ValidationResult validate(Archetype archetype, FullArchetypeRepository re
messages.addAll(runValidations(lookup, flattened, repository, flatParent, validationsPhase3));
} catch (Exception e) {
messages.add(new ValidationMessage(ErrorType.OTHER, "flattening failed with exception " + e));
logger.error("error during validation", e);
}
}
if(archetype instanceof Template) {
Expand Down
Loading