use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.
the class TagValidatorTest method validateValid.
@Test
public void validateValid() throws Exception {
Tag tag = mock(Tag.class);
when(tag.getRelationIri()).thenReturn(Relation.isRealizationOf.getIRI());
tagValidator.validate(tag);
}
use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.
the class TagValidatorTest method validateInvalid.
@Test(expectedExceptions = MolgenisValidationException.class)
public void validateInvalid() throws Exception {
Tag tag = mock(Tag.class);
when(tag.getRelationIri()).thenReturn("blaat");
tagValidator.validate(tag);
}
use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.
the class EntityUtils method equals.
/**
* Returns true if an attribute equals another attribute.
* Skips the identifier if checkIdentifier is set to false
* <p>
* Other attribute identifiers can be null when importing and this attribute
* has not been persisted to the db yet
* </p>
*
* @param checkIdentifier skips checking attribute identifier, parent attribute identifier and attribute entity identifier
*/
public static boolean equals(Attribute attr, Attribute otherAttr, boolean checkIdentifier) {
if (attr == null || otherAttr == null) {
if (attr == null && otherAttr == null)
return true;
return false;
}
if (checkIdentifier)
if (!Objects.equals(attr.getIdentifier(), otherAttr.getIdentifier()))
return false;
if (!Objects.equals(attr.getName(), otherAttr.getName()))
return false;
EntityType entity = attr.getEntity();
EntityType otherEntity = otherAttr.getEntity();
if (checkIdentifier) {
if (entity == null && otherEntity != null)
return false;
if (entity != null && otherEntity == null)
return false;
if (entity != null && !entity.getId().equals(otherEntity.getId()))
return false;
}
if (!Objects.equals(attr.getSequenceNumber(), otherAttr.getSequenceNumber()))
return false;
if (!Objects.equals(attr.getLabel(), otherAttr.getLabel()))
return false;
if (!Objects.equals(attr.getDescription(), otherAttr.getDescription()))
return false;
if (!Objects.equals(attr.getDataType(), otherAttr.getDataType()))
return false;
if (!Objects.equals(attr.isIdAttribute(), otherAttr.isIdAttribute()))
return false;
if (!Objects.equals(attr.isLabelAttribute(), otherAttr.isLabelAttribute()))
return false;
if (!Objects.equals(attr.getLookupAttributeIndex(), otherAttr.getLookupAttributeIndex()))
return false;
// recursively compare attribute parent
if (!EntityUtils.equals(attr.getParent(), otherAttr.getParent(), checkIdentifier))
return false;
// compare entity identifier
EntityType refEntity = attr.getRefEntity();
EntityType otherRefEntity = otherAttr.getRefEntity();
if (refEntity == null && otherRefEntity != null)
return false;
if (refEntity != null && otherRefEntity == null)
return false;
if (refEntity != null && !refEntity.getId().equals(otherRefEntity.getId()))
return false;
if (!EntityUtils.equals(attr.getMappedBy(), otherAttr.getMappedBy()))
return false;
if (!Objects.equals(attr.getOrderBy(), otherAttr.getOrderBy()))
return false;
if (!Objects.equals(attr.getExpression(), otherAttr.getExpression()))
return false;
if (!Objects.equals(attr.isNillable(), otherAttr.isNillable()))
return false;
if (!Objects.equals(attr.isAuto(), otherAttr.isAuto()))
return false;
if (!Objects.equals(attr.isVisible(), otherAttr.isVisible()))
return false;
if (!Objects.equals(attr.isAggregatable(), otherAttr.isAggregatable()))
return false;
if (!Objects.equals(attr.getEnumOptions(), otherAttr.getEnumOptions()))
return false;
if (!Objects.equals(attr.getRangeMin(), otherAttr.getRangeMin()))
return false;
if (!Objects.equals(attr.getRangeMax(), otherAttr.getRangeMax()))
return false;
if (!Objects.equals(attr.isReadOnly(), otherAttr.isReadOnly()))
return false;
if (!Objects.equals(attr.isUnique(), otherAttr.isUnique()))
return false;
if (!Objects.equals(attr.getNullableExpression(), otherAttr.getNullableExpression()))
return false;
if (!Objects.equals(attr.getVisibleExpression(), otherAttr.getVisibleExpression()))
return false;
if (!Objects.equals(attr.getValidationExpression(), otherAttr.getValidationExpression()))
return false;
if (!Objects.equals(attr.getDefaultValue(), otherAttr.getDefaultValue()))
return false;
// compare tag identifiers
List<Tag> tags = newArrayList(attr.getTags());
List<Tag> otherTags = newArrayList(otherAttr.getTags());
if (tags.size() != otherTags.size())
return false;
for (int i = 0; i < tags.size(); ++i) {
if (!Objects.equals(tags.get(i).getId(), otherTags.get(i).getId()))
return false;
}
return true;
}
use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.
the class TagMapperTest method testToTagReferences.
@Test
public void testToTagReferences() {
String id0 = "id0";
String id1 = "id1";
EditorTagIdentifier tagIdentifier0 = EditorTagIdentifier.create(id0, "label0");
EditorTagIdentifier tagIdentifier1 = EditorTagIdentifier.create(id1, "label1");
List<Tag> tags = copyOf(tagMapper.toTagReferences(of(tagIdentifier0, tagIdentifier1)));
assertEquals(tags.size(), 2);
assertEquals(tags.get(0).getIdValue(), id0);
assertEquals(tags.get(1).getIdValue(), id1);
}
use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.
the class TagMapperTest method testToEditorTags.
@Test
public void testToEditorTags() {
String id0 = "id0";
String label0 = "label0";
String id1 = "id1";
String label1 = "label1";
Tag tag0 = mock(Tag.class);
when(tag0.getId()).thenReturn(id0);
when(tag0.getLabel()).thenReturn(label0);
Tag tag1 = mock(Tag.class);
when(tag1.getId()).thenReturn(id1);
when(tag1.getLabel()).thenReturn(label1);
List<EditorTagIdentifier> editorTags = tagMapper.toEditorTags(of(tag0, tag1));
assertEquals(editorTags, of(EditorTagIdentifier.create(id0, label0), EditorTagIdentifier.create(id1, label1)));
}
Aggregations