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

Support BMM Indexed Container meta-type, enabling Hash<K,V> structures #581

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions bmm/src/main/java/org/openehr/bmm/core/BmmContainerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* Author: Claude Nanjo
*/

import org.openehr.bmm.persistence.validation.BmmDefinitions;

import java.util.List;

/**
Expand All @@ -36,7 +38,7 @@
private BmmGenericClass containerType;

/**
*
* The type of the contained item
*/
private BmmUnitaryType baseType;

Expand Down Expand Up @@ -90,7 +92,8 @@
*/
@Override
public String getTypeName() {
return containerType.getName() + "<" + baseType.getTypeName() + ">";
return containerType.getName() +
BmmDefinitions.GENERIC_LEFT_DELIMITER + baseType.getTypeName() + BmmDefinitions.GENERIC_RIGHT_DELIMITER;

Check warning on line 96 in bmm/src/main/java/org/openehr/bmm/core/BmmContainerType.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/core/BmmContainerType.java#L95-L96

Added lines #L95 - L96 were not covered by tests
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.openehr.bmm.core;

import com.nedap.archie.base.MultiplicityInterval;

/**
* Subtype of BMM_CONTAINER_PROPERTY that represents an indexed container type based on one of the inbuilt types
* Hash &lt;&gt;.
*/
public class BmmIndexedContainerProperty extends BmmProperty<BmmIndexedContainerType> {

/**
* We have to replicate cardinality here from BmmContainerProperty since we are inheriting from
* BmmProperty &lt;BmmIndexedContainerType&gt; (which creates correct typing of the 'type' property) not BmmContainerProperty
*/
private MultiplicityInterval cardinality;

public BmmIndexedContainerProperty (String aName, BmmIndexedContainerType aType, String aDocumentation, boolean isMandatoryFlag, boolean isComputedFlag) {
super(aName, aType, aDocumentation, isMandatoryFlag, isComputedFlag);
cardinality = MultiplicityInterval.createOpen();
}

public MultiplicityInterval getCardinality() {
return cardinality;

Check warning on line 23 in bmm/src/main/java/org/openehr/bmm/core/BmmIndexedContainerProperty.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/core/BmmIndexedContainerProperty.java#L23

Added line #L23 was not covered by tests
}
public void setCardinality(MultiplicityInterval cardinality) {
this.cardinality = cardinality;
}

Check warning on line 27 in bmm/src/main/java/org/openehr/bmm/core/BmmIndexedContainerProperty.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/core/BmmIndexedContainerProperty.java#L26-L27

Added lines #L26 - L27 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.openehr.bmm.core;

import org.openehr.bmm.persistence.validation.BmmDefinitions;

public class BmmIndexedContainerType extends BmmContainerType {

/**
* The type of the index
*/
private BmmSimpleType indexType;
public BmmIndexedContainerType (BmmUnitaryType aBaseType, BmmSimpleType anIndexType, BmmGenericClass aContainerClass) {
super (aBaseType, aContainerClass);
indexType = anIndexType;
}
public BmmSimpleType getIndexType() { return indexType; }

@Override
public String getTypeName() {
return getContainerType().getName() +
BmmDefinitions.GENERIC_LEFT_DELIMITER +
indexType.getTypeName() + BmmDefinitions.GENERIC_SEPARATOR +
getBaseType().getTypeName() +
BmmDefinitions.GENERIC_RIGHT_DELIMITER;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.openehr.bmm.v2.persistence;

import com.nedap.archie.base.Interval;
import com.nedap.archie.base.MultiplicityInterval;
import org.openehr.bmm.core.*;
import org.openehr.bmm.v2.validation.converters.BmmClassProcessor;

public class PBmmIndexedContainerProperty extends PBmmProperty<PBmmIndexedContainerType> {

/**
* We have to replicate cardinality here from PBmmContainerProperty since we are inheriting from
* PBmmProperty<PBmmIndexedContainerType> (which creates correct typing of typeDef) not PBmmContainerProperty
*/
private Interval<Integer> cardinality;

public Interval<Integer> getCardinality() {
return cardinality;
}
public void setCardinality(Interval<Integer> cardinality) {
this.cardinality = cardinality;
}

Check warning on line 21 in bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerProperty.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerProperty.java#L20-L21

Added lines #L20 - L21 were not covered by tests
public PBmmIndexedContainerProperty() {
super();
}
@Override
public BmmIndexedContainerProperty createBmmProperty(BmmClassProcessor classProcessor, BmmClass bmmClass) {
PBmmIndexedContainerType typeRef = getTypeRef();
if (typeRef != null) {
BmmIndexedContainerType bmmType = (BmmIndexedContainerType) typeRef.createBmmType(classProcessor, bmmClass);
BmmIndexedContainerProperty bmmProperty = new BmmIndexedContainerProperty(getName(), bmmType, getDocumentation(), nullToFalse(isMandatory()), nullToFalse(isComputed()));
if (getCardinality() != null) {
bmmProperty.setCardinality(new MultiplicityInterval(getCardinality()));

Check warning on line 32 in bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerProperty.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerProperty.java#L32

Added line #L32 was not covered by tests
}
populateImBooleans(bmmProperty);
return bmmProperty;
}
throw new RuntimeException("BmmTypeCreate failed for type " + typeRef + " of property "
+ getName() + " in class " + bmmClass.getName());
}

Check warning on line 39 in bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerProperty.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerProperty.java#L37-L39

Added lines #L37 - L39 were not covered by tests

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.openehr.bmm.v2.persistence;

import org.openehr.bmm.core.*;
import org.openehr.bmm.persistence.validation.BmmDefinitions;
import org.openehr.bmm.v2.validation.converters.BmmClassProcessor;

import java.util.ArrayList;
import java.util.List;

public class PBmmIndexedContainerType extends PBmmContainerType {

private String indexType;

public String getIndexType() {
return indexType;
}

public void setIndexType(String indexType) {
this.indexType = indexType;
}

@Override
public BmmIndexedContainerType createBmmType(BmmClassProcessor processor, BmmClass classDefinition) {
BmmClass containerClassDef = processor.getClassDefinition (getContainerType());
BmmClass indexClassDef = processor.getClassDefinition (indexType);
PBmmUnitaryType containedType = getTypeRef(); //get the actual typeref for conversion
if (containerClassDef instanceof BmmGenericClass &&
indexClassDef instanceof BmmSimpleClass &&
containedType != null)
{
BmmType containedBmmType = containedType.createBmmType(processor, classDefinition);
if (containedBmmType instanceof BmmUnitaryType) {
return new BmmIndexedContainerType((BmmUnitaryType) containedBmmType,
((BmmSimpleClass) indexClassDef).getType(),
(BmmGenericClass) containerClassDef);
}
}

throw new RuntimeException("BmmClass " + containerClassDef.getName() + " is not defined in this model or not an indexed container type");
}
@Override
public String asTypeString() {
return getContainerType() + BmmDefinitions.GENERIC_LEFT_DELIMITER +
indexType + BmmDefinitions.GENERIC_SEPARATOR + getTypeRef().asTypeString() +
BmmDefinitions.GENERIC_RIGHT_DELIMITER;
}
@Override
public List<String> flattenedTypeList() {
List<String> result = new ArrayList<>();
result.add(getContainerType());
result.add(indexType);

Check warning on line 51 in bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerType.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerType.java#L49-L51

Added lines #L49 - L51 were not covered by tests
if (getTypeRef() != null) {
result.addAll(getTypeRef().flattenedTypeList());

Check warning on line 53 in bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerType.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerType.java#L53

Added line #L53 was not covered by tests
}
return result;

Check warning on line 55 in bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerType.java

View check run for this annotation

Codecov / codecov/patch

bmm/src/main/java/org/openehr/bmm/v2/persistence/PBmmIndexedContainerType.java#L55

Added line #L55 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class BmmTypeNaming extends ClassNameIdResolver {
put("BMM_INCLUDE_SPEC", BmmIncludeSpec.class).
put("P_BMM_CLASS", PBmmClass.class).
put("P_BMM_CONTAINER_PROPERTY", PBmmContainerProperty.class).
put("P_BMM_INDEXED_CONTAINER_PROPERTY", PBmmIndexedContainerProperty.class).
put("P_BMM_ENUMERATION", PBmmEnumeration.class).
put("P_BMM_ENUMERATION_STRING", PBmmEnumerationString.class).
put("P_BMM_ENUMERATION_INTEGER", PBmmEnumerationInteger.class).
Expand All @@ -33,6 +34,7 @@ public class BmmTypeNaming extends ClassNameIdResolver {
put("P_BMM_GENERIC_TYPE", PBmmGenericType.class).
put("P_BMM_OPEN_TYPE", PBmmOpenType.class).
put("P_BMM_CONTAINER_TYPE", PBmmContainerType.class).
put("P_BMM_INDEXED_CONTAINER_TYPE", PBmmIndexedContainerType.class).
put("P_BMM_PACKAGE", PBmmPackage.class).
put("P_BMM_PROPERTY", PBmmProperty.class).
put("P_BMM_SCHEMA", PBmmSchema.class).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void parseOpenEHRRoundTrip() throws Exception{
parseRoundTrip("/openehr/openehr_primitive_types_102.bmm");
parseRoundTrip("/openehr/openehr_rm_102.bmm");
parseRoundTrip("/openehr/openehr_structures_102.bmm");
parseRoundTrip("/openehr/openehr_base_110.bmm");
}

public void parseRoundTrip(String name) throws Exception {
Expand Down
Loading