Search in sources :

Example 31 with EntityType

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

the class QueryGeneratorReferencesTest method setUp.

@BeforeMethod
public void setUp() {
    EntityType refEntityType = entityTypeFactory.create("ref_entity");
    String refIdAttributeName = "xid";
    refEntityType.addAttribute(attrFactory.create().setName(refIdAttributeName), ROLE_ID);
    refEntityType.addAttribute(attrFactory.create().setName(refBoolAttributeName).setDataType(BOOL));
    refEntityType.addAttribute(attrFactory.create().setName(refCategoricalAttributeName).setDataType(CATEGORICAL).setRefEntity(refEntityType).setNillable(true));
    Attribute attrCompound = attrFactory.create().setName(refCompoundAttributeName).setDataType(COMPOUND);
    Attribute compoundPart0Attribute = attrFactory.create().setName(refCompoundPart0AttributeName).setDataType(STRING).setParent(attrCompound);
    String refCompoundPart1AttributeName = "xcompoundpart1";
    Attribute compoundPart1Attribute = attrFactory.create().setName(refCompoundPart1AttributeName).setDataType(STRING).setParent(attrCompound);
    refEntityType.addAttribute(attrCompound);
    refEntityType.addAttribute(compoundPart0Attribute);
    refEntityType.addAttribute(compoundPart1Attribute);
    refEntityType.addAttribute(attrFactory.create().setName(refDateAttributeName).setDataType(DATE));
    refEntityType.addAttribute(attrFactory.create().setName(refDateTimeAttributeName).setDataType(DATE_TIME));
    refEntityType.addAttribute(attrFactory.create().setName(refDecimalAttributeName).setDataType(DECIMAL));
    String refEmailAttributeName = "xemail";
    refEntityType.addAttribute(attrFactory.create().setName(refEmailAttributeName).setDataType(EMAIL));
    String refEnumAttributeName = "xenum";
    refEntityType.addAttribute(attrFactory.create().setName(refEnumAttributeName).setDataType(ENUM).setEnumOptions(Arrays.asList("enum0", "enum1", "enum2")));
    String refHtmlAttributeName = "xhtml";
    refEntityType.addAttribute(attrFactory.create().setName(refHtmlAttributeName).setDataType(HTML));
    String refHyperlinkAttributeName = "xhyperlink";
    refEntityType.addAttribute(attrFactory.create().setName(refHyperlinkAttributeName).setDataType(HYPERLINK));
    refEntityType.addAttribute(attrFactory.create().setName(refIntAttributeName).setDataType(INT));
    refEntityType.addAttribute(attrFactory.create().setName(refLongAttributeName).setDataType(LONG));
    String refMrefAttributeName = "xmref";
    refEntityType.addAttribute(attrFactory.create().setName(refMrefAttributeName).setDataType(MREF).setRefEntity(refEntityType).setNillable(true));
    String refScriptAttributeName = "xscript";
    refEntityType.addAttribute(attrFactory.create().setName(refScriptAttributeName).setDataType(SCRIPT));
    refEntityType.addAttribute(attrFactory.create().setName(refStringAttributeName).setDataType(STRING));
    String refTextAttributeName = "xtext";
    refEntityType.addAttribute(attrFactory.create().setName(refTextAttributeName).setDataType(TEXT));
    String refXrefAttributeName = "xxref";
    refEntityType.addAttribute(attrFactory.create().setName(refXrefAttributeName).setDataType(XREF).setRefEntity(refEntityType).setNillable(true));
    EntityType emd = entityTypeFactory.create("entity");
    String idAttributeName = "id";
    emd.addAttribute(attrFactory.create().setName(idAttributeName), ROLE_ID);
    emd.addAttribute(attrFactory.create().setName(stringAttributeName).setUnique(true), ROLE_LABEL);
    String mrefAttributeName = "mref";
    emd.addAttribute(attrFactory.create().setName(mrefAttributeName).setDataType(MREF).setNillable(true).setRefEntity(refEntityType));
    this.entityType = emd;
    DocumentIdGenerator documentIdGenerator = mock(DocumentIdGenerator.class);
    when(documentIdGenerator.generateId(any(Attribute.class))).thenAnswer(invocation -> ((Attribute) invocation.getArguments()[0]).getName());
    queryGenerator = new QueryGenerator(documentIdGenerator);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 32 with EntityType

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

the class AnnotatorDependencyOrderResolverTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    Attribute attra = attributeFactory.create().setName("A").setDataType(STRING);
    // to check for matching "STRING" attributes to required "TEXT" attributes
    Attribute attra2 = attributeFactory.create().setName("A").setDataType(TEXT);
    Attribute attrb = attributeFactory.create().setName("B").setDataType(STRING);
    Attribute attrc = attributeFactory.create().setName("C").setDataType(STRING);
    Attribute attrd = attributeFactory.create().setName("D").setDataType(STRING);
    Attribute attre = attributeFactory.create().setName("E").setDataType(STRING);
    Attribute attrf = attributeFactory.create().setName("F").setDataType(STRING);
    Attribute attrg = attributeFactory.create().setName("G").setDataType(STRING);
    Attribute attrh = attributeFactory.create().setName("H").setDataType(STRING);
    Attribute attri = attributeFactory.create().setName("I").setDataType(STRING);
    Attribute attrj = attributeFactory.create().setName("J").setDataType(STRING);
    EntityType emd = entityTypeFactory.create("test");
    emd.addAttributes(Arrays.asList(attra, attrb));
    when(repo.getEntityType()).thenReturn(emd);
    when(annotator1.getInfo()).thenReturn(annotator1info);
    when(annotator2.getInfo()).thenReturn(annotator2info);
    when(annotator3.getInfo()).thenReturn(annotator3info);
    when(annotator4.getInfo()).thenReturn(annotator4info);
    when(annotator5.getInfo()).thenReturn(annotator5info);
    when(annotator1.getSimpleName()).thenReturn("annotator1");
    when(annotator2.getSimpleName()).thenReturn("annotator2");
    when(annotator3.getSimpleName()).thenReturn("annotator3");
    when(annotator4.getSimpleName()).thenReturn("annotator4");
    when(annotator5.getSimpleName()).thenReturn("annotator5");
    when(annotator1.getRequiredAttributes()).thenReturn(Arrays.asList(attrd, attrh, attri));
    when(annotator1info.getOutputAttributes()).thenReturn(Arrays.asList(attre, attrc));
    when(annotator2.getRequiredAttributes()).thenReturn(Arrays.asList(attra2, attrb));
    when(annotator2info.getOutputAttributes()).thenReturn(Arrays.asList(attrj));
    when(annotator3.getRequiredAttributes()).thenReturn(Arrays.asList(attra2, attrh));
    when(annotator3info.getOutputAttributes()).thenReturn(Arrays.asList(attrd, attrj));
    when(annotator4.getRequiredAttributes()).thenReturn(Arrays.asList(attra, attrb));
    when(annotator4info.getOutputAttributes()).thenReturn(Arrays.asList(attrh));
    when(annotator5.getRequiredAttributes()).thenReturn(Arrays.asList(attrb, attrd));
    when(annotator5info.getOutputAttributes()).thenReturn(Arrays.asList(attri, attrf));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 33 with EntityType

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

the class L1CacheRepositoryDecorator method deleteAll.

@Override
public void deleteAll(Stream<Object> ids) {
    evictBiDiReferencedEntityTypes();
    if (cacheable) {
        EntityType entityType = getEntityType();
        ids = ids.peek(id -> l1Cache.putDeletion(EntityKey.create(entityType, id)));
    }
    delegate().deleteAll(ids);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Spliterators.spliteratorUnknownSize(java.util.Spliterators.spliteratorUnknownSize) java.util(java.util) org.molgenis.data(org.molgenis.data) Iterators.partition(com.google.common.collect.Iterators.partition) ORDERED(java.util.Spliterator.ORDERED) WRITABLE(org.molgenis.data.RepositoryCapability.WRITABLE) CACHEABLE(org.molgenis.data.RepositoryCapability.CACHEABLE) Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) Iterators(com.google.common.collect.Iterators) Collectors.toList(java.util.stream.Collectors.toList) Lists(com.google.common.collect.Lists) Stream(java.util.stream.Stream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SORTED(java.util.Spliterator.SORTED) Collectors.toMap(java.util.stream.Collectors.toMap) StreamSupport.stream(java.util.stream.StreamSupport.stream) Objects.requireNonNull(java.util.Objects.requireNonNull)

Example 34 with EntityType

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

the class EntityHydration method dehydrate.

/**
 * Creates a Map containing the values required to rebuild this entity.
 * For references to other entities only stores the ids.
 *
 * @param entity the {@link Entity} to dehydrate
 * @return Map representation of the entity
 */
public Map<String, Object> dehydrate(Entity entity) {
    LOG.trace("Dehydrating entity {}", entity);
    Map<String, Object> dehydratedEntity = newHashMap();
    EntityType entityType = entity.getEntityType();
    entityType.getAtomicAttributes().forEach(attribute -> {
        // Only dehydrate if the attribute is NOT computed
        if (!attribute.hasExpression()) {
            String name = attribute.getName();
            AttributeType type = attribute.getDataType();
            dehydratedEntity.put(name, getValueBasedOnType(entity, name, type));
        }
    });
    return dehydratedEntity;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) AttributeType(org.molgenis.data.meta.AttributeType)

Example 35 with EntityType

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

the class EntityHydrationTest method beforeClass.

@BeforeClass
public void beforeClass() throws ParseException {
    // create referenced entities
    EntityType refEntityType = entityTestHarness.createDynamicRefEntityType();
    refEntities = entityTestHarness.createTestRefEntities(refEntityType, 1);
    entityType = entityTestHarness.createDynamicTestEntityType(refEntityType);
    // create hydrated entity
    hydratedEntity = entityTestHarness.createTestEntities(entityType, 1, refEntities).collect(toList()).get(0);
    LocalDate date = LocalDate.parse("2012-12-21");
    Instant dateTime = Instant.parse("1985-08-12T06:12:13Z");
    // create dehydrated entity
    dehydratedEntity = newHashMap();
    dehydratedEntity.put(ATTR_ID, "0");
    dehydratedEntity.put(ATTR_STRING, "string1");
    dehydratedEntity.put(ATTR_BOOL, true);
    dehydratedEntity.put(ATTR_CATEGORICAL, "0");
    dehydratedEntity.put(ATTR_CATEGORICAL_MREF, singletonList("0"));
    dehydratedEntity.put(ATTR_DATE, date);
    dehydratedEntity.put(ATTR_DATETIME, dateTime);
    dehydratedEntity.put(ATTR_EMAIL, "this.is@mail.address");
    dehydratedEntity.put(ATTR_DECIMAL, 0.123);
    dehydratedEntity.put(ATTR_HTML, null);
    dehydratedEntity.put(ATTR_HYPERLINK, "http://www.molgenis.org");
    dehydratedEntity.put(ATTR_LONG, 0L);
    dehydratedEntity.put(ATTR_INT, 10);
    dehydratedEntity.put(ATTR_SCRIPT, "/bin/blaat/script.sh");
    dehydratedEntity.put(ATTR_XREF, "0");
    dehydratedEntity.put(ATTR_MREF, singletonList("0"));
    dehydratedEntity.put(ATTR_COMPOUND_CHILD_INT, 10);
    dehydratedEntity.put(ATTR_ENUM, "option1");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Instant(java.time.Instant) LocalDate(java.time.LocalDate) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

EntityType (org.molgenis.data.meta.model.EntityType)581 Test (org.testng.annotations.Test)367 Attribute (org.molgenis.data.meta.model.Attribute)315 Entity (org.molgenis.data.Entity)98 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)71 DynamicEntity (org.molgenis.data.support.DynamicEntity)61 Stream (java.util.stream.Stream)44 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)43 WithMockUser (org.springframework.security.test.context.support.WithMockUser)40 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)36 QueryImpl (org.molgenis.data.support.QueryImpl)33 Package (org.molgenis.data.meta.model.Package)32 Objects.requireNonNull (java.util.Objects.requireNonNull)22 Collectors.toList (java.util.stream.Collectors.toList)22 BeforeMethod (org.testng.annotations.BeforeMethod)20 AttributeType (org.molgenis.data.meta.AttributeType)19 List (java.util.List)17 String.format (java.lang.String.format)16 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)16 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)15