Search in sources :

Example 1 with Tag

use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.

the class TagRepositoryValidationDecoratorTest method testUpdateStreamValid.

@Test
public void testUpdateStreamValid() throws Exception {
    Tag tag0 = mock(Tag.class);
    Tag tag1 = mock(Tag.class);
    doNothing().when(tagValidator).validate(tag0);
    doNothing().when(tagValidator).validate(tag1);
    tagRepositoryValidationDecorator.update(Stream.of(tag0, tag1));
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Tag>> tagCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(delegateRepository).update(tagCaptor.capture());
    assertEquals(tagCaptor.getValue().collect(toList()), asList(tag0, tag1));
    verify(tagValidator).validate(tag0);
    verify(tagValidator).validate(tag1);
}
Also used : Stream(java.util.stream.Stream) Tag(org.molgenis.data.meta.model.Tag) Test(org.testng.annotations.Test)

Example 2 with Tag

use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.

the class EntityUtils method equals.

/**
 * Returns true if entity metadata equals another entity metadata. TODO docs
 */
public static boolean equals(EntityType entityType, EntityType otherEntityType) {
    if (entityType == null && otherEntityType != null)
        return false;
    if (entityType != null && otherEntityType == null)
        return false;
    if (!(entityType != null && entityType.getId().equals(otherEntityType.getId())))
        return false;
    if (!Objects.equals(entityType.getLabel(), otherEntityType.getLabel()))
        return false;
    if (!Objects.equals(entityType.getDescription(), otherEntityType.getDescription()))
        return false;
    if (entityType.isAbstract() != otherEntityType.isAbstract())
        return false;
    // NB This is at such a low level that we do not know the default backend
    // so we don't check if the other one is the default if the backend is null.
    String backend = entityType.getBackend();
    String otherBackend = otherEntityType.getBackend();
    if ((backend == null && otherBackend != null) || (backend != null && otherBackend == null) || (backend != null && !backend.equals(otherBackend))) {
        return false;
    }
    // compare package identifiers
    Package pack = entityType.getPackage();
    Package otherPackage = otherEntityType.getPackage();
    if (pack == null && otherPackage != null)
        return false;
    if (pack != null && otherPackage == null)
        return false;
    if (pack != null && !pack.getIdValue().equals(otherPackage.getIdValue())) {
        return false;
    }
    // compare id attribute identifier (identifier might be null if id attribute hasn't been persisted yet)
    Attribute ownIdAttribute = entityType.getOwnIdAttribute();
    Attribute otherOwnIdAttribute = otherEntityType.getOwnIdAttribute();
    if (ownIdAttribute == null && otherOwnIdAttribute != null)
        return false;
    if (ownIdAttribute != null && otherOwnIdAttribute == null)
        return false;
    if (ownIdAttribute != null && !Objects.equals(ownIdAttribute.getIdentifier(), otherOwnIdAttribute.getIdentifier()))
        return false;
    // compare label attribute identifier (identifier might be null if id attribute hasn't been persisted yet)
    Attribute ownLabelAttribute = entityType.getOwnLabelAttribute();
    Attribute otherOwnLabelAttribute = otherEntityType.getOwnLabelAttribute();
    if (ownLabelAttribute == null && otherOwnLabelAttribute != null)
        return false;
    if (ownLabelAttribute != null && otherOwnLabelAttribute == null)
        return false;
    if (ownLabelAttribute != null && !Objects.equals(ownLabelAttribute.getIdentifier(), otherOwnLabelAttribute.getIdentifier()))
        return false;
    // compare lookup attribute identifiers
    List<Attribute> lookupAttrs = newArrayList(entityType.getOwnLookupAttributes());
    List<Attribute> otherLookupAttrs = newArrayList(otherEntityType.getOwnLookupAttributes());
    if (lookupAttrs.size() != otherLookupAttrs.size())
        return false;
    for (int i = 0; i < lookupAttrs.size(); ++i) {
        // identifier might be null if id attribute hasn't been persisted yet
        if (!Objects.equals(lookupAttrs.get(i).getIdentifier(), otherLookupAttrs.get(i).getIdentifier())) {
            return false;
        }
    }
    // compare extends entity identifier
    EntityType extendsEntityType = entityType.getExtends();
    EntityType otherExtendsEntityType = otherEntityType.getExtends();
    if (extendsEntityType == null && otherExtendsEntityType != null)
        return false;
    if (extendsEntityType != null && otherExtendsEntityType == null)
        return false;
    if (extendsEntityType != null && !extendsEntityType.getId().equals(otherExtendsEntityType.getId()))
        return false;
    // compare attributes
    if (!equals(entityType.getOwnAllAttributes(), otherEntityType.getOwnAllAttributes()))
        return false;
    // compare tag identifiers
    List<Tag> tags = newArrayList(entityType.getTags());
    List<Tag> otherTags = newArrayList(otherEntityType.getTags());
    if (tags.size() != otherTags.size())
        return false;
    for (int i = 0; i < tags.size(); ++i) {
        if (!tags.get(i).getId().equals(otherTags.get(i).getId()))
            return false;
    }
    return entityType.getIndexingDepth() == otherEntityType.getIndexingDepth();
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) Package(org.molgenis.data.meta.model.Package) Tag(org.molgenis.data.meta.model.Tag)

