Exemple #1
0
  @Test
  public void createRowMapperXref() throws Exception {
    AttributeMetaData refIdAttr = mock(AttributeMetaData.class);
    when(refIdAttr.getDataType()).thenReturn(STRING);

    EntityMetaData refEntityMeta = mock(EntityMetaData.class);
    when(refEntityMeta.getIdAttribute()).thenReturn(refIdAttr);

    String xrefAttr = "xrefAttr";
    AttributeMetaData oneToManyAttr = mock(AttributeMetaData.class);
    when(oneToManyAttr.getName()).thenReturn(xrefAttr);
    when(oneToManyAttr.getDataType()).thenReturn(XREF);
    when(oneToManyAttr.getRefEntity()).thenReturn(refEntityMeta);

    EntityMetaData entityMeta = mock(EntityMetaData.class);
    when(entityMeta.getAtomicAttributes()).thenReturn(singleton(oneToManyAttr));
    ResultSet rs = mock(ResultSet.class);
    when(rs.getString(xrefAttr)).thenReturn("id0");
    int rowNum = 0;

    Entity entity = mock(Entity.class);
    Fetch fetch = null;
    //noinspection ConstantConditions
    when(entityManager.create(entityMeta, fetch)).thenReturn(entity);
    Entity refEntity = mock(Entity.class);
    when(entityManager.getReference(refEntityMeta, "id0")).thenReturn(refEntity);
    assertEquals(
        postgreSqlEntityFactory.createRowMapper(entityMeta, null).mapRow(rs, rowNum), entity);
    verify(entity).set(xrefAttr, refEntity);
  }
Exemple #2
0
 /**
  * Create default entity fetch that fetches all attributes.
  *
  * @param entityMeta
  * @return default entity fetch or null
  */
 public static Fetch createDefaultEntityFetch(EntityMetaData entityMeta, String languageCode) {
   boolean hasRefAttr = false;
   Fetch fetch = new Fetch();
   for (AttributeMetaData attr : entityMeta.getAtomicAttributes()) {
     Fetch subFetch = createDefaultAttributeFetch(attr, languageCode);
     if (subFetch != null) {
       hasRefAttr = true;
     }
     fetch.field(attr.getName(), subFetch);
   }
   return hasRefAttr ? fetch : null;
 }
Exemple #3
0
 private static Map<String, Object> attributeToMap(AttributeMetaData attributeMetaData) {
   Map<String, Object> map = new HashMap<String, Object>();
   map.put(AttributeMetaDataMetaData.NAME, attributeMetaData.getName());
   map.put(AttributeMetaDataMetaData.LABEL, attributeMetaData.getLabel());
   map.put(AttributeMetaDataMetaData.DESCRIPTION, attributeMetaData.getDescription());
   map.put(AttributeMetaDataMetaData.DATA_TYPE, attributeMetaData.getDataType().toString());
   map.put(AttributeMetaDataMetaData.NILLABLE, attributeMetaData.isNillable());
   map.put(AttributeMetaDataMetaData.UNIQUE, attributeMetaData.isUnique());
   if (attributeMetaData.getRefEntity() != null) {
     map.put(AttributeMetaDataMetaData.REF_ENTITY, attributeMetaData.getRefEntity().getName());
   }
   return map;
 }
Exemple #4
0
  private static void createFetchContentRec(
      AttributeFilter attrFilter,
      EntityMetaData entityMeta,
      AttributeMetaData attr,
      Fetch fetch,
      String languageCode) {
    AttributeType attrType = attr.getDataType();
    switch (attrType) {
      case COMPOUND:
        {
          AttributeFilter subAttrFilter =
              attrFilter != null ? attrFilter.getAttributeFilter(entityMeta, attr) : null;
          if (subAttrFilter != null && !subAttrFilter.isIncludeAllAttrs()) {
            // include compound attribute parts defined by filter
            if (subAttrFilter.isIncludeIdAttr()) {
              createFetchContentRec(
                  subAttrFilter, entityMeta, entityMeta.getIdAttribute(), fetch, languageCode);
            }
            if (subAttrFilter.isIncludeLabelAttr()) {
              createFetchContentRec(
                  subAttrFilter,
                  entityMeta,
                  entityMeta.getLabelAttribute(languageCode),
                  fetch,
                  languageCode);
            }
            subAttrFilter.forEach(
                entry -> {
                  String attrPartName = entry.getKey();
                  AttributeMetaData attrPart = attr.getAttributePart(attrPartName);
                  createFetchContentRec(subAttrFilter, entityMeta, attrPart, fetch, languageCode);
                });
          } else {
            // include all compound attribute parts
            attr.getAttributeParts()
                .forEach(
                    attrPart -> {
                      createFetchContentRec(
                          subAttrFilter, entityMeta, attrPart, fetch, languageCode);
                    });
          }
          break;
        }
      case CATEGORICAL:
      case CATEGORICAL_MREF:
      case FILE:
      case MREF:
      case XREF:
        {
          AttributeFilter subAttrFilter =
              attrFilter != null ? attrFilter.getAttributeFilter(entityMeta, attr) : null;
          Fetch subFetch;
          if (subAttrFilter != null) {
            subFetch = convert(subAttrFilter, attr.getRefEntity(), languageCode);

          } else {
            subFetch = createDefaultAttributeFetch(attr, languageCode);
          }
          fetch.field(attr.getName(), subFetch);
          break;
        }
        // $CASES-OMITTED$
      default:
        fetch.field(attr.getName());
        break;
    }
  }