Example 3 with Tag

use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.

the class EmxImportServiceIT method verifyItEmxTags.

private void verifyItEmxTags() {
    verifyFirstAndLastRows("sys_md_Tag", tagFirstRow, tagLastRow);
    EntityType entityType = dataService.getEntityType("it_emx_tags_TagEntity");
    Iterable<Tag> entityTags = entityType.getTags();
    assertEquals(getIdsAsSet(entityTags), newHashSet("entitytag0", "entitytag1"));
    Iterable<Tag> idTags = entityType.getAttribute("id").getTags();
    Iterable<Tag> labelTags = entityType.getAttribute("label").getTags();
    assertEquals(getIdsAsSet(idTags), newHashSet("attributetag0", "attributetag1"));
    assertEquals(getIdsAsSet(labelTags), newHashSet("attributetag0", "attributetag1"));
    Package emxPackage = entityType.getPackage();
    Iterable<Tag> packageTags = emxPackage.getTags();
    assertEquals(getIdsAsSet(packageTags), newHashSet("packagetag0", "packagetag1"));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Tag(org.molgenis.data.meta.model.Tag) Package(org.molgenis.data.meta.model.Package)

Example 4 with Tag

use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.

the class TagRepositoryValidationDecoratorTest method testAddStreamInvalid.

@Test(expectedExceptions = MolgenisValidationException.class)
public void testAddStreamInvalid() throws Exception {
    Tag tag0 = mock(Tag.class);
    Tag tag1 = mock(Tag.class);
    doNothing().when(tagValidator).validate(tag0);
    doThrow(mock(MolgenisValidationException.class)).when(tagValidator).validate(tag1);
    tagRepositoryValidationDecorator.add(Stream.of(tag0, tag1));
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Tag>> tagCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(delegateRepository).add(tagCaptor.capture());
    // consume stream
    tagCaptor.getValue().count();
}
Also used : Stream(java.util.stream.Stream) Tag(org.molgenis.data.meta.model.Tag) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) Test(org.testng.annotations.Test)

Example 5 with Tag

use of org.molgenis.data.meta.model.Tag in project molgenis by molgenis.

the class TagRepositoryValidationDecoratorTest method testUpdateInvalid.

@Test(expectedExceptions = MolgenisValidationException.class)
public void testUpdateInvalid() throws Exception {
    Tag tag = mock(Tag.class);
    doThrow(mock(MolgenisValidationException.class)).when(tagValidator).validate(tag);
    tagRepositoryValidationDecorator.update(tag);
}
Also used : Tag(org.molgenis.data.meta.model.Tag) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException) Test(org.testng.annotations.Test)

Aggregations

Tag (org.molgenis.data.meta.model.Tag)18 Test (org.testng.annotations.Test)14 Stream (java.util.stream.Stream)4 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)4 EntityType (org.molgenis.data.meta.model.EntityType)3 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)2 Package (org.molgenis.data.meta.model.Package)2 EditorTagIdentifier (org.molgenis.metadata.manager.model.EditorTagIdentifier)2 Attribute (org.molgenis.data.meta.model.Attribute)1